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