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