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