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