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(),
210 SIGNAL(showChannelList(NetworkId,QString,bool)),
211 SLOT(showChannelList(NetworkId,QString,bool)));
212 connect(Client::instance(),
213 SIGNAL(showChannelList(NetworkId,QString,bool)),
214 SLOT(showChannelList(NetworkId,QString,bool)));
215 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showNetworkConfig(NetworkId)), SLOT(showNetworkConfig(NetworkId)));
216 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
217 connect(Client::instance(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
218 connect(Client::instance(), SIGNAL(dbUpgradeInProgress(bool)), SLOT(showMigrationWarning(bool)));
219 connect(Client::instance(), SIGNAL(exitRequested(QString)), SLOT(onExitRequested(QString)));
221 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList, QVariantList)), SLOT(showCoreConfigWizard(QVariantList, QVariantList)));
222 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
223 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
224 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
225 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
227 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
231 setDockNestingEnabled(true);
232 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
233 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
234 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
235 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
237 // Order is sometimes important
241 // setupTransferWidget(); not ready yet
253 _bufferWidget->setFocusProxy(_inputWidget);
254 _chatMonitorView->setFocusProxy(_inputWidget);
257 # ifdef HAVE_QTMULTIMEDIA
258 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
261 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
263 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
265 QtUi::registerNotificationBackend(new KNotificationBackend(this));
266 #endif /* HAVE_KDE */
269 #ifndef QT_NO_SYSTEMTRAYICON
270 QtUi::registerNotificationBackend(new SystrayAnimationNotificationBackend(this));
273 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
274 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
275 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
278 #ifdef HAVE_INDICATEQT
279 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
282 #ifdef HAVE_NOTIFICATION_CENTER
283 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
287 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
290 // we assume that at this point, all configurable actions are defined!
291 QtUi::loadShortcuts();
293 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
295 setDisconnectedState(); // Disable menus and stuff
298 setAutoSaveSettings();
301 // restore mainwin state
303 restoreStateFromSettings(s);
305 // restore locked state of docks
306 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
308 Quassel::registerQuitHandler([this]() {
310 saveStateToSettings(s);
312 // Close all open dialogs and the MainWin, so we can safely kill the Client instance afterwards
313 // Note: This does not quit the application, as quitOnLastWindowClosed is set to false.
314 // We rely on another quit handler to be registered that actually quits the application.
315 qApp->closeAllWindows();
318 QTimer::singleShot(0, this, SLOT(doAutoConnect()));
322 void MainWin::saveStateToSettings(UiSettings &s)
324 s.setValue("MainWinSize", _normalSize);
325 s.setValue("MainWinPos", _normalPos);
326 s.setValue("MainWinState", saveState());
327 s.setValue("MainWinGeometry", saveGeometry());
328 s.setValue("MainWinMinimized", isMinimized());
329 s.setValue("MainWinMaximized", isMaximized());
330 s.setValue("MainWinHidden", !isVisible());
331 BufferId lastBufId = Client::bufferModel()->currentBuffer();
332 if (lastBufId.isValid())
333 s.setValue("LastUsedBufferId", lastBufId.toInt());
336 saveAutoSaveSettings();
341 void MainWin::restoreStateFromSettings(UiSettings &s)
343 _normalSize = s.value("MainWinSize", size()).toSize();
344 _normalPos = s.value("MainWinPos", pos()).toPoint();
345 bool maximized = s.value("MainWinMaximized", false).toBool();
348 restoreGeometry(s.value("MainWinGeometry").toByteArray());
351 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
356 restoreState(s.value("MainWinState").toByteArray());
362 if ((Quassel::isOptionSet("hidewindow")
363 || s.value("MainWinHidden").toBool())
364 && _systemTray->isSystemTrayAvailable())
365 QtUi::hideMainWidget();
366 else if (s.value("MainWinMinimized").toBool())
374 QMenu *MainWin::createPopupMenu()
376 QMenu *popupMenu = QMainWindow::createPopupMenu();
377 popupMenu->addSeparator();
378 ActionCollection *coll = QtUi::actionCollection("General");
379 popupMenu->addAction(coll->action("ToggleMenuBar"));
384 void MainWin::updateIcon()
387 if (Client::isConnected())
388 icon = icon::get("quassel");
390 icon = icon::get("inactive-quassel");
395 void MainWin::setupActions()
397 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
399 coll->addAction("ConnectCore", new Action(icon::get("connect-quassel"), tr("&Connect to Core..."), coll,
400 this, SLOT(showCoreConnectionDlg())));
401 coll->addAction("DisconnectCore", new Action(icon::get("disconnect-quassel"), tr("&Disconnect from Core"), coll,
402 Client::instance(), SLOT(disconnectFromCore())));
403 coll->addAction("ChangePassword", new Action(icon::get("dialog-password"), tr("Change &Password..."), coll,
404 this, SLOT(showPasswordChangeDlg())));
405 coll->addAction("CoreInfo", new Action(icon::get("help-about"), tr("Core &Info..."), coll,
406 this, SLOT(showCoreInfoDlg())));
407 coll->addAction("ConfigureNetworks", new Action(icon::get("configure"), tr("Configure &Networks..."), coll,
408 this, SLOT(on_actionConfigureNetworks_triggered())));
409 // QKeySequence::Quit was added in Qt 4.6, and could be used instead. However, that key
410 // sequence is empty by default on Windows, which would remove Ctrl-Q to quit. It may be best
411 // to just keep it this way.
413 // See https://doc.qt.io/qt-5/qkeysequence.html
414 coll->addAction("Quit", new Action(icon::get("application-exit"), tr("&Quit"), coll,
415 Quassel::instance(), SLOT(quit()), Qt::CTRL + Qt::Key_Q));
418 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
419 this, SLOT(on_actionConfigureViews_triggered())));
421 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
422 lockAct->setCheckable(true);
423 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
425 coll->addAction("ToggleSearchBar", new Action(icon::get("edit-find"), tr("Show &Search Bar"), coll,
426 0, 0, QKeySequence::Find))->setCheckable(true);
427 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
428 this, SLOT(showAwayLog())));
429 coll->addAction("ToggleMenuBar", new Action(icon::get("show-menu"), tr("Show &Menubar"), coll,
430 0, 0))->setCheckable(true);
432 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
433 0, 0))->setCheckable(true);
436 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
438 _fullScreenAction = new Action(icon::get("view-fullscreen"), tr("&Full Screen Mode"), coll,
439 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
440 _fullScreenAction->setCheckable(true);
441 coll->addAction("ToggleFullScreen", _fullScreenAction);
445 QAction *configureShortcutsAct = new Action(icon::get("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
446 this, SLOT(showShortcutsDlg()));
447 configureShortcutsAct->setMenuRole(QAction::NoRole);
448 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
451 QAction *configureQuasselAct = new Action(icon::get("configure"), tr("&Configure Quassel..."), coll,
452 this, SLOT(showSettingsDlg()));
453 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
455 QAction *configureQuasselAct = new Action(icon::get("configure"), tr("&Configure Quassel..."), coll,
456 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
458 coll->addAction("ConfigureQuassel", configureQuasselAct);
461 QAction *aboutQuasselAct = new Action(icon::get("quassel"), tr("&About Quassel"), coll,
462 this, SLOT(showAboutDlg()));
463 aboutQuasselAct->setMenuRole(QAction::AboutRole);
464 coll->addAction("AboutQuassel", aboutQuasselAct);
466 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
467 qApp, SLOT(aboutQt()));
468 aboutQtAct->setMenuRole(QAction::AboutQtRole);
469 coll->addAction("AboutQt", aboutQtAct);
470 coll->addAction("DebugNetworkModel", new Action(icon::get("tools-report-bug"), tr("Debug &NetworkModel"), coll,
471 this, SLOT(on_actionDebugNetworkModel_triggered())));
472 coll->addAction("DebugBufferViewOverlay", new Action(icon::get("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
473 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
474 coll->addAction("DebugMessageModel", new Action(icon::get("tools-report-bug"), tr("Debug &MessageModel"), coll,
475 this, SLOT(on_actionDebugMessageModel_triggered())));
476 coll->addAction("DebugHotList", new Action(icon::get("tools-report-bug"), tr("Debug &HotList"), coll,
477 this, SLOT(on_actionDebugHotList_triggered())));
478 coll->addAction("DebugLog", new Action(icon::get("tools-report-bug"), tr("Debug &Log"), coll,
479 this, SLOT(on_actionDebugLog_triggered())));
480 coll->addAction("ReloadStyle", new Action(icon::get("view-refresh"), tr("Reload Stylesheet"), coll,
481 QtUi::style(), SLOT(reload()), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_R)));
483 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
484 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
487 coll = QtUi::actionCollection("TextFormat", tr("Text formatting"));
489 coll->addAction("FormatApplyColor", new Action(
490 icon::get("format-text-color"), tr("Apply foreground color"), coll,
491 this, SLOT(on_inputFormatApplyColor_triggered()),
492 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_G)));
494 coll->addAction("FormatApplyColorFill", new Action(
495 icon::get("format-fill-color"), tr("Apply background color"), coll,
496 this, SLOT(on_inputFormatApplyColorFill_triggered()),
497 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B)));
499 coll->addAction("FormatClear", new Action(
500 icon::get("edit-clear"), tr("Clear formatting"), coll,
501 this, SLOT(on_inputFormatClear_triggered()),
502 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C)));
504 coll->addAction("FormatBold", new Action(
505 icon::get("format-text-bold"), tr("Toggle bold"), coll,
506 this, SLOT(on_inputFormatBold_triggered()),
507 QKeySequence::Bold));
509 coll->addAction("FormatItalic", new Action(
510 icon::get("format-text-italic"), tr("Toggle italics"), coll,
511 this, SLOT(on_inputFormatItalic_triggered()),
512 QKeySequence::Italic));
514 coll->addAction("FormatUnderline", new Action(
515 icon::get("format-text-underline"), tr("Toggle underline"), coll,
516 this, SLOT(on_inputFormatUnderline_triggered()), QKeySequence::Underline));
519 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
521 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
522 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
524 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
525 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
529 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
530 const int jumpModifier = Qt::ControlModifier;
532 const int bindModifier = Qt::ControlModifier;
533 const int jumpModifier = Qt::AltModifier;
536 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
537 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
538 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
539 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
540 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
541 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
542 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
543 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
544 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
545 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
546 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
547 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
548 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
549 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
550 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
551 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
552 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
553 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
554 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
555 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
557 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
558 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
559 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
560 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
561 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
562 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
563 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
564 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
565 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
566 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
567 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
568 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
569 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
570 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
571 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
572 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
573 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
574 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
575 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
576 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
579 coll->addAction("NextBufferView", new Action(icon::get("go-next-view"), tr("Activate Next Chat List"), coll,
580 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
581 coll->addAction("PreviousBufferView", new Action(icon::get("go-previous-view"), tr("Activate Previous Chat List"), coll,
582 this, SLOT(previousBufferView()), QKeySequence::Back));
583 coll->addAction("NextBuffer", new Action(icon::get("go-down"), tr("Go to Next Chat"), coll,
584 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
585 coll->addAction("PreviousBuffer", new Action(icon::get("go-up"), tr("Go to Previous Chat"), coll,
586 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
590 void MainWin::setupMenus()
592 ActionCollection *coll = QtUi::actionCollection("General");
594 _fileMenu = menuBar()->addMenu(tr("&File"));
596 static const QStringList coreActions = QStringList()
597 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
600 foreach(QString actionName, coreActions) {
601 coreAction = coll->action(actionName);
602 _fileMenu->addAction(coreAction);
603 flagRemoteCoreOnly(coreAction);
605 flagRemoteCoreOnly(_fileMenu->addSeparator());
607 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
608 _networksMenu->addAction(coll->action("ConfigureNetworks"));
609 _networksMenu->addSeparator();
610 _fileMenu->addSeparator();
611 _fileMenu->addAction(coll->action("Quit"));
613 _viewMenu = menuBar()->addMenu(tr("&View"));
614 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
615 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
616 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
617 _viewMenu->addSeparator();
619 _viewMenu->addAction(coll->action("ToggleMenuBar"));
620 _viewMenu->addAction(coll->action("ToggleStatusBar"));
621 _viewMenu->addAction(coll->action("ToggleSearchBar"));
623 coreAction = coll->action("ShowAwayLog");
624 flagRemoteCoreOnly(coreAction);
625 _viewMenu->addAction(coreAction);
627 _viewMenu->addSeparator();
628 _viewMenu->addAction(coll->action("LockLayout"));
630 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
632 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
633 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
635 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
637 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
640 _helpMenu = menuBar()->addMenu(tr("&Help"));
642 _helpMenu->addAction(coll->action("AboutQuassel"));
644 _helpMenu->addAction(coll->action("AboutQt"));
646 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
648 _helpMenu->addSeparator();
649 _helpDebugMenu = _helpMenu->addMenu(icon::get("tools-report-bug"), tr("Debug"));
650 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
651 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
652 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
653 _helpDebugMenu->addAction(coll->action("DebugHotList"));
654 _helpDebugMenu->addAction(coll->action("DebugLog"));
655 _helpDebugMenu->addSeparator();
656 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
659 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
661 QtUiSettings uiSettings;
662 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
663 showMenuBar->setChecked(enabled);
664 enabled ? menuBar()->show() : menuBar()->hide();
666 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
667 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
671 void MainWin::setupBufferWidget()
673 _bufferWidget = new BufferWidget(this);
674 _bufferWidget->setModel(Client::bufferModel());
675 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
676 setCentralWidget(_bufferWidget);
680 void MainWin::addBufferView(int bufferViewConfigId)
682 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
686 void MainWin::addBufferView(ClientBufferViewConfig *config)
691 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
692 BufferViewDock *dock = new BufferViewDock(config, this);
694 //create the view and initialize it's filter
695 BufferView *view = new BufferView(dock);
696 view->setFilteredModel(Client::bufferModel(), config);
697 view->installEventFilter(_inputWidget); // for key presses
699 Client::bufferModel()->synchronizeView(view);
701 dock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
703 dock->setWidget(view);
704 dock->setVisible(_layoutLoaded); // don't show before state has been restored
706 addDockWidget(Qt::LeftDockWidgetArea, dock);
707 _bufferViewsMenu->addAction(dock->toggleViewAction());
709 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
710 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
711 _bufferViews.append(dock);
713 if (!activeBufferView())
718 void MainWin::removeBufferView(int bufferViewConfigId)
721 BufferViewDock *dock;
722 foreach(QAction *action, _bufferViewsMenu->actions()) {
723 actionData = action->data();
724 if (!actionData.isValid())
727 dock = qobject_cast<BufferViewDock *>(action->parent());
728 if (dock && actionData.toInt() == bufferViewConfigId) {
729 removeAction(action);
730 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
731 _bufferViews.removeAll(dock);
733 if (dock->isActive()) {
734 dock->setActive(false);
735 _activeBufferViewIndex = -1;
745 void MainWin::bufferViewToggled(bool enabled)
747 if (!enabled && !isMinimized()) {
748 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
749 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
752 QAction *action = qobject_cast<QAction *>(sender());
754 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
757 // Make sure we don't toggle backlog fetch for a view we've already removed
758 if (!_bufferViews.contains(dock))
762 Client::bufferViewOverlay()->addView(dock->bufferViewId());
764 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
768 void MainWin::bufferViewVisibilityChanged(bool visible)
771 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
773 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
778 BufferView *MainWin::allBuffersView() const
780 // "All Buffers" is always the first dock created
781 if (_bufferViews.count() > 0)
782 return _bufferViews[0]->bufferView();
787 BufferView *MainWin::activeBufferView() const
789 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
791 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
792 return dock->isActive() ? dock->bufferView() : 0;
796 void MainWin::changeActiveBufferView(int bufferViewId)
798 if (bufferViewId < 0)
801 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
802 _bufferViews[_activeBufferViewIndex]->setActive(false);
803 _activeBufferViewIndex = -1;
806 for (int i = 0; i < _bufferViews.count(); i++) {
807 BufferViewDock *dock = _bufferViews.at(i);
808 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
809 _activeBufferViewIndex = i;
810 dock->setActive(true);
815 nextBufferView(); // fallback
819 void MainWin::showPasswordChangeDlg()
821 if(Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
822 PasswordChangeDlg dlg(this);
826 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
827 tr("<b>Your Quassel Core does not support this feature</b>"),
828 QMessageBox::Ok, this);
829 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
835 void MainWin::showMigrationWarning(bool show)
837 if (show && !_migrationWarning) {
838 _migrationWarning = new QMessageBox(QMessageBox::Information,
840 "<b>" + tr("Your database is being upgraded") + "</b>",
841 QMessageBox::NoButton, this);
842 _migrationWarning->setInformativeText("<p>"
843 + tr("In order to support new features, we need to make changes to your backlog database. This may take a long while.")
845 + tr("Do not exit Quassel until the upgrade is complete!")
847 _migrationWarning->setStandardButtons(QMessageBox::NoButton);
848 _migrationWarning->show();
850 else if (!show && _migrationWarning) {
851 _migrationWarning->close();
852 _migrationWarning->deleteLater();
853 _migrationWarning = nullptr;
858 void MainWin::onExitRequested(const QString &reason)
860 if (!reason.isEmpty()) {
861 QMessageBox box(QMessageBox::Critical,
863 "<b>" + tr("Quassel encountered a fatal error and is terminated.") + "</b>",
864 QMessageBox::Ok, this);
865 box.setInformativeText("<p>" + tr("Reason:<em>") + " " + reason + "</em>");
871 void MainWin::changeActiveBufferView(bool backwards)
873 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
874 _bufferViews[_activeBufferViewIndex]->setActive(false);
877 if (!_bufferViews.count())
880 int c = _bufferViews.count();
881 while (c--) { // yes, this will reactivate the current active one if all others fail
883 if (--_activeBufferViewIndex < 0)
884 _activeBufferViewIndex = _bufferViews.count()-1;
887 if (++_activeBufferViewIndex >= _bufferViews.count())
888 _activeBufferViewIndex = 0;
891 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
892 if (dock->isHidden())
895 dock->setActive(true);
899 _activeBufferViewIndex = -1;
903 void MainWin::nextBufferView()
905 changeActiveBufferView(false);
909 void MainWin::previousBufferView()
911 changeActiveBufferView(true);
915 void MainWin::nextBuffer()
917 BufferView *view = activeBufferView();
923 void MainWin::previousBuffer()
925 BufferView *view = activeBufferView();
927 view->previousBuffer();
931 void MainWin::hideCurrentBuffer()
933 BufferView *view = activeBufferView();
935 view->hideCurrentBuffer();
939 void MainWin::showNotificationsDlg()
941 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
946 void MainWin::on_actionConfigureNetworks_triggered()
948 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
953 void MainWin::on_actionConfigureViews_triggered()
955 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
960 void MainWin::on_actionLockLayout_toggled(bool lock)
962 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
963 foreach(VerticalDock *dock, docks) {
964 dock->showTitle(!lock);
967 QList<NickListDock *> nickdocks = findChildren<NickListDock *>();
968 foreach(NickListDock *nickdock, nickdocks) {
969 nickdock->setLocked(lock);
972 QList<BufferViewDock *> bufferdocks = findChildren<BufferViewDock *>();
973 foreach(BufferViewDock *bufferdock, bufferdocks) {
974 bufferdock->setLocked(lock);
977 if (Client::bufferViewManager()) {
978 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
979 config->setLocked(lock);
983 _mainToolBar->setMovable(!lock);
984 _nickToolBar->setMovable(!lock);
986 QtUiSettings().setValue("LockLayout", lock);
990 void MainWin::setupNickWidget()
993 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
994 nickDock->setObjectName("NickDock");
995 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
996 nickDock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
998 _nickListWidget = new NickListWidget(nickDock);
999 nickDock->setWidget(_nickListWidget);
1001 addDockWidget(Qt::RightDockWidgetArea, nickDock);
1002 _viewMenu->addAction(nickDock->toggleViewAction());
1003 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
1005 // See NickListDock::NickListDock();
1006 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
1008 // attach the NickListWidget to the BufferModel and the default selection
1009 _nickListWidget->setModel(Client::bufferModel());
1010 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1012 _nickListWidget->setVisible(false);
1016 void MainWin::setupChatMonitor()
1018 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
1019 dock->setObjectName("ChatMonitorDock");
1021 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
1022 _chatMonitorView = new ChatMonitorView(filter, this);
1023 _chatMonitorView->show();
1024 dock->setWidget(_chatMonitorView);
1027 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1028 _viewMenu->addAction(dock->toggleViewAction());
1029 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
1033 void MainWin::setupInputWidget()
1035 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
1036 dock->setObjectName("InputDock");
1038 _inputWidget = new InputWidget(dock);
1039 dock->setWidget(_inputWidget);
1041 addDockWidget(Qt::BottomDockWidgetArea, dock);
1043 _viewMenu->addAction(dock->toggleViewAction());
1044 dock->toggleViewAction()->setText(tr("Show Input Line"));
1046 _inputWidget->setModel(Client::bufferModel());
1047 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1049 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
1051 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
1055 void MainWin::setupTopicWidget()
1057 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
1058 dock->setObjectName("TopicDock");
1059 _topicWidget = new TopicWidget(dock);
1061 dock->setWidget(_topicWidget);
1063 _topicWidget->setModel(Client::bufferModel());
1064 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1066 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1068 _viewMenu->addAction(dock->toggleViewAction());
1069 dock->toggleViewAction()->setText(tr("Show Topic Line"));
1073 void MainWin::setupTransferWidget()
1075 auto dock = new QDockWidget(tr("Transfers"), this);
1076 dock->setObjectName("TransferDock");
1077 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
1079 auto view = new QTableView(dock); // to be replaced by the real thing
1080 view->setModel(Client::transferModel());
1081 dock->setWidget(view);
1082 dock->hide(); // hidden by default
1083 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1085 auto action = dock->toggleViewAction();
1086 action->setText(tr("Show File Transfers"));
1087 action->setIcon(icon::get("download"));
1088 action->setShortcut(QKeySequence(Qt::Key_F6));
1089 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
1090 _viewMenu->addAction(action);
1094 void MainWin::setupViewMenuTail()
1096 _viewMenu->addSeparator();
1097 _viewMenu->addAction(_fullScreenAction);
1101 void MainWin::setupTitleSetter()
1103 _titleSetter.setModel(Client::bufferModel());
1104 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1108 void MainWin::setupStatusBar()
1110 // MessageProcessor progress
1111 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1114 _coreConnectionStatusWidget->update();
1115 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1117 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1119 QtUiSettings uiSettings;
1121 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1122 showStatusbar->setChecked(enabled);
1123 enabled ? statusBar()->show() : statusBar()->hide();
1125 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1126 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1128 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1132 void MainWin::setupHotList()
1134 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1135 flatProxy->setSourceModel(Client::bufferModel());
1136 _bufferHotList = new BufferHotListFilter(flatProxy);
1140 void MainWin::saveMenuBarStatus(bool enabled)
1142 QtUiSettings uiSettings;
1143 uiSettings.setValue("ShowMenuBar", enabled);
1147 void MainWin::saveStatusBarStatus(bool enabled)
1149 QtUiSettings uiSettings;
1150 uiSettings.setValue("ShowStatusBar", enabled);
1154 void MainWin::setupSystray()
1157 _systemTray = new StatusNotifierItem(this);
1158 #elif !defined QT_NO_SYSTEMTRAYICON
1159 _systemTray = new LegacySystemTray(this);
1161 _systemTray = new SystemTray(this); // dummy
1166 void MainWin::setupToolBars()
1168 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1169 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1170 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1171 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1174 setUnifiedTitleAndToolBarOnMac(true);
1178 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1180 _mainToolBar = new QToolBar(this);
1181 _mainToolBar->setObjectName("MainToolBar");
1183 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1184 addToolBar(_mainToolBar);
1186 if (Quassel::runMode() != Quassel::Monolithic) {
1187 ActionCollection *coll = QtUi::actionCollection("General");
1188 _mainToolBar->addAction(coll->action("ConnectCore"));
1189 _mainToolBar->addAction(coll->action("DisconnectCore"));
1192 _mainToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1194 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1195 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1198 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1200 _nickToolBar = new QToolBar(this);
1201 _nickToolBar->setObjectName("NickToolBar");
1203 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1204 _nickToolBar->setVisible(false); //default: not visible
1205 addToolBar(_nickToolBar);
1206 _nickToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1208 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1209 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1212 QtUiSettings uiSettings;
1214 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1215 _mainToolBar->setVisible(visible);
1216 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1220 void MainWin::saveMainToolBarStatus(bool enabled)
1223 QtUiSettings uiSettings;
1224 uiSettings.setValue("ShowMainToolBar", enabled);
1231 void MainWin::doAutoConnect()
1233 if (!Client::coreConnection()->connectToCore()) {
1234 // No autoconnect selected (or no accounts)
1235 showCoreConnectionDlg();
1240 void MainWin::connectedToCore()
1242 Q_CHECK_PTR(Client::bufferViewManager());
1243 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1244 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1245 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1247 if (Client::transferManager()) {
1248 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1251 setConnectedState();
1255 void MainWin::setConnectedState()
1257 ActionCollection *coll = QtUi::actionCollection("General");
1259 coll->action("ConnectCore")->setEnabled(false);
1260 coll->action("DisconnectCore")->setEnabled(true);
1261 coll->action("ChangePassword")->setEnabled(true);
1262 coll->action("CoreInfo")->setEnabled(true);
1264 foreach(QAction *action, _fileMenu->actions()) {
1265 if (isRemoteCoreOnly(action))
1266 action->setVisible(!Client::internalCore());
1269 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1270 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1271 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1272 if (!Client::internalCore()) {
1273 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1274 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1275 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1278 // _viewMenu->setEnabled(true);
1279 if (!Client::internalCore())
1280 statusBar()->showMessage(tr("Connected to core."));
1282 statusBar()->clearMessage();
1284 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1286 systemTray()->setState(SystemTray::Active);
1288 if (Client::networkIds().isEmpty()) {
1289 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1293 // Monolithic always preselects last used buffer - Client only if the connection died
1294 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1296 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1297 if (lastUsedBufferId.isValid())
1298 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1304 void MainWin::loadLayout()
1307 int accountId = Client::currentCoreAccount().accountId().toInt();
1308 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1309 if (state.isEmpty()) {
1310 foreach(BufferViewDock *view, _bufferViews)
1312 _layoutLoaded = true;
1315 _nickListWidget->setVisible(true);
1316 restoreState(state, accountId);
1317 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1318 if (bufferViewId >= 0)
1319 changeActiveBufferView(bufferViewId);
1321 _layoutLoaded = true;
1325 void MainWin::saveLayout()
1328 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1329 if (accountId > 0) {
1330 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1331 BufferView *view = activeBufferView();
1332 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1337 void MainWin::disconnectedFromCore()
1339 // save core specific layout and remove bufferviews;
1341 _layoutLoaded = false;
1343 QVariant actionData;
1344 BufferViewDock *dock;
1345 foreach(QAction *action, _bufferViewsMenu->actions()) {
1346 actionData = action->data();
1347 if (!actionData.isValid())
1350 dock = qobject_cast<BufferViewDock *>(action->parent());
1351 if (dock && actionData.toInt() != -1) {
1352 removeAction(action);
1353 _bufferViews.removeAll(dock);
1354 dock->deleteLater();
1358 // store last active buffer
1360 BufferId lastBufId = _bufferWidget->currentBuffer();
1361 if (lastBufId.isValid()) {
1362 s.setValue("LastUsedBufferId", lastBufId.toInt());
1363 // clear the current selection
1364 Client::bufferModel()->standardSelectionModel()->clearSelection();
1366 restoreState(s.value("MainWinState").toByteArray());
1367 setDisconnectedState();
1371 void MainWin::setDisconnectedState()
1373 ActionCollection *coll = QtUi::actionCollection("General");
1374 //ui.menuCore->setEnabled(false);
1375 coll->action("ConnectCore")->setEnabled(true);
1376 coll->action("DisconnectCore")->setEnabled(false);
1377 coll->action("CoreInfo")->setEnabled(false);
1378 coll->action("ChangePassword")->setEnabled(false);
1379 //_viewMenu->setEnabled(false);
1380 statusBar()->showMessage(tr("Not connected to core."));
1381 if (_msgProcessorStatusWidget)
1382 _msgProcessorStatusWidget->setProgress(0, 0);
1384 systemTray()->setState(SystemTray::Passive);
1385 _nickListWidget->setVisible(false);
1389 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1391 Q_UNUSED(errorMessage)
1392 CoreConnectAuthDlg dlg(account, this);
1393 *valid = (dlg.exec() == QDialog::Accepted);
1397 void MainWin::handleNoSslInClient(bool *accepted)
1399 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1400 QMessageBox::Ignore|QMessageBox::Cancel, this);
1401 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1402 box.setDefaultButton(QMessageBox::Ignore);
1403 *accepted = box.exec() == QMessageBox::Ignore;
1407 void MainWin::handleNoSslInCore(bool *accepted)
1409 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1410 QMessageBox::Ignore|QMessageBox::Cancel, this);
1411 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1412 box.setDefaultButton(QMessageBox::Ignore);
1413 *accepted = box.exec() == QMessageBox::Ignore;
1419 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1421 QString errorString = "<ul>";
1422 foreach(const QSslError error, socket->sslErrors())
1423 errorString += QString("<li>%1</li>").arg(error.errorString());
1424 errorString += "</ul>";
1426 QMessageBox box(QMessageBox::Warning,
1427 tr("Untrusted Security Certificate"),
1428 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1429 QMessageBox::Cancel, this);
1430 box.setInformativeText(errorString);
1431 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1432 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1434 QMessageBox::ButtonRole role;
1437 role = box.buttonRole(box.clickedButton());
1438 if (role == QMessageBox::HelpRole) {
1439 SslInfoDlg dlg(socket, this);
1443 while (role == QMessageBox::HelpRole);
1445 *accepted = role == QMessageBox::AcceptRole;
1447 QMessageBox box2(QMessageBox::Warning,
1448 tr("Untrusted Security Certificate"),
1449 tr("Would you like to accept this certificate forever without being prompted?"),
1451 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1452 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1454 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1459 #endif /* HAVE_SSL */
1461 void MainWin::handleCoreConnectionError(const QString &error)
1463 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1467 void MainWin::showCoreConnectionDlg()
1469 CoreConnectDlg dlg(this);
1470 if (dlg.exec() == QDialog::Accepted) {
1471 AccountId accId = dlg.selectedAccount();
1472 if (accId.isValid())
1473 Client::coreConnection()->connectToCore(accId);
1478 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1480 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1486 void MainWin::showChannelList(NetworkId netId, const QString &channelFilters, bool listImmediately)
1488 if (!netId.isValid()) {
1489 QAction *action = qobject_cast<QAction *>(sender());
1491 netId = action->data().value<NetworkId>();
1492 if (!netId.isValid()) {
1493 // We still haven't found a valid network, probably no network selected, e.g. "/list"
1494 // on the client homescreen when no networks are connected.
1495 QMessageBox box(QMessageBox::Information, tr("No network selected"),
1496 QString("<b>%1</b>").arg(tr("No network selected")),
1497 QMessageBox::Ok, this);
1498 box.setInformativeText(tr("Select a network before trying to view the channel list."));
1504 ChannelListDlg *channelListDlg = new ChannelListDlg(this);
1505 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1506 channelListDlg->setNetwork(netId);
1507 if (!channelFilters.isEmpty()) {
1508 channelListDlg->setChannelFilters(channelFilters);
1510 if (listImmediately) {
1511 channelListDlg->requestSearch();
1513 channelListDlg->show();
1517 void MainWin::showNetworkConfig(NetworkId netId)
1519 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
1520 if (netId.isValid())
1521 qobject_cast<NetworksSettingsPage *>(dlg.currentPage())->bufferList_Open(netId);
1526 void MainWin::showIgnoreList(QString newRule)
1528 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1529 // prepare config dialog for new rule
1530 if (!newRule.isEmpty())
1531 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1536 void MainWin::showCoreInfoDlg()
1538 CoreInfoDlg(this).exec();
1542 void MainWin::showAwayLog()
1546 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1547 _awayLog = new AwayLogView(filter, 0);
1548 filter->setParent(_awayLog);
1549 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1550 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1555 void MainWin::awayLogDestroyed()
1561 void MainWin::showSettingsDlg()
1563 SettingsDlg *dlg = new SettingsDlg();
1565 //Category: Interface
1566 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1567 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1568 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1569 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1570 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1571 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1572 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1573 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1575 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1577 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1578 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1579 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1580 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1583 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1584 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1585 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1586 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1587 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1588 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1590 // Category: Remote Cores
1591 if (Quassel::runMode() != Quassel::Monolithic) {
1592 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1593 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1600 void MainWin::showAboutDlg()
1602 AboutDlg(this).exec();
1606 void MainWin::showShortcutsDlg()
1609 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1610 foreach(KActionCollection *coll, QtUi::actionCollections())
1611 dlg.addCollection(coll, coll->property("Category").toString());
1612 dlg.configure(true);
1614 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1620 void MainWin::showNewTransferDlg(const QUuid &transferId)
1622 auto transfer = Client::transferManager()->transfer(transferId);
1624 if (transfer->status() == Transfer::Status::New) {
1625 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1630 qWarning() << "Unknown transfer ID" << transferId;
1635 void MainWin::onFullScreenToggled()
1637 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1638 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1641 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1643 if (_fullScreenAction->isChecked())
1644 setWindowState(windowState() | Qt::WindowFullScreen);
1646 setWindowState(windowState() & ~Qt::WindowFullScreen);
1651 /********************************************************************************************************/
1653 bool MainWin::event(QEvent *event)
1655 switch(event->type()) {
1656 case QEvent::WindowActivate: {
1657 BufferId bufferId = Client::bufferModel()->currentBuffer();
1658 if (bufferId.isValid())
1659 Client::instance()->markBufferAsRead(bufferId);
1662 case QEvent::WindowDeactivate:
1663 if (bufferWidget()->autoMarkerLineOnLostFocus())
1664 bufferWidget()->setMarkerLine();
1669 return QMainWindow::event(event);
1673 void MainWin::moveEvent(QMoveEvent *event)
1675 if (!(windowState() & Qt::WindowMaximized))
1676 _normalPos = event->pos();
1678 QMainWindow::moveEvent(event);
1682 void MainWin::resizeEvent(QResizeEvent *event)
1684 if (!(windowState() & Qt::WindowMaximized))
1685 _normalSize = event->size();
1687 QMainWindow::resizeEvent(event);
1691 void MainWin::closeEvent(QCloseEvent *event)
1694 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1696 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1697 // This messes up MainWinState/MainWinHidden save/restore.
1698 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1699 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1700 QtUi::hideMainWidget();
1703 else if(!_aboutToQuit) {
1704 _aboutToQuit = true;
1706 Quassel::instance()->quit();
1714 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1718 bool hasFocus = QApplication::activeWindow() != 0;
1720 for (int i = start; i <= end; i++) {
1721 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1722 if (!idx.isValid()) {
1723 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1726 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1727 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1730 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1731 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1733 // check if bufferId belongs to the shown chatlists
1734 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1735 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1738 // check if it's the buffer currently displayed
1739 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1742 // only show notifications for higlights or queries
1743 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1746 // and of course: don't notify for ignored messages
1747 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1750 // seems like we have a legit notification candidate!
1751 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1752 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1753 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1754 AbstractNotificationBackend::NotificationType type;
1756 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1757 type = AbstractNotificationBackend::PrivMsg;
1758 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1759 type = AbstractNotificationBackend::PrivMsgFocused;
1760 else if (flags & Message::Highlight && !hasFocus)
1761 type = AbstractNotificationBackend::Highlight;
1763 type = AbstractNotificationBackend::HighlightFocused;
1765 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1770 void MainWin::currentBufferChanged(BufferId buffer)
1772 if (buffer.isValid())
1773 Client::instance()->markBufferAsRead(buffer);
1777 void MainWin::clientNetworkCreated(NetworkId id)
1779 const Network *net = Client::network(id);
1780 QAction *act = new QAction(net->networkName(), this);
1781 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1782 act->setData(QVariant::fromValue<NetworkId>(id));
1783 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1784 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1786 QAction *beforeAction = 0;
1787 foreach(QAction *action, _networksMenu->actions()) {
1788 if (!action->data().isValid()) // ignore stock actions
1790 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1791 beforeAction = action;
1795 _networksMenu->insertAction(beforeAction, act);
1799 void MainWin::clientNetworkUpdated()
1801 const Network *net = qobject_cast<const Network *>(sender());
1805 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1809 action->setText(net->networkName());
1811 switch (net->connectionState()) {
1812 case Network::Initialized:
1813 action->setIcon(icon::get("network-connect"));
1814 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1815 if (!bufferWidget()->currentBuffer().isValid()) {
1816 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1817 if (idx.isValid()) {
1818 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1819 Client::bufferModel()->switchToBuffer(statusBufferId);
1823 case Network::Disconnected:
1824 action->setIcon(icon::get("network-disconnect"));
1827 action->setIcon(icon::get("network-wired"));
1832 void MainWin::clientNetworkRemoved(NetworkId id)
1834 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1838 action->deleteLater();
1842 void MainWin::connectOrDisconnectFromNet()
1844 QAction *act = qobject_cast<QAction *>(sender());
1846 const Network *net = Client::network(act->data().value<NetworkId>());
1848 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1849 else net->requestDisconnect();
1853 void MainWin::on_inputFormatApplyColor_triggered()
1858 _inputWidget->applyFormatActiveColor();
1862 void MainWin::on_inputFormatApplyColorFill_triggered()
1867 _inputWidget->applyFormatActiveColorFill();
1871 void MainWin::on_inputFormatClear_triggered()
1876 _inputWidget->clearFormat();
1880 void MainWin::on_inputFormatBold_triggered()
1885 _inputWidget->toggleFormatBold();
1889 void MainWin::on_inputFormatItalic_triggered()
1894 _inputWidget->toggleFormatItalic();
1898 void MainWin::on_inputFormatUnderline_triggered()
1903 _inputWidget->toggleFormatUnderline();
1907 void MainWin::on_jumpHotBuffer_triggered()
1909 if (!_bufferHotList->rowCount())
1912 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1915 void MainWin::on_bufferSearch_triggered()
1917 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1918 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1922 _bufferViews[_activeBufferViewIndex]->activateFilter();
1926 void MainWin::onJumpKey()
1928 QAction *action = qobject_cast<QAction *>(sender());
1929 if (!action || !Client::bufferModel())
1931 int idx = action->property("Index").toInt();
1933 if (_jumpKeyMap.isEmpty())
1934 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1936 if (!_jumpKeyMap.contains(idx))
1939 BufferId buffer = _jumpKeyMap.value(idx);
1940 if (buffer.isValid())
1941 Client::bufferModel()->switchToBuffer(buffer);
1945 void MainWin::bindJumpKey()
1947 QAction *action = qobject_cast<QAction *>(sender());
1948 if (!action || !Client::bufferModel())
1950 int idx = action->property("Index").toInt();
1952 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1953 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1957 void MainWin::on_actionDebugNetworkModel_triggered()
1959 QTreeView *view = new QTreeView;
1960 view->setAttribute(Qt::WA_DeleteOnClose);
1961 view->setWindowTitle("Debug NetworkModel View");
1962 view->setModel(Client::networkModel());
1963 view->setColumnWidth(0, 250);
1964 view->setColumnWidth(1, 250);
1965 view->setColumnWidth(2, 80);
1966 view->resize(610, 300);
1971 void MainWin::on_actionDebugHotList_triggered()
1973 _bufferHotList->invalidate();
1974 _bufferHotList->sort(0, Qt::DescendingOrder);
1976 QTreeView *view = new QTreeView;
1977 view->setAttribute(Qt::WA_DeleteOnClose);
1978 view->setModel(_bufferHotList);
1983 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1985 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1986 overlay->setAttribute(Qt::WA_DeleteOnClose);
1991 void MainWin::on_actionDebugMessageModel_triggered()
1993 QTableView *view = new QTableView(0);
1994 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1995 filter->setSourceModel(Client::messageModel());
1996 view->setModel(filter);
1997 view->setAttribute(Qt::WA_DeleteOnClose, true);
1998 view->verticalHeader()->hide();
1999 view->horizontalHeader()->setStretchLastSection(true);
2004 void MainWin::on_actionDebugLog_triggered()
2006 DebugLogWidget *logWidget = new DebugLogWidget(nullptr); // will be deleted on close
2011 void MainWin::showStatusBarMessage(const QString &message)
2013 statusBar()->showMessage(message, 10000);