Add rudimentary keyboard navigation for previous/next buffer
[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 "qtui.h"
31 #include "titlesetter.h"
32 #include "uisettings.h"
33
34 class ActionCollection;
35 class BufferHotListFilter;
36 class BufferView;
37 class BufferViewConfig;
38 class ClientBufferViewConfig;
39 class CoreAccount;
40 class CoreConnectionStatusWidget;
41 class BufferViewDock;
42 class BufferWidget;
43 class InputWidget;
44 class MsgProcessorStatusWidget;
45 class NickListWidget;
46 class SystemTray;
47 class ChatMonitorView;
48 class TopicWidget;
49
50 class QMenu;
51 class QLabel;
52 class QToolBar;
53
54 class KHelpMenu;
55
56 //!\brief The main window of Quassel's QtUi.
57 class MainWin
58 #ifdef HAVE_KDE
59 : public KMainWindow {
60 #else
61 : public QMainWindow {
62 #endif
63   Q_OBJECT
64
65   public:
66     MainWin(QWidget *parent = 0);
67     virtual ~MainWin();
68
69     void init();
70
71     void addBufferView(ClientBufferViewConfig *config);
72     BufferView *allBuffersView() const;
73     BufferView *activeBufferView() const;
74
75     inline BufferWidget *bufferWidget() const { return _bufferWidget; }
76     inline SystemTray *systemTray() const { return _systemTray; }
77
78     bool event(QEvent *event);
79
80     static void flagRemoteCoreOnly(QObject *object) { object->setProperty("REMOTE_CORE_ONLY", true); }
81     static bool isRemoteCoreOnly(QObject *object) { return object->property("REMOTE_CORE_ONLY").toBool(); }
82
83     void saveStateToSettings(UiSettings &);
84     void restoreStateFromSettings(UiSettings &);
85
86   public slots:
87     void showStatusBarMessage(const QString &message);
88     void nextBufferView();     //!< Activate the next bufferview
89     void previousBufferView(); //!< Activate the previous bufferview
90     void nextBuffer();
91     void previousBuffer();
92
93     //! Quit application
94     void quit();
95
96   protected:
97     void closeEvent(QCloseEvent *event);
98     void moveEvent(QMoveEvent *event);
99     void resizeEvent(QResizeEvent *event);
100
101   protected slots:
102     void connectedToCore();
103     void setConnectedState();
104     void disconnectedFromCore();
105     void setDisconnectedState();
106
107   private slots:
108     void addBufferView(int bufferViewConfigId);
109     void awayLogDestroyed();
110     void removeBufferView(int bufferViewConfigId);
111     void currentBufferChanged(BufferId);
112     void messagesInserted(const QModelIndex &parent, int start, int end);
113     void showAboutDlg();
114     void showChannelList(NetworkId netId = NetworkId());
115     void showCoreConnectionDlg();
116     void showCoreConfigWizard(const QVariantList &);
117     void showCoreInfoDlg();
118     void showAwayLog();
119     void showSettingsDlg();
120     void showNotificationsDlg();
121     void showIgnoreList(QString newRule = QString());
122     void showShortcutsDlg();
123
124     void handleCoreConnectionError(const QString &errorMsg);
125     void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage);
126     void handleNoSslInClient(bool *accepted);
127     void handleNoSslInCore(bool *accepted);
128 #ifdef HAVE_SSL
129     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
130 #endif
131
132     void on_actionConfigureNetworks_triggered();
133     void on_actionConfigureViews_triggered();
134     void on_actionLockLayout_toggled(bool lock);
135     void on_jumpHotBuffer_triggered();
136     void on_actionDebugNetworkModel_triggered();
137     void on_actionDebugBufferViewOverlay_triggered();
138     void on_actionDebugMessageModel_triggered();
139     void on_actionDebugHotList_triggered();
140     void on_actionDebugLog_triggered();
141
142     void bindJumpKey();
143     void onJumpKey();
144
145     void clientNetworkCreated(NetworkId);
146     void clientNetworkRemoved(NetworkId);
147     void clientNetworkUpdated();
148     void connectOrDisconnectFromNet();
149
150     void saveMenuBarStatus(bool enabled);
151     void saveStatusBarStatus(bool enabled);
152
153     void loadLayout();
154     void saveLayout();
155
156     void bufferViewToggled(bool enabled);
157     void bufferViewVisibilityChanged(bool visible);
158     void changeActiveBufferView(bool backwards);
159     void changeActiveBufferView(int bufferViewId);
160
161   signals:
162     void connectToCore(const QVariantMap &connInfo);
163     void disconnectFromCore();
164
165   private:
166 #ifdef HAVE_KDE
167     KHelpMenu *_kHelpMenu;
168 #endif
169
170     MsgProcessorStatusWidget *_msgProcessorStatusWidget;
171     CoreConnectionStatusWidget *_coreConnectionStatusWidget;
172     SystemTray *_systemTray;
173
174     TitleSetter _titleSetter;
175
176     void setupActions();
177     void setupBufferWidget();
178     void setupMenus();
179     void setupNickWidget();
180     void setupChatMonitor();
181     void setupInputWidget();
182     void setupTopicWidget();
183     void setupStatusBar();
184     void setupSystray();
185     void setupTitleSetter();
186     void setupToolBars();
187     void setupHotList();
188
189     void updateIcon();
190     void enableMenus();
191
192     QList<BufferViewDock *> _bufferViews;
193     BufferWidget *_bufferWidget;
194     NickListWidget *_nickListWidget;
195     InputWidget *_inputWidget;
196     ChatMonitorView *_chatMonitorView;
197     TopicWidget *_topicWidget;
198
199     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
200     QMenu *_toolbarMenu;
201     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
202
203     QWidget *_awayLog;
204
205     bool _layoutLoaded;
206
207     QSize _normalSize; //!< Size of the non-maximized window
208     QPoint _normalPos; //!< Position of the non-maximized window
209
210     BufferHotListFilter *_bufferHotList;
211     QHash<int, BufferId> _jumpKeyMap;
212     int _activeBufferViewIndex;
213
214     friend class QtUi;
215 };
216
217 #endif