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