1 /***************************************************************************
2 * Copyright (C) 2005-2020 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 <QInputDialog>
26 #include <QMessageBox>
32 # include <kconfigwidgets_version.h>
34 # include <KConfigWidgets/KStandardAction>
35 # include <KWidgetsAddons/KToggleFullScreenAction>
36 # include <KXmlGui/KHelpMenu>
37 # include <KXmlGui/KShortcutsDialog>
38 # include <KXmlGui/KToolBar>
47 #include "actioncollection.h"
48 #include "awaylogfilter.h"
49 #include "awaylogview.h"
50 #include "bufferhotlistfilter.h"
51 #include "buffermodel.h"
52 #include "bufferview.h"
53 #include "bufferviewoverlay.h"
54 #include "bufferviewoverlayfilter.h"
55 #include "bufferwidget.h"
56 #include "channellistdlg.h"
57 #include "chatlinemodel.h"
58 #include "chatmonitorfilter.h"
59 #include "chatmonitorview.h"
62 #include "clientbacklogmanager.h"
63 #include "clientbufferviewconfig.h"
64 #include "clientbufferviewmanager.h"
65 #include "clientignorelistmanager.h"
66 #include "clienttransfer.h"
67 #include "clienttransfermanager.h"
68 #include "contextmenuactionprovider.h"
69 #include "coreconfigwizard.h"
70 #include "coreconnectdlg.h"
71 #include "coreconnection.h"
72 #include "coreconnectionstatuswidget.h"
73 #include "coreinfodlg.h"
74 #include "debugbufferviewoverlay.h"
75 #include "debuglogdlg.h"
76 #include "debugmessagemodelfilter.h"
77 #include "flatproxymodel.h"
79 #include "inputwidget.h"
80 #include "ircconnectionwizard.h"
81 #include "irclistmodel.h"
82 #include "legacysystemtray.h"
83 #include "msgprocessorstatuswidget.h"
84 #include "nicklistwidget.h"
85 #include "passwordchangedlg.h"
86 #include "qtuiapplication.h"
87 #include "qtuimessageprocessor.h"
88 #include "qtuisettings.h"
89 #include "qtuistyle.h"
90 #include "receivefiledlg.h"
91 #include "resourcetreedlg.h"
92 #include "settingsdlg.h"
93 #include "settingspagedlg.h"
94 #include "sslinfodlg.h"
95 #include "statusnotifieritem.h"
96 #include "toolbaractionprovider.h"
97 #include "topicwidget.h"
98 #include "transfermodel.h"
99 #include "verticaldock.h"
102 # ifdef HAVE_QTMULTIMEDIA
103 # include "qtmultimedianotificationbackend.h"
105 # include "systraynotificationbackend.h"
106 # include "taskbarnotificationbackend.h"
108 # include "knotificationbackend.h"
109 #endif /* HAVE_KDE */
110 #include "systrayanimationnotificationbackend.h"
113 # include "snorenotificationbackend.h"
116 #ifdef HAVE_NOTIFICATION_CENTER
117 # include "osxnotificationbackend.h"
121 # include "dockmanagernotificationbackend.h"
124 #include "settingspages/aliasessettingspage.h"
125 #include "settingspages/appearancesettingspage.h"
126 #include "settingspages/backlogsettingspage.h"
127 #include "settingspages/bufferviewsettingspage.h"
128 #include "settingspages/chatmonitorsettingspage.h"
129 #include "settingspages/chatviewcolorsettingspage.h"
130 #include "settingspages/chatviewsettingspage.h"
131 #include "settingspages/connectionsettingspage.h"
132 #include "settingspages/coreaccountsettingspage.h"
133 #include "settingspages/coreconnectionsettingspage.h"
134 #include "settingspages/corehighlightsettingspage.h"
135 #include "settingspages/dccsettingspage.h"
136 #include "settingspages/highlightsettingspage.h"
137 #include "settingspages/identitiessettingspage.h"
138 #include "settingspages/ignorelistsettingspage.h"
139 #include "settingspages/inputwidgetsettingspage.h"
140 #include "settingspages/itemviewsettingspage.h"
141 #include "settingspages/networkssettingspage.h"
142 #include "settingspages/notificationssettingspage.h"
143 #include "settingspages/topicwidgetsettingspage.h"
146 # include "settingspages/shortcutssettingspage.h"
150 # include "settingspages/sonnetsettingspage.h"
153 MainWin::MainWin(QWidget* parent)
155 : KMainWindow(parent)
156 , _kHelpMenu(new KHelpMenu(this))
159 : QMainWindow(parent)
162 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this))
163 , _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this))
166 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
168 QtUiSettings uiSettings;
169 QString style = uiSettings.value("Style", QString()).toString();
170 if (!style.isEmpty()) {
171 QApplication::setStyle(style);
174 QApplication::setQuitOnLastWindowClosed(false);
176 setWindowTitle("Quassel IRC");
177 setWindowIconText("Quassel IRC");
178 // Set the default icon for all windows
179 QApplication::setWindowIcon(icon::get("quassel"));
185 connect(Client::instance(), &Client::networkCreated, this, &MainWin::clientNetworkCreated);
186 connect(Client::instance(), &Client::networkRemoved, this, &MainWin::clientNetworkRemoved);
187 connect(Client::messageModel(), &QAbstractItemModel::rowsInserted, this, &MainWin::messagesInserted);
188 connect(GraphicalUi::contextMenuActionProvider(), &NetworkModelController::showChannelList, this, &MainWin::showChannelList);
189 connect(Client::instance(), &Client::showChannelList, this, &MainWin::showChannelList);
190 connect(GraphicalUi::contextMenuActionProvider(), &NetworkModelController::showNetworkConfig, this, &MainWin::showNetworkConfig);
191 connect(GraphicalUi::contextMenuActionProvider(), &NetworkModelController::showIgnoreList, this, &MainWin::showIgnoreList);
192 connect(Client::instance(), &Client::showIgnoreList, this, &MainWin::showIgnoreList);
193 connect(Client::instance(), &Client::dbUpgradeInProgress, this, &MainWin::showMigrationWarning);
194 connect(Client::instance(), &Client::exitRequested, this, &MainWin::onExitRequested);
196 connect(Client::coreConnection(), &CoreConnection::startCoreSetup, this, &MainWin::showCoreConfigWizard);
197 connect(Client::coreConnection(), &CoreConnection::connectionErrorPopup, this, &MainWin::handleCoreConnectionError);
198 connect(Client::coreConnection(), &CoreConnection::userAuthenticationRequired, this, &MainWin::userAuthenticationRequired);
199 connect(Client::coreConnection(), &CoreConnection::handleNoSslInClient, this, &MainWin::handleNoSslInClient);
200 connect(Client::coreConnection(), &CoreConnection::handleNoSslInCore, this, &MainWin::handleNoSslInCore);
201 connect(Client::coreConnection(), &CoreConnection::handleSslErrors, this, &MainWin::handleSslErrors);
204 setDockNestingEnabled(true);
205 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
206 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
207 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
208 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
210 // Order is sometimes important
214 // setupTransferWidget(); not ready yet
226 _bufferWidget->setFocusProxy(_inputWidget);
227 _chatMonitorView->setFocusProxy(_inputWidget);
230 # ifdef HAVE_QTMULTIMEDIA
231 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
233 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
235 QtUi::registerNotificationBackend(new KNotificationBackend(this));
236 #endif /* HAVE_KDE */
238 #ifndef QT_NO_SYSTEMTRAYICON
239 QtUi::registerNotificationBackend(new SystrayAnimationNotificationBackend(this));
242 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
243 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
244 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
247 #ifdef HAVE_NOTIFICATION_CENTER
248 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
252 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
255 // we assume that at this point, all configurable actions are defined!
256 QtUi::loadShortcuts();
258 connect(bufferWidget(), selectOverload<BufferId>(&AbstractBufferContainer::currentChanged), this, &MainWin::currentBufferChanged);
260 setDisconnectedState(); // Disable menus and stuff
263 setAutoSaveSettings();
266 // restore mainwin state
268 restoreStateFromSettings(s);
270 // restore locked state of docks
271 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
273 Quassel::registerQuitHandler([this]() {
275 saveStateToSettings(s);
277 // Close all open dialogs and the MainWin, so we can safely kill the Client instance afterwards
278 // Note: This does not quit the application, as quitOnLastWindowClosed is set to false.
279 // We rely on another quit handler to be registered that actually quits the application.
280 qApp->closeAllWindows();
283 QTimer::singleShot(0, this, &MainWin::doAutoConnect);
286 void MainWin::saveStateToSettings(UiSettings& s)
288 s.setValue("MainWinSize", _normalSize);
289 s.setValue("MainWinPos", _normalPos);
290 s.setValue("MainWinState", saveState());
291 s.setValue("MainWinGeometry", saveGeometry());
292 s.setValue("MainWinMinimized", isMinimized());
293 s.setValue("MainWinMaximized", isMaximized());
294 s.setValue("MainWinHidden", !isVisible());
295 BufferId lastBufId = Client::bufferModel()->currentBuffer();
296 if (lastBufId.isValid())
297 s.setValue("LastUsedBufferId", lastBufId.toInt());
300 saveAutoSaveSettings();
304 void MainWin::restoreStateFromSettings(UiSettings& s)
306 _normalSize = s.value("MainWinSize", size()).toSize();
307 _normalPos = s.value("MainWinPos", pos()).toPoint();
308 bool maximized = s.value("MainWinMaximized", false).toBool();
311 restoreGeometry(s.value("MainWinGeometry").toByteArray());
314 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
319 restoreState(s.value("MainWinState").toByteArray());
325 if ((Quassel::isOptionSet("hidewindow") || s.value("MainWinHidden").toBool()) && _systemTray->isSystemTrayAvailable())
326 QtUi::hideMainWidget();
327 else if (s.value("MainWinMinimized").toBool())
335 QMenu* MainWin::createPopupMenu()
337 QMenu* popupMenu = QMainWindow::createPopupMenu();
338 popupMenu->addSeparator();
339 ActionCollection* coll = QtUi::actionCollection("General");
340 popupMenu->addAction(coll->action("ToggleMenuBar"));
344 void MainWin::updateIcon()
347 if (Client::isConnected())
348 icon = icon::get("quassel");
350 icon = icon::get("inactive-quassel");
354 void MainWin::setupActions()
356 QAction* action{nullptr};
357 ActionCollection* coll = QtUi::actionCollection("General", tr("General"));
361 {{"ConnectCore", new Action(icon::get("connect-quassel"), tr("&Connect to Core..."), coll, this, &MainWin::showCoreConnectionDlg)},
363 new Action(icon::get("disconnect-quassel"), tr("&Disconnect from Core"), coll, Client::instance(), &Client::disconnectFromCore)},
364 {"ChangePassword", new Action(icon::get("dialog-password"), tr("Change &Password..."), coll, this, &MainWin::showPasswordChangeDlg)},
365 {"CoreInfo", new Action(icon::get("help-about"), tr("Core &Info..."), coll, this, &MainWin::showCoreInfoDlg)},
366 {"ConfigureNetworks",
367 new Action(icon::get("configure"), tr("Configure &Networks..."), coll, this, &MainWin::onConfigureNetworksTriggered)},
368 {"Quit", new Action(icon::get("application-exit"), tr("&Quit"), coll, Quassel::instance(), &Quassel::quit, Qt::CTRL + Qt::Key_Q)}});
371 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll, this, &MainWin::onConfigureViewsTriggered));
373 coll->addAction("ToggleSearchBar", new Action(icon::get("edit-find"), tr("Show &Search Bar"), coll, QKeySequence::Find))->setCheckable(true);
374 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll, this, &MainWin::showAwayLog));
375 coll->addAction("ToggleMenuBar", new Action(icon::get("show-menu"), tr("Show &Menubar"), coll))->setCheckable(true);
376 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll))->setCheckable(true);
378 action = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
379 action->setCheckable(true);
380 connect(action, &QAction::toggled, this, &MainWin::onLockLayoutToggled);
383 # if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 23, 0)
384 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
386 _fullScreenAction = KStandardAction::fullScreen(this, &MainWin::onFullScreenToggled, this, coll);
389 _fullScreenAction = new Action(icon::get("view-fullscreen"),
390 tr("&Full Screen Mode"),
393 &MainWin::onFullScreenToggled,
394 QKeySequence::FullScreen);
395 _fullScreenAction->setCheckable(true);
396 coll->addAction("ToggleFullScreen", _fullScreenAction);
400 coll->addAction("ConfigureShortcuts",
401 new Action(icon::get("configure-shortcuts"), tr("Configure &Shortcuts..."), coll, this, &MainWin::showShortcutsDlg))
402 ->setMenuRole(QAction::NoRole);
403 coll->addAction("ConfigureQuassel",
404 new Action(icon::get("configure"), tr("&Configure Quassel..."), coll, this, &MainWin::showSettingsDlg, QKeySequence(Qt::Key_F7)))
405 ->setMenuRole(QAction::PreferencesRole);
408 coll->addAction("AboutQuassel", new Action(icon::get("quassel"), tr("&About Quassel"), coll, this, &MainWin::showAboutDlg))
409 ->setMenuRole(QAction::AboutRole);
410 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo-32.png"), tr("About &Qt"), coll, qApp, &QApplication::aboutQt))
411 ->setMenuRole(QAction::AboutQtRole);
413 {{"DebugNetworkModel",
414 new Action(icon::get("tools-report-bug"), tr("Debug &NetworkModel"), coll, this, &MainWin::onDebugNetworkModelTriggered)},
415 {"DebugBufferViewOverlay",
416 new Action(icon::get("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll, this, &MainWin::onDebugBufferViewOverlayTriggered)},
417 {"DebugMessageModel",
418 new Action(icon::get("tools-report-bug"), tr("Debug &MessageModel"), coll, this, &MainWin::onDebugMessageModelTriggered)},
419 {"DebugHotList", new Action(icon::get("tools-report-bug"), tr("Debug &HotList"), coll, this, &MainWin::onDebugHotListTriggered)},
420 {"DebugLog", new Action(icon::get("tools-report-bug"), tr("Debug &Log"), coll, this, &MainWin::onDebugLogTriggered)},
422 new Action(icon::get("tools-report-bug"), tr("Show &Resource Tree"), coll, this, &MainWin::onShowResourceTreeTriggered)},
424 new Action(icon::get("view-refresh"),
425 tr("Reload Stylesheet"),
429 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_R))}});
432 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll, this, &MainWin::hideCurrentBuffer, QKeySequence::Close));
435 coll = QtUi::actionCollection("TextFormat", tr("Text formatting"));
438 {{"FormatApplyColor",
439 new Action(icon::get("format-text-color"),
440 tr("Apply foreground color"),
443 &MainWin::onFormatApplyColorTriggered,
444 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_G))},
445 {"FormatApplyColorFill",
446 new Action(icon::get("format-fill-color"),
447 tr("Apply background color"),
450 &MainWin::onFormatApplyColorFillTriggered,
451 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B))},
453 new Action(icon::get("edit-clear"),
454 tr("Clear formatting"),
457 &MainWin::onFormatClearTriggered,
458 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C))},
460 new Action(icon::get("format-text-bold"), tr("Toggle bold"), coll, this, &MainWin::onFormatBoldTriggered, QKeySequence::Bold)},
462 new Action(icon::get("format-text-italic"), tr("Toggle italics"), coll, this, &MainWin::onFormatItalicTriggered, QKeySequence::Italic)},
464 new Action(icon::get("format-text-underline"),
465 tr("Toggle underline"),
468 &MainWin::onFormatUnderlineTriggered,
469 QKeySequence::Underline)}});
472 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
476 new Action(tr("Jump to hot chat"), coll, this, &MainWin::onJumpHotBufferTriggered, QKeySequence(Qt::META + Qt::Key_A))},
477 {"ActivateBufferFilter",
478 new Action(tr("Activate the buffer search"), coll, this, &MainWin::onBufferSearchTriggered, QKeySequence(Qt::CTRL + Qt::Key_S))}});
482 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
483 const int jumpModifier = Qt::ControlModifier;
485 const int bindModifier = Qt::ControlModifier;
486 const int jumpModifier = Qt::AltModifier;
489 coll->addAction("BindJumpKey0",
490 new Action(tr("Set Quick Access #0"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_0)))
491 ->setProperty("Index", 0);
492 coll->addAction("BindJumpKey1",
493 new Action(tr("Set Quick Access #1"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_1)))
494 ->setProperty("Index", 1);
495 coll->addAction("BindJumpKey2",
496 new Action(tr("Set Quick Access #2"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_2)))
497 ->setProperty("Index", 2);
498 coll->addAction("BindJumpKey3",
499 new Action(tr("Set Quick Access #3"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_3)))
500 ->setProperty("Index", 3);
501 coll->addAction("BindJumpKey4",
502 new Action(tr("Set Quick Access #4"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_4)))
503 ->setProperty("Index", 4);
504 coll->addAction("BindJumpKey5",
505 new Action(tr("Set Quick Access #5"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_5)))
506 ->setProperty("Index", 5);
507 coll->addAction("BindJumpKey6",
508 new Action(tr("Set Quick Access #6"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_6)))
509 ->setProperty("Index", 6);
510 coll->addAction("BindJumpKey7",
511 new Action(tr("Set Quick Access #7"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_7)))
512 ->setProperty("Index", 7);
513 coll->addAction("BindJumpKey8",
514 new Action(tr("Set Quick Access #8"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_8)))
515 ->setProperty("Index", 8);
516 coll->addAction("BindJumpKey9",
517 new Action(tr("Set Quick Access #9"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_9)))
518 ->setProperty("Index", 9);
520 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_0)))
521 ->setProperty("Index", 0);
522 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_1)))
523 ->setProperty("Index", 1);
524 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_2)))
525 ->setProperty("Index", 2);
526 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_3)))
527 ->setProperty("Index", 3);
528 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_4)))
529 ->setProperty("Index", 4);
530 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_5)))
531 ->setProperty("Index", 5);
532 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_6)))
533 ->setProperty("Index", 6);
534 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_7)))
535 ->setProperty("Index", 7);
536 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_8)))
537 ->setProperty("Index", 8);
538 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_9)))
539 ->setProperty("Index", 9);
542 coll->addAction("NextBufferView",
543 new Action(icon::get("go-next-view"),
544 tr("Activate Next Chat List"),
547 &MainWin::nextBufferView,
548 QKeySequence(QKeySequence::Forward)));
549 coll->addAction("PreviousBufferView",
550 new Action(icon::get("go-previous-view"),
551 tr("Activate Previous Chat List"),
554 &MainWin::previousBufferView,
555 QKeySequence::Back));
556 coll->addAction("NextBuffer",
557 new Action(icon::get("go-down"),
558 tr("Go to Next Chat"),
561 &MainWin::nextBuffer,
562 QKeySequence(Qt::ALT + Qt::Key_Down)));
563 coll->addAction("PreviousBuffer",
564 new Action(icon::get("go-up"),
565 tr("Go to Previous Chat"),
568 &MainWin::previousBuffer,
569 QKeySequence(Qt::ALT + Qt::Key_Up)));
572 void MainWin::setupMenus()
574 ActionCollection* coll = QtUi::actionCollection("General");
576 _fileMenu = menuBar()->addMenu(tr("&File"));
578 static const QStringList coreActions = QStringList() << "ConnectCore"
584 foreach (QString actionName, coreActions) {
585 coreAction = coll->action(actionName);
586 _fileMenu->addAction(coreAction);
587 flagRemoteCoreOnly(coreAction);
589 flagRemoteCoreOnly(_fileMenu->addSeparator());
591 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
592 _networksMenu->addAction(coll->action("ConfigureNetworks"));
593 _networksMenu->addSeparator();
594 _fileMenu->addSeparator();
595 _fileMenu->addAction(coll->action("Quit"));
597 _viewMenu = menuBar()->addMenu(tr("&View"));
598 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
599 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
600 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
601 _viewMenu->addSeparator();
603 _viewMenu->addAction(coll->action("ToggleMenuBar"));
604 _viewMenu->addAction(coll->action("ToggleStatusBar"));
605 _viewMenu->addAction(coll->action("ToggleSearchBar"));
607 coreAction = coll->action("ShowAwayLog");
608 flagRemoteCoreOnly(coreAction);
609 _viewMenu->addAction(coreAction);
611 _viewMenu->addSeparator();
612 _viewMenu->addAction(coll->action("LockLayout"));
614 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
616 # if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 23, 0)
617 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
618 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
620 _settingsMenu->addAction(KStandardAction::configureNotifications(this, &MainWin::showNotificationsDlg, this));
621 _settingsMenu->addAction(KStandardAction::keyBindings(this, &MainWin::showShortcutsDlg, this));
624 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
626 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
628 _helpMenu = menuBar()->addMenu(tr("&Help"));
630 _helpMenu->addAction(coll->action("AboutQuassel"));
632 _helpMenu->addAction(coll->action("AboutQt"));
634 # if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 23, 0)
635 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
637 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, &KHelpMenu::aboutKDE, this));
640 _helpMenu->addSeparator();
641 _helpDebugMenu = _helpMenu->addMenu(icon::get("tools-report-bug"), tr("Debug"));
642 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
643 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
644 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
645 _helpDebugMenu->addAction(coll->action("DebugHotList"));
646 _helpDebugMenu->addAction(coll->action("DebugLog"));
647 _helpDebugMenu->addAction(coll->action("ShowResourceTree"));
648 _helpDebugMenu->addSeparator();
649 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
652 QAction* showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
654 QtUiSettings uiSettings;
655 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
656 showMenuBar->setChecked(enabled);
657 enabled ? menuBar()->show() : menuBar()->hide();
659 connect(showMenuBar, &QAction::toggled, menuBar(), &QMenuBar::setVisible);
660 connect(showMenuBar, &QAction::toggled, this, &MainWin::saveMenuBarStatus);
663 void MainWin::setupBufferWidget()
665 _bufferWidget = new BufferWidget(this);
666 _bufferWidget->setModel(Client::bufferModel());
667 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
668 setCentralWidget(_bufferWidget);
671 void MainWin::addBufferView(int bufferViewConfigId)
673 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
676 void MainWin::addBufferView(ClientBufferViewConfig* config)
681 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
682 auto* dock = new BufferViewDock(config, this);
684 // create the view and initialize it's filter
685 auto* view = new BufferView(dock);
686 view->setFilteredModel(Client::bufferModel(), config);
687 view->installEventFilter(_inputWidget); // for key presses
689 Client::bufferModel()->synchronizeView(view);
691 dock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
693 dock->setWidget(view);
694 dock->setVisible(_layoutLoaded); // don't show before state has been restored
696 addDockWidget(Qt::LeftDockWidgetArea, dock);
697 _bufferViewsMenu->addAction(dock->toggleViewAction());
699 connect(dock->toggleViewAction(), &QAction::toggled, this, &MainWin::bufferViewToggled);
700 connect(dock, &QDockWidget::visibilityChanged, this, &MainWin::bufferViewVisibilityChanged);
701 _bufferViews.append(dock);
703 if (!activeBufferView())
707 void MainWin::removeBufferView(int bufferViewConfigId)
710 BufferViewDock* dock;
711 foreach (QAction* action, _bufferViewsMenu->actions()) {
712 actionData = action->data();
713 if (!actionData.isValid())
716 dock = qobject_cast<BufferViewDock*>(action->parent());
717 if (dock && actionData.toInt() == bufferViewConfigId) {
718 removeAction(action);
719 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
720 _bufferViews.removeAll(dock);
722 if (dock->isActive()) {
723 dock->setActive(false);
724 _activeBufferViewIndex = -1;
733 void MainWin::bufferViewToggled(bool enabled)
735 if (!enabled && !isMinimized()) {
736 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
737 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
740 auto* action = qobject_cast<QAction*>(sender());
742 auto* dock = qobject_cast<BufferViewDock*>(action->parent());
745 // Make sure we don't toggle backlog fetch for a view we've already removed
746 if (!_bufferViews.contains(dock))
750 Client::bufferViewOverlay()->addView(dock->bufferViewId());
752 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
755 void MainWin::bufferViewVisibilityChanged(bool visible)
758 auto* dock = qobject_cast<BufferViewDock*>(sender());
760 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
764 BufferView* MainWin::allBuffersView() const
766 // "All Buffers" is always the first dock created
767 if (_bufferViews.count() > 0)
768 return _bufferViews[0]->bufferView();
772 BufferView* MainWin::activeBufferView() const
774 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
776 BufferViewDock* dock = _bufferViews.at(_activeBufferViewIndex);
777 return dock->isActive() ? dock->bufferView() : nullptr;
780 void MainWin::changeActiveBufferView(int bufferViewId)
782 if (bufferViewId < 0)
785 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
786 _bufferViews[_activeBufferViewIndex]->setActive(false);
787 _activeBufferViewIndex = -1;
790 for (int i = 0; i < _bufferViews.count(); i++) {
791 BufferViewDock* dock = _bufferViews.at(i);
792 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
793 _activeBufferViewIndex = i;
794 dock->setActive(true);
799 nextBufferView(); // fallback
802 void MainWin::showPasswordChangeDlg()
804 if (Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
805 PasswordChangeDlg{}.exec();
808 QMessageBox box(QMessageBox::Warning,
809 tr("Feature Not Supported"),
810 tr("<b>Your Quassel Core does not support this feature</b>"),
812 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
817 void MainWin::showMigrationWarning(bool show)
819 if (show && !_migrationWarning) {
820 _migrationWarning = new QMessageBox(QMessageBox::Information,
822 "<b>" + tr("Your database is being upgraded") + "</b>",
823 QMessageBox::NoButton,
825 _migrationWarning->setInformativeText(
826 "<p>" + tr("In order to support new features, we need to make changes to your backlog database. This may take a long while.")
827 + "</p><p>" + tr("Do not exit Quassel until the upgrade is complete!") + "</p>");
828 _migrationWarning->setStandardButtons(QMessageBox::NoButton);
829 _migrationWarning->show();
831 else if (!show && _migrationWarning) {
832 _migrationWarning->close();
833 _migrationWarning->deleteLater();
834 _migrationWarning = nullptr;
838 void MainWin::onExitRequested(const QString& reason)
840 if (!reason.isEmpty()) {
841 QMessageBox box(QMessageBox::Critical,
843 "<b>" + tr("Quassel encountered a fatal error and is terminated.") + "</b>",
845 box.setInformativeText("<p>" + tr("Reason:<em>") + " " + reason + "</em>");
850 void MainWin::changeActiveBufferView(bool backwards)
852 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
853 _bufferViews[_activeBufferViewIndex]->setActive(false);
856 if (!_bufferViews.count())
859 int c = _bufferViews.count();
860 while (c--) { // yes, this will reactivate the current active one if all others fail
862 if (--_activeBufferViewIndex < 0)
863 _activeBufferViewIndex = _bufferViews.count() - 1;
866 if (++_activeBufferViewIndex >= _bufferViews.count())
867 _activeBufferViewIndex = 0;
870 BufferViewDock* dock = _bufferViews.at(_activeBufferViewIndex);
871 if (dock->isHidden())
874 dock->setActive(true);
878 _activeBufferViewIndex = -1;
881 void MainWin::nextBufferView()
883 changeActiveBufferView(false);
886 void MainWin::previousBufferView()
888 changeActiveBufferView(true);
891 void MainWin::nextBuffer()
893 BufferView* view = activeBufferView();
898 void MainWin::previousBuffer()
900 BufferView* view = activeBufferView();
902 view->previousBuffer();
905 void MainWin::hideCurrentBuffer()
907 BufferView* view = activeBufferView();
909 view->hideCurrentBuffer();
912 void MainWin::showNotificationsDlg()
914 SettingsPageDlg{new NotificationsSettingsPage{}}.exec();
917 void MainWin::onConfigureNetworksTriggered()
919 SettingsPageDlg{new NetworksSettingsPage{}}.exec();
922 void MainWin::onConfigureViewsTriggered()
924 SettingsPageDlg{new BufferViewSettingsPage{}}.exec();
927 void MainWin::onLockLayoutToggled(bool lock)
929 QList<VerticalDock*> docks = findChildren<VerticalDock*>();
930 foreach (VerticalDock* dock, docks) {
931 dock->showTitle(!lock);
934 QList<NickListDock*> nickdocks = findChildren<NickListDock*>();
935 foreach (NickListDock* nickdock, nickdocks) {
936 nickdock->setLocked(lock);
939 QList<BufferViewDock*> bufferdocks = findChildren<BufferViewDock*>();
940 foreach (BufferViewDock* bufferdock, bufferdocks) {
941 bufferdock->setLocked(lock);
944 if (Client::bufferViewManager()) {
945 foreach (ClientBufferViewConfig* config, Client::bufferViewManager()->clientBufferViewConfigs()) {
946 config->setLocked(lock);
950 _mainToolBar->setMovable(!lock);
951 _nickToolBar->setMovable(!lock);
953 QtUiSettings().setValue("LockLayout", lock);
956 void MainWin::setupNickWidget()
959 NickListDock* nickDock = new NickListDock(tr("Nicks"), this);
960 nickDock->setObjectName("NickDock");
961 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
962 nickDock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
964 _nickListWidget = new NickListWidget(nickDock);
965 nickDock->setWidget(_nickListWidget);
967 addDockWidget(Qt::RightDockWidgetArea, nickDock);
968 _viewMenu->addAction(nickDock->toggleViewAction());
969 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
971 // See NickListDock::NickListDock();
972 // connect(nickDock->toggleViewAction(), &NickListDock::triggered, nickListWidget, &QWidget::showWidget);
974 // attach the NickListWidget to the BufferModel and the default selection
975 _nickListWidget->setModel(Client::bufferModel());
976 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
978 _nickListWidget->setVisible(false);
981 void MainWin::setupChatMonitor()
983 VerticalDock* dock = new VerticalDock(tr("Chat Monitor"), this);
984 dock->setObjectName("ChatMonitorDock");
986 auto* filter = new ChatMonitorFilter(Client::messageModel(), this);
987 _chatMonitorView = new ChatMonitorView(filter, this);
988 _chatMonitorView->show();
989 dock->setWidget(_chatMonitorView);
992 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
993 _viewMenu->addAction(dock->toggleViewAction());
994 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
997 void MainWin::setupInputWidget()
999 VerticalDock* dock = new VerticalDock(tr("Inputline"), this);
1000 dock->setObjectName("InputDock");
1002 _inputWidget = new InputWidget(dock);
1003 dock->setWidget(_inputWidget);
1005 addDockWidget(Qt::BottomDockWidgetArea, dock);
1007 _viewMenu->addAction(dock->toggleViewAction());
1008 dock->toggleViewAction()->setText(tr("Show Input Line"));
1010 _inputWidget->setModel(Client::bufferModel());
1011 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1013 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
1016 void MainWin::setupTopicWidget()
1018 VerticalDock* dock = new VerticalDock(tr("Topic"), this);
1019 dock->setObjectName("TopicDock");
1020 _topicWidget = new TopicWidget(dock);
1022 dock->setWidget(_topicWidget);
1024 _topicWidget->setModel(Client::bufferModel());
1025 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1027 connect(_topicWidget, &TopicWidget::switchedPlain, _bufferWidget, selectOverload<>(&QWidget::setFocus));
1029 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1031 _viewMenu->addAction(dock->toggleViewAction());
1032 dock->toggleViewAction()->setText(tr("Show Topic Line"));
1035 void MainWin::setupTransferWidget()
1037 auto dock = new QDockWidget(tr("Transfers"), this);
1038 dock->setObjectName("TransferDock");
1039 dock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1041 auto view = new QTableView(dock); // to be replaced by the real thing
1042 view->setModel(Client::transferModel());
1043 dock->setWidget(view);
1044 dock->hide(); // hidden by default
1045 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1047 auto action = dock->toggleViewAction();
1048 action->setText(tr("Show File Transfers"));
1049 action->setIcon(icon::get("download"));
1050 action->setShortcut(QKeySequence(Qt::Key_F6));
1051 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
1052 _viewMenu->addAction(action);
1055 void MainWin::setupViewMenuTail()
1057 _viewMenu->addSeparator();
1058 _viewMenu->addAction(_fullScreenAction);
1061 void MainWin::setupTitleSetter()
1063 _titleSetter.setModel(Client::bufferModel());
1064 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1067 void MainWin::setupStatusBar()
1069 // MessageProcessor progress
1070 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1073 _coreConnectionStatusWidget->update();
1074 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1076 QAction* showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1078 QtUiSettings uiSettings;
1080 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1081 showStatusbar->setChecked(enabled);
1082 enabled ? statusBar()->show() : statusBar()->hide();
1084 connect(showStatusbar, &QAction::toggled, statusBar(), &QWidget::setVisible);
1085 connect(showStatusbar, &QAction::toggled, this, &MainWin::saveStatusBarStatus);
1087 connect(Client::coreConnection(), &CoreConnection::connectionMsg, statusBar(), [statusBar = statusBar()](auto&& message) {
1088 statusBar->showMessage(message);
1092 void MainWin::setupHotList()
1094 auto* flatProxy = new FlatProxyModel(this);
1095 flatProxy->setSourceModel(Client::bufferModel());
1096 _bufferHotList = new BufferHotListFilter(flatProxy);
1099 void MainWin::saveMenuBarStatus(bool enabled)
1101 QtUiSettings uiSettings;
1102 uiSettings.setValue("ShowMenuBar", enabled);
1105 void MainWin::saveStatusBarStatus(bool enabled)
1107 QtUiSettings uiSettings;
1108 uiSettings.setValue("ShowStatusBar", enabled);
1111 void MainWin::setupSystray()
1114 _systemTray = new StatusNotifierItem(this);
1115 #elif !defined QT_NO_SYSTEMTRAYICON
1116 _systemTray = new LegacySystemTray(this);
1118 _systemTray = new SystemTray(this); // dummy
1122 void MainWin::setupToolBars()
1124 connect(_bufferWidget,
1125 selectOverload<const QModelIndex&>(&AbstractBufferContainer::currentChanged),
1126 QtUi::toolBarActionProvider(),
1127 &ToolBarActionProvider::onCurrentBufferChanged);
1128 connect(_nickListWidget,
1129 &NickListWidget::nickSelectionChanged,
1130 QtUi::toolBarActionProvider(),
1131 &ToolBarActionProvider::onNickSelectionChanged);
1134 setUnifiedTitleAndToolBarOnMac(true);
1138 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1140 _mainToolBar = new QToolBar(this);
1141 _mainToolBar->setObjectName("MainToolBar");
1143 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1144 addToolBar(_mainToolBar);
1146 if (Quassel::runMode() != Quassel::Monolithic) {
1147 ActionCollection* coll = QtUi::actionCollection("General");
1148 _mainToolBar->addAction(coll->action("ConnectCore"));
1149 _mainToolBar->addAction(coll->action("DisconnectCore"));
1152 _mainToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1154 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1155 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1158 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1160 _nickToolBar = new QToolBar(this);
1161 _nickToolBar->setObjectName("NickToolBar");
1163 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1164 _nickToolBar->setVisible(false); // default: not visible
1165 addToolBar(_nickToolBar);
1166 _nickToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1168 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1169 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1172 QtUiSettings uiSettings;
1174 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1175 _mainToolBar->setVisible(visible);
1176 connect(_mainToolBar, &QToolBar::visibilityChanged, this, &MainWin::saveMainToolBarStatus);
1180 void MainWin::saveMainToolBarStatus(bool enabled)
1183 QtUiSettings uiSettings;
1184 uiSettings.setValue("ShowMainToolBar", enabled);
1190 void MainWin::doAutoConnect()
1192 int accountId = Quassel::optionValue("account").toInt();
1193 if (!Client::coreConnection()->connectToCore(accountId)) {
1194 // No autoconnect selected (or no accounts)
1195 showCoreConnectionDlg();
1199 void MainWin::connectedToCore()
1201 Q_CHECK_PTR(Client::bufferViewManager());
1202 connect(Client::bufferViewManager(), &BufferViewManager::bufferViewConfigAdded, this, selectOverload<int>(&MainWin::addBufferView));
1203 connect(Client::bufferViewManager(), &BufferViewManager::bufferViewConfigDeleted, this, &MainWin::removeBufferView);
1204 connect(Client::bufferViewManager(), &SyncableObject::initDone, this, &MainWin::loadLayout);
1206 if (Client::transferManager()) {
1207 connect(Client::transferManager(), &TransferManager::transferAdded, this, &MainWin::showNewTransferDlg);
1210 setConnectedState();
1213 void MainWin::setConnectedState()
1215 ActionCollection* coll = QtUi::actionCollection("General");
1217 coll->action("ConnectCore")->setEnabled(false);
1218 coll->action("DisconnectCore")->setEnabled(true);
1219 coll->action("ChangePassword")->setEnabled(true);
1220 coll->action("CoreInfo")->setEnabled(true);
1222 foreach (QAction* action, _fileMenu->actions()) {
1223 if (isRemoteCoreOnly(action))
1224 action->setVisible(!Client::internalCore());
1227 disconnect(Client::backlogManager(),
1228 &ClientBacklogManager::updateProgress,
1229 _msgProcessorStatusWidget,
1230 &MsgProcessorStatusWidget::setProgress);
1231 disconnect(Client::backlogManager(), &ClientBacklogManager::messagesRequested, this, &MainWin::showStatusBarMessage);
1232 disconnect(Client::backlogManager(), &ClientBacklogManager::messagesProcessed, this, &MainWin::showStatusBarMessage);
1233 if (!Client::internalCore()) {
1234 connect(Client::backlogManager(),
1235 &ClientBacklogManager::updateProgress,
1236 _msgProcessorStatusWidget,
1237 &MsgProcessorStatusWidget::setProgress);
1238 connect(Client::backlogManager(), &ClientBacklogManager::messagesRequested, this, &MainWin::showStatusBarMessage);
1239 connect(Client::backlogManager(), &ClientBacklogManager::messagesProcessed, this, &MainWin::showStatusBarMessage);
1242 // _viewMenu->setEnabled(true);
1243 if (!Client::internalCore())
1244 statusBar()->showMessage(tr("Connected to core."));
1246 statusBar()->clearMessage();
1248 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1250 systemTray()->setState(SystemTray::Active);
1252 if (Client::networkIds().isEmpty()) {
1253 IrcConnectionWizard* wizard = new IrcConnectionWizard(this, Qt::Sheet);
1257 // Monolithic always preselects last used buffer - Client only if the connection died
1258 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1260 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1261 if (lastUsedBufferId.isValid())
1262 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1267 void MainWin::loadLayout()
1270 int accountId = Client::currentCoreAccount().accountId().toInt();
1271 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1272 _nickListWidget->setVisible(true);
1273 if (state.isEmpty()) {
1274 foreach (BufferViewDock* view, _bufferViews)
1276 _layoutLoaded = true;
1279 restoreState(state, accountId);
1280 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1281 if (bufferViewId >= 0)
1282 changeActiveBufferView(bufferViewId);
1284 _layoutLoaded = true;
1287 void MainWin::saveLayout()
1290 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1291 if (accountId > 0) {
1292 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1293 BufferView* view = activeBufferView();
1294 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1298 void MainWin::disconnectedFromCore()
1300 // save core specific layout and remove bufferviews;
1302 _layoutLoaded = false;
1304 QVariant actionData;
1305 BufferViewDock* dock;
1306 foreach (QAction* action, _bufferViewsMenu->actions()) {
1307 actionData = action->data();
1308 if (!actionData.isValid())
1311 dock = qobject_cast<BufferViewDock*>(action->parent());
1312 if (dock && actionData.toInt() != -1) {
1313 removeAction(action);
1314 _bufferViews.removeAll(dock);
1315 dock->deleteLater();
1319 // store last active buffer
1321 BufferId lastBufId = _bufferWidget->currentBuffer();
1322 if (lastBufId.isValid()) {
1323 s.setValue("LastUsedBufferId", lastBufId.toInt());
1324 // clear the current selection
1325 Client::bufferModel()->standardSelectionModel()->clearSelection();
1327 restoreState(s.value("MainWinState").toByteArray());
1328 setDisconnectedState();
1331 void MainWin::setDisconnectedState()
1333 ActionCollection* coll = QtUi::actionCollection("General");
1334 // ui.menuCore->setEnabled(false);
1335 coll->action("ConnectCore")->setEnabled(true);
1336 coll->action("DisconnectCore")->setEnabled(false);
1337 coll->action("CoreInfo")->setEnabled(false);
1338 coll->action("ChangePassword")->setEnabled(false);
1339 //_viewMenu->setEnabled(false);
1340 statusBar()->showMessage(tr("Not connected to core."));
1341 if (_msgProcessorStatusWidget)
1342 _msgProcessorStatusWidget->setProgress(0, 0);
1344 systemTray()->setState(SystemTray::Passive);
1345 _nickListWidget->setVisible(false);
1348 void MainWin::userAuthenticationRequired(CoreAccount* account, bool* valid, const QString& errorMessage)
1350 Q_UNUSED(errorMessage)
1351 CoreConnectAuthDlg dlg(account);
1352 *valid = (dlg.exec() == QDialog::Accepted);
1355 void MainWin::handleNoSslInClient(bool* accepted)
1357 QMessageBox box(QMessageBox::Warning,
1358 tr("Unencrypted Connection"),
1359 tr("<b>Your client does not support SSL encryption</b>"),
1360 QMessageBox::Ignore | QMessageBox::Cancel);
1361 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1362 box.setDefaultButton(QMessageBox::Ignore);
1363 *accepted = (box.exec() == QMessageBox::Ignore);
1366 void MainWin::handleNoSslInCore(bool* accepted)
1368 QMessageBox box(QMessageBox::Warning,
1369 tr("Unencrypted Connection"),
1370 tr("<b>Your core does not support SSL encryption</b>"),
1371 QMessageBox::Ignore | QMessageBox::Cancel);
1372 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1373 box.setDefaultButton(QMessageBox::Ignore);
1374 *accepted = (box.exec() == QMessageBox::Ignore);
1377 void MainWin::handleSslErrors(const QSslSocket* socket, bool* accepted, bool* permanently)
1379 QString errorString = "<ul>";
1380 foreach (const QSslError error, socket->sslErrors())
1381 errorString += QString("<li>%1</li>").arg(error.errorString());
1382 errorString += "</ul>";
1384 QMessageBox box(QMessageBox::Warning,
1385 tr("Untrusted Security Certificate"),
1386 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1387 QMessageBox::Cancel);
1388 box.setInformativeText(errorString);
1389 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1390 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1392 QMessageBox::ButtonRole role;
1395 role = box.buttonRole(box.clickedButton());
1396 if (role == QMessageBox::HelpRole) {
1397 SslInfoDlg dlg(socket);
1400 } while (role == QMessageBox::HelpRole);
1402 *accepted = role == QMessageBox::AcceptRole;
1404 QMessageBox box2(QMessageBox::Warning,
1405 tr("Untrusted Security Certificate"),
1406 tr("Would you like to accept this certificate forever without being prompted?"),
1407 QMessageBox::NoButton);
1408 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1409 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1411 *permanently = (box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole);
1415 void MainWin::handleCoreConnectionError(const QString& error)
1417 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1420 void MainWin::showCoreConnectionDlg()
1423 if (dlg.exec() == QDialog::Accepted) {
1424 AccountId accId = dlg.selectedAccount();
1425 if (accId.isValid())
1426 Client::coreConnection()->connectToCore(accId);
1430 void MainWin::showCoreConfigWizard(const QVariantList& backends, const QVariantList& authenticators)
1432 auto* wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1437 void MainWin::showChannelList(NetworkId netId, const QString& channelFilters, bool listImmediately)
1439 if (!netId.isValid()) {
1440 auto* action = qobject_cast<QAction*>(sender());
1442 netId = action->data().value<NetworkId>();
1443 if (!netId.isValid()) {
1444 // We still haven't found a valid network, probably no network selected, e.g. "/list"
1445 // on the client homescreen when no networks are connected.
1446 QMessageBox box(QMessageBox::Information,
1447 tr("No network selected"),
1448 QString("<b>%1</b>").arg(tr("No network selected")),
1450 box.setInformativeText(tr("Select a network before trying to view the channel list."));
1456 auto* channelListDlg = new ChannelListDlg(this);
1457 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1458 channelListDlg->setNetwork(netId);
1459 if (!channelFilters.isEmpty()) {
1460 channelListDlg->setChannelFilters(channelFilters);
1462 if (listImmediately) {
1463 channelListDlg->requestSearch();
1465 channelListDlg->show();
1468 void MainWin::showNetworkConfig(NetworkId netId)
1470 SettingsPageDlg dlg{new NetworksSettingsPage{}};
1471 if (netId.isValid())
1472 qobject_cast<NetworksSettingsPage*>(dlg.currentPage())->bufferList_Open(netId);
1476 void MainWin::showIgnoreList(QString newRule)
1478 SettingsPageDlg dlg{new IgnoreListSettingsPage{}};
1479 // prepare config dialog for new rule
1480 if (!newRule.isEmpty())
1481 qobject_cast<IgnoreListSettingsPage*>(dlg.currentPage())->editIgnoreRule(newRule);
1485 void MainWin::showCoreInfoDlg()
1487 CoreInfoDlg{}.exec();
1490 void MainWin::showAwayLog()
1494 auto* filter = new AwayLogFilter(Client::messageModel());
1495 _awayLog = new AwayLogView(filter, nullptr);
1496 filter->setParent(_awayLog);
1497 connect(_awayLog, &QObject::destroyed, this, &MainWin::awayLogDestroyed);
1498 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1502 void MainWin::awayLogDestroyed()
1507 void MainWin::showSettingsDlg()
1509 auto dlg = new SettingsDlg();
1511 // Category: Interface
1512 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1513 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1514 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1515 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1516 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1517 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1518 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1519 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1521 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1523 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1524 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1525 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1526 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1529 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1530 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1531 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1532 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1533 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1534 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1536 // Category: Remote Cores
1537 if (Quassel::runMode() != Quassel::Monolithic) {
1538 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1539 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1545 void MainWin::showAboutDlg()
1550 void MainWin::showShortcutsDlg()
1553 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed);
1554 foreach (KActionCollection* coll, QtUi::actionCollections()) {
1555 dlg.addCollection(coll, coll->property("Category").toString());
1557 dlg.configure(true);
1559 SettingsPageDlg{new ShortcutsSettingsPage{QtUi::actionCollections()}}.exec();
1563 void MainWin::showNewTransferDlg(const QUuid& transferId)
1565 auto transfer = Client::transferManager()->transfer(transferId);
1567 if (transfer->status() == Transfer::Status::New) {
1568 auto* dlg = new ReceiveFileDlg(transfer, this);
1573 qWarning() << "Unknown transfer ID" << transferId;
1577 void MainWin::onFullScreenToggled()
1579 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1580 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1583 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1585 if (_fullScreenAction->isChecked())
1586 setWindowState(windowState() | Qt::WindowFullScreen);
1588 setWindowState(windowState() & ~Qt::WindowFullScreen);
1592 /********************************************************************************************************/
1594 bool MainWin::event(QEvent* event)
1596 switch (event->type()) {
1597 case QEvent::WindowActivate: {
1598 BufferId bufferId = Client::bufferModel()->currentBuffer();
1599 if (bufferId.isValid())
1600 Client::instance()->markBufferAsRead(bufferId);
1603 case QEvent::WindowDeactivate:
1604 if (bufferWidget()->autoMarkerLineOnLostFocus())
1605 bufferWidget()->setMarkerLine();
1610 return QMainWindow::event(event);
1613 void MainWin::moveEvent(QMoveEvent* event)
1615 if (!(windowState() & Qt::WindowMaximized))
1616 _normalPos = event->pos();
1618 QMainWindow::moveEvent(event);
1621 void MainWin::resizeEvent(QResizeEvent* event)
1623 if (!(windowState() & Qt::WindowMaximized))
1624 _normalSize = event->size();
1626 QMainWindow::resizeEvent(event);
1629 void MainWin::closeEvent(QCloseEvent* event)
1632 auto* app = qobject_cast<QtUiApplication*> qApp;
1634 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1635 // This messes up MainWinState/MainWinHidden save/restore.
1636 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1637 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1638 QtUi::hideMainWidget();
1641 else if (!_aboutToQuit) {
1642 _aboutToQuit = true;
1644 Quassel::instance()->quit();
1651 void MainWin::messagesInserted(const QModelIndex& parent, int start, int end)
1655 bool hasFocus = QApplication::activeWindow() != nullptr;
1657 for (int i = start; i <= end; i++) {
1658 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1659 if (!idx.isValid()) {
1660 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1663 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1664 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1667 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1668 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1670 // check if bufferId belongs to the shown chatlists
1671 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) || Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1674 // check if it's the buffer currently displayed
1675 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1678 // only show notifications for higlights or queries
1679 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1682 // and of course: don't notify for ignored messages
1683 if (Client::ignoreListManager()
1684 && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1685 Client::networkModel()->networkName(bufId)))
1688 // seems like we have a legit notification candidate!
1689 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1690 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1691 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1692 AbstractNotificationBackend::NotificationType type;
1694 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1695 type = AbstractNotificationBackend::PrivMsg;
1696 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1697 type = AbstractNotificationBackend::PrivMsgFocused;
1698 else if (flags & Message::Highlight && !hasFocus)
1699 type = AbstractNotificationBackend::Highlight;
1701 type = AbstractNotificationBackend::HighlightFocused;
1703 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1707 void MainWin::currentBufferChanged(BufferId buffer)
1709 if (buffer.isValid())
1710 Client::instance()->markBufferAsRead(buffer);
1713 void MainWin::clientNetworkCreated(NetworkId id)
1715 const Network* net = Client::network(id);
1716 auto* act = new QAction(net->networkName(), this);
1717 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1718 act->setData(QVariant::fromValue(id));
1719 connect(net, &SyncableObject::updatedRemotely, this, &MainWin::clientNetworkUpdated);
1720 connect(act, &QAction::triggered, this, &MainWin::connectOrDisconnectFromNet);
1722 QAction* beforeAction = nullptr;
1723 foreach (QAction* action, _networksMenu->actions()) {
1724 if (!action->data().isValid()) // ignore stock actions
1726 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1727 beforeAction = action;
1731 _networksMenu->insertAction(beforeAction, act);
1734 void MainWin::clientNetworkUpdated()
1736 const auto* net = qobject_cast<const Network*>(sender());
1740 auto* action = findChild<QAction*>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1744 action->setText(net->networkName());
1746 switch (net->connectionState()) {
1747 case Network::Initialized:
1748 action->setIcon(icon::get("network-connect"));
1749 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1750 if (!bufferWidget()->currentBuffer().isValid()) {
1751 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1752 if (idx.isValid()) {
1753 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1754 Client::bufferModel()->switchToBuffer(statusBufferId);
1758 case Network::Disconnected:
1759 action->setIcon(icon::get("network-disconnect"));
1762 action->setIcon(icon::get("network-wired"));
1766 void MainWin::clientNetworkRemoved(NetworkId id)
1768 auto* action = findChild<QAction*>(QString("NetworkAction-%1").arg(id.toInt()));
1772 action->deleteLater();
1775 void MainWin::connectOrDisconnectFromNet()
1777 auto* act = qobject_cast<QAction*>(sender());
1780 const Network* net = Client::network(act->data().value<NetworkId>());
1783 if (net->connectionState() == Network::Disconnected)
1784 net->requestConnect();
1786 net->requestDisconnect();
1789 void MainWin::onFormatApplyColorTriggered()
1794 _inputWidget->applyFormatActiveColor();
1797 void MainWin::onFormatApplyColorFillTriggered()
1802 _inputWidget->applyFormatActiveColorFill();
1805 void MainWin::onFormatClearTriggered()
1810 _inputWidget->clearFormat();
1813 void MainWin::onFormatBoldTriggered()
1818 _inputWidget->toggleFormatBold();
1821 void MainWin::onFormatItalicTriggered()
1826 _inputWidget->toggleFormatItalic();
1829 void MainWin::onFormatUnderlineTriggered()
1834 _inputWidget->toggleFormatUnderline();
1837 void MainWin::onJumpHotBufferTriggered()
1839 if (!_bufferHotList->rowCount())
1842 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1845 void MainWin::onBufferSearchTriggered()
1847 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1848 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1852 _bufferViews[_activeBufferViewIndex]->activateFilter();
1855 void MainWin::onJumpKey()
1857 auto* action = qobject_cast<QAction*>(sender());
1858 if (!action || !Client::bufferModel())
1860 int idx = action->property("Index").toInt();
1862 if (_jumpKeyMap.isEmpty())
1863 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1865 if (!_jumpKeyMap.contains(idx))
1868 BufferId buffer = _jumpKeyMap.value(idx);
1869 if (buffer.isValid())
1870 Client::bufferModel()->switchToBuffer(buffer);
1873 void MainWin::bindJumpKey()
1875 auto* action = qobject_cast<QAction*>(sender());
1876 if (!action || !Client::bufferModel())
1878 int idx = action->property("Index").toInt();
1880 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1881 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1884 void MainWin::onDebugNetworkModelTriggered()
1886 auto* view = new QTreeView;
1887 view->setAttribute(Qt::WA_DeleteOnClose);
1888 view->setWindowTitle("Debug NetworkModel View");
1889 view->setModel(Client::networkModel());
1890 view->setColumnWidth(0, 250);
1891 view->setColumnWidth(1, 250);
1892 view->setColumnWidth(2, 80);
1893 view->resize(610, 300);
1897 void MainWin::onDebugHotListTriggered()
1899 _bufferHotList->invalidate();
1900 _bufferHotList->sort(0, Qt::DescendingOrder);
1902 auto* view = new QTreeView;
1903 view->setAttribute(Qt::WA_DeleteOnClose);
1904 view->setModel(_bufferHotList);
1908 void MainWin::onDebugBufferViewOverlayTriggered()
1910 auto* overlay = new DebugBufferViewOverlay(nullptr);
1911 overlay->setAttribute(Qt::WA_DeleteOnClose);
1915 void MainWin::onDebugMessageModelTriggered()
1917 auto* view = new QTableView(nullptr);
1918 auto* filter = new DebugMessageModelFilter(view);
1919 filter->setSourceModel(Client::messageModel());
1920 view->setModel(filter);
1921 view->setAttribute(Qt::WA_DeleteOnClose, true);
1922 view->verticalHeader()->hide();
1923 view->horizontalHeader()->setStretchLastSection(true);
1927 void MainWin::onDebugLogTriggered()
1929 auto dlg = new DebugLogDlg(this); // will be deleted on close
1933 void MainWin::onShowResourceTreeTriggered()
1935 auto dlg = new ResourceTreeDlg(this); // will be deleted on close
1939 void MainWin::showStatusBarMessage(const QString& message)
1941 statusBar()->showMessage(message, 10000);