1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
25 #include <QMessageBox>
29 #include <QInputDialog>
32 # include <kconfigwidgets_version.h>
33 # include <KConfigWidgets/KStandardAction>
34 # include <KXmlGui/KHelpMenu>
35 # include <KXmlGui/KShortcutsDialog>
36 # include <KXmlGui/KToolBar>
37 # include <KWidgetsAddons/KToggleFullScreenAction>
45 #include "awaylogfilter.h"
46 #include "awaylogview.h"
48 #include "actioncollection.h"
49 #include "bufferhotlistfilter.h"
50 #include "buffermodel.h"
51 #include "bufferview.h"
52 #include "bufferviewoverlay.h"
53 #include "bufferviewoverlayfilter.h"
54 #include "bufferwidget.h"
55 #include "channellistdlg.h"
56 #include "chatlinemodel.h"
57 #include "chatmonitorfilter.h"
58 #include "chatmonitorview.h"
61 #include "clientbacklogmanager.h"
62 #include "clientbufferviewconfig.h"
63 #include "clientbufferviewmanager.h"
64 #include "clientignorelistmanager.h"
65 #include "clienttransfer.h"
66 #include "clienttransfermanager.h"
67 #include "coreconfigwizard.h"
68 #include "coreconnectdlg.h"
69 #include "coreconnection.h"
70 #include "coreconnectionstatuswidget.h"
71 #include "coreinfodlg.h"
72 #include "contextmenuactionprovider.h"
73 #include "debugbufferviewoverlay.h"
74 #include "debuglogdlg.h"
75 #include "debugmessagemodelfilter.h"
76 #include "flatproxymodel.h"
78 #include "inputwidget.h"
79 #include "irclistmodel.h"
80 #include "ircconnectionwizard.h"
81 #include "legacysystemtray.h"
82 #include "msgprocessorstatuswidget.h"
83 #include "nicklistwidget.h"
84 #include "passwordchangedlg.h"
85 #include "qtuiapplication.h"
86 #include "qtuimessageprocessor.h"
87 #include "qtuisettings.h"
88 #include "qtuistyle.h"
89 #include "receivefiledlg.h"
90 #include "resourcetreedlg.h"
91 #include "settingsdlg.h"
92 #include "settingspagedlg.h"
93 #include "statusnotifieritem.h"
94 #include "toolbaractionprovider.h"
95 #include "topicwidget.h"
96 #include "transfermodel.h"
97 #include "verticaldock.h"
100 # ifdef HAVE_QTMULTIMEDIA
101 # include "qtmultimedianotificationbackend.h"
103 # include "systraynotificationbackend.h"
104 # include "taskbarnotificationbackend.h"
106 # include "knotificationbackend.h"
107 #endif /* HAVE_KDE */
108 #include "systrayanimationnotificationbackend.h"
112 # include "snorenotificationbackend.h"
116 # include "sslinfodlg.h"
119 #ifdef HAVE_NOTIFICATION_CENTER
120 #include "osxnotificationbackend.h"
124 #include "dockmanagernotificationbackend.h"
127 #include "settingspages/aliasessettingspage.h"
128 #include "settingspages/appearancesettingspage.h"
129 #include "settingspages/backlogsettingspage.h"
130 #include "settingspages/bufferviewsettingspage.h"
131 #include "settingspages/chatmonitorsettingspage.h"
132 #include "settingspages/chatviewsettingspage.h"
133 #include "settingspages/chatviewcolorsettingspage.h"
134 #include "settingspages/connectionsettingspage.h"
135 #include "settingspages/coreaccountsettingspage.h"
136 #include "settingspages/coreconnectionsettingspage.h"
137 #include <settingspages/corehighlightsettingspage.h>
138 #include "settingspages/dccsettingspage.h"
139 #include "settingspages/highlightsettingspage.h"
140 #include "settingspages/identitiessettingspage.h"
141 #include "settingspages/ignorelistsettingspage.h"
142 #include "settingspages/inputwidgetsettingspage.h"
143 #include "settingspages/itemviewsettingspage.h"
144 #include "settingspages/networkssettingspage.h"
145 #include "settingspages/notificationssettingspage.h"
146 #include "settingspages/topicwidgetsettingspage.h"
149 # include "settingspages/shortcutssettingspage.h"
153 # include "settingspages/sonnetsettingspage.h"
157 MainWin::MainWin(QWidget *parent)
159 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
161 : QMainWindow(parent),
163 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
164 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
167 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
169 QtUiSettings uiSettings;
170 QString style = uiSettings.value("Style", QString()).toString();
171 if (!style.isEmpty()) {
172 QApplication::setStyle(style);
175 QApplication::setQuitOnLastWindowClosed(false);
177 setWindowTitle("Quassel IRC");
178 setWindowIconText("Quassel IRC");
179 // Set the default icon for all windows
180 QApplication::setWindowIcon(icon::get("quassel"));
187 connect(Client::instance(), &Client::networkCreated, this, &MainWin::clientNetworkCreated);
188 connect(Client::instance(), &Client::networkRemoved, this, &MainWin::clientNetworkRemoved);
189 connect(Client::messageModel(), &QAbstractItemModel::rowsInserted,
190 this, &MainWin::messagesInserted);
191 connect(GraphicalUi::contextMenuActionProvider(),
192 &NetworkModelController::showChannelList,
193 this, &MainWin::showChannelList);
194 connect(Client::instance(),
195 &Client::showChannelList,
196 this, &MainWin::showChannelList);
197 connect(GraphicalUi::contextMenuActionProvider(), &NetworkModelController::showNetworkConfig, this, &MainWin::showNetworkConfig);
198 connect(GraphicalUi::contextMenuActionProvider(), &NetworkModelController::showIgnoreList, this, &MainWin::showIgnoreList);
199 connect(Client::instance(), &Client::showIgnoreList, this, &MainWin::showIgnoreList);
200 connect(Client::instance(), &Client::dbUpgradeInProgress, this, &MainWin::showMigrationWarning);
201 connect(Client::instance(), &Client::exitRequested, this, &MainWin::onExitRequested);
203 connect(Client::coreConnection(), &CoreConnection::startCoreSetup, this, &MainWin::showCoreConfigWizard);
204 connect(Client::coreConnection(), &CoreConnection::connectionErrorPopup, this, &MainWin::handleCoreConnectionError);
205 connect(Client::coreConnection(), &CoreConnection::userAuthenticationRequired, this, &MainWin::userAuthenticationRequired);
206 connect(Client::coreConnection(), &CoreConnection::handleNoSslInClient, this, &MainWin::handleNoSslInClient);
207 connect(Client::coreConnection(), &CoreConnection::handleNoSslInCore, this, &MainWin::handleNoSslInCore);
209 connect(Client::coreConnection(), &CoreConnection::handleSslErrors, this, &MainWin::handleSslErrors);
213 setDockNestingEnabled(true);
214 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
215 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
216 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
217 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
219 // Order is sometimes important
223 // setupTransferWidget(); not ready yet
235 _bufferWidget->setFocusProxy(_inputWidget);
236 _chatMonitorView->setFocusProxy(_inputWidget);
239 # ifdef HAVE_QTMULTIMEDIA
240 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
242 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
244 QtUi::registerNotificationBackend(new KNotificationBackend(this));
245 #endif /* HAVE_KDE */
248 #ifndef QT_NO_SYSTEMTRAYICON
249 QtUi::registerNotificationBackend(new SystrayAnimationNotificationBackend(this));
252 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
253 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
254 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
257 #ifdef HAVE_NOTIFICATION_CENTER
258 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
262 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
265 // we assume that at this point, all configurable actions are defined!
266 QtUi::loadShortcuts();
268 connect(bufferWidget(), selectOverload<BufferId>(&AbstractBufferContainer::currentChanged), this, &MainWin::currentBufferChanged);
270 setDisconnectedState(); // Disable menus and stuff
273 setAutoSaveSettings();
276 // restore mainwin state
278 restoreStateFromSettings(s);
280 // restore locked state of docks
281 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
283 Quassel::registerQuitHandler([this]() {
285 saveStateToSettings(s);
287 // Close all open dialogs and the MainWin, so we can safely kill the Client instance afterwards
288 // Note: This does not quit the application, as quitOnLastWindowClosed is set to false.
289 // We rely on another quit handler to be registered that actually quits the application.
290 qApp->closeAllWindows();
293 QTimer::singleShot(0, this, &MainWin::doAutoConnect);
297 void MainWin::saveStateToSettings(UiSettings &s)
299 s.setValue("MainWinSize", _normalSize);
300 s.setValue("MainWinPos", _normalPos);
301 s.setValue("MainWinState", saveState());
302 s.setValue("MainWinGeometry", saveGeometry());
303 s.setValue("MainWinMinimized", isMinimized());
304 s.setValue("MainWinMaximized", isMaximized());
305 s.setValue("MainWinHidden", !isVisible());
306 BufferId lastBufId = Client::bufferModel()->currentBuffer();
307 if (lastBufId.isValid())
308 s.setValue("LastUsedBufferId", lastBufId.toInt());
311 saveAutoSaveSettings();
316 void MainWin::restoreStateFromSettings(UiSettings &s)
318 _normalSize = s.value("MainWinSize", size()).toSize();
319 _normalPos = s.value("MainWinPos", pos()).toPoint();
320 bool maximized = s.value("MainWinMaximized", false).toBool();
323 restoreGeometry(s.value("MainWinGeometry").toByteArray());
326 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
331 restoreState(s.value("MainWinState").toByteArray());
337 if ((Quassel::isOptionSet("hidewindow")
338 || s.value("MainWinHidden").toBool())
339 && _systemTray->isSystemTrayAvailable())
340 QtUi::hideMainWidget();
341 else if (s.value("MainWinMinimized").toBool())
349 QMenu *MainWin::createPopupMenu()
351 QMenu *popupMenu = QMainWindow::createPopupMenu();
352 popupMenu->addSeparator();
353 ActionCollection *coll = QtUi::actionCollection("General");
354 popupMenu->addAction(coll->action("ToggleMenuBar"));
359 void MainWin::updateIcon()
362 if (Client::isConnected())
363 icon = icon::get("quassel");
365 icon = icon::get("inactive-quassel");
370 void MainWin::setupActions()
372 QAction *action{nullptr};
373 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
377 {"ConnectCore", new Action(icon::get("connect-quassel"), tr("&Connect to Core..."), coll, this, &MainWin::showCoreConnectionDlg)},
378 {"DisconnectCore", new Action(icon::get("disconnect-quassel"), tr("&Disconnect from Core"), coll, Client::instance(), &Client::disconnectFromCore)},
379 {"ChangePassword", new Action(icon::get("dialog-password"), tr("Change &Password..."), coll, this, &MainWin::showPasswordChangeDlg)},
380 {"CoreInfo", new Action(icon::get("help-about"), tr("Core &Info..."), coll, this, &MainWin::showCoreInfoDlg)},
381 {"ConfigureNetworks", new Action(icon::get("configure"), tr("Configure &Networks..."), coll, this, &MainWin::onConfigureNetworksTriggered)},
382 {"Quit", new Action(icon::get("application-exit"), tr("&Quit"), coll, Quassel::instance(), &Quassel::quit, Qt::CTRL + Qt::Key_Q)}
386 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll, this, &MainWin::onConfigureViewsTriggered));
388 coll->addAction("ToggleSearchBar", new Action(icon::get("edit-find"), tr("Show &Search Bar"), coll, QKeySequence::Find))->setCheckable(true);
389 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll, this, &MainWin::showAwayLog));
390 coll->addAction("ToggleMenuBar", new Action(icon::get("show-menu"), tr("Show &Menubar"), coll))->setCheckable(true);
391 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll))->setCheckable(true);
393 action = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
394 action->setCheckable(true);
395 connect(action, &QAction::toggled, this, &MainWin::onLockLayoutToggled);
398 #if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5,23,0)
399 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
401 _fullScreenAction = KStandardAction::fullScreen(this, &MainWin::onFullScreenToggled, this, coll);
404 _fullScreenAction = new Action(icon::get("view-fullscreen"), tr("&Full Screen Mode"), coll, this, &MainWin::onFullScreenToggled, QKeySequence::FullScreen);
405 _fullScreenAction->setCheckable(true);
406 coll->addAction("ToggleFullScreen", _fullScreenAction);
410 coll->addAction("ConfigureShortcuts", new Action(icon::get("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
411 this, &MainWin::showShortcutsDlg))->setMenuRole(QAction::NoRole);
412 coll->addAction("ConfigureQuassel", new Action(icon::get("configure"), tr("&Configure Quassel..."), coll,
413 this, &MainWin::showSettingsDlg, QKeySequence(Qt::Key_F7)))->setMenuRole(QAction::PreferencesRole);
416 coll->addAction("AboutQuassel", new Action(icon::get("quassel"), tr("&About Quassel"), coll, this, &MainWin::showAboutDlg))->setMenuRole(QAction::AboutRole);
417 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll, qApp, &QApplication::aboutQt))->setMenuRole(QAction::AboutQtRole);
419 {"DebugNetworkModel", new Action(icon::get("tools-report-bug"), tr("Debug &NetworkModel"), coll, this, &MainWin::onDebugNetworkModelTriggered)},
420 {"DebugBufferViewOverlay", new Action(icon::get("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll, this, &MainWin::onDebugBufferViewOverlayTriggered)},
421 {"DebugMessageModel", new Action(icon::get("tools-report-bug"), tr("Debug &MessageModel"), coll, this, &MainWin::onDebugMessageModelTriggered)},
422 {"DebugHotList", new Action(icon::get("tools-report-bug"), tr("Debug &HotList"), coll, this, &MainWin::onDebugHotListTriggered)},
423 {"DebugLog", new Action(icon::get("tools-report-bug"), tr("Debug &Log"), coll, this, &MainWin::onDebugLogTriggered)},
424 {"ShowResourceTree", new Action(icon::get("tools-report-bug"), tr("Show &Resource Tree"), coll, this, &MainWin::onShowResourceTreeTriggered)},
425 {"ReloadStyle", new Action(icon::get("view-refresh"), tr("Reload Stylesheet"), coll, QtUi::style(), &UiStyle::reload, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_R))}
429 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll, this, &MainWin::hideCurrentBuffer, QKeySequence::Close));
432 coll = QtUi::actionCollection("TextFormat", tr("Text formatting"));
435 {"FormatApplyColor", new Action(
436 icon::get("format-text-color"), tr("Apply foreground color"), coll,
437 this, &MainWin::onFormatApplyColorTriggered,
438 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_G))
440 {"FormatApplyColorFill", new Action(
441 icon::get("format-fill-color"), tr("Apply background color"), coll,
442 this, &MainWin::onFormatApplyColorFillTriggered,
443 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B))
445 {"FormatClear", new Action(
446 icon::get("edit-clear"), tr("Clear formatting"), coll,
447 this, &MainWin::onFormatClearTriggered,
448 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C))
450 {"FormatBold", new Action(
451 icon::get("format-text-bold"), tr("Toggle bold"), coll,
452 this, &MainWin::onFormatBoldTriggered,
455 {"FormatItalic", new Action(
456 icon::get("format-text-italic"), tr("Toggle italics"), coll,
457 this, &MainWin::onFormatItalicTriggered,
458 QKeySequence::Italic)
460 {"FormatUnderline", new Action(
461 icon::get("format-text-underline"), tr("Toggle underline"), coll,
462 this, &MainWin::onFormatUnderlineTriggered,
463 QKeySequence::Underline)
468 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
471 {"JumpHotBuffer", new Action(tr("Jump to hot chat"), coll, this, &MainWin::onJumpHotBufferTriggered, QKeySequence(Qt::META + Qt::Key_A))},
472 {"ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll, this, &MainWin::onBufferSearchTriggered, QKeySequence(Qt::CTRL + Qt::Key_S))}
477 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
478 const int jumpModifier = Qt::ControlModifier;
480 const int bindModifier = Qt::ControlModifier;
481 const int jumpModifier = Qt::AltModifier;
484 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, &MainWin::bindJumpKey,
485 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
486 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, &MainWin::bindJumpKey,
487 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
488 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, &MainWin::bindJumpKey,
489 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
490 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, &MainWin::bindJumpKey,
491 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
492 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, &MainWin::bindJumpKey,
493 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
494 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, &MainWin::bindJumpKey,
495 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
496 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, &MainWin::bindJumpKey,
497 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
498 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, &MainWin::bindJumpKey,
499 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
500 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, &MainWin::bindJumpKey,
501 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
502 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, &MainWin::bindJumpKey,
503 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
505 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, &MainWin::onJumpKey,
506 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
507 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, &MainWin::onJumpKey,
508 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
509 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, &MainWin::onJumpKey,
510 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
511 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, &MainWin::onJumpKey,
512 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
513 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, &MainWin::onJumpKey,
514 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
515 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, &MainWin::onJumpKey,
516 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
517 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, &MainWin::onJumpKey,
518 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
519 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, &MainWin::onJumpKey,
520 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
521 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, &MainWin::onJumpKey,
522 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
523 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, &MainWin::onJumpKey,
524 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
527 coll->addAction("NextBufferView", new Action(icon::get("go-next-view"), tr("Activate Next Chat List"), coll,
528 this, &MainWin::nextBufferView, QKeySequence(QKeySequence::Forward)));
529 coll->addAction("PreviousBufferView", new Action(icon::get("go-previous-view"), tr("Activate Previous Chat List"), coll,
530 this, &MainWin::previousBufferView, QKeySequence::Back));
531 coll->addAction("NextBuffer", new Action(icon::get("go-down"), tr("Go to Next Chat"), coll,
532 this, &MainWin::nextBuffer, QKeySequence(Qt::ALT + Qt::Key_Down)));
533 coll->addAction("PreviousBuffer", new Action(icon::get("go-up"), tr("Go to Previous Chat"), coll,
534 this, &MainWin::previousBuffer, QKeySequence(Qt::ALT + Qt::Key_Up)));
538 void MainWin::setupMenus()
540 ActionCollection *coll = QtUi::actionCollection("General");
542 _fileMenu = menuBar()->addMenu(tr("&File"));
544 static const QStringList coreActions = QStringList()
545 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
548 foreach(QString actionName, coreActions) {
549 coreAction = coll->action(actionName);
550 _fileMenu->addAction(coreAction);
551 flagRemoteCoreOnly(coreAction);
553 flagRemoteCoreOnly(_fileMenu->addSeparator());
555 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
556 _networksMenu->addAction(coll->action("ConfigureNetworks"));
557 _networksMenu->addSeparator();
558 _fileMenu->addSeparator();
559 _fileMenu->addAction(coll->action("Quit"));
561 _viewMenu = menuBar()->addMenu(tr("&View"));
562 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
563 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
564 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
565 _viewMenu->addSeparator();
567 _viewMenu->addAction(coll->action("ToggleMenuBar"));
568 _viewMenu->addAction(coll->action("ToggleStatusBar"));
569 _viewMenu->addAction(coll->action("ToggleSearchBar"));
571 coreAction = coll->action("ShowAwayLog");
572 flagRemoteCoreOnly(coreAction);
573 _viewMenu->addAction(coreAction);
575 _viewMenu->addSeparator();
576 _viewMenu->addAction(coll->action("LockLayout"));
578 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
580 #if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5,23,0)
581 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
582 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
584 _settingsMenu->addAction(KStandardAction::configureNotifications(this, &MainWin::showNotificationsDlg, this));
585 _settingsMenu->addAction(KStandardAction::keyBindings(this, &MainWin::showShortcutsDlg, this));
588 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
590 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
593 _helpMenu = menuBar()->addMenu(tr("&Help"));
595 _helpMenu->addAction(coll->action("AboutQuassel"));
597 _helpMenu->addAction(coll->action("AboutQt"));
599 #if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5,23,0)
600 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
602 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, &KHelpMenu::aboutKDE, this));
605 _helpMenu->addSeparator();
606 _helpDebugMenu = _helpMenu->addMenu(icon::get("tools-report-bug"), tr("Debug"));
607 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
608 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
609 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
610 _helpDebugMenu->addAction(coll->action("DebugHotList"));
611 _helpDebugMenu->addAction(coll->action("DebugLog"));
612 _helpDebugMenu->addAction(coll->action("ShowResourceTree"));
613 _helpDebugMenu->addSeparator();
614 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
617 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
619 QtUiSettings uiSettings;
620 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
621 showMenuBar->setChecked(enabled);
622 enabled ? menuBar()->show() : menuBar()->hide();
624 connect(showMenuBar, &QAction::toggled, menuBar(), &QMenuBar::setVisible);
625 connect(showMenuBar, &QAction::toggled, this, &MainWin::saveMenuBarStatus);
629 void MainWin::setupBufferWidget()
631 _bufferWidget = new BufferWidget(this);
632 _bufferWidget->setModel(Client::bufferModel());
633 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
634 setCentralWidget(_bufferWidget);
638 void MainWin::addBufferView(int bufferViewConfigId)
640 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
644 void MainWin::addBufferView(ClientBufferViewConfig *config)
649 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
650 auto *dock = new BufferViewDock(config, this);
652 //create the view and initialize it's filter
653 auto *view = new BufferView(dock);
654 view->setFilteredModel(Client::bufferModel(), config);
655 view->installEventFilter(_inputWidget); // for key presses
657 Client::bufferModel()->synchronizeView(view);
659 dock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
661 dock->setWidget(view);
662 dock->setVisible(_layoutLoaded); // don't show before state has been restored
664 addDockWidget(Qt::LeftDockWidgetArea, dock);
665 _bufferViewsMenu->addAction(dock->toggleViewAction());
667 connect(dock->toggleViewAction(), &QAction::toggled, this, &MainWin::bufferViewToggled);
668 connect(dock, &QDockWidget::visibilityChanged, this, &MainWin::bufferViewVisibilityChanged);
669 _bufferViews.append(dock);
671 if (!activeBufferView())
676 void MainWin::removeBufferView(int bufferViewConfigId)
679 BufferViewDock *dock;
680 foreach(QAction *action, _bufferViewsMenu->actions()) {
681 actionData = action->data();
682 if (!actionData.isValid())
685 dock = qobject_cast<BufferViewDock *>(action->parent());
686 if (dock && actionData.toInt() == bufferViewConfigId) {
687 removeAction(action);
688 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
689 _bufferViews.removeAll(dock);
691 if (dock->isActive()) {
692 dock->setActive(false);
693 _activeBufferViewIndex = -1;
703 void MainWin::bufferViewToggled(bool enabled)
705 if (!enabled && !isMinimized()) {
706 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
707 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
710 auto *action = qobject_cast<QAction *>(sender());
712 auto *dock = qobject_cast<BufferViewDock *>(action->parent());
715 // Make sure we don't toggle backlog fetch for a view we've already removed
716 if (!_bufferViews.contains(dock))
720 Client::bufferViewOverlay()->addView(dock->bufferViewId());
722 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
726 void MainWin::bufferViewVisibilityChanged(bool visible)
729 auto *dock = qobject_cast<BufferViewDock *>(sender());
731 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
736 BufferView *MainWin::allBuffersView() const
738 // "All Buffers" is always the first dock created
739 if (_bufferViews.count() > 0)
740 return _bufferViews[0]->bufferView();
745 BufferView *MainWin::activeBufferView() const
747 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
749 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
750 return dock->isActive() ? dock->bufferView() : nullptr;
754 void MainWin::changeActiveBufferView(int bufferViewId)
756 if (bufferViewId < 0)
759 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
760 _bufferViews[_activeBufferViewIndex]->setActive(false);
761 _activeBufferViewIndex = -1;
764 for (int i = 0; i < _bufferViews.count(); i++) {
765 BufferViewDock *dock = _bufferViews.at(i);
766 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
767 _activeBufferViewIndex = i;
768 dock->setActive(true);
773 nextBufferView(); // fallback
777 void MainWin::showPasswordChangeDlg()
779 if(Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
780 PasswordChangeDlg{}.exec();
783 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
784 tr("<b>Your Quassel Core does not support this feature</b>"),
786 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
792 void MainWin::showMigrationWarning(bool show)
794 if (show && !_migrationWarning) {
795 _migrationWarning = new QMessageBox(QMessageBox::Information,
797 "<b>" + tr("Your database is being upgraded") + "</b>",
798 QMessageBox::NoButton, this);
799 _migrationWarning->setInformativeText("<p>"
800 + tr("In order to support new features, we need to make changes to your backlog database. This may take a long while.")
802 + tr("Do not exit Quassel until the upgrade is complete!")
804 _migrationWarning->setStandardButtons(QMessageBox::NoButton);
805 _migrationWarning->show();
807 else if (!show && _migrationWarning) {
808 _migrationWarning->close();
809 _migrationWarning->deleteLater();
810 _migrationWarning = nullptr;
815 void MainWin::onExitRequested(const QString &reason)
817 if (!reason.isEmpty()) {
818 QMessageBox box(QMessageBox::Critical,
820 "<b>" + tr("Quassel encountered a fatal error and is terminated.") + "</b>",
822 box.setInformativeText("<p>" + tr("Reason:<em>") + " " + reason + "</em>");
828 void MainWin::changeActiveBufferView(bool backwards)
830 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
831 _bufferViews[_activeBufferViewIndex]->setActive(false);
834 if (!_bufferViews.count())
837 int c = _bufferViews.count();
838 while (c--) { // yes, this will reactivate the current active one if all others fail
840 if (--_activeBufferViewIndex < 0)
841 _activeBufferViewIndex = _bufferViews.count()-1;
844 if (++_activeBufferViewIndex >= _bufferViews.count())
845 _activeBufferViewIndex = 0;
848 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
849 if (dock->isHidden())
852 dock->setActive(true);
856 _activeBufferViewIndex = -1;
860 void MainWin::nextBufferView()
862 changeActiveBufferView(false);
866 void MainWin::previousBufferView()
868 changeActiveBufferView(true);
872 void MainWin::nextBuffer()
874 BufferView *view = activeBufferView();
880 void MainWin::previousBuffer()
882 BufferView *view = activeBufferView();
884 view->previousBuffer();
888 void MainWin::hideCurrentBuffer()
890 BufferView *view = activeBufferView();
892 view->hideCurrentBuffer();
896 void MainWin::showNotificationsDlg()
898 SettingsPageDlg{new NotificationsSettingsPage{}}.exec();
902 void MainWin::onConfigureNetworksTriggered()
904 SettingsPageDlg{new NetworksSettingsPage{}}.exec();
908 void MainWin::onConfigureViewsTriggered()
910 SettingsPageDlg{new BufferViewSettingsPage{}}.exec();
914 void MainWin::onLockLayoutToggled(bool lock)
916 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
917 foreach(VerticalDock *dock, docks) {
918 dock->showTitle(!lock);
921 QList<NickListDock *> nickdocks = findChildren<NickListDock *>();
922 foreach(NickListDock *nickdock, nickdocks) {
923 nickdock->setLocked(lock);
926 QList<BufferViewDock *> bufferdocks = findChildren<BufferViewDock *>();
927 foreach(BufferViewDock *bufferdock, bufferdocks) {
928 bufferdock->setLocked(lock);
931 if (Client::bufferViewManager()) {
932 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
933 config->setLocked(lock);
937 _mainToolBar->setMovable(!lock);
938 _nickToolBar->setMovable(!lock);
940 QtUiSettings().setValue("LockLayout", lock);
944 void MainWin::setupNickWidget()
947 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
948 nickDock->setObjectName("NickDock");
949 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
950 nickDock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
952 _nickListWidget = new NickListWidget(nickDock);
953 nickDock->setWidget(_nickListWidget);
955 addDockWidget(Qt::RightDockWidgetArea, nickDock);
956 _viewMenu->addAction(nickDock->toggleViewAction());
957 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
959 // See NickListDock::NickListDock();
960 // connect(nickDock->toggleViewAction(), &NickListDock::triggered, nickListWidget, &QWidget::showWidget);
962 // attach the NickListWidget to the BufferModel and the default selection
963 _nickListWidget->setModel(Client::bufferModel());
964 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
966 _nickListWidget->setVisible(false);
970 void MainWin::setupChatMonitor()
972 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
973 dock->setObjectName("ChatMonitorDock");
975 auto *filter = new ChatMonitorFilter(Client::messageModel(), this);
976 _chatMonitorView = new ChatMonitorView(filter, this);
977 _chatMonitorView->show();
978 dock->setWidget(_chatMonitorView);
981 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
982 _viewMenu->addAction(dock->toggleViewAction());
983 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
987 void MainWin::setupInputWidget()
989 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
990 dock->setObjectName("InputDock");
992 _inputWidget = new InputWidget(dock);
993 dock->setWidget(_inputWidget);
995 addDockWidget(Qt::BottomDockWidgetArea, dock);
997 _viewMenu->addAction(dock->toggleViewAction());
998 dock->toggleViewAction()->setText(tr("Show Input Line"));
1000 _inputWidget->setModel(Client::bufferModel());
1001 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1003 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
1007 void MainWin::setupTopicWidget()
1009 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
1010 dock->setObjectName("TopicDock");
1011 _topicWidget = new TopicWidget(dock);
1013 dock->setWidget(_topicWidget);
1015 _topicWidget->setModel(Client::bufferModel());
1016 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1018 connect(_topicWidget, &TopicWidget::switchedPlain, _bufferWidget, selectOverload<>(&QWidget::setFocus));
1020 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1022 _viewMenu->addAction(dock->toggleViewAction());
1023 dock->toggleViewAction()->setText(tr("Show Topic Line"));
1027 void MainWin::setupTransferWidget()
1029 auto dock = new QDockWidget(tr("Transfers"), this);
1030 dock->setObjectName("TransferDock");
1031 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
1033 auto view = new QTableView(dock); // to be replaced by the real thing
1034 view->setModel(Client::transferModel());
1035 dock->setWidget(view);
1036 dock->hide(); // hidden by default
1037 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1039 auto action = dock->toggleViewAction();
1040 action->setText(tr("Show File Transfers"));
1041 action->setIcon(icon::get("download"));
1042 action->setShortcut(QKeySequence(Qt::Key_F6));
1043 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
1044 _viewMenu->addAction(action);
1048 void MainWin::setupViewMenuTail()
1050 _viewMenu->addSeparator();
1051 _viewMenu->addAction(_fullScreenAction);
1055 void MainWin::setupTitleSetter()
1057 _titleSetter.setModel(Client::bufferModel());
1058 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1062 void MainWin::setupStatusBar()
1064 // MessageProcessor progress
1065 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1068 _coreConnectionStatusWidget->update();
1069 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1071 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1073 QtUiSettings uiSettings;
1075 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1076 showStatusbar->setChecked(enabled);
1077 enabled ? statusBar()->show() : statusBar()->hide();
1079 connect(showStatusbar, &QAction::toggled, statusBar(), &QWidget::setVisible);
1080 connect(showStatusbar, &QAction::toggled, this, &MainWin::saveStatusBarStatus);
1082 connect(Client::coreConnection(), &CoreConnection::connectionMsg, statusBar(), [statusBar = statusBar()](auto &&message) {
1083 statusBar->showMessage(message);
1088 void MainWin::setupHotList()
1090 auto *flatProxy = new FlatProxyModel(this);
1091 flatProxy->setSourceModel(Client::bufferModel());
1092 _bufferHotList = new BufferHotListFilter(flatProxy);
1096 void MainWin::saveMenuBarStatus(bool enabled)
1098 QtUiSettings uiSettings;
1099 uiSettings.setValue("ShowMenuBar", enabled);
1103 void MainWin::saveStatusBarStatus(bool enabled)
1105 QtUiSettings uiSettings;
1106 uiSettings.setValue("ShowStatusBar", enabled);
1110 void MainWin::setupSystray()
1113 _systemTray = new StatusNotifierItem(this);
1114 #elif !defined QT_NO_SYSTEMTRAYICON
1115 _systemTray = new LegacySystemTray(this);
1117 _systemTray = new SystemTray(this); // dummy
1122 void MainWin::setupToolBars()
1124 connect(_bufferWidget, selectOverload<const QModelIndex&>(&AbstractBufferContainer::currentChanged),
1125 QtUi::toolBarActionProvider(), &ToolBarActionProvider::onCurrentBufferChanged);
1126 connect(_nickListWidget, &NickListWidget::nickSelectionChanged,
1127 QtUi::toolBarActionProvider(), &ToolBarActionProvider::onNickSelectionChanged);
1130 setUnifiedTitleAndToolBarOnMac(true);
1134 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1136 _mainToolBar = new QToolBar(this);
1137 _mainToolBar->setObjectName("MainToolBar");
1139 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1140 addToolBar(_mainToolBar);
1142 if (Quassel::runMode() != Quassel::Monolithic) {
1143 ActionCollection *coll = QtUi::actionCollection("General");
1144 _mainToolBar->addAction(coll->action("ConnectCore"));
1145 _mainToolBar->addAction(coll->action("DisconnectCore"));
1148 _mainToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1150 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1151 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1154 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1156 _nickToolBar = new QToolBar(this);
1157 _nickToolBar->setObjectName("NickToolBar");
1159 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1160 _nickToolBar->setVisible(false); //default: not visible
1161 addToolBar(_nickToolBar);
1162 _nickToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1164 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1165 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1168 QtUiSettings uiSettings;
1170 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1171 _mainToolBar->setVisible(visible);
1172 connect(_mainToolBar, &QToolBar::visibilityChanged, this, &MainWin::saveMainToolBarStatus);
1176 void MainWin::saveMainToolBarStatus(bool enabled)
1179 QtUiSettings uiSettings;
1180 uiSettings.setValue("ShowMainToolBar", enabled);
1187 void MainWin::doAutoConnect()
1189 if (!Client::coreConnection()->connectToCore()) {
1190 // No autoconnect selected (or no accounts)
1191 showCoreConnectionDlg();
1196 void MainWin::connectedToCore()
1198 Q_CHECK_PTR(Client::bufferViewManager());
1199 connect(Client::bufferViewManager(), &BufferViewManager::bufferViewConfigAdded, this, selectOverload<int>(&MainWin::addBufferView));
1200 connect(Client::bufferViewManager(), &BufferViewManager::bufferViewConfigDeleted, this, &MainWin::removeBufferView);
1201 connect(Client::bufferViewManager(), &SyncableObject::initDone, this, &MainWin::loadLayout);
1203 if (Client::transferManager()) {
1204 connect(Client::transferManager(), &TransferManager::transferAdded, this, &MainWin::showNewTransferDlg);
1207 setConnectedState();
1211 void MainWin::setConnectedState()
1213 ActionCollection *coll = QtUi::actionCollection("General");
1215 coll->action("ConnectCore")->setEnabled(false);
1216 coll->action("DisconnectCore")->setEnabled(true);
1217 coll->action("ChangePassword")->setEnabled(true);
1218 coll->action("CoreInfo")->setEnabled(true);
1220 foreach(QAction *action, _fileMenu->actions()) {
1221 if (isRemoteCoreOnly(action))
1222 action->setVisible(!Client::internalCore());
1225 disconnect(Client::backlogManager(), &ClientBacklogManager::updateProgress, _msgProcessorStatusWidget, &MsgProcessorStatusWidget::setProgress);
1226 disconnect(Client::backlogManager(), &ClientBacklogManager::messagesRequested, this, &MainWin::showStatusBarMessage);
1227 disconnect(Client::backlogManager(), &ClientBacklogManager::messagesProcessed, this, &MainWin::showStatusBarMessage);
1228 if (!Client::internalCore()) {
1229 connect(Client::backlogManager(), &ClientBacklogManager::updateProgress, _msgProcessorStatusWidget, &MsgProcessorStatusWidget::setProgress);
1230 connect(Client::backlogManager(), &ClientBacklogManager::messagesRequested, this, &MainWin::showStatusBarMessage);
1231 connect(Client::backlogManager(), &ClientBacklogManager::messagesProcessed, this, &MainWin::showStatusBarMessage);
1234 // _viewMenu->setEnabled(true);
1235 if (!Client::internalCore())
1236 statusBar()->showMessage(tr("Connected to core."));
1238 statusBar()->clearMessage();
1240 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1242 systemTray()->setState(SystemTray::Active);
1244 if (Client::networkIds().isEmpty()) {
1245 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1249 // Monolithic always preselects last used buffer - Client only if the connection died
1250 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1252 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1253 if (lastUsedBufferId.isValid())
1254 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1260 void MainWin::loadLayout()
1263 int accountId = Client::currentCoreAccount().accountId().toInt();
1264 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1265 if (state.isEmpty()) {
1266 foreach(BufferViewDock *view, _bufferViews)
1268 _layoutLoaded = true;
1271 _nickListWidget->setVisible(true);
1272 restoreState(state, accountId);
1273 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1274 if (bufferViewId >= 0)
1275 changeActiveBufferView(bufferViewId);
1277 _layoutLoaded = true;
1281 void MainWin::saveLayout()
1284 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1285 if (accountId > 0) {
1286 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1287 BufferView *view = activeBufferView();
1288 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1293 void MainWin::disconnectedFromCore()
1295 // save core specific layout and remove bufferviews;
1297 _layoutLoaded = false;
1299 QVariant actionData;
1300 BufferViewDock *dock;
1301 foreach(QAction *action, _bufferViewsMenu->actions()) {
1302 actionData = action->data();
1303 if (!actionData.isValid())
1306 dock = qobject_cast<BufferViewDock *>(action->parent());
1307 if (dock && actionData.toInt() != -1) {
1308 removeAction(action);
1309 _bufferViews.removeAll(dock);
1310 dock->deleteLater();
1314 // store last active buffer
1316 BufferId lastBufId = _bufferWidget->currentBuffer();
1317 if (lastBufId.isValid()) {
1318 s.setValue("LastUsedBufferId", lastBufId.toInt());
1319 // clear the current selection
1320 Client::bufferModel()->standardSelectionModel()->clearSelection();
1322 restoreState(s.value("MainWinState").toByteArray());
1323 setDisconnectedState();
1327 void MainWin::setDisconnectedState()
1329 ActionCollection *coll = QtUi::actionCollection("General");
1330 //ui.menuCore->setEnabled(false);
1331 coll->action("ConnectCore")->setEnabled(true);
1332 coll->action("DisconnectCore")->setEnabled(false);
1333 coll->action("CoreInfo")->setEnabled(false);
1334 coll->action("ChangePassword")->setEnabled(false);
1335 //_viewMenu->setEnabled(false);
1336 statusBar()->showMessage(tr("Not connected to core."));
1337 if (_msgProcessorStatusWidget)
1338 _msgProcessorStatusWidget->setProgress(0, 0);
1340 systemTray()->setState(SystemTray::Passive);
1341 _nickListWidget->setVisible(false);
1345 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1347 Q_UNUSED(errorMessage)
1348 CoreConnectAuthDlg dlg(account);
1349 *valid = (dlg.exec() == QDialog::Accepted);
1353 void MainWin::handleNoSslInClient(bool *accepted)
1355 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1356 QMessageBox::Ignore|QMessageBox::Cancel);
1357 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1358 box.setDefaultButton(QMessageBox::Ignore);
1359 *accepted = box.exec() == QMessageBox::Ignore;
1363 void MainWin::handleNoSslInCore(bool *accepted)
1365 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1366 QMessageBox::Ignore|QMessageBox::Cancel);
1367 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1368 box.setDefaultButton(QMessageBox::Ignore);
1369 *accepted = box.exec() == QMessageBox::Ignore;
1375 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1377 QString errorString = "<ul>";
1378 foreach(const QSslError error, socket->sslErrors())
1379 errorString += QString("<li>%1</li>").arg(error.errorString());
1380 errorString += "</ul>";
1382 QMessageBox box(QMessageBox::Warning,
1383 tr("Untrusted Security Certificate"),
1384 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1385 QMessageBox::Cancel);
1386 box.setInformativeText(errorString);
1387 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1388 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1390 QMessageBox::ButtonRole role;
1393 role = box.buttonRole(box.clickedButton());
1394 if (role == QMessageBox::HelpRole) {
1395 SslInfoDlg dlg(socket);
1399 while (role == QMessageBox::HelpRole);
1401 *accepted = role == QMessageBox::AcceptRole;
1403 QMessageBox box2(QMessageBox::Warning,
1404 tr("Untrusted Security Certificate"),
1405 tr("Would you like to accept this certificate forever without being prompted?"),
1407 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1408 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1410 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1415 #endif /* HAVE_SSL */
1417 void MainWin::handleCoreConnectionError(const QString &error)
1419 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1423 void MainWin::showCoreConnectionDlg()
1426 if (dlg.exec() == QDialog::Accepted) {
1427 AccountId accId = dlg.selectedAccount();
1428 if (accId.isValid())
1429 Client::coreConnection()->connectToCore(accId);
1434 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1436 auto *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1442 void MainWin::showChannelList(NetworkId netId, const QString &channelFilters, bool listImmediately)
1444 if (!netId.isValid()) {
1445 auto *action = qobject_cast<QAction *>(sender());
1447 netId = action->data().value<NetworkId>();
1448 if (!netId.isValid()) {
1449 // We still haven't found a valid network, probably no network selected, e.g. "/list"
1450 // on the client homescreen when no networks are connected.
1451 QMessageBox box(QMessageBox::Information, tr("No network selected"),
1452 QString("<b>%1</b>").arg(tr("No network selected")),
1454 box.setInformativeText(tr("Select a network before trying to view the channel list."));
1460 auto *channelListDlg = new ChannelListDlg(this);
1461 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1462 channelListDlg->setNetwork(netId);
1463 if (!channelFilters.isEmpty()) {
1464 channelListDlg->setChannelFilters(channelFilters);
1466 if (listImmediately) {
1467 channelListDlg->requestSearch();
1469 channelListDlg->show();
1473 void MainWin::showNetworkConfig(NetworkId netId)
1475 SettingsPageDlg dlg{new NetworksSettingsPage{}};
1476 if (netId.isValid())
1477 qobject_cast<NetworksSettingsPage *>(dlg.currentPage())->bufferList_Open(netId);
1482 void MainWin::showIgnoreList(QString newRule)
1484 SettingsPageDlg dlg{new IgnoreListSettingsPage{}};
1485 // prepare config dialog for new rule
1486 if (!newRule.isEmpty())
1487 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1492 void MainWin::showCoreInfoDlg()
1494 CoreInfoDlg{}.exec();
1498 void MainWin::showAwayLog()
1502 auto *filter = new AwayLogFilter(Client::messageModel());
1503 _awayLog = new AwayLogView(filter, nullptr);
1504 filter->setParent(_awayLog);
1505 connect(_awayLog, &QObject::destroyed, this, &MainWin::awayLogDestroyed);
1506 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1511 void MainWin::awayLogDestroyed()
1517 void MainWin::showSettingsDlg()
1519 auto *dlg = new SettingsDlg();
1521 //Category: Interface
1522 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1523 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1524 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1525 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1526 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1527 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1528 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1529 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1531 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1533 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1534 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1535 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1536 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1539 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1540 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1541 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1542 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1543 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1544 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1546 // Category: Remote Cores
1547 if (Quassel::runMode() != Quassel::Monolithic) {
1548 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1549 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1556 void MainWin::showAboutDlg()
1562 void MainWin::showShortcutsDlg()
1565 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed);
1566 foreach(KActionCollection *coll, QtUi::actionCollections())
1567 dlg.addCollection(coll, coll->property("Category").toString());
1568 dlg.configure(true);
1570 SettingsPageDlg{new ShortcutsSettingsPage{QtUi::actionCollections()}}.exec();
1575 void MainWin::showNewTransferDlg(const QUuid &transferId)
1577 auto transfer = Client::transferManager()->transfer(transferId);
1579 if (transfer->status() == Transfer::Status::New) {
1580 auto *dlg = new ReceiveFileDlg(transfer, this);
1585 qWarning() << "Unknown transfer ID" << transferId;
1590 void MainWin::onFullScreenToggled()
1592 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1593 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1596 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1598 if (_fullScreenAction->isChecked())
1599 setWindowState(windowState() | Qt::WindowFullScreen);
1601 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);
1628 void MainWin::moveEvent(QMoveEvent *event)
1630 if (!(windowState() & Qt::WindowMaximized))
1631 _normalPos = event->pos();
1633 QMainWindow::moveEvent(event);
1637 void MainWin::resizeEvent(QResizeEvent *event)
1639 if (!(windowState() & Qt::WindowMaximized))
1640 _normalSize = event->size();
1642 QMainWindow::resizeEvent(event);
1646 void MainWin::closeEvent(QCloseEvent *event)
1649 auto *app = qobject_cast<QtUiApplication *> qApp;
1651 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1652 // This messes up MainWinState/MainWinHidden save/restore.
1653 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1654 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1655 QtUi::hideMainWidget();
1658 else if(!_aboutToQuit) {
1659 _aboutToQuit = true;
1661 Quassel::instance()->quit();
1669 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1673 bool hasFocus = QApplication::activeWindow() != nullptr;
1675 for (int i = start; i <= end; i++) {
1676 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1677 if (!idx.isValid()) {
1678 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1681 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1682 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1685 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1686 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1688 // check if bufferId belongs to the shown chatlists
1689 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1690 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1693 // check if it's the buffer currently displayed
1694 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1697 // only show notifications for higlights or queries
1698 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1701 // and of course: don't notify for ignored messages
1702 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1705 // seems like we have a legit notification candidate!
1706 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1707 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1708 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1709 AbstractNotificationBackend::NotificationType type;
1711 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1712 type = AbstractNotificationBackend::PrivMsg;
1713 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1714 type = AbstractNotificationBackend::PrivMsgFocused;
1715 else if (flags & Message::Highlight && !hasFocus)
1716 type = AbstractNotificationBackend::Highlight;
1718 type = AbstractNotificationBackend::HighlightFocused;
1720 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1725 void MainWin::currentBufferChanged(BufferId buffer)
1727 if (buffer.isValid())
1728 Client::instance()->markBufferAsRead(buffer);
1732 void MainWin::clientNetworkCreated(NetworkId id)
1734 const Network *net = Client::network(id);
1735 auto *act = new QAction(net->networkName(), this);
1736 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1737 act->setData(QVariant::fromValue<NetworkId>(id));
1738 connect(net, &SyncableObject::updatedRemotely, this, &MainWin::clientNetworkUpdated);
1739 connect(act, &QAction::triggered, this, &MainWin::connectOrDisconnectFromNet);
1741 QAction *beforeAction = nullptr;
1742 foreach(QAction *action, _networksMenu->actions()) {
1743 if (!action->data().isValid()) // ignore stock actions
1745 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1746 beforeAction = action;
1750 _networksMenu->insertAction(beforeAction, act);
1754 void MainWin::clientNetworkUpdated()
1756 const auto *net = qobject_cast<const Network *>(sender());
1760 auto *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1764 action->setText(net->networkName());
1766 switch (net->connectionState()) {
1767 case Network::Initialized:
1768 action->setIcon(icon::get("network-connect"));
1769 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1770 if (!bufferWidget()->currentBuffer().isValid()) {
1771 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1772 if (idx.isValid()) {
1773 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1774 Client::bufferModel()->switchToBuffer(statusBufferId);
1778 case Network::Disconnected:
1779 action->setIcon(icon::get("network-disconnect"));
1782 action->setIcon(icon::get("network-wired"));
1787 void MainWin::clientNetworkRemoved(NetworkId id)
1789 auto *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1793 action->deleteLater();
1797 void MainWin::connectOrDisconnectFromNet()
1799 auto *act = qobject_cast<QAction *>(sender());
1801 const Network *net = Client::network(act->data().value<NetworkId>());
1803 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1804 else net->requestDisconnect();
1808 void MainWin::onFormatApplyColorTriggered()
1813 _inputWidget->applyFormatActiveColor();
1817 void MainWin::onFormatApplyColorFillTriggered()
1822 _inputWidget->applyFormatActiveColorFill();
1826 void MainWin::onFormatClearTriggered()
1831 _inputWidget->clearFormat();
1835 void MainWin::onFormatBoldTriggered()
1840 _inputWidget->toggleFormatBold();
1844 void MainWin::onFormatItalicTriggered()
1849 _inputWidget->toggleFormatItalic();
1853 void MainWin::onFormatUnderlineTriggered()
1858 _inputWidget->toggleFormatUnderline();
1862 void MainWin::onJumpHotBufferTriggered()
1864 if (!_bufferHotList->rowCount())
1867 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1870 void MainWin::onBufferSearchTriggered()
1872 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1873 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1877 _bufferViews[_activeBufferViewIndex]->activateFilter();
1881 void MainWin::onJumpKey()
1883 auto *action = qobject_cast<QAction *>(sender());
1884 if (!action || !Client::bufferModel())
1886 int idx = action->property("Index").toInt();
1888 if (_jumpKeyMap.isEmpty())
1889 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1891 if (!_jumpKeyMap.contains(idx))
1894 BufferId buffer = _jumpKeyMap.value(idx);
1895 if (buffer.isValid())
1896 Client::bufferModel()->switchToBuffer(buffer);
1900 void MainWin::bindJumpKey()
1902 auto *action = qobject_cast<QAction *>(sender());
1903 if (!action || !Client::bufferModel())
1905 int idx = action->property("Index").toInt();
1907 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1908 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1912 void MainWin::onDebugNetworkModelTriggered()
1914 auto *view = new QTreeView;
1915 view->setAttribute(Qt::WA_DeleteOnClose);
1916 view->setWindowTitle("Debug NetworkModel View");
1917 view->setModel(Client::networkModel());
1918 view->setColumnWidth(0, 250);
1919 view->setColumnWidth(1, 250);
1920 view->setColumnWidth(2, 80);
1921 view->resize(610, 300);
1926 void MainWin::onDebugHotListTriggered()
1928 _bufferHotList->invalidate();
1929 _bufferHotList->sort(0, Qt::DescendingOrder);
1931 auto *view = new QTreeView;
1932 view->setAttribute(Qt::WA_DeleteOnClose);
1933 view->setModel(_bufferHotList);
1938 void MainWin::onDebugBufferViewOverlayTriggered()
1940 auto *overlay = new DebugBufferViewOverlay(nullptr);
1941 overlay->setAttribute(Qt::WA_DeleteOnClose);
1946 void MainWin::onDebugMessageModelTriggered()
1948 auto *view = new QTableView(nullptr);
1949 auto *filter = new DebugMessageModelFilter(view);
1950 filter->setSourceModel(Client::messageModel());
1951 view->setModel(filter);
1952 view->setAttribute(Qt::WA_DeleteOnClose, true);
1953 view->verticalHeader()->hide();
1954 view->horizontalHeader()->setStretchLastSection(true);
1959 void MainWin::onDebugLogTriggered()
1961 auto dlg = new DebugLogDlg(this); // will be deleted on close
1965 void MainWin::onShowResourceTreeTriggered()
1967 auto dlg = new ResourceTreeDlg(this); // will be deleted on close
1971 void MainWin::showStatusBarMessage(const QString &message)
1973 statusBar()->showMessage(message, 10000);