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