Sanitize topic message
[quassel.git] / src / qtui / mainwin.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2013 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 #ifndef MAINWIN_H_
22 #define MAINWIN_H_
23
24 #ifdef HAVE_KDE
25 #  include <KMainWindow>
26 #else
27 #  include <QMainWindow>
28 #endif
29
30 #include "qtui.h"
31 #include "titlesetter.h"
32 #include "uisettings.h"
33
34 class ActionCollection;
35 class BufferHotListFilter;
36 class BufferView;
37 class BufferViewConfig;
38 class ClientBufferViewConfig;
39 class CoreAccount;
40 class CoreConnectionStatusWidget;
41 class BufferViewDock;
42 class BufferWidget;
43 class InputWidget;
44 class MsgProcessorStatusWidget;
45 class NickListWidget;
46 class SystemTray;
47 class ChatMonitorView;
48 class TopicWidget;
49
50 class QMenu;
51 class QLabel;
52 class QToolBar;
53
54 class KHelpMenu;
55
56 //!\brief The main window of Quassel's QtUi.
57 class MainWin
58 #ifdef HAVE_KDE
59     : public KMainWindow
60 {
61 #else
62 : public QMainWindow {
63 #endif
64     Q_OBJECT
65
66 public:
67     MainWin(QWidget *parent = 0);
68     virtual ~MainWin();
69
70     void init();
71
72     void addBufferView(ClientBufferViewConfig *config);
73     BufferView *allBuffersView() const;
74     BufferView *activeBufferView() const;
75
76     inline BufferWidget *bufferWidget() const { return _bufferWidget; }
77     inline SystemTray *systemTray() const { return _systemTray; }
78
79     bool event(QEvent *event);
80
81     static void flagRemoteCoreOnly(QObject *object) { object->setProperty("REMOTE_CORE_ONLY", true); }
82     static bool isRemoteCoreOnly(QObject *object) { return object->property("REMOTE_CORE_ONLY").toBool(); }
83
84     void saveStateToSettings(UiSettings &);
85     void restoreStateFromSettings(UiSettings &);
86
87 public slots:
88     void showStatusBarMessage(const QString &message);
89     void hideCurrentBuffer();
90     void nextBufferView();     //!< Activate the next bufferview
91     void previousBufferView(); //!< Activate the previous bufferview
92     void nextBuffer();
93     void previousBuffer();
94
95     //! Quit application
96     void quit();
97
98 protected:
99     void closeEvent(QCloseEvent *event);
100     void moveEvent(QMoveEvent *event);
101     void resizeEvent(QResizeEvent *event);
102
103 protected slots:
104     void connectedToCore();
105     void setConnectedState();
106     void disconnectedFromCore();
107     void setDisconnectedState();
108
109 private slots:
110     void addBufferView(int bufferViewConfigId);
111     void awayLogDestroyed();
112     void removeBufferView(int bufferViewConfigId);
113     void currentBufferChanged(BufferId);
114     void messagesInserted(const QModelIndex &parent, int start, int end);
115     void showAboutDlg();
116     void showChannelList(NetworkId netId = NetworkId());
117     void showCoreConnectionDlg();
118     void showCoreConfigWizard(const QVariantList &);
119     void showCoreInfoDlg();
120     void showAwayLog();
121     void showSettingsDlg();
122     void showNotificationsDlg();
123     void showIgnoreList(QString newRule = QString());
124     void showShortcutsDlg();
125     void toggleFullscreen();
126
127     void handleCoreConnectionError(const QString &errorMsg);
128     void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage);
129     void handleNoSslInClient(bool *accepted);
130     void handleNoSslInCore(bool *accepted);
131 #ifdef HAVE_SSL
132     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
133 #endif
134
135     void on_actionConfigureNetworks_triggered();
136     void on_actionConfigureViews_triggered();
137     void on_actionLockLayout_toggled(bool lock);
138     void on_jumpHotBuffer_triggered();
139     void on_actionDebugNetworkModel_triggered();
140     void on_actionDebugBufferViewOverlay_triggered();
141     void on_actionDebugMessageModel_triggered();
142     void on_actionDebugHotList_triggered();
143     void on_actionDebugLog_triggered();
144
145     void bindJumpKey();
146     void onJumpKey();
147
148     void clientNetworkCreated(NetworkId);
149     void clientNetworkRemoved(NetworkId);
150     void clientNetworkUpdated();
151     void connectOrDisconnectFromNet();
152
153     void saveMenuBarStatus(bool enabled);
154     void saveStatusBarStatus(bool enabled);
155
156     void loadLayout();
157     void saveLayout();
158
159     void bufferViewToggled(bool enabled);
160     void bufferViewVisibilityChanged(bool visible);
161     void changeActiveBufferView(bool backwards);
162     void changeActiveBufferView(int bufferViewId);
163
164 signals:
165     void connectToCore(const QVariantMap &connInfo);
166     void disconnectFromCore();
167
168 private:
169 #ifdef HAVE_KDE
170     KHelpMenu *_kHelpMenu;
171 #endif
172
173     MsgProcessorStatusWidget *_msgProcessorStatusWidget;
174     CoreConnectionStatusWidget *_coreConnectionStatusWidget;
175     SystemTray *_systemTray;
176
177     TitleSetter _titleSetter;
178
179     void setupActions();
180     void setupBufferWidget();
181     void setupMenus();
182     void setupNickWidget();
183     void setupChatMonitor();
184     void setupInputWidget();
185     void setupTopicWidget();
186     void setupViewMenuTail();
187     void setupStatusBar();
188     void setupSystray();
189     void setupTitleSetter();
190     void setupToolBars();
191     void setupHotList();
192
193     void updateIcon();
194     void enableMenus();
195
196     QList<BufferViewDock *> _bufferViews;
197     BufferWidget *_bufferWidget;
198     NickListWidget *_nickListWidget;
199     InputWidget *_inputWidget;
200     ChatMonitorView *_chatMonitorView;
201     TopicWidget *_topicWidget;
202
203     QMenu *_fileMenu, *_networksMenu, *_viewMenu, *_bufferViewsMenu, *_settingsMenu, *_helpMenu, *_helpDebugMenu;
204     QMenu *_toolbarMenu;
205     QToolBar *_mainToolBar, *_chatViewToolBar, *_nickToolBar;
206
207     QWidget *_awayLog;
208
209     bool _layoutLoaded;
210
211     QSize _normalSize; //!< Size of the non-maximized window
212     QPoint _normalPos; //!< Position of the non-maximized window
213
214     BufferHotListFilter *_bufferHotList;
215     QHash<int, BufferId> _jumpKeyMap;
216     int _activeBufferViewIndex;
217
218     friend class QtUi;
219 };
220
221
222 #endif