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