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(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
208 connect(Client::instance(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
210 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList, QVariantList)), SLOT(showCoreConfigWizard(QVariantList, QVariantList)));
211 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
212 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
213 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
214 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
216 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
220 setDockNestingEnabled(true);
221 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
222 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
223 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
224 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
226 // Order is sometimes important
230 // setupTransferWidget(); not ready yet
242 _bufferWidget->setFocusProxy(_inputWidget);
243 _chatMonitorView->setFocusProxy(_inputWidget);
246 # ifdef HAVE_QTMULTIMEDIA
247 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
250 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
252 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
254 QtUi::registerNotificationBackend(new KNotificationBackend(this));
255 #endif /* HAVE_KDE */
259 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
260 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
261 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
264 #ifdef HAVE_INDICATEQT
265 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
268 #ifdef HAVE_NOTIFICATION_CENTER
269 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
273 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
276 // we assume that at this point, all configurable actions are defined!
277 QtUi::loadShortcuts();
279 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
281 setDisconnectedState(); // Disable menus and stuff
284 setAutoSaveSettings();
287 // restore mainwin state
289 restoreStateFromSettings(s);
291 // restore locked state of docks
292 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
294 CoreConnection *conn = Client::coreConnection();
295 if (!conn->connectToCore()) {
296 // No autoconnect selected (or no accounts)
297 showCoreConnectionDlg();
310 saveStateToSettings(s);
312 QApplication::quit();
316 void MainWin::saveStateToSettings(UiSettings &s)
318 s.setValue("MainWinSize", _normalSize);
319 s.setValue("MainWinPos", _normalPos);
320 s.setValue("MainWinState", saveState());
321 s.setValue("MainWinGeometry", saveGeometry());
322 s.setValue("MainWinMinimized", isMinimized());
323 s.setValue("MainWinMaximized", isMaximized());
324 s.setValue("MainWinHidden", !isVisible());
325 BufferId lastBufId = Client::bufferModel()->currentBuffer();
326 if (lastBufId.isValid())
327 s.setValue("LastUsedBufferId", lastBufId.toInt());
330 saveAutoSaveSettings();
335 void MainWin::restoreStateFromSettings(UiSettings &s)
337 _normalSize = s.value("MainWinSize", size()).toSize();
338 _normalPos = s.value("MainWinPos", pos()).toPoint();
339 bool maximized = s.value("MainWinMaximized", false).toBool();
342 restoreGeometry(s.value("MainWinGeometry").toByteArray());
345 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
350 restoreState(s.value("MainWinState").toByteArray());
356 if ((Quassel::isOptionSet("hidewindow")
357 || s.value("MainWinHidden").toBool())
358 && _systemTray->isSystemTrayAvailable())
359 QtUi::hideMainWidget();
360 else if (s.value("MainWinMinimized").toBool())
368 QMenu *MainWin::createPopupMenu()
370 QMenu *popupMenu = QMainWindow::createPopupMenu();
371 popupMenu->addSeparator();
372 ActionCollection *coll = QtUi::actionCollection("General");
373 popupMenu->addAction(coll->action("ToggleMenuBar"));
378 void MainWin::updateIcon()
381 if (Client::isConnected())
382 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
384 icon = QIcon::fromTheme("inactive-quassel", QIcon(":/icons/inactive-quassel.png"));
386 qApp->setWindowIcon(icon);
390 void MainWin::setupActions()
392 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
394 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("connect-quassel", QIcon(":/icons/connect-quassel.png")), tr("&Connect to Core..."), coll,
395 this, SLOT(showCoreConnectionDlg())));
396 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("disconnect-quassel", QIcon(":/icons/disconnect-quassel.png")), tr("&Disconnect from Core"), coll,
397 Client::instance(), SLOT(disconnectFromCore())));
398 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
399 this, SLOT(showPasswordChangeDlg())));
400 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
401 this, SLOT(showCoreInfoDlg())));
402 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
403 this, SLOT(on_actionConfigureNetworks_triggered())));
404 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
405 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
406 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
409 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
410 this, SLOT(on_actionConfigureViews_triggered())));
412 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
413 lockAct->setCheckable(true);
414 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
416 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
417 0, 0, QKeySequence::Find))->setCheckable(true);
418 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
419 this, SLOT(showAwayLog())));
420 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
421 0, 0))->setCheckable(true);
423 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
424 0, 0))->setCheckable(true);
427 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
429 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
430 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
431 _fullScreenAction->setCheckable(true);
432 coll->addAction("ToggleFullScreen", _fullScreenAction);
436 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
437 this, SLOT(showShortcutsDlg()));
438 configureShortcutsAct->setMenuRole(QAction::NoRole);
439 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
442 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
443 this, SLOT(showSettingsDlg()));
444 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
446 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
447 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
449 coll->addAction("ConfigureQuassel", configureQuasselAct);
452 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
453 this, SLOT(showAboutDlg()));
454 aboutQuasselAct->setMenuRole(QAction::AboutRole);
455 coll->addAction("AboutQuassel", aboutQuasselAct);
457 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
458 qApp, SLOT(aboutQt()));
459 aboutQtAct->setMenuRole(QAction::AboutQtRole);
460 coll->addAction("AboutQt", aboutQtAct);
461 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
462 this, SLOT(on_actionDebugNetworkModel_triggered())));
463 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
464 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
465 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
466 this, SLOT(on_actionDebugMessageModel_triggered())));
467 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
468 this, SLOT(on_actionDebugHotList_triggered())));
469 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
470 this, SLOT(on_actionDebugLog_triggered())));
471 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
472 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
474 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
475 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
478 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
480 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
481 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
483 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
484 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
488 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
489 const int jumpModifier = Qt::ControlModifier;
491 const int bindModifier = Qt::ControlModifier;
492 const int jumpModifier = Qt::AltModifier;
495 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
496 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
497 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
498 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
499 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
500 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
501 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
502 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
503 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
504 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
505 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
506 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
507 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
508 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
509 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
510 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
511 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
512 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
513 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
514 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
516 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
517 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
518 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
519 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
520 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
521 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
522 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
523 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
524 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
525 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
526 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
527 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
528 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
529 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
530 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
531 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
532 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
533 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
534 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
535 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
538 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
539 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
540 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
541 this, SLOT(previousBufferView()), QKeySequence::Back));
542 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
543 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
544 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
545 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
549 void MainWin::setupMenus()
551 ActionCollection *coll = QtUi::actionCollection("General");
553 _fileMenu = menuBar()->addMenu(tr("&File"));
555 static const QStringList coreActions = QStringList()
556 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
559 foreach(QString actionName, coreActions) {
560 coreAction = coll->action(actionName);
561 _fileMenu->addAction(coreAction);
562 flagRemoteCoreOnly(coreAction);
564 flagRemoteCoreOnly(_fileMenu->addSeparator());
566 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
567 _networksMenu->addAction(coll->action("ConfigureNetworks"));
568 _networksMenu->addSeparator();
569 _fileMenu->addSeparator();
570 _fileMenu->addAction(coll->action("Quit"));
572 _viewMenu = menuBar()->addMenu(tr("&View"));
573 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
574 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
575 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
576 _viewMenu->addSeparator();
578 _viewMenu->addAction(coll->action("ToggleMenuBar"));
579 _viewMenu->addAction(coll->action("ToggleStatusBar"));
580 _viewMenu->addAction(coll->action("ToggleSearchBar"));
582 coreAction = coll->action("ShowAwayLog");
583 flagRemoteCoreOnly(coreAction);
584 _viewMenu->addAction(coreAction);
586 _viewMenu->addSeparator();
587 _viewMenu->addAction(coll->action("LockLayout"));
589 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
591 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
592 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
594 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
596 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
599 _helpMenu = menuBar()->addMenu(tr("&Help"));
601 _helpMenu->addAction(coll->action("AboutQuassel"));
603 _helpMenu->addAction(coll->action("AboutQt"));
605 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
607 _helpMenu->addSeparator();
608 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
609 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
610 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
611 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
612 _helpDebugMenu->addAction(coll->action("DebugHotList"));
613 _helpDebugMenu->addAction(coll->action("DebugLog"));
614 _helpDebugMenu->addSeparator();
615 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
618 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
620 QtUiSettings uiSettings;
621 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
622 showMenuBar->setChecked(enabled);
623 enabled ? menuBar()->show() : menuBar()->hide();
625 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
626 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
630 void MainWin::setupBufferWidget()
632 _bufferWidget = new BufferWidget(this);
633 _bufferWidget->setModel(Client::bufferModel());
634 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
635 setCentralWidget(_bufferWidget);
639 void MainWin::addBufferView(int bufferViewConfigId)
641 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
645 void MainWin::addBufferView(ClientBufferViewConfig *config)
650 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
651 BufferViewDock *dock = new BufferViewDock(config, this);
653 //create the view and initialize it's filter
654 BufferView *view = new BufferView(dock);
655 view->setFilteredModel(Client::bufferModel(), config);
656 view->installEventFilter(_inputWidget); // for key presses
658 Client::bufferModel()->synchronizeView(view);
660 dock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
662 dock->setWidget(view);
663 dock->setVisible(_layoutLoaded); // don't show before state has been restored
665 addDockWidget(Qt::LeftDockWidgetArea, dock);
666 _bufferViewsMenu->addAction(dock->toggleViewAction());
668 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
669 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
670 _bufferViews.append(dock);
672 if (!activeBufferView())
677 void MainWin::removeBufferView(int bufferViewConfigId)
680 BufferViewDock *dock;
681 foreach(QAction *action, _bufferViewsMenu->actions()) {
682 actionData = action->data();
683 if (!actionData.isValid())
686 dock = qobject_cast<BufferViewDock *>(action->parent());
687 if (dock && actionData.toInt() == bufferViewConfigId) {
688 removeAction(action);
689 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
690 _bufferViews.removeAll(dock);
692 if (dock->isActive()) {
693 dock->setActive(false);
694 _activeBufferViewIndex = -1;
704 void MainWin::bufferViewToggled(bool enabled)
706 if (!enabled && !isMinimized()) {
707 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
708 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
711 QAction *action = qobject_cast<QAction *>(sender());
713 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
716 // Make sure we don't toggle backlog fetch for a view we've already removed
717 if (!_bufferViews.contains(dock))
721 Client::bufferViewOverlay()->addView(dock->bufferViewId());
723 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
727 void MainWin::bufferViewVisibilityChanged(bool visible)
730 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
732 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
737 BufferView *MainWin::allBuffersView() const
739 // "All Buffers" is always the first dock created
740 if (_bufferViews.count() > 0)
741 return _bufferViews[0]->bufferView();
746 BufferView *MainWin::activeBufferView() const
748 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
750 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
751 return dock->isActive() ? dock->bufferView() : 0;
755 void MainWin::changeActiveBufferView(int bufferViewId)
757 if (bufferViewId < 0)
760 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
761 _bufferViews[_activeBufferViewIndex]->setActive(false);
762 _activeBufferViewIndex = -1;
765 for (int i = 0; i < _bufferViews.count(); i++) {
766 BufferViewDock *dock = _bufferViews.at(i);
767 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
768 _activeBufferViewIndex = i;
769 dock->setActive(true);
774 nextBufferView(); // fallback
778 void MainWin::showPasswordChangeDlg()
780 if(Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
781 PasswordChangeDlg dlg(this);
785 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
786 tr("<b>Your Quassel Core does not support this feature</b>"),
787 QMessageBox::Ok, this);
788 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
794 void MainWin::changeActiveBufferView(bool backwards)
796 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
797 _bufferViews[_activeBufferViewIndex]->setActive(false);
800 if (!_bufferViews.count())
803 int c = _bufferViews.count();
804 while (c--) { // yes, this will reactivate the current active one if all others fail
806 if (--_activeBufferViewIndex < 0)
807 _activeBufferViewIndex = _bufferViews.count()-1;
810 if (++_activeBufferViewIndex >= _bufferViews.count())
811 _activeBufferViewIndex = 0;
814 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
815 if (dock->isHidden())
818 dock->setActive(true);
822 _activeBufferViewIndex = -1;
826 void MainWin::nextBufferView()
828 changeActiveBufferView(false);
832 void MainWin::previousBufferView()
834 changeActiveBufferView(true);
838 void MainWin::nextBuffer()
840 BufferView *view = activeBufferView();
846 void MainWin::previousBuffer()
848 BufferView *view = activeBufferView();
850 view->previousBuffer();
854 void MainWin::hideCurrentBuffer()
856 BufferView *view = activeBufferView();
858 view->hideCurrentBuffer();
862 void MainWin::showNotificationsDlg()
864 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
869 void MainWin::on_actionConfigureNetworks_triggered()
871 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
876 void MainWin::on_actionConfigureViews_triggered()
878 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
883 void MainWin::on_actionLockLayout_toggled(bool lock)
885 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
886 foreach(VerticalDock *dock, docks) {
887 dock->showTitle(!lock);
890 QList<NickListDock *> nickdocks = findChildren<NickListDock *>();
891 foreach(NickListDock *nickdock, nickdocks) {
892 nickdock->setLocked(lock);
895 QList<BufferViewDock *> bufferdocks = findChildren<BufferViewDock *>();
896 foreach(BufferViewDock *bufferdock, bufferdocks) {
897 bufferdock->setLocked(lock);
900 if (Client::bufferViewManager()) {
901 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
902 config->setLocked(lock);
906 _mainToolBar->setMovable(!lock);
907 _nickToolBar->setMovable(!lock);
909 QtUiSettings().setValue("LockLayout", lock);
913 void MainWin::setupNickWidget()
916 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
917 nickDock->setObjectName("NickDock");
918 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
919 nickDock->setLocked(QtUiSettings().value("LockLayout", false).toBool());
921 _nickListWidget = new NickListWidget(nickDock);
922 nickDock->setWidget(_nickListWidget);
924 addDockWidget(Qt::RightDockWidgetArea, nickDock);
925 _viewMenu->addAction(nickDock->toggleViewAction());
926 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
928 // See NickListDock::NickListDock();
929 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
931 // attach the NickListWidget to the BufferModel and the default selection
932 _nickListWidget->setModel(Client::bufferModel());
933 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
935 _nickListWidget->setVisible(false);
939 void MainWin::setupChatMonitor()
941 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
942 dock->setObjectName("ChatMonitorDock");
944 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
945 _chatMonitorView = new ChatMonitorView(filter, this);
946 _chatMonitorView->show();
947 dock->setWidget(_chatMonitorView);
950 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
951 _viewMenu->addAction(dock->toggleViewAction());
952 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
956 void MainWin::setupInputWidget()
958 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
959 dock->setObjectName("InputDock");
961 _inputWidget = new InputWidget(dock);
962 dock->setWidget(_inputWidget);
964 addDockWidget(Qt::BottomDockWidgetArea, dock);
966 _viewMenu->addAction(dock->toggleViewAction());
967 dock->toggleViewAction()->setText(tr("Show Input Line"));
969 _inputWidget->setModel(Client::bufferModel());
970 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
972 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
974 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
978 void MainWin::setupTopicWidget()
980 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
981 dock->setObjectName("TopicDock");
982 _topicWidget = new TopicWidget(dock);
984 dock->setWidget(_topicWidget);
986 _topicWidget->setModel(Client::bufferModel());
987 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
989 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
991 _viewMenu->addAction(dock->toggleViewAction());
992 dock->toggleViewAction()->setText(tr("Show Topic Line"));
996 void MainWin::setupTransferWidget()
998 auto dock = new QDockWidget(tr("Transfers"), this);
999 dock->setObjectName("TransferDock");
1000 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
1002 auto view = new QTableView(dock); // to be replaced by the real thing
1003 view->setModel(Client::transferModel());
1004 dock->setWidget(view);
1005 dock->hide(); // hidden by default
1006 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
1008 auto action = dock->toggleViewAction();
1009 action->setText(tr("Show File Transfers"));
1010 action->setIcon(QIcon::fromTheme("download"));
1011 action->setShortcut(QKeySequence(Qt::Key_F6));
1012 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
1013 _viewMenu->addAction(action);
1017 void MainWin::setupViewMenuTail()
1019 _viewMenu->addSeparator();
1020 _viewMenu->addAction(_fullScreenAction);
1024 void MainWin::setupTitleSetter()
1026 _titleSetter.setModel(Client::bufferModel());
1027 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1031 void MainWin::setupStatusBar()
1033 // MessageProcessor progress
1034 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1037 _coreConnectionStatusWidget->update();
1038 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1040 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1042 QtUiSettings uiSettings;
1044 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1045 showStatusbar->setChecked(enabled);
1046 enabled ? statusBar()->show() : statusBar()->hide();
1048 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1049 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1051 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1055 void MainWin::setupHotList()
1057 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1058 flatProxy->setSourceModel(Client::bufferModel());
1059 _bufferHotList = new BufferHotListFilter(flatProxy);
1063 void MainWin::saveMenuBarStatus(bool enabled)
1065 QtUiSettings uiSettings;
1066 uiSettings.setValue("ShowMenuBar", enabled);
1070 void MainWin::saveStatusBarStatus(bool enabled)
1072 QtUiSettings uiSettings;
1073 uiSettings.setValue("ShowStatusBar", enabled);
1077 void MainWin::setupSystray()
1080 _systemTray = new StatusNotifierItem(this);
1081 #elif !defined QT_NO_SYSTEMTRAYICON
1082 _systemTray = new LegacySystemTray(this);
1084 _systemTray = new SystemTray(this); // dummy
1086 _systemTray->init();
1090 void MainWin::setupToolBars()
1092 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1093 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1094 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1095 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1098 setUnifiedTitleAndToolBarOnMac(true);
1102 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1104 _mainToolBar = new QToolBar(this);
1105 _mainToolBar->setObjectName("MainToolBar");
1107 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1108 addToolBar(_mainToolBar);
1110 if (Quassel::runMode() != Quassel::Monolithic) {
1111 ActionCollection *coll = QtUi::actionCollection("General");
1112 _mainToolBar->addAction(coll->action("ConnectCore"));
1113 _mainToolBar->addAction(coll->action("DisconnectCore"));
1116 _mainToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1118 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1119 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1122 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1124 _nickToolBar = new QToolBar(this);
1125 _nickToolBar->setObjectName("NickToolBar");
1127 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1128 _nickToolBar->setVisible(false); //default: not visible
1129 addToolBar(_nickToolBar);
1130 _nickToolBar->setMovable(!QtUiSettings().value("LockLayout", false).toBool());
1132 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1133 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1136 QtUiSettings uiSettings;
1138 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1139 _mainToolBar->setVisible(visible);
1140 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1144 void MainWin::saveMainToolBarStatus(bool enabled)
1147 QtUiSettings uiSettings;
1148 uiSettings.setValue("ShowMainToolBar", enabled);
1155 void MainWin::connectedToCore()
1157 Q_CHECK_PTR(Client::bufferViewManager());
1158 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1159 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1160 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1162 if (Client::transferManager()) {
1163 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1166 setConnectedState();
1170 void MainWin::setConnectedState()
1172 ActionCollection *coll = QtUi::actionCollection("General");
1174 coll->action("ConnectCore")->setEnabled(false);
1175 coll->action("DisconnectCore")->setEnabled(true);
1176 coll->action("ChangePassword")->setEnabled(true);
1177 coll->action("CoreInfo")->setEnabled(true);
1179 foreach(QAction *action, _fileMenu->actions()) {
1180 if (isRemoteCoreOnly(action))
1181 action->setVisible(!Client::internalCore());
1184 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1185 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1186 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1187 if (!Client::internalCore()) {
1188 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1189 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1190 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1193 // _viewMenu->setEnabled(true);
1194 if (!Client::internalCore())
1195 statusBar()->showMessage(tr("Connected to core."));
1197 statusBar()->clearMessage();
1199 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1201 systemTray()->setState(SystemTray::Active);
1203 if (Client::networkIds().isEmpty()) {
1204 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1208 // Monolithic always preselects last used buffer - Client only if the connection died
1209 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1211 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1212 if (lastUsedBufferId.isValid())
1213 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1219 void MainWin::loadLayout()
1222 int accountId = Client::currentCoreAccount().accountId().toInt();
1223 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1224 if (state.isEmpty()) {
1225 foreach(BufferViewDock *view, _bufferViews)
1227 _layoutLoaded = true;
1230 _nickListWidget->setVisible(true);
1231 restoreState(state, accountId);
1232 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1233 if (bufferViewId >= 0)
1234 changeActiveBufferView(bufferViewId);
1236 _layoutLoaded = true;
1240 void MainWin::saveLayout()
1243 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1244 if (accountId > 0) {
1245 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1246 BufferView *view = activeBufferView();
1247 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1252 void MainWin::disconnectedFromCore()
1254 // save core specific layout and remove bufferviews;
1256 _layoutLoaded = false;
1258 QVariant actionData;
1259 BufferViewDock *dock;
1260 foreach(QAction *action, _bufferViewsMenu->actions()) {
1261 actionData = action->data();
1262 if (!actionData.isValid())
1265 dock = qobject_cast<BufferViewDock *>(action->parent());
1266 if (dock && actionData.toInt() != -1) {
1267 removeAction(action);
1268 _bufferViews.removeAll(dock);
1269 dock->deleteLater();
1273 // store last active buffer
1275 BufferId lastBufId = _bufferWidget->currentBuffer();
1276 if (lastBufId.isValid()) {
1277 s.setValue("LastUsedBufferId", lastBufId.toInt());
1278 // clear the current selection
1279 Client::bufferModel()->standardSelectionModel()->clearSelection();
1281 restoreState(s.value("MainWinState").toByteArray());
1282 setDisconnectedState();
1286 void MainWin::setDisconnectedState()
1288 ActionCollection *coll = QtUi::actionCollection("General");
1289 //ui.menuCore->setEnabled(false);
1290 coll->action("ConnectCore")->setEnabled(true);
1291 coll->action("DisconnectCore")->setEnabled(false);
1292 coll->action("CoreInfo")->setEnabled(false);
1293 coll->action("ChangePassword")->setEnabled(false);
1294 //_viewMenu->setEnabled(false);
1295 statusBar()->showMessage(tr("Not connected to core."));
1296 if (_msgProcessorStatusWidget)
1297 _msgProcessorStatusWidget->setProgress(0, 0);
1299 systemTray()->setState(SystemTray::Passive);
1300 _nickListWidget->setVisible(false);
1304 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1306 Q_UNUSED(errorMessage)
1307 CoreConnectAuthDlg dlg(account, this);
1308 *valid = (dlg.exec() == QDialog::Accepted);
1312 void MainWin::handleNoSslInClient(bool *accepted)
1314 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1315 QMessageBox::Ignore|QMessageBox::Cancel, this);
1316 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1317 box.setDefaultButton(QMessageBox::Ignore);
1318 *accepted = box.exec() == QMessageBox::Ignore;
1322 void MainWin::handleNoSslInCore(bool *accepted)
1324 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1325 QMessageBox::Ignore|QMessageBox::Cancel, this);
1326 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1327 box.setDefaultButton(QMessageBox::Ignore);
1328 *accepted = box.exec() == QMessageBox::Ignore;
1334 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1336 QString errorString = "<ul>";
1337 foreach(const QSslError error, socket->sslErrors())
1338 errorString += QString("<li>%1</li>").arg(error.errorString());
1339 errorString += "</ul>";
1341 QMessageBox box(QMessageBox::Warning,
1342 tr("Untrusted Security Certificate"),
1343 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1344 QMessageBox::Cancel, this);
1345 box.setInformativeText(errorString);
1346 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1347 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1349 QMessageBox::ButtonRole role;
1352 role = box.buttonRole(box.clickedButton());
1353 if (role == QMessageBox::HelpRole) {
1354 SslInfoDlg dlg(socket, this);
1358 while (role == QMessageBox::HelpRole);
1360 *accepted = role == QMessageBox::AcceptRole;
1362 QMessageBox box2(QMessageBox::Warning,
1363 tr("Untrusted Security Certificate"),
1364 tr("Would you like to accept this certificate forever without being prompted?"),
1366 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1367 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1369 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1374 #endif /* HAVE_SSL */
1376 void MainWin::handleCoreConnectionError(const QString &error)
1378 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1382 void MainWin::showCoreConnectionDlg()
1384 CoreConnectDlg dlg(this);
1385 if (dlg.exec() == QDialog::Accepted) {
1386 AccountId accId = dlg.selectedAccount();
1387 if (accId.isValid())
1388 Client::coreConnection()->connectToCore(accId);
1393 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1395 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1401 void MainWin::showChannelList(NetworkId netId)
1403 ChannelListDlg *channelListDlg = new ChannelListDlg();
1405 if (!netId.isValid()) {
1406 QAction *action = qobject_cast<QAction *>(sender());
1408 netId = action->data().value<NetworkId>();
1411 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1412 channelListDlg->setNetwork(netId);
1413 channelListDlg->show();
1417 void MainWin::showIgnoreList(QString newRule)
1419 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1420 // prepare config dialog for new rule
1421 if (!newRule.isEmpty())
1422 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1427 void MainWin::showCoreInfoDlg()
1429 CoreInfoDlg(this).exec();
1433 void MainWin::showAwayLog()
1437 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1438 _awayLog = new AwayLogView(filter, 0);
1439 filter->setParent(_awayLog);
1440 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1441 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1446 void MainWin::awayLogDestroyed()
1452 void MainWin::showSettingsDlg()
1454 SettingsDlg *dlg = new SettingsDlg();
1456 //Category: Interface
1457 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1458 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1459 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1460 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1461 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1462 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1463 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1464 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1466 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1468 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1469 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1470 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1471 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1474 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1475 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1476 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1477 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1478 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1479 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1481 // Category: Remote Cores
1482 if (Quassel::runMode() != Quassel::Monolithic) {
1483 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1484 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1491 void MainWin::showAboutDlg()
1493 AboutDlg(this).exec();
1497 void MainWin::showShortcutsDlg()
1500 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1501 foreach(KActionCollection *coll, QtUi::actionCollections())
1502 dlg.addCollection(coll, coll->property("Category").toString());
1503 dlg.configure(true);
1505 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1511 void MainWin::showNewTransferDlg(const QUuid &transferId)
1513 auto transfer = Client::transferManager()->transfer(transferId);
1515 if (transfer->status() == Transfer::Status::New) {
1516 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1521 qWarning() << "Unknown transfer ID" << transferId;
1526 void MainWin::onFullScreenToggled()
1528 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1529 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1532 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1534 if (_fullScreenAction->isChecked())
1535 setWindowState(windowState() | Qt::WindowFullScreen);
1537 setWindowState(windowState() & ~Qt::WindowFullScreen);
1542 /********************************************************************************************************/
1544 bool MainWin::event(QEvent *event)
1546 switch(event->type()) {
1547 case QEvent::WindowActivate: {
1548 BufferId bufferId = Client::bufferModel()->currentBuffer();
1549 if (bufferId.isValid())
1550 Client::instance()->markBufferAsRead(bufferId);
1553 case QEvent::WindowDeactivate:
1554 if (bufferWidget()->autoMarkerLineOnLostFocus())
1555 bufferWidget()->setMarkerLine();
1560 return QMainWindow::event(event);
1564 void MainWin::moveEvent(QMoveEvent *event)
1566 if (!(windowState() & Qt::WindowMaximized))
1567 _normalPos = event->pos();
1569 QMainWindow::moveEvent(event);
1573 void MainWin::resizeEvent(QResizeEvent *event)
1575 if (!(windowState() & Qt::WindowMaximized))
1576 _normalSize = event->size();
1578 QMainWindow::resizeEvent(event);
1582 void MainWin::closeEvent(QCloseEvent *event)
1585 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1587 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1588 // This messes up MainWinState/MainWinHidden save/restore.
1589 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1590 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1591 QtUi::hideMainWidget();
1594 else if(!_aboutToQuit) {
1595 _aboutToQuit = true;
1605 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1609 bool hasFocus = QApplication::activeWindow() != 0;
1611 for (int i = start; i <= end; i++) {
1612 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1613 if (!idx.isValid()) {
1614 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1617 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1618 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1621 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1622 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1624 // check if bufferId belongs to the shown chatlists
1625 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1626 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1629 // check if it's the buffer currently displayed
1630 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1633 // only show notifications for higlights or queries
1634 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1637 // and of course: don't notify for ignored messages
1638 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1641 // seems like we have a legit notification candidate!
1642 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1643 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1644 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1645 AbstractNotificationBackend::NotificationType type;
1647 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1648 type = AbstractNotificationBackend::PrivMsg;
1649 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1650 type = AbstractNotificationBackend::PrivMsgFocused;
1651 else if (flags & Message::Highlight && !hasFocus)
1652 type = AbstractNotificationBackend::Highlight;
1654 type = AbstractNotificationBackend::HighlightFocused;
1656 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1661 void MainWin::currentBufferChanged(BufferId buffer)
1663 if (buffer.isValid())
1664 Client::instance()->markBufferAsRead(buffer);
1668 void MainWin::clientNetworkCreated(NetworkId id)
1670 const Network *net = Client::network(id);
1671 QAction *act = new QAction(net->networkName(), this);
1672 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1673 act->setData(QVariant::fromValue<NetworkId>(id));
1674 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1675 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1677 QAction *beforeAction = 0;
1678 foreach(QAction *action, _networksMenu->actions()) {
1679 if (!action->data().isValid()) // ignore stock actions
1681 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1682 beforeAction = action;
1686 _networksMenu->insertAction(beforeAction, act);
1690 void MainWin::clientNetworkUpdated()
1692 const Network *net = qobject_cast<const Network *>(sender());
1696 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1700 action->setText(net->networkName());
1702 switch (net->connectionState()) {
1703 case Network::Initialized:
1704 action->setIcon(QIcon::fromTheme("network-connect"));
1705 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1706 if (!bufferWidget()->currentBuffer().isValid()) {
1707 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1708 if (idx.isValid()) {
1709 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1710 Client::bufferModel()->switchToBuffer(statusBufferId);
1714 case Network::Disconnected:
1715 action->setIcon(QIcon::fromTheme("network-disconnect"));
1718 action->setIcon(QIcon::fromTheme("network-wired"));
1723 void MainWin::clientNetworkRemoved(NetworkId id)
1725 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1729 action->deleteLater();
1733 void MainWin::connectOrDisconnectFromNet()
1735 QAction *act = qobject_cast<QAction *>(sender());
1737 const Network *net = Client::network(act->data().value<NetworkId>());
1739 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1740 else net->requestDisconnect();
1744 void MainWin::on_jumpHotBuffer_triggered()
1746 if (!_bufferHotList->rowCount())
1749 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1752 void MainWin::on_bufferSearch_triggered()
1754 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1755 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1759 _bufferViews[_activeBufferViewIndex]->activateFilter();
1763 void MainWin::onJumpKey()
1765 QAction *action = qobject_cast<QAction *>(sender());
1766 if (!action || !Client::bufferModel())
1768 int idx = action->property("Index").toInt();
1770 if (_jumpKeyMap.isEmpty())
1771 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1773 if (!_jumpKeyMap.contains(idx))
1776 BufferId buffer = _jumpKeyMap.value(idx);
1777 if (buffer.isValid())
1778 Client::bufferModel()->switchToBuffer(buffer);
1782 void MainWin::bindJumpKey()
1784 QAction *action = qobject_cast<QAction *>(sender());
1785 if (!action || !Client::bufferModel())
1787 int idx = action->property("Index").toInt();
1789 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1790 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1794 void MainWin::on_actionDebugNetworkModel_triggered()
1796 QTreeView *view = new QTreeView;
1797 view->setAttribute(Qt::WA_DeleteOnClose);
1798 view->setWindowTitle("Debug NetworkModel View");
1799 view->setModel(Client::networkModel());
1800 view->setColumnWidth(0, 250);
1801 view->setColumnWidth(1, 250);
1802 view->setColumnWidth(2, 80);
1803 view->resize(610, 300);
1808 void MainWin::on_actionDebugHotList_triggered()
1810 _bufferHotList->invalidate();
1811 _bufferHotList->sort(0, Qt::DescendingOrder);
1813 QTreeView *view = new QTreeView;
1814 view->setAttribute(Qt::WA_DeleteOnClose);
1815 view->setModel(_bufferHotList);
1820 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1822 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1823 overlay->setAttribute(Qt::WA_DeleteOnClose);
1828 void MainWin::on_actionDebugMessageModel_triggered()
1830 QTableView *view = new QTableView(0);
1831 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1832 filter->setSourceModel(Client::messageModel());
1833 view->setModel(filter);
1834 view->setAttribute(Qt::WA_DeleteOnClose, true);
1835 view->verticalHeader()->hide();
1836 view->horizontalHeader()->setStretchLastSection(true);
1841 void MainWin::on_actionDebugLog_triggered()
1843 DebugLogWidget *logWidget = new DebugLogWidget(0);
1848 void MainWin::showStatusBarMessage(const QString &message)
1850 statusBar()->showMessage(message, 10000);