Enable Breeze on Appveyor
[quassel.git] / src / qtui / mainwin.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2015 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 #ifdef HAVE_KDE4
24 #  include <KMainWindow>
25 #elif defined 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 ClientBufferViewConfig;
40 class ClientTransfer;
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 ChatMonitorView;
50 class TopicWidget;
51
52 class QMenu;
53 class QLabel;
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 = 0);
69     virtual ~MainWin();
70
71     void init();
72
73     void addBufferView(ClientBufferViewConfig *config);
74     BufferView *allBuffersView() const;
75     BufferView *activeBufferView() const;
76
77     inline BufferWidget *bufferWidget() const { return _bufferWidget; }
78     inline SystemTray *systemTray() const { return _systemTray; }
79
80     bool event(QEvent *event);
81
82     static void flagRemoteCoreOnly(QObject *object) { object->setProperty("REMOTE_CORE_ONLY", true); }
83     static bool isRemoteCoreOnly(QObject *object) { return object->property("REMOTE_CORE_ONLY").toBool(); }
84
85     void saveStateToSettings(UiSettings &);
86     void restoreStateFromSettings(UiSettings &);
87
88     // We need to override this to add the show/hide menu bar option
89     virtual QMenu *createPopupMenu();
90
91 public slots:
92     void showStatusBarMessage(const QString &message);
93     void hideCurrentBuffer();
94     void nextBufferView();     //!< Activate the next bufferview
95     void previousBufferView(); //!< Activate the previous bufferview
96     void nextBuffer();
97     void previousBuffer();
98
99     //! Quit application
100     void quit();
101
102 protected:
103     void closeEvent(QCloseEvent *event);
104     void moveEvent(QMoveEvent *event);
105     void resizeEvent(QResizeEvent *event);
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     void showChannelList(NetworkId netId = NetworkId());
121     void showCoreConnectionDlg();
122     void showCoreConfigWizard(const QVariantList &);
123     void showCoreInfoDlg();
124     void showAwayLog();
125     void showSettingsDlg();
126     void showNotificationsDlg();
127     void showIgnoreList(QString newRule = QString());
128     void showShortcutsDlg();
129     void showPasswordChangeDlg();
130     void showNewTransferDlg(const ClientTransfer *transfer);
131     void onFullScreenToggled();
132
133     void handleCoreConnectionError(const QString &errorMsg);
134     void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage);
135     void handleNoSslInClient(bool *accepted);
136     void handleNoSslInCore(bool *accepted);
137 #ifdef HAVE_SSL
138     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
139 #endif
140
141     void on_actionConfigureNetworks_triggered();
142     void on_actionConfigureViews_triggered();
143     void on_actionLockLayout_toggled(bool lock);
144     void on_jumpHotBuffer_triggered();
145     void on_actionDebugNetworkModel_triggered();
146     void on_actionDebugBufferViewOverlay_triggered();
147     void on_actionDebugMessageModel_triggered();
148     void on_actionDebugHotList_triggered();
149     void on_actionDebugLog_triggered();
150
151     void bindJumpKey();
152     void onJumpKey();
153
154     void clientNetworkCreated(NetworkId);
155     void clientNetworkRemoved(NetworkId);
156     void clientNetworkUpdated();
157     void connectOrDisconnectFromNet();
158
159     void saveMenuBarStatus(bool enabled);
160     void saveStatusBarStatus(bool enabled);
161     void saveMainToolBarStatus(bool enabled);
162
163     void loadLayout();
164     void saveLayout();
165
166     void bufferViewToggled(bool enabled);
167     void bufferViewVisibilityChanged(bool visible);
168     void changeActiveBufferView(bool backwards);
169     void changeActiveBufferView(int bufferViewId);
170
171 signals:
172     void connectToCore(const QVariantMap &connInfo);
173     void disconnectFromCore();
174
175 private:
176 #ifdef HAVE_KDE
177     KHelpMenu *_kHelpMenu;
178 #endif
179
180     MsgProcessorStatusWidget *_msgProcessorStatusWidget;
181     CoreConnectionStatusWidget *_coreConnectionStatusWidget;
182     SystemTray *_systemTray;
183
184     TitleSetter _titleSetter;
185
186     void setupActions();
187     void setupBufferWidget();
188     void setupMenus();
189     void setupNickWidget();
190     void setupChatMonitor();
191     void setupInputWidget();
192     void setupTopicWidget();
193     void setupViewMenuTail();
194     void setupStatusBar();
195     void setupSystray();
196     void setupTitleSetter();
197     void setupToolBars();
198     void setupHotList();
199
200     void updateIcon();
201     void enableMenus();
202
203     QList<BufferViewDock *> _bufferViews;
204     BufferWidget *_bufferWidget;
205     NickListWidget *_nickListWidget;
206     InputWidget *_inputWidget;
207     ChatMonitorView *_chatMonitorView;
208     TopicWidget *_topicWidget;
209
210     QAction *_fullScreenAction;
211     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
212     QMenu *_toolbarMenu;
213     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
214
215     QWidget *_awayLog;
216
217     bool _layoutLoaded;
218
219     QSize _normalSize; //!< Size of the non-maximized window
220     QPoint _normalPos; //!< Position of the non-maximized window
221
222     BufferHotListFilter *_bufferHotList;
223     QHash<int, BufferId> _jumpKeyMap;
224     int _activeBufferViewIndex;
225
226     bool _aboutToQuit; //closeEvent can occur multiple times on OSX
227
228     friend class QtUi;
229 };