Introduce settingspage for editing core accounts
[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 "clientsyncer.h"
55 #include "clientbacklogmanager.h"
56 #include "clientbufferviewconfig.h"
57 #include "clientbufferviewmanager.h"
58 #include "clientignorelistmanager.h"
59 #include "coreinfodlg.h"
60 #include "coreconnectdlg.h"
61 #include "contextmenuactionprovider.h"
62 #include "debugbufferviewoverlay.h"
63 #include "debuglogwidget.h"
64 #include "debugmessagemodelfilter.h"
65 #include "flatproxymodel.h"
66 #include "iconloader.h"
67 #include "inputwidget.h"
68 #include "irclistmodel.h"
69 #include "ircconnectionwizard.h"
70 #include "jumpkeyhandler.h"
71 #include "msgprocessorstatuswidget.h"
72 #include "nicklistwidget.h"
73 #include "qtuiapplication.h"
74 #include "qtuimessageprocessor.h"
75 #include "qtuisettings.h"
76 #include "qtuistyle.h"
77 #include "settingsdlg.h"
78 #include "settingspagedlg.h"
79 #include "systemtray.h"
80 #include "toolbaractionprovider.h"
81 #include "topicwidget.h"
82 #include "verticaldock.h"
83
84 #ifndef HAVE_KDE
85 #  ifdef HAVE_DBUS
86 #    include "desktopnotificationbackend.h"
87 #  endif
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_INDICATEQT
98   #include "indicatornotificationbackend.h"
99 #endif
100
101 #include "settingspages/aliasessettingspage.h"
102 #include "settingspages/appearancesettingspage.h"
103 #include "settingspages/backlogsettingspage.h"
104 #include "settingspages/bufferviewsettingspage.h"
105 #include "settingspages/chatmonitorsettingspage.h"
106 #include "settingspages/chatviewsettingspage.h"
107 #include "settingspages/connectionsettingspage.h"
108 #include "settingspages/coreaccountsettingspage.h"
109 #include "settingspages/generalsettingspage.h"
110 #include "settingspages/highlightsettingspage.h"
111 #include "settingspages/identitiessettingspage.h"
112 #include "settingspages/ignorelistsettingspage.h"
113 #include "settingspages/inputwidgetsettingspage.h"
114 #include "settingspages/itemviewsettingspage.h"
115 #include "settingspages/networkssettingspage.h"
116 #include "settingspages/notificationssettingspage.h"
117 #include "settingspages/topicwidgetsettingspage.h"
118
119 MainWin::MainWin(QWidget *parent)
120 #ifdef HAVE_KDE
121   : KMainWindow(parent),
122   _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
123 #else
124   : QMainWindow(parent),
125 #endif
126     coreLagLabel(new QLabel()),
127     sslLabel(new QLabel()),
128     msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
129     _titleSetter(this),
130     _awayLog(0),
131     _layoutLoaded(false)
132 {
133 #ifdef Q_WS_WIN
134   dwTickCount = 0;
135 #endif
136
137   QtUiSettings uiSettings;
138   QString style = uiSettings.value("Style", QString()).toString();
139   if(!style.isEmpty()) {
140     QApplication::setStyle(style);
141   }
142
143   QApplication::setQuitOnLastWindowClosed(false);
144
145   setWindowTitle("Quassel IRC");
146   setWindowIconText("Quassel IRC");
147   updateIcon();
148
149   installEventFilter(new JumpKeyHandler(this));
150 }
151
152 void MainWin::init() {
153   connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
154   connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
155   connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
156            SLOT(messagesInserted(const QModelIndex &, int, int)));
157   connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
158   connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
159
160   // Setup Dock Areas
161   setDockNestingEnabled(true);
162   setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
163   setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
164   setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
165   setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
166
167   // Order is sometimes important
168   setupActions();
169   setupBufferWidget();
170   setupMenus();
171   setupTopicWidget();
172   setupChatMonitor();
173   setupNickWidget();
174   setupInputWidget();
175   setupStatusBar();
176   setupToolBars();
177   setupSystray();
178   setupTitleSetter();
179   setupHotList();
180
181 #ifndef HAVE_KDE
182   QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
183   QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
184 #  ifdef HAVE_PHONON
185   QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
186 #  endif
187 #  ifdef HAVE_DBUS
188   QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
189 #  endif
190
191 #else /* HAVE_KDE */
192   QtUi::registerNotificationBackend(new KNotificationBackend(this));
193 #endif /* HAVE_KDE */
194
195 #ifdef HAVE_INDICATEQT
196   QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
197 #endif
198
199   connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
200
201   setDisconnectedState();  // Disable menus and stuff
202
203 #ifdef HAVE_KDE
204   setAutoSaveSettings();
205 #endif
206
207   // restore mainwin state
208   QtUiSettings s;
209   restoreStateFromSettings(s);
210
211   // restore locked state of docks
212   QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
213
214   if(Quassel::runMode() != Quassel::Monolithic) {
215     showCoreConnectionDlg(true); // autoconnect if appropriate
216   } else {
217     startInternalCore();
218   }
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
652 void MainWin::setupHotList() {
653   FlatProxyModel *flatProxy = new FlatProxyModel(this);
654   flatProxy->setSourceModel(Client::bufferModel());
655   _bufferHotList = new BufferHotListFilter(flatProxy);
656 }
657
658 void MainWin::saveMenuBarStatus(bool enabled) {
659   QtUiSettings uiSettings;
660   uiSettings.setValue("ShowMenuBar", enabled);
661 }
662
663 void MainWin::saveStatusBarStatus(bool enabled) {
664   QtUiSettings uiSettings;
665   uiSettings.setValue("ShowStatusBar", enabled);
666 }
667
668 void MainWin::setupSystray() {
669   _systemTray = new SystemTray(this);
670 }
671
672 void MainWin::setupToolBars() {
673   connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
674           QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
675   connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
676           QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
677
678 #ifdef Q_WS_MAC
679   setUnifiedTitleAndToolBarOnMac(true);
680 #endif
681
682 #ifdef HAVE_KDE
683   _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
684 #else
685   _mainToolBar = new QToolBar(this);
686   _mainToolBar->setObjectName("MainToolBar");
687 #endif
688   _mainToolBar->setWindowTitle(tr("Main Toolbar"));
689   addToolBar(_mainToolBar);
690
691   QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
692   _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
693 }
694
695 void MainWin::connectedToCore() {
696   Q_CHECK_PTR(Client::bufferViewManager());
697   connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
698   connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
699   connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
700
701   setConnectedState();
702 }
703
704 void MainWin::setConnectedState() {
705   ActionCollection *coll = QtUi::actionCollection("General");
706
707   coll->action("ConnectCore")->setEnabled(false);
708   coll->action("DisconnectCore")->setEnabled(true);
709   coll->action("CoreInfo")->setEnabled(true);
710
711   foreach(QAction *action, _fileMenu->actions()) {
712     if(isRemoteCoreOnly(action))
713       action->setVisible(!Client::internalCore());
714   }
715
716   disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
717   disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
718   disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
719   if(!Client::internalCore()) {
720     connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
721     connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
722     connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
723   }
724
725   // _viewMenu->setEnabled(true);
726   if(!Client::internalCore())
727     statusBar()->showMessage(tr("Connected to core."));
728   else
729     statusBar()->clearMessage();
730
731   if(Client::signalProxy()->isSecure()) {
732     sslLabel->setPixmap(SmallIcon("security-high"));
733   } else {
734     sslLabel->setPixmap(SmallIcon("security-low"));
735   }
736
737   sslLabel->setVisible(!Client::internalCore());
738   coreLagLabel->setVisible(!Client::internalCore());
739   updateIcon();
740   systemTray()->setState(SystemTray::Active);
741
742   if(Client::networkIds().isEmpty()) {
743     IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
744     wizard->show();
745   }
746 }
747
748 void MainWin::loadLayout() {
749   QtUiSettings s;
750   int accountId = Client::currentCoreAccount().toInt();
751   QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
752   if(state.isEmpty()) {
753     // Make sure that the default bufferview is shown
754     if(_bufferViews.count())
755       _bufferViews.at(0)->show();
756     return;
757   }
758
759   restoreState(state, accountId);
760   _layoutLoaded = true;
761 }
762
763 void MainWin::saveLayout() {
764   QtUiSettings s;
765   int accountId = Client::currentCoreAccount().toInt();
766   if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
767 }
768
769 void MainWin::updateLagIndicator(int lag) {
770   QString text = tr("Core Lag: %1");
771   if(lag == -1)
772     text = text.arg('-');
773   else
774     text = text.arg("%1 msec").arg(lag);
775   coreLagLabel->setText(text);
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   sslLabel->setPixmap(QPixmap());
813   sslLabel->hide();
814   updateLagIndicator();
815   coreLagLabel->hide();
816   if(msgProcessorStatusWidget)
817     msgProcessorStatusWidget->setProgress(0, 0);
818   updateIcon();
819   systemTray()->setState(SystemTray::Inactive);
820 }
821
822 void MainWin::startInternalCore() {
823   ClientSyncer *syncer = new ClientSyncer();
824   Client::registerClientSyncer(syncer);
825   connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
826   syncer->useInternalCore();
827 }
828
829 void MainWin::showCoreConnectionDlg(bool autoConnect) {
830   CoreConnectDlg(autoConnect, this).exec();
831 }
832
833 void MainWin::showChannelList(NetworkId netId) {
834   ChannelListDlg *channelListDlg = new ChannelListDlg();
835
836   if(!netId.isValid()) {
837     QAction *action = qobject_cast<QAction *>(sender());
838     if(action)
839       netId = action->data().value<NetworkId>();
840   }
841
842   channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
843   channelListDlg->setNetwork(netId);
844   channelListDlg->show();
845 }
846
847 void MainWin::showIgnoreList(QString newRule) {
848   SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
849   // prepare config dialog for new rule
850   if(!newRule.isEmpty())
851     qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
852   dlg.exec();
853 }
854
855 void MainWin::showCoreInfoDlg() {
856   CoreInfoDlg(this).exec();
857 }
858
859 void MainWin::showAwayLog() {
860   if(_awayLog)
861     return;
862   AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
863   _awayLog = new AwayLogView(filter, 0);
864   filter->setParent(_awayLog);
865   connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
866   _awayLog->setAttribute(Qt::WA_DeleteOnClose);
867   _awayLog->show();
868 }
869
870 void MainWin::awayLogDestroyed() {
871   _awayLog = 0;
872 }
873
874 void MainWin::showSettingsDlg() {
875   SettingsDlg *dlg = new SettingsDlg();
876
877   //Category: Interface
878   dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
879   dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
880   dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
881   dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
882   dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
883   dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
884   dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
885   dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
886   dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
887   dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
888
889   //Category: Misc
890   dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
891   dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
892   dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
893   dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
894   dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
895   dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
896
897   if(Quassel::runMode() != Quassel::Monolithic) {
898     dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
899   }
900
901   dlg->show();
902 }
903
904 void MainWin::showAboutDlg() {
905   AboutDlg(this).exec();
906 }
907
908 #ifdef HAVE_KDE
909 void MainWin::showShortcutsDlg() {
910   KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
911 }
912 #endif
913
914 /********************************************************************************************************/
915
916 bool MainWin::event(QEvent *event) {
917   if(event->type() == QEvent::WindowActivate) {
918     BufferId buffer = Client::bufferModel()->currentBuffer();
919     if(buffer.isValid())
920       QtUi::closeNotifications(buffer);
921   }
922   return QMainWindow::event(event);
923 }
924
925 void MainWin::moveEvent(QMoveEvent *event) {
926   if(!(windowState() & Qt::WindowMaximized))
927     _normalPos = event->pos();
928
929   QMainWindow::moveEvent(event);
930 }
931
932 void MainWin::resizeEvent(QResizeEvent *event) {
933   if(!(windowState() & Qt::WindowMaximized))
934     _normalSize = event->size();
935
936   QMainWindow::resizeEvent(event);
937 }
938
939 void MainWin::closeEvent(QCloseEvent *event) {
940   QtUiSettings s;
941   QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
942   Q_ASSERT(app);
943   if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
944     hideToTray();
945     event->ignore();
946   } else {
947     event->accept();
948     quit();
949   }
950 }
951
952 void MainWin::changeEvent(QEvent *event) {
953 #ifdef Q_WS_WIN
954   if(event->type() == QEvent::ActivationChange)
955     dwTickCount = GetTickCount();  // needed for toggleMinimizedToTray()
956 #endif
957
958   QMainWindow::changeEvent(event);
959 }
960
961 void MainWin::hideToTray() {
962   if(!systemTray()->isSystemTrayAvailable()) {
963     qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
964     return;
965   }
966   hide();
967   systemTray()->setIconVisible();
968 }
969
970 void MainWin::toggleMinimizedToTray() {
971 #ifdef Q_WS_WIN
972   // the problem is that we lose focus when the systray icon is activated
973   // and we don't know the former active window
974   // therefore we watch for activation event and use our stopwatch :)
975   // courtesy: KSystemTrayIcon
976   if(GetTickCount() - dwTickCount >= 300)
977     // we weren't active in the last 300ms -> activate
978     forceActivated();
979   else
980     hideToTray();
981
982 #else
983
984   if(!isVisible() || isMinimized())
985     // restore
986     forceActivated();
987   else
988     hideToTray();
989
990 #endif
991 }
992
993 void MainWin::forceActivated() {
994 #ifdef HAVE_KDE
995   show();
996   KWindowSystem::forceActiveWindow(winId());
997 #else
998
999 #ifdef Q_WS_X11
1000   // Bypass focus stealing prevention
1001   QX11Info::setAppUserTime(QX11Info::appTime());
1002 #endif
1003
1004   if(windowState() & Qt::WindowMinimized) {
1005     // restore
1006     setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
1007   }
1008
1009   // this does not actually work on all platforms... and causes more evil than good
1010   // move(frameGeometry().topLeft()); // avoid placement policies
1011   show();
1012   raise();
1013   activateWindow();
1014 #endif /* HAVE_KDE */
1015 }
1016
1017 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1018   Q_UNUSED(parent);
1019
1020   bool hasFocus = QApplication::activeWindow() != 0;
1021
1022   for(int i = start; i <= end; i++) {
1023     QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1024     if(!idx.isValid()) {
1025       qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1026       continue;
1027     }
1028     Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1029     if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1030       continue;
1031
1032     BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1033     BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1034
1035     if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1036       continue;
1037
1038     if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1039       && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1040                                                                              Client::networkModel()->networkName(bufId))))
1041     {
1042       QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1043       QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1044       QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1045       AbstractNotificationBackend::NotificationType type;
1046
1047       if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1048         type = AbstractNotificationBackend::PrivMsg;
1049       else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1050         type = AbstractNotificationBackend::PrivMsgFocused;
1051       else if(flags & Message::Highlight && !hasFocus)
1052         type = AbstractNotificationBackend::Highlight;
1053       else
1054         type = AbstractNotificationBackend::HighlightFocused;
1055
1056       QtUi::invokeNotification(bufId, type, sender, contents);
1057     }
1058   }
1059 }
1060
1061 void MainWin::currentBufferChanged(BufferId buffer) {
1062   if(buffer.isValid())
1063     QtUi::closeNotifications(buffer);
1064 }
1065
1066 void MainWin::clientNetworkCreated(NetworkId id) {
1067   const Network *net = Client::network(id);
1068   QAction *act = new QAction(net->networkName(), this);
1069   act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1070   act->setData(QVariant::fromValue<NetworkId>(id));
1071   connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1072   connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1073
1074   QAction *beforeAction = 0;
1075   foreach(QAction *action, _networksMenu->actions()) {
1076     if(!action->data().isValid())  // ignore stock actions
1077       continue;
1078     if(net->networkName().localeAwareCompare(action->text()) < 0) {
1079       beforeAction = action;
1080       break;
1081     }
1082   }
1083   _networksMenu->insertAction(beforeAction, act);
1084 }
1085
1086 void MainWin::clientNetworkUpdated() {
1087   const Network *net = qobject_cast<const Network *>(sender());
1088   if(!net)
1089     return;
1090
1091   QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1092   if(!action)
1093     return;
1094
1095   action->setText(net->networkName());
1096
1097   switch(net->connectionState()) {
1098   case Network::Initialized:
1099     action->setIcon(SmallIcon("network-connect"));
1100     break;
1101   case Network::Disconnected:
1102     action->setIcon(SmallIcon("network-disconnect"));
1103     break;
1104   default:
1105     action->setIcon(SmallIcon("network-wired"));
1106   }
1107 }
1108
1109 void MainWin::clientNetworkRemoved(NetworkId id) {
1110   QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1111   if(!action)
1112     return;
1113
1114   action->deleteLater();
1115 }
1116
1117 void MainWin::connectOrDisconnectFromNet() {
1118   QAction *act = qobject_cast<QAction *>(sender());
1119   if(!act) return;
1120   const Network *net = Client::network(act->data().value<NetworkId>());
1121   if(!net) return;
1122   if(net->connectionState() == Network::Disconnected) net->requestConnect();
1123   else net->requestDisconnect();
1124 }
1125
1126 void MainWin::on_jumpHotBuffer_triggered() {
1127   if(!_bufferHotList->rowCount())
1128     return;
1129
1130   QModelIndex topIndex = _bufferHotList->index(0, 0);
1131   BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1132   Client::bufferModel()->switchToBuffer(bufferId);
1133 }
1134
1135 void MainWin::on_actionDebugNetworkModel_triggered() {
1136   QTreeView *view = new QTreeView;
1137   view->setAttribute(Qt::WA_DeleteOnClose);
1138   view->setWindowTitle("Debug NetworkModel View");
1139   view->setModel(Client::networkModel());
1140   view->setColumnWidth(0, 250);
1141   view->setColumnWidth(1, 250);
1142   view->setColumnWidth(2, 80);
1143   view->resize(610, 300);
1144   view->show();
1145 }
1146
1147 void MainWin::on_actionDebugHotList_triggered() {
1148   QTreeView *view = new QTreeView;
1149   view->setAttribute(Qt::WA_DeleteOnClose);
1150   view->setModel(_bufferHotList);
1151   view->show();
1152 }
1153
1154 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1155   DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1156   overlay->setAttribute(Qt::WA_DeleteOnClose);
1157   overlay->show();
1158 }
1159
1160 void MainWin::on_actionDebugMessageModel_triggered() {
1161   QTableView *view = new QTableView(0);
1162   DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1163   filter->setSourceModel(Client::messageModel());
1164   view->setModel(filter);
1165   view->setAttribute(Qt::WA_DeleteOnClose, true);
1166   view->verticalHeader()->hide();
1167   view->horizontalHeader()->setStretchLastSection(true);
1168   view->show();
1169 }
1170
1171 void MainWin::on_actionDebugLog_triggered() {
1172   DebugLogWidget *logWidget = new DebugLogWidget(0);
1173   logWidget->show();
1174 }
1175
1176 void MainWin::showStatusBarMessage(const QString &message) {
1177   statusBar()->showMessage(message, 10000);
1178 }
1179