Greatly simplify TransferManager API and implementation
[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 #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 public slots:
90     void showStatusBarMessage(const QString &message);
91     void hideCurrentBuffer();
92     void nextBufferView();     //!< Activate the next bufferview
93     void previousBufferView(); //!< Activate the previous bufferview
94     void nextBuffer();
95     void previousBuffer();
96
97     //! Quit application
98     void quit();
99
100 protected:
101     void closeEvent(QCloseEvent *event);
102     void moveEvent(QMoveEvent *event);
103     void resizeEvent(QResizeEvent *event);
104
105 protected slots:
106     void connectedToCore();
107     void setConnectedState();
108     void disconnectedFromCore();
109     void setDisconnectedState();
110
111 private slots:
112     void addBufferView(int bufferViewConfigId);
113     void awayLogDestroyed();
114     void removeBufferView(int bufferViewConfigId);
115     void currentBufferChanged(BufferId);
116     void messagesInserted(const QModelIndex &parent, int start, int end);
117     void showAboutDlg();
118     void showChannelList(NetworkId netId = NetworkId());
119     void showCoreConnectionDlg();
120     void showCoreConfigWizard(const QVariantList &);
121     void showCoreInfoDlg();
122     void showAwayLog();
123     void showSettingsDlg();
124     void showNotificationsDlg();
125     void showIgnoreList(QString newRule = QString());
126     void showShortcutsDlg();
127     void showPasswordChangeDlg();
128     void showNewTransferDlg(const QUuid &transferId);
129     void onFullScreenToggled();
130
131     void handleCoreConnectionError(const QString &errorMsg);
132     void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage);
133     void handleNoSslInClient(bool *accepted);
134     void handleNoSslInCore(bool *accepted);
135 #ifdef HAVE_SSL
136     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
137 #endif
138
139     void on_actionConfigureNetworks_triggered();
140     void on_actionConfigureViews_triggered();
141     void on_actionLockLayout_toggled(bool lock);
142     void on_jumpHotBuffer_triggered();
143     void on_actionDebugNetworkModel_triggered();
144     void on_actionDebugBufferViewOverlay_triggered();
145     void on_actionDebugMessageModel_triggered();
146     void on_actionDebugHotList_triggered();
147     void on_actionDebugLog_triggered();
148
149     void bindJumpKey();
150     void onJumpKey();
151
152     void clientNetworkCreated(NetworkId);
153     void clientNetworkRemoved(NetworkId);
154     void clientNetworkUpdated();
155     void connectOrDisconnectFromNet();
156
157     void saveMenuBarStatus(bool enabled);
158     void saveStatusBarStatus(bool enabled);
159     void saveMainToolBarStatus(bool enabled);
160
161     void loadLayout();
162     void saveLayout();
163
164     void bufferViewToggled(bool enabled);
165     void bufferViewVisibilityChanged(bool visible);
166     void changeActiveBufferView(bool backwards);
167     void changeActiveBufferView(int bufferViewId);
168
169 signals:
170     void connectToCore(const QVariantMap &connInfo);
171     void disconnectFromCore();
172
173 private:
174 #ifdef HAVE_KDE
175     KHelpMenu *_kHelpMenu;
176 #endif
177
178     MsgProcessorStatusWidget *_msgProcessorStatusWidget;
179     CoreConnectionStatusWidget *_coreConnectionStatusWidget;
180     SystemTray *_systemTray;
181
182     TitleSetter _titleSetter;
183
184     void setupActions();
185     void setupBufferWidget();
186     void setupMenus();
187     void setupNickWidget();
188     void setupChatMonitor();
189     void setupInputWidget();
190     void setupTopicWidget();
191     void setupViewMenuTail();
192     void setupStatusBar();
193     void setupSystray();
194     void setupTitleSetter();
195     void setupToolBars();
196     void setupHotList();
197
198     void updateIcon();
199     void enableMenus();
200
201     QList<BufferViewDock *> _bufferViews;
202     BufferWidget *_bufferWidget;
203     NickListWidget *_nickListWidget;
204     InputWidget *_inputWidget;
205     ChatMonitorView *_chatMonitorView;
206     TopicWidget *_topicWidget;
207
208     QAction *_fullScreenAction;
209     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
210     QMenu *_toolbarMenu;
211     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
212
213     QWidget *_awayLog;
214
215     bool _layoutLoaded;
216
217     QSize _normalSize; //!< Size of the non-maximized window
218     QPoint _normalPos; //!< Position of the non-maximized window
219
220     BufferHotListFilter *_bufferHotList;
221     QHash<int, BufferId> _jumpKeyMap;
222     int _activeBufferViewIndex;
223
224     friend class QtUi;
225 };