4495bfeb3322d67cb7d0a7f0b381e37dc2ee43ad
[quassel.git] / src / qtui / mainwin.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2016 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 #include "mainwin.h"
22
23 #include <QIcon>
24 #include <QMenuBar>
25 #include <QMessageBox>
26 #include <QStatusBar>
27 #include <QTableView>
28 #include <QToolBar>
29 #include <QInputDialog>
30
31 #ifdef HAVE_KDE4
32 #  include <KHelpMenu>
33 #  include <KMenuBar>
34 #  include <KShortcutsDialog>
35 #  include <KStatusBar>
36 #  include <KToggleFullScreenAction>
37 #  include <KToolBar>
38 #endif
39
40 #ifdef HAVE_KF5
41 #  include <KConfigWidgets/KStandardAction>
42 #  include <KXmlGui/KHelpMenu>
43 #  include <KXmlGui/KShortcutsDialog>
44 #  include <KXmlGui/KToolBar>
45 #  include <KWidgetsAddons/KToggleFullScreenAction>
46 #endif
47
48 #ifdef Q_WS_X11
49 #  include <QX11Info>
50 #endif
51
52 #include "aboutdlg.h"
53 #include "awaylogfilter.h"
54 #include "awaylogview.h"
55 #include "action.h"
56 #include "actioncollection.h"
57 #include "bufferhotlistfilter.h"
58 #include "buffermodel.h"
59 #include "bufferview.h"
60 #include "bufferviewoverlay.h"
61 #include "bufferviewoverlayfilter.h"
62 #include "bufferwidget.h"
63 #include "channellistdlg.h"
64 #include "chatlinemodel.h"
65 #include "chatmonitorfilter.h"
66 #include "chatmonitorview.h"
67 #include "chatview.h"
68 #include "client.h"
69 #include "clientbacklogmanager.h"
70 #include "clientbufferviewconfig.h"
71 #include "clientbufferviewmanager.h"
72 #include "clientignorelistmanager.h"
73 #include "clienttransfer.h"
74 #include "clienttransfermanager.h"
75 #include "coreconfigwizard.h"
76 #include "coreconnectdlg.h"
77 #include "coreconnection.h"
78 #include "coreconnectionstatuswidget.h"
79 #include "coreinfodlg.h"
80 #include "contextmenuactionprovider.h"
81 #include "debugbufferviewoverlay.h"
82 #include "debuglogwidget.h"
83 #include "debugmessagemodelfilter.h"
84 #include "flatproxymodel.h"
85 #include "inputwidget.h"
86 #include "irclistmodel.h"
87 #include "ircconnectionwizard.h"
88 #include "legacysystemtray.h"
89 #include "msgprocessorstatuswidget.h"
90 #include "nicklistwidget.h"
91 #include "passwordchangedlg.h"
92 #include "qtuiapplication.h"
93 #include "qtuimessageprocessor.h"
94 #include "qtuisettings.h"
95 #include "qtuistyle.h"
96 #include "receivefiledlg.h"
97 #include "settingsdlg.h"
98 #include "settingspagedlg.h"
99 #include "statusnotifieritem.h"
100 #include "toolbaractionprovider.h"
101 #include "topicwidget.h"
102 #include "transfermodel.h"
103 #include "verticaldock.h"
104
105 #ifndef HAVE_KDE
106 #  ifdef HAVE_QTMULTIMEDIA
107 #    include "qtmultimedianotificationbackend.h"
108 #  endif
109 #  ifdef HAVE_PHONON
110 #    include "phononnotificationbackend.h"
111 #  endif
112 #  include "systraynotificationbackend.h"
113 #  include "taskbarnotificationbackend.h"
114 #else /* HAVE_KDE */
115 #  include "knotificationbackend.h"
116 #endif /* HAVE_KDE */
117
118
119 #ifdef HAVE_LIBSNORE
120 #  include "snorenotificationbackend.h"
121 #endif
122
123 #ifdef HAVE_SSL
124 #  include "sslinfodlg.h"
125 #endif
126
127 #ifdef HAVE_INDICATEQT
128   #include "indicatornotificationbackend.h"
129 #endif
130
131 #ifdef HAVE_NOTIFICATION_CENTER
132   #include "osxnotificationbackend.h"
133 #endif
134
135 #ifdef HAVE_DBUS
136   #include "dockmanagernotificationbackend.h"
137 #endif
138
139 #include "settingspages/aliasessettingspage.h"
140 #include "settingspages/appearancesettingspage.h"
141 #include "settingspages/backlogsettingspage.h"
142 #include "settingspages/bufferviewsettingspage.h"
143 #include "settingspages/chatmonitorsettingspage.h"
144 #include "settingspages/chatviewsettingspage.h"
145 #include "settingspages/chatviewcolorsettingspage.h"
146 #include "settingspages/connectionsettingspage.h"
147 #include "settingspages/coreaccountsettingspage.h"
148 #include "settingspages/coreconnectionsettingspage.h"
149 #include "settingspages/dccsettingspage.h"
150 #include "settingspages/highlightsettingspage.h"
151 #include "settingspages/identitiessettingspage.h"
152 #include "settingspages/ignorelistsettingspage.h"
153 #include "settingspages/inputwidgetsettingspage.h"
154 #include "settingspages/itemviewsettingspage.h"
155 #include "settingspages/networkssettingspage.h"
156 #include "settingspages/notificationssettingspage.h"
157 #include "settingspages/topicwidgetsettingspage.h"
158
159 #ifndef HAVE_KDE
160 #  include "settingspages/shortcutssettingspage.h"
161 #endif
162
163 #ifdef HAVE_SONNET
164 #  include "settingspages/sonnetsettingspage.h"
165 #endif
166
167
168 MainWin::MainWin(QWidget *parent)
169 #ifdef HAVE_KDE
170     : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
171 #else
172     : QMainWindow(parent),
173 #endif
174     _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
175     _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
176     _titleSetter(this),
177     _awayLog(0),
178     _layoutLoaded(false),
179     _activeBufferViewIndex(-1),
180     _aboutToQuit(false)
181 {
182     setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
183
184     QtUiSettings uiSettings;
185     QString style = uiSettings.value("Style", QString()).toString();
186     if (!style.isEmpty()) {
187         QApplication::setStyle(style);
188     }
189
190     QApplication::setQuitOnLastWindowClosed(false);
191
192     setWindowTitle("Quassel IRC");
193     setWindowIconText("Quassel IRC");
194     updateIcon();
195 }
196
197
198 void MainWin::init()
199 {
200     connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
201     connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
202     connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
203         SLOT(messagesInserted(const QModelIndex &, int, int)));
204     connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
205     connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
206
207     connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList, QVariantList)), SLOT(showCoreConfigWizard(QVariantList, QVariantList)));
208     connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
209     connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
210     connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
211     connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
212 #ifdef HAVE_SSL
213     connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
214 #endif
215
216     // Setup Dock Areas
217     setDockNestingEnabled(true);
218     setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
219     setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
220     setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
221     setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
222
223     // Order is sometimes important
224     setupActions();
225     setupBufferWidget();
226     setupMenus();
227     setupTransferWidget();
228     setupChatMonitor();
229     setupTopicWidget();
230     setupInputWidget();
231     setupNickWidget();
232     setupViewMenuTail();
233     setupStatusBar();
234     setupToolBars();
235     setupSystray();
236     setupTitleSetter();
237     setupHotList();
238
239     _bufferWidget->setFocusProxy(_inputWidget);
240     _chatMonitorView->setFocusProxy(_inputWidget);
241
242 #ifndef HAVE_KDE
243 #  ifdef HAVE_QTMULTIMEDIA
244     QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
245 #  endif
246 #  ifdef HAVE_PHONON
247     QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
248 #  endif
249     QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
250 #else /* HAVE_KDE */
251     QtUi::registerNotificationBackend(new KNotificationBackend(this));
252 #endif /* HAVE_KDE */
253
254
255 #ifdef HAVE_LIBSNORE
256     QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
257 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
258     QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
259 #endif
260
261 #ifdef HAVE_INDICATEQT
262     QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
263 #endif
264
265 #ifdef HAVE_NOTIFICATION_CENTER
266     QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
267 #endif
268
269 #ifdef HAVE_DBUS
270     QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
271 #endif
272
273     // we assume that at this point, all configurable actions are defined!
274     QtUi::loadShortcuts();
275
276     connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
277
278     setDisconnectedState(); // Disable menus and stuff
279
280 #ifdef HAVE_KDE
281     setAutoSaveSettings();
282 #endif
283
284     // restore mainwin state
285     QtUiSettings s;
286     restoreStateFromSettings(s);
287
288     // restore locked state of docks
289     QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
290
291     CoreConnection *conn = Client::coreConnection();
292     if (!conn->connectToCore()) {
293         // No autoconnect selected (or no accounts)
294         showCoreConnectionDlg();
295     }
296 }
297
298
299 MainWin::~MainWin()
300 {
301 }
302
303
304 void MainWin::quit()
305 {
306     QtUiSettings s;
307     saveStateToSettings(s);
308     saveLayout();
309     QApplication::quit();
310 }
311
312
313 void MainWin::saveStateToSettings(UiSettings &s)
314 {
315     s.setValue("MainWinSize", _normalSize);
316     s.setValue("MainWinPos", _normalPos);
317     s.setValue("MainWinState", saveState());
318     s.setValue("MainWinGeometry", saveGeometry());
319     s.setValue("MainWinMinimized", isMinimized());
320     s.setValue("MainWinMaximized", isMaximized());
321     s.setValue("MainWinHidden", !isVisible());
322     BufferId lastBufId = Client::bufferModel()->currentBuffer();
323     if (lastBufId.isValid())
324         s.setValue("LastUsedBufferId", lastBufId.toInt());
325
326 #ifdef HAVE_KDE
327     saveAutoSaveSettings();
328 #endif
329 }
330
331
332 void MainWin::restoreStateFromSettings(UiSettings &s)
333 {
334     _normalSize = s.value("MainWinSize", size()).toSize();
335     _normalPos = s.value("MainWinPos", pos()).toPoint();
336     bool maximized = s.value("MainWinMaximized", false).toBool();
337
338 #ifndef HAVE_KDE
339     restoreGeometry(s.value("MainWinGeometry").toByteArray());
340
341     if (maximized) {
342         // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
343         resize(_normalSize);
344         move(_normalPos);
345     }
346
347     restoreState(s.value("MainWinState").toByteArray());
348
349 #else
350     move(_normalPos);
351 #endif
352
353     if ((Quassel::isOptionSet("hidewindow")
354             || s.value("MainWinHidden").toBool())
355             && _systemTray->isSystemTrayAvailable())
356         QtUi::hideMainWidget();
357     else if (s.value("MainWinMinimized").toBool())
358         showMinimized();
359     else if (maximized)
360         showMaximized();
361     else
362         show();
363 }
364
365 QMenu *MainWin::createPopupMenu()
366 {
367     QMenu *popupMenu = QMainWindow::createPopupMenu();
368     popupMenu->addSeparator();
369     ActionCollection *coll = QtUi::actionCollection("General");
370     popupMenu->addAction(coll->action("ToggleMenuBar"));
371     return popupMenu;
372 }
373
374
375 void MainWin::updateIcon()
376 {
377     QIcon icon;
378     if (Client::isConnected())
379         icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
380     else
381         icon = QIcon::fromTheme("inactive-quassel", QIcon(":/icons/inactive-quassel.png"));
382     setWindowIcon(icon);
383     qApp->setWindowIcon(icon);
384 }
385
386
387 void MainWin::setupActions()
388 {
389     ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
390     // File
391     coll->addAction("ConnectCore", new Action(QIcon::fromTheme("connect-quassel", QIcon(":/icons/connect-quassel.png")), tr("&Connect to Core..."), coll,
392             this, SLOT(showCoreConnectionDlg())));
393     coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("disconnect-quassel", QIcon(":/icons/disconnect-quassel.png")), tr("&Disconnect from Core"), coll,
394             Client::instance(), SLOT(disconnectFromCore())));
395     coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
396             this, SLOT(showPasswordChangeDlg())));
397     coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
398             this, SLOT(showCoreInfoDlg())));
399     coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
400             this, SLOT(on_actionConfigureNetworks_triggered())));
401     // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
402     coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
403             this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
404
405     // View
406     coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
407             this, SLOT(on_actionConfigureViews_triggered())));
408
409     QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
410     lockAct->setCheckable(true);
411     connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
412
413     coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
414             0, 0, QKeySequence::Find))->setCheckable(true);
415     coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
416             this, SLOT(showAwayLog())));
417     coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
418             0, 0))->setCheckable(true);
419
420     coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
421             0, 0))->setCheckable(true);
422
423 #ifdef HAVE_KDE
424     _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
425 #else
426     _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
427         this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
428     _fullScreenAction->setCheckable(true);
429     coll->addAction("ToggleFullScreen", _fullScreenAction);
430 #endif
431
432     // Settings
433     QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
434         this, SLOT(showShortcutsDlg()));
435     configureShortcutsAct->setMenuRole(QAction::NoRole);
436     coll->addAction("ConfigureShortcuts", configureShortcutsAct);
437
438 #ifdef Q_OS_MAC
439     QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
440         this, SLOT(showSettingsDlg()));
441     configureQuasselAct->setMenuRole(QAction::PreferencesRole);
442 #else
443     QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
444         this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
445 #endif
446     coll->addAction("ConfigureQuassel", configureQuasselAct);
447
448     // Help
449     QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
450         this, SLOT(showAboutDlg()));
451     aboutQuasselAct->setMenuRole(QAction::AboutRole);
452     coll->addAction("AboutQuassel", aboutQuasselAct);
453
454     QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
455         qApp, SLOT(aboutQt()));
456     aboutQtAct->setMenuRole(QAction::AboutQtRole);
457     coll->addAction("AboutQt", aboutQtAct);
458     coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
459             this, SLOT(on_actionDebugNetworkModel_triggered())));
460     coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
461             this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
462     coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
463             this, SLOT(on_actionDebugMessageModel_triggered())));
464     coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
465             this, SLOT(on_actionDebugHotList_triggered())));
466     coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
467             this, SLOT(on_actionDebugLog_triggered())));
468     coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
469             QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
470
471     coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
472             this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
473
474     // Navigation
475     coll = QtUi::actionCollection("Navigation", tr("Navigation"));
476
477     coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
478             this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
479
480     coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
481             this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
482
483     // Jump keys
484 #ifdef Q_OS_MAC
485     const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
486     const int jumpModifier = Qt::ControlModifier;
487 #else
488     const int bindModifier = Qt::ControlModifier;
489     const int jumpModifier = Qt::AltModifier;
490 #endif
491
492     coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
493             QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
494     coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
495             QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
496     coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
497             QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
498     coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
499             QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
500     coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
501             QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
502     coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
503             QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
504     coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
505             QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
506     coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
507             QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
508     coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
509             QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
510     coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
511             QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
512
513     coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
514             QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
515     coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
516             QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
517     coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
518             QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
519     coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
520             QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
521     coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
522             QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
523     coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
524             QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
525     coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
526             QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
527     coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
528             QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
529     coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
530             QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
531     coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
532             QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
533
534     // Buffer navigation
535     coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
536             this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
537     coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
538             this, SLOT(previousBufferView()), QKeySequence::Back));
539     coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
540             this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
541     coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
542             this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
543 }
544
545
546 void MainWin::setupMenus()
547 {
548     ActionCollection *coll = QtUi::actionCollection("General");
549
550     _fileMenu = menuBar()->addMenu(tr("&File"));
551
552     static const QStringList coreActions = QStringList()
553         << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
554
555     QAction *coreAction;
556     foreach(QString actionName, coreActions) {
557         coreAction = coll->action(actionName);
558         _fileMenu->addAction(coreAction);
559         flagRemoteCoreOnly(coreAction);
560     }
561     flagRemoteCoreOnly(_fileMenu->addSeparator());
562
563     _networksMenu = _fileMenu->addMenu(tr("&Networks"));
564     _networksMenu->addAction(coll->action("ConfigureNetworks"));
565     _networksMenu->addSeparator();
566     _fileMenu->addSeparator();
567     _fileMenu->addAction(coll->action("Quit"));
568
569     _viewMenu = menuBar()->addMenu(tr("&View"));
570     _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
571     _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
572     _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
573     _viewMenu->addSeparator();
574
575     _viewMenu->addAction(coll->action("ToggleMenuBar"));
576     _viewMenu->addAction(coll->action("ToggleStatusBar"));
577     _viewMenu->addAction(coll->action("ToggleSearchBar"));
578
579     coreAction = coll->action("ShowAwayLog");
580     flagRemoteCoreOnly(coreAction);
581     _viewMenu->addAction(coreAction);
582
583     _viewMenu->addSeparator();
584     _viewMenu->addAction(coll->action("LockLayout"));
585
586     _settingsMenu = menuBar()->addMenu(tr("&Settings"));
587 #ifdef HAVE_KDE
588     _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
589     _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
590 #else
591     _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
592 #endif
593     _settingsMenu->addAction(coll->action("ConfigureQuassel"));
594
595
596     _helpMenu = menuBar()->addMenu(tr("&Help"));
597
598     _helpMenu->addAction(coll->action("AboutQuassel"));
599 #ifndef HAVE_KDE
600     _helpMenu->addAction(coll->action("AboutQt"));
601 #else
602     _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
603 #endif
604     _helpMenu->addSeparator();
605     _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
606     _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
607     _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
608     _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
609     _helpDebugMenu->addAction(coll->action("DebugHotList"));
610     _helpDebugMenu->addAction(coll->action("DebugLog"));
611     _helpDebugMenu->addSeparator();
612     _helpDebugMenu->addAction(coll->action("ReloadStyle"));
613
614     // Toggle visibility
615     QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
616
617     QtUiSettings uiSettings;
618     bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
619     showMenuBar->setChecked(enabled);
620     enabled ? menuBar()->show() : menuBar()->hide();
621
622     connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
623     connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
624 }
625
626
627 void MainWin::setupBufferWidget()
628 {
629     _bufferWidget = new BufferWidget(this);
630     _bufferWidget->setModel(Client::bufferModel());
631     _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
632     setCentralWidget(_bufferWidget);
633 }
634
635
636 void MainWin::addBufferView(int bufferViewConfigId)
637 {
638     addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
639 }
640
641
642 void MainWin::addBufferView(ClientBufferViewConfig *config)
643 {
644     if (!config)
645         return;
646
647     config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
648     BufferViewDock *dock = new BufferViewDock(config, this);
649
650     //create the view and initialize it's filter
651     BufferView *view = new BufferView(dock);
652     view->setFilteredModel(Client::bufferModel(), config);
653     view->installEventFilter(_inputWidget); // for key presses
654
655     Client::bufferModel()->synchronizeView(view);
656
657     dock->setWidget(view);
658     dock->setVisible(_layoutLoaded); // don't show before state has been restored
659
660     addDockWidget(Qt::LeftDockWidgetArea, dock);
661     _bufferViewsMenu->addAction(dock->toggleViewAction());
662
663     connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
664     connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
665     _bufferViews.append(dock);
666
667     if (!activeBufferView())
668         nextBufferView();
669 }
670
671
672 void MainWin::removeBufferView(int bufferViewConfigId)
673 {
674     QVariant actionData;
675     BufferViewDock *dock;
676     foreach(QAction *action, _bufferViewsMenu->actions()) {
677         actionData = action->data();
678         if (!actionData.isValid())
679             continue;
680
681         dock = qobject_cast<BufferViewDock *>(action->parent());
682         if (dock && actionData.toInt() == bufferViewConfigId) {
683             removeAction(action);
684             Client::bufferViewOverlay()->removeView(dock->bufferViewId());
685             _bufferViews.removeAll(dock);
686
687             if (dock->isActive()) {
688                 dock->setActive(false);
689                 _activeBufferViewIndex = -1;
690                 nextBufferView();
691             }
692
693             dock->deleteLater();
694         }
695     }
696 }
697
698
699 void MainWin::bufferViewToggled(bool enabled)
700 {
701     if (!enabled && !isMinimized()) {
702         // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
703         // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
704         return;
705     }
706     QAction *action = qobject_cast<QAction *>(sender());
707     Q_ASSERT(action);
708     BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
709     Q_ASSERT(dock);
710
711     // Make sure we don't toggle backlog fetch for a view we've already removed
712     if (!_bufferViews.contains(dock))
713         return;
714
715     if (enabled)
716         Client::bufferViewOverlay()->addView(dock->bufferViewId());
717     else
718         Client::bufferViewOverlay()->removeView(dock->bufferViewId());
719 }
720
721
722 void MainWin::bufferViewVisibilityChanged(bool visible)
723 {
724     Q_UNUSED(visible);
725     BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
726     Q_ASSERT(dock);
727     if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
728         nextBufferView();
729 }
730
731
732 BufferView *MainWin::allBuffersView() const
733 {
734     // "All Buffers" is always the first dock created
735     if (_bufferViews.count() > 0)
736         return _bufferViews[0]->bufferView();
737     return 0;
738 }
739
740
741 BufferView *MainWin::activeBufferView() const
742 {
743     if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
744         return 0;
745     BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
746     return dock->isActive() ? dock->bufferView() : 0;
747 }
748
749
750 void MainWin::changeActiveBufferView(int bufferViewId)
751 {
752     if (bufferViewId < 0)
753         return;
754
755     if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
756         _bufferViews[_activeBufferViewIndex]->setActive(false);
757         _activeBufferViewIndex = -1;
758     }
759
760     for (int i = 0; i < _bufferViews.count(); i++) {
761         BufferViewDock *dock = _bufferViews.at(i);
762         if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
763             _activeBufferViewIndex = i;
764             dock->setActive(true);
765             return;
766         }
767     }
768
769     nextBufferView(); // fallback
770 }
771
772
773 void MainWin::showPasswordChangeDlg()
774 {
775     if((Client::coreFeatures() & Quassel::PasswordChange)) {
776         PasswordChangeDlg dlg(this);
777         dlg.exec();
778     }
779     else {
780         QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
781                         tr("<b>Your Quassel Core does not support this feature</b>"),
782                         QMessageBox::Ok, this);
783         box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
784         box.exec();
785     }
786 }
787
788
789 void MainWin::changeActiveBufferView(bool backwards)
790 {
791     if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
792         _bufferViews[_activeBufferViewIndex]->setActive(false);
793     }
794
795     if (!_bufferViews.count())
796         return;
797
798     int c = _bufferViews.count();
799     while (c--) { // yes, this will reactivate the current active one if all others fail
800         if (backwards) {
801             if (--_activeBufferViewIndex < 0)
802                 _activeBufferViewIndex = _bufferViews.count()-1;
803         }
804         else {
805             if (++_activeBufferViewIndex >= _bufferViews.count())
806                 _activeBufferViewIndex = 0;
807         }
808
809         BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
810         if (dock->isHidden())
811             continue;
812
813         dock->setActive(true);
814         return;
815     }
816
817     _activeBufferViewIndex = -1;
818 }
819
820
821 void MainWin::nextBufferView()
822 {
823     changeActiveBufferView(false);
824 }
825
826
827 void MainWin::previousBufferView()
828 {
829     changeActiveBufferView(true);
830 }
831
832
833 void MainWin::nextBuffer()
834 {
835     BufferView *view = activeBufferView();
836     if (view)
837         view->nextBuffer();
838 }
839
840
841 void MainWin::previousBuffer()
842 {
843     BufferView *view = activeBufferView();
844     if (view)
845         view->previousBuffer();
846 }
847
848
849 void MainWin::hideCurrentBuffer()
850 {
851     BufferView *view = activeBufferView();
852     if (view)
853         view->hideCurrentBuffer();
854 }
855
856
857 void MainWin::showNotificationsDlg()
858 {
859     SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
860     dlg.exec();
861 }
862
863
864 void MainWin::on_actionConfigureNetworks_triggered()
865 {
866     SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
867     dlg.exec();
868 }
869
870
871 void MainWin::on_actionConfigureViews_triggered()
872 {
873     SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
874     dlg.exec();
875 }
876
877
878 void MainWin::on_actionLockLayout_toggled(bool lock)
879 {
880     QList<VerticalDock *> docks = findChildren<VerticalDock *>();
881     foreach(VerticalDock *dock, docks) {
882         dock->showTitle(!lock);
883     }
884     if (Client::bufferViewManager()) {
885         foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
886             config->setLocked(lock);
887         }
888     }
889     QtUiSettings().setValue("LockLayout", lock);
890 }
891
892
893 void MainWin::setupNickWidget()
894 {
895     // create nick dock
896     NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
897     nickDock->setObjectName("NickDock");
898     nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
899
900     _nickListWidget = new NickListWidget(nickDock);
901     nickDock->setWidget(_nickListWidget);
902
903     addDockWidget(Qt::RightDockWidgetArea, nickDock);
904     _viewMenu->addAction(nickDock->toggleViewAction());
905     nickDock->toggleViewAction()->setText(tr("Show Nick List"));
906
907     // See NickListDock::NickListDock();
908     // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
909
910     // attach the NickListWidget to the BufferModel and the default selection
911     _nickListWidget->setModel(Client::bufferModel());
912     _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
913
914     _nickListWidget->setVisible(false);
915 }
916
917
918 void MainWin::setupChatMonitor()
919 {
920     VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
921     dock->setObjectName("ChatMonitorDock");
922
923     ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
924     _chatMonitorView = new ChatMonitorView(filter, this);
925     _chatMonitorView->show();
926     dock->setWidget(_chatMonitorView);
927     dock->hide();
928
929     addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
930     _viewMenu->addAction(dock->toggleViewAction());
931     dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
932 }
933
934
935 void MainWin::setupInputWidget()
936 {
937     VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
938     dock->setObjectName("InputDock");
939
940     _inputWidget = new InputWidget(dock);
941     dock->setWidget(_inputWidget);
942
943     addDockWidget(Qt::BottomDockWidgetArea, dock);
944
945     _viewMenu->addAction(dock->toggleViewAction());
946     dock->toggleViewAction()->setText(tr("Show Input Line"));
947
948     _inputWidget->setModel(Client::bufferModel());
949     _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
950
951     _inputWidget->inputLine()->installEventFilter(_bufferWidget);
952
953     connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
954 }
955
956
957 void MainWin::setupTopicWidget()
958 {
959     VerticalDock *dock = new VerticalDock(tr("Topic"), this);
960     dock->setObjectName("TopicDock");
961     _topicWidget = new TopicWidget(dock);
962
963     dock->setWidget(_topicWidget);
964
965     _topicWidget->setModel(Client::bufferModel());
966     _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
967
968     addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
969
970     _viewMenu->addAction(dock->toggleViewAction());
971     dock->toggleViewAction()->setText(tr("Show Topic Line"));
972 }
973
974
975 void MainWin::setupTransferWidget()
976 {
977     auto dock = new QDockWidget(tr("Transfers"), this);
978     dock->setObjectName("TransferDock");
979     dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
980
981     auto view = new QTableView(dock); // to be replaced by the real thing
982     view->setModel(Client::transferModel());
983     dock->setWidget(view);
984     dock->hide(); // hidden by default
985     addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
986
987     auto action = dock->toggleViewAction();
988     action->setText(tr("Show File Transfers"));
989     action->setIcon(QIcon::fromTheme("download"));
990     action->setShortcut(QKeySequence(Qt::Key_F6));
991     QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
992     _viewMenu->addAction(action);
993 }
994
995
996 void MainWin::setupViewMenuTail()
997 {
998     _viewMenu->addSeparator();
999     _viewMenu->addAction(_fullScreenAction);
1000 }
1001
1002
1003 void MainWin::setupTitleSetter()
1004 {
1005     _titleSetter.setModel(Client::bufferModel());
1006     _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1007 }
1008
1009
1010 void MainWin::setupStatusBar()
1011 {
1012     // MessageProcessor progress
1013     statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1014
1015     // Connection state
1016     _coreConnectionStatusWidget->update();
1017     statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1018
1019     QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1020
1021     QtUiSettings uiSettings;
1022
1023     bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1024     showStatusbar->setChecked(enabled);
1025     enabled ? statusBar()->show() : statusBar()->hide();
1026
1027     connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1028     connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1029
1030     connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1031 }
1032
1033
1034 void MainWin::setupHotList()
1035 {
1036     FlatProxyModel *flatProxy = new FlatProxyModel(this);
1037     flatProxy->setSourceModel(Client::bufferModel());
1038     _bufferHotList = new BufferHotListFilter(flatProxy);
1039 }
1040
1041
1042 void MainWin::saveMenuBarStatus(bool enabled)
1043 {
1044     QtUiSettings uiSettings;
1045     uiSettings.setValue("ShowMenuBar", enabled);
1046 }
1047
1048
1049 void MainWin::saveStatusBarStatus(bool enabled)
1050 {
1051     QtUiSettings uiSettings;
1052     uiSettings.setValue("ShowStatusBar", enabled);
1053 }
1054
1055
1056 void MainWin::setupSystray()
1057 {
1058 #ifdef HAVE_DBUS
1059     _systemTray = new StatusNotifierItem(this);
1060 #elif !defined QT_NO_SYSTEMTRAYICON
1061     _systemTray = new LegacySystemTray(this);
1062 #else
1063     _systemTray = new SystemTray(this); // dummy
1064 #endif
1065     _systemTray->init();
1066 }
1067
1068
1069 void MainWin::setupToolBars()
1070 {
1071     connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1072         QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1073     connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1074         QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1075
1076 #ifdef Q_OS_MAC
1077     setUnifiedTitleAndToolBarOnMac(true);
1078 #endif
1079
1080 #ifdef HAVE_KDE
1081     _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1082 #else
1083     _mainToolBar = new QToolBar(this);
1084     _mainToolBar->setObjectName("MainToolBar");
1085 #endif
1086     _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1087     addToolBar(_mainToolBar);
1088
1089     if (Quassel::runMode() != Quassel::Monolithic) {
1090         ActionCollection *coll = QtUi::actionCollection("General");
1091         _mainToolBar->addAction(coll->action("ConnectCore"));
1092         _mainToolBar->addAction(coll->action("DisconnectCore"));
1093     }
1094
1095     QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1096     _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1097
1098 #ifdef HAVE_KDE
1099     _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1100 #else
1101     _nickToolBar = new QToolBar(this);
1102     _nickToolBar->setObjectName("NickToolBar");
1103 #endif
1104     _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1105     _nickToolBar->setVisible(false); //default: not visible
1106     addToolBar(_nickToolBar);
1107
1108     QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1109     _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1110
1111 #ifdef Q_OS_MAC
1112     QtUiSettings uiSettings;
1113
1114     bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1115     _mainToolBar->setVisible(visible);
1116     connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1117 #endif
1118 }
1119
1120 void MainWin::saveMainToolBarStatus(bool enabled)
1121 {
1122 #ifdef Q_OS_MAC
1123     QtUiSettings uiSettings;
1124     uiSettings.setValue("ShowMainToolBar", enabled);
1125 #else
1126     Q_UNUSED(enabled);
1127 #endif
1128 }
1129
1130
1131 void MainWin::connectedToCore()
1132 {
1133     Q_CHECK_PTR(Client::bufferViewManager());
1134     connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1135     connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1136     connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1137
1138     if (Client::transferManager()) {
1139         connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1140     }
1141
1142     setConnectedState();
1143 }
1144
1145
1146 void MainWin::setConnectedState()
1147 {
1148     ActionCollection *coll = QtUi::actionCollection("General");
1149
1150     coll->action("ConnectCore")->setEnabled(false);
1151     coll->action("DisconnectCore")->setEnabled(true);
1152     coll->action("ChangePassword")->setEnabled(true);
1153     coll->action("CoreInfo")->setEnabled(true);
1154
1155     foreach(QAction *action, _fileMenu->actions()) {
1156         if (isRemoteCoreOnly(action))
1157             action->setVisible(!Client::internalCore());
1158     }
1159
1160     disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1161     disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1162     disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1163     if (!Client::internalCore()) {
1164         connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1165         connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1166         connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1167     }
1168
1169     // _viewMenu->setEnabled(true);
1170     if (!Client::internalCore())
1171         statusBar()->showMessage(tr("Connected to core."));
1172     else
1173         statusBar()->clearMessage();
1174
1175     _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1176     updateIcon();
1177     systemTray()->setState(SystemTray::Active);
1178
1179     if (Client::networkIds().isEmpty()) {
1180         IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1181         wizard->show();
1182     }
1183     else {
1184         // Monolithic always preselects last used buffer - Client only if the connection died
1185         if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1186             QtUiSettings s;
1187             BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1188             if (lastUsedBufferId.isValid())
1189                 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1190         }
1191     }
1192 }
1193
1194
1195 void MainWin::loadLayout()
1196 {
1197     QtUiSettings s;
1198     int accountId = Client::currentCoreAccount().accountId().toInt();
1199     QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1200     if (state.isEmpty()) {
1201         foreach(BufferViewDock *view, _bufferViews)
1202         view->show();
1203         _layoutLoaded = true;
1204         return;
1205     }
1206     _nickListWidget->setVisible(true);
1207     restoreState(state, accountId);
1208     int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1209     if (bufferViewId >= 0)
1210         changeActiveBufferView(bufferViewId);
1211
1212     _layoutLoaded = true;
1213 }
1214
1215
1216 void MainWin::saveLayout()
1217 {
1218     QtUiSettings s;
1219     int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1220     if (accountId > 0) {
1221         s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1222         BufferView *view = activeBufferView();
1223         s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1224     }
1225 }
1226
1227
1228 void MainWin::disconnectedFromCore()
1229 {
1230     // save core specific layout and remove bufferviews;
1231     saveLayout();
1232     _layoutLoaded = false;
1233
1234     QVariant actionData;
1235     BufferViewDock *dock;
1236     foreach(QAction *action, _bufferViewsMenu->actions()) {
1237         actionData = action->data();
1238         if (!actionData.isValid())
1239             continue;
1240
1241         dock = qobject_cast<BufferViewDock *>(action->parent());
1242         if (dock && actionData.toInt() != -1) {
1243             removeAction(action);
1244             _bufferViews.removeAll(dock);
1245             dock->deleteLater();
1246         }
1247     }
1248
1249     // store last active buffer
1250     QtUiSettings s;
1251     BufferId lastBufId = _bufferWidget->currentBuffer();
1252     if (lastBufId.isValid()) {
1253         s.setValue("LastUsedBufferId", lastBufId.toInt());
1254         // clear the current selection
1255         Client::bufferModel()->standardSelectionModel()->clearSelection();
1256     }
1257     restoreState(s.value("MainWinState").toByteArray());
1258     setDisconnectedState();
1259 }
1260
1261
1262 void MainWin::setDisconnectedState()
1263 {
1264     ActionCollection *coll = QtUi::actionCollection("General");
1265     //ui.menuCore->setEnabled(false);
1266     coll->action("ConnectCore")->setEnabled(true);
1267     coll->action("DisconnectCore")->setEnabled(false);
1268     coll->action("CoreInfo")->setEnabled(false);
1269     coll->action("ChangePassword")->setEnabled(false);
1270     //_viewMenu->setEnabled(false);
1271     statusBar()->showMessage(tr("Not connected to core."));
1272     if (_msgProcessorStatusWidget)
1273         _msgProcessorStatusWidget->setProgress(0, 0);
1274     updateIcon();
1275     systemTray()->setState(SystemTray::Passive);
1276     _nickListWidget->setVisible(false);
1277 }
1278
1279
1280 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1281 {
1282     Q_UNUSED(errorMessage)
1283     CoreConnectAuthDlg dlg(account, this);
1284     *valid = (dlg.exec() == QDialog::Accepted);
1285 }
1286
1287
1288 void MainWin::handleNoSslInClient(bool *accepted)
1289 {
1290     QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1291         QMessageBox::Ignore|QMessageBox::Cancel, this);
1292     box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1293     box.setDefaultButton(QMessageBox::Ignore);
1294     *accepted = box.exec() == QMessageBox::Ignore;
1295 }
1296
1297
1298 void MainWin::handleNoSslInCore(bool *accepted)
1299 {
1300     QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1301         QMessageBox::Ignore|QMessageBox::Cancel, this);
1302     box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1303     box.setDefaultButton(QMessageBox::Ignore);
1304     *accepted = box.exec() == QMessageBox::Ignore;
1305 }
1306
1307
1308 #ifdef HAVE_SSL
1309
1310 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1311 {
1312     QString errorString = "<ul>";
1313     foreach(const QSslError error, socket->sslErrors())
1314     errorString += QString("<li>%1</li>").arg(error.errorString());
1315     errorString += "</ul>";
1316
1317     QMessageBox box(QMessageBox::Warning,
1318         tr("Untrusted Security Certificate"),
1319         tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1320         QMessageBox::Cancel, this);
1321     box.setInformativeText(errorString);
1322     box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1323     box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1324
1325     QMessageBox::ButtonRole role;
1326     do {
1327         box.exec();
1328         role = box.buttonRole(box.clickedButton());
1329         if (role == QMessageBox::HelpRole) {
1330             SslInfoDlg dlg(socket, this);
1331             dlg.exec();
1332         }
1333     }
1334     while (role == QMessageBox::HelpRole);
1335
1336     *accepted = role == QMessageBox::AcceptRole;
1337     if (*accepted) {
1338         QMessageBox box2(QMessageBox::Warning,
1339             tr("Untrusted Security Certificate"),
1340             tr("Would you like to accept this certificate forever without being prompted?"),
1341             0, this);
1342         box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1343         box2.addButton(tr("Forever"), QMessageBox::YesRole);
1344         box2.exec();
1345         *permanently =  box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1346     }
1347 }
1348
1349
1350 #endif /* HAVE_SSL */
1351
1352 void MainWin::handleCoreConnectionError(const QString &error)
1353 {
1354     QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1355 }
1356
1357
1358 void MainWin::showCoreConnectionDlg()
1359 {
1360     CoreConnectDlg dlg(this);
1361     if (dlg.exec() == QDialog::Accepted) {
1362         AccountId accId = dlg.selectedAccount();
1363         if (accId.isValid())
1364             Client::coreConnection()->connectToCore(accId);
1365     }
1366 }
1367
1368
1369 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1370 {
1371     CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1372
1373     wizard->show();
1374 }
1375
1376
1377 void MainWin::showChannelList(NetworkId netId)
1378 {
1379     ChannelListDlg *channelListDlg = new ChannelListDlg();
1380
1381     if (!netId.isValid()) {
1382         QAction *action = qobject_cast<QAction *>(sender());
1383         if (action)
1384             netId = action->data().value<NetworkId>();
1385     }
1386
1387     channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1388     channelListDlg->setNetwork(netId);
1389     channelListDlg->show();
1390 }
1391
1392
1393 void MainWin::showIgnoreList(QString newRule)
1394 {
1395     SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1396     // prepare config dialog for new rule
1397     if (!newRule.isEmpty())
1398         qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1399     dlg.exec();
1400 }
1401
1402
1403 void MainWin::showCoreInfoDlg()
1404 {
1405     CoreInfoDlg(this).exec();
1406 }
1407
1408
1409 void MainWin::showAwayLog()
1410 {
1411     if (_awayLog)
1412         return;
1413     AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1414     _awayLog = new AwayLogView(filter, 0);
1415     filter->setParent(_awayLog);
1416     connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1417     _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1418     _awayLog->show();
1419 }
1420
1421
1422 void MainWin::awayLogDestroyed()
1423 {
1424     _awayLog = 0;
1425 }
1426
1427
1428 void MainWin::showSettingsDlg()
1429 {
1430     SettingsDlg *dlg = new SettingsDlg();
1431
1432     //Category: Interface
1433     dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1434     dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1435     dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1436     dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1437     dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1438     dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1439     dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1440     dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1441 #ifdef HAVE_SONNET
1442     dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1443 #endif
1444     dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1445     dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1446     dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1447
1448     //Category: IRC
1449     dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1450     dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1451     dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1452     dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1453     dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1454     dlg->registerSettingsPage(new DccSettingsPage(dlg));
1455
1456     // Category: Remote Cores
1457     if (Quassel::runMode() != Quassel::Monolithic) {
1458         dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1459         dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1460     }
1461
1462     dlg->show();
1463 }
1464
1465
1466 void MainWin::showAboutDlg()
1467 {
1468     AboutDlg(this).exec();
1469 }
1470
1471
1472 void MainWin::showShortcutsDlg()
1473 {
1474 #ifdef HAVE_KDE
1475     KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1476     foreach(KActionCollection *coll, QtUi::actionCollections())
1477     dlg.addCollection(coll, coll->property("Category").toString());
1478     dlg.configure(true);
1479 #else
1480     SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1481     dlg.exec();
1482 #endif
1483 }
1484
1485
1486 void MainWin::showNewTransferDlg(const QUuid &transferId)
1487 {
1488     auto transfer = Client::transferManager()->transfer(transferId);
1489     if (transfer) {
1490         if (transfer->status() == Transfer::Status::New) {
1491             ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1492             dlg->show();
1493         }
1494     }
1495     else {
1496         qWarning() << "Unknown transfer ID" << transferId;
1497     }
1498 }
1499
1500
1501 void MainWin::onFullScreenToggled()
1502 {
1503     // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1504     // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1505
1506 #ifdef HAVE_KDE
1507     static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1508 #else
1509     if (_fullScreenAction->isChecked())
1510         setWindowState(windowState() | Qt::WindowFullScreen);
1511     else
1512         setWindowState(windowState() & ~Qt::WindowFullScreen);
1513 #endif
1514 }
1515
1516
1517 /********************************************************************************************************/
1518
1519 bool MainWin::event(QEvent *event)
1520 {
1521     switch(event->type()) {
1522     case QEvent::WindowActivate: {
1523         BufferId bufferId = Client::bufferModel()->currentBuffer();
1524         if (bufferId.isValid())
1525             Client::instance()->markBufferAsRead(bufferId);
1526         break;
1527     }
1528     case QEvent::WindowDeactivate:
1529         if (bufferWidget()->autoMarkerLineOnLostFocus())
1530             bufferWidget()->setMarkerLine();
1531         break;
1532     default:
1533         break;
1534     }
1535     return QMainWindow::event(event);
1536 }
1537
1538
1539 void MainWin::moveEvent(QMoveEvent *event)
1540 {
1541     if (!(windowState() & Qt::WindowMaximized))
1542         _normalPos = event->pos();
1543
1544     QMainWindow::moveEvent(event);
1545 }
1546
1547
1548 void MainWin::resizeEvent(QResizeEvent *event)
1549 {
1550     if (!(windowState() & Qt::WindowMaximized))
1551         _normalSize = event->size();
1552
1553     QMainWindow::resizeEvent(event);
1554 }
1555
1556
1557 void MainWin::closeEvent(QCloseEvent *event)
1558 {
1559     QtUiSettings s;
1560     QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1561     Q_ASSERT(app);
1562     // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1563     // This messes up MainWinState/MainWinHidden save/restore.
1564     // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1565     if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1566         QtUi::hideMainWidget();
1567         event->ignore();
1568     }
1569     else if(!_aboutToQuit) {
1570         _aboutToQuit = true;
1571         event->accept();
1572         quit();
1573     }
1574     else {
1575         event->ignore();
1576     }
1577 }
1578
1579
1580 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1581 {
1582     Q_UNUSED(parent);
1583
1584     bool hasFocus = QApplication::activeWindow() != 0;
1585
1586     for (int i = start; i <= end; i++) {
1587         QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1588         if (!idx.isValid()) {
1589             qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1590             continue;
1591         }
1592         Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1593         if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1594             continue;
1595
1596         BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1597         BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1598
1599         // check if bufferId belongs to the shown chatlists
1600         if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1601               Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1602             continue;
1603
1604         // check if it's the buffer currently displayed
1605         if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1606             continue;
1607
1608         // only show notifications for higlights or queries
1609         if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1610             continue;
1611
1612         // and of course: don't notify for ignored messages
1613         if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1614             continue;
1615
1616         // seems like we have a legit notification candidate!
1617         QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1618         QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1619         QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1620         AbstractNotificationBackend::NotificationType type;
1621
1622         if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1623             type = AbstractNotificationBackend::PrivMsg;
1624         else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1625             type = AbstractNotificationBackend::PrivMsgFocused;
1626         else if (flags & Message::Highlight && !hasFocus)
1627             type = AbstractNotificationBackend::Highlight;
1628         else
1629             type = AbstractNotificationBackend::HighlightFocused;
1630
1631         QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1632     }
1633 }
1634
1635
1636 void MainWin::currentBufferChanged(BufferId buffer)
1637 {
1638     if (buffer.isValid())
1639         Client::instance()->markBufferAsRead(buffer);
1640 }
1641
1642
1643 void MainWin::clientNetworkCreated(NetworkId id)
1644 {
1645     const Network *net = Client::network(id);
1646     QAction *act = new QAction(net->networkName(), this);
1647     act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1648     act->setData(QVariant::fromValue<NetworkId>(id));
1649     connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1650     connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1651
1652     QAction *beforeAction = 0;
1653     foreach(QAction *action, _networksMenu->actions()) {
1654         if (!action->data().isValid()) // ignore stock actions
1655             continue;
1656         if (net->networkName().localeAwareCompare(action->text()) < 0) {
1657             beforeAction = action;
1658             break;
1659         }
1660     }
1661     _networksMenu->insertAction(beforeAction, act);
1662 }
1663
1664
1665 void MainWin::clientNetworkUpdated()
1666 {
1667     const Network *net = qobject_cast<const Network *>(sender());
1668     if (!net)
1669         return;
1670
1671     QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1672     if (!action)
1673         return;
1674
1675     action->setText(net->networkName());
1676
1677     switch (net->connectionState()) {
1678     case Network::Initialized:
1679         action->setIcon(QIcon::fromTheme("network-connect"));
1680         // if we have no currently selected buffer, jump to the first connecting statusbuffer
1681         if (!bufferWidget()->currentBuffer().isValid()) {
1682             QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1683             if (idx.isValid()) {
1684                 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1685                 Client::bufferModel()->switchToBuffer(statusBufferId);
1686             }
1687         }
1688         break;
1689     case Network::Disconnected:
1690         action->setIcon(QIcon::fromTheme("network-disconnect"));
1691         break;
1692     default:
1693         action->setIcon(QIcon::fromTheme("network-wired"));
1694     }
1695 }
1696
1697
1698 void MainWin::clientNetworkRemoved(NetworkId id)
1699 {
1700     QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1701     if (!action)
1702         return;
1703
1704     action->deleteLater();
1705 }
1706
1707
1708 void MainWin::connectOrDisconnectFromNet()
1709 {
1710     QAction *act = qobject_cast<QAction *>(sender());
1711     if (!act) return;
1712     const Network *net = Client::network(act->data().value<NetworkId>());
1713     if (!net) return;
1714     if (net->connectionState() == Network::Disconnected) net->requestConnect();
1715     else net->requestDisconnect();
1716 }
1717
1718
1719 void MainWin::on_jumpHotBuffer_triggered()
1720 {
1721     if (!_bufferHotList->rowCount())
1722         return;
1723
1724     Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1725 }
1726
1727 void MainWin::on_bufferSearch_triggered()
1728 {
1729     if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1730         qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1731         return;
1732     }
1733
1734     _bufferViews[_activeBufferViewIndex]->activateFilter();
1735 }
1736
1737
1738 void MainWin::onJumpKey()
1739 {
1740     QAction *action = qobject_cast<QAction *>(sender());
1741     if (!action || !Client::bufferModel())
1742         return;
1743     int idx = action->property("Index").toInt();
1744
1745     if (_jumpKeyMap.isEmpty())
1746         _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1747
1748     if (!_jumpKeyMap.contains(idx))
1749         return;
1750
1751     BufferId buffer = _jumpKeyMap.value(idx);
1752     if (buffer.isValid())
1753         Client::bufferModel()->switchToBuffer(buffer);
1754 }
1755
1756
1757 void MainWin::bindJumpKey()
1758 {
1759     QAction *action = qobject_cast<QAction *>(sender());
1760     if (!action || !Client::bufferModel())
1761         return;
1762     int idx = action->property("Index").toInt();
1763
1764     _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1765     CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1766 }
1767
1768
1769 void MainWin::on_actionDebugNetworkModel_triggered()
1770 {
1771     QTreeView *view = new QTreeView;
1772     view->setAttribute(Qt::WA_DeleteOnClose);
1773     view->setWindowTitle("Debug NetworkModel View");
1774     view->setModel(Client::networkModel());
1775     view->setColumnWidth(0, 250);
1776     view->setColumnWidth(1, 250);
1777     view->setColumnWidth(2, 80);
1778     view->resize(610, 300);
1779     view->show();
1780 }
1781
1782
1783 void MainWin::on_actionDebugHotList_triggered()
1784 {
1785     _bufferHotList->invalidate();
1786     _bufferHotList->sort(0, Qt::DescendingOrder);
1787
1788     QTreeView *view = new QTreeView;
1789     view->setAttribute(Qt::WA_DeleteOnClose);
1790     view->setModel(_bufferHotList);
1791     view->show();
1792 }
1793
1794
1795 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1796 {
1797     DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1798     overlay->setAttribute(Qt::WA_DeleteOnClose);
1799     overlay->show();
1800 }
1801
1802
1803 void MainWin::on_actionDebugMessageModel_triggered()
1804 {
1805     QTableView *view = new QTableView(0);
1806     DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1807     filter->setSourceModel(Client::messageModel());
1808     view->setModel(filter);
1809     view->setAttribute(Qt::WA_DeleteOnClose, true);
1810     view->verticalHeader()->hide();
1811     view->horizontalHeader()->setStretchLastSection(true);
1812     view->show();
1813 }
1814
1815
1816 void MainWin::on_actionDebugLog_triggered()
1817 {
1818     DebugLogWidget *logWidget = new DebugLogWidget(0);
1819     logWidget->show();
1820 }
1821
1822
1823 void MainWin::showStatusBarMessage(const QString &message)
1824 {
1825     statusBar()->showMessage(message, 10000);
1826 }