InputLine now regains focus on keypress
[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 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     inline BufferWidget *bufferWidget() const;
71
72     virtual bool event(QEvent *event);
73
74     static void flagRemoteCoreOnly(QObject *object) { object->setProperty("REMOTE_CORE_ONLY", true); }
75     static bool isRemoteCoreOnly(QObject *object) { return object->property("REMOTE_CORE_ONLY").toBool(); }
76
77   public slots:
78     void saveStateToSession(const QString &sessionId);
79     void saveStateToSessionSettings(SessionSettings &s);
80     void showStatusBarMessage(const QString &message);
81
82   protected:
83     void closeEvent(QCloseEvent *event);
84     virtual void changeEvent(QEvent *event);
85
86   protected slots:
87     void connectedToCore();
88     void setConnectedState();
89     void updateLagIndicator(int lag);
90     void securedConnection();
91     void disconnectedFromCore();
92     void setDisconnectedState();
93     void systrayActivated(QSystemTrayIcon::ActivationReason);
94
95   private slots:
96     void addBufferView(int bufferViewConfigId);
97     void removeBufferView(int bufferViewConfigId);
98     void messagesInserted(const QModelIndex &parent, int start, int end);
99     void showAboutDlg();
100     void showChannelList(NetworkId netId = NetworkId());
101     void startInternalCore();
102     void showCoreConnectionDlg(bool autoConnect = false);
103     void showCoreInfoDlg();
104     void showSettingsDlg();
105     void showNotificationsDlg();
106 #ifdef HAVE_KDE
107     void showShortcutsDlg();
108 #endif
109     void on_actionConfigureNetworks_triggered();
110     void on_actionConfigureViews_triggered();
111     void on_actionLockDockPositions_toggled(bool lock);
112     void on_actionDebugNetworkModel_triggered();
113     void on_actionDebugMessageModel_triggered();
114     void on_actionDebugLog_triggered();
115
116     void clientNetworkCreated(NetworkId);
117     void clientNetworkRemoved(NetworkId);
118     void clientNetworkUpdated();
119     void connectOrDisconnectFromNet();
120
121     void saveStatusBarStatus(bool enabled);
122
123     void loadLayout();
124     void saveLayout();
125
126   signals:
127     void connectToCore(const QVariantMap &connInfo);
128     void disconnectFromCore();
129
130   private:
131 #ifdef HAVE_KDE
132     KHelpMenu *_kHelpMenu;
133 #endif
134
135     QMenu *systrayMenu;
136     QLabel *coreLagLabel;
137     QLabel *sslLabel;
138     MsgProcessorStatusWidget *msgProcessorStatusWidget;
139
140     TitleSetter _titleSetter;
141
142     void setupActions();
143     void setupBufferWidget();
144     void setupMenus();
145     void setupNickWidget();
146     void setupChatMonitor();
147     void setupInputWidget();
148     void setupTopicWidget();
149     void setupStatusBar();
150     void setupSystray();
151     void setupTitleSetter();
152
153     void updateIcon();
154     void toggleVisibility();
155     void enableMenus();
156
157     QSystemTrayIcon *_trayIcon;
158
159     QList<BufferViewDock *> _bufferViews;
160     BufferWidget *_bufferWidget;
161     NickListWidget *_nickListWidget;
162     InputWidget *_inputWidget;
163
164     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
165
166     friend class QtUi;
167 };
168
169 QSystemTrayIcon *MainWin::systemTrayIcon() const {
170   return _trayIcon;
171 }
172
173 BufferWidget *MainWin::bufferWidget() const {
174   return _bufferWidget;
175 }
176
177 #endif