More windowstate-related changes
[quassel.git] / src / qtui / mainwin.h
1 /***************************************************************************
2  *   Copyright (C) 2005-09 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef MAINWIN_H_
22 #define MAINWIN_H_
23
24 #ifdef HAVE_KDE
25 #  include <KMainWindow>
26 #else
27 #  include <QMainWindow>
28 #endif
29
30 #ifdef Q_WS_WIN
31 #  include <windows.h>
32 #endif
33
34 #include <QSystemTrayIcon>
35
36 #include "qtui.h"
37 #include "titlesetter.h"
38 #include "uisettings.h"
39
40 class ActionCollection;
41 class BufferHotListFilter;
42 class BufferView;
43 class BufferViewConfig;
44 class ClientBufferViewConfig;
45 class BufferViewDock;
46 class BufferWidget;
47 class InputWidget;
48 class MsgProcessorStatusWidget;
49 class NickListWidget;
50 class SystemTray;
51
52 class QMenu;
53 class QLabel;
54 class QToolBar;
55
56 class KHelpMenu;
57
58 //!\brief The main window of Quassel's QtUi.
59 class MainWin
60 #ifdef HAVE_KDE
61 : public KMainWindow {
62 #else
63 : public QMainWindow {
64 #endif
65   Q_OBJECT
66
67   public:
68     MainWin(QWidget *parent = 0);
69     virtual ~MainWin();
70
71     void init();
72
73     void addBufferView(ClientBufferViewConfig *config);
74     BufferView *allBuffersView() const;
75
76     inline SystemTray *systemTray() const;
77
78     bool event(QEvent *event);
79
80     static void flagRemoteCoreOnly(QObject *object) { object->setProperty("REMOTE_CORE_ONLY", true); }
81     static bool isRemoteCoreOnly(QObject *object) { return object->property("REMOTE_CORE_ONLY").toBool(); }
82
83     void saveStateToSettings(UiSettings &);
84     void restoreStateFromSettings(UiSettings &);
85
86   public slots:
87     void showStatusBarMessage(const QString &message);
88
89     void toggleMinimizedToTray();
90
91     //! Bring window to front and focus it
92     void forceActivated();
93
94   protected:
95     void closeEvent(QCloseEvent *event);
96     void changeEvent(QEvent *event);
97     void moveEvent(QMoveEvent *event);
98     void resizeEvent(QResizeEvent *event);
99
100   protected slots:
101     void connectedToCore();
102     void setConnectedState();
103     void updateLagIndicator(int lag = -1);
104     void disconnectedFromCore();
105     void setDisconnectedState();
106
107   private slots:
108     void addBufferView(int bufferViewConfigId);
109     void awayLogDestroyed();
110     void removeBufferView(int bufferViewConfigId);
111     void messagesInserted(const QModelIndex &parent, int start, int end);
112     void showAboutDlg();
113     void showChannelList(NetworkId netId = NetworkId());
114     void startInternalCore();
115     void showCoreConnectionDlg(bool autoConnect = false);
116     void showCoreInfoDlg();
117     void showAwayLog();
118     void showSettingsDlg();
119     void showNotificationsDlg();
120 #ifdef HAVE_KDE
121     void showShortcutsDlg();
122 #endif
123     void on_actionConfigureNetworks_triggered();
124     void on_actionConfigureViews_triggered();
125     void on_actionLockLayout_toggled(bool lock);
126     void on_jumpHotBuffer_triggered();
127     void on_actionDebugNetworkModel_triggered();
128     void on_actionDebugBufferViewOverlay_triggered();
129     void on_actionDebugMessageModel_triggered();
130     void on_actionDebugHotList_triggered();
131     void on_actionDebugLog_triggered();
132
133     void clientNetworkCreated(NetworkId);
134     void clientNetworkRemoved(NetworkId);
135     void clientNetworkUpdated();
136     void connectOrDisconnectFromNet();
137
138     void saveStatusBarStatus(bool enabled);
139     void aboutToQuit();
140
141     void loadLayout();
142     void saveLayout();
143
144     void bufferViewToggled(bool enabled);
145
146   signals:
147     void connectToCore(const QVariantMap &connInfo);
148     void disconnectFromCore();
149
150   private:
151 #ifdef HAVE_KDE
152     KHelpMenu *_kHelpMenu;
153 #endif
154
155     QLabel *coreLagLabel;
156     QLabel *sslLabel;
157     MsgProcessorStatusWidget *msgProcessorStatusWidget;
158
159     TitleSetter _titleSetter;
160
161     void setupActions();
162     void setupBufferWidget();
163     void setupMenus();
164     void setupNickWidget();
165     void setupChatMonitor();
166     void setupInputWidget();
167     void setupTopicWidget();
168     void setupStatusBar();
169     void setupSystray();
170     void setupTitleSetter();
171     void setupToolBars();
172     void setupHotList();
173
174     void updateIcon();
175     void enableMenus();
176
177     void hideToTray();
178
179     SystemTray *_systemTray;
180
181     QList<BufferViewDock *> _bufferViews;
182     BufferWidget *_bufferWidget;
183     NickListWidget *_nickListWidget;
184     InputWidget *_inputWidget;
185
186     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
187     QMenu *_toolbarMenu;
188     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
189
190     QWidget *_awayLog;
191
192     QSize _normalSize; //!< Size of the non-maximized window
193     QPoint _normalPos; //!< Position of the non-maximized window
194     bool _isHidden;
195
196 #ifdef Q_WS_WIN
197     DWORD dwTickCount;
198 #endif
199
200     BufferHotListFilter *_bufferHotList;
201
202     friend class QtUi;
203 };
204
205 SystemTray *MainWin::systemTray() const {
206   return _systemTray;
207 }
208
209 #endif