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