common: Port remote nicks to NickHighlightMatcher
[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     void onExitRequested(const QString &reason);
104
105     //! Quit application
106     void quit();
107
108 protected:
109     void closeEvent(QCloseEvent *event);
110     void moveEvent(QMoveEvent *event);
111     void resizeEvent(QResizeEvent *event);
112
113 protected slots:
114     void connectedToCore();
115     void setConnectedState();
116     void disconnectedFromCore();
117     void setDisconnectedState();
118
119 private slots:
120     void addBufferView(int bufferViewConfigId);
121     void awayLogDestroyed();
122     void removeBufferView(int bufferViewConfigId);
123     void currentBufferChanged(BufferId);
124     void messagesInserted(const QModelIndex &parent, int start, int end);
125     void showAboutDlg();
126
127     /**
128      * Show the channel list dialog for the network, optionally searching by channel name
129      *
130      * @param networkId        Network ID for associated network
131      * @param channelFilters   Partial channel name to search for, or empty to show all
132      * @param listImmediately  If true, immediately list channels, otherwise just show dialog
133      */
134     void showChannelList(NetworkId netId = {}, const QString &channelFilters = {},
135                          bool listImmediately = false);
136
137     void showNetworkConfig(NetworkId netId = NetworkId());
138     void showCoreConnectionDlg();
139     void showCoreConfigWizard(const QVariantList &, const QVariantList &);
140     void showCoreInfoDlg();
141     void showAwayLog();
142     void showSettingsDlg();
143     void showNotificationsDlg();
144     void showIgnoreList(QString newRule = QString());
145     void showShortcutsDlg();
146     void showPasswordChangeDlg();
147     void showNewTransferDlg(const QUuid &transferId);
148     void onFullScreenToggled();
149
150     void doAutoConnect();
151
152     void handleCoreConnectionError(const QString &errorMsg);
153     void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage);
154     void handleNoSslInClient(bool *accepted);
155     void handleNoSslInCore(bool *accepted);
156 #ifdef HAVE_SSL
157     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
158 #endif
159
160     void on_actionConfigureNetworks_triggered();
161     void on_actionConfigureViews_triggered();
162     void on_actionLockLayout_toggled(bool lock);
163
164     /**
165      * Apply the active color to the input widget selected or typed text
166      *
167      * @seealso InputWidget::applyFormatActiveColor()
168      */
169     void on_inputFormatApplyColor_triggered();
170
171     /**
172      * Apply the active fill color to the input widget selected or typed text background
173      *
174      * @seealso InputWidget::applyFormatActiveColorFill()
175      */
176     void on_inputFormatApplyColorFill_triggered();
177
178     /**
179      * Toggle the boldness of the input widget selected or typed text
180      *
181      * @seealso InputWidget::toggleFormatBold()
182      */
183     void on_inputFormatBold_triggered();
184
185     /**
186      * Toggle the italicness of the input widget selected or typed text
187      *
188      * @seealso InputWidget::toggleFormatItalic()
189      */
190     void on_inputFormatItalic_triggered();
191
192     /**
193      * Toggle the underlining of the input widget selected or typed text
194      *
195      * @seealso InputWidget::toggleFormatUnderline()
196      */
197     void on_inputFormatUnderline_triggered();
198
199     /**
200      * Clear the formatting of the input widget selected or typed text
201      *
202      * @seealso InputWidget::clearFormat()
203      */
204     void on_inputFormatClear_triggered();
205
206     void on_jumpHotBuffer_triggered();
207     void on_bufferSearch_triggered();
208     void on_actionDebugNetworkModel_triggered();
209     void on_actionDebugBufferViewOverlay_triggered();
210     void on_actionDebugMessageModel_triggered();
211     void on_actionDebugHotList_triggered();
212     void on_actionDebugLog_triggered();
213
214     void bindJumpKey();
215     void onJumpKey();
216
217     void clientNetworkCreated(NetworkId);
218     void clientNetworkRemoved(NetworkId);
219     void clientNetworkUpdated();
220     void connectOrDisconnectFromNet();
221
222     void saveMenuBarStatus(bool enabled);
223     void saveStatusBarStatus(bool enabled);
224     void saveMainToolBarStatus(bool enabled);
225
226     void loadLayout();
227     void saveLayout();
228
229     void bufferViewToggled(bool enabled);
230     void bufferViewVisibilityChanged(bool visible);
231     void changeActiveBufferView(bool backwards);
232     void changeActiveBufferView(int bufferViewId);
233
234 signals:
235     void connectToCore(const QVariantMap &connInfo);
236     void disconnectFromCore();
237
238 private:
239 #ifdef HAVE_KDE
240     KHelpMenu *_kHelpMenu;
241 #endif
242
243     MsgProcessorStatusWidget *_msgProcessorStatusWidget;
244     CoreConnectionStatusWidget *_coreConnectionStatusWidget;
245     SystemTray *_systemTray;
246
247     TitleSetter _titleSetter;
248
249     void setupActions();
250     void setupBufferWidget();
251     void setupMenus();
252     void setupNickWidget();
253     void setupChatMonitor();
254     void setupInputWidget();
255     void setupTopicWidget();
256     void setupTransferWidget();
257     void setupViewMenuTail();
258     void setupStatusBar();
259     void setupSystray();
260     void setupTitleSetter();
261     void setupToolBars();
262     void setupHotList();
263
264     void updateIcon();
265     void enableMenus();
266
267     QList<BufferViewDock *> _bufferViews;
268     BufferWidget *_bufferWidget;
269     NickListWidget *_nickListWidget;
270     InputWidget *_inputWidget;
271     ChatMonitorView *_chatMonitorView;
272     TopicWidget *_topicWidget;
273
274     QAction *_fullScreenAction;
275     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
276     QMenu *_toolbarMenu;
277     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
278
279     QWidget *_awayLog;
280
281     QMessageBox* _migrationWarning{nullptr};
282
283     bool _layoutLoaded;
284
285     QSize _normalSize; //!< Size of the non-maximized window
286     QPoint _normalPos; //!< Position of the non-maximized window
287
288     BufferHotListFilter *_bufferHotList;
289     QHash<int, BufferId> _jumpKeyMap;
290     int _activeBufferViewIndex;
291
292     bool _aboutToQuit; //closeEvent can occur multiple times on OSX
293
294     friend class QtUi;
295 };