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