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