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