Don't quit when the last window is closed (could still be running in systray...)
[quassel.git] / src / qtui / mainwin.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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 #include <QMainWindow>
25 #include <QSystemTrayIcon>
26
27 #include "qtui.h"
28 #include "sessionsettings.h"
29 #include "titlesetter.h"
30
31 class ActionCollection;
32 class BufferViewConfig;
33 class BufferWidget;
34 class MsgProcessorStatusWidget;
35 class NickListWidget;
36 class SystemTrayIcon;
37
38 class QMenu;
39 class QLabel;
40
41 //!\brief The main window of Quassel's QtUi.
42 class MainWin : public QMainWindow {
43   Q_OBJECT
44
45   public:
46     MainWin(QWidget *parent = 0);
47     virtual ~MainWin();
48
49     void init();
50
51     void addBufferView(BufferViewConfig *config = 0);
52
53     inline QSystemTrayIcon *systemTrayIcon() const;
54
55     virtual bool event(QEvent *event);
56   public slots:
57     void saveStateToSession(const QString &sessionId);
58     void saveStateToSessionSettings(SessionSettings &s);
59     void showStatusBarMessage(const QString &message);
60
61   protected:
62     void closeEvent(QCloseEvent *event);
63     virtual void changeEvent(QEvent *event);
64
65   protected slots:
66     void connectedToCore();
67     void setConnectedState();
68     void updateLagIndicator(int lag);
69     void securedConnection();
70     void disconnectedFromCore();
71     void setDisconnectedState();
72     void systrayActivated(QSystemTrayIcon::ActivationReason);
73
74   private slots:
75     void addBufferView(int bufferViewConfigId);
76     void removeBufferView(int bufferViewConfigId);
77     void messagesInserted(const QModelIndex &parent, int start, int end);
78     void showAboutDlg();
79     void showChannelList(NetworkId netId = NetworkId());
80     void showCoreConnectionDlg(bool autoConnect = false);
81     void showCoreInfoDlg();
82     void showSettingsDlg();
83     void on_actionEditNetworks_triggered();
84     void on_actionManageViews_triggered();
85     void on_actionLockDockPositions_toggled(bool lock);
86     void on_actionDebugNetworkModel_triggered();
87     void on_actionDebugMessageModel_triggered();
88     void on_actionDebugLog_triggered();
89
90     void clientNetworkCreated(NetworkId);
91     void clientNetworkRemoved(NetworkId);
92     void clientNetworkUpdated();
93     void connectOrDisconnectFromNet();
94
95     void saveStatusBarStatus(bool enabled);
96
97     void loadLayout();
98     void saveLayout();
99
100   signals:
101     void connectToCore(const QVariantMap &connInfo);
102     void disconnectFromCore();
103
104   private:
105
106     QMenu *systrayMenu;
107     QLabel *coreLagLabel;
108     QLabel *sslLabel;
109     MsgProcessorStatusWidget *msgProcessorStatusWidget;
110
111     TitleSetter _titleSetter;
112
113     void setupActions();
114     void setupBufferWidget();
115     void setupMenus();
116     void setupViews();
117     void setupNickWidget();
118     void setupChatMonitor();
119     void setupInputWidget();
120     void setupTopicWidget();
121     void setupStatusBar();
122     void setupSystray();
123     void setupTitleSetter();
124
125     void updateIcon();
126     void toggleVisibility();
127     void enableMenus();
128
129     QSystemTrayIcon *_trayIcon;
130
131     QList<QDockWidget *> _netViews;
132     BufferWidget *_bufferWidget;
133     NickListWidget *_nickListWidget;
134
135     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
136
137     friend class QtUi;
138 };
139
140 QSystemTrayIcon *MainWin::systemTrayIcon() const {
141   return _trayIcon;
142 }
143
144 #endif