96a4254445138ab225d48963bd73247de90ee83d
[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 showNotificationsDlg();
99     void on_actionEditNetworks_triggered();
100     void on_actionManageViews_triggered();
101     void on_actionLockDockPositions_toggled(bool lock);
102     void on_actionDebugNetworkModel_triggered();
103     void on_actionDebugMessageModel_triggered();
104     void on_actionDebugLog_triggered();
105
106     void clientNetworkCreated(NetworkId);
107     void clientNetworkRemoved(NetworkId);
108     void clientNetworkUpdated();
109     void connectOrDisconnectFromNet();
110
111     void saveStatusBarStatus(bool enabled);
112
113     void loadLayout();
114     void saveLayout();
115
116   signals:
117     void connectToCore(const QVariantMap &connInfo);
118     void disconnectFromCore();
119
120   private:
121 #ifdef HAVE_KDE
122     KHelpMenu *_kHelpMenu;
123 #endif
124
125     QMenu *systrayMenu;
126     QLabel *coreLagLabel;
127     QLabel *sslLabel;
128     MsgProcessorStatusWidget *msgProcessorStatusWidget;
129
130     TitleSetter _titleSetter;
131
132     void setupActions();
133     void setupBufferWidget();
134     void setupMenus();
135     void setupViews();
136     void setupNickWidget();
137     void setupChatMonitor();
138     void setupInputWidget();
139     void setupTopicWidget();
140     void setupStatusBar();
141     void setupSystray();
142     void setupTitleSetter();
143
144     void updateIcon();
145     void toggleVisibility();
146     void enableMenus();
147
148     QSystemTrayIcon *_trayIcon;
149
150     QList<BufferViewDock *> _bufferViews;
151     BufferWidget *_bufferWidget;
152     NickListWidget *_nickListWidget;
153
154     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
155
156     friend class QtUi;
157 };
158
159 QSystemTrayIcon *MainWin::systemTrayIcon() const {
160   return _trayIcon;
161 }
162
163 #endif