431a30822a0e1473a8fb85b3afd176440c74ad26
[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 QMenu;
54 class QLabel;
55 class QToolBar;
56
57 class KHelpMenu;
58
59 //!\brief The main window of Quassel's QtUi.
60 class MainWin
61 #ifdef HAVE_KDE
62     : public KMainWindow {
63 #else
64     : public QMainWindow {
65 #endif
66     Q_OBJECT
67
68 public:
69     MainWin(QWidget *parent = 0);
70     virtual ~MainWin();
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     //! Quit application
101     void quit();
102
103 protected:
104     void closeEvent(QCloseEvent *event);
105     void moveEvent(QMoveEvent *event);
106     void resizeEvent(QResizeEvent *event);
107
108 protected slots:
109     void connectedToCore();
110     void setConnectedState();
111     void disconnectedFromCore();
112     void setDisconnectedState();
113
114 private slots:
115     void addBufferView(int bufferViewConfigId);
116     void awayLogDestroyed();
117     void removeBufferView(int bufferViewConfigId);
118     void currentBufferChanged(BufferId);
119     void messagesInserted(const QModelIndex &parent, int start, int end);
120     void showAboutDlg();
121     void showChannelList(NetworkId netId = NetworkId());
122     void showNetworkConfig(NetworkId netId = NetworkId());
123     void showCoreConnectionDlg();
124     void showCoreConfigWizard(const QVariantList &, const QVariantList &);
125     void showCoreInfoDlg();
126     void showAwayLog();
127     void showSettingsDlg();
128     void showNotificationsDlg();
129     void showIgnoreList(QString newRule = QString());
130     void showShortcutsDlg();
131     void showPasswordChangeDlg();
132     void showNewTransferDlg(const QUuid &transferId);
133     void onFullScreenToggled();
134
135     void handleCoreConnectionError(const QString &errorMsg);
136     void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage);
137     void handleNoSslInClient(bool *accepted);
138     void handleNoSslInCore(bool *accepted);
139 #ifdef HAVE_SSL
140     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
141 #endif
142
143     void on_actionConfigureNetworks_triggered();
144     void on_actionConfigureViews_triggered();
145     void on_actionLockLayout_toggled(bool lock);
146     void on_jumpHotBuffer_triggered();
147     void on_bufferSearch_triggered();
148     void on_actionDebugNetworkModel_triggered();
149     void on_actionDebugBufferViewOverlay_triggered();
150     void on_actionDebugMessageModel_triggered();
151     void on_actionDebugHotList_triggered();
152     void on_actionDebugLog_triggered();
153
154     void bindJumpKey();
155     void onJumpKey();
156
157     void clientNetworkCreated(NetworkId);
158     void clientNetworkRemoved(NetworkId);
159     void clientNetworkUpdated();
160     void connectOrDisconnectFromNet();
161
162     void saveMenuBarStatus(bool enabled);
163     void saveStatusBarStatus(bool enabled);
164     void saveMainToolBarStatus(bool enabled);
165
166     void loadLayout();
167     void saveLayout();
168
169     void bufferViewToggled(bool enabled);
170     void bufferViewVisibilityChanged(bool visible);
171     void changeActiveBufferView(bool backwards);
172     void changeActiveBufferView(int bufferViewId);
173
174 signals:
175     void connectToCore(const QVariantMap &connInfo);
176     void disconnectFromCore();
177
178 private:
179 #ifdef HAVE_KDE
180     KHelpMenu *_kHelpMenu;
181 #endif
182
183     MsgProcessorStatusWidget *_msgProcessorStatusWidget;
184     CoreConnectionStatusWidget *_coreConnectionStatusWidget;
185     SystemTray *_systemTray;
186
187     TitleSetter _titleSetter;
188
189     void setupActions();
190     void setupBufferWidget();
191     void setupMenus();
192     void setupNickWidget();
193     void setupChatMonitor();
194     void setupInputWidget();
195     void setupTopicWidget();
196     void setupTransferWidget();
197     void setupViewMenuTail();
198     void setupStatusBar();
199     void setupSystray();
200     void setupTitleSetter();
201     void setupToolBars();
202     void setupHotList();
203
204     void updateIcon();
205     void enableMenus();
206
207     QList<BufferViewDock *> _bufferViews;
208     BufferWidget *_bufferWidget;
209     NickListWidget *_nickListWidget;
210     InputWidget *_inputWidget;
211     ChatMonitorView *_chatMonitorView;
212     TopicWidget *_topicWidget;
213
214     QAction *_fullScreenAction;
215     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
216     QMenu *_toolbarMenu;
217     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
218
219     QWidget *_awayLog;
220
221     bool _layoutLoaded;
222
223     QSize _normalSize; //!< Size of the non-maximized window
224     QPoint _normalPos; //!< Position of the non-maximized window
225
226     BufferHotListFilter *_bufferHotList;
227     QHash<int, BufferId> _jumpKeyMap;
228     int _activeBufferViewIndex;
229
230     bool _aboutToQuit; //closeEvent can occur multiple times on OSX
231
232     friend class QtUi;
233 };