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