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