ed467cd46d0b66979b30a401326235db125edf7d
[quassel.git] / src / qtui / mainwin.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-09 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #include "mainwin.h"
21
22 #ifdef HAVE_KDE
23 #  include <KAction>
24 #  include <KActionCollection>
25 #  include <KHelpMenu>
26 #  include <KMenuBar>
27 #  include <KShortcutsDialog>
28 #  include <KStatusBar>
29 #  include <KToolBar>
30 #  include <KWindowSystem>
31 #endif
32
33 #ifdef Q_WS_X11
34 #  include <QX11Info>
35 #endif
36
37 #include "aboutdlg.h"
38 #include "awaylogfilter.h"
39 #include "awaylogview.h"
40 #include "action.h"
41 #include "actioncollection.h"
42 #include "bufferhotlistfilter.h"
43 #include "buffermodel.h"
44 #include "bufferview.h"
45 #include "bufferviewoverlay.h"
46 #include "bufferviewoverlayfilter.h"
47 #include "bufferwidget.h"
48 #include "channellistdlg.h"
49 #include "chatlinemodel.h"
50 #include "chatmonitorfilter.h"
51 #include "chatmonitorview.h"
52 #include "chatview.h"
53 #include "client.h"
54 #include "clientbacklogmanager.h"
55 #include "clientbufferviewconfig.h"
56 #include "clientbufferviewmanager.h"
57 #include "clientignorelistmanager.h"
58 #include "coreconnectdlg.h"
59 #include "coreconnection.h"
60 #include "coreconnectionstatuswidget.h"
61 #include "coreinfodlg.h"
62 #include "contextmenuactionprovider.h"
63 #include "debugbufferviewoverlay.h"
64 #include "debuglogwidget.h"
65 #include "debugmessagemodelfilter.h"
66 #include "flatproxymodel.h"
67 #include "iconloader.h"
68 #include "inputwidget.h"
69 #include "irclistmodel.h"
70 #include "ircconnectionwizard.h"
71 #include "jumpkeyhandler.h"
72 #include "msgprocessorstatuswidget.h"
73 #include "nicklistwidget.h"
74 #include "qtuiapplication.h"
75 #include "qtuimessageprocessor.h"
76 #include "qtuisettings.h"
77 #include "qtuistyle.h"
78 #include "settingsdlg.h"
79 #include "settingspagedlg.h"
80 #include "systemtray.h"
81 #include "toolbaractionprovider.h"
82 #include "topicwidget.h"
83 #include "verticaldock.h"
84
85 #ifndef HAVE_KDE
86 #  ifdef HAVE_DBUS
87 #    include "desktopnotificationbackend.h"
88 #  endif
89 #  ifdef HAVE_PHONON
90 #    include "phononnotificationbackend.h"
91 #  endif
92 #  include "systraynotificationbackend.h"
93 #  include "taskbarnotificationbackend.h"
94 #else /* HAVE_KDE */
95 #  include "knotificationbackend.h"
96 #endif /* HAVE_KDE */
97
98 #ifdef HAVE_INDICATEQT
99   #include "indicatornotificationbackend.h"
100 #endif
101
102 #include "settingspages/aliasessettingspage.h"
103 #include "settingspages/appearancesettingspage.h"
104 #include "settingspages/backlogsettingspage.h"
105 #include "settingspages/bufferviewsettingspage.h"
106 #include "settingspages/chatmonitorsettingspage.h"
107 #include "settingspages/chatviewsettingspage.h"
108 #include "settingspages/connectionsettingspage.h"
109 #include "settingspages/coreaccountsettingspage.h"
110 #include "settingspages/generalsettingspage.h"
111 #include "settingspages/highlightsettingspage.h"
112 #include "settingspages/identitiessettingspage.h"
113 #include "settingspages/ignorelistsettingspage.h"
114 #include "settingspages/inputwidgetsettingspage.h"
115 #include "settingspages/itemviewsettingspage.h"
116 #include "settingspages/networkssettingspage.h"
117 #include "settingspages/notificationssettingspage.h"
118 #include "settingspages/topicwidgetsettingspage.h"
119
120 MainWin::MainWin(QWidget *parent)
121 #ifdef HAVE_KDE
122   : KMainWindow(parent),
123   _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
124 #else
125   : QMainWindow(parent),
126 #endif
127     coreLagLabel(new QLabel()),
128     sslLabel(new QLabel()),
129     _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
130     _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
131     _titleSetter(this),
132     _awayLog(0),
133     _layoutLoaded(false)
134 {
135 #ifdef Q_WS_WIN
136   dwTickCount = 0;
137 #endif
138
139   QtUiSettings uiSettings;
140   QString style = uiSettings.value("Style", QString()).toString();
141   if(!style.isEmpty()) {
142     QApplication::setStyle(style);
143   }
144
145   QApplication::setQuitOnLastWindowClosed(false);
146
147   setWindowTitle("Quassel IRC");
148   setWindowIconText("Quassel IRC");
149   updateIcon();
150
151   installEventFilter(new JumpKeyHandler(this));
152 }
153
154 void MainWin::init() {
155   connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
156   connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
157   connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
158            SLOT(messagesInserted(const QModelIndex &, int, int)));
159   connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
160   connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
161   connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
162
163   // Setup Dock Areas
164   setDockNestingEnabled(true);
165   setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
166   setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
167   setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
168   setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
169
170   // Order is sometimes important
171   setupActions();
172   setupBufferWidget();
173   setupMenus();
174   setupTopicWidget();
175   setupChatMonitor();
176   setupNickWidget();
177   setupInputWidget();
178   setupStatusBar();
179   setupToolBars();
180   setupSystray();
181   setupTitleSetter();
182   setupHotList();
183
184 #ifndef HAVE_KDE
185   QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
186   QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
187 #  ifdef HAVE_PHONON
188   QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
189 #  endif
190 #  ifdef HAVE_DBUS
191   QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
192 #  endif
193
194 #else /* HAVE_KDE */
195   QtUi::registerNotificationBackend(new KNotificationBackend(this));
196 #endif /* HAVE_KDE */
197
198 #ifdef HAVE_INDICATEQT
199   QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
200 #endif
201
202   connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
203
204   setDisconnectedState();  // Disable menus and stuff
205
206 #ifdef HAVE_KDE
207   setAutoSaveSettings();
208 #endif
209
210   // restore mainwin state
211   QtUiSettings s;
212   restoreStateFromSettings(s);
213
214   // restore locked state of docks
215   QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
216
217   CoreConnection *conn = Client::coreConnection();
218   if(!conn->connectToCore()) {
219     // No autoconnect selected (or no accounts)
220     showCoreConnectionDlg();
221   }
222 }
223
224 MainWin::~MainWin() {
225
226 }
227
228 void MainWin::quit() {
229   QtUiSettings s;
230   saveStateToSettings(s);
231   saveLayout();
232   QApplication::quit();
233 }
234
235 void MainWin::saveStateToSettings(UiSettings &s) {
236   s.setValue("MainWinSize", _normalSize);
237   s.setValue("MainWinPos", _normalPos);
238   s.setValue("MainWinState", saveState());
239   s.setValue("MainWinGeometry", saveGeometry());
240   s.setValue("MainWinMinimized", isMinimized());
241   s.setValue("MainWinMaximized", isMaximized());
242   s.setValue("MainWinHidden", !isVisible());
243
244 #ifdef HAVE_KDE
245   saveAutoSaveSettings();
246 #endif
247 }
248
249 void MainWin::restoreStateFromSettings(UiSettings &s) {
250   _normalSize = s.value("MainWinSize", size()).toSize();
251   _normalPos = s.value("MainWinPos", pos()).toPoint();
252   bool maximized = s.value("MainWinMaximized", false).toBool();
253
254 #ifndef HAVE_KDE
255   restoreGeometry(s.value("MainWinGeometry").toByteArray());
256
257   if(maximized) {
258     // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
259     resize(_normalSize);
260     move(_normalPos);
261   }
262
263   restoreState(s.value("MainWinState").toByteArray());
264
265 #else
266   move(_normalPos);
267 #endif
268
269   if(s.value("MainWinHidden").toBool())
270     hideToTray();
271   else if(s.value("MainWinMinimized").toBool())
272     showMinimized();
273   else if(maximized)
274     showMaximized();
275   else
276     show();
277 }
278
279 void MainWin::updateIcon() {
280 #ifdef Q_WS_MAC
281   const int size = 128;
282 #else
283   const int size = 48;
284 #endif
285
286   QPixmap icon;
287   if(Client::isConnected())
288     icon = DesktopIcon("quassel", size);
289   else
290     icon = DesktopIcon("quassel_inactive", size);
291   setWindowIcon(icon);
292   qApp->setWindowIcon(icon);
293 }
294
295 void MainWin::setupActions() {
296   ActionCollection *coll = QtUi::actionCollection("General");
297   // File
298   coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
299                                              this, SLOT(showCoreConnectionDlg())));
300   coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
301                                                 Client::instance(), SLOT(disconnectFromCore())));
302   coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
303                                           this, SLOT(showCoreInfoDlg())));
304   coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
305                                               this, SLOT(on_actionConfigureNetworks_triggered())));
306   coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
307                                       this, SLOT(quit()), tr("Ctrl+Q")));
308
309   // View
310   coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
311                                              this, SLOT(on_actionConfigureViews_triggered())));
312
313   QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
314   lockAct->setCheckable(true);
315   connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
316
317   coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
318                                                 0, 0, QKeySequence::Find))->setCheckable(true);
319   coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
320                                             this, SLOT(showAwayLog())));
321   coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
322                                                 0, 0, tr("Ctrl+M")))->setCheckable(true);
323
324   coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
325                                                 0, 0))->setCheckable(true);
326
327   // Settings
328   coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
329                                                   this, SLOT(showSettingsDlg()), tr("F7")));
330
331   // Help
332   coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
333                                               this, SLOT(showAboutDlg())));
334   coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
335                                          qApp, SLOT(aboutQt())));
336   coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
337                                        this, SLOT(on_actionDebugNetworkModel_triggered())));
338   coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
339                                        this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
340   coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
341                                        this, SLOT(on_actionDebugMessageModel_triggered())));
342   coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
343                                        this, SLOT(on_actionDebugHotList_triggered())));
344   coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
345                                        this, SLOT(on_actionDebugLog_triggered())));
346   coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
347                                        QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
348
349   // Navigation
350   coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
351                                               this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
352 }
353
354 void MainWin::setupMenus() {
355   ActionCollection *coll = QtUi::actionCollection("General");
356
357   _fileMenu = menuBar()->addMenu(tr("&File"));
358
359   static const QStringList coreActions = QStringList()
360     << "ConnectCore" << "DisconnectCore" << "CoreInfo";
361
362   QAction *coreAction;
363   foreach(QString actionName, coreActions) {
364     coreAction = coll->action(actionName);
365     _fileMenu->addAction(coreAction);
366     flagRemoteCoreOnly(coreAction);
367   }
368   flagRemoteCoreOnly(_fileMenu->addSeparator());
369
370   _networksMenu = _fileMenu->addMenu(tr("&Networks"));
371   _networksMenu->addAction(coll->action("ConfigureNetworks"));
372   _networksMenu->addSeparator();
373   _fileMenu->addSeparator();
374   _fileMenu->addAction(coll->action("Quit"));
375
376   _viewMenu = menuBar()->addMenu(tr("&View"));
377   _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
378   _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
379   _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
380   _viewMenu->addSeparator();
381
382   _viewMenu->addAction(coll->action("ToggleMenuBar"));
383   _viewMenu->addAction(coll->action("ToggleStatusBar"));
384   _viewMenu->addAction(coll->action("ToggleSearchBar"));
385
386   coreAction = coll->action("ShowAwayLog");
387   flagRemoteCoreOnly(coreAction);
388   _viewMenu->addAction(coreAction);
389
390   _viewMenu->addSeparator();
391   _viewMenu->addAction(coll->action("LockLayout"));
392
393   _settingsMenu = menuBar()->addMenu(tr("&Settings"));
394 #ifdef HAVE_KDE
395   _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
396   _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
397 #endif
398   _settingsMenu->addAction(coll->action("ConfigureQuassel"));
399
400   _helpMenu = menuBar()->addMenu(tr("&Help"));
401   _helpMenu->addAction(coll->action("AboutQuassel"));
402 #ifndef HAVE_KDE
403   _helpMenu->addAction(coll->action("AboutQt"));
404 #else
405   _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
406 #endif
407   _helpMenu->addSeparator();
408   _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
409   _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
410   _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
411   _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
412   _helpDebugMenu->addAction(coll->action("DebugHotList"));
413   _helpDebugMenu->addAction(coll->action("DebugLog"));
414   _helpDebugMenu->addSeparator();
415   _helpDebugMenu->addAction(coll->action("ReloadStyle"));
416
417   // Toggle visibility
418   QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
419
420   QtUiSettings uiSettings;
421   bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
422   showMenuBar->setChecked(enabled);
423   enabled ? menuBar()->show() : menuBar()->hide();
424
425   connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
426   connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
427 }
428
429 void MainWin::setupBufferWidget() {
430   _bufferWidget = new BufferWidget(this);
431   _bufferWidget->setModel(Client::bufferModel());
432   _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
433   setCentralWidget(_bufferWidget);
434 }
435
436 void MainWin::addBufferView(int bufferViewConfigId) {
437   addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
438 }
439
440 void MainWin::addBufferView(ClientBufferViewConfig *config) {
441   if(!config)
442     return;
443
444   config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
445   BufferViewDock *dock = new BufferViewDock(config, this);
446
447   //create the view and initialize it's filter
448   BufferView *view = new BufferView(dock);
449   view->setFilteredModel(Client::bufferModel(), config);
450   view->installEventFilter(_inputWidget); // for key presses
451
452   Client::bufferModel()->synchronizeView(view);
453
454   dock->setWidget(view);
455   dock->setVisible(_layoutLoaded); // don't show before state has been restored
456
457   addDockWidget(Qt::LeftDockWidgetArea, dock);
458   _bufferViewsMenu->addAction(dock->toggleViewAction());
459
460   connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
461   _bufferViews.append(dock);
462 }
463
464 void MainWin::removeBufferView(int bufferViewConfigId) {
465   QVariant actionData;
466   BufferViewDock *dock;
467   foreach(QAction *action, _bufferViewsMenu->actions()) {
468     actionData = action->data();
469     if(!actionData.isValid())
470       continue;
471
472     dock = qobject_cast<BufferViewDock *>(action->parent());
473     if(dock && actionData.toInt() == bufferViewConfigId) {
474       removeAction(action);
475       _bufferViews.removeAll(dock);
476       Client::bufferViewOverlay()->removeView(dock->bufferViewId());
477       dock->deleteLater();
478     }
479   }
480 }
481
482 void MainWin::bufferViewToggled(bool enabled) {
483   QAction *action = qobject_cast<QAction *>(sender());
484   Q_ASSERT(action);
485   BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
486   Q_ASSERT(dock);
487
488   // Make sure we don't toggle backlog fetch for a view we've already removed
489   if(!_bufferViews.contains(dock))
490     return;
491
492   if(enabled) {
493     Client::bufferViewOverlay()->addView(dock->bufferViewId());
494     BufferViewConfig *config = dock->config();
495     if(config && config->isInitialized()) {
496       BufferIdList buffers;
497       if(config->networkId().isValid()) {
498         foreach(BufferId bufferId, config->bufferList()) {
499           if(Client::networkModel()->networkId(bufferId) == config->networkId())
500             buffers << bufferId;
501         }
502         foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
503           if(Client::networkModel()->networkId(bufferId) == config->networkId())
504             buffers << bufferId;
505         }
506       } else {
507         buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
508       }
509       Client::backlogManager()->checkForBacklog(buffers);
510     }
511   } else {
512     Client::bufferViewOverlay()->removeView(dock->bufferViewId());
513   }
514 }
515
516 BufferView *MainWin::allBuffersView() const {
517   // "All Buffers" is always the first dock created
518   if(_bufferViews.count() > 0)
519     return _bufferViews[0]->bufferView();
520   return 0;
521 }
522
523 void MainWin::showNotificationsDlg() {
524   SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
525   dlg.exec();
526 }
527
528 void MainWin::on_actionConfigureNetworks_triggered() {
529   SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
530   dlg.exec();
531 }
532
533 void MainWin::on_actionConfigureViews_triggered() {
534   SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
535   dlg.exec();
536 }
537
538 void MainWin::on_actionLockLayout_toggled(bool lock) {
539   QList<VerticalDock *> docks = findChildren<VerticalDock *>();
540   foreach(VerticalDock *dock, docks) {
541     dock->showTitle(!lock);
542   }
543   if(Client::bufferViewManager()) {
544     foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
545       config->setLocked(lock);
546     }
547   }
548   QtUiSettings().setValue("LockLayout", lock);
549 }
550
551 void MainWin::setupNickWidget() {
552   // create nick dock
553   NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
554   nickDock->setObjectName("NickDock");
555   nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
556
557   _nickListWidget = new NickListWidget(nickDock);
558   nickDock->setWidget(_nickListWidget);
559
560   addDockWidget(Qt::RightDockWidgetArea, nickDock);
561   _viewMenu->addAction(nickDock->toggleViewAction());
562   nickDock->toggleViewAction()->setText(tr("Show Nick List"));
563
564   // See NickListDock::NickListDock();
565   // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
566
567   // attach the NickListWidget to the BufferModel and the default selection
568   _nickListWidget->setModel(Client::bufferModel());
569   _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
570 }
571
572 void MainWin::setupChatMonitor() {
573   VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
574   dock->setObjectName("ChatMonitorDock");
575
576   ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
577   ChatMonitorView *chatView = new ChatMonitorView(filter, this);
578   chatView->show();
579   dock->setWidget(chatView);
580   dock->hide();
581
582   addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
583   _viewMenu->addAction(dock->toggleViewAction());
584   dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
585 }
586
587 void MainWin::setupInputWidget() {
588   VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
589   dock->setObjectName("InputDock");
590
591   _inputWidget = new InputWidget(dock);
592   dock->setWidget(_inputWidget);
593
594   addDockWidget(Qt::BottomDockWidgetArea, dock);
595
596   _viewMenu->addAction(dock->toggleViewAction());
597   dock->toggleViewAction()->setText(tr("Show Input Line"));
598
599   _inputWidget->setModel(Client::bufferModel());
600   _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
601
602   _bufferWidget->setFocusProxy(_inputWidget);
603
604   _inputWidget->inputLine()->installEventFilter(_bufferWidget);
605 }
606
607 void MainWin::setupTopicWidget() {
608   VerticalDock *dock = new VerticalDock(tr("Topic"), this);
609   dock->setObjectName("TopicDock");
610   TopicWidget *topicwidget = new TopicWidget(dock);
611
612   dock->setWidget(topicwidget);
613
614   topicwidget->setModel(Client::bufferModel());
615   topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
616
617   addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
618
619   _viewMenu->addAction(dock->toggleViewAction());
620   dock->toggleViewAction()->setText(tr("Show Topic Line"));
621 }
622
623 void MainWin::setupTitleSetter() {
624   _titleSetter.setModel(Client::bufferModel());
625   _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
626 }
627
628 void MainWin::setupStatusBar() {
629   // MessageProcessor progress
630   statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
631
632   // Connection state
633   _coreConnectionStatusWidget->update();
634   statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
635
636   // Core Lag:
637   updateLagIndicator();
638   statusBar()->addPermanentWidget(coreLagLabel);
639   coreLagLabel->hide();
640   connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
641
642   // SSL indicator
643   sslLabel->setPixmap(QPixmap());
644   statusBar()->addPermanentWidget(sslLabel);
645   sslLabel->hide();
646
647   QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
648
649   QtUiSettings uiSettings;
650
651   bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
652   showStatusbar->setChecked(enabled);
653   enabled ? statusBar()->show() : statusBar()->hide();
654
655   connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
656   connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
657
658   connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
659 }
660
661 void MainWin::setupHotList() {
662   FlatProxyModel *flatProxy = new FlatProxyModel(this);
663   flatProxy->setSourceModel(Client::bufferModel());
664   _bufferHotList = new BufferHotListFilter(flatProxy);
665 }
666
667 void MainWin::saveMenuBarStatus(bool enabled) {
668   QtUiSettings uiSettings;
669   uiSettings.setValue("ShowMenuBar", enabled);
670 }
671
672 void MainWin::saveStatusBarStatus(bool enabled) {
673   QtUiSettings uiSettings;
674   uiSettings.setValue("ShowStatusBar", enabled);
675 }
676
677 void MainWin::setupSystray() {
678   _systemTray = new SystemTray(this);
679 }
680
681 void MainWin::setupToolBars() {
682   connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
683           QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
684   connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
685           QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
686
687 #ifdef Q_WS_MAC
688   setUnifiedTitleAndToolBarOnMac(true);
689 #endif
690
691 #ifdef HAVE_KDE
692   _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
693 #else
694   _mainToolBar = new QToolBar(this);
695   _mainToolBar->setObjectName("MainToolBar");
696 #endif
697   _mainToolBar->setWindowTitle(tr("Main Toolbar"));
698   addToolBar(_mainToolBar);
699
700   QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
701   _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
702 }
703
704 void MainWin::connectedToCore() {
705   Q_CHECK_PTR(Client::bufferViewManager());
706   connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
707   connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
708   connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
709
710   setConnectedState();
711 }
712
713 void MainWin::setConnectedState() {
714   ActionCollection *coll = QtUi::actionCollection("General");
715
716   coll->action("ConnectCore")->setEnabled(false);
717   coll->action("DisconnectCore")->setEnabled(true);
718   coll->action("CoreInfo")->setEnabled(true);
719
720   foreach(QAction *action, _fileMenu->actions()) {
721     if(isRemoteCoreOnly(action))
722       action->setVisible(!Client::internalCore());
723   }
724
725   disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
726   disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
727   disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
728   if(!Client::internalCore()) {
729     connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
730     connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
731     connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
732   }
733
734   // _viewMenu->setEnabled(true);
735   if(!Client::internalCore())
736     statusBar()->showMessage(tr("Connected to core."));
737   else
738     statusBar()->clearMessage();
739
740   if(Client::signalProxy()->isSecure()) {
741     sslLabel->setPixmap(SmallIcon("security-high"));
742   } else {
743     sslLabel->setPixmap(SmallIcon("security-low"));
744   }
745
746   sslLabel->setVisible(!Client::internalCore());
747   coreLagLabel->setVisible(!Client::internalCore());
748   updateIcon();
749   systemTray()->setState(SystemTray::Active);
750
751   if(Client::networkIds().isEmpty()) {
752     IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
753     wizard->show();
754   }
755 }
756
757 void MainWin::loadLayout() {
758   QtUiSettings s;
759   int accountId = Client::currentCoreAccount().accountId().toInt();
760   QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
761   if(state.isEmpty()) {
762     // Make sure that the default bufferview is shown
763     if(_bufferViews.count())
764       _bufferViews.at(0)->show();
765     return;
766   }
767
768   restoreState(state, accountId);
769   _layoutLoaded = true;
770 }
771
772 void MainWin::saveLayout() {
773   QtUiSettings s;
774   int accountId = Client::currentCoreAccount().accountId().toInt();
775   if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
776 }
777
778 void MainWin::updateLagIndicator(int lag) {
779   QString text = tr("Core Lag: %1");
780   if(lag == -1)
781     text = text.arg('-');
782   else
783     text = text.arg("%1 msec").arg(lag);
784   coreLagLabel->setText(text);
785 }
786
787 void MainWin::disconnectedFromCore() {
788   // save core specific layout and remove bufferviews;
789   saveLayout();
790   _layoutLoaded = false;
791
792   QVariant actionData;
793   BufferViewDock *dock;
794   foreach(QAction *action, _bufferViewsMenu->actions()) {
795     actionData = action->data();
796     if(!actionData.isValid())
797       continue;
798
799     dock = qobject_cast<BufferViewDock *>(action->parent());
800     if(dock && actionData.toInt() != -1) {
801       removeAction(action);
802       _bufferViews.removeAll(dock);
803       Client::bufferViewOverlay()->removeView(dock->bufferViewId());
804       dock->deleteLater();
805     }
806   }
807
808   QtUiSettings s;
809   restoreState(s.value("MainWinState").toByteArray());
810   setDisconnectedState();
811 }
812
813 void MainWin::setDisconnectedState() {
814   ActionCollection *coll = QtUi::actionCollection("General");
815   //ui.menuCore->setEnabled(false);
816   coll->action("ConnectCore")->setEnabled(true);
817   coll->action("DisconnectCore")->setEnabled(false);
818   coll->action("CoreInfo")->setEnabled(false);
819   //_viewMenu->setEnabled(false);
820   statusBar()->showMessage(tr("Not connected to core."));
821   sslLabel->setPixmap(QPixmap());
822   sslLabel->hide();
823   updateLagIndicator();
824   coreLagLabel->hide();
825   if(_msgProcessorStatusWidget)
826     _msgProcessorStatusWidget->setProgress(0, 0);
827   updateIcon();
828   systemTray()->setState(SystemTray::Inactive);
829 }
830
831 void MainWin::startInternalCore() {
832
833 }
834
835 void MainWin::showCoreConnectionDlg() {
836   CoreConnectDlg dlg(this);
837   if(dlg.exec() == QDialog::Accepted) {
838     AccountId accId = dlg.selectedAccount();
839     if(accId.isValid())
840       Client::coreConnection()->connectToCore(accId);
841   }
842 }
843
844 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
845   Q_UNUSED(errorMessage)
846   CoreConnectAuthDlg dlg(account, this);
847   *valid = (dlg.exec() == QDialog::Accepted);
848 }
849
850 void MainWin::showChannelList(NetworkId netId) {
851   ChannelListDlg *channelListDlg = new ChannelListDlg();
852
853   if(!netId.isValid()) {
854     QAction *action = qobject_cast<QAction *>(sender());
855     if(action)
856       netId = action->data().value<NetworkId>();
857   }
858
859   channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
860   channelListDlg->setNetwork(netId);
861   channelListDlg->show();
862 }
863
864 void MainWin::showIgnoreList(QString newRule) {
865   SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
866   // prepare config dialog for new rule
867   if(!newRule.isEmpty())
868     qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
869   dlg.exec();
870 }
871
872 void MainWin::showCoreInfoDlg() {
873   CoreInfoDlg(this).exec();
874 }
875
876 void MainWin::showAwayLog() {
877   if(_awayLog)
878     return;
879   AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
880   _awayLog = new AwayLogView(filter, 0);
881   filter->setParent(_awayLog);
882   connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
883   _awayLog->setAttribute(Qt::WA_DeleteOnClose);
884   _awayLog->show();
885 }
886
887 void MainWin::awayLogDestroyed() {
888   _awayLog = 0;
889 }
890
891 void MainWin::showSettingsDlg() {
892   SettingsDlg *dlg = new SettingsDlg();
893
894   //Category: Interface
895   dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
896   dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
897   dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
898   dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
899   dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
900   dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
901   dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
902   dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
903   dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
904   dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
905
906   //Category: Misc
907   dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
908   dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
909   dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
910   dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
911   dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
912   dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
913
914   if(Quassel::runMode() != Quassel::Monolithic) {
915     dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
916   }
917
918   dlg->show();
919 }
920
921 void MainWin::showAboutDlg() {
922   AboutDlg(this).exec();
923 }
924
925 #ifdef HAVE_KDE
926 void MainWin::showShortcutsDlg() {
927   KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
928 }
929 #endif
930
931 /********************************************************************************************************/
932
933 bool MainWin::event(QEvent *event) {
934   if(event->type() == QEvent::WindowActivate) {
935     BufferId buffer = Client::bufferModel()->currentBuffer();
936     if(buffer.isValid())
937       QtUi::closeNotifications(buffer);
938   }
939   return QMainWindow::event(event);
940 }
941
942 void MainWin::moveEvent(QMoveEvent *event) {
943   if(!(windowState() & Qt::WindowMaximized))
944     _normalPos = event->pos();
945
946   QMainWindow::moveEvent(event);
947 }
948
949 void MainWin::resizeEvent(QResizeEvent *event) {
950   if(!(windowState() & Qt::WindowMaximized))
951     _normalSize = event->size();
952
953   QMainWindow::resizeEvent(event);
954 }
955
956 void MainWin::closeEvent(QCloseEvent *event) {
957   QtUiSettings s;
958   QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
959   Q_ASSERT(app);
960   if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
961     hideToTray();
962     event->ignore();
963   } else {
964     event->accept();
965     quit();
966   }
967 }
968
969 void MainWin::changeEvent(QEvent *event) {
970 #ifdef Q_WS_WIN
971   if(event->type() == QEvent::ActivationChange)
972     dwTickCount = GetTickCount();  // needed for toggleMinimizedToTray()
973 #endif
974
975   QMainWindow::changeEvent(event);
976 }
977
978 void MainWin::hideToTray() {
979   if(!systemTray()->isSystemTrayAvailable()) {
980     qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
981     return;
982   }
983   hide();
984   systemTray()->setIconVisible();
985 }
986
987 void MainWin::toggleMinimizedToTray() {
988 #ifdef Q_WS_WIN
989   // the problem is that we lose focus when the systray icon is activated
990   // and we don't know the former active window
991   // therefore we watch for activation event and use our stopwatch :)
992   // courtesy: KSystemTrayIcon
993   if(GetTickCount() - dwTickCount >= 300)
994     // we weren't active in the last 300ms -> activate
995     forceActivated();
996   else
997     hideToTray();
998
999 #else
1000
1001   if(!isVisible() || isMinimized())
1002     // restore
1003     forceActivated();
1004   else
1005     hideToTray();
1006
1007 #endif
1008 }
1009
1010 void MainWin::forceActivated() {
1011 #ifdef HAVE_KDE
1012   show();
1013   KWindowSystem::forceActiveWindow(winId());
1014 #else
1015
1016 #ifdef Q_WS_X11
1017   // Bypass focus stealing prevention
1018   QX11Info::setAppUserTime(QX11Info::appTime());
1019 #endif
1020
1021   if(windowState() & Qt::WindowMinimized) {
1022     // restore
1023     setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
1024   }
1025
1026   // this does not actually work on all platforms... and causes more evil than good
1027   // move(frameGeometry().topLeft()); // avoid placement policies
1028   show();
1029   raise();
1030   activateWindow();
1031 #endif /* HAVE_KDE */
1032 }
1033
1034 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1035   Q_UNUSED(parent);
1036
1037   bool hasFocus = QApplication::activeWindow() != 0;
1038
1039   for(int i = start; i <= end; i++) {
1040     QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1041     if(!idx.isValid()) {
1042       qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1043       continue;
1044     }
1045     Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1046     if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1047       continue;
1048
1049     BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1050     BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1051
1052     if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1053       continue;
1054
1055     if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1056       && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1057                                                                              Client::networkModel()->networkName(bufId))))
1058     {
1059       QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1060       QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1061       QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1062       AbstractNotificationBackend::NotificationType type;
1063
1064       if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1065         type = AbstractNotificationBackend::PrivMsg;
1066       else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1067         type = AbstractNotificationBackend::PrivMsgFocused;
1068       else if(flags & Message::Highlight && !hasFocus)
1069         type = AbstractNotificationBackend::Highlight;
1070       else
1071         type = AbstractNotificationBackend::HighlightFocused;
1072
1073       QtUi::invokeNotification(bufId, type, sender, contents);
1074     }
1075   }
1076 }
1077
1078 void MainWin::currentBufferChanged(BufferId buffer) {
1079   if(buffer.isValid())
1080     QtUi::closeNotifications(buffer);
1081 }
1082
1083 void MainWin::clientNetworkCreated(NetworkId id) {
1084   const Network *net = Client::network(id);
1085   QAction *act = new QAction(net->networkName(), this);
1086   act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1087   act->setData(QVariant::fromValue<NetworkId>(id));
1088   connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1089   connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1090
1091   QAction *beforeAction = 0;
1092   foreach(QAction *action, _networksMenu->actions()) {
1093     if(!action->data().isValid())  // ignore stock actions
1094       continue;
1095     if(net->networkName().localeAwareCompare(action->text()) < 0) {
1096       beforeAction = action;
1097       break;
1098     }
1099   }
1100   _networksMenu->insertAction(beforeAction, act);
1101 }
1102
1103 void MainWin::clientNetworkUpdated() {
1104   const Network *net = qobject_cast<const Network *>(sender());
1105   if(!net)
1106     return;
1107
1108   QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1109   if(!action)
1110     return;
1111
1112   action->setText(net->networkName());
1113
1114   switch(net->connectionState()) {
1115   case Network::Initialized:
1116     action->setIcon(SmallIcon("network-connect"));
1117     break;
1118   case Network::Disconnected:
1119     action->setIcon(SmallIcon("network-disconnect"));
1120     break;
1121   default:
1122     action->setIcon(SmallIcon("network-wired"));
1123   }
1124 }
1125
1126 void MainWin::clientNetworkRemoved(NetworkId id) {
1127   QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1128   if(!action)
1129     return;
1130
1131   action->deleteLater();
1132 }
1133
1134 void MainWin::connectOrDisconnectFromNet() {
1135   QAction *act = qobject_cast<QAction *>(sender());
1136   if(!act) return;
1137   const Network *net = Client::network(act->data().value<NetworkId>());
1138   if(!net) return;
1139   if(net->connectionState() == Network::Disconnected) net->requestConnect();
1140   else net->requestDisconnect();
1141 }
1142
1143 void MainWin::on_jumpHotBuffer_triggered() {
1144   if(!_bufferHotList->rowCount())
1145     return;
1146
1147   QModelIndex topIndex = _bufferHotList->index(0, 0);
1148   BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1149   Client::bufferModel()->switchToBuffer(bufferId);
1150 }
1151
1152 void MainWin::on_actionDebugNetworkModel_triggered() {
1153   QTreeView *view = new QTreeView;
1154   view->setAttribute(Qt::WA_DeleteOnClose);
1155   view->setWindowTitle("Debug NetworkModel View");
1156   view->setModel(Client::networkModel());
1157   view->setColumnWidth(0, 250);
1158   view->setColumnWidth(1, 250);
1159   view->setColumnWidth(2, 80);
1160   view->resize(610, 300);
1161   view->show();
1162 }
1163
1164 void MainWin::on_actionDebugHotList_triggered() {
1165   QTreeView *view = new QTreeView;
1166   view->setAttribute(Qt::WA_DeleteOnClose);
1167   view->setModel(_bufferHotList);
1168   view->show();
1169 }
1170
1171 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1172   DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1173   overlay->setAttribute(Qt::WA_DeleteOnClose);
1174   overlay->show();
1175 }
1176
1177 void MainWin::on_actionDebugMessageModel_triggered() {
1178   QTableView *view = new QTableView(0);
1179   DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1180   filter->setSourceModel(Client::messageModel());
1181   view->setModel(filter);
1182   view->setAttribute(Qt::WA_DeleteOnClose, true);
1183   view->verticalHeader()->hide();
1184   view->horizontalHeader()->setStretchLastSection(true);
1185   view->show();
1186 }
1187
1188 void MainWin::on_actionDebugLog_triggered() {
1189   DebugLogWidget *logWidget = new DebugLogWidget(0);
1190   logWidget->show();
1191 }
1192
1193 void MainWin::showStatusBarMessage(const QString &message) {
1194   statusBar()->showMessage(message, 10000);
1195 }
1196