4f3f750dbad39dd18ffb18740d896f150059fd9d
[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 "qtui.h"
35 #include "titlesetter.h"
36 #include "uisettings.h"
37
38 class ActionCollection;
39 class BufferHotListFilter;
40 class BufferView;
41 class BufferViewConfig;
42 class ClientBufferViewConfig;
43 class CoreAccount;
44 class CoreConnectionStatusWidget;
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 BufferWidget *bufferWidget() const { return _bufferWidget; }
77
78 #ifndef QT_NO_SYSTEMTRAYICON
79     inline SystemTray *systemTray() const { return _systemTray; }
80 #endif
81
82     bool event(QEvent *event);
83
84     static void flagRemoteCoreOnly(QObject *object) { object->setProperty("REMOTE_CORE_ONLY", true); }
85     static bool isRemoteCoreOnly(QObject *object) { return object->property("REMOTE_CORE_ONLY").toBool(); }
86
87     void saveStateToSettings(UiSettings &);
88     void restoreStateFromSettings(UiSettings &);
89
90   public slots:
91     void showStatusBarMessage(const QString &message);
92
93 #ifndef QT_NO_SYSTEMTRAYICON
94     void toggleMinimizedToTray();
95 #endif
96
97     //! Bring window to front and focus it
98     void forceActivated();
99
100     //! Quit application
101     void quit();
102
103   protected:
104     void closeEvent(QCloseEvent *event);
105     void changeEvent(QEvent *event);
106     void moveEvent(QMoveEvent *event);
107     void resizeEvent(QResizeEvent *event);
108
109   protected slots:
110     void connectedToCore();
111     void setConnectedState();
112     void disconnectedFromCore();
113     void setDisconnectedState();
114
115   private slots:
116     void addBufferView(int bufferViewConfigId);
117     void awayLogDestroyed();
118     void removeBufferView(int bufferViewConfigId);
119     void currentBufferChanged(BufferId);
120     void messagesInserted(const QModelIndex &parent, int start, int end);
121     void showAboutDlg();
122     void showChannelList(NetworkId netId = NetworkId());
123     void showCoreConnectionDlg();
124     void showCoreConfigWizard(const QVariantList &);
125     void showCoreInfoDlg();
126     void showAwayLog();
127     void showSettingsDlg();
128     void showNotificationsDlg();
129     void showIgnoreList(QString newRule = QString());
130 #ifdef HAVE_KDE
131     void showShortcutsDlg();
132 #endif
133     void handleCoreConnectionError(const QString &errorMsg);
134     void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage);
135     void handleNoSslInClient(bool *accepted);
136     void handleNoSslInCore(bool *accepted);
137 #ifdef HAVE_SSL
138     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
139 #endif
140
141     void on_actionConfigureNetworks_triggered();
142     void on_actionConfigureViews_triggered();
143     void on_actionLockLayout_toggled(bool lock);
144     void on_jumpHotBuffer_triggered();
145     void on_actionDebugNetworkModel_triggered();
146     void on_actionDebugBufferViewOverlay_triggered();
147     void on_actionDebugMessageModel_triggered();
148     void on_actionDebugHotList_triggered();
149     void on_actionDebugLog_triggered();
150
151     void clientNetworkCreated(NetworkId);
152     void clientNetworkRemoved(NetworkId);
153     void clientNetworkUpdated();
154     void connectOrDisconnectFromNet();
155
156     void saveMenuBarStatus(bool enabled);
157     void saveStatusBarStatus(bool enabled);
158
159     void loadLayout();
160     void saveLayout();
161
162     void bufferViewToggled(bool enabled);
163
164   signals:
165     void connectToCore(const QVariantMap &connInfo);
166     void disconnectFromCore();
167
168   private:
169 #ifdef HAVE_KDE
170     KHelpMenu *_kHelpMenu;
171 #endif
172
173     MsgProcessorStatusWidget *_msgProcessorStatusWidget;
174     CoreConnectionStatusWidget *_coreConnectionStatusWidget;
175
176     TitleSetter _titleSetter;
177
178     void setupActions();
179     void setupBufferWidget();
180     void setupMenus();
181     void setupNickWidget();
182     void setupChatMonitor();
183     void setupInputWidget();
184     void setupTopicWidget();
185     void setupStatusBar();
186     void setupSystray();
187     void setupTitleSetter();
188     void setupToolBars();
189     void setupHotList();
190
191     void updateIcon();
192     void enableMenus();
193
194 #ifndef QT_NO_SYSTEMTRAYICON
195     void hideToTray();
196     SystemTray *_systemTray;
197 #endif
198
199     QList<BufferViewDock *> _bufferViews;
200     BufferWidget *_bufferWidget;
201     NickListWidget *_nickListWidget;
202     InputWidget *_inputWidget;
203
204     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
205     QMenu *_toolbarMenu;
206     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
207
208     QWidget *_awayLog;
209
210     bool _layoutLoaded;
211
212     QSize _normalSize; //!< Size of the non-maximized window
213     QPoint _normalPos; //!< Position of the non-maximized window
214
215 #ifdef Q_WS_WIN
216     DWORD dwTickCount;
217 #endif
218
219     BufferHotListFilter *_bufferHotList;
220
221     friend class QtUi;
222 };
223
224 #endif