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