476db5116b55371ae04027ab7105882dcbfe27ed
[quassel.git] / src / qtui / mainwin.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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 #include <QUuid>
24
25 #ifdef HAVE_KDE4
26 #  include <KMainWindow>
27 #elif defined HAVE_KF5
28 #  include <KXmlGui/KMainWindow>
29 #else
30 #  include <QMainWindow>
31 #endif
32
33 #include "qtui.h"
34 #include "titlesetter.h"
35 #include "uisettings.h"
36
37 class ActionCollection;
38 class BufferHotListFilter;
39 class BufferView;
40 class BufferViewConfig;
41 class ChatMonitorView;
42 class ClientBufferViewConfig;
43 class CoreAccount;
44 class CoreConnectionStatusWidget;
45 class BufferViewDock;
46 class BufferWidget;
47 class InputWidget;
48 class MsgProcessorStatusWidget;
49 class NickListWidget;
50 class SystemTray;
51 class TopicWidget;
52
53 class QLabel;
54 class QMenu;
55 class QMessageBox;
56 class QToolBar;
57
58 class KHelpMenu;
59
60 //!\brief The main window of Quassel's QtUi.
61 class MainWin
62 #ifdef HAVE_KDE
63     : public KMainWindow {
64 #else
65     : public QMainWindow {
66 #endif
67     Q_OBJECT
68
69 public:
70     MainWin(QWidget *parent = 0);
71     virtual ~MainWin();
72
73     void init();
74
75     void addBufferView(ClientBufferViewConfig *config);
76     BufferView *allBuffersView() const;
77     BufferView *activeBufferView() const;
78
79     inline BufferWidget *bufferWidget() const { return _bufferWidget; }
80     inline SystemTray *systemTray() const { return _systemTray; }
81
82     bool event(QEvent *event);
83
84     static void flagRemoteCoreOnly(QObject *object) { object->setProperty("REMOTE_CORE_ONLY", true); }
85     static bool isRemoteCoreOnly(QObject *object) { return object->property("REMOTE_CORE_ONLY").toBool(); }
86
87     void saveStateToSettings(UiSettings &);
88     void restoreStateFromSettings(UiSettings &);
89
90     // We need to override this to add the show/hide menu bar option
91     virtual QMenu *createPopupMenu();
92
93 public slots:
94     void showStatusBarMessage(const QString &message);
95     void hideCurrentBuffer();
96     void nextBufferView();     //!< Activate the next bufferview
97     void previousBufferView(); //!< Activate the previous bufferview
98     void nextBuffer();
99     void previousBuffer();
100
101     void showMigrationWarning(bool show);
102
103     //! Quit application
104     void quit();
105
106 protected:
107     void closeEvent(QCloseEvent *event);
108     void moveEvent(QMoveEvent *event);
109     void resizeEvent(QResizeEvent *event);
110
111 protected slots:
112     void connectedToCore();
113     void setConnectedState();
114     void disconnectedFromCore();
115     void setDisconnectedState();
116
117 private slots:
118     void addBufferView(int bufferViewConfigId);
119     void awayLogDestroyed();
120     void removeBufferView(int bufferViewConfigId);
121     void currentBufferChanged(BufferId);
122     void messagesInserted(const QModelIndex &parent, int start, int end);
123     void showAboutDlg();
124
125     /**
126      * Show the channel list dialog for the network, optionally searching by channel name
127      *
128      * @param networkId        Network ID for associated network
129      * @param channelFilters   Partial channel name to search for, or empty to show all
130      * @param listImmediately  If true, immediately list channels, otherwise just show dialog
131      */
132     void showChannelList(NetworkId netId = {}, const QString &channelFilters = {},
133                          bool listImmediately = false);
134
135     void showNetworkConfig(NetworkId netId = NetworkId());
136     void showCoreConnectionDlg();
137     void showCoreConfigWizard(const QVariantList &, const QVariantList &);
138     void showCoreInfoDlg();
139     void showAwayLog();
140     void showSettingsDlg();
141     void showNotificationsDlg();
142     void showIgnoreList(QString newRule = QString());
143     void showShortcutsDlg();
144     void showPasswordChangeDlg();
145     void showNewTransferDlg(const QUuid &transferId);
146     void onFullScreenToggled();
147
148     void doAutoConnect();
149
150     void handleCoreConnectionError(const QString &errorMsg);
151     void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage);
152     void handleNoSslInClient(bool *accepted);
153     void handleNoSslInCore(bool *accepted);
154 #ifdef HAVE_SSL
155     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
156 #endif
157
158     void on_actionConfigureNetworks_triggered();
159     void on_actionConfigureViews_triggered();
160     void on_actionLockLayout_toggled(bool lock);
161
162     /**
163      * Apply the active color to the input widget selected or typed text
164      *
165      * @seealso InputWidget::applyFormatActiveColor()
166      */
167     void on_inputFormatApplyColor_triggered();
168
169     /**
170      * Apply the active fill color to the input widget selected or typed text background
171      *
172      * @seealso InputWidget::applyFormatActiveColorFill()
173      */
174     void on_inputFormatApplyColorFill_triggered();
175
176     /**
177      * Toggle the boldness of the input widget selected or typed text
178      *
179      * @seealso InputWidget::toggleFormatBold()
180      */
181     void on_inputFormatBold_triggered();
182
183     /**
184      * Toggle the italicness of the input widget selected or typed text
185      *
186      * @seealso InputWidget::toggleFormatItalic()
187      */
188     void on_inputFormatItalic_triggered();
189
190     /**
191      * Toggle the underlining of the input widget selected or typed text
192      *
193      * @seealso InputWidget::toggleFormatUnderline()
194      */
195     void on_inputFormatUnderline_triggered();
196
197     /**
198      * Clear the formatting of the input widget selected or typed text
199      *
200      * @seealso InputWidget::clearFormat()
201      */
202     void on_inputFormatClear_triggered();
203
204     void on_jumpHotBuffer_triggered();
205     void on_bufferSearch_triggered();
206     void on_actionDebugNetworkModel_triggered();
207     void on_actionDebugBufferViewOverlay_triggered();
208     void on_actionDebugMessageModel_triggered();
209     void on_actionDebugHotList_triggered();
210     void on_actionDebugLog_triggered();
211
212     void bindJumpKey();
213     void onJumpKey();
214
215     void clientNetworkCreated(NetworkId);
216     void clientNetworkRemoved(NetworkId);
217     void clientNetworkUpdated();
218     void connectOrDisconnectFromNet();
219
220     void saveMenuBarStatus(bool enabled);
221     void saveStatusBarStatus(bool enabled);
222     void saveMainToolBarStatus(bool enabled);
223
224     void loadLayout();
225     void saveLayout();
226
227     void bufferViewToggled(bool enabled);
228     void bufferViewVisibilityChanged(bool visible);
229     void changeActiveBufferView(bool backwards);
230     void changeActiveBufferView(int bufferViewId);
231
232 signals:
233     void connectToCore(const QVariantMap &connInfo);
234     void disconnectFromCore();
235
236 private:
237 #ifdef HAVE_KDE
238     KHelpMenu *_kHelpMenu;
239 #endif
240
241     MsgProcessorStatusWidget *_msgProcessorStatusWidget;
242     CoreConnectionStatusWidget *_coreConnectionStatusWidget;
243     SystemTray *_systemTray;
244
245     TitleSetter _titleSetter;
246
247     void setupActions();
248     void setupBufferWidget();
249     void setupMenus();
250     void setupNickWidget();
251     void setupChatMonitor();
252     void setupInputWidget();
253     void setupTopicWidget();
254     void setupTransferWidget();
255     void setupViewMenuTail();
256     void setupStatusBar();
257     void setupSystray();
258     void setupTitleSetter();
259     void setupToolBars();
260     void setupHotList();
261
262     void updateIcon();
263     void enableMenus();
264
265     QList<BufferViewDock *> _bufferViews;
266     BufferWidget *_bufferWidget;
267     NickListWidget *_nickListWidget;
268     InputWidget *_inputWidget;
269     ChatMonitorView *_chatMonitorView;
270     TopicWidget *_topicWidget;
271
272     QAction *_fullScreenAction;
273     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
274     QMenu *_toolbarMenu;
275     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
276
277     QWidget *_awayLog;
278
279     QMessageBox* _migrationWarning{nullptr};
280
281     bool _layoutLoaded;
282
283     QSize _normalSize; //!< Size of the non-maximized window
284     QPoint _normalPos; //!< Position of the non-maximized window
285
286     BufferHotListFilter *_bufferHotList;
287     QHash<int, BufferId> _jumpKeyMap;
288     int _activeBufferViewIndex;
289
290     bool _aboutToQuit; //closeEvent can occur multiple times on OSX
291
292     friend class QtUi;
293 };