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 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
406 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
407 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
410 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
411 this, SLOT(on_actionConfigureViews_triggered())));
413 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
414 lockAct->setCheckable(true);
415 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
417 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
418 0, 0, QKeySequence::Find))->setCheckable(true);
419 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
420 this, SLOT(showAwayLog())));
421 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
422 0, 0))->setCheckable(true);
424 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
425 0, 0))->setCheckable(true);
428 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
430 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
431 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
432 _fullScreenAction->setCheckable(true);
433 coll->addAction("ToggleFullScreen", _fullScreenAction);
437 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
438 this, SLOT(showShortcutsDlg()));
439 configureShortcutsAct->setMenuRole(QAction::NoRole);
440 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
443 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
444 this, SLOT(showSettingsDlg()));
445 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
447 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
448 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
450 coll->addAction("ConfigureQuassel", configureQuasselAct);
453 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
454 this, SLOT(showAboutDlg()));
455 aboutQuasselAct->setMenuRole(QAction::AboutRole);
456 coll->addAction("AboutQuassel", aboutQuasselAct);
458 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
459 qApp, SLOT(aboutQt()));
460 aboutQtAct->setMenuRole(QAction::AboutQtRole);
461 coll->addAction("AboutQt", aboutQtAct);
462 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
463 this, SLOT(on_actionDebugNetworkModel_triggered())));
464 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
465 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
466 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
467 this, SLOT(on_actionDebugMessageModel_triggered())));
468 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
469 this, SLOT(on_actionDebugHotList_triggered())));
470 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
471 this, SLOT(on_actionDebugLog_triggered())));
472 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
473 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
475 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
476 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
479 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
481 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
482 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
484 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
485 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
489 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
490 const int jumpModifier = Qt::ControlModifier;
492 const int bindModifier = Qt::ControlModifier;
493 const int jumpModifier = Qt::AltModifier;
496 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
497 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
498 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
499 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
500 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
501 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
502 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
503 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
504 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
505 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
506 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
507 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
508 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
509 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
510 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
511 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
512 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
513 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
514 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
515 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
517 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
518 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
519 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
520 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
521 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
522 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
523 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
524 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
525 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
526 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
527 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
528 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
529 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
530 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
531 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
532 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
533 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
534 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
535 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
536 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
539 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
540 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
541 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
542 this, SLOT(previousBufferView()), QKeySequence::Back));
543 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
544 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
545 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
546 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
550 void MainWin::setupMenus()
552 ActionCollection *coll = QtUi::actionCollection("General");
554 _fileMenu = menuBar()->addMenu(tr("&File"));
556 static const QStringList coreActions = QStringList()
557 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
560 foreach(QString actionName, coreActions) {
561 coreAction = coll->action(actionName);
562 _fileMenu->addAction(coreAction);
563 flagRemoteCoreOnly(coreAction);
565 flagRemoteCoreOnly(_fileMenu->addSeparator());
567 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
568 _networksMenu->addAction(coll->action("ConfigureNetworks"));
569 _networksMenu->addSeparator();
570 _fileMenu->addSeparator();
571 _fileMenu->addAction(coll->action("Quit"));
573 _viewMenu = menuBar()->addMenu(tr("&View"));
574 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
575 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
576 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
577 _viewMenu->addSeparator();
579 _viewMenu->addAction(coll->action("ToggleMenuBar"));
580 _viewMenu->addAction(coll->action("ToggleStatusBar"));
581 _viewMenu->addAction(coll->action("ToggleSearchBar"));
583 coreAction = coll->action("ShowAwayLog");
584 flagRemoteCoreOnly(coreAction);
585 _viewMenu->addAction(coreAction);
587 _viewMenu->addSeparator();
588 _viewMenu->addAction(coll->action("LockLayout"));
590 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
592 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
593 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
595 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
597 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
600 _helpMenu = menuBar()->addMenu(tr("&Help"));
602 _helpMenu->addAction(coll->action("AboutQuassel"));
604 _helpMenu->addAction(coll->action("AboutQt"));
606 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
608 _helpMenu->addSeparator();
609 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
610 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
611 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
612 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
613 _helpDebugMenu->addAction(coll->action("DebugHotList"));
614 _helpDebugMenu->addAction(coll->action("DebugLog"));
615 _helpDebugMenu->addSeparator();
616 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
619 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
621 QtUiSettings uiSettings;
622 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
623 showMenuBar->setChecked(enabled);
624 enabled ? menuBar()->show() : menuBar()->hide();
626 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
627 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
631 void MainWin::setupBufferWidget()
633 _bufferWidget = new BufferWidget(this);
634 _bufferWidget->setModel(Client::bufferModel());
635 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
636 setCentralWidget(_bufferWidget);
640 void MainWin::addBufferView(int bufferViewConfigId)
642 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
646 void MainWin::addBufferView(ClientBufferViewConfig *config)
651 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
652 BufferViewDock *dock = new BufferViewDock(config, this);
654 //create the view and initialize it's filter
655 BufferView *view = new BufferView(dock);
656 view->setFilteredModel(Client::bufferModel(), config);
657 view->installEventFilter(_inputWidget); // for key presses
659 Client::bufferModel()->synchronizeView(view);
661 dock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
663 dock->setWidget(view);
664 dock->setVisible(_layoutLoaded); // don't show before state has been restored
666 addDockWidget(Qt::LeftDockWidgetArea, dock);
667 _bufferViewsMenu->addAction(dock->toggleViewAction());
669 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
670 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
671 _bufferViews.append(dock);
673 if (!activeBufferView())
678 void MainWin::removeBufferView(int bufferViewConfigId)
681 BufferViewDock *dock;
682 foreach(QAction *action, _bufferViewsMenu->actions()) {
683 actionData = action->data();
684 if (!actionData.isValid())
687 dock = qobject_cast<BufferViewDock *>(action->parent());
688 if (dock && actionData.toInt() == bufferViewConfigId) {
689 removeAction(action);
690 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
691 _bufferViews.removeAll(dock);
693 if (dock->isActive()) {
694 dock->setActive(false);
695 _activeBufferViewIndex = -1;
705 void MainWin::bufferViewToggled(bool enabled)
707 if (!enabled && !isMinimized()) {
708 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
709 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
712 QAction *action = qobject_cast<QAction *>(sender());
714 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
717 // Make sure we don't toggle backlog fetch for a view we've already removed
718 if (!_bufferViews.contains(dock))
722 Client::bufferViewOverlay()->addView(dock->bufferViewId());
724 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
728 void MainWin::bufferViewVisibilityChanged(bool visible)
731 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
733 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
738 BufferView *MainWin::allBuffersView() const
740 // "All Buffers" is always the first dock created
741 if (_bufferViews.count() > 0)
742 return _bufferViews[0]->bufferView();
747 BufferView *MainWin::activeBufferView() const
749 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
751 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
752 return dock->isActive() ? dock->bufferView() : 0;
756 void MainWin::changeActiveBufferView(int bufferViewId)
758 if (bufferViewId < 0)
761 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
762 _bufferViews[_activeBufferViewIndex]->setActive(false);
763 _activeBufferViewIndex = -1;
766 for (int i = 0; i < _bufferViews.count(); i++) {
767 BufferViewDock *dock = _bufferViews.at(i);
768 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
769 _activeBufferViewIndex = i;
770 dock->setActive(true);
775 nextBufferView(); // fallback
779 void MainWin::showPasswordChangeDlg()
781 if(Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
782 PasswordChangeDlg dlg(this);
786 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
787 tr("<b>Your Quassel Core does not support this feature</b>"),
788 QMessageBox::Ok, this);
789 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
795 void MainWin::changeActiveBufferView(bool backwards)
797 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
798 _bufferViews[_activeBufferViewIndex]->setActive(false);
801 if (!_bufferViews.count())
804 int c = _bufferViews.count();
805 while (c--) { // yes, this will reactivate the current active one if all others fail
807 if (--_activeBufferViewIndex < 0)
808 _activeBufferViewIndex = _bufferViews.count()-1;
811 if (++_activeBufferViewIndex >= _bufferViews.count())
812 _activeBufferViewIndex = 0;
815 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
816 if (dock->isHidden())
819 dock->setActive(true);
823 _activeBufferViewIndex = -1;
827 void MainWin::nextBufferView()
829 changeActiveBufferView(false);
833 void MainWin::previousBufferView()
835 changeActiveBufferView(true);
839 void MainWin::nextBuffer()
841 BufferView *view = activeBufferView();
847 void MainWin::previousBuffer()
849 BufferView *view = activeBufferView();
851 view->previousBuffer();
855 void MainWin::hideCurrentBuffer()
857 BufferView *view = activeBufferView();
859 view->hideCurrentBuffer();
863 void MainWin::showNotificationsDlg()
865 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
870 void MainWin::on_actionConfigureNetworks_triggered()
872 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
877 void MainWin::on_actionConfigureViews_triggered()
879 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
884 void MainWin::on_actionLockLayout_toggled(bool lock)
886 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
887 foreach(VerticalDock *dock, docks) {
888 dock->showTitle(!lock);
891 QList<NickListDock *> nickdocks = findChildren<NickListDock *>();
892 foreach(NickListDock *nickdock, nickdocks) {
893 nickdock->setLocked(lock);
896 QList<BufferViewDock *> bufferdocks = findChildren<BufferViewDock *>();
897 foreach(BufferViewDock *bufferdock, bufferdocks) {
898 bufferdock->setLocked(lock);
901 if (Client::bufferViewManager()) {
902 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
903 config->setLocked(lock);
907 _mainToolBar->setMovable(!lock);
908 _nickToolBar->setMovable(!lock);
910 QtUiSettings().setValue("LockLayout", lock);
914 void MainWin::setupNickWidget()
917 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
918 nickDock->setObjectName("NickDock");
919 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
920 nickDock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
922 _nickListWidget = new NickListWidget(nickDock);
923 nickDock->setWidget(_nickListWidget);
925 addDockWidget(Qt::RightDockWidgetArea, nickDock);
926 _viewMenu->addAction(nickDock->toggleViewAction());
927 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
929 // See NickListDock::NickListDock();
930 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
932 // attach the NickListWidget to the BufferModel and the default selection
933 _nickListWidget->setModel(Client::bufferModel());
934 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
936 _nickListWidget->setVisible(false);
940 void MainWin::setupChatMonitor()
942 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
943 dock->setObjectName("ChatMonitorDock");
945 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
946 _chatMonitorView = new ChatMonitorView(filter, this);
947 _chatMonitorView->show();
948 dock->setWidget(_chatMonitorView);
951 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
952 _viewMenu->addAction(dock->toggleViewAction());
953 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
957 void MainWin::setupInputWidget()
959 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
960 dock->setObjectName("InputDock");
962 _inputWidget = new InputWidget(dock);
963 dock->setWidget(_inputWidget);
965 addDockWidget(Qt::BottomDockWidgetArea, dock);
967 _viewMenu->addAction(dock->toggleViewAction());
968 dock->toggleViewAction()->setText(tr("Show Input Line"));
970 _inputWidget->setModel(Client::bufferModel());
971 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
973 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
975 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
979 void MainWin::setupTopicWidget()
981 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
982 dock->setObjectName("TopicDock");
983 _topicWidget = new TopicWidget(dock);
985 dock->setWidget(_topicWidget);
987 _topicWidget->setModel(Client::bufferModel());
988 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
990 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
992 _viewMenu->addAction(dock->toggleViewAction());
993 dock->toggleViewAction()->setText(tr("Show Topic Line"));
997 void MainWin::setupTransferWidget()
999 auto dock = new QDockWidget(tr("Transfers"), this);
1000 dock->setObjectName("TransferDock");
1001 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
1003 auto view = new QTableView(dock); // to be replaced by the real thing
1004 view->setModel(Client::transferModel());
1005 dock->setWidget(view);
1006 dock->hide(); // hidden by default
1007 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1009 auto action = dock->toggleViewAction();
1010 action->setText(tr("Show File Transfers"));
1011 action->setIcon(QIcon::fromTheme("download"));
1012 action->setShortcut(QKeySequence(Qt::Key_F6));
1013 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
1014 _viewMenu->addAction(action);
1018 void MainWin::setupViewMenuTail()
1020 _viewMenu->addSeparator();
1021 _viewMenu->addAction(_fullScreenAction);
1025 void MainWin::setupTitleSetter()
1027 _titleSetter.setModel(Client::bufferModel());
1028 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1032 void MainWin::setupStatusBar()
1034 // MessageProcessor progress
1035 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1038 _coreConnectionStatusWidget->update();
1039 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1041 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1043 QtUiSettings uiSettings;
1045 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1046 showStatusbar->setChecked(enabled);
1047 enabled ? statusBar()->show() : statusBar()->hide();
1049 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1050 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1052 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1056 void MainWin::setupHotList()
1058 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1059 flatProxy->setSourceModel(Client::bufferModel());
1060 _bufferHotList = new BufferHotListFilter(flatProxy);
1064 void MainWin::saveMenuBarStatus(bool enabled)
1066 QtUiSettings uiSettings;
1067 uiSettings.setValue("ShowMenuBar", enabled);
1071 void MainWin::saveStatusBarStatus(bool enabled)
1073 QtUiSettings uiSettings;
1074 uiSettings.setValue("ShowStatusBar", enabled);
1078 void MainWin::setupSystray()
1081 _systemTray = new StatusNotifierItem(this);
1082 #elif !defined QT_NO_SYSTEMTRAYICON
1083 _systemTray = new LegacySystemTray(this);
1085 _systemTray = new SystemTray(this); // dummy
1087 _systemTray->init();
1091 void MainWin::setupToolBars()
1093 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1094 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1095 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1096 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1099 setUnifiedTitleAndToolBarOnMac(true);
1103 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1105 _mainToolBar = new QToolBar(this);
1106 _mainToolBar->setObjectName("MainToolBar");
1108 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1109 addToolBar(_mainToolBar);
1111 if (Quassel::runMode() != Quassel::Monolithic) {
1112 ActionCollection *coll = QtUi::actionCollection("General");
1113 _mainToolBar->addAction(coll->action("ConnectCore"));
1114 _mainToolBar->addAction(coll->action("DisconnectCore"));
1117 _mainToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1119 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1120 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1123 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1125 _nickToolBar = new QToolBar(this);
1126 _nickToolBar->setObjectName("NickToolBar");
1128 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1129 _nickToolBar->setVisible(false); //default: not visible
1130 addToolBar(_nickToolBar);
1131 _nickToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1133 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1134 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1137 QtUiSettings uiSettings;
1139 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1140 _mainToolBar->setVisible(visible);
1141 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1145 void MainWin::saveMainToolBarStatus(bool enabled)
1148 QtUiSettings uiSettings;
1149 uiSettings.setValue("ShowMainToolBar", enabled);
1156 void MainWin::connectedToCore()
1158 Q_CHECK_PTR(Client::bufferViewManager());
1159 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1160 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1161 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1163 if (Client::transferManager()) {
1164 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1167 setConnectedState();
1171 void MainWin::setConnectedState()
1173 ActionCollection *coll = QtUi::actionCollection("General");
1175 coll->action("ConnectCore")->setEnabled(false);
1176 coll->action("DisconnectCore")->setEnabled(true);
1177 coll->action("ChangePassword")->setEnabled(true);
1178 coll->action("CoreInfo")->setEnabled(true);
1180 foreach(QAction *action, _fileMenu->actions()) {
1181 if (isRemoteCoreOnly(action))
1182 action->setVisible(!Client::internalCore());
1185 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1186 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1187 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1188 if (!Client::internalCore()) {
1189 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1190 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1191 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1194 // _viewMenu->setEnabled(true);
1195 if (!Client::internalCore())
1196 statusBar()->showMessage(tr("Connected to core."));
1198 statusBar()->clearMessage();
1200 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1202 systemTray()->setState(SystemTray::Active);
1204 if (Client::networkIds().isEmpty()) {
1205 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1209 // Monolithic always preselects last used buffer - Client only if the connection died
1210 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1212 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1213 if (lastUsedBufferId.isValid())
1214 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1220 void MainWin::loadLayout()
1223 int accountId = Client::currentCoreAccount().accountId().toInt();
1224 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1225 if (state.isEmpty()) {
1226 foreach(BufferViewDock *view, _bufferViews)
1228 _layoutLoaded = true;
1231 _nickListWidget->setVisible(true);
1232 restoreState(state, accountId);
1233 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1234 if (bufferViewId >= 0)
1235 changeActiveBufferView(bufferViewId);
1237 _layoutLoaded = true;
1241 void MainWin::saveLayout()
1244 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1245 if (accountId > 0) {
1246 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1247 BufferView *view = activeBufferView();
1248 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1253 void MainWin::disconnectedFromCore()
1255 // save core specific layout and remove bufferviews;
1257 _layoutLoaded = false;
1259 QVariant actionData;
1260 BufferViewDock *dock;
1261 foreach(QAction *action, _bufferViewsMenu->actions()) {
1262 actionData = action->data();
1263 if (!actionData.isValid())
1266 dock = qobject_cast<BufferViewDock *>(action->parent());
1267 if (dock && actionData.toInt() != -1) {
1268 removeAction(action);
1269 _bufferViews.removeAll(dock);
1270 dock->deleteLater();
1274 // store last active buffer
1276 BufferId lastBufId = _bufferWidget->currentBuffer();
1277 if (lastBufId.isValid()) {
1278 s.setValue("LastUsedBufferId", lastBufId.toInt());
1279 // clear the current selection
1280 Client::bufferModel()->standardSelectionModel()->clearSelection();
1282 restoreState(s.value("MainWinState").toByteArray());
1283 setDisconnectedState();
1287 void MainWin::setDisconnectedState()
1289 ActionCollection *coll = QtUi::actionCollection("General");
1290 //ui.menuCore->setEnabled(false);
1291 coll->action("ConnectCore")->setEnabled(true);
1292 coll->action("DisconnectCore")->setEnabled(false);
1293 coll->action("CoreInfo")->setEnabled(false);
1294 coll->action("ChangePassword")->setEnabled(false);
1295 //_viewMenu->setEnabled(false);
1296 statusBar()->showMessage(tr("Not connected to core."));
1297 if (_msgProcessorStatusWidget)
1298 _msgProcessorStatusWidget->setProgress(0, 0);
1300 systemTray()->setState(SystemTray::Passive);
1301 _nickListWidget->setVisible(false);
1305 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1307 Q_UNUSED(errorMessage)
1308 CoreConnectAuthDlg dlg(account, this);
1309 *valid = (dlg.exec() == QDialog::Accepted);
1313 void MainWin::handleNoSslInClient(bool *accepted)
1315 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1316 QMessageBox::Ignore|QMessageBox::Cancel, this);
1317 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1318 box.setDefaultButton(QMessageBox::Ignore);
1319 *accepted = box.exec() == QMessageBox::Ignore;
1323 void MainWin::handleNoSslInCore(bool *accepted)
1325 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1326 QMessageBox::Ignore|QMessageBox::Cancel, this);
1327 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1328 box.setDefaultButton(QMessageBox::Ignore);
1329 *accepted = box.exec() == QMessageBox::Ignore;
1335 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1337 QString errorString = "<ul>";
1338 foreach(const QSslError error, socket->sslErrors())
1339 errorString += QString("<li>%1</li>").arg(error.errorString());
1340 errorString += "</ul>";
1342 QMessageBox box(QMessageBox::Warning,
1343 tr("Untrusted Security Certificate"),
1344 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1345 QMessageBox::Cancel, this);
1346 box.setInformativeText(errorString);
1347 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1348 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1350 QMessageBox::ButtonRole role;
1353 role = box.buttonRole(box.clickedButton());
1354 if (role == QMessageBox::HelpRole) {
1355 SslInfoDlg dlg(socket, this);
1359 while (role == QMessageBox::HelpRole);
1361 *accepted = role == QMessageBox::AcceptRole;
1363 QMessageBox box2(QMessageBox::Warning,
1364 tr("Untrusted Security Certificate"),
1365 tr("Would you like to accept this certificate forever without being prompted?"),
1367 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1368 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1370 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1375 #endif /* HAVE_SSL */
1377 void MainWin::handleCoreConnectionError(const QString &error)
1379 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1383 void MainWin::showCoreConnectionDlg()
1385 CoreConnectDlg dlg(this);
1386 if (dlg.exec() == QDialog::Accepted) {
1387 AccountId accId = dlg.selectedAccount();
1388 if (accId.isValid())
1389 Client::coreConnection()->connectToCore(accId);
1394 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1396 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1402 void MainWin::showChannelList(NetworkId netId)
1404 ChannelListDlg *channelListDlg = new ChannelListDlg();
1406 if (!netId.isValid()) {
1407 QAction *action = qobject_cast<QAction *>(sender());
1409 netId = action->data().value<NetworkId>();
1412 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1413 channelListDlg->setNetwork(netId);
1414 channelListDlg->show();
1418 void MainWin::showNetworkConfig(NetworkId netId)
1420 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
1421 if (netId.isValid())
1422 qobject_cast<NetworksSettingsPage *>(dlg.currentPage())->bufferList_Open(netId);
1427 void MainWin::showIgnoreList(QString newRule)
1429 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1430 // prepare config dialog for new rule
1431 if (!newRule.isEmpty())
1432 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1437 void MainWin::showCoreInfoDlg()
1439 CoreInfoDlg(this).exec();
1443 void MainWin::showAwayLog()
1447 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1448 _awayLog = new AwayLogView(filter, 0);
1449 filter->setParent(_awayLog);
1450 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1451 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1456 void MainWin::awayLogDestroyed()
1462 void MainWin::showSettingsDlg()
1464 SettingsDlg *dlg = new SettingsDlg();
1466 //Category: Interface
1467 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1468 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1469 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1470 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1471 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1472 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1473 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1474 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1476 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1478 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1479 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1480 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1481 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1484 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1485 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1486 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1487 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1488 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1489 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1491 // Category: Remote Cores
1492 if (Quassel::runMode() != Quassel::Monolithic) {
1493 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1494 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1501 void MainWin::showAboutDlg()
1503 AboutDlg(this).exec();
1507 void MainWin::showShortcutsDlg()
1510 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1511 foreach(KActionCollection *coll, QtUi::actionCollections())
1512 dlg.addCollection(coll, coll->property("Category").toString());
1513 dlg.configure(true);
1515 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1521 void MainWin::showNewTransferDlg(const QUuid &transferId)
1523 auto transfer = Client::transferManager()->transfer(transferId);
1525 if (transfer->status() == Transfer::Status::New) {
1526 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1531 qWarning() << "Unknown transfer ID" << transferId;
1536 void MainWin::onFullScreenToggled()
1538 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1539 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1542 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1544 if (_fullScreenAction->isChecked())
1545 setWindowState(windowState() | Qt::WindowFullScreen);
1547 setWindowState(windowState() & ~Qt::WindowFullScreen);
1552 /********************************************************************************************************/
1554 bool MainWin::event(QEvent *event)
1556 switch(event->type()) {
1557 case QEvent::WindowActivate: {
1558 BufferId bufferId = Client::bufferModel()->currentBuffer();
1559 if (bufferId.isValid())
1560 Client::instance()->markBufferAsRead(bufferId);
1563 case QEvent::WindowDeactivate:
1564 if (bufferWidget()->autoMarkerLineOnLostFocus())
1565 bufferWidget()->setMarkerLine();
1570 return QMainWindow::event(event);
1574 void MainWin::moveEvent(QMoveEvent *event)
1576 if (!(windowState() & Qt::WindowMaximized))
1577 _normalPos = event->pos();
1579 QMainWindow::moveEvent(event);
1583 void MainWin::resizeEvent(QResizeEvent *event)
1585 if (!(windowState() & Qt::WindowMaximized))
1586 _normalSize = event->size();
1588 QMainWindow::resizeEvent(event);
1592 void MainWin::closeEvent(QCloseEvent *event)
1595 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1597 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1598 // This messes up MainWinState/MainWinHidden save/restore.
1599 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1600 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1601 QtUi::hideMainWidget();
1604 else if(!_aboutToQuit) {
1605 _aboutToQuit = true;
1615 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1619 bool hasFocus = QApplication::activeWindow() != 0;
1621 for (int i = start; i <= end; i++) {
1622 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1623 if (!idx.isValid()) {
1624 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1627 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1628 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1631 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1632 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1634 // check if bufferId belongs to the shown chatlists
1635 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1636 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1639 // check if it's the buffer currently displayed
1640 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1643 // only show notifications for higlights or queries
1644 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1647 // and of course: don't notify for ignored messages
1648 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1651 // seems like we have a legit notification candidate!
1652 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1653 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1654 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1655 AbstractNotificationBackend::NotificationType type;
1657 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1658 type = AbstractNotificationBackend::PrivMsg;
1659 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1660 type = AbstractNotificationBackend::PrivMsgFocused;
1661 else if (flags & Message::Highlight && !hasFocus)
1662 type = AbstractNotificationBackend::Highlight;
1664 type = AbstractNotificationBackend::HighlightFocused;
1666 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1671 void MainWin::currentBufferChanged(BufferId buffer)
1673 if (buffer.isValid())
1674 Client::instance()->markBufferAsRead(buffer);
1678 void MainWin::clientNetworkCreated(NetworkId id)
1680 const Network *net = Client::network(id);
1681 QAction *act = new QAction(net->networkName(), this);
1682 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1683 act->setData(QVariant::fromValue<NetworkId>(id));
1684 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1685 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1687 QAction *beforeAction = 0;
1688 foreach(QAction *action, _networksMenu->actions()) {
1689 if (!action->data().isValid()) // ignore stock actions
1691 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1692 beforeAction = action;
1696 _networksMenu->insertAction(beforeAction, act);
1700 void MainWin::clientNetworkUpdated()
1702 const Network *net = qobject_cast<const Network *>(sender());
1706 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1710 action->setText(net->networkName());
1712 switch (net->connectionState()) {
1713 case Network::Initialized:
1714 action->setIcon(QIcon::fromTheme("network-connect"));
1715 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1716 if (!bufferWidget()->currentBuffer().isValid()) {
1717 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1718 if (idx.isValid()) {
1719 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1720 Client::bufferModel()->switchToBuffer(statusBufferId);
1724 case Network::Disconnected:
1725 action->setIcon(QIcon::fromTheme("network-disconnect"));
1728 action->setIcon(QIcon::fromTheme("network-wired"));
1733 void MainWin::clientNetworkRemoved(NetworkId id)
1735 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1739 action->deleteLater();
1743 void MainWin::connectOrDisconnectFromNet()
1745 QAction *act = qobject_cast<QAction *>(sender());
1747 const Network *net = Client::network(act->data().value<NetworkId>());
1749 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1750 else net->requestDisconnect();
1754 void MainWin::on_jumpHotBuffer_triggered()
1756 if (!_bufferHotList->rowCount())
1759 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1762 void MainWin::on_bufferSearch_triggered()
1764 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1765 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1769 _bufferViews[_activeBufferViewIndex]->activateFilter();
1773 void MainWin::onJumpKey()
1775 QAction *action = qobject_cast<QAction *>(sender());
1776 if (!action || !Client::bufferModel())
1778 int idx = action->property("Index").toInt();
1780 if (_jumpKeyMap.isEmpty())
1781 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1783 if (!_jumpKeyMap.contains(idx))
1786 BufferId buffer = _jumpKeyMap.value(idx);
1787 if (buffer.isValid())
1788 Client::bufferModel()->switchToBuffer(buffer);
1792 void MainWin::bindJumpKey()
1794 QAction *action = qobject_cast<QAction *>(sender());
1795 if (!action || !Client::bufferModel())
1797 int idx = action->property("Index").toInt();
1799 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1800 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1804 void MainWin::on_actionDebugNetworkModel_triggered()
1806 QTreeView *view = new QTreeView;
1807 view->setAttribute(Qt::WA_DeleteOnClose);
1808 view->setWindowTitle("Debug NetworkModel View");
1809 view->setModel(Client::networkModel());
1810 view->setColumnWidth(0, 250);
1811 view->setColumnWidth(1, 250);
1812 view->setColumnWidth(2, 80);
1813 view->resize(610, 300);
1818 void MainWin::on_actionDebugHotList_triggered()
1820 _bufferHotList->invalidate();
1821 _bufferHotList->sort(0, Qt::DescendingOrder);
1823 QTreeView *view = new QTreeView;
1824 view->setAttribute(Qt::WA_DeleteOnClose);
1825 view->setModel(_bufferHotList);
1830 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1832 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1833 overlay->setAttribute(Qt::WA_DeleteOnClose);
1838 void MainWin::on_actionDebugMessageModel_triggered()
1840 QTableView *view = new QTableView(0);
1841 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1842 filter->setSourceModel(Client::messageModel());
1843 view->setModel(filter);
1844 view->setAttribute(Qt::WA_DeleteOnClose, true);
1845 view->verticalHeader()->hide();
1846 view->horizontalHeader()->setStretchLastSection(true);
1851 void MainWin::on_actionDebugLog_triggered()
1853 DebugLogWidget *logWidget = new DebugLogWidget(0);
1858 void MainWin::showStatusBarMessage(const QString &message)
1860 statusBar()->showMessage(message, 10000);