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>
34 # include <KShortcutsDialog>
35 # include <KStatusBar>
36 # include <KToggleFullScreenAction>
41 # include <KConfigWidgets/KStandardAction>
42 # include <KXmlGui/KHelpMenu>
43 # include <KXmlGui/KShortcutsDialog>
44 # include <KXmlGui/KToolBar>
45 # include <KWidgetsAddons/KToggleFullScreenAction>
53 #include "awaylogfilter.h"
54 #include "awaylogview.h"
56 #include "actioncollection.h"
57 #include "bufferhotlistfilter.h"
58 #include "buffermodel.h"
59 #include "bufferview.h"
60 #include "bufferviewoverlay.h"
61 #include "bufferviewoverlayfilter.h"
62 #include "bufferwidget.h"
63 #include "channellistdlg.h"
64 #include "chatlinemodel.h"
65 #include "chatmonitorfilter.h"
66 #include "chatmonitorview.h"
69 #include "clientbacklogmanager.h"
70 #include "clientbufferviewconfig.h"
71 #include "clientbufferviewmanager.h"
72 #include "clientignorelistmanager.h"
73 #include "clienttransfer.h"
74 #include "clienttransfermanager.h"
75 #include "coreconfigwizard.h"
76 #include "coreconnectdlg.h"
77 #include "coreconnection.h"
78 #include "coreconnectionstatuswidget.h"
79 #include "coreinfodlg.h"
80 #include "contextmenuactionprovider.h"
81 #include "debugbufferviewoverlay.h"
82 #include "debuglogdlg.h"
83 #include "debugmessagemodelfilter.h"
84 #include "flatproxymodel.h"
86 #include "inputwidget.h"
87 #include "irclistmodel.h"
88 #include "ircconnectionwizard.h"
89 #include "legacysystemtray.h"
90 #include "msgprocessorstatuswidget.h"
91 #include "nicklistwidget.h"
92 #include "passwordchangedlg.h"
93 #include "qtuiapplication.h"
94 #include "qtuimessageprocessor.h"
95 #include "qtuisettings.h"
96 #include "qtuistyle.h"
97 #include "receivefiledlg.h"
98 #include "settingsdlg.h"
99 #include "settingspagedlg.h"
100 #include "statusnotifieritem.h"
101 #include "toolbaractionprovider.h"
102 #include "topicwidget.h"
103 #include "transfermodel.h"
104 #include "verticaldock.h"
107 # ifdef HAVE_QTMULTIMEDIA
108 # include "qtmultimedianotificationbackend.h"
110 # include "systraynotificationbackend.h"
111 # include "taskbarnotificationbackend.h"
113 # include "knotificationbackend.h"
114 #endif /* HAVE_KDE */
115 #include "systrayanimationnotificationbackend.h"
119 # include "snorenotificationbackend.h"
123 # include "sslinfodlg.h"
126 #ifdef HAVE_NOTIFICATION_CENTER
127 #include "osxnotificationbackend.h"
131 #include "dockmanagernotificationbackend.h"
134 #include "settingspages/aliasessettingspage.h"
135 #include "settingspages/appearancesettingspage.h"
136 #include "settingspages/backlogsettingspage.h"
137 #include "settingspages/bufferviewsettingspage.h"
138 #include "settingspages/chatmonitorsettingspage.h"
139 #include "settingspages/chatviewsettingspage.h"
140 #include "settingspages/chatviewcolorsettingspage.h"
141 #include "settingspages/connectionsettingspage.h"
142 #include "settingspages/coreaccountsettingspage.h"
143 #include "settingspages/coreconnectionsettingspage.h"
144 #include <settingspages/corehighlightsettingspage.h>
145 #include "settingspages/dccsettingspage.h"
146 #include "settingspages/highlightsettingspage.h"
147 #include "settingspages/identitiessettingspage.h"
148 #include "settingspages/ignorelistsettingspage.h"
149 #include "settingspages/inputwidgetsettingspage.h"
150 #include "settingspages/itemviewsettingspage.h"
151 #include "settingspages/networkssettingspage.h"
152 #include "settingspages/notificationssettingspage.h"
153 #include "settingspages/topicwidgetsettingspage.h"
156 # include "settingspages/shortcutssettingspage.h"
160 # include "settingspages/sonnetsettingspage.h"
164 MainWin::MainWin(QWidget *parent)
166 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
168 : QMainWindow(parent),
170 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
171 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
174 _layoutLoaded(false),
175 _activeBufferViewIndex(-1),
178 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
180 QtUiSettings uiSettings;
181 QString style = uiSettings.value("Style", QString()).toString();
182 if (!style.isEmpty()) {
183 QApplication::setStyle(style);
186 QApplication::setQuitOnLastWindowClosed(false);
188 setWindowTitle("Quassel IRC");
189 setWindowIconText("Quassel IRC");
190 // Set the default icon for all windows
191 QApplication::setWindowIcon(icon::get("quassel"));
198 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
199 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
200 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
201 SLOT(messagesInserted(const QModelIndex &, int, int)));
202 connect(GraphicalUi::contextMenuActionProvider(),
203 SIGNAL(showChannelList(NetworkId,QString,bool)),
204 SLOT(showChannelList(NetworkId,QString,bool)));
205 connect(Client::instance(),
206 SIGNAL(showChannelList(NetworkId,QString,bool)),
207 SLOT(showChannelList(NetworkId,QString,bool)));
208 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showNetworkConfig(NetworkId)), SLOT(showNetworkConfig(NetworkId)));
209 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
210 connect(Client::instance(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
211 connect(Client::instance(), SIGNAL(dbUpgradeInProgress(bool)), SLOT(showMigrationWarning(bool)));
212 connect(Client::instance(), SIGNAL(exitRequested(QString)), SLOT(onExitRequested(QString)));
214 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList, QVariantList)), SLOT(showCoreConfigWizard(QVariantList, QVariantList)));
215 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
216 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
217 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
218 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
220 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
224 setDockNestingEnabled(true);
225 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
226 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
227 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
228 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
230 // Order is sometimes important
234 // setupTransferWidget(); not ready yet
246 _bufferWidget->setFocusProxy(_inputWidget);
247 _chatMonitorView->setFocusProxy(_inputWidget);
250 # ifdef HAVE_QTMULTIMEDIA
251 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
253 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
255 QtUi::registerNotificationBackend(new KNotificationBackend(this));
256 #endif /* HAVE_KDE */
259 #ifndef QT_NO_SYSTEMTRAYICON
260 QtUi::registerNotificationBackend(new SystrayAnimationNotificationBackend(this));
263 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
264 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
265 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
268 #ifdef HAVE_NOTIFICATION_CENTER
269 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
273 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
276 // we assume that at this point, all configurable actions are defined!
277 QtUi::loadShortcuts();
279 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
281 setDisconnectedState(); // Disable menus and stuff
284 setAutoSaveSettings();
287 // restore mainwin state
289 restoreStateFromSettings(s);
291 // restore locked state of docks
292 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
294 Quassel::registerQuitHandler([this]() {
296 saveStateToSettings(s);
298 // Close all open dialogs and the MainWin, so we can safely kill the Client instance afterwards
299 // Note: This does not quit the application, as quitOnLastWindowClosed is set to false.
300 // We rely on another quit handler to be registered that actually quits the application.
301 qApp->closeAllWindows();
304 QTimer::singleShot(0, this, SLOT(doAutoConnect()));
308 void MainWin::saveStateToSettings(UiSettings &s)
310 s.setValue("MainWinSize", _normalSize);
311 s.setValue("MainWinPos", _normalPos);
312 s.setValue("MainWinState", saveState());
313 s.setValue("MainWinGeometry", saveGeometry());
314 s.setValue("MainWinMinimized", isMinimized());
315 s.setValue("MainWinMaximized", isMaximized());
316 s.setValue("MainWinHidden", !isVisible());
317 BufferId lastBufId = Client::bufferModel()->currentBuffer();
318 if (lastBufId.isValid())
319 s.setValue("LastUsedBufferId", lastBufId.toInt());
322 saveAutoSaveSettings();
327 void MainWin::restoreStateFromSettings(UiSettings &s)
329 _normalSize = s.value("MainWinSize", size()).toSize();
330 _normalPos = s.value("MainWinPos", pos()).toPoint();
331 bool maximized = s.value("MainWinMaximized", false).toBool();
334 restoreGeometry(s.value("MainWinGeometry").toByteArray());
337 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
342 restoreState(s.value("MainWinState").toByteArray());
348 if ((Quassel::isOptionSet("hidewindow")
349 || s.value("MainWinHidden").toBool())
350 && _systemTray->isSystemTrayAvailable())
351 QtUi::hideMainWidget();
352 else if (s.value("MainWinMinimized").toBool())
360 QMenu *MainWin::createPopupMenu()
362 QMenu *popupMenu = QMainWindow::createPopupMenu();
363 popupMenu->addSeparator();
364 ActionCollection *coll = QtUi::actionCollection("General");
365 popupMenu->addAction(coll->action("ToggleMenuBar"));
370 void MainWin::updateIcon()
373 if (Client::isConnected())
374 icon = icon::get("quassel");
376 icon = icon::get("inactive-quassel");
381 void MainWin::setupActions()
383 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
385 coll->addAction("ConnectCore", new Action(icon::get("connect-quassel"), tr("&Connect to Core..."), coll,
386 this, SLOT(showCoreConnectionDlg())));
387 coll->addAction("DisconnectCore", new Action(icon::get("disconnect-quassel"), tr("&Disconnect from Core"), coll,
388 Client::instance(), SLOT(disconnectFromCore())));
389 coll->addAction("ChangePassword", new Action(icon::get("dialog-password"), tr("Change &Password..."), coll,
390 this, SLOT(showPasswordChangeDlg())));
391 coll->addAction("CoreInfo", new Action(icon::get("help-about"), tr("Core &Info..."), coll,
392 this, SLOT(showCoreInfoDlg())));
393 coll->addAction("ConfigureNetworks", new Action(icon::get("configure"), tr("Configure &Networks..."), coll,
394 this, SLOT(on_actionConfigureNetworks_triggered())));
395 // QKeySequence::Quit was added in Qt 4.6, and could be used instead. However, that key
396 // sequence is empty by default on Windows, which would remove Ctrl-Q to quit. It may be best
397 // to just keep it this way.
399 // See https://doc.qt.io/qt-5/qkeysequence.html
400 coll->addAction("Quit", new Action(icon::get("application-exit"), tr("&Quit"), coll,
401 Quassel::instance(), SLOT(quit()), Qt::CTRL + Qt::Key_Q));
404 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
405 this, SLOT(on_actionConfigureViews_triggered())));
407 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
408 lockAct->setCheckable(true);
409 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
411 coll->addAction("ToggleSearchBar", new Action(icon::get("edit-find"), tr("Show &Search Bar"), coll,
412 0, 0, QKeySequence::Find))->setCheckable(true);
413 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
414 this, SLOT(showAwayLog())));
415 coll->addAction("ToggleMenuBar", new Action(icon::get("show-menu"), tr("Show &Menubar"), coll,
416 0, 0))->setCheckable(true);
418 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
419 0, 0))->setCheckable(true);
422 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
424 _fullScreenAction = new Action(icon::get("view-fullscreen"), tr("&Full Screen Mode"), coll,
425 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
426 _fullScreenAction->setCheckable(true);
427 coll->addAction("ToggleFullScreen", _fullScreenAction);
431 QAction *configureShortcutsAct = new Action(icon::get("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
432 this, SLOT(showShortcutsDlg()));
433 configureShortcutsAct->setMenuRole(QAction::NoRole);
434 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
437 QAction *configureQuasselAct = new Action(icon::get("configure"), tr("&Configure Quassel..."), coll,
438 this, SLOT(showSettingsDlg()));
439 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
441 QAction *configureQuasselAct = new Action(icon::get("configure"), tr("&Configure Quassel..."), coll,
442 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
444 coll->addAction("ConfigureQuassel", configureQuasselAct);
447 QAction *aboutQuasselAct = new Action(icon::get("quassel"), tr("&About Quassel"), coll,
448 this, SLOT(showAboutDlg()));
449 aboutQuasselAct->setMenuRole(QAction::AboutRole);
450 coll->addAction("AboutQuassel", aboutQuasselAct);
452 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
453 qApp, SLOT(aboutQt()));
454 aboutQtAct->setMenuRole(QAction::AboutQtRole);
455 coll->addAction("AboutQt", aboutQtAct);
456 coll->addAction("DebugNetworkModel", new Action(icon::get("tools-report-bug"), tr("Debug &NetworkModel"), coll,
457 this, SLOT(on_actionDebugNetworkModel_triggered())));
458 coll->addAction("DebugBufferViewOverlay", new Action(icon::get("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
459 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
460 coll->addAction("DebugMessageModel", new Action(icon::get("tools-report-bug"), tr("Debug &MessageModel"), coll,
461 this, SLOT(on_actionDebugMessageModel_triggered())));
462 coll->addAction("DebugHotList", new Action(icon::get("tools-report-bug"), tr("Debug &HotList"), coll,
463 this, SLOT(on_actionDebugHotList_triggered())));
464 coll->addAction("DebugLog", new Action(icon::get("tools-report-bug"), tr("Debug &Log"), coll,
465 this, SLOT(on_actionDebugLog_triggered())));
466 coll->addAction("ReloadStyle", new Action(icon::get("view-refresh"), tr("Reload Stylesheet"), coll,
467 QtUi::style(), SLOT(reload()), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_R)));
469 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
470 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
473 coll = QtUi::actionCollection("TextFormat", tr("Text formatting"));
475 coll->addAction("FormatApplyColor", new Action(
476 icon::get("format-text-color"), tr("Apply foreground color"), coll,
477 this, SLOT(on_inputFormatApplyColor_triggered()),
478 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_G)));
480 coll->addAction("FormatApplyColorFill", new Action(
481 icon::get("format-fill-color"), tr("Apply background color"), coll,
482 this, SLOT(on_inputFormatApplyColorFill_triggered()),
483 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B)));
485 coll->addAction("FormatClear", new Action(
486 icon::get("edit-clear"), tr("Clear formatting"), coll,
487 this, SLOT(on_inputFormatClear_triggered()),
488 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C)));
490 coll->addAction("FormatBold", new Action(
491 icon::get("format-text-bold"), tr("Toggle bold"), coll,
492 this, SLOT(on_inputFormatBold_triggered()),
493 QKeySequence::Bold));
495 coll->addAction("FormatItalic", new Action(
496 icon::get("format-text-italic"), tr("Toggle italics"), coll,
497 this, SLOT(on_inputFormatItalic_triggered()),
498 QKeySequence::Italic));
500 coll->addAction("FormatUnderline", new Action(
501 icon::get("format-text-underline"), tr("Toggle underline"), coll,
502 this, SLOT(on_inputFormatUnderline_triggered()), QKeySequence::Underline));
505 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
507 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
508 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
510 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
511 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
515 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
516 const int jumpModifier = Qt::ControlModifier;
518 const int bindModifier = Qt::ControlModifier;
519 const int jumpModifier = Qt::AltModifier;
522 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
523 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
524 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
525 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
526 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
527 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
528 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
529 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
530 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
531 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
532 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
533 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
534 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
535 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
536 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
537 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
538 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
539 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
540 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
541 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
543 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
544 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
545 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
546 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
547 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
548 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
549 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
550 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
551 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
552 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
553 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
554 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
555 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
556 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
557 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
558 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
559 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
560 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
561 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
562 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
565 coll->addAction("NextBufferView", new Action(icon::get("go-next-view"), tr("Activate Next Chat List"), coll,
566 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
567 coll->addAction("PreviousBufferView", new Action(icon::get("go-previous-view"), tr("Activate Previous Chat List"), coll,
568 this, SLOT(previousBufferView()), QKeySequence::Back));
569 coll->addAction("NextBuffer", new Action(icon::get("go-down"), tr("Go to Next Chat"), coll,
570 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
571 coll->addAction("PreviousBuffer", new Action(icon::get("go-up"), tr("Go to Previous Chat"), coll,
572 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
576 void MainWin::setupMenus()
578 ActionCollection *coll = QtUi::actionCollection("General");
580 _fileMenu = menuBar()->addMenu(tr("&File"));
582 static const QStringList coreActions = QStringList()
583 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
586 foreach(QString actionName, coreActions) {
587 coreAction = coll->action(actionName);
588 _fileMenu->addAction(coreAction);
589 flagRemoteCoreOnly(coreAction);
591 flagRemoteCoreOnly(_fileMenu->addSeparator());
593 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
594 _networksMenu->addAction(coll->action("ConfigureNetworks"));
595 _networksMenu->addSeparator();
596 _fileMenu->addSeparator();
597 _fileMenu->addAction(coll->action("Quit"));
599 _viewMenu = menuBar()->addMenu(tr("&View"));
600 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
601 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
602 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
603 _viewMenu->addSeparator();
605 _viewMenu->addAction(coll->action("ToggleMenuBar"));
606 _viewMenu->addAction(coll->action("ToggleStatusBar"));
607 _viewMenu->addAction(coll->action("ToggleSearchBar"));
609 coreAction = coll->action("ShowAwayLog");
610 flagRemoteCoreOnly(coreAction);
611 _viewMenu->addAction(coreAction);
613 _viewMenu->addSeparator();
614 _viewMenu->addAction(coll->action("LockLayout"));
616 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
618 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
619 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
621 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
623 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
626 _helpMenu = menuBar()->addMenu(tr("&Help"));
628 _helpMenu->addAction(coll->action("AboutQuassel"));
630 _helpMenu->addAction(coll->action("AboutQt"));
632 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
634 _helpMenu->addSeparator();
635 _helpDebugMenu = _helpMenu->addMenu(icon::get("tools-report-bug"), tr("Debug"));
636 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
637 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
638 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
639 _helpDebugMenu->addAction(coll->action("DebugHotList"));
640 _helpDebugMenu->addAction(coll->action("DebugLog"));
641 _helpDebugMenu->addSeparator();
642 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
645 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
647 QtUiSettings uiSettings;
648 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
649 showMenuBar->setChecked(enabled);
650 enabled ? menuBar()->show() : menuBar()->hide();
652 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
653 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
657 void MainWin::setupBufferWidget()
659 _bufferWidget = new BufferWidget(this);
660 _bufferWidget->setModel(Client::bufferModel());
661 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
662 setCentralWidget(_bufferWidget);
666 void MainWin::addBufferView(int bufferViewConfigId)
668 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
672 void MainWin::addBufferView(ClientBufferViewConfig *config)
677 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
678 BufferViewDock *dock = new BufferViewDock(config, this);
680 //create the view and initialize it's filter
681 BufferView *view = new BufferView(dock);
682 view->setFilteredModel(Client::bufferModel(), config);
683 view->installEventFilter(_inputWidget); // for key presses
685 Client::bufferModel()->synchronizeView(view);
687 dock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
689 dock->setWidget(view);
690 dock->setVisible(_layoutLoaded); // don't show before state has been restored
692 addDockWidget(Qt::LeftDockWidgetArea, dock);
693 _bufferViewsMenu->addAction(dock->toggleViewAction());
695 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
696 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
697 _bufferViews.append(dock);
699 if (!activeBufferView())
704 void MainWin::removeBufferView(int bufferViewConfigId)
707 BufferViewDock *dock;
708 foreach(QAction *action, _bufferViewsMenu->actions()) {
709 actionData = action->data();
710 if (!actionData.isValid())
713 dock = qobject_cast<BufferViewDock *>(action->parent());
714 if (dock && actionData.toInt() == bufferViewConfigId) {
715 removeAction(action);
716 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
717 _bufferViews.removeAll(dock);
719 if (dock->isActive()) {
720 dock->setActive(false);
721 _activeBufferViewIndex = -1;
731 void MainWin::bufferViewToggled(bool enabled)
733 if (!enabled && !isMinimized()) {
734 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
735 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
738 QAction *action = qobject_cast<QAction *>(sender());
740 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
743 // Make sure we don't toggle backlog fetch for a view we've already removed
744 if (!_bufferViews.contains(dock))
748 Client::bufferViewOverlay()->addView(dock->bufferViewId());
750 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
754 void MainWin::bufferViewVisibilityChanged(bool visible)
757 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
759 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
764 BufferView *MainWin::allBuffersView() const
766 // "All Buffers" is always the first dock created
767 if (_bufferViews.count() > 0)
768 return _bufferViews[0]->bufferView();
773 BufferView *MainWin::activeBufferView() const
775 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
777 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
778 return dock->isActive() ? dock->bufferView() : 0;
782 void MainWin::changeActiveBufferView(int bufferViewId)
784 if (bufferViewId < 0)
787 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
788 _bufferViews[_activeBufferViewIndex]->setActive(false);
789 _activeBufferViewIndex = -1;
792 for (int i = 0; i < _bufferViews.count(); i++) {
793 BufferViewDock *dock = _bufferViews.at(i);
794 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
795 _activeBufferViewIndex = i;
796 dock->setActive(true);
801 nextBufferView(); // fallback
805 void MainWin::showPasswordChangeDlg()
807 if(Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
808 PasswordChangeDlg{}.exec();
811 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
812 tr("<b>Your Quassel Core does not support this feature</b>"),
814 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
820 void MainWin::showMigrationWarning(bool show)
822 if (show && !_migrationWarning) {
823 _migrationWarning = new QMessageBox(QMessageBox::Information,
825 "<b>" + tr("Your database is being upgraded") + "</b>",
826 QMessageBox::NoButton, this);
827 _migrationWarning->setInformativeText("<p>"
828 + tr("In order to support new features, we need to make changes to your backlog database. This may take a long while.")
830 + tr("Do not exit Quassel until the upgrade is complete!")
832 _migrationWarning->setStandardButtons(QMessageBox::NoButton);
833 _migrationWarning->show();
835 else if (!show && _migrationWarning) {
836 _migrationWarning->close();
837 _migrationWarning->deleteLater();
838 _migrationWarning = nullptr;
843 void MainWin::onExitRequested(const QString &reason)
845 if (!reason.isEmpty()) {
846 QMessageBox box(QMessageBox::Critical,
848 "<b>" + tr("Quassel encountered a fatal error and is terminated.") + "</b>",
850 box.setInformativeText("<p>" + tr("Reason:<em>") + " " + reason + "</em>");
856 void MainWin::changeActiveBufferView(bool backwards)
858 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
859 _bufferViews[_activeBufferViewIndex]->setActive(false);
862 if (!_bufferViews.count())
865 int c = _bufferViews.count();
866 while (c--) { // yes, this will reactivate the current active one if all others fail
868 if (--_activeBufferViewIndex < 0)
869 _activeBufferViewIndex = _bufferViews.count()-1;
872 if (++_activeBufferViewIndex >= _bufferViews.count())
873 _activeBufferViewIndex = 0;
876 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
877 if (dock->isHidden())
880 dock->setActive(true);
884 _activeBufferViewIndex = -1;
888 void MainWin::nextBufferView()
890 changeActiveBufferView(false);
894 void MainWin::previousBufferView()
896 changeActiveBufferView(true);
900 void MainWin::nextBuffer()
902 BufferView *view = activeBufferView();
908 void MainWin::previousBuffer()
910 BufferView *view = activeBufferView();
912 view->previousBuffer();
916 void MainWin::hideCurrentBuffer()
918 BufferView *view = activeBufferView();
920 view->hideCurrentBuffer();
924 void MainWin::showNotificationsDlg()
926 SettingsPageDlg{new NotificationsSettingsPage{}}.exec();
930 void MainWin::on_actionConfigureNetworks_triggered()
932 SettingsPageDlg{new NetworksSettingsPage{}}.exec();
936 void MainWin::on_actionConfigureViews_triggered()
938 SettingsPageDlg{new BufferViewSettingsPage{}}.exec();
942 void MainWin::on_actionLockLayout_toggled(bool lock)
944 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
945 foreach(VerticalDock *dock, docks) {
946 dock->showTitle(!lock);
949 QList<NickListDock *> nickdocks = findChildren<NickListDock *>();
950 foreach(NickListDock *nickdock, nickdocks) {
951 nickdock->setLocked(lock);
954 QList<BufferViewDock *> bufferdocks = findChildren<BufferViewDock *>();
955 foreach(BufferViewDock *bufferdock, bufferdocks) {
956 bufferdock->setLocked(lock);
959 if (Client::bufferViewManager()) {
960 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
961 config->setLocked(lock);
965 _mainToolBar->setMovable(!lock);
966 _nickToolBar->setMovable(!lock);
968 QtUiSettings().setValue("LockLayout", lock);
972 void MainWin::setupNickWidget()
975 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
976 nickDock->setObjectName("NickDock");
977 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
978 nickDock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
980 _nickListWidget = new NickListWidget(nickDock);
981 nickDock->setWidget(_nickListWidget);
983 addDockWidget(Qt::RightDockWidgetArea, nickDock);
984 _viewMenu->addAction(nickDock->toggleViewAction());
985 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
987 // See NickListDock::NickListDock();
988 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
990 // attach the NickListWidget to the BufferModel and the default selection
991 _nickListWidget->setModel(Client::bufferModel());
992 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
994 _nickListWidget->setVisible(false);
998 void MainWin::setupChatMonitor()
1000 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
1001 dock->setObjectName("ChatMonitorDock");
1003 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
1004 _chatMonitorView = new ChatMonitorView(filter, this);
1005 _chatMonitorView->show();
1006 dock->setWidget(_chatMonitorView);
1009 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1010 _viewMenu->addAction(dock->toggleViewAction());
1011 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
1015 void MainWin::setupInputWidget()
1017 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
1018 dock->setObjectName("InputDock");
1020 _inputWidget = new InputWidget(dock);
1021 dock->setWidget(_inputWidget);
1023 addDockWidget(Qt::BottomDockWidgetArea, dock);
1025 _viewMenu->addAction(dock->toggleViewAction());
1026 dock->toggleViewAction()->setText(tr("Show Input Line"));
1028 _inputWidget->setModel(Client::bufferModel());
1029 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1031 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
1033 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
1037 void MainWin::setupTopicWidget()
1039 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
1040 dock->setObjectName("TopicDock");
1041 _topicWidget = new TopicWidget(dock);
1043 dock->setWidget(_topicWidget);
1045 _topicWidget->setModel(Client::bufferModel());
1046 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1048 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1050 _viewMenu->addAction(dock->toggleViewAction());
1051 dock->toggleViewAction()->setText(tr("Show Topic Line"));
1055 void MainWin::setupTransferWidget()
1057 auto dock = new QDockWidget(tr("Transfers"), this);
1058 dock->setObjectName("TransferDock");
1059 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
1061 auto view = new QTableView(dock); // to be replaced by the real thing
1062 view->setModel(Client::transferModel());
1063 dock->setWidget(view);
1064 dock->hide(); // hidden by default
1065 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1067 auto action = dock->toggleViewAction();
1068 action->setText(tr("Show File Transfers"));
1069 action->setIcon(icon::get("download"));
1070 action->setShortcut(QKeySequence(Qt::Key_F6));
1071 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
1072 _viewMenu->addAction(action);
1076 void MainWin::setupViewMenuTail()
1078 _viewMenu->addSeparator();
1079 _viewMenu->addAction(_fullScreenAction);
1083 void MainWin::setupTitleSetter()
1085 _titleSetter.setModel(Client::bufferModel());
1086 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1090 void MainWin::setupStatusBar()
1092 // MessageProcessor progress
1093 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1096 _coreConnectionStatusWidget->update();
1097 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1099 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1101 QtUiSettings uiSettings;
1103 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1104 showStatusbar->setChecked(enabled);
1105 enabled ? statusBar()->show() : statusBar()->hide();
1107 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1108 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1110 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1114 void MainWin::setupHotList()
1116 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1117 flatProxy->setSourceModel(Client::bufferModel());
1118 _bufferHotList = new BufferHotListFilter(flatProxy);
1122 void MainWin::saveMenuBarStatus(bool enabled)
1124 QtUiSettings uiSettings;
1125 uiSettings.setValue("ShowMenuBar", enabled);
1129 void MainWin::saveStatusBarStatus(bool enabled)
1131 QtUiSettings uiSettings;
1132 uiSettings.setValue("ShowStatusBar", enabled);
1136 void MainWin::setupSystray()
1139 _systemTray = new StatusNotifierItem(this);
1140 #elif !defined QT_NO_SYSTEMTRAYICON
1141 _systemTray = new LegacySystemTray(this);
1143 _systemTray = new SystemTray(this); // dummy
1148 void MainWin::setupToolBars()
1150 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1151 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1152 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1153 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1156 setUnifiedTitleAndToolBarOnMac(true);
1160 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1162 _mainToolBar = new QToolBar(this);
1163 _mainToolBar->setObjectName("MainToolBar");
1165 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1166 addToolBar(_mainToolBar);
1168 if (Quassel::runMode() != Quassel::Monolithic) {
1169 ActionCollection *coll = QtUi::actionCollection("General");
1170 _mainToolBar->addAction(coll->action("ConnectCore"));
1171 _mainToolBar->addAction(coll->action("DisconnectCore"));
1174 _mainToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1176 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1177 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1180 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1182 _nickToolBar = new QToolBar(this);
1183 _nickToolBar->setObjectName("NickToolBar");
1185 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1186 _nickToolBar->setVisible(false); //default: not visible
1187 addToolBar(_nickToolBar);
1188 _nickToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1190 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1191 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1194 QtUiSettings uiSettings;
1196 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1197 _mainToolBar->setVisible(visible);
1198 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1202 void MainWin::saveMainToolBarStatus(bool enabled)
1205 QtUiSettings uiSettings;
1206 uiSettings.setValue("ShowMainToolBar", enabled);
1213 void MainWin::doAutoConnect()
1215 if (!Client::coreConnection()->connectToCore()) {
1216 // No autoconnect selected (or no accounts)
1217 showCoreConnectionDlg();
1222 void MainWin::connectedToCore()
1224 Q_CHECK_PTR(Client::bufferViewManager());
1225 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1226 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1227 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1229 if (Client::transferManager()) {
1230 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1233 setConnectedState();
1237 void MainWin::setConnectedState()
1239 ActionCollection *coll = QtUi::actionCollection("General");
1241 coll->action("ConnectCore")->setEnabled(false);
1242 coll->action("DisconnectCore")->setEnabled(true);
1243 coll->action("ChangePassword")->setEnabled(true);
1244 coll->action("CoreInfo")->setEnabled(true);
1246 foreach(QAction *action, _fileMenu->actions()) {
1247 if (isRemoteCoreOnly(action))
1248 action->setVisible(!Client::internalCore());
1251 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1252 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1253 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1254 if (!Client::internalCore()) {
1255 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1256 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1257 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1260 // _viewMenu->setEnabled(true);
1261 if (!Client::internalCore())
1262 statusBar()->showMessage(tr("Connected to core."));
1264 statusBar()->clearMessage();
1266 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1268 systemTray()->setState(SystemTray::Active);
1270 if (Client::networkIds().isEmpty()) {
1271 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1275 // Monolithic always preselects last used buffer - Client only if the connection died
1276 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1278 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1279 if (lastUsedBufferId.isValid())
1280 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1286 void MainWin::loadLayout()
1289 int accountId = Client::currentCoreAccount().accountId().toInt();
1290 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1291 if (state.isEmpty()) {
1292 foreach(BufferViewDock *view, _bufferViews)
1294 _layoutLoaded = true;
1297 _nickListWidget->setVisible(true);
1298 restoreState(state, accountId);
1299 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1300 if (bufferViewId >= 0)
1301 changeActiveBufferView(bufferViewId);
1303 _layoutLoaded = true;
1307 void MainWin::saveLayout()
1310 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1311 if (accountId > 0) {
1312 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1313 BufferView *view = activeBufferView();
1314 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1319 void MainWin::disconnectedFromCore()
1321 // save core specific layout and remove bufferviews;
1323 _layoutLoaded = false;
1325 QVariant actionData;
1326 BufferViewDock *dock;
1327 foreach(QAction *action, _bufferViewsMenu->actions()) {
1328 actionData = action->data();
1329 if (!actionData.isValid())
1332 dock = qobject_cast<BufferViewDock *>(action->parent());
1333 if (dock && actionData.toInt() != -1) {
1334 removeAction(action);
1335 _bufferViews.removeAll(dock);
1336 dock->deleteLater();
1340 // store last active buffer
1342 BufferId lastBufId = _bufferWidget->currentBuffer();
1343 if (lastBufId.isValid()) {
1344 s.setValue("LastUsedBufferId", lastBufId.toInt());
1345 // clear the current selection
1346 Client::bufferModel()->standardSelectionModel()->clearSelection();
1348 restoreState(s.value("MainWinState").toByteArray());
1349 setDisconnectedState();
1353 void MainWin::setDisconnectedState()
1355 ActionCollection *coll = QtUi::actionCollection("General");
1356 //ui.menuCore->setEnabled(false);
1357 coll->action("ConnectCore")->setEnabled(true);
1358 coll->action("DisconnectCore")->setEnabled(false);
1359 coll->action("CoreInfo")->setEnabled(false);
1360 coll->action("ChangePassword")->setEnabled(false);
1361 //_viewMenu->setEnabled(false);
1362 statusBar()->showMessage(tr("Not connected to core."));
1363 if (_msgProcessorStatusWidget)
1364 _msgProcessorStatusWidget->setProgress(0, 0);
1366 systemTray()->setState(SystemTray::Passive);
1367 _nickListWidget->setVisible(false);
1371 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1373 Q_UNUSED(errorMessage)
1374 CoreConnectAuthDlg dlg(account);
1375 *valid = (dlg.exec() == QDialog::Accepted);
1379 void MainWin::handleNoSslInClient(bool *accepted)
1381 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1382 QMessageBox::Ignore|QMessageBox::Cancel);
1383 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1384 box.setDefaultButton(QMessageBox::Ignore);
1385 *accepted = box.exec() == QMessageBox::Ignore;
1389 void MainWin::handleNoSslInCore(bool *accepted)
1391 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1392 QMessageBox::Ignore|QMessageBox::Cancel);
1393 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1394 box.setDefaultButton(QMessageBox::Ignore);
1395 *accepted = box.exec() == QMessageBox::Ignore;
1401 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1403 QString errorString = "<ul>";
1404 foreach(const QSslError error, socket->sslErrors())
1405 errorString += QString("<li>%1</li>").arg(error.errorString());
1406 errorString += "</ul>";
1408 QMessageBox box(QMessageBox::Warning,
1409 tr("Untrusted Security Certificate"),
1410 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1411 QMessageBox::Cancel);
1412 box.setInformativeText(errorString);
1413 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1414 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1416 QMessageBox::ButtonRole role;
1419 role = box.buttonRole(box.clickedButton());
1420 if (role == QMessageBox::HelpRole) {
1421 SslInfoDlg dlg(socket);
1425 while (role == QMessageBox::HelpRole);
1427 *accepted = role == QMessageBox::AcceptRole;
1429 QMessageBox box2(QMessageBox::Warning,
1430 tr("Untrusted Security Certificate"),
1431 tr("Would you like to accept this certificate forever without being prompted?"),
1433 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1434 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1436 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1441 #endif /* HAVE_SSL */
1443 void MainWin::handleCoreConnectionError(const QString &error)
1445 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1449 void MainWin::showCoreConnectionDlg()
1452 if (dlg.exec() == QDialog::Accepted) {
1453 AccountId accId = dlg.selectedAccount();
1454 if (accId.isValid())
1455 Client::coreConnection()->connectToCore(accId);
1460 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1462 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1468 void MainWin::showChannelList(NetworkId netId, const QString &channelFilters, bool listImmediately)
1470 if (!netId.isValid()) {
1471 QAction *action = qobject_cast<QAction *>(sender());
1473 netId = action->data().value<NetworkId>();
1474 if (!netId.isValid()) {
1475 // We still haven't found a valid network, probably no network selected, e.g. "/list"
1476 // on the client homescreen when no networks are connected.
1477 QMessageBox box(QMessageBox::Information, tr("No network selected"),
1478 QString("<b>%1</b>").arg(tr("No network selected")),
1480 box.setInformativeText(tr("Select a network before trying to view the channel list."));
1486 ChannelListDlg *channelListDlg = new ChannelListDlg(this);
1487 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1488 channelListDlg->setNetwork(netId);
1489 if (!channelFilters.isEmpty()) {
1490 channelListDlg->setChannelFilters(channelFilters);
1492 if (listImmediately) {
1493 channelListDlg->requestSearch();
1495 channelListDlg->show();
1499 void MainWin::showNetworkConfig(NetworkId netId)
1501 SettingsPageDlg dlg{new NetworksSettingsPage{}};
1502 if (netId.isValid())
1503 qobject_cast<NetworksSettingsPage *>(dlg.currentPage())->bufferList_Open(netId);
1508 void MainWin::showIgnoreList(QString newRule)
1510 SettingsPageDlg dlg{new IgnoreListSettingsPage{}};
1511 // prepare config dialog for new rule
1512 if (!newRule.isEmpty())
1513 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1518 void MainWin::showCoreInfoDlg()
1520 CoreInfoDlg{}.exec();
1524 void MainWin::showAwayLog()
1528 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1529 _awayLog = new AwayLogView(filter, 0);
1530 filter->setParent(_awayLog);
1531 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1532 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1537 void MainWin::awayLogDestroyed()
1543 void MainWin::showSettingsDlg()
1545 SettingsDlg *dlg = new SettingsDlg(this);
1547 //Category: Interface
1548 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1549 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1550 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1551 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1552 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1553 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1554 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1555 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1557 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1559 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1560 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1561 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1562 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1565 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1566 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1567 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1568 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1569 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1570 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1572 // Category: Remote Cores
1573 if (Quassel::runMode() != Quassel::Monolithic) {
1574 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1575 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1582 void MainWin::showAboutDlg()
1588 void MainWin::showShortcutsDlg()
1591 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed);
1592 foreach(KActionCollection *coll, QtUi::actionCollections())
1593 dlg.addCollection(coll, coll->property("Category").toString());
1594 dlg.configure(true);
1596 SettingsPageDlg{new ShortcutsSettingsPage{QtUi::actionCollections()}}.exec();
1601 void MainWin::showNewTransferDlg(const QUuid &transferId)
1603 auto transfer = Client::transferManager()->transfer(transferId);
1605 if (transfer->status() == Transfer::Status::New) {
1606 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1611 qWarning() << "Unknown transfer ID" << transferId;
1616 void MainWin::onFullScreenToggled()
1618 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1619 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1622 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1624 if (_fullScreenAction->isChecked())
1625 setWindowState(windowState() | Qt::WindowFullScreen);
1627 setWindowState(windowState() & ~Qt::WindowFullScreen);
1632 /********************************************************************************************************/
1634 bool MainWin::event(QEvent *event)
1636 switch(event->type()) {
1637 case QEvent::WindowActivate: {
1638 BufferId bufferId = Client::bufferModel()->currentBuffer();
1639 if (bufferId.isValid())
1640 Client::instance()->markBufferAsRead(bufferId);
1643 case QEvent::WindowDeactivate:
1644 if (bufferWidget()->autoMarkerLineOnLostFocus())
1645 bufferWidget()->setMarkerLine();
1650 return QMainWindow::event(event);
1654 void MainWin::moveEvent(QMoveEvent *event)
1656 if (!(windowState() & Qt::WindowMaximized))
1657 _normalPos = event->pos();
1659 QMainWindow::moveEvent(event);
1663 void MainWin::resizeEvent(QResizeEvent *event)
1665 if (!(windowState() & Qt::WindowMaximized))
1666 _normalSize = event->size();
1668 QMainWindow::resizeEvent(event);
1672 void MainWin::closeEvent(QCloseEvent *event)
1675 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1677 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1678 // This messes up MainWinState/MainWinHidden save/restore.
1679 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1680 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1681 QtUi::hideMainWidget();
1684 else if(!_aboutToQuit) {
1685 _aboutToQuit = true;
1687 Quassel::instance()->quit();
1695 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1699 bool hasFocus = QApplication::activeWindow() != 0;
1701 for (int i = start; i <= end; i++) {
1702 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1703 if (!idx.isValid()) {
1704 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1707 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1708 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1711 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1712 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1714 // check if bufferId belongs to the shown chatlists
1715 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1716 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1719 // check if it's the buffer currently displayed
1720 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1723 // only show notifications for higlights or queries
1724 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1727 // and of course: don't notify for ignored messages
1728 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1731 // seems like we have a legit notification candidate!
1732 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1733 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1734 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1735 AbstractNotificationBackend::NotificationType type;
1737 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1738 type = AbstractNotificationBackend::PrivMsg;
1739 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1740 type = AbstractNotificationBackend::PrivMsgFocused;
1741 else if (flags & Message::Highlight && !hasFocus)
1742 type = AbstractNotificationBackend::Highlight;
1744 type = AbstractNotificationBackend::HighlightFocused;
1746 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1751 void MainWin::currentBufferChanged(BufferId buffer)
1753 if (buffer.isValid())
1754 Client::instance()->markBufferAsRead(buffer);
1758 void MainWin::clientNetworkCreated(NetworkId id)
1760 const Network *net = Client::network(id);
1761 QAction *act = new QAction(net->networkName(), this);
1762 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1763 act->setData(QVariant::fromValue<NetworkId>(id));
1764 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1765 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1767 QAction *beforeAction = 0;
1768 foreach(QAction *action, _networksMenu->actions()) {
1769 if (!action->data().isValid()) // ignore stock actions
1771 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1772 beforeAction = action;
1776 _networksMenu->insertAction(beforeAction, act);
1780 void MainWin::clientNetworkUpdated()
1782 const Network *net = qobject_cast<const Network *>(sender());
1786 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1790 action->setText(net->networkName());
1792 switch (net->connectionState()) {
1793 case Network::Initialized:
1794 action->setIcon(icon::get("network-connect"));
1795 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1796 if (!bufferWidget()->currentBuffer().isValid()) {
1797 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1798 if (idx.isValid()) {
1799 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1800 Client::bufferModel()->switchToBuffer(statusBufferId);
1804 case Network::Disconnected:
1805 action->setIcon(icon::get("network-disconnect"));
1808 action->setIcon(icon::get("network-wired"));
1813 void MainWin::clientNetworkRemoved(NetworkId id)
1815 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1819 action->deleteLater();
1823 void MainWin::connectOrDisconnectFromNet()
1825 QAction *act = qobject_cast<QAction *>(sender());
1827 const Network *net = Client::network(act->data().value<NetworkId>());
1829 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1830 else net->requestDisconnect();
1834 void MainWin::on_inputFormatApplyColor_triggered()
1839 _inputWidget->applyFormatActiveColor();
1843 void MainWin::on_inputFormatApplyColorFill_triggered()
1848 _inputWidget->applyFormatActiveColorFill();
1852 void MainWin::on_inputFormatClear_triggered()
1857 _inputWidget->clearFormat();
1861 void MainWin::on_inputFormatBold_triggered()
1866 _inputWidget->toggleFormatBold();
1870 void MainWin::on_inputFormatItalic_triggered()
1875 _inputWidget->toggleFormatItalic();
1879 void MainWin::on_inputFormatUnderline_triggered()
1884 _inputWidget->toggleFormatUnderline();
1888 void MainWin::on_jumpHotBuffer_triggered()
1890 if (!_bufferHotList->rowCount())
1893 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1896 void MainWin::on_bufferSearch_triggered()
1898 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1899 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1903 _bufferViews[_activeBufferViewIndex]->activateFilter();
1907 void MainWin::onJumpKey()
1909 QAction *action = qobject_cast<QAction *>(sender());
1910 if (!action || !Client::bufferModel())
1912 int idx = action->property("Index").toInt();
1914 if (_jumpKeyMap.isEmpty())
1915 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1917 if (!_jumpKeyMap.contains(idx))
1920 BufferId buffer = _jumpKeyMap.value(idx);
1921 if (buffer.isValid())
1922 Client::bufferModel()->switchToBuffer(buffer);
1926 void MainWin::bindJumpKey()
1928 QAction *action = qobject_cast<QAction *>(sender());
1929 if (!action || !Client::bufferModel())
1931 int idx = action->property("Index").toInt();
1933 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1934 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1938 void MainWin::on_actionDebugNetworkModel_triggered()
1940 QTreeView *view = new QTreeView;
1941 view->setAttribute(Qt::WA_DeleteOnClose);
1942 view->setWindowTitle("Debug NetworkModel View");
1943 view->setModel(Client::networkModel());
1944 view->setColumnWidth(0, 250);
1945 view->setColumnWidth(1, 250);
1946 view->setColumnWidth(2, 80);
1947 view->resize(610, 300);
1952 void MainWin::on_actionDebugHotList_triggered()
1954 _bufferHotList->invalidate();
1955 _bufferHotList->sort(0, Qt::DescendingOrder);
1957 QTreeView *view = new QTreeView;
1958 view->setAttribute(Qt::WA_DeleteOnClose);
1959 view->setModel(_bufferHotList);
1964 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1966 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1967 overlay->setAttribute(Qt::WA_DeleteOnClose);
1972 void MainWin::on_actionDebugMessageModel_triggered()
1974 QTableView *view = new QTableView(0);
1975 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1976 filter->setSourceModel(Client::messageModel());
1977 view->setModel(filter);
1978 view->setAttribute(Qt::WA_DeleteOnClose, true);
1979 view->verticalHeader()->hide();
1980 view->horizontalHeader()->setStretchLastSection(true);
1985 void MainWin::on_actionDebugLog_triggered()
1987 auto dlg = new DebugLogDlg(this);
1992 void MainWin::showStatusBarMessage(const QString &message)
1994 statusBar()->showMessage(message, 10000);