1 /***************************************************************************
2 * Copyright (C) 2005-2016 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/highlightsettingspage.h"
150 #include "settingspages/identitiessettingspage.h"
151 #include "settingspages/ignorelistsettingspage.h"
152 #include "settingspages/inputwidgetsettingspage.h"
153 #include "settingspages/itemviewsettingspage.h"
154 #include "settingspages/networkssettingspage.h"
155 #include "settingspages/notificationssettingspage.h"
156 #include "settingspages/topicwidgetsettingspage.h"
159 # include "settingspages/shortcutssettingspage.h"
163 # include "settingspages/sonnetsettingspage.h"
167 MainWin::MainWin(QWidget *parent)
169 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
171 : QMainWindow(parent),
173 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
174 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
177 _layoutLoaded(false),
178 _activeBufferViewIndex(-1),
181 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
183 QtUiSettings uiSettings;
184 QString style = uiSettings.value("Style", QString()).toString();
185 if (!style.isEmpty()) {
186 QApplication::setStyle(style);
189 QApplication::setQuitOnLastWindowClosed(false);
191 setWindowTitle("Quassel IRC");
192 setWindowIconText("Quassel IRC");
199 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
200 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
201 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
202 SLOT(messagesInserted(const QModelIndex &, int, int)));
203 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
204 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
206 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
207 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
208 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
209 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
210 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
212 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
216 setDockNestingEnabled(true);
217 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
218 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
219 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
220 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
222 // Order is sometimes important
226 setupTransferWidget();
238 _bufferWidget->setFocusProxy(_inputWidget);
239 _chatMonitorView->setFocusProxy(_inputWidget);
242 # ifdef HAVE_QTMULTIMEDIA
243 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
246 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
248 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
250 QtUi::registerNotificationBackend(new KNotificationBackend(this));
251 #endif /* HAVE_KDE */
255 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
256 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
257 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
260 #ifdef HAVE_INDICATEQT
261 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
264 #ifdef HAVE_NOTIFICATION_CENTER
265 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
269 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
272 // we assume that at this point, all configurable actions are defined!
273 QtUi::loadShortcuts();
275 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
277 setDisconnectedState(); // Disable menus and stuff
280 setAutoSaveSettings();
283 // restore mainwin state
285 restoreStateFromSettings(s);
287 // restore locked state of docks
288 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
290 CoreConnection *conn = Client::coreConnection();
291 if (!conn->connectToCore()) {
292 // No autoconnect selected (or no accounts)
293 showCoreConnectionDlg();
306 saveStateToSettings(s);
308 QApplication::quit();
312 void MainWin::saveStateToSettings(UiSettings &s)
314 s.setValue("MainWinSize", _normalSize);
315 s.setValue("MainWinPos", _normalPos);
316 s.setValue("MainWinState", saveState());
317 s.setValue("MainWinGeometry", saveGeometry());
318 s.setValue("MainWinMinimized", isMinimized());
319 s.setValue("MainWinMaximized", isMaximized());
320 s.setValue("MainWinHidden", !isVisible());
321 BufferId lastBufId = Client::bufferModel()->currentBuffer();
322 if (lastBufId.isValid())
323 s.setValue("LastUsedBufferId", lastBufId.toInt());
326 saveAutoSaveSettings();
331 void MainWin::restoreStateFromSettings(UiSettings &s)
333 _normalSize = s.value("MainWinSize", size()).toSize();
334 _normalPos = s.value("MainWinPos", pos()).toPoint();
335 bool maximized = s.value("MainWinMaximized", false).toBool();
338 restoreGeometry(s.value("MainWinGeometry").toByteArray());
341 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
346 restoreState(s.value("MainWinState").toByteArray());
352 if ((Quassel::isOptionSet("hidewindow")
353 || s.value("MainWinHidden").toBool())
354 && _systemTray->isSystemTrayAvailable())
355 QtUi::hideMainWidget();
356 else if (s.value("MainWinMinimized").toBool())
364 QMenu *MainWin::createPopupMenu()
366 QMenu *popupMenu = QMainWindow::createPopupMenu();
367 popupMenu->addSeparator();
368 ActionCollection *coll = QtUi::actionCollection("General");
369 popupMenu->addAction(coll->action("ToggleMenuBar"));
374 void MainWin::updateIcon()
377 if (Client::isConnected())
378 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
380 icon = QIcon::fromTheme("quassel-inactive", QIcon(":/icons/quassel-128.png"));
382 qApp->setWindowIcon(icon);
386 void MainWin::setupActions()
388 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
390 coll->addAction("ConnectCore", new Action(QIcon(":/icons/quassel-128.png"), tr("&Connect to Core..."), coll,
391 this, SLOT(showCoreConnectionDlg())));
392 coll->addAction("DisconnectCore", new Action(QIcon(":/icons/quassel-disconnect.png"), tr("&Disconnect from Core"), coll,
393 Client::instance(), SLOT(disconnectFromCore())));
394 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
395 this, SLOT(showPasswordChangeDlg())));
396 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
397 this, SLOT(showCoreInfoDlg())));
398 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
399 this, SLOT(on_actionConfigureNetworks_triggered())));
400 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
401 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
402 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
405 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
406 this, SLOT(on_actionConfigureViews_triggered())));
408 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
409 lockAct->setCheckable(true);
410 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
412 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
413 0, 0, QKeySequence::Find))->setCheckable(true);
414 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
415 this, SLOT(showAwayLog())));
416 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
417 0, 0))->setCheckable(true);
419 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
420 0, 0))->setCheckable(true);
423 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
425 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
426 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
427 _fullScreenAction->setCheckable(true);
428 coll->addAction("ToggleFullScreen", _fullScreenAction);
432 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
433 this, SLOT(showShortcutsDlg()));
434 configureShortcutsAct->setMenuRole(QAction::NoRole);
435 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
438 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
439 this, SLOT(showSettingsDlg()));
440 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
442 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
443 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
445 coll->addAction("ConfigureQuassel", configureQuasselAct);
448 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
449 this, SLOT(showAboutDlg()));
450 aboutQuasselAct->setMenuRole(QAction::AboutRole);
451 coll->addAction("AboutQuassel", aboutQuasselAct);
453 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
454 qApp, SLOT(aboutQt()));
455 aboutQtAct->setMenuRole(QAction::AboutQtRole);
456 coll->addAction("AboutQt", aboutQtAct);
457 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
458 this, SLOT(on_actionDebugNetworkModel_triggered())));
459 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
460 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
461 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
462 this, SLOT(on_actionDebugMessageModel_triggered())));
463 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
464 this, SLOT(on_actionDebugHotList_triggered())));
465 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
466 this, SLOT(on_actionDebugLog_triggered())));
467 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
468 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
470 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
471 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
474 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
476 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
477 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
479 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
480 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
484 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
485 const int jumpModifier = Qt::ControlModifier;
487 const int bindModifier = Qt::ControlModifier;
488 const int jumpModifier = Qt::AltModifier;
491 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
492 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
493 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
494 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
495 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
496 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
497 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
498 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
499 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
500 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
501 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
502 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
503 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
504 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
505 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
506 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
507 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
508 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
509 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
510 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
512 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
513 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
514 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
515 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
516 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
517 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
518 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
519 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
520 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
521 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
522 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
523 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
524 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
525 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
526 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
527 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
528 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
529 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
530 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
531 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
534 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
535 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
536 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
537 this, SLOT(previousBufferView()), QKeySequence::Back));
538 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
539 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
540 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
541 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
545 void MainWin::setupMenus()
547 ActionCollection *coll = QtUi::actionCollection("General");
549 _fileMenu = menuBar()->addMenu(tr("&File"));
551 static const QStringList coreActions = QStringList()
552 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
555 foreach(QString actionName, coreActions) {
556 coreAction = coll->action(actionName);
557 _fileMenu->addAction(coreAction);
558 flagRemoteCoreOnly(coreAction);
560 flagRemoteCoreOnly(_fileMenu->addSeparator());
562 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
563 _networksMenu->addAction(coll->action("ConfigureNetworks"));
564 _networksMenu->addSeparator();
565 _fileMenu->addSeparator();
566 _fileMenu->addAction(coll->action("Quit"));
568 _viewMenu = menuBar()->addMenu(tr("&View"));
569 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
570 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
571 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
572 _viewMenu->addSeparator();
574 _viewMenu->addAction(coll->action("ToggleMenuBar"));
575 _viewMenu->addAction(coll->action("ToggleStatusBar"));
576 _viewMenu->addAction(coll->action("ToggleSearchBar"));
578 coreAction = coll->action("ShowAwayLog");
579 flagRemoteCoreOnly(coreAction);
580 _viewMenu->addAction(coreAction);
582 _viewMenu->addSeparator();
583 _viewMenu->addAction(coll->action("LockLayout"));
585 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
587 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
588 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
590 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
592 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
595 _helpMenu = menuBar()->addMenu(tr("&Help"));
597 _helpMenu->addAction(coll->action("AboutQuassel"));
599 _helpMenu->addAction(coll->action("AboutQt"));
601 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
603 _helpMenu->addSeparator();
604 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
605 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
606 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
607 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
608 _helpDebugMenu->addAction(coll->action("DebugHotList"));
609 _helpDebugMenu->addAction(coll->action("DebugLog"));
610 _helpDebugMenu->addSeparator();
611 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
614 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
616 QtUiSettings uiSettings;
617 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
618 showMenuBar->setChecked(enabled);
619 enabled ? menuBar()->show() : menuBar()->hide();
621 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
622 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
626 void MainWin::setupBufferWidget()
628 _bufferWidget = new BufferWidget(this);
629 _bufferWidget->setModel(Client::bufferModel());
630 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
631 setCentralWidget(_bufferWidget);
635 void MainWin::addBufferView(int bufferViewConfigId)
637 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
641 void MainWin::addBufferView(ClientBufferViewConfig *config)
646 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
647 BufferViewDock *dock = new BufferViewDock(config, this);
649 //create the view and initialize it's filter
650 BufferView *view = new BufferView(dock);
651 view->setFilteredModel(Client::bufferModel(), config);
652 view->installEventFilter(_inputWidget); // for key presses
654 Client::bufferModel()->synchronizeView(view);
656 dock->setWidget(view);
657 dock->setVisible(_layoutLoaded); // don't show before state has been restored
659 addDockWidget(Qt::LeftDockWidgetArea, dock);
660 _bufferViewsMenu->addAction(dock->toggleViewAction());
662 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
663 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
664 _bufferViews.append(dock);
666 if (!activeBufferView())
671 void MainWin::removeBufferView(int bufferViewConfigId)
674 BufferViewDock *dock;
675 foreach(QAction *action, _bufferViewsMenu->actions()) {
676 actionData = action->data();
677 if (!actionData.isValid())
680 dock = qobject_cast<BufferViewDock *>(action->parent());
681 if (dock && actionData.toInt() == bufferViewConfigId) {
682 removeAction(action);
683 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
684 _bufferViews.removeAll(dock);
686 if (dock->isActive()) {
687 dock->setActive(false);
688 _activeBufferViewIndex = -1;
698 void MainWin::bufferViewToggled(bool enabled)
700 if (!enabled && !isMinimized()) {
701 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
702 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
705 QAction *action = qobject_cast<QAction *>(sender());
707 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
710 // Make sure we don't toggle backlog fetch for a view we've already removed
711 if (!_bufferViews.contains(dock))
715 Client::bufferViewOverlay()->addView(dock->bufferViewId());
717 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
721 void MainWin::bufferViewVisibilityChanged(bool visible)
724 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
726 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
731 BufferView *MainWin::allBuffersView() const
733 // "All Buffers" is always the first dock created
734 if (_bufferViews.count() > 0)
735 return _bufferViews[0]->bufferView();
740 BufferView *MainWin::activeBufferView() const
742 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
744 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
745 return dock->isActive() ? dock->bufferView() : 0;
749 void MainWin::changeActiveBufferView(int bufferViewId)
751 if (bufferViewId < 0)
754 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
755 _bufferViews[_activeBufferViewIndex]->setActive(false);
756 _activeBufferViewIndex = -1;
759 for (int i = 0; i < _bufferViews.count(); i++) {
760 BufferViewDock *dock = _bufferViews.at(i);
761 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
762 _activeBufferViewIndex = i;
763 dock->setActive(true);
768 nextBufferView(); // fallback
772 void MainWin::showPasswordChangeDlg()
774 if((Client::coreFeatures() & Quassel::PasswordChange)) {
775 PasswordChangeDlg dlg(this);
779 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
780 tr("<b>Your Quassel Core does not support this feature</b>"),
781 QMessageBox::Ok, this);
782 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
788 void MainWin::changeActiveBufferView(bool backwards)
790 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
791 _bufferViews[_activeBufferViewIndex]->setActive(false);
794 if (!_bufferViews.count())
797 int c = _bufferViews.count();
798 while (c--) { // yes, this will reactivate the current active one if all others fail
800 if (--_activeBufferViewIndex < 0)
801 _activeBufferViewIndex = _bufferViews.count()-1;
804 if (++_activeBufferViewIndex >= _bufferViews.count())
805 _activeBufferViewIndex = 0;
808 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
809 if (dock->isHidden())
812 dock->setActive(true);
816 _activeBufferViewIndex = -1;
820 void MainWin::nextBufferView()
822 changeActiveBufferView(false);
826 void MainWin::previousBufferView()
828 changeActiveBufferView(true);
832 void MainWin::nextBuffer()
834 BufferView *view = activeBufferView();
840 void MainWin::previousBuffer()
842 BufferView *view = activeBufferView();
844 view->previousBuffer();
848 void MainWin::hideCurrentBuffer()
850 BufferView *view = activeBufferView();
852 view->hideCurrentBuffer();
856 void MainWin::showNotificationsDlg()
858 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
863 void MainWin::on_actionConfigureNetworks_triggered()
865 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
870 void MainWin::on_actionConfigureViews_triggered()
872 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
877 void MainWin::on_actionLockLayout_toggled(bool lock)
879 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
880 foreach(VerticalDock *dock, docks) {
881 dock->showTitle(!lock);
883 if (Client::bufferViewManager()) {
884 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
885 config->setLocked(lock);
888 QtUiSettings().setValue("LockLayout", lock);
892 void MainWin::setupNickWidget()
895 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
896 nickDock->setObjectName("NickDock");
897 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
899 _nickListWidget = new NickListWidget(nickDock);
900 nickDock->setWidget(_nickListWidget);
902 addDockWidget(Qt::RightDockWidgetArea, nickDock);
903 _viewMenu->addAction(nickDock->toggleViewAction());
904 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
906 // See NickListDock::NickListDock();
907 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
909 // attach the NickListWidget to the BufferModel and the default selection
910 _nickListWidget->setModel(Client::bufferModel());
911 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
913 _nickListWidget->setVisible(false);
917 void MainWin::setupChatMonitor()
919 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
920 dock->setObjectName("ChatMonitorDock");
922 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
923 _chatMonitorView = new ChatMonitorView(filter, this);
924 _chatMonitorView->show();
925 dock->setWidget(_chatMonitorView);
928 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
929 _viewMenu->addAction(dock->toggleViewAction());
930 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
934 void MainWin::setupInputWidget()
936 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
937 dock->setObjectName("InputDock");
939 _inputWidget = new InputWidget(dock);
940 dock->setWidget(_inputWidget);
942 addDockWidget(Qt::BottomDockWidgetArea, dock);
944 _viewMenu->addAction(dock->toggleViewAction());
945 dock->toggleViewAction()->setText(tr("Show Input Line"));
947 _inputWidget->setModel(Client::bufferModel());
948 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
950 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
952 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
956 void MainWin::setupTopicWidget()
958 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
959 dock->setObjectName("TopicDock");
960 _topicWidget = new TopicWidget(dock);
962 dock->setWidget(_topicWidget);
964 _topicWidget->setModel(Client::bufferModel());
965 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
967 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
969 _viewMenu->addAction(dock->toggleViewAction());
970 dock->toggleViewAction()->setText(tr("Show Topic Line"));
974 void MainWin::setupTransferWidget()
976 auto dock = new QDockWidget(tr("Transfers"), this);
977 dock->setObjectName("TransferDock");
978 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
980 auto view = new QTableView(dock); // to be replaced by the real thing
981 view->setModel(Client::transferModel());
982 dock->setWidget(view);
983 dock->hide(); // hidden by default
984 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
986 auto action = dock->toggleViewAction();
987 action->setText(tr("Show File Transfers"));
988 action->setIcon(QIcon::fromTheme("download"));
989 action->setShortcut(QKeySequence(Qt::Key_F6));
990 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
991 _viewMenu->addAction(action);
995 void MainWin::setupViewMenuTail()
997 _viewMenu->addSeparator();
998 _viewMenu->addAction(_fullScreenAction);
1002 void MainWin::setupTitleSetter()
1004 _titleSetter.setModel(Client::bufferModel());
1005 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1009 void MainWin::setupStatusBar()
1011 // MessageProcessor progress
1012 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1015 _coreConnectionStatusWidget->update();
1016 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1018 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1020 QtUiSettings uiSettings;
1022 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1023 showStatusbar->setChecked(enabled);
1024 enabled ? statusBar()->show() : statusBar()->hide();
1026 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1027 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1029 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1033 void MainWin::setupHotList()
1035 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1036 flatProxy->setSourceModel(Client::bufferModel());
1037 _bufferHotList = new BufferHotListFilter(flatProxy);
1041 void MainWin::saveMenuBarStatus(bool enabled)
1043 QtUiSettings uiSettings;
1044 uiSettings.setValue("ShowMenuBar", enabled);
1048 void MainWin::saveStatusBarStatus(bool enabled)
1050 QtUiSettings uiSettings;
1051 uiSettings.setValue("ShowStatusBar", enabled);
1055 void MainWin::setupSystray()
1058 _systemTray = new StatusNotifierItem(this);
1059 #elif !defined QT_NO_SYSTEMTRAYICON
1060 _systemTray = new LegacySystemTray(this);
1062 _systemTray = new SystemTray(this); // dummy
1064 _systemTray->init();
1068 void MainWin::setupToolBars()
1070 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1071 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1072 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1073 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1076 setUnifiedTitleAndToolBarOnMac(true);
1080 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1082 _mainToolBar = new QToolBar(this);
1083 _mainToolBar->setObjectName("MainToolBar");
1085 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1086 addToolBar(_mainToolBar);
1088 if (Quassel::runMode() != Quassel::Monolithic) {
1089 ActionCollection *coll = QtUi::actionCollection("General");
1090 _mainToolBar->addAction(coll->action("ConnectCore"));
1091 _mainToolBar->addAction(coll->action("DisconnectCore"));
1094 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1095 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1098 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1100 _nickToolBar = new QToolBar(this);
1101 _nickToolBar->setObjectName("NickToolBar");
1103 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1104 _nickToolBar->setVisible(false); //default: not visible
1105 addToolBar(_nickToolBar);
1107 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1108 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1111 QtUiSettings uiSettings;
1113 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1114 _mainToolBar->setVisible(visible);
1115 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1119 void MainWin::saveMainToolBarStatus(bool enabled)
1122 QtUiSettings uiSettings;
1123 uiSettings.setValue("ShowMainToolBar", enabled);
1130 void MainWin::connectedToCore()
1132 Q_CHECK_PTR(Client::bufferViewManager());
1133 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1134 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1135 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1137 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1139 setConnectedState();
1143 void MainWin::setConnectedState()
1145 ActionCollection *coll = QtUi::actionCollection("General");
1147 coll->action("ConnectCore")->setEnabled(false);
1148 coll->action("DisconnectCore")->setEnabled(true);
1149 coll->action("ChangePassword")->setEnabled(true);
1150 coll->action("CoreInfo")->setEnabled(true);
1152 foreach(QAction *action, _fileMenu->actions()) {
1153 if (isRemoteCoreOnly(action))
1154 action->setVisible(!Client::internalCore());
1157 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1158 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1159 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1160 if (!Client::internalCore()) {
1161 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1162 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1163 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1166 // _viewMenu->setEnabled(true);
1167 if (!Client::internalCore())
1168 statusBar()->showMessage(tr("Connected to core."));
1170 statusBar()->clearMessage();
1172 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1174 systemTray()->setState(SystemTray::Active);
1176 if (Client::networkIds().isEmpty()) {
1177 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1181 // Monolithic always preselects last used buffer - Client only if the connection died
1182 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1184 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1185 if (lastUsedBufferId.isValid())
1186 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1192 void MainWin::loadLayout()
1195 int accountId = Client::currentCoreAccount().accountId().toInt();
1196 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1197 if (state.isEmpty()) {
1198 foreach(BufferViewDock *view, _bufferViews)
1200 _layoutLoaded = true;
1203 _nickListWidget->setVisible(true);
1204 restoreState(state, accountId);
1205 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1206 if (bufferViewId >= 0)
1207 changeActiveBufferView(bufferViewId);
1209 _layoutLoaded = true;
1213 void MainWin::saveLayout()
1216 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1217 if (accountId > 0) {
1218 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1219 BufferView *view = activeBufferView();
1220 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1225 void MainWin::disconnectedFromCore()
1227 // save core specific layout and remove bufferviews;
1229 _layoutLoaded = false;
1231 QVariant actionData;
1232 BufferViewDock *dock;
1233 foreach(QAction *action, _bufferViewsMenu->actions()) {
1234 actionData = action->data();
1235 if (!actionData.isValid())
1238 dock = qobject_cast<BufferViewDock *>(action->parent());
1239 if (dock && actionData.toInt() != -1) {
1240 removeAction(action);
1241 _bufferViews.removeAll(dock);
1242 dock->deleteLater();
1246 // store last active buffer
1248 BufferId lastBufId = _bufferWidget->currentBuffer();
1249 if (lastBufId.isValid()) {
1250 s.setValue("LastUsedBufferId", lastBufId.toInt());
1251 // clear the current selection
1252 Client::bufferModel()->standardSelectionModel()->clearSelection();
1254 restoreState(s.value("MainWinState").toByteArray());
1255 setDisconnectedState();
1259 void MainWin::setDisconnectedState()
1261 ActionCollection *coll = QtUi::actionCollection("General");
1262 //ui.menuCore->setEnabled(false);
1263 coll->action("ConnectCore")->setEnabled(true);
1264 coll->action("DisconnectCore")->setEnabled(false);
1265 coll->action("CoreInfo")->setEnabled(false);
1266 coll->action("ChangePassword")->setEnabled(false);
1267 //_viewMenu->setEnabled(false);
1268 statusBar()->showMessage(tr("Not connected to core."));
1269 if (_msgProcessorStatusWidget)
1270 _msgProcessorStatusWidget->setProgress(0, 0);
1272 systemTray()->setState(SystemTray::Passive);
1273 _nickListWidget->setVisible(false);
1277 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1279 Q_UNUSED(errorMessage)
1280 CoreConnectAuthDlg dlg(account, this);
1281 *valid = (dlg.exec() == QDialog::Accepted);
1285 void MainWin::handleNoSslInClient(bool *accepted)
1287 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1288 QMessageBox::Ignore|QMessageBox::Cancel, this);
1289 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1290 box.setDefaultButton(QMessageBox::Ignore);
1291 *accepted = box.exec() == QMessageBox::Ignore;
1295 void MainWin::handleNoSslInCore(bool *accepted)
1297 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1298 QMessageBox::Ignore|QMessageBox::Cancel, this);
1299 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1300 box.setDefaultButton(QMessageBox::Ignore);
1301 *accepted = box.exec() == QMessageBox::Ignore;
1307 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1309 QString errorString = "<ul>";
1310 foreach(const QSslError error, socket->sslErrors())
1311 errorString += QString("<li>%1</li>").arg(error.errorString());
1312 errorString += "</ul>";
1314 QMessageBox box(QMessageBox::Warning,
1315 tr("Untrusted Security Certificate"),
1316 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1317 QMessageBox::Cancel, this);
1318 box.setInformativeText(errorString);
1319 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1320 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1322 QMessageBox::ButtonRole role;
1325 role = box.buttonRole(box.clickedButton());
1326 if (role == QMessageBox::HelpRole) {
1327 SslInfoDlg dlg(socket, this);
1331 while (role == QMessageBox::HelpRole);
1333 *accepted = role == QMessageBox::AcceptRole;
1335 QMessageBox box2(QMessageBox::Warning,
1336 tr("Untrusted Security Certificate"),
1337 tr("Would you like to accept this certificate forever without being prompted?"),
1339 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1340 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1342 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1347 #endif /* HAVE_SSL */
1349 void MainWin::handleCoreConnectionError(const QString &error)
1351 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1355 void MainWin::showCoreConnectionDlg()
1357 CoreConnectDlg dlg(this);
1358 if (dlg.exec() == QDialog::Accepted) {
1359 AccountId accId = dlg.selectedAccount();
1360 if (accId.isValid())
1361 Client::coreConnection()->connectToCore(accId);
1366 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1368 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1374 void MainWin::showChannelList(NetworkId netId)
1376 ChannelListDlg *channelListDlg = new ChannelListDlg();
1378 if (!netId.isValid()) {
1379 QAction *action = qobject_cast<QAction *>(sender());
1381 netId = action->data().value<NetworkId>();
1384 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1385 channelListDlg->setNetwork(netId);
1386 channelListDlg->show();
1390 void MainWin::showIgnoreList(QString newRule)
1392 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1393 // prepare config dialog for new rule
1394 if (!newRule.isEmpty())
1395 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1400 void MainWin::showCoreInfoDlg()
1402 CoreInfoDlg(this).exec();
1406 void MainWin::showAwayLog()
1410 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1411 _awayLog = new AwayLogView(filter, 0);
1412 filter->setParent(_awayLog);
1413 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1414 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1419 void MainWin::awayLogDestroyed()
1425 void MainWin::showSettingsDlg()
1427 SettingsDlg *dlg = new SettingsDlg();
1429 //Category: Interface
1430 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1431 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1432 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1433 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1434 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1435 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1436 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1437 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1439 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1441 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1442 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1443 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1446 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1447 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1448 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1449 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1450 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1452 // Category: Remote Cores
1453 if (Quassel::runMode() != Quassel::Monolithic) {
1454 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1455 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1462 void MainWin::showAboutDlg()
1464 AboutDlg(this).exec();
1468 void MainWin::showShortcutsDlg()
1471 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1472 foreach(KActionCollection *coll, QtUi::actionCollections())
1473 dlg.addCollection(coll, coll->property("Category").toString());
1474 dlg.configure(true);
1476 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1482 void MainWin::showNewTransferDlg(const QUuid &transferId)
1484 auto transfer = Client::transferManager()->transfer(transferId);
1486 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1490 qWarning() << "Unknown transfer ID" << transferId;
1495 void MainWin::onFullScreenToggled()
1497 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1498 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1501 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1503 if (_fullScreenAction->isChecked())
1504 setWindowState(windowState() | Qt::WindowFullScreen);
1506 setWindowState(windowState() & ~Qt::WindowFullScreen);
1511 /********************************************************************************************************/
1513 bool MainWin::event(QEvent *event)
1515 switch(event->type()) {
1516 case QEvent::WindowActivate: {
1517 BufferId bufferId = Client::bufferModel()->currentBuffer();
1518 if (bufferId.isValid())
1519 Client::instance()->markBufferAsRead(bufferId);
1522 case QEvent::WindowDeactivate:
1523 if (bufferWidget()->autoMarkerLineOnLostFocus())
1524 bufferWidget()->setMarkerLine();
1529 return QMainWindow::event(event);
1533 void MainWin::moveEvent(QMoveEvent *event)
1535 if (!(windowState() & Qt::WindowMaximized))
1536 _normalPos = event->pos();
1538 QMainWindow::moveEvent(event);
1542 void MainWin::resizeEvent(QResizeEvent *event)
1544 if (!(windowState() & Qt::WindowMaximized))
1545 _normalSize = event->size();
1547 QMainWindow::resizeEvent(event);
1551 void MainWin::closeEvent(QCloseEvent *event)
1554 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1556 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1557 // This messes up MainWinState/MainWinHidden save/restore.
1558 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1559 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1560 QtUi::hideMainWidget();
1563 else if(!_aboutToQuit) {
1564 _aboutToQuit = true;
1574 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1578 bool hasFocus = QApplication::activeWindow() != 0;
1580 for (int i = start; i <= end; i++) {
1581 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1582 if (!idx.isValid()) {
1583 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1586 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1587 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1590 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1591 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1593 // check if bufferId belongs to the shown chatlists
1594 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1595 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1598 // check if it's the buffer currently displayed
1599 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1602 // only show notifications for higlights or queries
1603 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1606 // and of course: don't notify for ignored messages
1607 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1610 // seems like we have a legit notification candidate!
1611 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1612 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1613 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1614 AbstractNotificationBackend::NotificationType type;
1616 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1617 type = AbstractNotificationBackend::PrivMsg;
1618 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1619 type = AbstractNotificationBackend::PrivMsgFocused;
1620 else if (flags & Message::Highlight && !hasFocus)
1621 type = AbstractNotificationBackend::Highlight;
1623 type = AbstractNotificationBackend::HighlightFocused;
1625 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1630 void MainWin::currentBufferChanged(BufferId buffer)
1632 if (buffer.isValid())
1633 Client::instance()->markBufferAsRead(buffer);
1637 void MainWin::clientNetworkCreated(NetworkId id)
1639 const Network *net = Client::network(id);
1640 QAction *act = new QAction(net->networkName(), this);
1641 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1642 act->setData(QVariant::fromValue<NetworkId>(id));
1643 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1644 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1646 QAction *beforeAction = 0;
1647 foreach(QAction *action, _networksMenu->actions()) {
1648 if (!action->data().isValid()) // ignore stock actions
1650 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1651 beforeAction = action;
1655 _networksMenu->insertAction(beforeAction, act);
1659 void MainWin::clientNetworkUpdated()
1661 const Network *net = qobject_cast<const Network *>(sender());
1665 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1669 action->setText(net->networkName());
1671 switch (net->connectionState()) {
1672 case Network::Initialized:
1673 action->setIcon(QIcon::fromTheme("network-connect"));
1674 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1675 if (!bufferWidget()->currentBuffer().isValid()) {
1676 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1677 if (idx.isValid()) {
1678 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1679 Client::bufferModel()->switchToBuffer(statusBufferId);
1683 case Network::Disconnected:
1684 action->setIcon(QIcon::fromTheme("network-disconnect"));
1687 action->setIcon(QIcon::fromTheme("network-wired"));
1692 void MainWin::clientNetworkRemoved(NetworkId id)
1694 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1698 action->deleteLater();
1702 void MainWin::connectOrDisconnectFromNet()
1704 QAction *act = qobject_cast<QAction *>(sender());
1706 const Network *net = Client::network(act->data().value<NetworkId>());
1708 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1709 else net->requestDisconnect();
1713 void MainWin::on_jumpHotBuffer_triggered()
1715 if (!_bufferHotList->rowCount())
1718 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1721 void MainWin::on_bufferSearch_triggered()
1723 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1724 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1728 _bufferViews[_activeBufferViewIndex]->activateFilter();
1732 void MainWin::onJumpKey()
1734 QAction *action = qobject_cast<QAction *>(sender());
1735 if (!action || !Client::bufferModel())
1737 int idx = action->property("Index").toInt();
1739 if (_jumpKeyMap.isEmpty())
1740 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1742 if (!_jumpKeyMap.contains(idx))
1745 BufferId buffer = _jumpKeyMap.value(idx);
1746 if (buffer.isValid())
1747 Client::bufferModel()->switchToBuffer(buffer);
1751 void MainWin::bindJumpKey()
1753 QAction *action = qobject_cast<QAction *>(sender());
1754 if (!action || !Client::bufferModel())
1756 int idx = action->property("Index").toInt();
1758 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1759 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1763 void MainWin::on_actionDebugNetworkModel_triggered()
1765 QTreeView *view = new QTreeView;
1766 view->setAttribute(Qt::WA_DeleteOnClose);
1767 view->setWindowTitle("Debug NetworkModel View");
1768 view->setModel(Client::networkModel());
1769 view->setColumnWidth(0, 250);
1770 view->setColumnWidth(1, 250);
1771 view->setColumnWidth(2, 80);
1772 view->resize(610, 300);
1777 void MainWin::on_actionDebugHotList_triggered()
1779 _bufferHotList->invalidate();
1780 _bufferHotList->sort(0, Qt::DescendingOrder);
1782 QTreeView *view = new QTreeView;
1783 view->setAttribute(Qt::WA_DeleteOnClose);
1784 view->setModel(_bufferHotList);
1789 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1791 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1792 overlay->setAttribute(Qt::WA_DeleteOnClose);
1797 void MainWin::on_actionDebugMessageModel_triggered()
1799 QTableView *view = new QTableView(0);
1800 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1801 filter->setSourceModel(Client::messageModel());
1802 view->setModel(filter);
1803 view->setAttribute(Qt::WA_DeleteOnClose, true);
1804 view->verticalHeader()->hide();
1805 view->horizontalHeader()->setStretchLastSection(true);
1810 void MainWin::on_actionDebugLog_triggered()
1812 DebugLogWidget *logWidget = new DebugLogWidget(0);
1817 void MainWin::showStatusBarMessage(const QString &message)
1819 statusBar()->showMessage(message, 10000);