1 /***************************************************************************
2 * Copyright (C) 2005-2013 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
24 #include <QMessageBox>
30 # include <KActionCollection>
33 # include <KShortcutsDialog>
34 # include <KStatusBar>
35 # include <KToggleFullScreenAction>
37 # include <KWindowSystem>
45 #include "awaylogfilter.h"
46 #include "awaylogview.h"
48 #include "actioncollection.h"
49 #include "bufferhotlistfilter.h"
50 #include "buffermodel.h"
51 #include "bufferview.h"
52 #include "bufferviewoverlay.h"
53 #include "bufferviewoverlayfilter.h"
54 #include "bufferwidget.h"
55 #include "channellistdlg.h"
56 #include "chatlinemodel.h"
57 #include "chatmonitorfilter.h"
58 #include "chatmonitorview.h"
61 #include "clientbacklogmanager.h"
62 #include "clientbufferviewconfig.h"
63 #include "clientbufferviewmanager.h"
64 #include "clientignorelistmanager.h"
65 #include "coreconfigwizard.h"
66 #include "coreconnectdlg.h"
67 #include "coreconnection.h"
68 #include "coreconnectionstatuswidget.h"
69 #include "coreinfodlg.h"
70 #include "contextmenuactionprovider.h"
71 #include "debugbufferviewoverlay.h"
72 #include "debuglogwidget.h"
73 #include "debugmessagemodelfilter.h"
74 #include "flatproxymodel.h"
75 #include "iconloader.h"
76 #include "inputwidget.h"
77 #include "irclistmodel.h"
78 #include "ircconnectionwizard.h"
79 #include "legacysystemtray.h"
80 #include "msgprocessorstatuswidget.h"
81 #include "nicklistwidget.h"
82 #include "qtuiapplication.h"
83 #include "qtuimessageprocessor.h"
84 #include "qtuisettings.h"
85 #include "qtuistyle.h"
86 #include "settingsdlg.h"
87 #include "settingspagedlg.h"
88 #include "statusnotifieritem.h"
89 #include "toolbaractionprovider.h"
90 #include "topicwidget.h"
91 #include "verticaldock.h"
95 # include "phononnotificationbackend.h"
97 # include "systraynotificationbackend.h"
98 # include "taskbarnotificationbackend.h"
100 # include "knotificationbackend.h"
101 #endif /* HAVE_KDE */
104 # include "sslinfodlg.h"
107 #ifdef HAVE_INDICATEQT
108 #include "indicatornotificationbackend.h"
111 #ifdef HAVE_NOTIFICATION_CENTER
112 #include "osxnotificationbackend.h"
115 #include "settingspages/aliasessettingspage.h"
116 #include "settingspages/appearancesettingspage.h"
117 #include "settingspages/backlogsettingspage.h"
118 #include "settingspages/bufferviewsettingspage.h"
119 #include "settingspages/chatmonitorsettingspage.h"
120 #include "settingspages/chatviewsettingspage.h"
121 #include "settingspages/connectionsettingspage.h"
122 #include "settingspages/coreaccountsettingspage.h"
123 #include "settingspages/coreconnectionsettingspage.h"
124 #include "settingspages/highlightsettingspage.h"
125 #include "settingspages/identitiessettingspage.h"
126 #include "settingspages/ignorelistsettingspage.h"
127 #include "settingspages/inputwidgetsettingspage.h"
128 #include "settingspages/itemviewsettingspage.h"
129 #include "settingspages/networkssettingspage.h"
130 #include "settingspages/notificationssettingspage.h"
131 #include "settingspages/topicwidgetsettingspage.h"
134 # include "settingspages/shortcutssettingspage.h"
137 MainWin::MainWin(QWidget *parent)
139 : KMainWindow(parent),
140 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
142 : QMainWindow(parent),
144 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
145 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
148 _layoutLoaded(false),
149 _activeBufferViewIndex(-1)
151 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
153 QtUiSettings uiSettings;
154 QString style = uiSettings.value("Style", QString()).toString();
155 if (!style.isEmpty()) {
156 QApplication::setStyle(style);
159 QApplication::setQuitOnLastWindowClosed(false);
161 setWindowTitle("Quassel IRC");
162 setWindowIconText("Quassel IRC");
169 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
170 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
171 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
172 SLOT(messagesInserted(const QModelIndex &, int, int)));
173 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
174 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
176 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
177 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
178 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
179 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
180 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
182 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
186 setDockNestingEnabled(true);
187 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
188 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
189 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
190 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
192 // Order is sometimes important
209 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
211 # ifndef QT_NO_SYSTEMTRAYICON
212 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
215 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
218 QtUi::registerNotificationBackend(new KNotificationBackend(this));
219 #endif /* HAVE_KDE */
221 #ifdef HAVE_INDICATEQT
222 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
225 #ifdef HAVE_NOTIFICATION_CENTER
226 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
229 // we assume that at this point, all configurable actions are defined!
230 QtUi::loadShortcuts();
232 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
234 setDisconnectedState(); // Disable menus and stuff
237 setAutoSaveSettings();
240 // restore mainwin state
242 restoreStateFromSettings(s);
244 // restore locked state of docks
245 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
247 CoreConnection *conn = Client::coreConnection();
248 if (!conn->connectToCore()) {
249 // No autoconnect selected (or no accounts)
250 showCoreConnectionDlg();
263 saveStateToSettings(s);
265 QApplication::quit();
269 void MainWin::saveStateToSettings(UiSettings &s)
271 s.setValue("MainWinSize", _normalSize);
272 s.setValue("MainWinPos", _normalPos);
273 s.setValue("MainWinState", saveState());
274 s.setValue("MainWinGeometry", saveGeometry());
275 s.setValue("MainWinMinimized", isMinimized());
276 s.setValue("MainWinMaximized", isMaximized());
277 s.setValue("MainWinHidden", !isVisible());
278 BufferId lastBufId = Client::bufferModel()->currentBuffer();
279 if (lastBufId.isValid())
280 s.setValue("LastUsedBufferId", lastBufId.toInt());
283 saveAutoSaveSettings();
288 void MainWin::restoreStateFromSettings(UiSettings &s)
290 _normalSize = s.value("MainWinSize", size()).toSize();
291 _normalPos = s.value("MainWinPos", pos()).toPoint();
292 bool maximized = s.value("MainWinMaximized", false).toBool();
295 restoreGeometry(s.value("MainWinGeometry").toByteArray());
298 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
303 restoreState(s.value("MainWinState").toByteArray());
309 if ((Quassel::isOptionSet("hidewindow")
310 || s.value("MainWinHidden").toBool())
311 && _systemTray->isSystemTrayAvailable())
312 QtUi::hideMainWidget();
313 else if (s.value("MainWinMinimized").toBool())
322 void MainWin::updateIcon()
325 const int size = 128;
331 if (Client::isConnected())
332 icon = DesktopIcon("quassel", size);
334 icon = DesktopIcon("quassel-inactive", size);
336 qApp->setWindowIcon(icon);
340 void MainWin::setupActions()
342 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
344 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
345 this, SLOT(showCoreConnectionDlg())));
346 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
347 Client::instance(), SLOT(disconnectFromCore())));
348 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
349 this, SLOT(showCoreInfoDlg())));
350 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
351 this, SLOT(on_actionConfigureNetworks_triggered())));
352 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
353 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
354 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
357 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
358 this, SLOT(on_actionConfigureViews_triggered())));
360 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
361 lockAct->setCheckable(true);
362 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
364 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
365 0, 0, QKeySequence::Find))->setCheckable(true);
366 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
367 this, SLOT(showAwayLog())));
368 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
369 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
371 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
372 0, 0))->setCheckable(true);
375 QAction *fullScreenAct = KStandardAction::fullScreen(this, SLOT(toggleFullscreen()), this, coll);
377 QAction *fullScreenAct = new Action(SmallIcon("view-fullscreen"), tr("&Full Screen Mode"), coll,
378 this, SLOT(toggleFullscreen()), QKeySequence(Qt::Key_F11));
379 fullScreenAct->setCheckable(true);
381 coll->addAction("ToggleFullscreen", fullScreenAct);
384 QAction *configureShortcutsAct = new Action(SmallIcon("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
385 this, SLOT(showShortcutsDlg()));
386 configureShortcutsAct->setMenuRole(QAction::NoRole);
387 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
390 QAction *configureQuasselAct = new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
391 this, SLOT(showSettingsDlg()));
392 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
394 QAction *configureQuasselAct = new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
395 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
397 coll->addAction("ConfigureQuassel", configureQuasselAct);
400 QAction *aboutQuasselAct = new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
401 this, SLOT(showAboutDlg()));
402 aboutQuasselAct->setMenuRole(QAction::AboutRole);
403 coll->addAction("AboutQuassel", aboutQuasselAct);
405 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
406 qApp, SLOT(aboutQt()));
407 aboutQtAct->setMenuRole(QAction::AboutQtRole);
408 coll->addAction("AboutQt", aboutQtAct);
409 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
410 this, SLOT(on_actionDebugNetworkModel_triggered())));
411 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
412 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
413 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
414 this, SLOT(on_actionDebugMessageModel_triggered())));
415 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
416 this, SLOT(on_actionDebugHotList_triggered())));
417 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
418 this, SLOT(on_actionDebugLog_triggered())));
419 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
420 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
422 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
423 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
426 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
428 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
429 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
433 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
434 const int jumpModifier = Qt::ControlModifier;
436 const int bindModifier = Qt::ControlModifier;
437 const int jumpModifier = Qt::AltModifier;
440 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
441 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
442 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
443 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
444 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
445 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
446 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
447 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
448 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
449 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
450 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
451 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
452 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
453 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
454 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
455 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
456 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
457 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
458 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
459 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
461 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
462 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
463 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
464 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
465 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
466 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
467 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
468 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
469 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
470 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
471 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
472 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
473 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
474 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
475 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
476 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
477 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
478 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
479 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
480 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
483 coll->addAction("NextBufferView", new Action(SmallIcon("go-next-view"), tr("Activate Next Chat List"), coll,
484 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
485 coll->addAction("PreviousBufferView", new Action(SmallIcon("go-previous-view"), tr("Activate Previous Chat List"), coll,
486 this, SLOT(previousBufferView()), QKeySequence::Back));
487 coll->addAction("NextBuffer", new Action(SmallIcon("go-down"), tr("Go to Next Chat"), coll,
488 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
489 coll->addAction("PreviousBuffer", new Action(SmallIcon("go-up"), tr("Go to Previous Chat"), coll,
490 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
494 void MainWin::setupMenus()
496 ActionCollection *coll = QtUi::actionCollection("General");
498 _fileMenu = menuBar()->addMenu(tr("&File"));
500 static const QStringList coreActions = QStringList()
501 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
504 foreach(QString actionName, coreActions) {
505 coreAction = coll->action(actionName);
506 _fileMenu->addAction(coreAction);
507 flagRemoteCoreOnly(coreAction);
509 flagRemoteCoreOnly(_fileMenu->addSeparator());
511 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
512 _networksMenu->addAction(coll->action("ConfigureNetworks"));
513 _networksMenu->addSeparator();
514 _fileMenu->addSeparator();
515 _fileMenu->addAction(coll->action("Quit"));
517 _viewMenu = menuBar()->addMenu(tr("&View"));
518 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
519 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
520 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
521 _viewMenu->addSeparator();
523 _viewMenu->addAction(coll->action("ToggleMenuBar"));
524 _viewMenu->addAction(coll->action("ToggleStatusBar"));
525 _viewMenu->addAction(coll->action("ToggleSearchBar"));
527 coreAction = coll->action("ShowAwayLog");
528 flagRemoteCoreOnly(coreAction);
529 _viewMenu->addAction(coreAction);
531 _viewMenu->addSeparator();
532 _viewMenu->addAction(coll->action("LockLayout"));
534 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
536 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
537 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
539 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
541 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
543 _helpMenu = menuBar()->addMenu(tr("&Help"));
544 _helpMenu->addAction(coll->action("AboutQuassel"));
546 _helpMenu->addAction(coll->action("AboutQt"));
548 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
550 _helpMenu->addSeparator();
551 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
552 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
553 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
554 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
555 _helpDebugMenu->addAction(coll->action("DebugHotList"));
556 _helpDebugMenu->addAction(coll->action("DebugLog"));
557 _helpDebugMenu->addSeparator();
558 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
561 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
563 QtUiSettings uiSettings;
564 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
565 showMenuBar->setChecked(enabled);
566 enabled ? menuBar()->show() : menuBar()->hide();
568 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
569 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
573 void MainWin::setupBufferWidget()
575 _bufferWidget = new BufferWidget(this);
576 _bufferWidget->setModel(Client::bufferModel());
577 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
578 setCentralWidget(_bufferWidget);
582 void MainWin::addBufferView(int bufferViewConfigId)
584 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
588 void MainWin::addBufferView(ClientBufferViewConfig *config)
593 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
594 BufferViewDock *dock = new BufferViewDock(config, this);
596 //create the view and initialize it's filter
597 BufferView *view = new BufferView(dock);
598 view->setFilteredModel(Client::bufferModel(), config);
599 view->installEventFilter(_inputWidget); // for key presses
601 Client::bufferModel()->synchronizeView(view);
603 dock->setWidget(view);
604 dock->setVisible(_layoutLoaded); // don't show before state has been restored
606 addDockWidget(Qt::LeftDockWidgetArea, dock);
607 _bufferViewsMenu->addAction(dock->toggleViewAction());
609 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
610 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
611 _bufferViews.append(dock);
613 if (!activeBufferView())
618 void MainWin::removeBufferView(int bufferViewConfigId)
621 BufferViewDock *dock;
622 foreach(QAction *action, _bufferViewsMenu->actions()) {
623 actionData = action->data();
624 if (!actionData.isValid())
627 dock = qobject_cast<BufferViewDock *>(action->parent());
628 if (dock && actionData.toInt() == bufferViewConfigId) {
629 removeAction(action);
630 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
631 _bufferViews.removeAll(dock);
633 if (dock->isActive()) {
634 dock->setActive(false);
635 _activeBufferViewIndex = -1;
645 void MainWin::bufferViewToggled(bool enabled)
647 if (!enabled && !isVisible()) {
648 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
649 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
652 QAction *action = qobject_cast<QAction *>(sender());
654 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
657 // Make sure we don't toggle backlog fetch for a view we've already removed
658 if (!_bufferViews.contains(dock))
662 Client::bufferViewOverlay()->addView(dock->bufferViewId());
664 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
668 void MainWin::bufferViewVisibilityChanged(bool visible)
671 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
673 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
678 BufferView *MainWin::allBuffersView() const
680 // "All Buffers" is always the first dock created
681 if (_bufferViews.count() > 0)
682 return _bufferViews[0]->bufferView();
687 BufferView *MainWin::activeBufferView() const
689 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
691 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
692 return dock->isActive() ? qobject_cast<BufferView *>(dock->widget()) : 0;
696 void MainWin::changeActiveBufferView(int bufferViewId)
698 if (bufferViewId < 0)
701 BufferView *current = activeBufferView();
703 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
704 _activeBufferViewIndex = -1;
707 for (int i = 0; i < _bufferViews.count(); i++) {
708 BufferViewDock *dock = _bufferViews.at(i);
709 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
710 _activeBufferViewIndex = i;
711 dock->setActive(true);
716 nextBufferView(); // fallback
720 void MainWin::changeActiveBufferView(bool backwards)
722 BufferView *current = activeBufferView();
724 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
726 if (!_bufferViews.count())
729 int c = _bufferViews.count();
730 while (c--) { // yes, this will reactivate the current active one if all others fail
732 if (--_activeBufferViewIndex < 0)
733 _activeBufferViewIndex = _bufferViews.count()-1;
736 if (++_activeBufferViewIndex >= _bufferViews.count())
737 _activeBufferViewIndex = 0;
740 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
741 if (dock->isHidden())
744 dock->setActive(true);
748 _activeBufferViewIndex = -1;
752 void MainWin::nextBufferView()
754 changeActiveBufferView(false);
758 void MainWin::previousBufferView()
760 changeActiveBufferView(true);
764 void MainWin::nextBuffer()
766 BufferView *view = activeBufferView();
772 void MainWin::previousBuffer()
774 BufferView *view = activeBufferView();
776 view->previousBuffer();
780 void MainWin::hideCurrentBuffer()
782 BufferView *view = activeBufferView();
784 view->hideCurrentBuffer();
788 void MainWin::showNotificationsDlg()
790 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
795 void MainWin::on_actionConfigureNetworks_triggered()
797 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
802 void MainWin::on_actionConfigureViews_triggered()
804 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
809 void MainWin::on_actionLockLayout_toggled(bool lock)
811 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
812 foreach(VerticalDock *dock, docks) {
813 dock->showTitle(!lock);
815 if (Client::bufferViewManager()) {
816 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
817 config->setLocked(lock);
820 QtUiSettings().setValue("LockLayout", lock);
824 void MainWin::setupNickWidget()
827 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
828 nickDock->setObjectName("NickDock");
829 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
831 _nickListWidget = new NickListWidget(nickDock);
832 nickDock->setWidget(_nickListWidget);
834 addDockWidget(Qt::RightDockWidgetArea, nickDock);
835 _viewMenu->addAction(nickDock->toggleViewAction());
836 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
838 // See NickListDock::NickListDock();
839 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
841 // attach the NickListWidget to the BufferModel and the default selection
842 _nickListWidget->setModel(Client::bufferModel());
843 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
847 void MainWin::setupChatMonitor()
849 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
850 dock->setObjectName("ChatMonitorDock");
852 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
853 _chatMonitorView = new ChatMonitorView(filter, this);
854 _chatMonitorView->setFocusProxy(_inputWidget);
855 _chatMonitorView->show();
856 dock->setWidget(_chatMonitorView);
859 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
860 _viewMenu->addAction(dock->toggleViewAction());
861 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
865 void MainWin::setupInputWidget()
867 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
868 dock->setObjectName("InputDock");
870 _inputWidget = new InputWidget(dock);
871 dock->setWidget(_inputWidget);
873 addDockWidget(Qt::BottomDockWidgetArea, dock);
875 _viewMenu->addAction(dock->toggleViewAction());
876 dock->toggleViewAction()->setText(tr("Show Input Line"));
878 _inputWidget->setModel(Client::bufferModel());
879 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
881 _bufferWidget->setFocusProxy(_inputWidget);
883 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
885 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
889 void MainWin::setupTopicWidget()
891 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
892 dock->setObjectName("TopicDock");
893 _topicWidget = new TopicWidget(dock);
895 dock->setWidget(_topicWidget);
897 _topicWidget->setModel(Client::bufferModel());
898 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
900 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
902 _viewMenu->addAction(dock->toggleViewAction());
903 dock->toggleViewAction()->setText(tr("Show Topic Line"));
907 void MainWin::setupViewMenuTail()
909 _viewMenu->addSeparator();
910 _viewMenu->addAction(QtUi::actionCollection("General")->action("ToggleFullscreen"));
914 void MainWin::setupTitleSetter()
916 _titleSetter.setModel(Client::bufferModel());
917 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
921 void MainWin::setupStatusBar()
923 // MessageProcessor progress
924 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
927 _coreConnectionStatusWidget->update();
928 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
930 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
932 QtUiSettings uiSettings;
934 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
935 showStatusbar->setChecked(enabled);
936 enabled ? statusBar()->show() : statusBar()->hide();
938 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
939 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
941 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
945 void MainWin::setupHotList()
947 FlatProxyModel *flatProxy = new FlatProxyModel(this);
948 flatProxy->setSourceModel(Client::bufferModel());
949 _bufferHotList = new BufferHotListFilter(flatProxy);
953 void MainWin::saveMenuBarStatus(bool enabled)
955 QtUiSettings uiSettings;
956 uiSettings.setValue("ShowMenuBar", enabled);
960 void MainWin::saveStatusBarStatus(bool enabled)
962 QtUiSettings uiSettings;
963 uiSettings.setValue("ShowStatusBar", enabled);
967 void MainWin::setupSystray()
970 _systemTray = new StatusNotifierItem(this);
971 #elif !defined QT_NO_SYSTEMTRAYICON
972 _systemTray = new LegacySystemTray(this);
974 _systemTray = new SystemTray(this); // dummy
980 void MainWin::setupToolBars()
982 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
983 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
984 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
985 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
988 setUnifiedTitleAndToolBarOnMac(true);
992 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
994 _mainToolBar = new QToolBar(this);
995 _mainToolBar->setObjectName("MainToolBar");
997 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
998 addToolBar(_mainToolBar);
1000 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1001 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1005 void MainWin::connectedToCore()
1007 Q_CHECK_PTR(Client::bufferViewManager());
1008 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1009 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1010 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1012 setConnectedState();
1016 void MainWin::setConnectedState()
1018 ActionCollection *coll = QtUi::actionCollection("General");
1020 coll->action("ConnectCore")->setEnabled(false);
1021 coll->action("DisconnectCore")->setEnabled(true);
1022 coll->action("CoreInfo")->setEnabled(true);
1024 foreach(QAction *action, _fileMenu->actions()) {
1025 if (isRemoteCoreOnly(action))
1026 action->setVisible(!Client::internalCore());
1029 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1030 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1031 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1032 if (!Client::internalCore()) {
1033 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1034 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1035 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1038 // _viewMenu->setEnabled(true);
1039 if (!Client::internalCore())
1040 statusBar()->showMessage(tr("Connected to core."));
1042 statusBar()->clearMessage();
1044 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1046 systemTray()->setState(SystemTray::Active);
1048 if (Client::networkIds().isEmpty()) {
1049 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1053 // Monolithic always preselects last used buffer - Client only if the connection died
1054 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1056 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1057 if (lastUsedBufferId.isValid())
1058 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1064 void MainWin::loadLayout()
1067 int accountId = Client::currentCoreAccount().accountId().toInt();
1068 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1069 if (state.isEmpty()) {
1070 foreach(BufferViewDock *view, _bufferViews)
1072 _layoutLoaded = true;
1076 restoreState(state, accountId);
1077 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1078 if (bufferViewId >= 0)
1079 changeActiveBufferView(bufferViewId);
1081 _layoutLoaded = true;
1085 void MainWin::saveLayout()
1088 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1089 if (accountId > 0) {
1090 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1091 BufferView *view = activeBufferView();
1092 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1097 void MainWin::disconnectedFromCore()
1099 // save core specific layout and remove bufferviews;
1101 _layoutLoaded = false;
1103 QVariant actionData;
1104 BufferViewDock *dock;
1105 foreach(QAction *action, _bufferViewsMenu->actions()) {
1106 actionData = action->data();
1107 if (!actionData.isValid())
1110 dock = qobject_cast<BufferViewDock *>(action->parent());
1111 if (dock && actionData.toInt() != -1) {
1112 removeAction(action);
1113 _bufferViews.removeAll(dock);
1114 dock->deleteLater();
1118 // store last active buffer
1120 BufferId lastBufId = _bufferWidget->currentBuffer();
1121 if (lastBufId.isValid()) {
1122 s.setValue("LastUsedBufferId", lastBufId.toInt());
1123 // clear the current selection
1124 Client::bufferModel()->standardSelectionModel()->clearSelection();
1126 restoreState(s.value("MainWinState").toByteArray());
1127 setDisconnectedState();
1131 void MainWin::setDisconnectedState()
1133 ActionCollection *coll = QtUi::actionCollection("General");
1134 //ui.menuCore->setEnabled(false);
1135 coll->action("ConnectCore")->setEnabled(true);
1136 coll->action("DisconnectCore")->setEnabled(false);
1137 coll->action("CoreInfo")->setEnabled(false);
1138 //_viewMenu->setEnabled(false);
1139 statusBar()->showMessage(tr("Not connected to core."));
1140 if (_msgProcessorStatusWidget)
1141 _msgProcessorStatusWidget->setProgress(0, 0);
1143 systemTray()->setState(SystemTray::Passive);
1147 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1149 Q_UNUSED(errorMessage)
1150 CoreConnectAuthDlg dlg(account, this);
1151 *valid = (dlg.exec() == QDialog::Accepted);
1155 void MainWin::handleNoSslInClient(bool *accepted)
1157 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1158 QMessageBox::Ignore|QMessageBox::Cancel, this);
1159 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1160 box.setDefaultButton(QMessageBox::Ignore);
1161 *accepted = box.exec() == QMessageBox::Ignore;
1165 void MainWin::handleNoSslInCore(bool *accepted)
1167 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1168 QMessageBox::Ignore|QMessageBox::Cancel, this);
1169 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1170 box.setDefaultButton(QMessageBox::Ignore);
1171 *accepted = box.exec() == QMessageBox::Ignore;
1177 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1179 QString errorString = "<ul>";
1180 foreach(const QSslError error, socket->sslErrors())
1181 errorString += QString("<li>%1</li>").arg(error.errorString());
1182 errorString += "</ul>";
1184 QMessageBox box(QMessageBox::Warning,
1185 tr("Untrusted Security Certificate"),
1186 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1187 QMessageBox::Cancel, this);
1188 box.setInformativeText(errorString);
1189 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1190 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1192 QMessageBox::ButtonRole role;
1195 role = box.buttonRole(box.clickedButton());
1196 if (role == QMessageBox::HelpRole) {
1197 SslInfoDlg dlg(socket, this);
1201 while (role == QMessageBox::HelpRole);
1203 *accepted = role == QMessageBox::AcceptRole;
1205 QMessageBox box2(QMessageBox::Warning,
1206 tr("Untrusted Security Certificate"),
1207 tr("Would you like to accept this certificate forever without being prompted?"),
1209 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1210 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1212 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1217 #endif /* HAVE_SSL */
1219 void MainWin::handleCoreConnectionError(const QString &error)
1221 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1225 void MainWin::showCoreConnectionDlg()
1227 CoreConnectDlg dlg(this);
1228 if (dlg.exec() == QDialog::Accepted) {
1229 AccountId accId = dlg.selectedAccount();
1230 if (accId.isValid())
1231 Client::coreConnection()->connectToCore(accId);
1236 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1238 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1244 void MainWin::showChannelList(NetworkId netId)
1246 ChannelListDlg *channelListDlg = new ChannelListDlg();
1248 if (!netId.isValid()) {
1249 QAction *action = qobject_cast<QAction *>(sender());
1251 netId = action->data().value<NetworkId>();
1254 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1255 channelListDlg->setNetwork(netId);
1256 channelListDlg->show();
1260 void MainWin::showIgnoreList(QString newRule)
1262 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1263 // prepare config dialog for new rule
1264 if (!newRule.isEmpty())
1265 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1270 void MainWin::showCoreInfoDlg()
1272 CoreInfoDlg(this).exec();
1276 void MainWin::showAwayLog()
1280 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1281 _awayLog = new AwayLogView(filter, 0);
1282 filter->setParent(_awayLog);
1283 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1284 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1289 void MainWin::awayLogDestroyed()
1295 void MainWin::showSettingsDlg()
1297 SettingsDlg *dlg = new SettingsDlg();
1299 //Category: Interface
1300 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1301 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1302 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1303 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1304 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1305 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1306 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1307 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1308 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1309 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1312 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1313 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1314 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1315 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1316 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1318 // Category: Remote Cores
1319 if (Quassel::runMode() != Quassel::Monolithic) {
1320 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1321 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1328 void MainWin::showAboutDlg()
1330 AboutDlg(this).exec();
1334 void MainWin::showShortcutsDlg()
1337 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1338 foreach(KActionCollection *coll, QtUi::actionCollections())
1339 dlg.addCollection(coll, coll->property("Category").toString());
1342 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1348 void MainWin::toggleFullscreen()
1357 /********************************************************************************************************/
1359 bool MainWin::event(QEvent *event)
1361 if (event->type() == QEvent::WindowActivate) {
1362 BufferId buffer = Client::bufferModel()->currentBuffer();
1363 if (buffer.isValid())
1364 Client::instance()->markBufferAsRead(buffer);
1366 return QMainWindow::event(event);
1370 void MainWin::moveEvent(QMoveEvent *event)
1372 if (!(windowState() & Qt::WindowMaximized))
1373 _normalPos = event->pos();
1375 QMainWindow::moveEvent(event);
1379 void MainWin::resizeEvent(QResizeEvent *event)
1381 if (!(windowState() & Qt::WindowMaximized))
1382 _normalSize = event->size();
1384 QMainWindow::resizeEvent(event);
1388 void MainWin::closeEvent(QCloseEvent *event)
1391 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1393 if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1394 QtUi::hideMainWidget();
1404 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1408 bool hasFocus = QApplication::activeWindow() != 0;
1410 for (int i = start; i <= end; i++) {
1411 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1412 if (!idx.isValid()) {
1413 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1416 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1417 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1420 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1421 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1423 // check if bufferId belongs to the shown chatlists
1424 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1425 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1428 // check if it's the buffer currently displayed
1429 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1432 // only show notifications for higlights or queries
1433 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1436 // and of course: don't notify for ignored messages
1437 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1440 // seems like we have a legit notification candidate!
1441 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1442 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1443 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1444 AbstractNotificationBackend::NotificationType type;
1446 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1447 type = AbstractNotificationBackend::PrivMsg;
1448 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1449 type = AbstractNotificationBackend::PrivMsgFocused;
1450 else if (flags & Message::Highlight && !hasFocus)
1451 type = AbstractNotificationBackend::Highlight;
1453 type = AbstractNotificationBackend::HighlightFocused;
1455 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1460 void MainWin::currentBufferChanged(BufferId buffer)
1462 if (buffer.isValid())
1463 Client::instance()->markBufferAsRead(buffer);
1467 void MainWin::clientNetworkCreated(NetworkId id)
1469 const Network *net = Client::network(id);
1470 QAction *act = new QAction(net->networkName(), this);
1471 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1472 act->setData(QVariant::fromValue<NetworkId>(id));
1473 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1474 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1476 QAction *beforeAction = 0;
1477 foreach(QAction *action, _networksMenu->actions()) {
1478 if (!action->data().isValid()) // ignore stock actions
1480 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1481 beforeAction = action;
1485 _networksMenu->insertAction(beforeAction, act);
1489 void MainWin::clientNetworkUpdated()
1491 const Network *net = qobject_cast<const Network *>(sender());
1495 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1499 action->setText(net->networkName());
1501 switch (net->connectionState()) {
1502 case Network::Initialized:
1503 action->setIcon(SmallIcon("network-connect"));
1504 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1505 if (!bufferWidget()->currentBuffer().isValid()) {
1506 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1507 if (idx.isValid()) {
1508 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1509 Client::bufferModel()->switchToBuffer(statusBufferId);
1513 case Network::Disconnected:
1514 action->setIcon(SmallIcon("network-disconnect"));
1517 action->setIcon(SmallIcon("network-wired"));
1522 void MainWin::clientNetworkRemoved(NetworkId id)
1524 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1528 action->deleteLater();
1532 void MainWin::connectOrDisconnectFromNet()
1534 QAction *act = qobject_cast<QAction *>(sender());
1536 const Network *net = Client::network(act->data().value<NetworkId>());
1538 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1539 else net->requestDisconnect();
1543 void MainWin::on_jumpHotBuffer_triggered()
1545 if (!_bufferHotList->rowCount())
1548 QModelIndex topIndex = _bufferHotList->index(0, 0);
1549 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1550 Client::bufferModel()->switchToBuffer(bufferId);
1554 void MainWin::onJumpKey()
1556 QAction *action = qobject_cast<QAction *>(sender());
1557 if (!action || !Client::bufferModel())
1559 int idx = action->property("Index").toInt();
1561 if (_jumpKeyMap.isEmpty())
1562 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1564 if (!_jumpKeyMap.contains(idx))
1567 BufferId buffer = _jumpKeyMap.value(idx);
1568 if (buffer.isValid())
1569 Client::bufferModel()->switchToBuffer(buffer);
1573 void MainWin::bindJumpKey()
1575 QAction *action = qobject_cast<QAction *>(sender());
1576 if (!action || !Client::bufferModel())
1578 int idx = action->property("Index").toInt();
1580 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1581 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1585 void MainWin::on_actionDebugNetworkModel_triggered()
1587 QTreeView *view = new QTreeView;
1588 view->setAttribute(Qt::WA_DeleteOnClose);
1589 view->setWindowTitle("Debug NetworkModel View");
1590 view->setModel(Client::networkModel());
1591 view->setColumnWidth(0, 250);
1592 view->setColumnWidth(1, 250);
1593 view->setColumnWidth(2, 80);
1594 view->resize(610, 300);
1599 void MainWin::on_actionDebugHotList_triggered()
1601 QTreeView *view = new QTreeView;
1602 view->setAttribute(Qt::WA_DeleteOnClose);
1603 view->setModel(_bufferHotList);
1608 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1610 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1611 overlay->setAttribute(Qt::WA_DeleteOnClose);
1616 void MainWin::on_actionDebugMessageModel_triggered()
1618 QTableView *view = new QTableView(0);
1619 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1620 filter->setSourceModel(Client::messageModel());
1621 view->setModel(filter);
1622 view->setAttribute(Qt::WA_DeleteOnClose, true);
1623 view->verticalHeader()->hide();
1624 view->horizontalHeader()->setStretchLastSection(true);
1629 void MainWin::on_actionDebugLog_triggered()
1631 DebugLogWidget *logWidget = new DebugLogWidget(0);
1636 void MainWin::showStatusBarMessage(const QString &message)
1638 statusBar()->showMessage(message, 10000);