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