Systray icon improvements
[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 "sessionsettings.h"
38 #include "titlesetter.h"
39
40 class ActionCollection;
41 class BufferView;
42 class BufferViewConfig;
43 class ClientBufferViewConfig;
44 class BufferViewDock;
45 class BufferWidget;
46 class InputWidget;
47 class MsgProcessorStatusWidget;
48 class NickListWidget;
49 class SystemTray;
50
51 class QMenu;
52 class QLabel;
53 class QToolBar;
54
55 class KHelpMenu;
56
57 //!\brief The main window of Quassel's QtUi.
58 class MainWin
59 #ifdef HAVE_KDE
60 : public KMainWindow {
61 #else
62 : public QMainWindow {
63 #endif
64   Q_OBJECT
65
66   public:
67     MainWin(QWidget *parent = 0);
68     virtual ~MainWin();
69
70     void init();
71
72     void addBufferView(ClientBufferViewConfig *config);
73     BufferView *allBuffersView() const;
74
75     inline SystemTray *systemTray() const;
76
77     bool event(QEvent *event);
78
79     static void flagRemoteCoreOnly(QObject *object) { object->setProperty("REMOTE_CORE_ONLY", true); }
80     static bool isRemoteCoreOnly(QObject *object) { return object->property("REMOTE_CORE_ONLY").toBool(); }
81
82   public slots:
83     void saveStateToSession(const QString &sessionId);
84     void saveStateToSessionSettings(SessionSettings &s);
85     void showStatusBarMessage(const QString &message);
86
87     void toggleMinimizedToTray();
88
89     //! Bring window to front and focus it
90     void forceActivated();
91
92   protected:
93     void closeEvent(QCloseEvent *event);
94     void changeEvent(QEvent *event);
95
96   protected slots:
97     void connectedToCore();
98     void setConnectedState();
99     void updateLagIndicator(int lag = -1);
100     void disconnectedFromCore();
101     void setDisconnectedState();
102
103   private slots:
104     void addBufferView(int bufferViewConfigId);
105     void awayLogDestroyed();
106     void removeBufferView(int bufferViewConfigId);
107     void messagesInserted(const QModelIndex &parent, int start, int end);
108     void showAboutDlg();
109     void showChannelList(NetworkId netId = NetworkId());
110     void startInternalCore();
111     void showCoreConnectionDlg(bool autoConnect = false);
112     void showCoreInfoDlg();
113     void showAwayLog();
114     void showSettingsDlg();
115     void showNotificationsDlg();
116 #ifdef HAVE_KDE
117     void showShortcutsDlg();
118 #endif
119     void on_actionConfigureNetworks_triggered();
120     void on_actionConfigureViews_triggered();
121     void on_actionLockLayout_toggled(bool lock);
122     void on_actionDebugNetworkModel_triggered();
123     void on_actionDebugMessageModel_triggered();
124     void on_actionDebugLog_triggered();
125
126     void clientNetworkCreated(NetworkId);
127     void clientNetworkRemoved(NetworkId);
128     void clientNetworkUpdated();
129     void connectOrDisconnectFromNet();
130
131     void saveStatusBarStatus(bool enabled);
132
133     void loadLayout();
134     void saveLayout();
135
136   signals:
137     void connectToCore(const QVariantMap &connInfo);
138     void disconnectFromCore();
139
140   private:
141 #ifdef HAVE_KDE
142     KHelpMenu *_kHelpMenu;
143 #endif
144
145     QLabel *coreLagLabel;
146     QLabel *sslLabel;
147     MsgProcessorStatusWidget *msgProcessorStatusWidget;
148
149     TitleSetter _titleSetter;
150
151     void setupActions();
152     void setupBufferWidget();
153     void setupMenus();
154     void setupNickWidget();
155     void setupChatMonitor();
156     void setupInputWidget();
157     void setupTopicWidget();
158     void setupStatusBar();
159     void setupSystray();
160     void setupTitleSetter();
161     void setupToolBars();
162
163     void updateIcon();
164     void enableMenus();
165
166     void hideToTray();
167
168     SystemTray *_systemTray;
169
170     QList<BufferViewDock *> _bufferViews;
171     BufferWidget *_bufferWidget;
172     NickListWidget *_nickListWidget;
173     InputWidget *_inputWidget;
174
175     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
176     QMenu *_toolbarMenu;
177     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
178
179     QWidget *_awayLog;
180     friend class QtUi;
181
182 #ifdef Q_WS_WIN
183     DWORD dwTickCount;
184 #endif
185 };
186
187 SystemTray *MainWin::systemTray() const {
188   return _systemTray;
189 }
190
191 #endif