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("TextFormat", tr("Text formatting"));
485 coll->addAction("FormatApplyColor", new Action(
486 QIcon::fromTheme("format-text-color"), tr("Apply foreground color"), coll,
487 this, SLOT(on_inputFormatApplyColor_triggered()),
488 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_G)));
490 coll->addAction("FormatApplyColorFill", new Action(
491 QIcon::fromTheme("format-fill-color"), tr("Apply background color"), coll,
492 this, SLOT(on_inputFormatApplyColorFill_triggered()),
493 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B)));
495 coll->addAction("FormatClear", new Action(
496 QIcon::fromTheme("edit-clear"), tr("Clear formatting"), coll,
497 this, SLOT(on_inputFormatClear_triggered()),
498 QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C)));
500 coll->addAction("FormatBold", new Action(
501 QIcon::fromTheme("format-text-bold"), tr("Toggle bold"), coll,
502 this, SLOT(on_inputFormatBold_triggered()),
503 QKeySequence::Bold));
505 coll->addAction("FormatItalic", new Action(
506 QIcon::fromTheme("format-text-italic"), tr("Toggle italics"), coll,
507 this, SLOT(on_inputFormatItalic_triggered()),
508 QKeySequence::Italic));
510 coll->addAction("FormatUnderline", new Action(
511 QIcon::fromTheme("format-text-underline"), tr("Toggle underline"), coll,
512 this, SLOT(on_inputFormatUnderline_triggered()), QKeySequence::Underline));
515 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
517 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
518 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
520 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
521 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
525 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
526 const int jumpModifier = Qt::ControlModifier;
528 const int bindModifier = Qt::ControlModifier;
529 const int jumpModifier = Qt::AltModifier;
532 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
533 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
534 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
535 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
536 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
537 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
538 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
539 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
540 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
541 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
542 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
543 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
544 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
545 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
546 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
547 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
548 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
549 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
550 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
551 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
553 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
554 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
555 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
556 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
557 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
558 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
559 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
560 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
561 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
562 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
563 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
564 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
565 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
566 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
567 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
568 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
569 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
570 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
571 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
572 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
575 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
576 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
577 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
578 this, SLOT(previousBufferView()), QKeySequence::Back));
579 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
580 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
581 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
582 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
586 void MainWin::setupMenus()
588 ActionCollection *coll = QtUi::actionCollection("General");
590 _fileMenu = menuBar()->addMenu(tr("&File"));
592 static const QStringList coreActions = QStringList()
593 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
596 foreach(QString actionName, coreActions) {
597 coreAction = coll->action(actionName);
598 _fileMenu->addAction(coreAction);
599 flagRemoteCoreOnly(coreAction);
601 flagRemoteCoreOnly(_fileMenu->addSeparator());
603 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
604 _networksMenu->addAction(coll->action("ConfigureNetworks"));
605 _networksMenu->addSeparator();
606 _fileMenu->addSeparator();
607 _fileMenu->addAction(coll->action("Quit"));
609 _viewMenu = menuBar()->addMenu(tr("&View"));
610 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
611 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
612 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
613 _viewMenu->addSeparator();
615 _viewMenu->addAction(coll->action("ToggleMenuBar"));
616 _viewMenu->addAction(coll->action("ToggleStatusBar"));
617 _viewMenu->addAction(coll->action("ToggleSearchBar"));
619 coreAction = coll->action("ShowAwayLog");
620 flagRemoteCoreOnly(coreAction);
621 _viewMenu->addAction(coreAction);
623 _viewMenu->addSeparator();
624 _viewMenu->addAction(coll->action("LockLayout"));
626 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
628 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
629 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
631 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
633 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
636 _helpMenu = menuBar()->addMenu(tr("&Help"));
638 _helpMenu->addAction(coll->action("AboutQuassel"));
640 _helpMenu->addAction(coll->action("AboutQt"));
642 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
644 _helpMenu->addSeparator();
645 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
646 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
647 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
648 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
649 _helpDebugMenu->addAction(coll->action("DebugHotList"));
650 _helpDebugMenu->addAction(coll->action("DebugLog"));
651 _helpDebugMenu->addSeparator();
652 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
655 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
657 QtUiSettings uiSettings;
658 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
659 showMenuBar->setChecked(enabled);
660 enabled ? menuBar()->show() : menuBar()->hide();
662 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
663 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
667 void MainWin::setupBufferWidget()
669 _bufferWidget = new BufferWidget(this);
670 _bufferWidget->setModel(Client::bufferModel());
671 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
672 setCentralWidget(_bufferWidget);
676 void MainWin::addBufferView(int bufferViewConfigId)
678 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
682 void MainWin::addBufferView(ClientBufferViewConfig *config)
687 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
688 BufferViewDock *dock = new BufferViewDock(config, this);
690 //create the view and initialize it's filter
691 BufferView *view = new BufferView(dock);
692 view->setFilteredModel(Client::bufferModel(), config);
693 view->installEventFilter(_inputWidget); // for key presses
695 Client::bufferModel()->synchronizeView(view);
697 dock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
699 dock->setWidget(view);
700 dock->setVisible(_layoutLoaded); // don't show before state has been restored
702 addDockWidget(Qt::LeftDockWidgetArea, dock);
703 _bufferViewsMenu->addAction(dock->toggleViewAction());
705 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
706 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
707 _bufferViews.append(dock);
709 if (!activeBufferView())
714 void MainWin::removeBufferView(int bufferViewConfigId)
717 BufferViewDock *dock;
718 foreach(QAction *action, _bufferViewsMenu->actions()) {
719 actionData = action->data();
720 if (!actionData.isValid())
723 dock = qobject_cast<BufferViewDock *>(action->parent());
724 if (dock && actionData.toInt() == bufferViewConfigId) {
725 removeAction(action);
726 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
727 _bufferViews.removeAll(dock);
729 if (dock->isActive()) {
730 dock->setActive(false);
731 _activeBufferViewIndex = -1;
741 void MainWin::bufferViewToggled(bool enabled)
743 if (!enabled && !isMinimized()) {
744 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
745 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
748 QAction *action = qobject_cast<QAction *>(sender());
750 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
753 // Make sure we don't toggle backlog fetch for a view we've already removed
754 if (!_bufferViews.contains(dock))
758 Client::bufferViewOverlay()->addView(dock->bufferViewId());
760 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
764 void MainWin::bufferViewVisibilityChanged(bool visible)
767 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
769 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
774 BufferView *MainWin::allBuffersView() const
776 // "All Buffers" is always the first dock created
777 if (_bufferViews.count() > 0)
778 return _bufferViews[0]->bufferView();
783 BufferView *MainWin::activeBufferView() const
785 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
787 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
788 return dock->isActive() ? dock->bufferView() : 0;
792 void MainWin::changeActiveBufferView(int bufferViewId)
794 if (bufferViewId < 0)
797 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
798 _bufferViews[_activeBufferViewIndex]->setActive(false);
799 _activeBufferViewIndex = -1;
802 for (int i = 0; i < _bufferViews.count(); i++) {
803 BufferViewDock *dock = _bufferViews.at(i);
804 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
805 _activeBufferViewIndex = i;
806 dock->setActive(true);
811 nextBufferView(); // fallback
815 void MainWin::showPasswordChangeDlg()
817 if(Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
818 PasswordChangeDlg dlg(this);
822 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
823 tr("<b>Your Quassel Core does not support this feature</b>"),
824 QMessageBox::Ok, this);
825 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
831 void MainWin::changeActiveBufferView(bool backwards)
833 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
834 _bufferViews[_activeBufferViewIndex]->setActive(false);
837 if (!_bufferViews.count())
840 int c = _bufferViews.count();
841 while (c--) { // yes, this will reactivate the current active one if all others fail
843 if (--_activeBufferViewIndex < 0)
844 _activeBufferViewIndex = _bufferViews.count()-1;
847 if (++_activeBufferViewIndex >= _bufferViews.count())
848 _activeBufferViewIndex = 0;
851 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
852 if (dock->isHidden())
855 dock->setActive(true);
859 _activeBufferViewIndex = -1;
863 void MainWin::nextBufferView()
865 changeActiveBufferView(false);
869 void MainWin::previousBufferView()
871 changeActiveBufferView(true);
875 void MainWin::nextBuffer()
877 BufferView *view = activeBufferView();
883 void MainWin::previousBuffer()
885 BufferView *view = activeBufferView();
887 view->previousBuffer();
891 void MainWin::hideCurrentBuffer()
893 BufferView *view = activeBufferView();
895 view->hideCurrentBuffer();
899 void MainWin::showNotificationsDlg()
901 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
906 void MainWin::on_actionConfigureNetworks_triggered()
908 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
913 void MainWin::on_actionConfigureViews_triggered()
915 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
920 void MainWin::on_actionLockLayout_toggled(bool lock)
922 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
923 foreach(VerticalDock *dock, docks) {
924 dock->showTitle(!lock);
927 QList<NickListDock *> nickdocks = findChildren<NickListDock *>();
928 foreach(NickListDock *nickdock, nickdocks) {
929 nickdock->setLocked(lock);
932 QList<BufferViewDock *> bufferdocks = findChildren<BufferViewDock *>();
933 foreach(BufferViewDock *bufferdock, bufferdocks) {
934 bufferdock->setLocked(lock);
937 if (Client::bufferViewManager()) {
938 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
939 config->setLocked(lock);
943 _mainToolBar->setMovable(!lock);
944 _nickToolBar->setMovable(!lock);
946 QtUiSettings().setValue("LockLayout", lock);
950 void MainWin::setupNickWidget()
953 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
954 nickDock->setObjectName("NickDock");
955 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
956 nickDock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
958 _nickListWidget = new NickListWidget(nickDock);
959 nickDock->setWidget(_nickListWidget);
961 addDockWidget(Qt::RightDockWidgetArea, nickDock);
962 _viewMenu->addAction(nickDock->toggleViewAction());
963 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
965 // See NickListDock::NickListDock();
966 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
968 // attach the NickListWidget to the BufferModel and the default selection
969 _nickListWidget->setModel(Client::bufferModel());
970 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
972 _nickListWidget->setVisible(false);
976 void MainWin::setupChatMonitor()
978 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
979 dock->setObjectName("ChatMonitorDock");
981 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
982 _chatMonitorView = new ChatMonitorView(filter, this);
983 _chatMonitorView->show();
984 dock->setWidget(_chatMonitorView);
987 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
988 _viewMenu->addAction(dock->toggleViewAction());
989 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
993 void MainWin::setupInputWidget()
995 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
996 dock->setObjectName("InputDock");
998 _inputWidget = new InputWidget(dock);
999 dock->setWidget(_inputWidget);
1001 addDockWidget(Qt::BottomDockWidgetArea, dock);
1003 _viewMenu->addAction(dock->toggleViewAction());
1004 dock->toggleViewAction()->setText(tr("Show Input Line"));
1006 _inputWidget->setModel(Client::bufferModel());
1007 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1009 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
1011 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
1015 void MainWin::setupTopicWidget()
1017 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
1018 dock->setObjectName("TopicDock");
1019 _topicWidget = new TopicWidget(dock);
1021 dock->setWidget(_topicWidget);
1023 _topicWidget->setModel(Client::bufferModel());
1024 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
1026 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1028 _viewMenu->addAction(dock->toggleViewAction());
1029 dock->toggleViewAction()->setText(tr("Show Topic Line"));
1033 void MainWin::setupTransferWidget()
1035 auto dock = new QDockWidget(tr("Transfers"), this);
1036 dock->setObjectName("TransferDock");
1037 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
1039 auto view = new QTableView(dock); // to be replaced by the real thing
1040 view->setModel(Client::transferModel());
1041 dock->setWidget(view);
1042 dock->hide(); // hidden by default
1043 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1045 auto action = dock->toggleViewAction();
1046 action->setText(tr("Show File Transfers"));
1047 action->setIcon(QIcon::fromTheme("download"));
1048 action->setShortcut(QKeySequence(Qt::Key_F6));
1049 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
1050 _viewMenu->addAction(action);
1054 void MainWin::setupViewMenuTail()
1056 _viewMenu->addSeparator();
1057 _viewMenu->addAction(_fullScreenAction);
1061 void MainWin::setupTitleSetter()
1063 _titleSetter.setModel(Client::bufferModel());
1064 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1068 void MainWin::setupStatusBar()
1070 // MessageProcessor progress
1071 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1074 _coreConnectionStatusWidget->update();
1075 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1077 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1079 QtUiSettings uiSettings;
1081 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1082 showStatusbar->setChecked(enabled);
1083 enabled ? statusBar()->show() : statusBar()->hide();
1085 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1086 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1088 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1092 void MainWin::setupHotList()
1094 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1095 flatProxy->setSourceModel(Client::bufferModel());
1096 _bufferHotList = new BufferHotListFilter(flatProxy);
1100 void MainWin::saveMenuBarStatus(bool enabled)
1102 QtUiSettings uiSettings;
1103 uiSettings.setValue("ShowMenuBar", enabled);
1107 void MainWin::saveStatusBarStatus(bool enabled)
1109 QtUiSettings uiSettings;
1110 uiSettings.setValue("ShowStatusBar", enabled);
1114 void MainWin::setupSystray()
1117 _systemTray = new StatusNotifierItem(this);
1118 #elif !defined QT_NO_SYSTEMTRAYICON
1119 _systemTray = new LegacySystemTray(this);
1121 _systemTray = new SystemTray(this); // dummy
1123 _systemTray->init();
1127 void MainWin::setupToolBars()
1129 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1130 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1131 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1132 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1135 setUnifiedTitleAndToolBarOnMac(true);
1139 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1141 _mainToolBar = new QToolBar(this);
1142 _mainToolBar->setObjectName("MainToolBar");
1144 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1145 addToolBar(_mainToolBar);
1147 if (Quassel::runMode() != Quassel::Monolithic) {
1148 ActionCollection *coll = QtUi::actionCollection("General");
1149 _mainToolBar->addAction(coll->action("ConnectCore"));
1150 _mainToolBar->addAction(coll->action("DisconnectCore"));
1153 _mainToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1155 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1156 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1159 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1161 _nickToolBar = new QToolBar(this);
1162 _nickToolBar->setObjectName("NickToolBar");
1164 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1165 _nickToolBar->setVisible(false); //default: not visible
1166 addToolBar(_nickToolBar);
1167 _nickToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1169 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1170 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1173 QtUiSettings uiSettings;
1175 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1176 _mainToolBar->setVisible(visible);
1177 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1181 void MainWin::saveMainToolBarStatus(bool enabled)
1184 QtUiSettings uiSettings;
1185 uiSettings.setValue("ShowMainToolBar", enabled);
1192 void MainWin::connectedToCore()
1194 Q_CHECK_PTR(Client::bufferViewManager());
1195 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1196 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1197 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1199 if (Client::transferManager()) {
1200 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1203 setConnectedState();
1207 void MainWin::setConnectedState()
1209 ActionCollection *coll = QtUi::actionCollection("General");
1211 coll->action("ConnectCore")->setEnabled(false);
1212 coll->action("DisconnectCore")->setEnabled(true);
1213 coll->action("ChangePassword")->setEnabled(true);
1214 coll->action("CoreInfo")->setEnabled(true);
1216 foreach(QAction *action, _fileMenu->actions()) {
1217 if (isRemoteCoreOnly(action))
1218 action->setVisible(!Client::internalCore());
1221 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1222 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1223 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1224 if (!Client::internalCore()) {
1225 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1226 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1227 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1230 // _viewMenu->setEnabled(true);
1231 if (!Client::internalCore())
1232 statusBar()->showMessage(tr("Connected to core."));
1234 statusBar()->clearMessage();
1236 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1238 systemTray()->setState(SystemTray::Active);
1240 if (Client::networkIds().isEmpty()) {
1241 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1245 // Monolithic always preselects last used buffer - Client only if the connection died
1246 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1248 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1249 if (lastUsedBufferId.isValid())
1250 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1256 void MainWin::loadLayout()
1259 int accountId = Client::currentCoreAccount().accountId().toInt();
1260 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1261 if (state.isEmpty()) {
1262 foreach(BufferViewDock *view, _bufferViews)
1264 _layoutLoaded = true;
1267 _nickListWidget->setVisible(true);
1268 restoreState(state, accountId);
1269 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1270 if (bufferViewId >= 0)
1271 changeActiveBufferView(bufferViewId);
1273 _layoutLoaded = true;
1277 void MainWin::saveLayout()
1280 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1281 if (accountId > 0) {
1282 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1283 BufferView *view = activeBufferView();
1284 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1289 void MainWin::disconnectedFromCore()
1291 // save core specific layout and remove bufferviews;
1293 _layoutLoaded = false;
1295 QVariant actionData;
1296 BufferViewDock *dock;
1297 foreach(QAction *action, _bufferViewsMenu->actions()) {
1298 actionData = action->data();
1299 if (!actionData.isValid())
1302 dock = qobject_cast<BufferViewDock *>(action->parent());
1303 if (dock && actionData.toInt() != -1) {
1304 removeAction(action);
1305 _bufferViews.removeAll(dock);
1306 dock->deleteLater();
1310 // store last active buffer
1312 BufferId lastBufId = _bufferWidget->currentBuffer();
1313 if (lastBufId.isValid()) {
1314 s.setValue("LastUsedBufferId", lastBufId.toInt());
1315 // clear the current selection
1316 Client::bufferModel()->standardSelectionModel()->clearSelection();
1318 restoreState(s.value("MainWinState").toByteArray());
1319 setDisconnectedState();
1323 void MainWin::setDisconnectedState()
1325 ActionCollection *coll = QtUi::actionCollection("General");
1326 //ui.menuCore->setEnabled(false);
1327 coll->action("ConnectCore")->setEnabled(true);
1328 coll->action("DisconnectCore")->setEnabled(false);
1329 coll->action("CoreInfo")->setEnabled(false);
1330 coll->action("ChangePassword")->setEnabled(false);
1331 //_viewMenu->setEnabled(false);
1332 statusBar()->showMessage(tr("Not connected to core."));
1333 if (_msgProcessorStatusWidget)
1334 _msgProcessorStatusWidget->setProgress(0, 0);
1336 systemTray()->setState(SystemTray::Passive);
1337 _nickListWidget->setVisible(false);
1341 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1343 Q_UNUSED(errorMessage)
1344 CoreConnectAuthDlg dlg(account, this);
1345 *valid = (dlg.exec() == QDialog::Accepted);
1349 void MainWin::handleNoSslInClient(bool *accepted)
1351 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1352 QMessageBox::Ignore|QMessageBox::Cancel, this);
1353 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1354 box.setDefaultButton(QMessageBox::Ignore);
1355 *accepted = box.exec() == QMessageBox::Ignore;
1359 void MainWin::handleNoSslInCore(bool *accepted)
1361 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1362 QMessageBox::Ignore|QMessageBox::Cancel, this);
1363 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1364 box.setDefaultButton(QMessageBox::Ignore);
1365 *accepted = box.exec() == QMessageBox::Ignore;
1371 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1373 QString errorString = "<ul>";
1374 foreach(const QSslError error, socket->sslErrors())
1375 errorString += QString("<li>%1</li>").arg(error.errorString());
1376 errorString += "</ul>";
1378 QMessageBox box(QMessageBox::Warning,
1379 tr("Untrusted Security Certificate"),
1380 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1381 QMessageBox::Cancel, this);
1382 box.setInformativeText(errorString);
1383 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1384 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1386 QMessageBox::ButtonRole role;
1389 role = box.buttonRole(box.clickedButton());
1390 if (role == QMessageBox::HelpRole) {
1391 SslInfoDlg dlg(socket, this);
1395 while (role == QMessageBox::HelpRole);
1397 *accepted = role == QMessageBox::AcceptRole;
1399 QMessageBox box2(QMessageBox::Warning,
1400 tr("Untrusted Security Certificate"),
1401 tr("Would you like to accept this certificate forever without being prompted?"),
1403 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1404 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1406 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1411 #endif /* HAVE_SSL */
1413 void MainWin::handleCoreConnectionError(const QString &error)
1415 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1419 void MainWin::showCoreConnectionDlg()
1421 CoreConnectDlg dlg(this);
1422 if (dlg.exec() == QDialog::Accepted) {
1423 AccountId accId = dlg.selectedAccount();
1424 if (accId.isValid())
1425 Client::coreConnection()->connectToCore(accId);
1430 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1432 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1438 void MainWin::showChannelList(NetworkId netId)
1440 ChannelListDlg *channelListDlg = new ChannelListDlg();
1442 if (!netId.isValid()) {
1443 QAction *action = qobject_cast<QAction *>(sender());
1445 netId = action->data().value<NetworkId>();
1448 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1449 channelListDlg->setNetwork(netId);
1450 channelListDlg->show();
1454 void MainWin::showNetworkConfig(NetworkId netId)
1456 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
1457 if (netId.isValid())
1458 qobject_cast<NetworksSettingsPage *>(dlg.currentPage())->bufferList_Open(netId);
1463 void MainWin::showIgnoreList(QString newRule)
1465 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1466 // prepare config dialog for new rule
1467 if (!newRule.isEmpty())
1468 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1473 void MainWin::showCoreInfoDlg()
1475 CoreInfoDlg(this).exec();
1479 void MainWin::showAwayLog()
1483 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1484 _awayLog = new AwayLogView(filter, 0);
1485 filter->setParent(_awayLog);
1486 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1487 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1492 void MainWin::awayLogDestroyed()
1498 void MainWin::showSettingsDlg()
1500 SettingsDlg *dlg = new SettingsDlg();
1502 //Category: Interface
1503 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1504 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1505 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1506 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1507 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1508 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1509 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1510 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1512 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1514 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1515 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1516 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1517 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1520 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1521 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1522 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1523 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1524 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1525 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1527 // Category: Remote Cores
1528 if (Quassel::runMode() != Quassel::Monolithic) {
1529 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1530 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1537 void MainWin::showAboutDlg()
1539 AboutDlg(this).exec();
1543 void MainWin::showShortcutsDlg()
1546 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1547 foreach(KActionCollection *coll, QtUi::actionCollections())
1548 dlg.addCollection(coll, coll->property("Category").toString());
1549 dlg.configure(true);
1551 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1557 void MainWin::showNewTransferDlg(const QUuid &transferId)
1559 auto transfer = Client::transferManager()->transfer(transferId);
1561 if (transfer->status() == Transfer::Status::New) {
1562 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1567 qWarning() << "Unknown transfer ID" << transferId;
1572 void MainWin::onFullScreenToggled()
1574 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1575 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1578 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1580 if (_fullScreenAction->isChecked())
1581 setWindowState(windowState() | Qt::WindowFullScreen);
1583 setWindowState(windowState() & ~Qt::WindowFullScreen);
1588 /********************************************************************************************************/
1590 bool MainWin::event(QEvent *event)
1592 switch(event->type()) {
1593 case QEvent::WindowActivate: {
1594 BufferId bufferId = Client::bufferModel()->currentBuffer();
1595 if (bufferId.isValid())
1596 Client::instance()->markBufferAsRead(bufferId);
1599 case QEvent::WindowDeactivate:
1600 if (bufferWidget()->autoMarkerLineOnLostFocus())
1601 bufferWidget()->setMarkerLine();
1606 return QMainWindow::event(event);
1610 void MainWin::moveEvent(QMoveEvent *event)
1612 if (!(windowState() & Qt::WindowMaximized))
1613 _normalPos = event->pos();
1615 QMainWindow::moveEvent(event);
1619 void MainWin::resizeEvent(QResizeEvent *event)
1621 if (!(windowState() & Qt::WindowMaximized))
1622 _normalSize = event->size();
1624 QMainWindow::resizeEvent(event);
1628 void MainWin::closeEvent(QCloseEvent *event)
1631 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1633 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1634 // This messes up MainWinState/MainWinHidden save/restore.
1635 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1636 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1637 QtUi::hideMainWidget();
1640 else if(!_aboutToQuit) {
1641 _aboutToQuit = true;
1651 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1655 bool hasFocus = QApplication::activeWindow() != 0;
1657 for (int i = start; i <= end; i++) {
1658 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1659 if (!idx.isValid()) {
1660 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1663 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1664 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1667 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1668 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1670 // check if bufferId belongs to the shown chatlists
1671 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1672 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1675 // check if it's the buffer currently displayed
1676 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1679 // only show notifications for higlights or queries
1680 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1683 // and of course: don't notify for ignored messages
1684 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1687 // seems like we have a legit notification candidate!
1688 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1689 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1690 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1691 AbstractNotificationBackend::NotificationType type;
1693 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1694 type = AbstractNotificationBackend::PrivMsg;
1695 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1696 type = AbstractNotificationBackend::PrivMsgFocused;
1697 else if (flags & Message::Highlight && !hasFocus)
1698 type = AbstractNotificationBackend::Highlight;
1700 type = AbstractNotificationBackend::HighlightFocused;
1702 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1707 void MainWin::currentBufferChanged(BufferId buffer)
1709 if (buffer.isValid())
1710 Client::instance()->markBufferAsRead(buffer);
1714 void MainWin::clientNetworkCreated(NetworkId id)
1716 const Network *net = Client::network(id);
1717 QAction *act = new QAction(net->networkName(), this);
1718 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1719 act->setData(QVariant::fromValue<NetworkId>(id));
1720 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1721 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1723 QAction *beforeAction = 0;
1724 foreach(QAction *action, _networksMenu->actions()) {
1725 if (!action->data().isValid()) // ignore stock actions
1727 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1728 beforeAction = action;
1732 _networksMenu->insertAction(beforeAction, act);
1736 void MainWin::clientNetworkUpdated()
1738 const Network *net = qobject_cast<const Network *>(sender());
1742 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1746 action->setText(net->networkName());
1748 switch (net->connectionState()) {
1749 case Network::Initialized:
1750 action->setIcon(QIcon::fromTheme("network-connect"));
1751 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1752 if (!bufferWidget()->currentBuffer().isValid()) {
1753 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1754 if (idx.isValid()) {
1755 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1756 Client::bufferModel()->switchToBuffer(statusBufferId);
1760 case Network::Disconnected:
1761 action->setIcon(QIcon::fromTheme("network-disconnect"));
1764 action->setIcon(QIcon::fromTheme("network-wired"));
1769 void MainWin::clientNetworkRemoved(NetworkId id)
1771 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1775 action->deleteLater();
1779 void MainWin::connectOrDisconnectFromNet()
1781 QAction *act = qobject_cast<QAction *>(sender());
1783 const Network *net = Client::network(act->data().value<NetworkId>());
1785 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1786 else net->requestDisconnect();
1790 void MainWin::on_inputFormatApplyColor_triggered()
1795 _inputWidget->applyFormatActiveColor();
1799 void MainWin::on_inputFormatApplyColorFill_triggered()
1804 _inputWidget->applyFormatActiveColorFill();
1808 void MainWin::on_inputFormatClear_triggered()
1813 _inputWidget->clearFormat();
1817 void MainWin::on_inputFormatBold_triggered()
1822 _inputWidget->toggleFormatBold();
1826 void MainWin::on_inputFormatItalic_triggered()
1831 _inputWidget->toggleFormatItalic();
1835 void MainWin::on_inputFormatUnderline_triggered()
1840 _inputWidget->toggleFormatUnderline();
1844 void MainWin::on_jumpHotBuffer_triggered()
1846 if (!_bufferHotList->rowCount())
1849 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1852 void MainWin::on_bufferSearch_triggered()
1854 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1855 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1859 _bufferViews[_activeBufferViewIndex]->activateFilter();
1863 void MainWin::onJumpKey()
1865 QAction *action = qobject_cast<QAction *>(sender());
1866 if (!action || !Client::bufferModel())
1868 int idx = action->property("Index").toInt();
1870 if (_jumpKeyMap.isEmpty())
1871 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1873 if (!_jumpKeyMap.contains(idx))
1876 BufferId buffer = _jumpKeyMap.value(idx);
1877 if (buffer.isValid())
1878 Client::bufferModel()->switchToBuffer(buffer);
1882 void MainWin::bindJumpKey()
1884 QAction *action = qobject_cast<QAction *>(sender());
1885 if (!action || !Client::bufferModel())
1887 int idx = action->property("Index").toInt();
1889 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1890 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1894 void MainWin::on_actionDebugNetworkModel_triggered()
1896 QTreeView *view = new QTreeView;
1897 view->setAttribute(Qt::WA_DeleteOnClose);
1898 view->setWindowTitle("Debug NetworkModel View");
1899 view->setModel(Client::networkModel());
1900 view->setColumnWidth(0, 250);
1901 view->setColumnWidth(1, 250);
1902 view->setColumnWidth(2, 80);
1903 view->resize(610, 300);
1908 void MainWin::on_actionDebugHotList_triggered()
1910 _bufferHotList->invalidate();
1911 _bufferHotList->sort(0, Qt::DescendingOrder);
1913 QTreeView *view = new QTreeView;
1914 view->setAttribute(Qt::WA_DeleteOnClose);
1915 view->setModel(_bufferHotList);
1920 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1922 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1923 overlay->setAttribute(Qt::WA_DeleteOnClose);
1928 void MainWin::on_actionDebugMessageModel_triggered()
1930 QTableView *view = new QTableView(0);
1931 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1932 filter->setSourceModel(Client::messageModel());
1933 view->setModel(filter);
1934 view->setAttribute(Qt::WA_DeleteOnClose, true);
1935 view->verticalHeader()->hide();
1936 view->horizontalHeader()->setStretchLastSection(true);
1941 void MainWin::on_actionDebugLog_triggered()
1943 DebugLogWidget *logWidget = new DebugLogWidget(0);
1948 void MainWin::showStatusBarMessage(const QString &message)
1950 statusBar()->showMessage(message, 10000);