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