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"
116 #include "dockmanagernotificationbackend.h"
119 #include "settingspages/aliasessettingspage.h"
120 #include "settingspages/appearancesettingspage.h"
121 #include "settingspages/backlogsettingspage.h"
122 #include "settingspages/bufferviewsettingspage.h"
123 #include "settingspages/chatmonitorsettingspage.h"
124 #include "settingspages/chatviewsettingspage.h"
125 #include "settingspages/connectionsettingspage.h"
126 #include "settingspages/coreaccountsettingspage.h"
127 #include "settingspages/coreconnectionsettingspage.h"
128 #include "settingspages/highlightsettingspage.h"
129 #include "settingspages/identitiessettingspage.h"
130 #include "settingspages/ignorelistsettingspage.h"
131 #include "settingspages/inputwidgetsettingspage.h"
132 #include "settingspages/itemviewsettingspage.h"
133 #include "settingspages/networkssettingspage.h"
134 #include "settingspages/notificationssettingspage.h"
135 #include "settingspages/topicwidgetsettingspage.h"
138 # include "settingspages/shortcutssettingspage.h"
141 MainWin::MainWin(QWidget *parent)
143 : KMainWindow(parent),
144 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
146 : QMainWindow(parent),
148 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
149 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
152 _layoutLoaded(false),
153 _activeBufferViewIndex(-1)
155 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
157 QtUiSettings uiSettings;
158 QString style = uiSettings.value("Style", QString()).toString();
159 if (!style.isEmpty()) {
160 QApplication::setStyle(style);
163 QApplication::setQuitOnLastWindowClosed(false);
165 setWindowTitle("Quassel IRC");
166 setWindowIconText("Quassel IRC");
173 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
174 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
175 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
176 SLOT(messagesInserted(const QModelIndex &, int, int)));
177 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
178 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
180 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
181 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
182 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
183 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
184 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
186 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
190 setDockNestingEnabled(true);
191 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
192 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
193 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
194 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
196 // Order is sometimes important
213 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
215 # ifndef QT_NO_SYSTEMTRAYICON
216 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
219 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
222 QtUi::registerNotificationBackend(new KNotificationBackend(this));
223 #endif /* HAVE_KDE */
225 #ifdef HAVE_INDICATEQT
226 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
229 #ifdef HAVE_NOTIFICATION_CENTER
230 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
234 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
237 // we assume that at this point, all configurable actions are defined!
238 QtUi::loadShortcuts();
240 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
242 setDisconnectedState(); // Disable menus and stuff
245 setAutoSaveSettings();
248 // restore mainwin state
250 restoreStateFromSettings(s);
252 // restore locked state of docks
253 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
255 CoreConnection *conn = Client::coreConnection();
256 if (!conn->connectToCore()) {
257 // No autoconnect selected (or no accounts)
258 showCoreConnectionDlg();
271 saveStateToSettings(s);
273 QApplication::quit();
277 void MainWin::saveStateToSettings(UiSettings &s)
279 s.setValue("MainWinSize", _normalSize);
280 s.setValue("MainWinPos", _normalPos);
281 s.setValue("MainWinState", saveState());
282 s.setValue("MainWinGeometry", saveGeometry());
283 s.setValue("MainWinMinimized", isMinimized());
284 s.setValue("MainWinMaximized", isMaximized());
285 s.setValue("MainWinHidden", !isVisible());
286 BufferId lastBufId = Client::bufferModel()->currentBuffer();
287 if (lastBufId.isValid())
288 s.setValue("LastUsedBufferId", lastBufId.toInt());
291 saveAutoSaveSettings();
296 void MainWin::restoreStateFromSettings(UiSettings &s)
298 _normalSize = s.value("MainWinSize", size()).toSize();
299 _normalPos = s.value("MainWinPos", pos()).toPoint();
300 bool maximized = s.value("MainWinMaximized", false).toBool();
303 restoreGeometry(s.value("MainWinGeometry").toByteArray());
306 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
311 restoreState(s.value("MainWinState").toByteArray());
317 if ((Quassel::isOptionSet("hidewindow")
318 || s.value("MainWinHidden").toBool())
319 && _systemTray->isSystemTrayAvailable())
320 QtUi::hideMainWidget();
321 else if (s.value("MainWinMinimized").toBool())
330 void MainWin::updateIcon()
333 const int size = 128;
339 if (Client::isConnected())
340 icon = DesktopIcon("quassel", size);
342 icon = DesktopIcon("quassel-inactive", size);
344 qApp->setWindowIcon(icon);
348 void MainWin::setupActions()
350 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
352 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
353 this, SLOT(showCoreConnectionDlg())));
354 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
355 Client::instance(), SLOT(disconnectFromCore())));
356 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
357 this, SLOT(showCoreInfoDlg())));
358 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
359 this, SLOT(on_actionConfigureNetworks_triggered())));
360 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
361 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
362 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
365 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
366 this, SLOT(on_actionConfigureViews_triggered())));
368 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
369 lockAct->setCheckable(true);
370 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
372 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
373 0, 0, QKeySequence::Find))->setCheckable(true);
374 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
375 this, SLOT(showAwayLog())));
376 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
377 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
379 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
380 0, 0))->setCheckable(true);
383 QAction *fullScreenAct = KStandardAction::fullScreen(this, SLOT(toggleFullscreen()), this, coll);
385 QAction *fullScreenAct = new Action(SmallIcon("view-fullscreen"), tr("&Full Screen Mode"), coll,
386 this, SLOT(toggleFullscreen()), QKeySequence(Qt::Key_F11));
387 fullScreenAct->setCheckable(true);
389 coll->addAction("ToggleFullscreen", fullScreenAct);
392 QAction *configureShortcutsAct = new Action(SmallIcon("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
393 this, SLOT(showShortcutsDlg()));
394 configureShortcutsAct->setMenuRole(QAction::NoRole);
395 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
398 QAction *configureQuasselAct = new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
399 this, SLOT(showSettingsDlg()));
400 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
402 QAction *configureQuasselAct = new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
403 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
405 coll->addAction("ConfigureQuassel", configureQuasselAct);
408 QAction *aboutQuasselAct = new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
409 this, SLOT(showAboutDlg()));
410 aboutQuasselAct->setMenuRole(QAction::AboutRole);
411 coll->addAction("AboutQuassel", aboutQuasselAct);
413 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
414 qApp, SLOT(aboutQt()));
415 aboutQtAct->setMenuRole(QAction::AboutQtRole);
416 coll->addAction("AboutQt", aboutQtAct);
417 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
418 this, SLOT(on_actionDebugNetworkModel_triggered())));
419 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
420 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
421 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
422 this, SLOT(on_actionDebugMessageModel_triggered())));
423 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
424 this, SLOT(on_actionDebugHotList_triggered())));
425 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
426 this, SLOT(on_actionDebugLog_triggered())));
427 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
428 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
430 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
431 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
434 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
436 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
437 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
441 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
442 const int jumpModifier = Qt::ControlModifier;
444 const int bindModifier = Qt::ControlModifier;
445 const int jumpModifier = Qt::AltModifier;
448 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
449 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
450 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
451 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
452 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
453 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
454 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
455 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
456 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
457 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
458 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
459 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
460 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
461 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
462 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
463 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
464 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
465 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
466 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
467 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
469 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
470 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
471 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
472 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
473 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
474 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
475 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
476 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
477 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
478 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
479 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
480 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
481 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
482 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
483 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
484 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
485 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
486 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
487 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
488 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
491 coll->addAction("NextBufferView", new Action(SmallIcon("go-next-view"), tr("Activate Next Chat List"), coll,
492 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
493 coll->addAction("PreviousBufferView", new Action(SmallIcon("go-previous-view"), tr("Activate Previous Chat List"), coll,
494 this, SLOT(previousBufferView()), QKeySequence::Back));
495 coll->addAction("NextBuffer", new Action(SmallIcon("go-down"), tr("Go to Next Chat"), coll,
496 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
497 coll->addAction("PreviousBuffer", new Action(SmallIcon("go-up"), tr("Go to Previous Chat"), coll,
498 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
502 void MainWin::setupMenus()
504 ActionCollection *coll = QtUi::actionCollection("General");
506 _fileMenu = menuBar()->addMenu(tr("&File"));
508 static const QStringList coreActions = QStringList()
509 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
512 foreach(QString actionName, coreActions) {
513 coreAction = coll->action(actionName);
514 _fileMenu->addAction(coreAction);
515 flagRemoteCoreOnly(coreAction);
517 flagRemoteCoreOnly(_fileMenu->addSeparator());
519 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
520 _networksMenu->addAction(coll->action("ConfigureNetworks"));
521 _networksMenu->addSeparator();
522 _fileMenu->addSeparator();
523 _fileMenu->addAction(coll->action("Quit"));
525 _viewMenu = menuBar()->addMenu(tr("&View"));
526 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
527 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
528 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
529 _viewMenu->addSeparator();
531 _viewMenu->addAction(coll->action("ToggleMenuBar"));
532 _viewMenu->addAction(coll->action("ToggleStatusBar"));
533 _viewMenu->addAction(coll->action("ToggleSearchBar"));
535 coreAction = coll->action("ShowAwayLog");
536 flagRemoteCoreOnly(coreAction);
537 _viewMenu->addAction(coreAction);
539 _viewMenu->addSeparator();
540 _viewMenu->addAction(coll->action("LockLayout"));
542 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
544 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
545 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
547 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
549 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
551 _helpMenu = menuBar()->addMenu(tr("&Help"));
552 _helpMenu->addAction(coll->action("AboutQuassel"));
554 _helpMenu->addAction(coll->action("AboutQt"));
556 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
558 _helpMenu->addSeparator();
559 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
560 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
561 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
562 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
563 _helpDebugMenu->addAction(coll->action("DebugHotList"));
564 _helpDebugMenu->addAction(coll->action("DebugLog"));
565 _helpDebugMenu->addSeparator();
566 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
569 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
571 QtUiSettings uiSettings;
572 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
573 showMenuBar->setChecked(enabled);
574 enabled ? menuBar()->show() : menuBar()->hide();
576 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
577 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
581 void MainWin::setupBufferWidget()
583 _bufferWidget = new BufferWidget(this);
584 _bufferWidget->setModel(Client::bufferModel());
585 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
586 setCentralWidget(_bufferWidget);
590 void MainWin::addBufferView(int bufferViewConfigId)
592 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
596 void MainWin::addBufferView(ClientBufferViewConfig *config)
601 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
602 BufferViewDock *dock = new BufferViewDock(config, this);
604 //create the view and initialize it's filter
605 BufferView *view = new BufferView(dock);
606 view->setFilteredModel(Client::bufferModel(), config);
607 view->installEventFilter(_inputWidget); // for key presses
609 Client::bufferModel()->synchronizeView(view);
611 dock->setWidget(view);
612 dock->setVisible(_layoutLoaded); // don't show before state has been restored
614 addDockWidget(Qt::LeftDockWidgetArea, dock);
615 _bufferViewsMenu->addAction(dock->toggleViewAction());
617 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
618 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
619 _bufferViews.append(dock);
621 if (!activeBufferView())
626 void MainWin::removeBufferView(int bufferViewConfigId)
629 BufferViewDock *dock;
630 foreach(QAction *action, _bufferViewsMenu->actions()) {
631 actionData = action->data();
632 if (!actionData.isValid())
635 dock = qobject_cast<BufferViewDock *>(action->parent());
636 if (dock && actionData.toInt() == bufferViewConfigId) {
637 removeAction(action);
638 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
639 _bufferViews.removeAll(dock);
641 if (dock->isActive()) {
642 dock->setActive(false);
643 _activeBufferViewIndex = -1;
653 void MainWin::bufferViewToggled(bool enabled)
655 if (!enabled && !isVisible()) {
656 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
657 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
660 QAction *action = qobject_cast<QAction *>(sender());
662 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
665 // Make sure we don't toggle backlog fetch for a view we've already removed
666 if (!_bufferViews.contains(dock))
670 Client::bufferViewOverlay()->addView(dock->bufferViewId());
672 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
676 void MainWin::bufferViewVisibilityChanged(bool visible)
679 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
681 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
686 BufferView *MainWin::allBuffersView() const
688 // "All Buffers" is always the first dock created
689 if (_bufferViews.count() > 0)
690 return _bufferViews[0]->bufferView();
695 BufferView *MainWin::activeBufferView() const
697 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
699 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
700 return dock->isActive() ? qobject_cast<BufferView *>(dock->widget()) : 0;
704 void MainWin::changeActiveBufferView(int bufferViewId)
706 if (bufferViewId < 0)
709 BufferView *current = activeBufferView();
711 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
712 _activeBufferViewIndex = -1;
715 for (int i = 0; i < _bufferViews.count(); i++) {
716 BufferViewDock *dock = _bufferViews.at(i);
717 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
718 _activeBufferViewIndex = i;
719 dock->setActive(true);
724 nextBufferView(); // fallback
728 void MainWin::changeActiveBufferView(bool backwards)
730 BufferView *current = activeBufferView();
732 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
734 if (!_bufferViews.count())
737 int c = _bufferViews.count();
738 while (c--) { // yes, this will reactivate the current active one if all others fail
740 if (--_activeBufferViewIndex < 0)
741 _activeBufferViewIndex = _bufferViews.count()-1;
744 if (++_activeBufferViewIndex >= _bufferViews.count())
745 _activeBufferViewIndex = 0;
748 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
749 if (dock->isHidden())
752 dock->setActive(true);
756 _activeBufferViewIndex = -1;
760 void MainWin::nextBufferView()
762 changeActiveBufferView(false);
766 void MainWin::previousBufferView()
768 changeActiveBufferView(true);
772 void MainWin::nextBuffer()
774 BufferView *view = activeBufferView();
780 void MainWin::previousBuffer()
782 BufferView *view = activeBufferView();
784 view->previousBuffer();
788 void MainWin::hideCurrentBuffer()
790 BufferView *view = activeBufferView();
792 view->hideCurrentBuffer();
796 void MainWin::showNotificationsDlg()
798 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
803 void MainWin::on_actionConfigureNetworks_triggered()
805 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
810 void MainWin::on_actionConfigureViews_triggered()
812 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
817 void MainWin::on_actionLockLayout_toggled(bool lock)
819 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
820 foreach(VerticalDock *dock, docks) {
821 dock->showTitle(!lock);
823 if (Client::bufferViewManager()) {
824 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
825 config->setLocked(lock);
828 QtUiSettings().setValue("LockLayout", lock);
832 void MainWin::setupNickWidget()
835 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
836 nickDock->setObjectName("NickDock");
837 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
839 _nickListWidget = new NickListWidget(nickDock);
840 nickDock->setWidget(_nickListWidget);
842 addDockWidget(Qt::RightDockWidgetArea, nickDock);
843 _viewMenu->addAction(nickDock->toggleViewAction());
844 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
846 // See NickListDock::NickListDock();
847 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
849 // attach the NickListWidget to the BufferModel and the default selection
850 _nickListWidget->setModel(Client::bufferModel());
851 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
855 void MainWin::setupChatMonitor()
857 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
858 dock->setObjectName("ChatMonitorDock");
860 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
861 _chatMonitorView = new ChatMonitorView(filter, this);
862 _chatMonitorView->setFocusProxy(_inputWidget);
863 _chatMonitorView->show();
864 dock->setWidget(_chatMonitorView);
867 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
868 _viewMenu->addAction(dock->toggleViewAction());
869 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
873 void MainWin::setupInputWidget()
875 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
876 dock->setObjectName("InputDock");
878 _inputWidget = new InputWidget(dock);
879 dock->setWidget(_inputWidget);
881 addDockWidget(Qt::BottomDockWidgetArea, dock);
883 _viewMenu->addAction(dock->toggleViewAction());
884 dock->toggleViewAction()->setText(tr("Show Input Line"));
886 _inputWidget->setModel(Client::bufferModel());
887 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
889 _bufferWidget->setFocusProxy(_inputWidget);
891 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
893 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
897 void MainWin::setupTopicWidget()
899 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
900 dock->setObjectName("TopicDock");
901 _topicWidget = new TopicWidget(dock);
903 dock->setWidget(_topicWidget);
905 _topicWidget->setModel(Client::bufferModel());
906 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
908 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
910 _viewMenu->addAction(dock->toggleViewAction());
911 dock->toggleViewAction()->setText(tr("Show Topic Line"));
915 void MainWin::setupViewMenuTail()
917 _viewMenu->addSeparator();
918 _viewMenu->addAction(QtUi::actionCollection("General")->action("ToggleFullscreen"));
922 void MainWin::setupTitleSetter()
924 _titleSetter.setModel(Client::bufferModel());
925 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
929 void MainWin::setupStatusBar()
931 // MessageProcessor progress
932 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
935 _coreConnectionStatusWidget->update();
936 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
938 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
940 QtUiSettings uiSettings;
942 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
943 showStatusbar->setChecked(enabled);
944 enabled ? statusBar()->show() : statusBar()->hide();
946 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
947 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
949 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
953 void MainWin::setupHotList()
955 FlatProxyModel *flatProxy = new FlatProxyModel(this);
956 flatProxy->setSourceModel(Client::bufferModel());
957 _bufferHotList = new BufferHotListFilter(flatProxy);
961 void MainWin::saveMenuBarStatus(bool enabled)
963 QtUiSettings uiSettings;
964 uiSettings.setValue("ShowMenuBar", enabled);
968 void MainWin::saveStatusBarStatus(bool enabled)
970 QtUiSettings uiSettings;
971 uiSettings.setValue("ShowStatusBar", enabled);
975 void MainWin::setupSystray()
978 _systemTray = new StatusNotifierItem(this);
979 #elif !defined QT_NO_SYSTEMTRAYICON
980 _systemTray = new LegacySystemTray(this);
982 _systemTray = new SystemTray(this); // dummy
988 void MainWin::setupToolBars()
990 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
991 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
992 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
993 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
996 setUnifiedTitleAndToolBarOnMac(true);
1000 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1002 _mainToolBar = new QToolBar(this);
1003 _mainToolBar->setObjectName("MainToolBar");
1005 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1006 addToolBar(_mainToolBar);
1008 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1009 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1013 void MainWin::connectedToCore()
1015 Q_CHECK_PTR(Client::bufferViewManager());
1016 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1017 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1018 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1020 setConnectedState();
1024 void MainWin::setConnectedState()
1026 ActionCollection *coll = QtUi::actionCollection("General");
1028 coll->action("ConnectCore")->setEnabled(false);
1029 coll->action("DisconnectCore")->setEnabled(true);
1030 coll->action("CoreInfo")->setEnabled(true);
1032 foreach(QAction *action, _fileMenu->actions()) {
1033 if (isRemoteCoreOnly(action))
1034 action->setVisible(!Client::internalCore());
1037 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1038 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1039 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1040 if (!Client::internalCore()) {
1041 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1042 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1043 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1046 // _viewMenu->setEnabled(true);
1047 if (!Client::internalCore())
1048 statusBar()->showMessage(tr("Connected to core."));
1050 statusBar()->clearMessage();
1052 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1054 systemTray()->setState(SystemTray::Active);
1056 if (Client::networkIds().isEmpty()) {
1057 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1061 // Monolithic always preselects last used buffer - Client only if the connection died
1062 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1064 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1065 if (lastUsedBufferId.isValid())
1066 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1072 void MainWin::loadLayout()
1075 int accountId = Client::currentCoreAccount().accountId().toInt();
1076 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1077 if (state.isEmpty()) {
1078 foreach(BufferViewDock *view, _bufferViews)
1080 _layoutLoaded = true;
1084 restoreState(state, accountId);
1085 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1086 if (bufferViewId >= 0)
1087 changeActiveBufferView(bufferViewId);
1089 _layoutLoaded = true;
1093 void MainWin::saveLayout()
1096 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1097 if (accountId > 0) {
1098 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1099 BufferView *view = activeBufferView();
1100 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1105 void MainWin::disconnectedFromCore()
1107 // save core specific layout and remove bufferviews;
1109 _layoutLoaded = false;
1111 QVariant actionData;
1112 BufferViewDock *dock;
1113 foreach(QAction *action, _bufferViewsMenu->actions()) {
1114 actionData = action->data();
1115 if (!actionData.isValid())
1118 dock = qobject_cast<BufferViewDock *>(action->parent());
1119 if (dock && actionData.toInt() != -1) {
1120 removeAction(action);
1121 _bufferViews.removeAll(dock);
1122 dock->deleteLater();
1126 // store last active buffer
1128 BufferId lastBufId = _bufferWidget->currentBuffer();
1129 if (lastBufId.isValid()) {
1130 s.setValue("LastUsedBufferId", lastBufId.toInt());
1131 // clear the current selection
1132 Client::bufferModel()->standardSelectionModel()->clearSelection();
1134 restoreState(s.value("MainWinState").toByteArray());
1135 setDisconnectedState();
1139 void MainWin::setDisconnectedState()
1141 ActionCollection *coll = QtUi::actionCollection("General");
1142 //ui.menuCore->setEnabled(false);
1143 coll->action("ConnectCore")->setEnabled(true);
1144 coll->action("DisconnectCore")->setEnabled(false);
1145 coll->action("CoreInfo")->setEnabled(false);
1146 //_viewMenu->setEnabled(false);
1147 statusBar()->showMessage(tr("Not connected to core."));
1148 if (_msgProcessorStatusWidget)
1149 _msgProcessorStatusWidget->setProgress(0, 0);
1151 systemTray()->setState(SystemTray::Passive);
1155 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1157 Q_UNUSED(errorMessage)
1158 CoreConnectAuthDlg dlg(account, this);
1159 *valid = (dlg.exec() == QDialog::Accepted);
1163 void MainWin::handleNoSslInClient(bool *accepted)
1165 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1166 QMessageBox::Ignore|QMessageBox::Cancel, this);
1167 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1168 box.setDefaultButton(QMessageBox::Ignore);
1169 *accepted = box.exec() == QMessageBox::Ignore;
1173 void MainWin::handleNoSslInCore(bool *accepted)
1175 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1176 QMessageBox::Ignore|QMessageBox::Cancel, this);
1177 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1178 box.setDefaultButton(QMessageBox::Ignore);
1179 *accepted = box.exec() == QMessageBox::Ignore;
1185 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1187 QString errorString = "<ul>";
1188 foreach(const QSslError error, socket->sslErrors())
1189 errorString += QString("<li>%1</li>").arg(error.errorString());
1190 errorString += "</ul>";
1192 QMessageBox box(QMessageBox::Warning,
1193 tr("Untrusted Security Certificate"),
1194 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1195 QMessageBox::Cancel, this);
1196 box.setInformativeText(errorString);
1197 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1198 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1200 QMessageBox::ButtonRole role;
1203 role = box.buttonRole(box.clickedButton());
1204 if (role == QMessageBox::HelpRole) {
1205 SslInfoDlg dlg(socket, this);
1209 while (role == QMessageBox::HelpRole);
1211 *accepted = role == QMessageBox::AcceptRole;
1213 QMessageBox box2(QMessageBox::Warning,
1214 tr("Untrusted Security Certificate"),
1215 tr("Would you like to accept this certificate forever without being prompted?"),
1217 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1218 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1220 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1225 #endif /* HAVE_SSL */
1227 void MainWin::handleCoreConnectionError(const QString &error)
1229 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1233 void MainWin::showCoreConnectionDlg()
1235 CoreConnectDlg dlg(this);
1236 if (dlg.exec() == QDialog::Accepted) {
1237 AccountId accId = dlg.selectedAccount();
1238 if (accId.isValid())
1239 Client::coreConnection()->connectToCore(accId);
1244 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1246 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1252 void MainWin::showChannelList(NetworkId netId)
1254 ChannelListDlg *channelListDlg = new ChannelListDlg();
1256 if (!netId.isValid()) {
1257 QAction *action = qobject_cast<QAction *>(sender());
1259 netId = action->data().value<NetworkId>();
1262 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1263 channelListDlg->setNetwork(netId);
1264 channelListDlg->show();
1268 void MainWin::showIgnoreList(QString newRule)
1270 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1271 // prepare config dialog for new rule
1272 if (!newRule.isEmpty())
1273 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1278 void MainWin::showCoreInfoDlg()
1280 CoreInfoDlg(this).exec();
1284 void MainWin::showAwayLog()
1288 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1289 _awayLog = new AwayLogView(filter, 0);
1290 filter->setParent(_awayLog);
1291 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1292 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1297 void MainWin::awayLogDestroyed()
1303 void MainWin::showSettingsDlg()
1305 SettingsDlg *dlg = new SettingsDlg();
1307 //Category: Interface
1308 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1309 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1310 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1311 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1312 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1313 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1314 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1315 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1316 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1317 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1320 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1321 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1322 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1323 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1324 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1326 // Category: Remote Cores
1327 if (Quassel::runMode() != Quassel::Monolithic) {
1328 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1329 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1336 void MainWin::showAboutDlg()
1338 AboutDlg(this).exec();
1342 void MainWin::showShortcutsDlg()
1345 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1346 foreach(KActionCollection *coll, QtUi::actionCollections())
1347 dlg.addCollection(coll, coll->property("Category").toString());
1350 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1356 void MainWin::toggleFullscreen()
1365 /********************************************************************************************************/
1367 bool MainWin::event(QEvent *event)
1369 if (event->type() == QEvent::WindowActivate) {
1370 BufferId buffer = Client::bufferModel()->currentBuffer();
1371 if (buffer.isValid())
1372 Client::instance()->markBufferAsRead(buffer);
1374 return QMainWindow::event(event);
1378 void MainWin::moveEvent(QMoveEvent *event)
1380 if (!(windowState() & Qt::WindowMaximized))
1381 _normalPos = event->pos();
1383 QMainWindow::moveEvent(event);
1387 void MainWin::resizeEvent(QResizeEvent *event)
1389 if (!(windowState() & Qt::WindowMaximized))
1390 _normalSize = event->size();
1392 QMainWindow::resizeEvent(event);
1396 void MainWin::closeEvent(QCloseEvent *event)
1399 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1401 if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1402 QtUi::hideMainWidget();
1412 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1416 bool hasFocus = QApplication::activeWindow() != 0;
1418 for (int i = start; i <= end; i++) {
1419 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1420 if (!idx.isValid()) {
1421 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1424 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1425 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1428 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1429 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1431 // check if bufferId belongs to the shown chatlists
1432 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1433 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1436 // check if it's the buffer currently displayed
1437 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1440 // only show notifications for higlights or queries
1441 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1444 // and of course: don't notify for ignored messages
1445 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1448 // seems like we have a legit notification candidate!
1449 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1450 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1451 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1452 AbstractNotificationBackend::NotificationType type;
1454 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1455 type = AbstractNotificationBackend::PrivMsg;
1456 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1457 type = AbstractNotificationBackend::PrivMsgFocused;
1458 else if (flags & Message::Highlight && !hasFocus)
1459 type = AbstractNotificationBackend::Highlight;
1461 type = AbstractNotificationBackend::HighlightFocused;
1463 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1468 void MainWin::currentBufferChanged(BufferId buffer)
1470 if (buffer.isValid())
1471 Client::instance()->markBufferAsRead(buffer);
1475 void MainWin::clientNetworkCreated(NetworkId id)
1477 const Network *net = Client::network(id);
1478 QAction *act = new QAction(net->networkName(), this);
1479 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1480 act->setData(QVariant::fromValue<NetworkId>(id));
1481 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1482 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1484 QAction *beforeAction = 0;
1485 foreach(QAction *action, _networksMenu->actions()) {
1486 if (!action->data().isValid()) // ignore stock actions
1488 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1489 beforeAction = action;
1493 _networksMenu->insertAction(beforeAction, act);
1497 void MainWin::clientNetworkUpdated()
1499 const Network *net = qobject_cast<const Network *>(sender());
1503 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1507 action->setText(net->networkName());
1509 switch (net->connectionState()) {
1510 case Network::Initialized:
1511 action->setIcon(SmallIcon("network-connect"));
1512 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1513 if (!bufferWidget()->currentBuffer().isValid()) {
1514 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1515 if (idx.isValid()) {
1516 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1517 Client::bufferModel()->switchToBuffer(statusBufferId);
1521 case Network::Disconnected:
1522 action->setIcon(SmallIcon("network-disconnect"));
1525 action->setIcon(SmallIcon("network-wired"));
1530 void MainWin::clientNetworkRemoved(NetworkId id)
1532 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1536 action->deleteLater();
1540 void MainWin::connectOrDisconnectFromNet()
1542 QAction *act = qobject_cast<QAction *>(sender());
1544 const Network *net = Client::network(act->data().value<NetworkId>());
1546 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1547 else net->requestDisconnect();
1551 void MainWin::on_jumpHotBuffer_triggered()
1553 if (!_bufferHotList->rowCount())
1556 QModelIndex topIndex = _bufferHotList->index(0, 0);
1557 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1558 Client::bufferModel()->switchToBuffer(bufferId);
1562 void MainWin::onJumpKey()
1564 QAction *action = qobject_cast<QAction *>(sender());
1565 if (!action || !Client::bufferModel())
1567 int idx = action->property("Index").toInt();
1569 if (_jumpKeyMap.isEmpty())
1570 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1572 if (!_jumpKeyMap.contains(idx))
1575 BufferId buffer = _jumpKeyMap.value(idx);
1576 if (buffer.isValid())
1577 Client::bufferModel()->switchToBuffer(buffer);
1581 void MainWin::bindJumpKey()
1583 QAction *action = qobject_cast<QAction *>(sender());
1584 if (!action || !Client::bufferModel())
1586 int idx = action->property("Index").toInt();
1588 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1589 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1593 void MainWin::on_actionDebugNetworkModel_triggered()
1595 QTreeView *view = new QTreeView;
1596 view->setAttribute(Qt::WA_DeleteOnClose);
1597 view->setWindowTitle("Debug NetworkModel View");
1598 view->setModel(Client::networkModel());
1599 view->setColumnWidth(0, 250);
1600 view->setColumnWidth(1, 250);
1601 view->setColumnWidth(2, 80);
1602 view->resize(610, 300);
1607 void MainWin::on_actionDebugHotList_triggered()
1609 QTreeView *view = new QTreeView;
1610 view->setAttribute(Qt::WA_DeleteOnClose);
1611 view->setModel(_bufferHotList);
1616 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1618 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1619 overlay->setAttribute(Qt::WA_DeleteOnClose);
1624 void MainWin::on_actionDebugMessageModel_triggered()
1626 QTableView *view = new QTableView(0);
1627 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1628 filter->setSourceModel(Client::messageModel());
1629 view->setModel(filter);
1630 view->setAttribute(Qt::WA_DeleteOnClose, true);
1631 view->verticalHeader()->hide();
1632 view->horizontalHeader()->setStretchLastSection(true);
1637 void MainWin::on_actionDebugLog_triggered()
1639 DebugLogWidget *logWidget = new DebugLogWidget(0);
1644 void MainWin::showStatusBarMessage(const QString &message)
1646 statusBar()->showMessage(message, 10000);