a42c3f8b9c49135a37916eee4a31aca8fb9f36a9
[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 CoreConnectionStatusWidget;
46 class BufferViewDock;
47 class BufferWidget;
48 class InputWidget;
49 class MsgProcessorStatusWidget;
50 class NickListWidget;
51 class SystemTray;
52
53 class QMenu;
54 class QLabel;
55 class QToolBar;
56
57 class KHelpMenu;
58
59 //!\brief The main window of Quassel's QtUi.
60 class MainWin
61 #ifdef HAVE_KDE
62 : public KMainWindow {
63 #else
64 : public QMainWindow {
65 #endif
66   Q_OBJECT
67
68   public:
69     MainWin(QWidget *parent = 0);
70     virtual ~MainWin();
71
72     void init();
73
74     void addBufferView(ClientBufferViewConfig *config);
75     BufferView *allBuffersView() const;
76
77     BufferWidget *bufferWidget() const { return _bufferWidget; }
78
79     inline SystemTray *systemTray() const;
80
81     bool event(QEvent *event);
82
83     static void flagRemoteCoreOnly(QObject *object) { object->setProperty("REMOTE_CORE_ONLY", true); }
84     static bool isRemoteCoreOnly(QObject *object) { return object->property("REMOTE_CORE_ONLY").toBool(); }
85
86     void saveStateToSettings(UiSettings &);
87     void restoreStateFromSettings(UiSettings &);
88
89   public slots:
90     void showStatusBarMessage(const QString &message);
91
92     void toggleMinimizedToTray();
93
94     //! Bring window to front and focus it
95     void forceActivated();
96
97     //! Quit application
98     void quit();
99
100   protected:
101     void closeEvent(QCloseEvent *event);
102     void changeEvent(QEvent *event);
103     void moveEvent(QMoveEvent *event);
104     void resizeEvent(QResizeEvent *event);
105
106   protected slots:
107     void connectedToCore();
108     void setConnectedState();
109     void updateLagIndicator(int lag = -1);
110     void disconnectedFromCore();
111     void setDisconnectedState();
112
113   private slots:
114     void addBufferView(int bufferViewConfigId);
115     void awayLogDestroyed();
116     void removeBufferView(int bufferViewConfigId);
117     void currentBufferChanged(BufferId);
118     void messagesInserted(const QModelIndex &parent, int start, int end);
119     void showAboutDlg();
120     void showChannelList(NetworkId netId = NetworkId());
121     void startInternalCore();
122     void showCoreConnectionDlg();
123     void showCoreInfoDlg();
124     void showAwayLog();
125     void showSettingsDlg();
126     void showNotificationsDlg();
127     void showIgnoreList(QString newRule = QString());
128 #ifdef HAVE_KDE
129     void showShortcutsDlg();
130 #endif
131     void on_actionConfigureNetworks_triggered();
132     void on_actionConfigureViews_triggered();
133     void on_actionLockLayout_toggled(bool lock);
134     void on_jumpHotBuffer_triggered();
135     void on_actionDebugNetworkModel_triggered();
136     void on_actionDebugBufferViewOverlay_triggered();
137     void on_actionDebugMessageModel_triggered();
138     void on_actionDebugHotList_triggered();
139     void on_actionDebugLog_triggered();
140
141     void clientNetworkCreated(NetworkId);
142     void clientNetworkRemoved(NetworkId);
143     void clientNetworkUpdated();
144     void connectOrDisconnectFromNet();
145
146     void saveMenuBarStatus(bool enabled);
147     void saveStatusBarStatus(bool enabled);
148
149     void loadLayout();
150     void saveLayout();
151
152     void bufferViewToggled(bool enabled);
153
154   signals:
155     void connectToCore(const QVariantMap &connInfo);
156     void disconnectFromCore();
157
158   private:
159 #ifdef HAVE_KDE
160     KHelpMenu *_kHelpMenu;
161 #endif
162
163     QLabel *coreLagLabel;
164     QLabel *sslLabel;
165     MsgProcessorStatusWidget *_msgProcessorStatusWidget;
166     CoreConnectionStatusWidget *_coreConnectionStatusWidget;
167
168     TitleSetter _titleSetter;
169
170     void setupActions();
171     void setupBufferWidget();
172     void setupMenus();
173     void setupNickWidget();
174     void setupChatMonitor();
175     void setupInputWidget();
176     void setupTopicWidget();
177     void setupStatusBar();
178     void setupSystray();
179     void setupTitleSetter();
180     void setupToolBars();
181     void setupHotList();
182
183     void updateIcon();
184     void enableMenus();
185
186     void hideToTray();
187
188     SystemTray *_systemTray;
189
190     QList<BufferViewDock *> _bufferViews;
191     BufferWidget *_bufferWidget;
192     NickListWidget *_nickListWidget;
193     InputWidget *_inputWidget;
194
195     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
196     QMenu *_toolbarMenu;
197     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
198
199     QWidget *_awayLog;
200
201     bool _layoutLoaded;
202
203     QSize _normalSize; //!< Size of the non-maximized window
204     QPoint _normalPos; //!< Position of the non-maximized window
205
206 #ifdef Q_WS_WIN
207     DWORD dwTickCount;
208 #endif
209
210     BufferHotListFilter *_bufferHotList;
211
212     friend class QtUi;
213 };
214
215 SystemTray *MainWin::systemTray() const {
216   return _systemTray;
217 }
218
219 #endif