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