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