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 "debuglogwidget.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"
111 # include "phononnotificationbackend.h"
113 # include "systraynotificationbackend.h"
114 # include "taskbarnotificationbackend.h"
116 # include "knotificationbackend.h"
117 #endif /* HAVE_KDE */
118 #include "systrayanimationnotificationbackend.h"
122 # include "snorenotificationbackend.h"
126 # include "sslinfodlg.h"
129 #ifdef HAVE_INDICATEQT
130 #include "indicatornotificationbackend.h"
133 #ifdef HAVE_NOTIFICATION_CENTER
134 #include "osxnotificationbackend.h"
138 #include "dockmanagernotificationbackend.h"
141 #include "settingspages/aliasessettingspage.h"
142 #include "settingspages/appearancesettingspage.h"
143 #include "settingspages/backlogsettingspage.h"
144 #include "settingspages/bufferviewsettingspage.h"
145 #include "settingspages/chatmonitorsettingspage.h"
146 #include "settingspages/chatviewsettingspage.h"
147 #include "settingspages/chatviewcolorsettingspage.h"
148 #include "settingspages/connectionsettingspage.h"
149 #include "settingspages/coreaccountsettingspage.h"
150 #include "settingspages/coreconnectionsettingspage.h"
151 #include <settingspages/corehighlightsettingspage.h>
152 #include "settingspages/dccsettingspage.h"
153 #include "settingspages/highlightsettingspage.h"
154 #include "settingspages/identitiessettingspage.h"
155 #include "settingspages/ignorelistsettingspage.h"
156 #include "settingspages/inputwidgetsettingspage.h"
157 #include "settingspages/itemviewsettingspage.h"
158 #include "settingspages/networkssettingspage.h"
159 #include "settingspages/notificationssettingspage.h"
160 #include "settingspages/topicwidgetsettingspage.h"
163 # include "settingspages/shortcutssettingspage.h"
167 # include "settingspages/sonnetsettingspage.h"
171 MainWin::MainWin(QWidget *parent)
173 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
175 : QMainWindow(parent),
177 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
178 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
181 _layoutLoaded(false),
182 _activeBufferViewIndex(-1),
185 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
187 QtUiSettings uiSettings;
188 QString style = uiSettings.value("Style", QString()).toString();
189 if (!style.isEmpty()) {
190 QApplication::setStyle(style);
193 QApplication::setQuitOnLastWindowClosed(false);
195 setWindowTitle("Quassel IRC");
196 setWindowIconText("Quassel IRC");
197 // Set the default icon for all windows
198 QApplication::setWindowIcon(icon::get("quassel"));
205 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
206 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
207 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
208 SLOT(messagesInserted(const QModelIndex &, int, int)));
209 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
210 connect(Client::instance(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
211 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showNetworkConfig(NetworkId)), SLOT(showNetworkConfig(NetworkId)));
212 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
213 connect(Client::instance(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
214 connect(Client::instance(), SIGNAL(dbUpgradeInProgress(bool)), SLOT(showMigrationWarning(bool)));
216 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList, QVariantList)), SLOT(showCoreConfigWizard(QVariantList, QVariantList)));
217 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
218 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
219 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
220 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
222 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
226 setDockNestingEnabled(true);
227 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
228 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
229 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
230 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
232 // Order is sometimes important
236 // setupTransferWidget(); not ready yet
248 _bufferWidget->setFocusProxy(_inputWidget);
249 _chatMonitorView->setFocusProxy(_inputWidget);
252 # ifdef HAVE_QTMULTIMEDIA
253 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
256 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
258 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
260 QtUi::registerNotificationBackend(new KNotificationBackend(this));
261 #endif /* HAVE_KDE */
264 #ifndef QT_NO_SYSTEMTRAYICON
265 QtUi::registerNotificationBackend(new SystrayAnimationNotificationBackend(this));
268 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
269 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
270 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
273 #ifdef HAVE_INDICATEQT
274 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
277 #ifdef HAVE_NOTIFICATION_CENTER
278 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
282 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
285 // we assume that at this point, all configurable actions are defined!
286 QtUi::loadShortcuts();
288 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
290 setDisconnectedState(); // Disable menus and stuff
293 setAutoSaveSettings();
296 // restore mainwin state
298 restoreStateFromSettings(s);
300 // restore locked state of docks
301 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
303 QTimer::singleShot(0, this, SLOT(doAutoConnect()));
315 saveStateToSettings(s);
317 QApplication::quit();
321 void MainWin::saveStateToSettings(UiSettings &s)
323 s.setValue("MainWinSize", _normalSize);
324 s.setValue("MainWinPos", _normalPos);
325 s.setValue("MainWinState", saveState());
326 s.setValue("MainWinGeometry", saveGeometry());
327 s.setValue("MainWinMinimized", isMinimized());
328 s.setValue("MainWinMaximized", isMaximized());
329 s.setValue("MainWinHidden", !isVisible());
330 BufferId lastBufId = Client::bufferModel()->currentBuffer();
331 if (lastBufId.isValid())
332 s.setValue("LastUsedBufferId", lastBufId.toInt());
335 saveAutoSaveSettings();
340 void MainWin::restoreStateFromSettings(UiSettings &s)
342 _normalSize = s.value("MainWinSize", size()).toSize();
343 _normalPos = s.value("MainWinPos", pos()).toPoint();
344 bool maximized = s.value("MainWinMaximized", false).toBool();
347 restoreGeometry(s.value("MainWinGeometry").toByteArray());
350 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
355 restoreState(s.value("MainWinState").toByteArray());
361 if ((Quassel::isOptionSet("hidewindow")
362 || s.value("MainWinHidden").toBool())
363 && _systemTray->isSystemTrayAvailable())
364 QtUi::hideMainWidget();
365 else if (s.value("MainWinMinimized").toBool())
373 QMenu *MainWin::createPopupMenu()
375 QMenu *popupMenu = QMainWindow::createPopupMenu();
376 popupMenu->addSeparator();
377 ActionCollection *coll = QtUi::actionCollection("General");
378 popupMenu->addAction(coll->action("ToggleMenuBar"));
383 void MainWin::updateIcon()
386 if (Client::isConnected())
387 icon = icon::get("quassel");
389 icon = icon::get("inactive-quassel");
394 void MainWin::setupActions()
396 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
398 coll->addAction("ConnectCore", new Action(icon::get("connect-quassel"), tr("&Connect to Core..."), coll,
399 this, SLOT(showCoreConnectionDlg())));
400 coll->addAction("DisconnectCore", new Action(icon::get("disconnect-quassel", ":/pics/quassel-eye.png"), tr("&Disconnect from Core"), coll,
401 Client::instance(), SLOT(disconnectFromCore())));
402 coll->addAction("ChangePassword", new Action(icon::get("dialog-password"), tr("Change &Password..."), coll,
403 this, SLOT(showPasswordChangeDlg())));
404 coll->addAction("CoreInfo", new Action(icon::get("help-about"), tr("Core &Info..."), coll,
405 this, SLOT(showCoreInfoDlg())));
406 coll->addAction("ConfigureNetworks", new Action(icon::get("configure"), tr("Configure &Networks..."), coll,
407 this, SLOT(on_actionConfigureNetworks_triggered())));
408 // QKeySequence::Quit was added in Qt 4.6, and could be used instead. However, that key
409 // sequence is empty by default on Windows, which would remove Ctrl-Q to quit. It may be best
410 // to just keep it this way.
412 // See https://doc.qt.io/qt-5/qkeysequence.html
413 coll->addAction("Quit", new Action(icon::get("application-exit"), tr("&Quit"), coll,
414 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
417 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
418 this, SLOT(on_actionConfigureViews_triggered())));
420 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
421 lockAct->setCheckable(true);
422 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
424 coll->addAction("ToggleSearchBar", new Action(icon::get("edit-find"), tr("Show &Search Bar"), coll,
425 0, 0, QKeySequence::Find))->setCheckable(true);
426 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
427 this, SLOT(showAwayLog())));
428 coll->addAction("ToggleMenuBar", new Action(icon::get("show-menu"), tr("Show &Menubar"), coll,
429 0, 0))->setCheckable(true);
431 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
432 0, 0))->setCheckable(true);
435 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
437 _fullScreenAction = new Action(icon::get("view-fullscreen"), tr("&Full Screen Mode"), coll,
438 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
439 _fullScreenAction->setCheckable(true);
440 coll->addAction("ToggleFullScreen", _fullScreenAction);
444 QAction *configureShortcutsAct = new Action(icon::get("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
445 this, SLOT(showShortcutsDlg()));
446 configureShortcutsAct->setMenuRole(QAction::NoRole);
447 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
450 QAction *configureQuasselAct = new Action(icon::get("configure"), tr("&Configure Quassel..."), coll,
451 this, SLOT(showSettingsDlg()));
452 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
454 QAction *configureQuasselAct = new Action(icon::get("configure"), tr("&Configure Quassel..."), coll,
455 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
457 coll->addAction("ConfigureQuassel", configureQuasselAct);
460 QAction *aboutQuasselAct = new Action(icon::get("quassel"), tr("&About Quassel"), coll,
461 this, SLOT(showAboutDlg()));
462 aboutQuasselAct->setMenuRole(QAction::AboutRole);
463 coll->addAction("AboutQuassel", aboutQuasselAct);
465 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
466 qApp, SLOT(aboutQt()));
467 aboutQtAct->setMenuRole(QAction::AboutQtRole);
468 coll->addAction("AboutQt", aboutQtAct);
469 coll->addAction("DebugNetworkModel", new Action(icon::get("tools-report-bug"), tr("Debug &NetworkModel"), coll,
470 this, SLOT(on_actionDebugNetworkModel_triggered())));
471 coll->addAction("DebugBufferViewOverlay", new Action(icon::get("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
472 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
473 coll->addAction("DebugMessageModel", new Action(icon::get("tools-report-bug"), tr("Debug &MessageModel"), coll,
474 this, SLOT(on_actionDebugMessageModel_triggered())));
475 coll->addAction("DebugHotList", new Action(icon::get("tools-report-bug"), tr("Debug &HotList"), coll,
476 this, SLOT(on_actionDebugHotList_triggered())));
477 coll->addAction("DebugLog", new Action(icon::get("tools-report-bug"), tr("Debug &Log"), coll,
478 this, SLOT(on_actionDebugLog_triggered())));
479 coll->addAction("ReloadStyle", new Action(icon::get("view-refresh"), tr("Reload Stylesheet"), coll,
480 QtUi::style(), SLOT(reload()), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_R)));
482 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
483 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
486 coll = QtUi::actionCollection("TextFormat", tr("Text formatting"));
488 coll->addAction("FormatApplyColor", new Action(
489 icon::get("format-text-color"), tr("Apply foreground color"), coll,
490 this, SLOT(on_inputFormatApplyColor_triggered()),
491 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_G)));
493 coll->addAction("FormatApplyColorFill", new Action(
494 icon::get("format-fill-color"), tr("Apply background color"), coll,
495 this, SLOT(on_inputFormatApplyColorFill_triggered()),
496 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B)));
498 coll->addAction("FormatClear", new Action(
499 icon::get("edit-clear"), tr("Clear formatting"), coll,
500 this, SLOT(on_inputFormatClear_triggered()),
501 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C)));
503 coll->addAction("FormatBold", new Action(
504 icon::get("format-text-bold"), tr("Toggle bold"), coll,
505 this, SLOT(on_inputFormatBold_triggered()),
506 QKeySequence::Bold));
508 coll->addAction("FormatItalic", new Action(
509 icon::get("format-text-italic"), tr("Toggle italics"), coll,
510 this, SLOT(on_inputFormatItalic_triggered()),
511 QKeySequence::Italic));
513 coll->addAction("FormatUnderline", new Action(
514 icon::get("format-text-underline"), tr("Toggle underline"), coll,
515 this, SLOT(on_inputFormatUnderline_triggered()), QKeySequence::Underline));
518 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
520 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
521 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
523 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
524 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
528 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
529 const int jumpModifier = Qt::ControlModifier;
531 const int bindModifier = Qt::ControlModifier;
532 const int jumpModifier = Qt::AltModifier;
535 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
536 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
537 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
538 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
539 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
540 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
541 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
542 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
543 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
544 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
545 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
546 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
547 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
548 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
549 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
550 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
551 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
552 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
553 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
554 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
556 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
557 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
558 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
559 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
560 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
561 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
562 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
563 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
564 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
565 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
566 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
567 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
568 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
569 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
570 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
571 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
572 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
573 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
574 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
575 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
578 coll->addAction("NextBufferView", new Action(icon::get("go-next-view"), tr("Activate Next Chat List"), coll,
579 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
580 coll->addAction("PreviousBufferView", new Action(icon::get("go-previous-view"), tr("Activate Previous Chat List"), coll,
581 this, SLOT(previousBufferView()), QKeySequence::Back));
582 coll->addAction("NextBuffer", new Action(icon::get("go-down"), tr("Go to Next Chat"), coll,
583 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
584 coll->addAction("PreviousBuffer", new Action(icon::get("go-up"), tr("Go to Previous Chat"), coll,
585 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
589 void MainWin::setupMenus()
591 ActionCollection *coll = QtUi::actionCollection("General");
593 _fileMenu = menuBar()->addMenu(tr("&File"));
595 static const QStringList coreActions = QStringList()
596 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
599 foreach(QString actionName, coreActions) {
600 coreAction = coll->action(actionName);
601 _fileMenu->addAction(coreAction);
602 flagRemoteCoreOnly(coreAction);
604 flagRemoteCoreOnly(_fileMenu->addSeparator());
606 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
607 _networksMenu->addAction(coll->action("ConfigureNetworks"));
608 _networksMenu->addSeparator();
609 _fileMenu->addSeparator();
610 _fileMenu->addAction(coll->action("Quit"));
612 _viewMenu = menuBar()->addMenu(tr("&View"));
613 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
614 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
615 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
616 _viewMenu->addSeparator();
618 _viewMenu->addAction(coll->action("ToggleMenuBar"));
619 _viewMenu->addAction(coll->action("ToggleStatusBar"));
620 _viewMenu->addAction(coll->action("ToggleSearchBar"));
622 coreAction = coll->action("ShowAwayLog");
623 flagRemoteCoreOnly(coreAction);
624 _viewMenu->addAction(coreAction);
626 _viewMenu->addSeparator();
627 _viewMenu->addAction(coll->action("LockLayout"));
629 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
631 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
632 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
634 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
636 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
639 _helpMenu = menuBar()->addMenu(tr("&Help"));
641 _helpMenu->addAction(coll->action("AboutQuassel"));
643 _helpMenu->addAction(coll->action("AboutQt"));
645 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
647 _helpMenu->addSeparator();
648 _helpDebugMenu = _helpMenu->addMenu(icon::get("tools-report-bug"), tr("Debug"));
649 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
650 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
651 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
652 _helpDebugMenu->addAction(coll->action("DebugHotList"));
653 _helpDebugMenu->addAction(coll->action("DebugLog"));
654 _helpDebugMenu->addSeparator();
655 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
658 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
660 QtUiSettings uiSettings;
661 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
662 showMenuBar->setChecked(enabled);
663 enabled ? menuBar()->show() : menuBar()->hide();
665 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
666 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
670 void MainWin::setupBufferWidget()
672 _bufferWidget = new BufferWidget(this);
673 _bufferWidget->setModel(Client::bufferModel());
674 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
675 setCentralWidget(_bufferWidget);
679 void MainWin::addBufferView(int bufferViewConfigId)
681 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
685 void MainWin::addBufferView(ClientBufferViewConfig *config)
690 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
691 BufferViewDock *dock = new BufferViewDock(config, this);
693 //create the view and initialize it's filter
694 BufferView *view = new BufferView(dock);
695 view->setFilteredModel(Client::bufferModel(), config);
696 view->installEventFilter(_inputWidget); // for key presses
698 Client::bufferModel()->synchronizeView(view);
700 dock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
702 dock->setWidget(view);
703 dock->setVisible(_layoutLoaded); // don't show before state has been restored
705 addDockWidget(Qt::LeftDockWidgetArea, dock);
706 _bufferViewsMenu->addAction(dock->toggleViewAction());
708 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
709 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
710 _bufferViews.append(dock);
712 if (!activeBufferView())
717 void MainWin::removeBufferView(int bufferViewConfigId)
720 BufferViewDock *dock;
721 foreach(QAction *action, _bufferViewsMenu->actions()) {
722 actionData = action->data();
723 if (!actionData.isValid())
726 dock = qobject_cast<BufferViewDock *>(action->parent());
727 if (dock && actionData.toInt() == bufferViewConfigId) {
728 removeAction(action);
729 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
730 _bufferViews.removeAll(dock);
732 if (dock->isActive()) {
733 dock->setActive(false);
734 _activeBufferViewIndex = -1;
744 void MainWin::bufferViewToggled(bool enabled)
746 if (!enabled && !isMinimized()) {
747 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
748 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
751 QAction *action = qobject_cast<QAction *>(sender());
753 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
756 // Make sure we don't toggle backlog fetch for a view we've already removed
757 if (!_bufferViews.contains(dock))
761 Client::bufferViewOverlay()->addView(dock->bufferViewId());
763 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
767 void MainWin::bufferViewVisibilityChanged(bool visible)
770 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
772 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
777 BufferView *MainWin::allBuffersView() const
779 // "All Buffers" is always the first dock created
780 if (_bufferViews.count() > 0)
781 return _bufferViews[0]->bufferView();
786 BufferView *MainWin::activeBufferView() const
788 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
790 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
791 return dock->isActive() ? dock->bufferView() : 0;
795 void MainWin::changeActiveBufferView(int bufferViewId)
797 if (bufferViewId < 0)
800 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
801 _bufferViews[_activeBufferViewIndex]->setActive(false);
802 _activeBufferViewIndex = -1;
805 for (int i = 0; i < _bufferViews.count(); i++) {
806 BufferViewDock *dock = _bufferViews.at(i);
807 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
808 _activeBufferViewIndex = i;
809 dock->setActive(true);
814 nextBufferView(); // fallback
818 void MainWin::showPasswordChangeDlg()
820 if(Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
821 PasswordChangeDlg dlg(this);
825 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
826 tr("<b>Your Quassel Core does not support this feature</b>"),
827 QMessageBox::Ok, this);
828 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
834 void MainWin::showMigrationWarning(bool show)
836 if (show && !_migrationWarning) {
837 _migrationWarning = new QMessageBox(QMessageBox::Information,
839 "<b>" + tr("Your database is being upgraded") + "</b>",
840 QMessageBox::NoButton, this);
841 _migrationWarning->setInformativeText("<p>"
842 + tr("In order to support new features, we need to make changes to your backlog database. This may take a long while.")
844 + tr("Do not exit Quassel until the upgrade is complete!")
846 _migrationWarning->setStandardButtons(QMessageBox::NoButton);
847 _migrationWarning->show();
849 else if (!show && _migrationWarning) {
850 _migrationWarning->close();
851 _migrationWarning->deleteLater();
852 _migrationWarning = nullptr;
857 void MainWin::changeActiveBufferView(bool backwards)
859 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
860 _bufferViews[_activeBufferViewIndex]->setActive(false);
863 if (!_bufferViews.count())
866 int c = _bufferViews.count();
867 while (c--) { // yes, this will reactivate the current active one if all others fail
869 if (--_activeBufferViewIndex < 0)
870 _activeBufferViewIndex = _bufferViews.count()-1;
873 if (++_activeBufferViewIndex >= _bufferViews.count())
874 _activeBufferViewIndex = 0;
877 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
878 if (dock->isHidden())
881 dock->setActive(true);
885 _activeBufferViewIndex = -1;
889 void MainWin::nextBufferView()
891 changeActiveBufferView(false);
895 void MainWin::previousBufferView()
897 changeActiveBufferView(true);
901 void MainWin::nextBuffer()
903 BufferView *view = activeBufferView();
909 void MainWin::previousBuffer()
911 BufferView *view = activeBufferView();
913 view->previousBuffer();
917 void MainWin::hideCurrentBuffer()
919 BufferView *view = activeBufferView();
921 view->hideCurrentBuffer();
925 void MainWin::showNotificationsDlg()
927 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
932 void MainWin::on_actionConfigureNetworks_triggered()
934 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
939 void MainWin::on_actionConfigureViews_triggered()
941 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
946 void MainWin::on_actionLockLayout_toggled(bool lock)
948 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
949 foreach(VerticalDock *dock, docks) {
950 dock->showTitle(!lock);
953 QList<NickListDock *> nickdocks = findChildren<NickListDock *>();
954 foreach(NickListDock *nickdock, nickdocks) {
955 nickdock->setLocked(lock);
958 QList<BufferViewDock *> bufferdocks = findChildren<BufferViewDock *>();
959 foreach(BufferViewDock *bufferdock, bufferdocks) {
960 bufferdock->setLocked(lock);
963 if (Client::bufferViewManager()) {
964 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
965 config->setLocked(lock);
969 _mainToolBar->setMovable(!lock);
970 _nickToolBar->setMovable(!lock);
972 QtUiSettings().setValue("LockLayout", lock);
976 void MainWin::setupNickWidget()
979 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
980 nickDock->setObjectName("NickDock");
981 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
982 nickDock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
984 _nickListWidget = new NickListWidget(nickDock);
985 nickDock->setWidget(_nickListWidget);
987 addDockWidget(Qt::RightDockWidgetArea, nickDock);
988 _viewMenu->addAction(nickDock->toggleViewAction());
989 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
991 // See NickListDock::NickListDock();
992 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
994 // attach the NickListWidget to the BufferModel and the default selection
995 _nickListWidget->setModel(Client::bufferModel());
996 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
998 _nickListWidget->setVisible(false);
1002 void MainWin::setupChatMonitor()
1004 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
1005 dock->setObjectName("ChatMonitorDock");
1007 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
1008 _chatMonitorView = new ChatMonitorView(filter, this);
1009 _chatMonitorView->show();
1010 dock->setWidget(_chatMonitorView);
1013 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1014 _viewMenu->addAction(dock->toggleViewAction());
1015 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
1019 void MainWin::setupInputWidget()
1021 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
1022 dock->setObjectName("InputDock");
1024 _inputWidget = new InputWidget(dock);
1025 dock->setWidget(_inputWidget);
1027 addDockWidget(Qt::BottomDockWidgetArea, dock);
1029 _viewMenu->addAction(dock->toggleViewAction());
1030 dock->toggleViewAction()->setText(tr("Show Input Line"));
1032 _inputWidget->setModel(Client::bufferModel());
1033 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1035 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
1037 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
1041 void MainWin::setupTopicWidget()
1043 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
1044 dock->setObjectName("TopicDock");
1045 _topicWidget = new TopicWidget(dock);
1047 dock->setWidget(_topicWidget);
1049 _topicWidget->setModel(Client::bufferModel());
1050 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1052 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1054 _viewMenu->addAction(dock->toggleViewAction());
1055 dock->toggleViewAction()->setText(tr("Show Topic Line"));
1059 void MainWin::setupTransferWidget()
1061 auto dock = new QDockWidget(tr("Transfers"), this);
1062 dock->setObjectName("TransferDock");
1063 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
1065 auto view = new QTableView(dock); // to be replaced by the real thing
1066 view->setModel(Client::transferModel());
1067 dock->setWidget(view);
1068 dock->hide(); // hidden by default
1069 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1071 auto action = dock->toggleViewAction();
1072 action->setText(tr("Show File Transfers"));
1073 action->setIcon(icon::get("download"));
1074 action->setShortcut(QKeySequence(Qt::Key_F6));
1075 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
1076 _viewMenu->addAction(action);
1080 void MainWin::setupViewMenuTail()
1082 _viewMenu->addSeparator();
1083 _viewMenu->addAction(_fullScreenAction);
1087 void MainWin::setupTitleSetter()
1089 _titleSetter.setModel(Client::bufferModel());
1090 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1094 void MainWin::setupStatusBar()
1096 // MessageProcessor progress
1097 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1100 _coreConnectionStatusWidget->update();
1101 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1103 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1105 QtUiSettings uiSettings;
1107 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1108 showStatusbar->setChecked(enabled);
1109 enabled ? statusBar()->show() : statusBar()->hide();
1111 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1112 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1114 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1118 void MainWin::setupHotList()
1120 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1121 flatProxy->setSourceModel(Client::bufferModel());
1122 _bufferHotList = new BufferHotListFilter(flatProxy);
1126 void MainWin::saveMenuBarStatus(bool enabled)
1128 QtUiSettings uiSettings;
1129 uiSettings.setValue("ShowMenuBar", enabled);
1133 void MainWin::saveStatusBarStatus(bool enabled)
1135 QtUiSettings uiSettings;
1136 uiSettings.setValue("ShowStatusBar", enabled);
1140 void MainWin::setupSystray()
1143 _systemTray = new StatusNotifierItem(this);
1144 #elif !defined QT_NO_SYSTEMTRAYICON
1145 _systemTray = new LegacySystemTray(this);
1147 _systemTray = new SystemTray(this); // dummy
1152 void MainWin::setupToolBars()
1154 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1155 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1156 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1157 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1160 setUnifiedTitleAndToolBarOnMac(true);
1164 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1166 _mainToolBar = new QToolBar(this);
1167 _mainToolBar->setObjectName("MainToolBar");
1169 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1170 addToolBar(_mainToolBar);
1172 if (Quassel::runMode() != Quassel::Monolithic) {
1173 ActionCollection *coll = QtUi::actionCollection("General");
1174 _mainToolBar->addAction(coll->action("ConnectCore"));
1175 _mainToolBar->addAction(coll->action("DisconnectCore"));
1178 _mainToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1180 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1181 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1184 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1186 _nickToolBar = new QToolBar(this);
1187 _nickToolBar->setObjectName("NickToolBar");
1189 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1190 _nickToolBar->setVisible(false); //default: not visible
1191 addToolBar(_nickToolBar);
1192 _nickToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1194 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1195 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1198 QtUiSettings uiSettings;
1200 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1201 _mainToolBar->setVisible(visible);
1202 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1206 void MainWin::saveMainToolBarStatus(bool enabled)
1209 QtUiSettings uiSettings;
1210 uiSettings.setValue("ShowMainToolBar", enabled);
1217 void MainWin::doAutoConnect()
1219 if (!Client::coreConnection()->connectToCore()) {
1220 // No autoconnect selected (or no accounts)
1221 showCoreConnectionDlg();
1226 void MainWin::connectedToCore()
1228 Q_CHECK_PTR(Client::bufferViewManager());
1229 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1230 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1231 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1233 if (Client::transferManager()) {
1234 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1237 setConnectedState();
1241 void MainWin::setConnectedState()
1243 ActionCollection *coll = QtUi::actionCollection("General");
1245 coll->action("ConnectCore")->setEnabled(false);
1246 coll->action("DisconnectCore")->setEnabled(true);
1247 coll->action("ChangePassword")->setEnabled(true);
1248 coll->action("CoreInfo")->setEnabled(true);
1250 foreach(QAction *action, _fileMenu->actions()) {
1251 if (isRemoteCoreOnly(action))
1252 action->setVisible(!Client::internalCore());
1255 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1256 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1257 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1258 if (!Client::internalCore()) {
1259 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1260 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1261 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1264 // _viewMenu->setEnabled(true);
1265 if (!Client::internalCore())
1266 statusBar()->showMessage(tr("Connected to core."));
1268 statusBar()->clearMessage();
1270 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1272 systemTray()->setState(SystemTray::Active);
1274 if (Client::networkIds().isEmpty()) {
1275 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1279 // Monolithic always preselects last used buffer - Client only if the connection died
1280 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1282 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1283 if (lastUsedBufferId.isValid())
1284 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1290 void MainWin::loadLayout()
1293 int accountId = Client::currentCoreAccount().accountId().toInt();
1294 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1295 if (state.isEmpty()) {
1296 foreach(BufferViewDock *view, _bufferViews)
1298 _layoutLoaded = true;
1301 _nickListWidget->setVisible(true);
1302 restoreState(state, accountId);
1303 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1304 if (bufferViewId >= 0)
1305 changeActiveBufferView(bufferViewId);
1307 _layoutLoaded = true;
1311 void MainWin::saveLayout()
1314 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1315 if (accountId > 0) {
1316 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1317 BufferView *view = activeBufferView();
1318 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1323 void MainWin::disconnectedFromCore()
1325 // save core specific layout and remove bufferviews;
1327 _layoutLoaded = false;
1329 QVariant actionData;
1330 BufferViewDock *dock;
1331 foreach(QAction *action, _bufferViewsMenu->actions()) {
1332 actionData = action->data();
1333 if (!actionData.isValid())
1336 dock = qobject_cast<BufferViewDock *>(action->parent());
1337 if (dock && actionData.toInt() != -1) {
1338 removeAction(action);
1339 _bufferViews.removeAll(dock);
1340 dock->deleteLater();
1344 // store last active buffer
1346 BufferId lastBufId = _bufferWidget->currentBuffer();
1347 if (lastBufId.isValid()) {
1348 s.setValue("LastUsedBufferId", lastBufId.toInt());
1349 // clear the current selection
1350 Client::bufferModel()->standardSelectionModel()->clearSelection();
1352 restoreState(s.value("MainWinState").toByteArray());
1353 setDisconnectedState();
1357 void MainWin::setDisconnectedState()
1359 ActionCollection *coll = QtUi::actionCollection("General");
1360 //ui.menuCore->setEnabled(false);
1361 coll->action("ConnectCore")->setEnabled(true);
1362 coll->action("DisconnectCore")->setEnabled(false);
1363 coll->action("CoreInfo")->setEnabled(false);
1364 coll->action("ChangePassword")->setEnabled(false);
1365 //_viewMenu->setEnabled(false);
1366 statusBar()->showMessage(tr("Not connected to core."));
1367 if (_msgProcessorStatusWidget)
1368 _msgProcessorStatusWidget->setProgress(0, 0);
1370 systemTray()->setState(SystemTray::Passive);
1371 _nickListWidget->setVisible(false);
1375 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1377 Q_UNUSED(errorMessage)
1378 CoreConnectAuthDlg dlg(account, this);
1379 *valid = (dlg.exec() == QDialog::Accepted);
1383 void MainWin::handleNoSslInClient(bool *accepted)
1385 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1386 QMessageBox::Ignore|QMessageBox::Cancel, this);
1387 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1388 box.setDefaultButton(QMessageBox::Ignore);
1389 *accepted = box.exec() == QMessageBox::Ignore;
1393 void MainWin::handleNoSslInCore(bool *accepted)
1395 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1396 QMessageBox::Ignore|QMessageBox::Cancel, this);
1397 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1398 box.setDefaultButton(QMessageBox::Ignore);
1399 *accepted = box.exec() == QMessageBox::Ignore;
1405 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1407 QString errorString = "<ul>";
1408 foreach(const QSslError error, socket->sslErrors())
1409 errorString += QString("<li>%1</li>").arg(error.errorString());
1410 errorString += "</ul>";
1412 QMessageBox box(QMessageBox::Warning,
1413 tr("Untrusted Security Certificate"),
1414 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1415 QMessageBox::Cancel, this);
1416 box.setInformativeText(errorString);
1417 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1418 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1420 QMessageBox::ButtonRole role;
1423 role = box.buttonRole(box.clickedButton());
1424 if (role == QMessageBox::HelpRole) {
1425 SslInfoDlg dlg(socket, this);
1429 while (role == QMessageBox::HelpRole);
1431 *accepted = role == QMessageBox::AcceptRole;
1433 QMessageBox box2(QMessageBox::Warning,
1434 tr("Untrusted Security Certificate"),
1435 tr("Would you like to accept this certificate forever without being prompted?"),
1437 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1438 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1440 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1445 #endif /* HAVE_SSL */
1447 void MainWin::handleCoreConnectionError(const QString &error)
1449 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1453 void MainWin::showCoreConnectionDlg()
1455 CoreConnectDlg dlg(this);
1456 if (dlg.exec() == QDialog::Accepted) {
1457 AccountId accId = dlg.selectedAccount();
1458 if (accId.isValid())
1459 Client::coreConnection()->connectToCore(accId);
1464 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1466 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1472 void MainWin::showChannelList(NetworkId netId)
1474 ChannelListDlg *channelListDlg = new ChannelListDlg();
1476 if (!netId.isValid()) {
1477 QAction *action = qobject_cast<QAction *>(sender());
1479 netId = action->data().value<NetworkId>();
1482 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1483 channelListDlg->setNetwork(netId);
1484 channelListDlg->show();
1488 void MainWin::showNetworkConfig(NetworkId netId)
1490 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
1491 if (netId.isValid())
1492 qobject_cast<NetworksSettingsPage *>(dlg.currentPage())->bufferList_Open(netId);
1497 void MainWin::showIgnoreList(QString newRule)
1499 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1500 // prepare config dialog for new rule
1501 if (!newRule.isEmpty())
1502 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1507 void MainWin::showCoreInfoDlg()
1509 CoreInfoDlg(this).exec();
1513 void MainWin::showAwayLog()
1517 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1518 _awayLog = new AwayLogView(filter, 0);
1519 filter->setParent(_awayLog);
1520 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1521 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1526 void MainWin::awayLogDestroyed()
1532 void MainWin::showSettingsDlg()
1534 SettingsDlg *dlg = new SettingsDlg();
1536 //Category: Interface
1537 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1538 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1539 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1540 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1541 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1542 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1543 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1544 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1546 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1548 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1549 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1550 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1551 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1554 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1555 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1556 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1557 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1558 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1559 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1561 // Category: Remote Cores
1562 if (Quassel::runMode() != Quassel::Monolithic) {
1563 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1564 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1571 void MainWin::showAboutDlg()
1573 AboutDlg(this).exec();
1577 void MainWin::showShortcutsDlg()
1580 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1581 foreach(KActionCollection *coll, QtUi::actionCollections())
1582 dlg.addCollection(coll, coll->property("Category").toString());
1583 dlg.configure(true);
1585 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1591 void MainWin::showNewTransferDlg(const QUuid &transferId)
1593 auto transfer = Client::transferManager()->transfer(transferId);
1595 if (transfer->status() == Transfer::Status::New) {
1596 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1601 qWarning() << "Unknown transfer ID" << transferId;
1606 void MainWin::onFullScreenToggled()
1608 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1609 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1612 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1614 if (_fullScreenAction->isChecked())
1615 setWindowState(windowState() | Qt::WindowFullScreen);
1617 setWindowState(windowState() & ~Qt::WindowFullScreen);
1622 /********************************************************************************************************/
1624 bool MainWin::event(QEvent *event)
1626 switch(event->type()) {
1627 case QEvent::WindowActivate: {
1628 BufferId bufferId = Client::bufferModel()->currentBuffer();
1629 if (bufferId.isValid())
1630 Client::instance()->markBufferAsRead(bufferId);
1633 case QEvent::WindowDeactivate:
1634 if (bufferWidget()->autoMarkerLineOnLostFocus())
1635 bufferWidget()->setMarkerLine();
1640 return QMainWindow::event(event);
1644 void MainWin::moveEvent(QMoveEvent *event)
1646 if (!(windowState() & Qt::WindowMaximized))
1647 _normalPos = event->pos();
1649 QMainWindow::moveEvent(event);
1653 void MainWin::resizeEvent(QResizeEvent *event)
1655 if (!(windowState() & Qt::WindowMaximized))
1656 _normalSize = event->size();
1658 QMainWindow::resizeEvent(event);
1662 void MainWin::closeEvent(QCloseEvent *event)
1665 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1667 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1668 // This messes up MainWinState/MainWinHidden save/restore.
1669 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1670 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1671 QtUi::hideMainWidget();
1674 else if(!_aboutToQuit) {
1675 _aboutToQuit = true;
1685 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1689 bool hasFocus = QApplication::activeWindow() != 0;
1691 for (int i = start; i <= end; i++) {
1692 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1693 if (!idx.isValid()) {
1694 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1697 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1698 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1701 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1702 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1704 // check if bufferId belongs to the shown chatlists
1705 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1706 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1709 // check if it's the buffer currently displayed
1710 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1713 // only show notifications for higlights or queries
1714 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1717 // and of course: don't notify for ignored messages
1718 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1721 // seems like we have a legit notification candidate!
1722 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1723 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1724 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1725 AbstractNotificationBackend::NotificationType type;
1727 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1728 type = AbstractNotificationBackend::PrivMsg;
1729 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1730 type = AbstractNotificationBackend::PrivMsgFocused;
1731 else if (flags & Message::Highlight && !hasFocus)
1732 type = AbstractNotificationBackend::Highlight;
1734 type = AbstractNotificationBackend::HighlightFocused;
1736 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1741 void MainWin::currentBufferChanged(BufferId buffer)
1743 if (buffer.isValid())
1744 Client::instance()->markBufferAsRead(buffer);
1748 void MainWin::clientNetworkCreated(NetworkId id)
1750 const Network *net = Client::network(id);
1751 QAction *act = new QAction(net->networkName(), this);
1752 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1753 act->setData(QVariant::fromValue<NetworkId>(id));
1754 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1755 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1757 QAction *beforeAction = 0;
1758 foreach(QAction *action, _networksMenu->actions()) {
1759 if (!action->data().isValid()) // ignore stock actions
1761 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1762 beforeAction = action;
1766 _networksMenu->insertAction(beforeAction, act);
1770 void MainWin::clientNetworkUpdated()
1772 const Network *net = qobject_cast<const Network *>(sender());
1776 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1780 action->setText(net->networkName());
1782 switch (net->connectionState()) {
1783 case Network::Initialized:
1784 action->setIcon(icon::get("network-connect"));
1785 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1786 if (!bufferWidget()->currentBuffer().isValid()) {
1787 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1788 if (idx.isValid()) {
1789 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1790 Client::bufferModel()->switchToBuffer(statusBufferId);
1794 case Network::Disconnected:
1795 action->setIcon(icon::get("network-disconnect"));
1798 action->setIcon(icon::get("network-wired"));
1803 void MainWin::clientNetworkRemoved(NetworkId id)
1805 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1809 action->deleteLater();
1813 void MainWin::connectOrDisconnectFromNet()
1815 QAction *act = qobject_cast<QAction *>(sender());
1817 const Network *net = Client::network(act->data().value<NetworkId>());
1819 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1820 else net->requestDisconnect();
1824 void MainWin::on_inputFormatApplyColor_triggered()
1829 _inputWidget->applyFormatActiveColor();
1833 void MainWin::on_inputFormatApplyColorFill_triggered()
1838 _inputWidget->applyFormatActiveColorFill();
1842 void MainWin::on_inputFormatClear_triggered()
1847 _inputWidget->clearFormat();
1851 void MainWin::on_inputFormatBold_triggered()
1856 _inputWidget->toggleFormatBold();
1860 void MainWin::on_inputFormatItalic_triggered()
1865 _inputWidget->toggleFormatItalic();
1869 void MainWin::on_inputFormatUnderline_triggered()
1874 _inputWidget->toggleFormatUnderline();
1878 void MainWin::on_jumpHotBuffer_triggered()
1880 if (!_bufferHotList->rowCount())
1883 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1886 void MainWin::on_bufferSearch_triggered()
1888 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1889 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1893 _bufferViews[_activeBufferViewIndex]->activateFilter();
1897 void MainWin::onJumpKey()
1899 QAction *action = qobject_cast<QAction *>(sender());
1900 if (!action || !Client::bufferModel())
1902 int idx = action->property("Index").toInt();
1904 if (_jumpKeyMap.isEmpty())
1905 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1907 if (!_jumpKeyMap.contains(idx))
1910 BufferId buffer = _jumpKeyMap.value(idx);
1911 if (buffer.isValid())
1912 Client::bufferModel()->switchToBuffer(buffer);
1916 void MainWin::bindJumpKey()
1918 QAction *action = qobject_cast<QAction *>(sender());
1919 if (!action || !Client::bufferModel())
1921 int idx = action->property("Index").toInt();
1923 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1924 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1928 void MainWin::on_actionDebugNetworkModel_triggered()
1930 QTreeView *view = new QTreeView;
1931 view->setAttribute(Qt::WA_DeleteOnClose);
1932 view->setWindowTitle("Debug NetworkModel View");
1933 view->setModel(Client::networkModel());
1934 view->setColumnWidth(0, 250);
1935 view->setColumnWidth(1, 250);
1936 view->setColumnWidth(2, 80);
1937 view->resize(610, 300);
1942 void MainWin::on_actionDebugHotList_triggered()
1944 _bufferHotList->invalidate();
1945 _bufferHotList->sort(0, Qt::DescendingOrder);
1947 QTreeView *view = new QTreeView;
1948 view->setAttribute(Qt::WA_DeleteOnClose);
1949 view->setModel(_bufferHotList);
1954 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1956 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1957 overlay->setAttribute(Qt::WA_DeleteOnClose);
1962 void MainWin::on_actionDebugMessageModel_triggered()
1964 QTableView *view = new QTableView(0);
1965 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1966 filter->setSourceModel(Client::messageModel());
1967 view->setModel(filter);
1968 view->setAttribute(Qt::WA_DeleteOnClose, true);
1969 view->verticalHeader()->hide();
1970 view->horizontalHeader()->setStretchLastSection(true);
1975 void MainWin::on_actionDebugLog_triggered()
1977 DebugLogWidget *logWidget = new DebugLogWidget(0);
1982 void MainWin::showStatusBarMessage(const QString &message)
1984 statusBar()->showMessage(message, 10000);