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