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