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)},
470 {"FormatStrikethrough",
471 new Action(icon::get("format-text-strikethrough"),
472 tr("Toggle strikethrough"),
475 &MainWin::onFormatStrikethroughTriggered,
476 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S))}});
479 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
483 new Action(tr("Jump to hot chat"), coll, this, &MainWin::onJumpHotBufferTriggered, QKeySequence(Qt::META + Qt::Key_A))},
484 {"ActivateBufferFilter",
485 new Action(tr("Activate the buffer search"), coll, this, &MainWin::onBufferSearchTriggered, QKeySequence(Qt::CTRL + Qt::Key_S))}});
489 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
490 const int jumpModifier = Qt::ControlModifier;
492 const int bindModifier = Qt::ControlModifier;
493 const int jumpModifier = Qt::AltModifier;
496 coll->addAction("BindJumpKey0",
497 new Action(tr("Set Quick Access #0"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_0)))
498 ->setProperty("Index", 0);
499 coll->addAction("BindJumpKey1",
500 new Action(tr("Set Quick Access #1"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_1)))
501 ->setProperty("Index", 1);
502 coll->addAction("BindJumpKey2",
503 new Action(tr("Set Quick Access #2"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_2)))
504 ->setProperty("Index", 2);
505 coll->addAction("BindJumpKey3",
506 new Action(tr("Set Quick Access #3"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_3)))
507 ->setProperty("Index", 3);
508 coll->addAction("BindJumpKey4",
509 new Action(tr("Set Quick Access #4"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_4)))
510 ->setProperty("Index", 4);
511 coll->addAction("BindJumpKey5",
512 new Action(tr("Set Quick Access #5"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_5)))
513 ->setProperty("Index", 5);
514 coll->addAction("BindJumpKey6",
515 new Action(tr("Set Quick Access #6"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_6)))
516 ->setProperty("Index", 6);
517 coll->addAction("BindJumpKey7",
518 new Action(tr("Set Quick Access #7"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_7)))
519 ->setProperty("Index", 7);
520 coll->addAction("BindJumpKey8",
521 new Action(tr("Set Quick Access #8"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_8)))
522 ->setProperty("Index", 8);
523 coll->addAction("BindJumpKey9",
524 new Action(tr("Set Quick Access #9"), coll, this, &MainWin::bindJumpKey, QKeySequence(bindModifier + Qt::Key_9)))
525 ->setProperty("Index", 9);
527 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_0)))
528 ->setProperty("Index", 0);
529 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_1)))
530 ->setProperty("Index", 1);
531 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_2)))
532 ->setProperty("Index", 2);
533 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_3)))
534 ->setProperty("Index", 3);
535 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_4)))
536 ->setProperty("Index", 4);
537 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_5)))
538 ->setProperty("Index", 5);
539 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_6)))
540 ->setProperty("Index", 6);
541 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_7)))
542 ->setProperty("Index", 7);
543 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_8)))
544 ->setProperty("Index", 8);
545 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, &MainWin::onJumpKey, QKeySequence(jumpModifier + Qt::Key_9)))
546 ->setProperty("Index", 9);
549 coll->addAction("NextBufferView",
550 new Action(icon::get("go-next-view"),
551 tr("Activate Next Chat List"),
554 &MainWin::nextBufferView,
555 QKeySequence(QKeySequence::Forward)));
556 coll->addAction("PreviousBufferView",
557 new Action(icon::get("go-previous-view"),
558 tr("Activate Previous Chat List"),
561 &MainWin::previousBufferView,
562 QKeySequence::Back));
563 coll->addAction("NextBuffer",
564 new Action(icon::get("go-down"),
565 tr("Go to Next Chat"),
568 &MainWin::nextBuffer,
569 QKeySequence(Qt::ALT + Qt::Key_Down)));
570 coll->addAction("PreviousBuffer",
571 new Action(icon::get("go-up"),
572 tr("Go to Previous Chat"),
575 &MainWin::previousBuffer,
576 QKeySequence(Qt::ALT + Qt::Key_Up)));
579 void MainWin::setupMenus()
581 ActionCollection* coll = QtUi::actionCollection("General");
583 _fileMenu = menuBar()->addMenu(tr("&File"));
585 static const QStringList coreActions = QStringList() << "ConnectCore"
591 foreach (QString actionName, coreActions) {
592 coreAction = coll->action(actionName);
593 _fileMenu->addAction(coreAction);
594 flagRemoteCoreOnly(coreAction);
596 flagRemoteCoreOnly(_fileMenu->addSeparator());
598 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
599 _networksMenu->addAction(coll->action("ConfigureNetworks"));
600 _networksMenu->addSeparator();
601 _fileMenu->addSeparator();
602 _fileMenu->addAction(coll->action("Quit"));
604 _viewMenu = menuBar()->addMenu(tr("&View"));
605 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
606 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
607 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
608 _viewMenu->addSeparator();
610 _viewMenu->addAction(coll->action("ToggleMenuBar"));
611 _viewMenu->addAction(coll->action("ToggleStatusBar"));
612 _viewMenu->addAction(coll->action("ToggleSearchBar"));
614 coreAction = coll->action("ShowAwayLog");
615 flagRemoteCoreOnly(coreAction);
616 _viewMenu->addAction(coreAction);
618 _viewMenu->addSeparator();
619 _viewMenu->addAction(coll->action("LockLayout"));
621 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
623 # if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 23, 0)
624 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
625 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
627 _settingsMenu->addAction(KStandardAction::configureNotifications(this, &MainWin::showNotificationsDlg, this));
628 _settingsMenu->addAction(KStandardAction::keyBindings(this, &MainWin::showShortcutsDlg, this));
631 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
633 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
635 _helpMenu = menuBar()->addMenu(tr("&Help"));
637 _helpMenu->addAction(coll->action("AboutQuassel"));
639 _helpMenu->addAction(coll->action("AboutQt"));
641 # if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 23, 0)
642 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
644 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, &KHelpMenu::aboutKDE, this));
647 _helpMenu->addSeparator();
648 _helpDebugMenu = _helpMenu->addMenu(icon::get("tools-report-bug"), tr("Debug"));
649 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
650 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
651 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
652 _helpDebugMenu->addAction(coll->action("DebugHotList"));
653 _helpDebugMenu->addAction(coll->action("DebugLog"));
654 _helpDebugMenu->addAction(coll->action("ShowResourceTree"));
655 _helpDebugMenu->addSeparator();
656 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
659 QAction* showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
661 QtUiSettings uiSettings;
662 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
663 showMenuBar->setChecked(enabled);
664 enabled ? menuBar()->show() : menuBar()->hide();
666 connect(showMenuBar, &QAction::toggled, menuBar(), &QMenuBar::setVisible);
667 connect(showMenuBar, &QAction::toggled, this, &MainWin::saveMenuBarStatus);
670 void MainWin::setupBufferWidget()
672 _bufferWidget = new BufferWidget(this);
673 _bufferWidget->setModel(Client::bufferModel());
674 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
675 setCentralWidget(_bufferWidget);
678 void MainWin::addBufferView(int bufferViewConfigId)
680 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
683 void MainWin::addBufferView(ClientBufferViewConfig* config)
688 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
689 auto* dock = new BufferViewDock(config, this);
691 // create the view and initialize it's filter
692 auto* view = new BufferView(dock);
693 view->setFilteredModel(Client::bufferModel(), config);
694 view->installEventFilter(_inputWidget); // for key presses
696 Client::bufferModel()->synchronizeView(view);
698 dock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
700 dock->setWidget(view);
701 dock->setVisible(_layoutLoaded); // don't show before state has been restored
703 addDockWidget(Qt::LeftDockWidgetArea, dock);
704 _bufferViewsMenu->addAction(dock->toggleViewAction());
706 connect(dock->toggleViewAction(), &QAction::toggled, this, &MainWin::bufferViewToggled);
707 connect(dock, &QDockWidget::visibilityChanged, this, &MainWin::bufferViewVisibilityChanged);
708 _bufferViews.append(dock);
710 if (!activeBufferView())
714 void MainWin::removeBufferView(int bufferViewConfigId)
717 BufferViewDock* dock;
718 foreach (QAction* action, _bufferViewsMenu->actions()) {
719 actionData = action->data();
720 if (!actionData.isValid())
723 dock = qobject_cast<BufferViewDock*>(action->parent());
724 if (dock && actionData.toInt() == bufferViewConfigId) {
725 removeAction(action);
726 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
727 _bufferViews.removeAll(dock);
729 if (dock->isActive()) {
730 dock->setActive(false);
731 _activeBufferViewIndex = -1;
740 void MainWin::bufferViewToggled(bool enabled)
742 if (!enabled && !isMinimized()) {
743 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
744 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
747 auto* action = qobject_cast<QAction*>(sender());
749 auto* dock = qobject_cast<BufferViewDock*>(action->parent());
752 // Make sure we don't toggle backlog fetch for a view we've already removed
753 if (!_bufferViews.contains(dock))
757 Client::bufferViewOverlay()->addView(dock->bufferViewId());
759 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
762 void MainWin::bufferViewVisibilityChanged(bool visible)
765 auto* dock = qobject_cast<BufferViewDock*>(sender());
767 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
771 BufferView* MainWin::allBuffersView() const
773 // "All Buffers" is always the first dock created
774 if (_bufferViews.count() > 0)
775 return _bufferViews[0]->bufferView();
779 BufferView* MainWin::activeBufferView() const
781 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
783 BufferViewDock* dock = _bufferViews.at(_activeBufferViewIndex);
784 return dock->isActive() ? dock->bufferView() : nullptr;
787 void MainWin::changeActiveBufferView(int bufferViewId)
789 if (bufferViewId < 0)
792 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
793 _bufferViews[_activeBufferViewIndex]->setActive(false);
794 _activeBufferViewIndex = -1;
797 for (int i = 0; i < _bufferViews.count(); i++) {
798 BufferViewDock* dock = _bufferViews.at(i);
799 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
800 _activeBufferViewIndex = i;
801 dock->setActive(true);
806 nextBufferView(); // fallback
809 void MainWin::showPasswordChangeDlg()
811 if (Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
812 PasswordChangeDlg{}.exec();
815 QMessageBox box(QMessageBox::Warning,
816 tr("Feature Not Supported"),
817 tr("<b>Your Quassel Core does not support this feature</b>"),
819 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
824 void MainWin::showMigrationWarning(bool show)
826 if (show && !_migrationWarning) {
827 _migrationWarning = new QMessageBox(QMessageBox::Information,
829 "<b>" + tr("Your database is being upgraded") + "</b>",
830 QMessageBox::NoButton,
832 _migrationWarning->setInformativeText(
833 "<p>" + tr("In order to support new features, we need to make changes to your backlog database. This may take a long while.")
834 + "</p><p>" + tr("Do not exit Quassel until the upgrade is complete!") + "</p>");
835 _migrationWarning->setStandardButtons(QMessageBox::NoButton);
836 _migrationWarning->show();
838 else if (!show && _migrationWarning) {
839 _migrationWarning->close();
840 _migrationWarning->deleteLater();
841 _migrationWarning = nullptr;
845 void MainWin::onExitRequested(const QString& reason)
847 if (!reason.isEmpty()) {
848 QMessageBox box(QMessageBox::Critical,
850 "<b>" + tr("Quassel encountered a fatal error and is terminated.") + "</b>",
852 box.setInformativeText("<p>" + tr("Reason:<em>") + " " + reason + "</em>");
857 void MainWin::changeActiveBufferView(bool backwards)
859 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
860 _bufferViews[_activeBufferViewIndex]->setActive(false);
863 if (!_bufferViews.count())
866 int c = _bufferViews.count();
867 while (c--) { // yes, this will reactivate the current active one if all others fail
869 if (--_activeBufferViewIndex < 0)
870 _activeBufferViewIndex = _bufferViews.count() - 1;
873 if (++_activeBufferViewIndex >= _bufferViews.count())
874 _activeBufferViewIndex = 0;
877 BufferViewDock* dock = _bufferViews.at(_activeBufferViewIndex);
878 if (dock->isHidden())
881 dock->setActive(true);
885 _activeBufferViewIndex = -1;
888 void MainWin::nextBufferView()
890 changeActiveBufferView(false);
893 void MainWin::previousBufferView()
895 changeActiveBufferView(true);
898 void MainWin::nextBuffer()
900 BufferView* view = activeBufferView();
905 void MainWin::previousBuffer()
907 BufferView* view = activeBufferView();
909 view->previousBuffer();
912 void MainWin::hideCurrentBuffer()
914 BufferView* view = activeBufferView();
916 view->hideCurrentBuffer();
919 void MainWin::showNotificationsDlg()
921 SettingsPageDlg{new NotificationsSettingsPage{}}.exec();
924 void MainWin::onConfigureNetworksTriggered()
926 SettingsPageDlg{new NetworksSettingsPage{}}.exec();
929 void MainWin::onConfigureViewsTriggered()
931 SettingsPageDlg{new BufferViewSettingsPage{}}.exec();
934 void MainWin::onLockLayoutToggled(bool lock)
936 QList<VerticalDock*> docks = findChildren<VerticalDock*>();
937 foreach (VerticalDock* dock, docks) {
938 dock->showTitle(!lock);
941 QList<NickListDock*> nickdocks = findChildren<NickListDock*>();
942 foreach (NickListDock* nickdock, nickdocks) {
943 nickdock->setLocked(lock);
946 QList<BufferViewDock*> bufferdocks = findChildren<BufferViewDock*>();
947 foreach (BufferViewDock* bufferdock, bufferdocks) {
948 bufferdock->setLocked(lock);
951 if (Client::bufferViewManager()) {
952 foreach (ClientBufferViewConfig* config, Client::bufferViewManager()->clientBufferViewConfigs()) {
953 config->setLocked(lock);
957 _mainToolBar->setMovable(!lock);
958 _nickToolBar->setMovable(!lock);
960 QtUiSettings().setValue("LockLayout", lock);
963 void MainWin::setupNickWidget()
966 NickListDock* nickDock = new NickListDock(tr("Nicks"), this);
967 nickDock->setObjectName("NickDock");
968 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
969 nickDock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
971 _nickListWidget = new NickListWidget(nickDock);
972 nickDock->setWidget(_nickListWidget);
974 addDockWidget(Qt::RightDockWidgetArea, nickDock);
975 _viewMenu->addAction(nickDock->toggleViewAction());
976 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
978 // See NickListDock::NickListDock();
979 // connect(nickDock->toggleViewAction(), &NickListDock::triggered, nickListWidget, &QWidget::showWidget);
981 // attach the NickListWidget to the BufferModel and the default selection
982 _nickListWidget->setModel(Client::bufferModel());
983 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
985 _nickListWidget->setVisible(false);
988 void MainWin::setupChatMonitor()
990 VerticalDock* dock = new VerticalDock(tr("Chat Monitor"), this);
991 dock->setObjectName("ChatMonitorDock");
993 auto* filter = new ChatMonitorFilter(Client::messageModel(), this);
994 _chatMonitorView = new ChatMonitorView(filter, this);
995 _chatMonitorView->show();
996 dock->setWidget(_chatMonitorView);
999 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1000 _viewMenu->addAction(dock->toggleViewAction());
1001 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
1004 void MainWin::setupInputWidget()
1006 VerticalDock* dock = new VerticalDock(tr("Inputline"), this);
1007 dock->setObjectName("InputDock");
1009 _inputWidget = new InputWidget(dock);
1010 dock->setWidget(_inputWidget);
1012 addDockWidget(Qt::BottomDockWidgetArea, dock);
1014 _viewMenu->addAction(dock->toggleViewAction());
1015 dock->toggleViewAction()->setText(tr("Show Input Line"));
1017 _inputWidget->setModel(Client::bufferModel());
1018 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1020 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
1023 void MainWin::setupTopicWidget()
1025 VerticalDock* dock = new VerticalDock(tr("Topic"), this);
1026 dock->setObjectName("TopicDock");
1027 _topicWidget = new TopicWidget(dock);
1029 dock->setWidget(_topicWidget);
1031 _topicWidget->setModel(Client::bufferModel());
1032 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1034 connect(_topicWidget, &TopicWidget::switchedPlain, _bufferWidget, selectOverload<>(&QWidget::setFocus));
1036 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1038 _viewMenu->addAction(dock->toggleViewAction());
1039 dock->toggleViewAction()->setText(tr("Show Topic Line"));
1042 void MainWin::setupTransferWidget()
1044 auto dock = new QDockWidget(tr("Transfers"), this);
1045 dock->setObjectName("TransferDock");
1046 dock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1048 auto view = new QTableView(dock); // to be replaced by the real thing
1049 view->setModel(Client::transferModel());
1050 dock->setWidget(view);
1051 dock->hide(); // hidden by default
1052 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1054 auto action = dock->toggleViewAction();
1055 action->setText(tr("Show File Transfers"));
1056 action->setIcon(icon::get("download"));
1057 action->setShortcut(QKeySequence(Qt::Key_F6));
1058 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
1059 _viewMenu->addAction(action);
1062 void MainWin::setupViewMenuTail()
1064 _viewMenu->addSeparator();
1065 _viewMenu->addAction(_fullScreenAction);
1068 void MainWin::setupTitleSetter()
1070 _titleSetter.setModel(Client::bufferModel());
1071 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1074 void MainWin::setupStatusBar()
1076 // MessageProcessor progress
1077 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1080 _coreConnectionStatusWidget->update();
1081 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1083 QAction* showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1085 QtUiSettings uiSettings;
1087 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1088 showStatusbar->setChecked(enabled);
1089 enabled ? statusBar()->show() : statusBar()->hide();
1091 connect(showStatusbar, &QAction::toggled, statusBar(), &QWidget::setVisible);
1092 connect(showStatusbar, &QAction::toggled, this, &MainWin::saveStatusBarStatus);
1094 connect(Client::coreConnection(), &CoreConnection::connectionMsg, statusBar(), [statusBar = statusBar()](auto&& message) {
1095 statusBar->showMessage(message);
1099 void MainWin::setupHotList()
1101 auto* flatProxy = new FlatProxyModel(this);
1102 flatProxy->setSourceModel(Client::bufferModel());
1103 _bufferHotList = new BufferHotListFilter(flatProxy);
1106 void MainWin::saveMenuBarStatus(bool enabled)
1108 QtUiSettings uiSettings;
1109 uiSettings.setValue("ShowMenuBar", enabled);
1112 void MainWin::saveStatusBarStatus(bool enabled)
1114 QtUiSettings uiSettings;
1115 uiSettings.setValue("ShowStatusBar", enabled);
1118 void MainWin::setupSystray()
1121 _systemTray = new StatusNotifierItem(this);
1122 #elif !defined QT_NO_SYSTEMTRAYICON
1123 _systemTray = new LegacySystemTray(this);
1125 _systemTray = new SystemTray(this); // dummy
1129 void MainWin::setupToolBars()
1131 connect(_bufferWidget,
1132 selectOverload<const QModelIndex&>(&AbstractBufferContainer::currentChanged),
1133 QtUi::toolBarActionProvider(),
1134 &ToolBarActionProvider::onCurrentBufferChanged);
1135 connect(_nickListWidget,
1136 &NickListWidget::nickSelectionChanged,
1137 QtUi::toolBarActionProvider(),
1138 &ToolBarActionProvider::onNickSelectionChanged);
1141 setUnifiedTitleAndToolBarOnMac(true);
1145 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1147 _mainToolBar = new QToolBar(this);
1148 _mainToolBar->setObjectName("MainToolBar");
1150 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1151 addToolBar(_mainToolBar);
1153 if (Quassel::runMode() != Quassel::Monolithic) {
1154 ActionCollection* coll = QtUi::actionCollection("General");
1155 _mainToolBar->addAction(coll->action("ConnectCore"));
1156 _mainToolBar->addAction(coll->action("DisconnectCore"));
1159 _mainToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1161 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1162 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1165 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1167 _nickToolBar = new QToolBar(this);
1168 _nickToolBar->setObjectName("NickToolBar");
1170 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1171 _nickToolBar->setVisible(false); // default: not visible
1172 addToolBar(_nickToolBar);
1173 _nickToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1175 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1176 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1179 QtUiSettings uiSettings;
1181 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1182 _mainToolBar->setVisible(visible);
1183 connect(_mainToolBar, &QToolBar::visibilityChanged, this, &MainWin::saveMainToolBarStatus);
1187 void MainWin::saveMainToolBarStatus(bool enabled)
1190 QtUiSettings uiSettings;
1191 uiSettings.setValue("ShowMainToolBar", enabled);
1197 void MainWin::doAutoConnect()
1199 int accountId = Quassel::optionValue("account").toInt();
1200 if (!Client::coreConnection()->connectToCore(accountId)) {
1201 // No autoconnect selected (or no accounts)
1202 showCoreConnectionDlg();
1206 void MainWin::connectedToCore()
1208 Q_CHECK_PTR(Client::bufferViewManager());
1209 connect(Client::bufferViewManager(), &BufferViewManager::bufferViewConfigAdded, this, selectOverload<int>(&MainWin::addBufferView));
1210 connect(Client::bufferViewManager(), &BufferViewManager::bufferViewConfigDeleted, this, &MainWin::removeBufferView);
1211 connect(Client::bufferViewManager(), &SyncableObject::initDone, this, &MainWin::loadLayout);
1213 if (Client::transferManager()) {
1214 connect(Client::transferManager(), &TransferManager::transferAdded, this, &MainWin::showNewTransferDlg);
1217 setConnectedState();
1220 void MainWin::setConnectedState()
1222 ActionCollection* coll = QtUi::actionCollection("General");
1224 coll->action("ConnectCore")->setEnabled(false);
1225 coll->action("DisconnectCore")->setEnabled(true);
1226 coll->action("ChangePassword")->setEnabled(true);
1227 coll->action("CoreInfo")->setEnabled(true);
1229 foreach (QAction* action, _fileMenu->actions()) {
1230 if (isRemoteCoreOnly(action))
1231 action->setVisible(!Client::internalCore());
1234 disconnect(Client::backlogManager(),
1235 &ClientBacklogManager::updateProgress,
1236 _msgProcessorStatusWidget,
1237 &MsgProcessorStatusWidget::setProgress);
1238 disconnect(Client::backlogManager(), &ClientBacklogManager::messagesRequested, this, &MainWin::showStatusBarMessage);
1239 disconnect(Client::backlogManager(), &ClientBacklogManager::messagesProcessed, this, &MainWin::showStatusBarMessage);
1240 if (!Client::internalCore()) {
1241 connect(Client::backlogManager(),
1242 &ClientBacklogManager::updateProgress,
1243 _msgProcessorStatusWidget,
1244 &MsgProcessorStatusWidget::setProgress);
1245 connect(Client::backlogManager(), &ClientBacklogManager::messagesRequested, this, &MainWin::showStatusBarMessage);
1246 connect(Client::backlogManager(), &ClientBacklogManager::messagesProcessed, this, &MainWin::showStatusBarMessage);
1249 // _viewMenu->setEnabled(true);
1250 if (!Client::internalCore())
1251 statusBar()->showMessage(tr("Connected to core."));
1253 statusBar()->clearMessage();
1255 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1257 systemTray()->setState(SystemTray::Active);
1259 if (Client::networkIds().isEmpty()) {
1260 IrcConnectionWizard* wizard = new IrcConnectionWizard(this, Qt::Sheet);
1264 // Monolithic always preselects last used buffer - Client only if the connection died
1265 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1267 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1268 if (lastUsedBufferId.isValid())
1269 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1274 void MainWin::loadLayout()
1277 int accountId = Client::currentCoreAccount().accountId().toInt();
1278 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1279 _nickListWidget->setVisible(true);
1280 if (state.isEmpty()) {
1281 foreach (BufferViewDock* view, _bufferViews)
1283 _layoutLoaded = true;
1286 restoreState(state, accountId);
1287 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1288 if (bufferViewId >= 0)
1289 changeActiveBufferView(bufferViewId);
1291 _layoutLoaded = true;
1294 void MainWin::saveLayout()
1297 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1298 if (accountId > 0) {
1299 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1300 BufferView* view = activeBufferView();
1301 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1305 void MainWin::disconnectedFromCore()
1307 // save core specific layout and remove bufferviews;
1309 _layoutLoaded = false;
1311 QVariant actionData;
1312 BufferViewDock* dock;
1313 foreach (QAction* action, _bufferViewsMenu->actions()) {
1314 actionData = action->data();
1315 if (!actionData.isValid())
1318 dock = qobject_cast<BufferViewDock*>(action->parent());
1319 if (dock && actionData.toInt() != -1) {
1320 removeAction(action);
1321 _bufferViews.removeAll(dock);
1322 dock->deleteLater();
1326 // store last active buffer
1328 BufferId lastBufId = _bufferWidget->currentBuffer();
1329 if (lastBufId.isValid()) {
1330 s.setValue("LastUsedBufferId", lastBufId.toInt());
1331 // clear the current selection
1332 Client::bufferModel()->standardSelectionModel()->clearSelection();
1334 restoreState(s.value("MainWinState").toByteArray());
1335 setDisconnectedState();
1338 void MainWin::setDisconnectedState()
1340 ActionCollection* coll = QtUi::actionCollection("General");
1341 // ui.menuCore->setEnabled(false);
1342 coll->action("ConnectCore")->setEnabled(true);
1343 coll->action("DisconnectCore")->setEnabled(false);
1344 coll->action("CoreInfo")->setEnabled(false);
1345 coll->action("ChangePassword")->setEnabled(false);
1346 //_viewMenu->setEnabled(false);
1347 statusBar()->showMessage(tr("Not connected to core."));
1348 if (_msgProcessorStatusWidget)
1349 _msgProcessorStatusWidget->setProgress(0, 0);
1351 systemTray()->setState(SystemTray::Passive);
1352 _nickListWidget->setVisible(false);
1355 void MainWin::userAuthenticationRequired(CoreAccount* account, bool* valid, const QString& errorMessage)
1357 Q_UNUSED(errorMessage)
1358 CoreConnectAuthDlg dlg(account);
1359 *valid = (dlg.exec() == QDialog::Accepted);
1362 void MainWin::handleNoSslInClient(bool* accepted)
1364 QMessageBox box(QMessageBox::Warning,
1365 tr("Unencrypted Connection"),
1366 tr("<b>Your client does not support SSL encryption</b>"),
1367 QMessageBox::Ignore | QMessageBox::Cancel);
1368 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1369 box.setDefaultButton(QMessageBox::Ignore);
1370 *accepted = (box.exec() == QMessageBox::Ignore);
1373 void MainWin::handleNoSslInCore(bool* accepted)
1375 QMessageBox box(QMessageBox::Warning,
1376 tr("Unencrypted Connection"),
1377 tr("<b>Your core does not support SSL encryption</b>"),
1378 QMessageBox::Ignore | QMessageBox::Cancel);
1379 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1380 box.setDefaultButton(QMessageBox::Ignore);
1381 *accepted = (box.exec() == QMessageBox::Ignore);
1384 void MainWin::handleSslErrors(const QSslSocket* socket, bool* accepted, bool* permanently)
1386 QString errorString = "<ul>";
1387 foreach (const QSslError error, socket->sslErrors())
1388 errorString += QString("<li>%1</li>").arg(error.errorString());
1389 errorString += "</ul>";
1391 QMessageBox box(QMessageBox::Warning,
1392 tr("Untrusted Security Certificate"),
1393 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1394 QMessageBox::Cancel);
1395 box.setInformativeText(errorString);
1396 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1397 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1399 QMessageBox::ButtonRole role;
1402 role = box.buttonRole(box.clickedButton());
1403 if (role == QMessageBox::HelpRole) {
1404 SslInfoDlg dlg(socket);
1407 } while (role == QMessageBox::HelpRole);
1409 *accepted = role == QMessageBox::AcceptRole;
1411 QMessageBox box2(QMessageBox::Warning,
1412 tr("Untrusted Security Certificate"),
1413 tr("Would you like to accept this certificate forever without being prompted?"),
1414 QMessageBox::NoButton);
1415 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1416 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1418 *permanently = (box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole);
1422 void MainWin::handleCoreConnectionError(const QString& error)
1424 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1427 void MainWin::showCoreConnectionDlg()
1430 if (dlg.exec() == QDialog::Accepted) {
1431 AccountId accId = dlg.selectedAccount();
1432 if (accId.isValid())
1433 Client::coreConnection()->connectToCore(accId);
1437 void MainWin::showCoreConfigWizard(const QVariantList& backends, const QVariantList& authenticators)
1439 auto* wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1444 void MainWin::showChannelList(NetworkId netId, const QString& channelFilters, bool listImmediately)
1446 if (!netId.isValid()) {
1447 auto* action = qobject_cast<QAction*>(sender());
1449 netId = action->data().value<NetworkId>();
1450 if (!netId.isValid()) {
1451 // We still haven't found a valid network, probably no network selected, e.g. "/list"
1452 // on the client homescreen when no networks are connected.
1453 QMessageBox box(QMessageBox::Information,
1454 tr("No network selected"),
1455 QString("<b>%1</b>").arg(tr("No network selected")),
1457 box.setInformativeText(tr("Select a network before trying to view the channel list."));
1463 auto* channelListDlg = new ChannelListDlg(this);
1464 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1465 channelListDlg->setNetwork(netId);
1466 if (!channelFilters.isEmpty()) {
1467 channelListDlg->setChannelFilters(channelFilters);
1469 if (listImmediately) {
1470 channelListDlg->requestSearch();
1472 channelListDlg->show();
1475 void MainWin::showNetworkConfig(NetworkId netId)
1477 SettingsPageDlg dlg{new NetworksSettingsPage{}};
1478 if (netId.isValid())
1479 qobject_cast<NetworksSettingsPage*>(dlg.currentPage())->bufferList_Open(netId);
1483 void MainWin::showIgnoreList(QString newRule)
1485 SettingsPageDlg dlg{new IgnoreListSettingsPage{}};
1486 // prepare config dialog for new rule
1487 if (!newRule.isEmpty())
1488 qobject_cast<IgnoreListSettingsPage*>(dlg.currentPage())->editIgnoreRule(newRule);
1492 void MainWin::showCoreInfoDlg()
1494 CoreInfoDlg{}.exec();
1497 void MainWin::showAwayLog()
1501 auto* filter = new AwayLogFilter(Client::messageModel());
1502 _awayLog = new AwayLogView(filter, nullptr);
1503 filter->setParent(_awayLog);
1504 connect(_awayLog, &QObject::destroyed, this, &MainWin::awayLogDestroyed);
1505 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1509 void MainWin::awayLogDestroyed()
1514 void MainWin::showSettingsDlg()
1516 auto dlg = new SettingsDlg();
1518 // Category: Interface
1519 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1520 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1521 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1522 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1523 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1524 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1525 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1526 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1528 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1530 auto coreHighlightsPage = new CoreHighlightSettingsPage(dlg);
1531 auto localHighlightsPage = new HighlightSettingsPage(dlg);
1532 // Let CoreHighlightSettingsPage reload HighlightSettingsPage after doing an import with
1533 // cleaning up. Otherwise, HighlightSettingsPage won't show that the local rules were deleted.
1534 connect(coreHighlightsPage, &CoreHighlightSettingsPage::localHighlightsChanged,
1535 localHighlightsPage, &HighlightSettingsPage::load);
1536 // Put core-side highlights before local/legacy highlights
1537 dlg->registerSettingsPage(coreHighlightsPage);
1538 dlg->registerSettingsPage(localHighlightsPage);
1539 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1540 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1543 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1544 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1545 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1546 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1547 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1548 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1550 // Category: Remote Cores
1551 if (Quassel::runMode() != Quassel::Monolithic) {
1552 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1553 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1559 void MainWin::showAboutDlg()
1564 void MainWin::showShortcutsDlg()
1567 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed);
1568 foreach (KActionCollection* coll, QtUi::actionCollections()) {
1569 dlg.addCollection(coll, coll->property("Category").toString());
1571 dlg.configure(true);
1573 SettingsPageDlg{new ShortcutsSettingsPage{QtUi::actionCollections()}}.exec();
1577 void MainWin::showNewTransferDlg(const QUuid& transferId)
1579 auto transfer = Client::transferManager()->transfer(transferId);
1581 if (transfer->status() == Transfer::Status::New) {
1582 auto* dlg = new ReceiveFileDlg(transfer, this);
1587 qWarning() << "Unknown transfer ID" << transferId;
1591 void MainWin::onFullScreenToggled()
1593 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1594 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1597 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1599 if (_fullScreenAction->isChecked())
1600 setWindowState(windowState() | Qt::WindowFullScreen);
1602 setWindowState(windowState() & ~Qt::WindowFullScreen);
1606 /********************************************************************************************************/
1608 bool MainWin::event(QEvent* event)
1610 switch (event->type()) {
1611 case QEvent::WindowActivate: {
1612 BufferId bufferId = Client::bufferModel()->currentBuffer();
1613 if (bufferId.isValid())
1614 Client::instance()->markBufferAsRead(bufferId);
1617 case QEvent::WindowDeactivate:
1618 if (bufferWidget()->autoMarkerLineOnLostFocus())
1619 bufferWidget()->setMarkerLine();
1624 return QMainWindow::event(event);
1627 void MainWin::moveEvent(QMoveEvent* event)
1629 if (!(windowState() & Qt::WindowMaximized))
1630 _normalPos = event->pos();
1632 QMainWindow::moveEvent(event);
1635 void MainWin::resizeEvent(QResizeEvent* event)
1637 if (!(windowState() & Qt::WindowMaximized))
1638 _normalSize = event->size();
1640 QMainWindow::resizeEvent(event);
1643 void MainWin::closeEvent(QCloseEvent* event)
1646 auto* app = qobject_cast<QtUiApplication*> qApp;
1648 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1649 // This messes up MainWinState/MainWinHidden save/restore.
1650 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1651 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1652 QtUi::hideMainWidget();
1655 else if (!_aboutToQuit) {
1656 _aboutToQuit = true;
1658 Quassel::instance()->quit();
1665 void MainWin::messagesInserted(const QModelIndex& parent, int start, int end)
1669 bool hasFocus = QApplication::activeWindow() != nullptr;
1671 for (int i = start; i <= end; i++) {
1672 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1673 if (!idx.isValid()) {
1674 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1677 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1678 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1681 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1682 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1684 // check if bufferId belongs to the shown chatlists
1685 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) || Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1688 // check if it's the buffer currently displayed
1689 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1692 // only show notifications for higlights or queries
1693 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1696 // and of course: don't notify for ignored messages
1697 if (Client::ignoreListManager()
1698 && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1699 Client::networkModel()->networkName(bufId)))
1702 // seems like we have a legit notification candidate!
1703 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1704 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1705 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1706 AbstractNotificationBackend::NotificationType type;
1708 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1709 type = AbstractNotificationBackend::PrivMsg;
1710 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1711 type = AbstractNotificationBackend::PrivMsgFocused;
1712 else if (flags & Message::Highlight && !hasFocus)
1713 type = AbstractNotificationBackend::Highlight;
1715 type = AbstractNotificationBackend::HighlightFocused;
1717 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1721 void MainWin::currentBufferChanged(BufferId buffer)
1723 if (buffer.isValid())
1724 Client::instance()->markBufferAsRead(buffer);
1727 void MainWin::clientNetworkCreated(NetworkId id)
1729 const Network* net = Client::network(id);
1730 auto* act = new QAction(net->networkName(), this);
1731 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1732 act->setData(QVariant::fromValue(id));
1733 connect(net, &SyncableObject::updatedRemotely, this, &MainWin::clientNetworkUpdated);
1734 connect(act, &QAction::triggered, this, &MainWin::connectOrDisconnectFromNet);
1736 QAction* beforeAction = nullptr;
1737 foreach (QAction* action, _networksMenu->actions()) {
1738 if (!action->data().isValid()) // ignore stock actions
1740 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1741 beforeAction = action;
1745 _networksMenu->insertAction(beforeAction, act);
1748 void MainWin::clientNetworkUpdated()
1750 const auto* net = qobject_cast<const Network*>(sender());
1754 auto* action = findChild<QAction*>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1758 action->setText(net->networkName());
1760 switch (net->connectionState()) {
1761 case Network::Initialized:
1762 action->setIcon(icon::get("network-connect"));
1763 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1764 if (!bufferWidget()->currentBuffer().isValid()) {
1765 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1766 if (idx.isValid()) {
1767 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1768 Client::bufferModel()->switchToBuffer(statusBufferId);
1772 case Network::Disconnected:
1773 action->setIcon(icon::get("network-disconnect"));
1776 action->setIcon(icon::get("network-wired"));
1780 void MainWin::clientNetworkRemoved(NetworkId id)
1782 auto* action = findChild<QAction*>(QString("NetworkAction-%1").arg(id.toInt()));
1786 action->deleteLater();
1789 void MainWin::connectOrDisconnectFromNet()
1791 auto* act = qobject_cast<QAction*>(sender());
1794 const Network* net = Client::network(act->data().value<NetworkId>());
1797 if (net->connectionState() == Network::Disconnected)
1798 net->requestConnect();
1800 net->requestDisconnect();
1803 void MainWin::onFormatApplyColorTriggered()
1808 _inputWidget->applyFormatActiveColor();
1811 void MainWin::onFormatApplyColorFillTriggered()
1816 _inputWidget->applyFormatActiveColorFill();
1819 void MainWin::onFormatClearTriggered()
1824 _inputWidget->clearFormat();
1827 void MainWin::onFormatBoldTriggered()
1832 _inputWidget->toggleFormatBold();
1835 void MainWin::onFormatItalicTriggered()
1840 _inputWidget->toggleFormatItalic();
1843 void MainWin::onFormatUnderlineTriggered()
1848 _inputWidget->toggleFormatUnderline();
1851 void MainWin::onFormatStrikethroughTriggered()
1856 _inputWidget->toggleFormatStrikethrough();
1860 void MainWin::onJumpHotBufferTriggered()
1862 if (!_bufferHotList->rowCount())
1865 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1868 void MainWin::onBufferSearchTriggered()
1870 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1871 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1875 _bufferViews[_activeBufferViewIndex]->activateFilter();
1878 void MainWin::onJumpKey()
1880 auto* action = qobject_cast<QAction*>(sender());
1881 if (!action || !Client::bufferModel())
1883 int idx = action->property("Index").toInt();
1885 if (_jumpKeyMap.isEmpty())
1886 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1888 if (!_jumpKeyMap.contains(idx))
1891 BufferId buffer = _jumpKeyMap.value(idx);
1892 if (buffer.isValid())
1893 Client::bufferModel()->switchToBuffer(buffer);
1896 void MainWin::bindJumpKey()
1898 auto* action = qobject_cast<QAction*>(sender());
1899 if (!action || !Client::bufferModel())
1901 int idx = action->property("Index").toInt();
1903 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1904 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1907 void MainWin::onDebugNetworkModelTriggered()
1909 auto* view = new QTreeView;
1910 view->setAttribute(Qt::WA_DeleteOnClose);
1911 view->setWindowTitle("Debug NetworkModel View");
1912 view->setModel(Client::networkModel());
1913 view->setColumnWidth(0, 250);
1914 view->setColumnWidth(1, 250);
1915 view->setColumnWidth(2, 80);
1916 view->resize(610, 300);
1920 void MainWin::onDebugHotListTriggered()
1922 _bufferHotList->invalidate();
1923 _bufferHotList->sort(0, Qt::DescendingOrder);
1925 auto* view = new QTreeView;
1926 view->setAttribute(Qt::WA_DeleteOnClose);
1927 view->setModel(_bufferHotList);
1931 void MainWin::onDebugBufferViewOverlayTriggered()
1933 auto* overlay = new DebugBufferViewOverlay(nullptr);
1934 overlay->setAttribute(Qt::WA_DeleteOnClose);
1938 void MainWin::onDebugMessageModelTriggered()
1940 auto* view = new QTableView(nullptr);
1941 auto* filter = new DebugMessageModelFilter(view);
1942 filter->setSourceModel(Client::messageModel());
1943 view->setModel(filter);
1944 view->setAttribute(Qt::WA_DeleteOnClose, true);
1945 view->verticalHeader()->hide();
1946 view->horizontalHeader()->setStretchLastSection(true);
1950 void MainWin::onDebugLogTriggered()
1952 auto dlg = new DebugLogDlg(this); // will be deleted on close
1956 void MainWin::onShowResourceTreeTriggered()
1958 auto dlg = new ResourceTreeDlg(this); // will be deleted on close
1962 void MainWin::showStatusBarMessage(const QString& message)
1964 statusBar()->showMessage(message, 10000);