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"
85 #include "inputwidget.h"
86 #include "irclistmodel.h"
87 #include "ircconnectionwizard.h"
88 #include "legacysystemtray.h"
89 #include "msgprocessorstatuswidget.h"
90 #include "nicklistwidget.h"
91 #include "passwordchangedlg.h"
92 #include "qtuiapplication.h"
93 #include "qtuimessageprocessor.h"
94 #include "qtuisettings.h"
95 #include "qtuistyle.h"
96 #include "receivefiledlg.h"
97 #include "settingsdlg.h"
98 #include "settingspagedlg.h"
99 #include "statusnotifieritem.h"
100 #include "toolbaractionprovider.h"
101 #include "topicwidget.h"
102 #include "transfermodel.h"
103 #include "verticaldock.h"
106 # ifdef HAVE_QTMULTIMEDIA
107 # include "qtmultimedianotificationbackend.h"
110 # include "phononnotificationbackend.h"
112 # include "systraynotificationbackend.h"
113 # include "taskbarnotificationbackend.h"
115 # include "knotificationbackend.h"
116 #endif /* HAVE_KDE */
120 # include "snorenotificationbackend.h"
124 # include "sslinfodlg.h"
127 #ifdef HAVE_INDICATEQT
128 #include "indicatornotificationbackend.h"
131 #ifdef HAVE_NOTIFICATION_CENTER
132 #include "osxnotificationbackend.h"
136 #include "dockmanagernotificationbackend.h"
139 #include "settingspages/aliasessettingspage.h"
140 #include "settingspages/appearancesettingspage.h"
141 #include "settingspages/backlogsettingspage.h"
142 #include "settingspages/bufferviewsettingspage.h"
143 #include "settingspages/chatmonitorsettingspage.h"
144 #include "settingspages/chatviewsettingspage.h"
145 #include "settingspages/chatviewcolorsettingspage.h"
146 #include "settingspages/connectionsettingspage.h"
147 #include "settingspages/coreaccountsettingspage.h"
148 #include "settingspages/coreconnectionsettingspage.h"
149 #include <settingspages/corehighlightsettingspage.h>
150 #include "settingspages/dccsettingspage.h"
151 #include "settingspages/highlightsettingspage.h"
152 #include "settingspages/identitiessettingspage.h"
153 #include "settingspages/ignorelistsettingspage.h"
154 #include "settingspages/inputwidgetsettingspage.h"
155 #include "settingspages/itemviewsettingspage.h"
156 #include "settingspages/networkssettingspage.h"
157 #include "settingspages/notificationssettingspage.h"
158 #include "settingspages/topicwidgetsettingspage.h"
161 # include "settingspages/shortcutssettingspage.h"
165 # include "settingspages/sonnetsettingspage.h"
169 MainWin::MainWin(QWidget *parent)
171 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
173 : QMainWindow(parent),
175 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
176 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
179 _layoutLoaded(false),
180 _activeBufferViewIndex(-1),
183 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
185 QtUiSettings uiSettings;
186 QString style = uiSettings.value("Style", QString()).toString();
187 if (!style.isEmpty()) {
188 QApplication::setStyle(style);
191 QApplication::setQuitOnLastWindowClosed(false);
193 setWindowTitle("Quassel IRC");
194 setWindowIconText("Quassel IRC");
201 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
202 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
203 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
204 SLOT(messagesInserted(const QModelIndex &, int, int)));
205 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
206 connect(Client::instance(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
207 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showNetworkConfig(NetworkId)), SLOT(showNetworkConfig(NetworkId)));
208 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
209 connect(Client::instance(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
211 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList, QVariantList)), SLOT(showCoreConfigWizard(QVariantList, QVariantList)));
212 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
213 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
214 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
215 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
217 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
221 setDockNestingEnabled(true);
222 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
223 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
224 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
225 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
227 // Order is sometimes important
231 // setupTransferWidget(); not ready yet
243 _bufferWidget->setFocusProxy(_inputWidget);
244 _chatMonitorView->setFocusProxy(_inputWidget);
247 # ifdef HAVE_QTMULTIMEDIA
248 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
251 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
253 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
255 QtUi::registerNotificationBackend(new KNotificationBackend(this));
256 #endif /* HAVE_KDE */
260 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
261 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
262 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
265 #ifdef HAVE_INDICATEQT
266 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
269 #ifdef HAVE_NOTIFICATION_CENTER
270 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
274 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
277 // we assume that at this point, all configurable actions are defined!
278 QtUi::loadShortcuts();
280 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
282 setDisconnectedState(); // Disable menus and stuff
285 setAutoSaveSettings();
288 // restore mainwin state
290 restoreStateFromSettings(s);
292 // restore locked state of docks
293 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
295 CoreConnection *conn = Client::coreConnection();
296 if (!conn->connectToCore()) {
297 // No autoconnect selected (or no accounts)
298 showCoreConnectionDlg();
311 saveStateToSettings(s);
313 QApplication::quit();
317 void MainWin::saveStateToSettings(UiSettings &s)
319 s.setValue("MainWinSize", _normalSize);
320 s.setValue("MainWinPos", _normalPos);
321 s.setValue("MainWinState", saveState());
322 s.setValue("MainWinGeometry", saveGeometry());
323 s.setValue("MainWinMinimized", isMinimized());
324 s.setValue("MainWinMaximized", isMaximized());
325 s.setValue("MainWinHidden", !isVisible());
326 BufferId lastBufId = Client::bufferModel()->currentBuffer();
327 if (lastBufId.isValid())
328 s.setValue("LastUsedBufferId", lastBufId.toInt());
331 saveAutoSaveSettings();
336 void MainWin::restoreStateFromSettings(UiSettings &s)
338 _normalSize = s.value("MainWinSize", size()).toSize();
339 _normalPos = s.value("MainWinPos", pos()).toPoint();
340 bool maximized = s.value("MainWinMaximized", false).toBool();
343 restoreGeometry(s.value("MainWinGeometry").toByteArray());
346 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
351 restoreState(s.value("MainWinState").toByteArray());
357 if ((Quassel::isOptionSet("hidewindow")
358 || s.value("MainWinHidden").toBool())
359 && _systemTray->isSystemTrayAvailable())
360 QtUi::hideMainWidget();
361 else if (s.value("MainWinMinimized").toBool())
369 QMenu *MainWin::createPopupMenu()
371 QMenu *popupMenu = QMainWindow::createPopupMenu();
372 popupMenu->addSeparator();
373 ActionCollection *coll = QtUi::actionCollection("General");
374 popupMenu->addAction(coll->action("ToggleMenuBar"));
379 void MainWin::updateIcon()
382 if (Client::isConnected())
383 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
385 icon = QIcon::fromTheme("inactive-quassel", QIcon(":/icons/inactive-quassel.png"));
387 qApp->setWindowIcon(icon);
391 void MainWin::setupActions()
393 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
395 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("connect-quassel", QIcon(":/icons/connect-quassel.png")), tr("&Connect to Core..."), coll,
396 this, SLOT(showCoreConnectionDlg())));
397 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("disconnect-quassel", QIcon(":/icons/disconnect-quassel.png")), tr("&Disconnect from Core"), coll,
398 Client::instance(), SLOT(disconnectFromCore())));
399 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
400 this, SLOT(showPasswordChangeDlg())));
401 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
402 this, SLOT(showCoreInfoDlg())));
403 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
404 this, SLOT(on_actionConfigureNetworks_triggered())));
405 // QKeySequence::Quit was added in Qt 4.6, and could be used instead. However, that key
406 // sequence is empty by default on Windows, which would remove Ctrl-Q to quit. It may be best
407 // to just keep it this way.
409 // See https://doc.qt.io/qt-5/qkeysequence.html
410 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
411 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
414 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
415 this, SLOT(on_actionConfigureViews_triggered())));
417 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
418 lockAct->setCheckable(true);
419 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
421 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
422 0, 0, QKeySequence::Find))->setCheckable(true);
423 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
424 this, SLOT(showAwayLog())));
425 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
426 0, 0))->setCheckable(true);
428 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
429 0, 0))->setCheckable(true);
432 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
434 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
435 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
436 _fullScreenAction->setCheckable(true);
437 coll->addAction("ToggleFullScreen", _fullScreenAction);
441 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
442 this, SLOT(showShortcutsDlg()));
443 configureShortcutsAct->setMenuRole(QAction::NoRole);
444 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
447 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
448 this, SLOT(showSettingsDlg()));
449 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
451 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
452 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
454 coll->addAction("ConfigureQuassel", configureQuasselAct);
457 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
458 this, SLOT(showAboutDlg()));
459 aboutQuasselAct->setMenuRole(QAction::AboutRole);
460 coll->addAction("AboutQuassel", aboutQuasselAct);
462 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
463 qApp, SLOT(aboutQt()));
464 aboutQtAct->setMenuRole(QAction::AboutQtRole);
465 coll->addAction("AboutQt", aboutQtAct);
466 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
467 this, SLOT(on_actionDebugNetworkModel_triggered())));
468 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
469 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
470 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
471 this, SLOT(on_actionDebugMessageModel_triggered())));
472 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
473 this, SLOT(on_actionDebugHotList_triggered())));
474 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
475 this, SLOT(on_actionDebugLog_triggered())));
476 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
477 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
479 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
480 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
483 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
485 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
486 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
488 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
489 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
493 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
494 const int jumpModifier = Qt::ControlModifier;
496 const int bindModifier = Qt::ControlModifier;
497 const int jumpModifier = Qt::AltModifier;
500 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
501 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
502 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
503 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
504 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
505 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
506 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
507 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
508 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
509 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
510 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
511 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
512 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
513 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
514 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
515 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
516 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
517 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
518 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
519 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
521 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
522 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
523 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
524 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
525 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
526 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
527 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
528 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
529 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
530 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
531 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
532 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
533 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
534 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
535 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
536 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
537 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
538 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
539 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
540 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
543 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
544 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
545 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
546 this, SLOT(previousBufferView()), QKeySequence::Back));
547 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
548 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
549 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
550 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
554 void MainWin::setupMenus()
556 ActionCollection *coll = QtUi::actionCollection("General");
558 _fileMenu = menuBar()->addMenu(tr("&File"));
560 static const QStringList coreActions = QStringList()
561 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
564 foreach(QString actionName, coreActions) {
565 coreAction = coll->action(actionName);
566 _fileMenu->addAction(coreAction);
567 flagRemoteCoreOnly(coreAction);
569 flagRemoteCoreOnly(_fileMenu->addSeparator());
571 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
572 _networksMenu->addAction(coll->action("ConfigureNetworks"));
573 _networksMenu->addSeparator();
574 _fileMenu->addSeparator();
575 _fileMenu->addAction(coll->action("Quit"));
577 _viewMenu = menuBar()->addMenu(tr("&View"));
578 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
579 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
580 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
581 _viewMenu->addSeparator();
583 _viewMenu->addAction(coll->action("ToggleMenuBar"));
584 _viewMenu->addAction(coll->action("ToggleStatusBar"));
585 _viewMenu->addAction(coll->action("ToggleSearchBar"));
587 coreAction = coll->action("ShowAwayLog");
588 flagRemoteCoreOnly(coreAction);
589 _viewMenu->addAction(coreAction);
591 _viewMenu->addSeparator();
592 _viewMenu->addAction(coll->action("LockLayout"));
594 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
596 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
597 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
599 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
601 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
604 _helpMenu = menuBar()->addMenu(tr("&Help"));
606 _helpMenu->addAction(coll->action("AboutQuassel"));
608 _helpMenu->addAction(coll->action("AboutQt"));
610 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
612 _helpMenu->addSeparator();
613 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
614 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
615 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
616 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
617 _helpDebugMenu->addAction(coll->action("DebugHotList"));
618 _helpDebugMenu->addAction(coll->action("DebugLog"));
619 _helpDebugMenu->addSeparator();
620 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
623 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
625 QtUiSettings uiSettings;
626 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
627 showMenuBar->setChecked(enabled);
628 enabled ? menuBar()->show() : menuBar()->hide();
630 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
631 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
635 void MainWin::setupBufferWidget()
637 _bufferWidget = new BufferWidget(this);
638 _bufferWidget->setModel(Client::bufferModel());
639 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
640 setCentralWidget(_bufferWidget);
644 void MainWin::addBufferView(int bufferViewConfigId)
646 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
650 void MainWin::addBufferView(ClientBufferViewConfig *config)
655 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
656 BufferViewDock *dock = new BufferViewDock(config, this);
658 //create the view and initialize it's filter
659 BufferView *view = new BufferView(dock);
660 view->setFilteredModel(Client::bufferModel(), config);
661 view->installEventFilter(_inputWidget); // for key presses
663 Client::bufferModel()->synchronizeView(view);
665 dock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
667 dock->setWidget(view);
668 dock->setVisible(_layoutLoaded); // don't show before state has been restored
670 addDockWidget(Qt::LeftDockWidgetArea, dock);
671 _bufferViewsMenu->addAction(dock->toggleViewAction());
673 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
674 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
675 _bufferViews.append(dock);
677 if (!activeBufferView())
682 void MainWin::removeBufferView(int bufferViewConfigId)
685 BufferViewDock *dock;
686 foreach(QAction *action, _bufferViewsMenu->actions()) {
687 actionData = action->data();
688 if (!actionData.isValid())
691 dock = qobject_cast<BufferViewDock *>(action->parent());
692 if (dock && actionData.toInt() == bufferViewConfigId) {
693 removeAction(action);
694 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
695 _bufferViews.removeAll(dock);
697 if (dock->isActive()) {
698 dock->setActive(false);
699 _activeBufferViewIndex = -1;
709 void MainWin::bufferViewToggled(bool enabled)
711 if (!enabled && !isMinimized()) {
712 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
713 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
716 QAction *action = qobject_cast<QAction *>(sender());
718 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
721 // Make sure we don't toggle backlog fetch for a view we've already removed
722 if (!_bufferViews.contains(dock))
726 Client::bufferViewOverlay()->addView(dock->bufferViewId());
728 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
732 void MainWin::bufferViewVisibilityChanged(bool visible)
735 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
737 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
742 BufferView *MainWin::allBuffersView() const
744 // "All Buffers" is always the first dock created
745 if (_bufferViews.count() > 0)
746 return _bufferViews[0]->bufferView();
751 BufferView *MainWin::activeBufferView() const
753 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
755 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
756 return dock->isActive() ? dock->bufferView() : 0;
760 void MainWin::changeActiveBufferView(int bufferViewId)
762 if (bufferViewId < 0)
765 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
766 _bufferViews[_activeBufferViewIndex]->setActive(false);
767 _activeBufferViewIndex = -1;
770 for (int i = 0; i < _bufferViews.count(); i++) {
771 BufferViewDock *dock = _bufferViews.at(i);
772 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
773 _activeBufferViewIndex = i;
774 dock->setActive(true);
779 nextBufferView(); // fallback
783 void MainWin::showPasswordChangeDlg()
785 if(Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
786 PasswordChangeDlg dlg(this);
790 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
791 tr("<b>Your Quassel Core does not support this feature</b>"),
792 QMessageBox::Ok, this);
793 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
799 void MainWin::changeActiveBufferView(bool backwards)
801 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
802 _bufferViews[_activeBufferViewIndex]->setActive(false);
805 if (!_bufferViews.count())
808 int c = _bufferViews.count();
809 while (c--) { // yes, this will reactivate the current active one if all others fail
811 if (--_activeBufferViewIndex < 0)
812 _activeBufferViewIndex = _bufferViews.count()-1;
815 if (++_activeBufferViewIndex >= _bufferViews.count())
816 _activeBufferViewIndex = 0;
819 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
820 if (dock->isHidden())
823 dock->setActive(true);
827 _activeBufferViewIndex = -1;
831 void MainWin::nextBufferView()
833 changeActiveBufferView(false);
837 void MainWin::previousBufferView()
839 changeActiveBufferView(true);
843 void MainWin::nextBuffer()
845 BufferView *view = activeBufferView();
851 void MainWin::previousBuffer()
853 BufferView *view = activeBufferView();
855 view->previousBuffer();
859 void MainWin::hideCurrentBuffer()
861 BufferView *view = activeBufferView();
863 view->hideCurrentBuffer();
867 void MainWin::showNotificationsDlg()
869 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
874 void MainWin::on_actionConfigureNetworks_triggered()
876 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
881 void MainWin::on_actionConfigureViews_triggered()
883 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
888 void MainWin::on_actionLockLayout_toggled(bool lock)
890 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
891 foreach(VerticalDock *dock, docks) {
892 dock->showTitle(!lock);
895 QList<NickListDock *> nickdocks = findChildren<NickListDock *>();
896 foreach(NickListDock *nickdock, nickdocks) {
897 nickdock->setLocked(lock);
900 QList<BufferViewDock *> bufferdocks = findChildren<BufferViewDock *>();
901 foreach(BufferViewDock *bufferdock, bufferdocks) {
902 bufferdock->setLocked(lock);
905 if (Client::bufferViewManager()) {
906 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
907 config->setLocked(lock);
911 _mainToolBar->setMovable(!lock);
912 _nickToolBar->setMovable(!lock);
914 QtUiSettings().setValue("LockLayout", lock);
918 void MainWin::setupNickWidget()
921 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
922 nickDock->setObjectName("NickDock");
923 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
924 nickDock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
926 _nickListWidget = new NickListWidget(nickDock);
927 nickDock->setWidget(_nickListWidget);
929 addDockWidget(Qt::RightDockWidgetArea, nickDock);
930 _viewMenu->addAction(nickDock->toggleViewAction());
931 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
933 // See NickListDock::NickListDock();
934 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
936 // attach the NickListWidget to the BufferModel and the default selection
937 _nickListWidget->setModel(Client::bufferModel());
938 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
940 _nickListWidget->setVisible(false);
944 void MainWin::setupChatMonitor()
946 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
947 dock->setObjectName("ChatMonitorDock");
949 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
950 _chatMonitorView = new ChatMonitorView(filter, this);
951 _chatMonitorView->show();
952 dock->setWidget(_chatMonitorView);
955 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
956 _viewMenu->addAction(dock->toggleViewAction());
957 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
961 void MainWin::setupInputWidget()
963 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
964 dock->setObjectName("InputDock");
966 _inputWidget = new InputWidget(dock);
967 dock->setWidget(_inputWidget);
969 addDockWidget(Qt::BottomDockWidgetArea, dock);
971 _viewMenu->addAction(dock->toggleViewAction());
972 dock->toggleViewAction()->setText(tr("Show Input Line"));
974 _inputWidget->setModel(Client::bufferModel());
975 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
977 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
979 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
983 void MainWin::setupTopicWidget()
985 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
986 dock->setObjectName("TopicDock");
987 _topicWidget = new TopicWidget(dock);
989 dock->setWidget(_topicWidget);
991 _topicWidget->setModel(Client::bufferModel());
992 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
994 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
996 _viewMenu->addAction(dock->toggleViewAction());
997 dock->toggleViewAction()->setText(tr("Show Topic Line"));
1001 void MainWin::setupTransferWidget()
1003 auto dock = new QDockWidget(tr("Transfers"), this);
1004 dock->setObjectName("TransferDock");
1005 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
1007 auto view = new QTableView(dock); // to be replaced by the real thing
1008 view->setModel(Client::transferModel());
1009 dock->setWidget(view);
1010 dock->hide(); // hidden by default
1011 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1013 auto action = dock->toggleViewAction();
1014 action->setText(tr("Show File Transfers"));
1015 action->setIcon(QIcon::fromTheme("download"));
1016 action->setShortcut(QKeySequence(Qt::Key_F6));
1017 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
1018 _viewMenu->addAction(action);
1022 void MainWin::setupViewMenuTail()
1024 _viewMenu->addSeparator();
1025 _viewMenu->addAction(_fullScreenAction);
1029 void MainWin::setupTitleSetter()
1031 _titleSetter.setModel(Client::bufferModel());
1032 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1036 void MainWin::setupStatusBar()
1038 // MessageProcessor progress
1039 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1042 _coreConnectionStatusWidget->update();
1043 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1045 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1047 QtUiSettings uiSettings;
1049 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1050 showStatusbar->setChecked(enabled);
1051 enabled ? statusBar()->show() : statusBar()->hide();
1053 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1054 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1056 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1060 void MainWin::setupHotList()
1062 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1063 flatProxy->setSourceModel(Client::bufferModel());
1064 _bufferHotList = new BufferHotListFilter(flatProxy);
1068 void MainWin::saveMenuBarStatus(bool enabled)
1070 QtUiSettings uiSettings;
1071 uiSettings.setValue("ShowMenuBar", enabled);
1075 void MainWin::saveStatusBarStatus(bool enabled)
1077 QtUiSettings uiSettings;
1078 uiSettings.setValue("ShowStatusBar", enabled);
1082 void MainWin::setupSystray()
1085 _systemTray = new StatusNotifierItem(this);
1086 #elif !defined QT_NO_SYSTEMTRAYICON
1087 _systemTray = new LegacySystemTray(this);
1089 _systemTray = new SystemTray(this); // dummy
1091 _systemTray->init();
1095 void MainWin::setupToolBars()
1097 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1098 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1099 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1100 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1103 setUnifiedTitleAndToolBarOnMac(true);
1107 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1109 _mainToolBar = new QToolBar(this);
1110 _mainToolBar->setObjectName("MainToolBar");
1112 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1113 addToolBar(_mainToolBar);
1115 if (Quassel::runMode() != Quassel::Monolithic) {
1116 ActionCollection *coll = QtUi::actionCollection("General");
1117 _mainToolBar->addAction(coll->action("ConnectCore"));
1118 _mainToolBar->addAction(coll->action("DisconnectCore"));
1121 _mainToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1123 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1124 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1127 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1129 _nickToolBar = new QToolBar(this);
1130 _nickToolBar->setObjectName("NickToolBar");
1132 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1133 _nickToolBar->setVisible(false); //default: not visible
1134 addToolBar(_nickToolBar);
1135 _nickToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1137 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1138 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1141 QtUiSettings uiSettings;
1143 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1144 _mainToolBar->setVisible(visible);
1145 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1149 void MainWin::saveMainToolBarStatus(bool enabled)
1152 QtUiSettings uiSettings;
1153 uiSettings.setValue("ShowMainToolBar", enabled);
1160 void MainWin::connectedToCore()
1162 Q_CHECK_PTR(Client::bufferViewManager());
1163 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1164 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1165 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1167 if (Client::transferManager()) {
1168 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1171 setConnectedState();
1175 void MainWin::setConnectedState()
1177 ActionCollection *coll = QtUi::actionCollection("General");
1179 coll->action("ConnectCore")->setEnabled(false);
1180 coll->action("DisconnectCore")->setEnabled(true);
1181 coll->action("ChangePassword")->setEnabled(true);
1182 coll->action("CoreInfo")->setEnabled(true);
1184 foreach(QAction *action, _fileMenu->actions()) {
1185 if (isRemoteCoreOnly(action))
1186 action->setVisible(!Client::internalCore());
1189 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1190 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1191 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1192 if (!Client::internalCore()) {
1193 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1194 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1195 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1198 // _viewMenu->setEnabled(true);
1199 if (!Client::internalCore())
1200 statusBar()->showMessage(tr("Connected to core."));
1202 statusBar()->clearMessage();
1204 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1206 systemTray()->setState(SystemTray::Active);
1208 if (Client::networkIds().isEmpty()) {
1209 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1213 // Monolithic always preselects last used buffer - Client only if the connection died
1214 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1216 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1217 if (lastUsedBufferId.isValid())
1218 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1224 void MainWin::loadLayout()
1227 int accountId = Client::currentCoreAccount().accountId().toInt();
1228 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1229 if (state.isEmpty()) {
1230 foreach(BufferViewDock *view, _bufferViews)
1232 _layoutLoaded = true;
1235 _nickListWidget->setVisible(true);
1236 restoreState(state, accountId);
1237 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1238 if (bufferViewId >= 0)
1239 changeActiveBufferView(bufferViewId);
1241 _layoutLoaded = true;
1245 void MainWin::saveLayout()
1248 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1249 if (accountId > 0) {
1250 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1251 BufferView *view = activeBufferView();
1252 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1257 void MainWin::disconnectedFromCore()
1259 // save core specific layout and remove bufferviews;
1261 _layoutLoaded = false;
1263 QVariant actionData;
1264 BufferViewDock *dock;
1265 foreach(QAction *action, _bufferViewsMenu->actions()) {
1266 actionData = action->data();
1267 if (!actionData.isValid())
1270 dock = qobject_cast<BufferViewDock *>(action->parent());
1271 if (dock && actionData.toInt() != -1) {
1272 removeAction(action);
1273 _bufferViews.removeAll(dock);
1274 dock->deleteLater();
1278 // store last active buffer
1280 BufferId lastBufId = _bufferWidget->currentBuffer();
1281 if (lastBufId.isValid()) {
1282 s.setValue("LastUsedBufferId", lastBufId.toInt());
1283 // clear the current selection
1284 Client::bufferModel()->standardSelectionModel()->clearSelection();
1286 restoreState(s.value("MainWinState").toByteArray());
1287 setDisconnectedState();
1291 void MainWin::setDisconnectedState()
1293 ActionCollection *coll = QtUi::actionCollection("General");
1294 //ui.menuCore->setEnabled(false);
1295 coll->action("ConnectCore")->setEnabled(true);
1296 coll->action("DisconnectCore")->setEnabled(false);
1297 coll->action("CoreInfo")->setEnabled(false);
1298 coll->action("ChangePassword")->setEnabled(false);
1299 //_viewMenu->setEnabled(false);
1300 statusBar()->showMessage(tr("Not connected to core."));
1301 if (_msgProcessorStatusWidget)
1302 _msgProcessorStatusWidget->setProgress(0, 0);
1304 systemTray()->setState(SystemTray::Passive);
1305 _nickListWidget->setVisible(false);
1309 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1311 Q_UNUSED(errorMessage)
1312 CoreConnectAuthDlg dlg(account, this);
1313 *valid = (dlg.exec() == QDialog::Accepted);
1317 void MainWin::handleNoSslInClient(bool *accepted)
1319 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1320 QMessageBox::Ignore|QMessageBox::Cancel, this);
1321 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1322 box.setDefaultButton(QMessageBox::Ignore);
1323 *accepted = box.exec() == QMessageBox::Ignore;
1327 void MainWin::handleNoSslInCore(bool *accepted)
1329 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1330 QMessageBox::Ignore|QMessageBox::Cancel, this);
1331 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1332 box.setDefaultButton(QMessageBox::Ignore);
1333 *accepted = box.exec() == QMessageBox::Ignore;
1339 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1341 QString errorString = "<ul>";
1342 foreach(const QSslError error, socket->sslErrors())
1343 errorString += QString("<li>%1</li>").arg(error.errorString());
1344 errorString += "</ul>";
1346 QMessageBox box(QMessageBox::Warning,
1347 tr("Untrusted Security Certificate"),
1348 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1349 QMessageBox::Cancel, this);
1350 box.setInformativeText(errorString);
1351 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1352 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1354 QMessageBox::ButtonRole role;
1357 role = box.buttonRole(box.clickedButton());
1358 if (role == QMessageBox::HelpRole) {
1359 SslInfoDlg dlg(socket, this);
1363 while (role == QMessageBox::HelpRole);
1365 *accepted = role == QMessageBox::AcceptRole;
1367 QMessageBox box2(QMessageBox::Warning,
1368 tr("Untrusted Security Certificate"),
1369 tr("Would you like to accept this certificate forever without being prompted?"),
1371 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1372 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1374 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1379 #endif /* HAVE_SSL */
1381 void MainWin::handleCoreConnectionError(const QString &error)
1383 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1387 void MainWin::showCoreConnectionDlg()
1389 CoreConnectDlg dlg(this);
1390 if (dlg.exec() == QDialog::Accepted) {
1391 AccountId accId = dlg.selectedAccount();
1392 if (accId.isValid())
1393 Client::coreConnection()->connectToCore(accId);
1398 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1400 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1406 void MainWin::showChannelList(NetworkId netId)
1408 ChannelListDlg *channelListDlg = new ChannelListDlg();
1410 if (!netId.isValid()) {
1411 QAction *action = qobject_cast<QAction *>(sender());
1413 netId = action->data().value<NetworkId>();
1416 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1417 channelListDlg->setNetwork(netId);
1418 channelListDlg->show();
1422 void MainWin::showNetworkConfig(NetworkId netId)
1424 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
1425 if (netId.isValid())
1426 qobject_cast<NetworksSettingsPage *>(dlg.currentPage())->bufferList_Open(netId);
1431 void MainWin::showIgnoreList(QString newRule)
1433 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1434 // prepare config dialog for new rule
1435 if (!newRule.isEmpty())
1436 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1441 void MainWin::showCoreInfoDlg()
1443 CoreInfoDlg(this).exec();
1447 void MainWin::showAwayLog()
1451 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1452 _awayLog = new AwayLogView(filter, 0);
1453 filter->setParent(_awayLog);
1454 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1455 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1460 void MainWin::awayLogDestroyed()
1466 void MainWin::showSettingsDlg()
1468 SettingsDlg *dlg = new SettingsDlg();
1470 //Category: Interface
1471 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1472 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1473 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1474 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1475 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1476 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1477 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1478 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1480 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1482 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1483 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1484 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1485 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1488 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1489 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1490 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1491 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1492 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1493 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1495 // Category: Remote Cores
1496 if (Quassel::runMode() != Quassel::Monolithic) {
1497 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1498 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1505 void MainWin::showAboutDlg()
1507 AboutDlg(this).exec();
1511 void MainWin::showShortcutsDlg()
1514 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1515 foreach(KActionCollection *coll, QtUi::actionCollections())
1516 dlg.addCollection(coll, coll->property("Category").toString());
1517 dlg.configure(true);
1519 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1525 void MainWin::showNewTransferDlg(const QUuid &transferId)
1527 auto transfer = Client::transferManager()->transfer(transferId);
1529 if (transfer->status() == Transfer::Status::New) {
1530 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1535 qWarning() << "Unknown transfer ID" << transferId;
1540 void MainWin::onFullScreenToggled()
1542 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1543 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1546 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1548 if (_fullScreenAction->isChecked())
1549 setWindowState(windowState() | Qt::WindowFullScreen);
1551 setWindowState(windowState() & ~Qt::WindowFullScreen);
1556 /********************************************************************************************************/
1558 bool MainWin::event(QEvent *event)
1560 switch(event->type()) {
1561 case QEvent::WindowActivate: {
1562 BufferId bufferId = Client::bufferModel()->currentBuffer();
1563 if (bufferId.isValid())
1564 Client::instance()->markBufferAsRead(bufferId);
1567 case QEvent::WindowDeactivate:
1568 if (bufferWidget()->autoMarkerLineOnLostFocus())
1569 bufferWidget()->setMarkerLine();
1574 return QMainWindow::event(event);
1578 void MainWin::moveEvent(QMoveEvent *event)
1580 if (!(windowState() & Qt::WindowMaximized))
1581 _normalPos = event->pos();
1583 QMainWindow::moveEvent(event);
1587 void MainWin::resizeEvent(QResizeEvent *event)
1589 if (!(windowState() & Qt::WindowMaximized))
1590 _normalSize = event->size();
1592 QMainWindow::resizeEvent(event);
1596 void MainWin::closeEvent(QCloseEvent *event)
1599 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1601 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1602 // This messes up MainWinState/MainWinHidden save/restore.
1603 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1604 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1605 QtUi::hideMainWidget();
1608 else if(!_aboutToQuit) {
1609 _aboutToQuit = true;
1619 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1623 bool hasFocus = QApplication::activeWindow() != 0;
1625 for (int i = start; i <= end; i++) {
1626 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1627 if (!idx.isValid()) {
1628 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1631 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1632 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1635 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1636 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1638 // check if bufferId belongs to the shown chatlists
1639 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1640 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1643 // check if it's the buffer currently displayed
1644 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1647 // only show notifications for higlights or queries
1648 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1651 // and of course: don't notify for ignored messages
1652 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1655 // seems like we have a legit notification candidate!
1656 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1657 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1658 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1659 AbstractNotificationBackend::NotificationType type;
1661 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1662 type = AbstractNotificationBackend::PrivMsg;
1663 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1664 type = AbstractNotificationBackend::PrivMsgFocused;
1665 else if (flags & Message::Highlight && !hasFocus)
1666 type = AbstractNotificationBackend::Highlight;
1668 type = AbstractNotificationBackend::HighlightFocused;
1670 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1675 void MainWin::currentBufferChanged(BufferId buffer)
1677 if (buffer.isValid())
1678 Client::instance()->markBufferAsRead(buffer);
1682 void MainWin::clientNetworkCreated(NetworkId id)
1684 const Network *net = Client::network(id);
1685 QAction *act = new QAction(net->networkName(), this);
1686 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1687 act->setData(QVariant::fromValue<NetworkId>(id));
1688 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1689 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1691 QAction *beforeAction = 0;
1692 foreach(QAction *action, _networksMenu->actions()) {
1693 if (!action->data().isValid()) // ignore stock actions
1695 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1696 beforeAction = action;
1700 _networksMenu->insertAction(beforeAction, act);
1704 void MainWin::clientNetworkUpdated()
1706 const Network *net = qobject_cast<const Network *>(sender());
1710 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1714 action->setText(net->networkName());
1716 switch (net->connectionState()) {
1717 case Network::Initialized:
1718 action->setIcon(QIcon::fromTheme("network-connect"));
1719 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1720 if (!bufferWidget()->currentBuffer().isValid()) {
1721 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1722 if (idx.isValid()) {
1723 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1724 Client::bufferModel()->switchToBuffer(statusBufferId);
1728 case Network::Disconnected:
1729 action->setIcon(QIcon::fromTheme("network-disconnect"));
1732 action->setIcon(QIcon::fromTheme("network-wired"));
1737 void MainWin::clientNetworkRemoved(NetworkId id)
1739 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1743 action->deleteLater();
1747 void MainWin::connectOrDisconnectFromNet()
1749 QAction *act = qobject_cast<QAction *>(sender());
1751 const Network *net = Client::network(act->data().value<NetworkId>());
1753 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1754 else net->requestDisconnect();
1758 void MainWin::on_jumpHotBuffer_triggered()
1760 if (!_bufferHotList->rowCount())
1763 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1766 void MainWin::on_bufferSearch_triggered()
1768 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1769 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1773 _bufferViews[_activeBufferViewIndex]->activateFilter();
1777 void MainWin::onJumpKey()
1779 QAction *action = qobject_cast<QAction *>(sender());
1780 if (!action || !Client::bufferModel())
1782 int idx = action->property("Index").toInt();
1784 if (_jumpKeyMap.isEmpty())
1785 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1787 if (!_jumpKeyMap.contains(idx))
1790 BufferId buffer = _jumpKeyMap.value(idx);
1791 if (buffer.isValid())
1792 Client::bufferModel()->switchToBuffer(buffer);
1796 void MainWin::bindJumpKey()
1798 QAction *action = qobject_cast<QAction *>(sender());
1799 if (!action || !Client::bufferModel())
1801 int idx = action->property("Index").toInt();
1803 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1804 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1808 void MainWin::on_actionDebugNetworkModel_triggered()
1810 QTreeView *view = new QTreeView;
1811 view->setAttribute(Qt::WA_DeleteOnClose);
1812 view->setWindowTitle("Debug NetworkModel View");
1813 view->setModel(Client::networkModel());
1814 view->setColumnWidth(0, 250);
1815 view->setColumnWidth(1, 250);
1816 view->setColumnWidth(2, 80);
1817 view->resize(610, 300);
1822 void MainWin::on_actionDebugHotList_triggered()
1824 _bufferHotList->invalidate();
1825 _bufferHotList->sort(0, Qt::DescendingOrder);
1827 QTreeView *view = new QTreeView;
1828 view->setAttribute(Qt::WA_DeleteOnClose);
1829 view->setModel(_bufferHotList);
1834 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1836 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1837 overlay->setAttribute(Qt::WA_DeleteOnClose);
1842 void MainWin::on_actionDebugMessageModel_triggered()
1844 QTableView *view = new QTableView(0);
1845 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1846 filter->setSourceModel(Client::messageModel());
1847 view->setModel(filter);
1848 view->setAttribute(Qt::WA_DeleteOnClose, true);
1849 view->verticalHeader()->hide();
1850 view->horizontalHeader()->setStretchLastSection(true);
1855 void MainWin::on_actionDebugLog_triggered()
1857 DebugLogWidget *logWidget = new DebugLogWidget(0);
1862 void MainWin::showStatusBarMessage(const QString &message)
1864 statusBar()->showMessage(message, 10000);