1 /***************************************************************************
2 * Copyright (C) 2005-2015 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 ***************************************************************************/
25 #include <QMessageBox>
28 #include <QInputDialog>
33 # include <KShortcutsDialog>
34 # include <KStatusBar>
35 # include <KToggleFullScreenAction>
40 # include <KConfigWidgets/KStandardAction>
41 # include <KXmlGui/KHelpMenu>
42 # include <KXmlGui/KShortcutsDialog>
43 # include <KXmlGui/KToolBar>
44 # include <KWidgetsAddons/KToggleFullScreenAction>
52 #include "awaylogfilter.h"
53 #include "awaylogview.h"
55 #include "actioncollection.h"
56 #include "bufferhotlistfilter.h"
57 #include "buffermodel.h"
58 #include "bufferview.h"
59 #include "bufferviewoverlay.h"
60 #include "bufferviewoverlayfilter.h"
61 #include "bufferwidget.h"
62 #include "channellistdlg.h"
63 #include "chatlinemodel.h"
64 #include "chatmonitorfilter.h"
65 #include "chatmonitorview.h"
68 #include "clientbacklogmanager.h"
69 #include "clientbufferviewconfig.h"
70 #include "clientbufferviewmanager.h"
71 #include "clientignorelistmanager.h"
72 #include "clienttransfer.h"
73 #include "clienttransfermanager.h"
74 #include "coreconfigwizard.h"
75 #include "coreconnectdlg.h"
76 #include "coreconnection.h"
77 #include "coreconnectionstatuswidget.h"
78 #include "coreinfodlg.h"
79 #include "contextmenuactionprovider.h"
80 #include "debugbufferviewoverlay.h"
81 #include "debuglogwidget.h"
82 #include "debugmessagemodelfilter.h"
83 #include "flatproxymodel.h"
84 #include "inputwidget.h"
85 #include "irclistmodel.h"
86 #include "ircconnectionwizard.h"
87 #include "legacysystemtray.h"
88 #include "msgprocessorstatuswidget.h"
89 #include "nicklistwidget.h"
90 #include "passwordchangedlg.h"
91 #include "qtuiapplication.h"
92 #include "qtuimessageprocessor.h"
93 #include "qtuisettings.h"
94 #include "qtuistyle.h"
95 #include "receivefiledlg.h"
96 #include "settingsdlg.h"
97 #include "settingspagedlg.h"
98 #include "statusnotifieritem.h"
99 #include "toolbaractionprovider.h"
100 #include "topicwidget.h"
101 #include "verticaldock.h"
105 # include "phononnotificationbackend.h"
107 # include "systraynotificationbackend.h"
108 # include "taskbarnotificationbackend.h"
110 # include "knotificationbackend.h"
111 #endif /* HAVE_KDE */
115 # include "snorenotificationbackend.h"
119 # include "sslinfodlg.h"
122 #ifdef HAVE_INDICATEQT
123 #include "indicatornotificationbackend.h"
126 #ifdef HAVE_NOTIFICATION_CENTER
127 #include "osxnotificationbackend.h"
131 #include "dockmanagernotificationbackend.h"
134 #include "settingspages/aliasessettingspage.h"
135 #include "settingspages/appearancesettingspage.h"
136 #include "settingspages/backlogsettingspage.h"
137 #include "settingspages/bufferviewsettingspage.h"
138 #include "settingspages/chatmonitorsettingspage.h"
139 #include "settingspages/chatviewsettingspage.h"
140 #include "settingspages/connectionsettingspage.h"
141 #include "settingspages/coreaccountsettingspage.h"
142 #include "settingspages/coreconnectionsettingspage.h"
143 #include "settingspages/highlightsettingspage.h"
144 #include "settingspages/identitiessettingspage.h"
145 #include "settingspages/ignorelistsettingspage.h"
146 #include "settingspages/inputwidgetsettingspage.h"
147 #include "settingspages/itemviewsettingspage.h"
148 #include "settingspages/networkssettingspage.h"
149 #include "settingspages/notificationssettingspage.h"
150 #include "settingspages/topicwidgetsettingspage.h"
153 # include "settingspages/shortcutssettingspage.h"
156 MainWin::MainWin(QWidget *parent)
158 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
160 : QMainWindow(parent),
162 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
163 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
166 _layoutLoaded(false),
167 _activeBufferViewIndex(-1),
170 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
172 QtUiSettings uiSettings;
173 QString style = uiSettings.value("Style", QString()).toString();
174 if (!style.isEmpty()) {
175 QApplication::setStyle(style);
178 QApplication::setQuitOnLastWindowClosed(false);
180 setWindowTitle("Quassel IRC");
181 setWindowIconText("Quassel IRC");
188 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
189 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
190 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
191 SLOT(messagesInserted(const QModelIndex &, int, int)));
192 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
193 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
195 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
196 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
197 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
198 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
199 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
201 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
205 setDockNestingEnabled(true);
206 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
207 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
208 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
209 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
211 // Order is sometimes important
228 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
230 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
232 QtUi::registerNotificationBackend(new KNotificationBackend(this));
233 #endif /* HAVE_KDE */
237 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
238 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
239 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
242 #ifdef HAVE_INDICATEQT
243 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
246 #ifdef HAVE_NOTIFICATION_CENTER
247 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
251 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
254 // we assume that at this point, all configurable actions are defined!
255 QtUi::loadShortcuts();
257 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
259 setDisconnectedState(); // Disable menus and stuff
262 setAutoSaveSettings();
265 // restore mainwin state
267 restoreStateFromSettings(s);
269 // restore locked state of docks
270 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
272 CoreConnection *conn = Client::coreConnection();
273 if (!conn->connectToCore()) {
274 // No autoconnect selected (or no accounts)
275 showCoreConnectionDlg();
288 saveStateToSettings(s);
290 QApplication::quit();
294 void MainWin::saveStateToSettings(UiSettings &s)
296 s.setValue("MainWinSize", _normalSize);
297 s.setValue("MainWinPos", _normalPos);
298 s.setValue("MainWinState", saveState());
299 s.setValue("MainWinGeometry", saveGeometry());
300 s.setValue("MainWinMinimized", isMinimized());
301 s.setValue("MainWinMaximized", isMaximized());
302 s.setValue("MainWinHidden", !isVisible());
303 BufferId lastBufId = Client::bufferModel()->currentBuffer();
304 if (lastBufId.isValid())
305 s.setValue("LastUsedBufferId", lastBufId.toInt());
308 saveAutoSaveSettings();
313 void MainWin::restoreStateFromSettings(UiSettings &s)
315 _normalSize = s.value("MainWinSize", size()).toSize();
316 _normalPos = s.value("MainWinPos", pos()).toPoint();
317 bool maximized = s.value("MainWinMaximized", false).toBool();
320 restoreGeometry(s.value("MainWinGeometry").toByteArray());
323 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
328 restoreState(s.value("MainWinState").toByteArray());
334 if ((Quassel::isOptionSet("hidewindow")
335 || s.value("MainWinHidden").toBool())
336 && _systemTray->isSystemTrayAvailable())
337 QtUi::hideMainWidget();
338 else if (s.value("MainWinMinimized").toBool())
346 QMenu *MainWin::createPopupMenu()
348 QMenu *popupMenu = QMainWindow::createPopupMenu();
349 popupMenu->addSeparator();
350 ActionCollection *coll = QtUi::actionCollection("General");
351 popupMenu->addAction(coll->action("ToggleMenuBar"));
356 void MainWin::updateIcon()
359 if (Client::isConnected())
360 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
362 icon = QIcon::fromTheme("quassel-inactive", QIcon(":/icons/quassel-128.png"));
364 qApp->setWindowIcon(icon);
368 void MainWin::setupActions()
370 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
372 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("network-connect"), tr("&Connect to Core..."), coll,
373 this, SLOT(showCoreConnectionDlg())));
374 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("network-disconnect"), tr("&Disconnect from Core"), coll,
375 Client::instance(), SLOT(disconnectFromCore())));
376 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
377 this, SLOT(showPasswordChangeDlg())));
378 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
379 this, SLOT(showCoreInfoDlg())));
380 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
381 this, SLOT(on_actionConfigureNetworks_triggered())));
382 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
383 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
384 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
387 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
388 this, SLOT(on_actionConfigureViews_triggered())));
390 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
391 lockAct->setCheckable(true);
392 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
394 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
395 0, 0, QKeySequence::Find))->setCheckable(true);
396 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
397 this, SLOT(showAwayLog())));
398 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
399 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
401 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
402 0, 0))->setCheckable(true);
405 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
407 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
408 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
409 _fullScreenAction->setCheckable(true);
410 coll->addAction("ToggleFullScreen", _fullScreenAction);
414 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
415 this, SLOT(showShortcutsDlg()));
416 configureShortcutsAct->setMenuRole(QAction::NoRole);
417 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
420 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
421 this, SLOT(showSettingsDlg()));
422 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
424 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
425 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
427 coll->addAction("ConfigureQuassel", configureQuasselAct);
430 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
431 this, SLOT(showAboutDlg()));
432 aboutQuasselAct->setMenuRole(QAction::AboutRole);
433 coll->addAction("AboutQuassel", aboutQuasselAct);
435 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
436 qApp, SLOT(aboutQt()));
437 aboutQtAct->setMenuRole(QAction::AboutQtRole);
438 coll->addAction("AboutQt", aboutQtAct);
439 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
440 this, SLOT(on_actionDebugNetworkModel_triggered())));
441 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
442 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
443 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
444 this, SLOT(on_actionDebugMessageModel_triggered())));
445 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
446 this, SLOT(on_actionDebugHotList_triggered())));
447 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
448 this, SLOT(on_actionDebugLog_triggered())));
449 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
450 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
452 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
453 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
456 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
458 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
459 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
463 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
464 const int jumpModifier = Qt::ControlModifier;
466 const int bindModifier = Qt::ControlModifier;
467 const int jumpModifier = Qt::AltModifier;
470 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
471 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
472 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
473 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
474 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
475 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
476 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
477 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
478 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
479 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
480 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
481 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
482 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
483 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
484 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
485 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
486 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
487 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
488 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
489 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
491 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
492 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
493 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
494 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
495 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
496 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
497 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
498 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
499 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
500 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
501 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
502 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
503 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
504 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
505 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
506 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
507 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
508 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
509 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
510 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
513 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
514 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
515 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
516 this, SLOT(previousBufferView()), QKeySequence::Back));
517 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
518 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
519 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
520 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
524 void MainWin::setupMenus()
526 ActionCollection *coll = QtUi::actionCollection("General");
528 _fileMenu = menuBar()->addMenu(tr("&File"));
530 static const QStringList coreActions = QStringList()
531 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
534 foreach(QString actionName, coreActions) {
535 coreAction = coll->action(actionName);
536 _fileMenu->addAction(coreAction);
537 flagRemoteCoreOnly(coreAction);
539 flagRemoteCoreOnly(_fileMenu->addSeparator());
541 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
542 _networksMenu->addAction(coll->action("ConfigureNetworks"));
543 _networksMenu->addSeparator();
544 _fileMenu->addSeparator();
545 _fileMenu->addAction(coll->action("Quit"));
547 _viewMenu = menuBar()->addMenu(tr("&View"));
548 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
549 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
550 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
551 _viewMenu->addSeparator();
553 _viewMenu->addAction(coll->action("ToggleMenuBar"));
554 _viewMenu->addAction(coll->action("ToggleStatusBar"));
555 _viewMenu->addAction(coll->action("ToggleSearchBar"));
557 coreAction = coll->action("ShowAwayLog");
558 flagRemoteCoreOnly(coreAction);
559 _viewMenu->addAction(coreAction);
561 _viewMenu->addSeparator();
562 _viewMenu->addAction(coll->action("LockLayout"));
564 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
566 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
567 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
569 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
571 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
574 _helpMenu = menuBar()->addMenu(tr("&Help"));
576 _helpMenu->addAction(coll->action("AboutQuassel"));
578 _helpMenu->addAction(coll->action("AboutQt"));
580 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
582 _helpMenu->addSeparator();
583 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
584 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
585 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
586 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
587 _helpDebugMenu->addAction(coll->action("DebugHotList"));
588 _helpDebugMenu->addAction(coll->action("DebugLog"));
589 _helpDebugMenu->addSeparator();
590 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
593 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
595 QtUiSettings uiSettings;
596 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
597 showMenuBar->setChecked(enabled);
598 enabled ? menuBar()->show() : menuBar()->hide();
600 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
601 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
605 void MainWin::setupBufferWidget()
607 _bufferWidget = new BufferWidget(this);
608 _bufferWidget->setModel(Client::bufferModel());
609 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
610 setCentralWidget(_bufferWidget);
614 void MainWin::addBufferView(int bufferViewConfigId)
616 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
620 void MainWin::addBufferView(ClientBufferViewConfig *config)
625 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
626 BufferViewDock *dock = new BufferViewDock(config, this);
628 //create the view and initialize it's filter
629 BufferView *view = new BufferView(dock);
630 view->setFilteredModel(Client::bufferModel(), config);
631 view->installEventFilter(_inputWidget); // for key presses
633 Client::bufferModel()->synchronizeView(view);
635 dock->setWidget(view);
636 dock->setVisible(_layoutLoaded); // don't show before state has been restored
638 addDockWidget(Qt::LeftDockWidgetArea, dock);
639 _bufferViewsMenu->addAction(dock->toggleViewAction());
641 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
642 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
643 _bufferViews.append(dock);
645 if (!activeBufferView())
650 void MainWin::removeBufferView(int bufferViewConfigId)
653 BufferViewDock *dock;
654 foreach(QAction *action, _bufferViewsMenu->actions()) {
655 actionData = action->data();
656 if (!actionData.isValid())
659 dock = qobject_cast<BufferViewDock *>(action->parent());
660 if (dock && actionData.toInt() == bufferViewConfigId) {
661 removeAction(action);
662 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
663 _bufferViews.removeAll(dock);
665 if (dock->isActive()) {
666 dock->setActive(false);
667 _activeBufferViewIndex = -1;
677 void MainWin::bufferViewToggled(bool enabled)
679 if (!enabled && !isMinimized()) {
680 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
681 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
684 QAction *action = qobject_cast<QAction *>(sender());
686 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
689 // Make sure we don't toggle backlog fetch for a view we've already removed
690 if (!_bufferViews.contains(dock))
694 Client::bufferViewOverlay()->addView(dock->bufferViewId());
696 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
700 void MainWin::bufferViewVisibilityChanged(bool visible)
703 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
705 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
710 BufferView *MainWin::allBuffersView() const
712 // "All Buffers" is always the first dock created
713 if (_bufferViews.count() > 0)
714 return _bufferViews[0]->bufferView();
719 BufferView *MainWin::activeBufferView() const
721 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
723 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
724 return dock->isActive() ? qobject_cast<BufferView *>(dock->widget()) : 0;
728 void MainWin::changeActiveBufferView(int bufferViewId)
730 if (bufferViewId < 0)
733 BufferView *current = activeBufferView();
735 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
736 _activeBufferViewIndex = -1;
739 for (int i = 0; i < _bufferViews.count(); i++) {
740 BufferViewDock *dock = _bufferViews.at(i);
741 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
742 _activeBufferViewIndex = i;
743 dock->setActive(true);
748 nextBufferView(); // fallback
752 void MainWin::showPasswordChangeDlg()
754 if((Client::coreFeatures() & Quassel::PasswordChange)) {
755 PasswordChangeDlg dlg(this);
759 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
760 tr("<b>Your Quassel Core does not support this feature</b>"),
761 QMessageBox::Ok, this);
762 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
768 void MainWin::changeActiveBufferView(bool backwards)
770 BufferView *current = activeBufferView();
772 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
774 if (!_bufferViews.count())
777 int c = _bufferViews.count();
778 while (c--) { // yes, this will reactivate the current active one if all others fail
780 if (--_activeBufferViewIndex < 0)
781 _activeBufferViewIndex = _bufferViews.count()-1;
784 if (++_activeBufferViewIndex >= _bufferViews.count())
785 _activeBufferViewIndex = 0;
788 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
789 if (dock->isHidden())
792 dock->setActive(true);
796 _activeBufferViewIndex = -1;
800 void MainWin::nextBufferView()
802 changeActiveBufferView(false);
806 void MainWin::previousBufferView()
808 changeActiveBufferView(true);
812 void MainWin::nextBuffer()
814 BufferView *view = activeBufferView();
820 void MainWin::previousBuffer()
822 BufferView *view = activeBufferView();
824 view->previousBuffer();
828 void MainWin::hideCurrentBuffer()
830 BufferView *view = activeBufferView();
832 view->hideCurrentBuffer();
836 void MainWin::showNotificationsDlg()
838 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
843 void MainWin::on_actionConfigureNetworks_triggered()
845 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
850 void MainWin::on_actionConfigureViews_triggered()
852 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
857 void MainWin::on_actionLockLayout_toggled(bool lock)
859 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
860 foreach(VerticalDock *dock, docks) {
861 dock->showTitle(!lock);
863 if (Client::bufferViewManager()) {
864 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
865 config->setLocked(lock);
868 QtUiSettings().setValue("LockLayout", lock);
872 void MainWin::setupNickWidget()
875 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
876 nickDock->setObjectName("NickDock");
877 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
879 _nickListWidget = new NickListWidget(nickDock);
880 nickDock->setWidget(_nickListWidget);
882 addDockWidget(Qt::RightDockWidgetArea, nickDock);
883 _viewMenu->addAction(nickDock->toggleViewAction());
884 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
886 // See NickListDock::NickListDock();
887 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
889 // attach the NickListWidget to the BufferModel and the default selection
890 _nickListWidget->setModel(Client::bufferModel());
891 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
895 void MainWin::setupChatMonitor()
897 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
898 dock->setObjectName("ChatMonitorDock");
900 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
901 _chatMonitorView = new ChatMonitorView(filter, this);
902 _chatMonitorView->setFocusProxy(_inputWidget);
903 _chatMonitorView->show();
904 dock->setWidget(_chatMonitorView);
907 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
908 _viewMenu->addAction(dock->toggleViewAction());
909 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
913 void MainWin::setupInputWidget()
915 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
916 dock->setObjectName("InputDock");
918 _inputWidget = new InputWidget(dock);
919 dock->setWidget(_inputWidget);
921 addDockWidget(Qt::BottomDockWidgetArea, dock);
923 _viewMenu->addAction(dock->toggleViewAction());
924 dock->toggleViewAction()->setText(tr("Show Input Line"));
926 _inputWidget->setModel(Client::bufferModel());
927 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
929 _bufferWidget->setFocusProxy(_inputWidget);
931 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
933 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
937 void MainWin::setupTopicWidget()
939 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
940 dock->setObjectName("TopicDock");
941 _topicWidget = new TopicWidget(dock);
943 dock->setWidget(_topicWidget);
945 _topicWidget->setModel(Client::bufferModel());
946 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
948 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
950 _viewMenu->addAction(dock->toggleViewAction());
951 dock->toggleViewAction()->setText(tr("Show Topic Line"));
955 void MainWin::setupViewMenuTail()
957 _viewMenu->addSeparator();
958 _viewMenu->addAction(_fullScreenAction);
962 void MainWin::setupTitleSetter()
964 _titleSetter.setModel(Client::bufferModel());
965 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
969 void MainWin::setupStatusBar()
971 // MessageProcessor progress
972 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
975 _coreConnectionStatusWidget->update();
976 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
978 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
980 QtUiSettings uiSettings;
982 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
983 showStatusbar->setChecked(enabled);
984 enabled ? statusBar()->show() : statusBar()->hide();
986 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
987 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
989 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
993 void MainWin::setupHotList()
995 FlatProxyModel *flatProxy = new FlatProxyModel(this);
996 flatProxy->setSourceModel(Client::bufferModel());
997 _bufferHotList = new BufferHotListFilter(flatProxy);
1001 void MainWin::saveMenuBarStatus(bool enabled)
1003 QtUiSettings uiSettings;
1004 uiSettings.setValue("ShowMenuBar", enabled);
1008 void MainWin::saveStatusBarStatus(bool enabled)
1010 QtUiSettings uiSettings;
1011 uiSettings.setValue("ShowStatusBar", enabled);
1015 void MainWin::setupSystray()
1018 _systemTray = new StatusNotifierItem(this);
1019 #elif !defined QT_NO_SYSTEMTRAYICON
1020 _systemTray = new LegacySystemTray(this);
1022 _systemTray = new SystemTray(this); // dummy
1024 _systemTray->init();
1028 void MainWin::setupToolBars()
1030 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1031 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1032 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1033 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1036 setUnifiedTitleAndToolBarOnMac(true);
1040 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1042 _mainToolBar = new QToolBar(this);
1043 _mainToolBar->setObjectName("MainToolBar");
1045 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1046 addToolBar(_mainToolBar);
1048 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1049 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1052 QtUiSettings uiSettings;
1054 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1055 _mainToolBar->setVisible(visible);
1056 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1060 void MainWin::saveMainToolBarStatus(bool enabled)
1063 QtUiSettings uiSettings;
1064 uiSettings.setValue("ShowMainToolBar", enabled);
1071 void MainWin::connectedToCore()
1073 Q_CHECK_PTR(Client::bufferViewManager());
1074 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1075 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1076 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1078 connect(Client::transferManager(), SIGNAL(transferAdded(const ClientTransfer*)), SLOT(showNewTransferDlg(const ClientTransfer*)));
1080 setConnectedState();
1084 void MainWin::setConnectedState()
1086 ActionCollection *coll = QtUi::actionCollection("General");
1088 coll->action("ConnectCore")->setEnabled(false);
1089 coll->action("DisconnectCore")->setEnabled(true);
1090 coll->action("ChangePassword")->setEnabled(true);
1091 coll->action("CoreInfo")->setEnabled(true);
1093 foreach(QAction *action, _fileMenu->actions()) {
1094 if (isRemoteCoreOnly(action))
1095 action->setVisible(!Client::internalCore());
1098 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1099 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1100 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1101 if (!Client::internalCore()) {
1102 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1103 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1104 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1107 // _viewMenu->setEnabled(true);
1108 if (!Client::internalCore())
1109 statusBar()->showMessage(tr("Connected to core."));
1111 statusBar()->clearMessage();
1113 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1115 systemTray()->setState(SystemTray::Active);
1117 if (Client::networkIds().isEmpty()) {
1118 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1122 // Monolithic always preselects last used buffer - Client only if the connection died
1123 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1125 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1126 if (lastUsedBufferId.isValid())
1127 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1133 void MainWin::loadLayout()
1136 int accountId = Client::currentCoreAccount().accountId().toInt();
1137 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1138 if (state.isEmpty()) {
1139 foreach(BufferViewDock *view, _bufferViews)
1141 _layoutLoaded = true;
1145 restoreState(state, accountId);
1146 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1147 if (bufferViewId >= 0)
1148 changeActiveBufferView(bufferViewId);
1150 _layoutLoaded = true;
1154 void MainWin::saveLayout()
1157 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1158 if (accountId > 0) {
1159 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1160 BufferView *view = activeBufferView();
1161 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1166 void MainWin::disconnectedFromCore()
1168 // save core specific layout and remove bufferviews;
1170 _layoutLoaded = false;
1172 QVariant actionData;
1173 BufferViewDock *dock;
1174 foreach(QAction *action, _bufferViewsMenu->actions()) {
1175 actionData = action->data();
1176 if (!actionData.isValid())
1179 dock = qobject_cast<BufferViewDock *>(action->parent());
1180 if (dock && actionData.toInt() != -1) {
1181 removeAction(action);
1182 _bufferViews.removeAll(dock);
1183 dock->deleteLater();
1187 // store last active buffer
1189 BufferId lastBufId = _bufferWidget->currentBuffer();
1190 if (lastBufId.isValid()) {
1191 s.setValue("LastUsedBufferId", lastBufId.toInt());
1192 // clear the current selection
1193 Client::bufferModel()->standardSelectionModel()->clearSelection();
1195 restoreState(s.value("MainWinState").toByteArray());
1196 setDisconnectedState();
1200 void MainWin::setDisconnectedState()
1202 ActionCollection *coll = QtUi::actionCollection("General");
1203 //ui.menuCore->setEnabled(false);
1204 coll->action("ConnectCore")->setEnabled(true);
1205 coll->action("DisconnectCore")->setEnabled(false);
1206 coll->action("CoreInfo")->setEnabled(false);
1207 coll->action("ChangePassword")->setEnabled(false);
1208 //_viewMenu->setEnabled(false);
1209 statusBar()->showMessage(tr("Not connected to core."));
1210 if (_msgProcessorStatusWidget)
1211 _msgProcessorStatusWidget->setProgress(0, 0);
1213 systemTray()->setState(SystemTray::Passive);
1217 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1219 Q_UNUSED(errorMessage)
1220 CoreConnectAuthDlg dlg(account, this);
1221 *valid = (dlg.exec() == QDialog::Accepted);
1225 void MainWin::handleNoSslInClient(bool *accepted)
1227 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1228 QMessageBox::Ignore|QMessageBox::Cancel, this);
1229 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1230 box.setDefaultButton(QMessageBox::Ignore);
1231 *accepted = box.exec() == QMessageBox::Ignore;
1235 void MainWin::handleNoSslInCore(bool *accepted)
1237 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1238 QMessageBox::Ignore|QMessageBox::Cancel, this);
1239 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1240 box.setDefaultButton(QMessageBox::Ignore);
1241 *accepted = box.exec() == QMessageBox::Ignore;
1247 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1249 QString errorString = "<ul>";
1250 foreach(const QSslError error, socket->sslErrors())
1251 errorString += QString("<li>%1</li>").arg(error.errorString());
1252 errorString += "</ul>";
1254 QMessageBox box(QMessageBox::Warning,
1255 tr("Untrusted Security Certificate"),
1256 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1257 QMessageBox::Cancel, this);
1258 box.setInformativeText(errorString);
1259 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1260 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1262 QMessageBox::ButtonRole role;
1265 role = box.buttonRole(box.clickedButton());
1266 if (role == QMessageBox::HelpRole) {
1267 SslInfoDlg dlg(socket, this);
1271 while (role == QMessageBox::HelpRole);
1273 *accepted = role == QMessageBox::AcceptRole;
1275 QMessageBox box2(QMessageBox::Warning,
1276 tr("Untrusted Security Certificate"),
1277 tr("Would you like to accept this certificate forever without being prompted?"),
1279 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1280 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1282 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1287 #endif /* HAVE_SSL */
1289 void MainWin::handleCoreConnectionError(const QString &error)
1291 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1295 void MainWin::showCoreConnectionDlg()
1297 CoreConnectDlg dlg(this);
1298 if (dlg.exec() == QDialog::Accepted) {
1299 AccountId accId = dlg.selectedAccount();
1300 if (accId.isValid())
1301 Client::coreConnection()->connectToCore(accId);
1306 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1308 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1314 void MainWin::showChannelList(NetworkId netId)
1316 ChannelListDlg *channelListDlg = new ChannelListDlg();
1318 if (!netId.isValid()) {
1319 QAction *action = qobject_cast<QAction *>(sender());
1321 netId = action->data().value<NetworkId>();
1324 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1325 channelListDlg->setNetwork(netId);
1326 channelListDlg->show();
1330 void MainWin::showIgnoreList(QString newRule)
1332 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1333 // prepare config dialog for new rule
1334 if (!newRule.isEmpty())
1335 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1340 void MainWin::showCoreInfoDlg()
1342 CoreInfoDlg(this).exec();
1346 void MainWin::showAwayLog()
1350 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1351 _awayLog = new AwayLogView(filter, 0);
1352 filter->setParent(_awayLog);
1353 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1354 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1359 void MainWin::awayLogDestroyed()
1365 void MainWin::showSettingsDlg()
1367 SettingsDlg *dlg = new SettingsDlg();
1369 //Category: Interface
1370 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1371 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1372 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1373 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1374 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1375 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1376 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1377 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1378 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1379 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1382 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1383 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1384 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1385 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1386 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1388 // Category: Remote Cores
1389 if (Quassel::runMode() != Quassel::Monolithic) {
1390 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1391 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1398 void MainWin::showAboutDlg()
1400 AboutDlg(this).exec();
1404 void MainWin::showShortcutsDlg()
1407 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1408 foreach(KActionCollection *coll, QtUi::actionCollections())
1409 dlg.addCollection(coll, coll->property("Category").toString());
1410 dlg.configure(true);
1412 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1418 void MainWin::showNewTransferDlg(const ClientTransfer *transfer)
1420 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1425 void MainWin::onFullScreenToggled()
1427 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1428 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1431 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1433 if (_fullScreenAction->isChecked())
1434 setWindowState(windowState() | Qt::WindowFullScreen);
1436 setWindowState(windowState() & ~Qt::WindowFullScreen);
1441 /********************************************************************************************************/
1443 bool MainWin::event(QEvent *event)
1445 switch(event->type()) {
1446 case QEvent::WindowActivate: {
1447 BufferId bufferId = Client::bufferModel()->currentBuffer();
1448 if (bufferId.isValid())
1449 Client::instance()->markBufferAsRead(bufferId);
1452 case QEvent::WindowDeactivate:
1453 if (bufferWidget()->autoMarkerLineOnLostFocus())
1454 bufferWidget()->setMarkerLine();
1459 return QMainWindow::event(event);
1463 void MainWin::moveEvent(QMoveEvent *event)
1465 if (!(windowState() & Qt::WindowMaximized))
1466 _normalPos = event->pos();
1468 QMainWindow::moveEvent(event);
1472 void MainWin::resizeEvent(QResizeEvent *event)
1474 if (!(windowState() & Qt::WindowMaximized))
1475 _normalSize = event->size();
1477 QMainWindow::resizeEvent(event);
1481 void MainWin::closeEvent(QCloseEvent *event)
1484 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1486 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1487 // This messes up MainWinState/MainWinHidden save/restore.
1488 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1489 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1490 QtUi::hideMainWidget();
1493 else if(!_aboutToQuit) {
1494 _aboutToQuit = true;
1504 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1508 bool hasFocus = QApplication::activeWindow() != 0;
1510 for (int i = start; i <= end; i++) {
1511 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1512 if (!idx.isValid()) {
1513 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1516 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1517 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1520 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1521 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1523 // check if bufferId belongs to the shown chatlists
1524 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1525 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1528 // check if it's the buffer currently displayed
1529 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1532 // only show notifications for higlights or queries
1533 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1536 // and of course: don't notify for ignored messages
1537 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1540 // seems like we have a legit notification candidate!
1541 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1542 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1543 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1544 AbstractNotificationBackend::NotificationType type;
1546 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1547 type = AbstractNotificationBackend::PrivMsg;
1548 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1549 type = AbstractNotificationBackend::PrivMsgFocused;
1550 else if (flags & Message::Highlight && !hasFocus)
1551 type = AbstractNotificationBackend::Highlight;
1553 type = AbstractNotificationBackend::HighlightFocused;
1555 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1560 void MainWin::currentBufferChanged(BufferId buffer)
1562 if (buffer.isValid())
1563 Client::instance()->markBufferAsRead(buffer);
1567 void MainWin::clientNetworkCreated(NetworkId id)
1569 const Network *net = Client::network(id);
1570 QAction *act = new QAction(net->networkName(), this);
1571 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1572 act->setData(QVariant::fromValue<NetworkId>(id));
1573 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1574 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1576 QAction *beforeAction = 0;
1577 foreach(QAction *action, _networksMenu->actions()) {
1578 if (!action->data().isValid()) // ignore stock actions
1580 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1581 beforeAction = action;
1585 _networksMenu->insertAction(beforeAction, act);
1589 void MainWin::clientNetworkUpdated()
1591 const Network *net = qobject_cast<const Network *>(sender());
1595 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1599 action->setText(net->networkName());
1601 switch (net->connectionState()) {
1602 case Network::Initialized:
1603 action->setIcon(QIcon::fromTheme("network-connect"));
1604 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1605 if (!bufferWidget()->currentBuffer().isValid()) {
1606 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1607 if (idx.isValid()) {
1608 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1609 Client::bufferModel()->switchToBuffer(statusBufferId);
1613 case Network::Disconnected:
1614 action->setIcon(QIcon::fromTheme("network-disconnect"));
1617 action->setIcon(QIcon::fromTheme("network-wired"));
1622 void MainWin::clientNetworkRemoved(NetworkId id)
1624 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1628 action->deleteLater();
1632 void MainWin::connectOrDisconnectFromNet()
1634 QAction *act = qobject_cast<QAction *>(sender());
1636 const Network *net = Client::network(act->data().value<NetworkId>());
1638 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1639 else net->requestDisconnect();
1643 void MainWin::on_jumpHotBuffer_triggered()
1645 if (!_bufferHotList->rowCount())
1648 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1652 void MainWin::onJumpKey()
1654 QAction *action = qobject_cast<QAction *>(sender());
1655 if (!action || !Client::bufferModel())
1657 int idx = action->property("Index").toInt();
1659 if (_jumpKeyMap.isEmpty())
1660 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1662 if (!_jumpKeyMap.contains(idx))
1665 BufferId buffer = _jumpKeyMap.value(idx);
1666 if (buffer.isValid())
1667 Client::bufferModel()->switchToBuffer(buffer);
1671 void MainWin::bindJumpKey()
1673 QAction *action = qobject_cast<QAction *>(sender());
1674 if (!action || !Client::bufferModel())
1676 int idx = action->property("Index").toInt();
1678 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1679 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1683 void MainWin::on_actionDebugNetworkModel_triggered()
1685 QTreeView *view = new QTreeView;
1686 view->setAttribute(Qt::WA_DeleteOnClose);
1687 view->setWindowTitle("Debug NetworkModel View");
1688 view->setModel(Client::networkModel());
1689 view->setColumnWidth(0, 250);
1690 view->setColumnWidth(1, 250);
1691 view->setColumnWidth(2, 80);
1692 view->resize(610, 300);
1697 void MainWin::on_actionDebugHotList_triggered()
1699 _bufferHotList->invalidate();
1700 _bufferHotList->sort(0, Qt::DescendingOrder);
1702 QTreeView *view = new QTreeView;
1703 view->setAttribute(Qt::WA_DeleteOnClose);
1704 view->setModel(_bufferHotList);
1709 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1711 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1712 overlay->setAttribute(Qt::WA_DeleteOnClose);
1717 void MainWin::on_actionDebugMessageModel_triggered()
1719 QTableView *view = new QTableView(0);
1720 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1721 filter->setSourceModel(Client::messageModel());
1722 view->setModel(filter);
1723 view->setAttribute(Qt::WA_DeleteOnClose, true);
1724 view->verticalHeader()->hide();
1725 view->horizontalHeader()->setStretchLastSection(true);
1730 void MainWin::on_actionDebugLog_triggered()
1732 DebugLogWidget *logWidget = new DebugLogWidget(0);
1737 void MainWin::showStatusBarMessage(const QString &message)
1739 statusBar()->showMessage(message, 10000);