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