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>
30 #include <settingspages/corehighlightsettingspage.h>
35 # include <KShortcutsDialog>
36 # include <KStatusBar>
37 # include <KToggleFullScreenAction>
42 # include <KConfigWidgets/KStandardAction>
43 # include <KXmlGui/KHelpMenu>
44 # include <KXmlGui/KShortcutsDialog>
45 # include <KXmlGui/KToolBar>
46 # include <KWidgetsAddons/KToggleFullScreenAction>
54 #include "awaylogfilter.h"
55 #include "awaylogview.h"
57 #include "actioncollection.h"
58 #include "bufferhotlistfilter.h"
59 #include "buffermodel.h"
60 #include "bufferview.h"
61 #include "bufferviewoverlay.h"
62 #include "bufferviewoverlayfilter.h"
63 #include "bufferwidget.h"
64 #include "channellistdlg.h"
65 #include "chatlinemodel.h"
66 #include "chatmonitorfilter.h"
67 #include "chatmonitorview.h"
70 #include "clientbacklogmanager.h"
71 #include "clientbufferviewconfig.h"
72 #include "clientbufferviewmanager.h"
73 #include "clientignorelistmanager.h"
74 #include "clienttransfer.h"
75 #include "clienttransfermanager.h"
76 #include "coreconfigwizard.h"
77 #include "coreconnectdlg.h"
78 #include "coreconnection.h"
79 #include "coreconnectionstatuswidget.h"
80 #include "coreinfodlg.h"
81 #include "contextmenuactionprovider.h"
82 #include "debugbufferviewoverlay.h"
83 #include "debuglogwidget.h"
84 #include "debugmessagemodelfilter.h"
85 #include "flatproxymodel.h"
86 #include "inputwidget.h"
87 #include "irclistmodel.h"
88 #include "ircconnectionwizard.h"
89 #include "legacysystemtray.h"
90 #include "msgprocessorstatuswidget.h"
91 #include "nicklistwidget.h"
92 #include "passwordchangedlg.h"
93 #include "qtuiapplication.h"
94 #include "qtuimessageprocessor.h"
95 #include "qtuisettings.h"
96 #include "qtuistyle.h"
97 #include "receivefiledlg.h"
98 #include "settingsdlg.h"
99 #include "settingspagedlg.h"
100 #include "statusnotifieritem.h"
101 #include "toolbaractionprovider.h"
102 #include "topicwidget.h"
103 #include "transfermodel.h"
104 #include "verticaldock.h"
107 # ifdef HAVE_QTMULTIMEDIA
108 # include "qtmultimedianotificationbackend.h"
111 # include "phononnotificationbackend.h"
113 # include "systraynotificationbackend.h"
114 # include "taskbarnotificationbackend.h"
116 # include "knotificationbackend.h"
117 #endif /* HAVE_KDE */
121 # include "snorenotificationbackend.h"
125 # include "sslinfodlg.h"
128 #ifdef HAVE_INDICATEQT
129 #include "indicatornotificationbackend.h"
132 #ifdef HAVE_NOTIFICATION_CENTER
133 #include "osxnotificationbackend.h"
137 #include "dockmanagernotificationbackend.h"
140 #include "settingspages/aliasessettingspage.h"
141 #include "settingspages/appearancesettingspage.h"
142 #include "settingspages/backlogsettingspage.h"
143 #include "settingspages/bufferviewsettingspage.h"
144 #include "settingspages/chatmonitorsettingspage.h"
145 #include "settingspages/chatviewsettingspage.h"
146 #include "settingspages/chatviewcolorsettingspage.h"
147 #include "settingspages/connectionsettingspage.h"
148 #include "settingspages/coreaccountsettingspage.h"
149 #include "settingspages/coreconnectionsettingspage.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(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
208 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList, QVariantList)), SLOT(showCoreConfigWizard(QVariantList, QVariantList)));
209 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
210 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
211 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
212 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
214 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
218 setDockNestingEnabled(true);
219 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
220 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
221 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
222 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
224 // Order is sometimes important
228 setupTransferWidget();
240 _bufferWidget->setFocusProxy(_inputWidget);
241 _chatMonitorView->setFocusProxy(_inputWidget);
244 # ifdef HAVE_QTMULTIMEDIA
245 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
248 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
250 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
252 QtUi::registerNotificationBackend(new KNotificationBackend(this));
253 #endif /* HAVE_KDE */
257 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
258 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
259 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
262 #ifdef HAVE_INDICATEQT
263 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
266 #ifdef HAVE_NOTIFICATION_CENTER
267 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
271 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
274 // we assume that at this point, all configurable actions are defined!
275 QtUi::loadShortcuts();
277 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
279 setDisconnectedState(); // Disable menus and stuff
282 setAutoSaveSettings();
285 // restore mainwin state
287 restoreStateFromSettings(s);
289 // restore locked state of docks
290 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
292 CoreConnection *conn = Client::coreConnection();
293 if (!conn->connectToCore()) {
294 // No autoconnect selected (or no accounts)
295 showCoreConnectionDlg();
308 saveStateToSettings(s);
310 QApplication::quit();
314 void MainWin::saveStateToSettings(UiSettings &s)
316 s.setValue("MainWinSize", _normalSize);
317 s.setValue("MainWinPos", _normalPos);
318 s.setValue("MainWinState", saveState());
319 s.setValue("MainWinGeometry", saveGeometry());
320 s.setValue("MainWinMinimized", isMinimized());
321 s.setValue("MainWinMaximized", isMaximized());
322 s.setValue("MainWinHidden", !isVisible());
323 BufferId lastBufId = Client::bufferModel()->currentBuffer();
324 if (lastBufId.isValid())
325 s.setValue("LastUsedBufferId", lastBufId.toInt());
328 saveAutoSaveSettings();
333 void MainWin::restoreStateFromSettings(UiSettings &s)
335 _normalSize = s.value("MainWinSize", size()).toSize();
336 _normalPos = s.value("MainWinPos", pos()).toPoint();
337 bool maximized = s.value("MainWinMaximized", false).toBool();
340 restoreGeometry(s.value("MainWinGeometry").toByteArray());
343 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
348 restoreState(s.value("MainWinState").toByteArray());
354 if ((Quassel::isOptionSet("hidewindow")
355 || s.value("MainWinHidden").toBool())
356 && _systemTray->isSystemTrayAvailable())
357 QtUi::hideMainWidget();
358 else if (s.value("MainWinMinimized").toBool())
366 QMenu *MainWin::createPopupMenu()
368 QMenu *popupMenu = QMainWindow::createPopupMenu();
369 popupMenu->addSeparator();
370 ActionCollection *coll = QtUi::actionCollection("General");
371 popupMenu->addAction(coll->action("ToggleMenuBar"));
376 void MainWin::updateIcon()
379 if (Client::isConnected())
380 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
382 icon = QIcon::fromTheme("inactive-quassel", QIcon(":/icons/inactive-quassel.png"));
384 qApp->setWindowIcon(icon);
388 void MainWin::setupActions()
390 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
392 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("connect-quassel", QIcon(":/icons/connect-quassel.png")), tr("&Connect to Core..."), coll,
393 this, SLOT(showCoreConnectionDlg())));
394 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("disconnect-quassel", QIcon(":/icons/disconnect-quassel.png")), tr("&Disconnect from Core"), coll,
395 Client::instance(), SLOT(disconnectFromCore())));
396 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
397 this, SLOT(showPasswordChangeDlg())));
398 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
399 this, SLOT(showCoreInfoDlg())));
400 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
401 this, SLOT(on_actionConfigureNetworks_triggered())));
402 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
403 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
404 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
407 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
408 this, SLOT(on_actionConfigureViews_triggered())));
410 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
411 lockAct->setCheckable(true);
412 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
414 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
415 0, 0, QKeySequence::Find))->setCheckable(true);
416 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
417 this, SLOT(showAwayLog())));
418 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
419 0, 0))->setCheckable(true);
421 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
422 0, 0))->setCheckable(true);
425 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
427 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
428 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
429 _fullScreenAction->setCheckable(true);
430 coll->addAction("ToggleFullScreen", _fullScreenAction);
434 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
435 this, SLOT(showShortcutsDlg()));
436 configureShortcutsAct->setMenuRole(QAction::NoRole);
437 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
440 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
441 this, SLOT(showSettingsDlg()));
442 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
444 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
445 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
447 coll->addAction("ConfigureQuassel", configureQuasselAct);
450 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
451 this, SLOT(showAboutDlg()));
452 aboutQuasselAct->setMenuRole(QAction::AboutRole);
453 coll->addAction("AboutQuassel", aboutQuasselAct);
455 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
456 qApp, SLOT(aboutQt()));
457 aboutQtAct->setMenuRole(QAction::AboutQtRole);
458 coll->addAction("AboutQt", aboutQtAct);
459 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
460 this, SLOT(on_actionDebugNetworkModel_triggered())));
461 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
462 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
463 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
464 this, SLOT(on_actionDebugMessageModel_triggered())));
465 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
466 this, SLOT(on_actionDebugHotList_triggered())));
467 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
468 this, SLOT(on_actionDebugLog_triggered())));
469 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
470 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
472 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
473 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
476 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
478 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
479 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
481 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
482 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
486 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
487 const int jumpModifier = Qt::ControlModifier;
489 const int bindModifier = Qt::ControlModifier;
490 const int jumpModifier = Qt::AltModifier;
493 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
494 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
495 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
496 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
497 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
498 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
499 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
500 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
501 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
502 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
503 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
504 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
505 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
506 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
507 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
508 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
509 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
510 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
511 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
512 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
514 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
515 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
516 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
517 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
518 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
519 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
520 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
521 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
522 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
523 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
524 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
525 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
526 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
527 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
528 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
529 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
530 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
531 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
532 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
533 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
536 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
537 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
538 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
539 this, SLOT(previousBufferView()), QKeySequence::Back));
540 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
541 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
542 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
543 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
547 void MainWin::setupMenus()
549 ActionCollection *coll = QtUi::actionCollection("General");
551 _fileMenu = menuBar()->addMenu(tr("&File"));
553 static const QStringList coreActions = QStringList()
554 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
557 foreach(QString actionName, coreActions) {
558 coreAction = coll->action(actionName);
559 _fileMenu->addAction(coreAction);
560 flagRemoteCoreOnly(coreAction);
562 flagRemoteCoreOnly(_fileMenu->addSeparator());
564 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
565 _networksMenu->addAction(coll->action("ConfigureNetworks"));
566 _networksMenu->addSeparator();
567 _fileMenu->addSeparator();
568 _fileMenu->addAction(coll->action("Quit"));
570 _viewMenu = menuBar()->addMenu(tr("&View"));
571 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
572 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
573 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
574 _viewMenu->addSeparator();
576 _viewMenu->addAction(coll->action("ToggleMenuBar"));
577 _viewMenu->addAction(coll->action("ToggleStatusBar"));
578 _viewMenu->addAction(coll->action("ToggleSearchBar"));
580 coreAction = coll->action("ShowAwayLog");
581 flagRemoteCoreOnly(coreAction);
582 _viewMenu->addAction(coreAction);
584 _viewMenu->addSeparator();
585 _viewMenu->addAction(coll->action("LockLayout"));
587 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
589 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
590 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
592 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
594 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
597 _helpMenu = menuBar()->addMenu(tr("&Help"));
599 _helpMenu->addAction(coll->action("AboutQuassel"));
601 _helpMenu->addAction(coll->action("AboutQt"));
603 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
605 _helpMenu->addSeparator();
606 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
607 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
608 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
609 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
610 _helpDebugMenu->addAction(coll->action("DebugHotList"));
611 _helpDebugMenu->addAction(coll->action("DebugLog"));
612 _helpDebugMenu->addSeparator();
613 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
616 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
618 QtUiSettings uiSettings;
619 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
620 showMenuBar->setChecked(enabled);
621 enabled ? menuBar()->show() : menuBar()->hide();
623 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
624 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
628 void MainWin::setupBufferWidget()
630 _bufferWidget = new BufferWidget(this);
631 _bufferWidget->setModel(Client::bufferModel());
632 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
633 setCentralWidget(_bufferWidget);
637 void MainWin::addBufferView(int bufferViewConfigId)
639 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
643 void MainWin::addBufferView(ClientBufferViewConfig *config)
648 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
649 BufferViewDock *dock = new BufferViewDock(config, this);
651 //create the view and initialize it's filter
652 BufferView *view = new BufferView(dock);
653 view->setFilteredModel(Client::bufferModel(), config);
654 view->installEventFilter(_inputWidget); // for key presses
656 Client::bufferModel()->synchronizeView(view);
658 dock->setWidget(view);
659 dock->setVisible(_layoutLoaded); // don't show before state has been restored
661 addDockWidget(Qt::LeftDockWidgetArea, dock);
662 _bufferViewsMenu->addAction(dock->toggleViewAction());
664 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
665 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
666 _bufferViews.append(dock);
668 if (!activeBufferView())
673 void MainWin::removeBufferView(int bufferViewConfigId)
676 BufferViewDock *dock;
677 foreach(QAction *action, _bufferViewsMenu->actions()) {
678 actionData = action->data();
679 if (!actionData.isValid())
682 dock = qobject_cast<BufferViewDock *>(action->parent());
683 if (dock && actionData.toInt() == bufferViewConfigId) {
684 removeAction(action);
685 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
686 _bufferViews.removeAll(dock);
688 if (dock->isActive()) {
689 dock->setActive(false);
690 _activeBufferViewIndex = -1;
700 void MainWin::bufferViewToggled(bool enabled)
702 if (!enabled && !isMinimized()) {
703 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
704 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
707 QAction *action = qobject_cast<QAction *>(sender());
709 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
712 // Make sure we don't toggle backlog fetch for a view we've already removed
713 if (!_bufferViews.contains(dock))
717 Client::bufferViewOverlay()->addView(dock->bufferViewId());
719 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
723 void MainWin::bufferViewVisibilityChanged(bool visible)
726 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
728 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
733 BufferView *MainWin::allBuffersView() const
735 // "All Buffers" is always the first dock created
736 if (_bufferViews.count() > 0)
737 return _bufferViews[0]->bufferView();
742 BufferView *MainWin::activeBufferView() const
744 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
746 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
747 return dock->isActive() ? dock->bufferView() : 0;
751 void MainWin::changeActiveBufferView(int bufferViewId)
753 if (bufferViewId < 0)
756 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
757 _bufferViews[_activeBufferViewIndex]->setActive(false);
758 _activeBufferViewIndex = -1;
761 for (int i = 0; i < _bufferViews.count(); i++) {
762 BufferViewDock *dock = _bufferViews.at(i);
763 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
764 _activeBufferViewIndex = i;
765 dock->setActive(true);
770 nextBufferView(); // fallback
774 void MainWin::showPasswordChangeDlg()
776 if((Client::coreFeatures() & Quassel::PasswordChange)) {
777 PasswordChangeDlg dlg(this);
781 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
782 tr("<b>Your Quassel Core does not support this feature</b>"),
783 QMessageBox::Ok, this);
784 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
790 void MainWin::changeActiveBufferView(bool backwards)
792 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
793 _bufferViews[_activeBufferViewIndex]->setActive(false);
796 if (!_bufferViews.count())
799 int c = _bufferViews.count();
800 while (c--) { // yes, this will reactivate the current active one if all others fail
802 if (--_activeBufferViewIndex < 0)
803 _activeBufferViewIndex = _bufferViews.count()-1;
806 if (++_activeBufferViewIndex >= _bufferViews.count())
807 _activeBufferViewIndex = 0;
810 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
811 if (dock->isHidden())
814 dock->setActive(true);
818 _activeBufferViewIndex = -1;
822 void MainWin::nextBufferView()
824 changeActiveBufferView(false);
828 void MainWin::previousBufferView()
830 changeActiveBufferView(true);
834 void MainWin::nextBuffer()
836 BufferView *view = activeBufferView();
842 void MainWin::previousBuffer()
844 BufferView *view = activeBufferView();
846 view->previousBuffer();
850 void MainWin::hideCurrentBuffer()
852 BufferView *view = activeBufferView();
854 view->hideCurrentBuffer();
858 void MainWin::showNotificationsDlg()
860 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
865 void MainWin::on_actionConfigureNetworks_triggered()
867 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
872 void MainWin::on_actionConfigureViews_triggered()
874 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
879 void MainWin::on_actionLockLayout_toggled(bool lock)
881 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
882 foreach(VerticalDock *dock, docks) {
883 dock->showTitle(!lock);
885 if (Client::bufferViewManager()) {
886 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
887 config->setLocked(lock);
890 QtUiSettings().setValue("LockLayout", lock);
894 void MainWin::setupNickWidget()
897 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
898 nickDock->setObjectName("NickDock");
899 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
901 _nickListWidget = new NickListWidget(nickDock);
902 nickDock->setWidget(_nickListWidget);
904 addDockWidget(Qt::RightDockWidgetArea, nickDock);
905 _viewMenu->addAction(nickDock->toggleViewAction());
906 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
908 // See NickListDock::NickListDock();
909 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
911 // attach the NickListWidget to the BufferModel and the default selection
912 _nickListWidget->setModel(Client::bufferModel());
913 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
915 _nickListWidget->setVisible(false);
919 void MainWin::setupChatMonitor()
921 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
922 dock->setObjectName("ChatMonitorDock");
924 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
925 _chatMonitorView = new ChatMonitorView(filter, this);
926 _chatMonitorView->show();
927 dock->setWidget(_chatMonitorView);
930 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
931 _viewMenu->addAction(dock->toggleViewAction());
932 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
936 void MainWin::setupInputWidget()
938 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
939 dock->setObjectName("InputDock");
941 _inputWidget = new InputWidget(dock);
942 dock->setWidget(_inputWidget);
944 addDockWidget(Qt::BottomDockWidgetArea, dock);
946 _viewMenu->addAction(dock->toggleViewAction());
947 dock->toggleViewAction()->setText(tr("Show Input Line"));
949 _inputWidget->setModel(Client::bufferModel());
950 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
952 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
954 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
958 void MainWin::setupTopicWidget()
960 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
961 dock->setObjectName("TopicDock");
962 _topicWidget = new TopicWidget(dock);
964 dock->setWidget(_topicWidget);
966 _topicWidget->setModel(Client::bufferModel());
967 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
969 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
971 _viewMenu->addAction(dock->toggleViewAction());
972 dock->toggleViewAction()->setText(tr("Show Topic Line"));
976 void MainWin::setupTransferWidget()
978 auto dock = new QDockWidget(tr("Transfers"), this);
979 dock->setObjectName("TransferDock");
980 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
982 auto view = new QTableView(dock); // to be replaced by the real thing
983 view->setModel(Client::transferModel());
984 dock->setWidget(view);
985 dock->hide(); // hidden by default
986 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
988 auto action = dock->toggleViewAction();
989 action->setText(tr("Show File Transfers"));
990 action->setIcon(QIcon::fromTheme("download"));
991 action->setShortcut(QKeySequence(Qt::Key_F6));
992 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
993 _viewMenu->addAction(action);
997 void MainWin::setupViewMenuTail()
999 _viewMenu->addSeparator();
1000 _viewMenu->addAction(_fullScreenAction);
1004 void MainWin::setupTitleSetter()
1006 _titleSetter.setModel(Client::bufferModel());
1007 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1011 void MainWin::setupStatusBar()
1013 // MessageProcessor progress
1014 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1017 _coreConnectionStatusWidget->update();
1018 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1020 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1022 QtUiSettings uiSettings;
1024 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1025 showStatusbar->setChecked(enabled);
1026 enabled ? statusBar()->show() : statusBar()->hide();
1028 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1029 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1031 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1035 void MainWin::setupHotList()
1037 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1038 flatProxy->setSourceModel(Client::bufferModel());
1039 _bufferHotList = new BufferHotListFilter(flatProxy);
1043 void MainWin::saveMenuBarStatus(bool enabled)
1045 QtUiSettings uiSettings;
1046 uiSettings.setValue("ShowMenuBar", enabled);
1050 void MainWin::saveStatusBarStatus(bool enabled)
1052 QtUiSettings uiSettings;
1053 uiSettings.setValue("ShowStatusBar", enabled);
1057 void MainWin::setupSystray()
1060 _systemTray = new StatusNotifierItem(this);
1061 #elif !defined QT_NO_SYSTEMTRAYICON
1062 _systemTray = new LegacySystemTray(this);
1064 _systemTray = new SystemTray(this); // dummy
1066 _systemTray->init();
1070 void MainWin::setupToolBars()
1072 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1073 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1074 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1075 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1078 setUnifiedTitleAndToolBarOnMac(true);
1082 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1084 _mainToolBar = new QToolBar(this);
1085 _mainToolBar->setObjectName("MainToolBar");
1087 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1088 addToolBar(_mainToolBar);
1090 if (Quassel::runMode() != Quassel::Monolithic) {
1091 ActionCollection *coll = QtUi::actionCollection("General");
1092 _mainToolBar->addAction(coll->action("ConnectCore"));
1093 _mainToolBar->addAction(coll->action("DisconnectCore"));
1096 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1097 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1100 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1102 _nickToolBar = new QToolBar(this);
1103 _nickToolBar->setObjectName("NickToolBar");
1105 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1106 _nickToolBar->setVisible(false); //default: not visible
1107 addToolBar(_nickToolBar);
1109 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1110 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1113 QtUiSettings uiSettings;
1115 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1116 _mainToolBar->setVisible(visible);
1117 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1121 void MainWin::saveMainToolBarStatus(bool enabled)
1124 QtUiSettings uiSettings;
1125 uiSettings.setValue("ShowMainToolBar", enabled);
1132 void MainWin::connectedToCore()
1134 Q_CHECK_PTR(Client::bufferViewManager());
1135 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1136 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1137 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1139 if (Client::transferManager()) {
1140 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1143 setConnectedState();
1147 void MainWin::setConnectedState()
1149 ActionCollection *coll = QtUi::actionCollection("General");
1151 coll->action("ConnectCore")->setEnabled(false);
1152 coll->action("DisconnectCore")->setEnabled(true);
1153 coll->action("ChangePassword")->setEnabled(true);
1154 coll->action("CoreInfo")->setEnabled(true);
1156 foreach(QAction *action, _fileMenu->actions()) {
1157 if (isRemoteCoreOnly(action))
1158 action->setVisible(!Client::internalCore());
1161 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1162 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1163 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1164 if (!Client::internalCore()) {
1165 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1166 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1167 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1170 // _viewMenu->setEnabled(true);
1171 if (!Client::internalCore())
1172 statusBar()->showMessage(tr("Connected to core."));
1174 statusBar()->clearMessage();
1176 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1178 systemTray()->setState(SystemTray::Active);
1180 if (Client::networkIds().isEmpty()) {
1181 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1185 // Monolithic always preselects last used buffer - Client only if the connection died
1186 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1188 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1189 if (lastUsedBufferId.isValid())
1190 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1196 void MainWin::loadLayout()
1199 int accountId = Client::currentCoreAccount().accountId().toInt();
1200 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1201 if (state.isEmpty()) {
1202 foreach(BufferViewDock *view, _bufferViews)
1204 _layoutLoaded = true;
1207 _nickListWidget->setVisible(true);
1208 restoreState(state, accountId);
1209 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1210 if (bufferViewId >= 0)
1211 changeActiveBufferView(bufferViewId);
1213 _layoutLoaded = true;
1217 void MainWin::saveLayout()
1220 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1221 if (accountId > 0) {
1222 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1223 BufferView *view = activeBufferView();
1224 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1229 void MainWin::disconnectedFromCore()
1231 // save core specific layout and remove bufferviews;
1233 _layoutLoaded = false;
1235 QVariant actionData;
1236 BufferViewDock *dock;
1237 foreach(QAction *action, _bufferViewsMenu->actions()) {
1238 actionData = action->data();
1239 if (!actionData.isValid())
1242 dock = qobject_cast<BufferViewDock *>(action->parent());
1243 if (dock && actionData.toInt() != -1) {
1244 removeAction(action);
1245 _bufferViews.removeAll(dock);
1246 dock->deleteLater();
1250 // store last active buffer
1252 BufferId lastBufId = _bufferWidget->currentBuffer();
1253 if (lastBufId.isValid()) {
1254 s.setValue("LastUsedBufferId", lastBufId.toInt());
1255 // clear the current selection
1256 Client::bufferModel()->standardSelectionModel()->clearSelection();
1258 restoreState(s.value("MainWinState").toByteArray());
1259 setDisconnectedState();
1263 void MainWin::setDisconnectedState()
1265 ActionCollection *coll = QtUi::actionCollection("General");
1266 //ui.menuCore->setEnabled(false);
1267 coll->action("ConnectCore")->setEnabled(true);
1268 coll->action("DisconnectCore")->setEnabled(false);
1269 coll->action("CoreInfo")->setEnabled(false);
1270 coll->action("ChangePassword")->setEnabled(false);
1271 //_viewMenu->setEnabled(false);
1272 statusBar()->showMessage(tr("Not connected to core."));
1273 if (_msgProcessorStatusWidget)
1274 _msgProcessorStatusWidget->setProgress(0, 0);
1276 systemTray()->setState(SystemTray::Passive);
1277 _nickListWidget->setVisible(false);
1281 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1283 Q_UNUSED(errorMessage)
1284 CoreConnectAuthDlg dlg(account, this);
1285 *valid = (dlg.exec() == QDialog::Accepted);
1289 void MainWin::handleNoSslInClient(bool *accepted)
1291 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1292 QMessageBox::Ignore|QMessageBox::Cancel, this);
1293 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1294 box.setDefaultButton(QMessageBox::Ignore);
1295 *accepted = box.exec() == QMessageBox::Ignore;
1299 void MainWin::handleNoSslInCore(bool *accepted)
1301 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1302 QMessageBox::Ignore|QMessageBox::Cancel, this);
1303 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1304 box.setDefaultButton(QMessageBox::Ignore);
1305 *accepted = box.exec() == QMessageBox::Ignore;
1311 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1313 QString errorString = "<ul>";
1314 foreach(const QSslError error, socket->sslErrors())
1315 errorString += QString("<li>%1</li>").arg(error.errorString());
1316 errorString += "</ul>";
1318 QMessageBox box(QMessageBox::Warning,
1319 tr("Untrusted Security Certificate"),
1320 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1321 QMessageBox::Cancel, this);
1322 box.setInformativeText(errorString);
1323 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1324 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1326 QMessageBox::ButtonRole role;
1329 role = box.buttonRole(box.clickedButton());
1330 if (role == QMessageBox::HelpRole) {
1331 SslInfoDlg dlg(socket, this);
1335 while (role == QMessageBox::HelpRole);
1337 *accepted = role == QMessageBox::AcceptRole;
1339 QMessageBox box2(QMessageBox::Warning,
1340 tr("Untrusted Security Certificate"),
1341 tr("Would you like to accept this certificate forever without being prompted?"),
1343 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1344 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1346 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1351 #endif /* HAVE_SSL */
1353 void MainWin::handleCoreConnectionError(const QString &error)
1355 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1359 void MainWin::showCoreConnectionDlg()
1361 CoreConnectDlg dlg(this);
1362 if (dlg.exec() == QDialog::Accepted) {
1363 AccountId accId = dlg.selectedAccount();
1364 if (accId.isValid())
1365 Client::coreConnection()->connectToCore(accId);
1370 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1372 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1378 void MainWin::showChannelList(NetworkId netId)
1380 ChannelListDlg *channelListDlg = new ChannelListDlg();
1382 if (!netId.isValid()) {
1383 QAction *action = qobject_cast<QAction *>(sender());
1385 netId = action->data().value<NetworkId>();
1388 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1389 channelListDlg->setNetwork(netId);
1390 channelListDlg->show();
1394 void MainWin::showIgnoreList(QString newRule)
1396 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1397 // prepare config dialog for new rule
1398 if (!newRule.isEmpty())
1399 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1404 void MainWin::showCoreInfoDlg()
1406 CoreInfoDlg(this).exec();
1410 void MainWin::showAwayLog()
1414 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1415 _awayLog = new AwayLogView(filter, 0);
1416 filter->setParent(_awayLog);
1417 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1418 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1423 void MainWin::awayLogDestroyed()
1429 void MainWin::showSettingsDlg()
1431 SettingsDlg *dlg = new SettingsDlg();
1433 //Category: Interface
1434 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1435 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1436 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1437 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1438 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1439 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1440 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1441 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1443 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1445 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1446 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1447 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1448 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1451 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1452 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1453 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1454 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1455 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1456 dlg->registerSettingsPage(new DccSettingsPage(dlg));
1458 // Category: Remote Cores
1459 if (Quassel::runMode() != Quassel::Monolithic) {
1460 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1461 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1468 void MainWin::showAboutDlg()
1470 AboutDlg(this).exec();
1474 void MainWin::showShortcutsDlg()
1477 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1478 foreach(KActionCollection *coll, QtUi::actionCollections())
1479 dlg.addCollection(coll, coll->property("Category").toString());
1480 dlg.configure(true);
1482 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1488 void MainWin::showNewTransferDlg(const QUuid &transferId)
1490 auto transfer = Client::transferManager()->transfer(transferId);
1492 if (transfer->status() == Transfer::Status::New) {
1493 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1498 qWarning() << "Unknown transfer ID" << transferId;
1503 void MainWin::onFullScreenToggled()
1505 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1506 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1509 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1511 if (_fullScreenAction->isChecked())
1512 setWindowState(windowState() | Qt::WindowFullScreen);
1514 setWindowState(windowState() & ~Qt::WindowFullScreen);
1519 /********************************************************************************************************/
1521 bool MainWin::event(QEvent *event)
1523 switch(event->type()) {
1524 case QEvent::WindowActivate: {
1525 BufferId bufferId = Client::bufferModel()->currentBuffer();
1526 if (bufferId.isValid())
1527 Client::instance()->markBufferAsRead(bufferId);
1530 case QEvent::WindowDeactivate:
1531 if (bufferWidget()->autoMarkerLineOnLostFocus())
1532 bufferWidget()->setMarkerLine();
1537 return QMainWindow::event(event);
1541 void MainWin::moveEvent(QMoveEvent *event)
1543 if (!(windowState() & Qt::WindowMaximized))
1544 _normalPos = event->pos();
1546 QMainWindow::moveEvent(event);
1550 void MainWin::resizeEvent(QResizeEvent *event)
1552 if (!(windowState() & Qt::WindowMaximized))
1553 _normalSize = event->size();
1555 QMainWindow::resizeEvent(event);
1559 void MainWin::closeEvent(QCloseEvent *event)
1562 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1564 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1565 // This messes up MainWinState/MainWinHidden save/restore.
1566 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1567 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1568 QtUi::hideMainWidget();
1571 else if(!_aboutToQuit) {
1572 _aboutToQuit = true;
1582 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1586 bool hasFocus = QApplication::activeWindow() != 0;
1588 for (int i = start; i <= end; i++) {
1589 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1590 if (!idx.isValid()) {
1591 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1594 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1595 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1598 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1599 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1601 // check if bufferId belongs to the shown chatlists
1602 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1603 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1606 // check if it's the buffer currently displayed
1607 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1610 // only show notifications for higlights or queries
1611 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1614 // and of course: don't notify for ignored messages
1615 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1618 // seems like we have a legit notification candidate!
1619 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1620 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1621 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1622 AbstractNotificationBackend::NotificationType type;
1624 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1625 type = AbstractNotificationBackend::PrivMsg;
1626 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1627 type = AbstractNotificationBackend::PrivMsgFocused;
1628 else if (flags & Message::Highlight && !hasFocus)
1629 type = AbstractNotificationBackend::Highlight;
1631 type = AbstractNotificationBackend::HighlightFocused;
1633 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1638 void MainWin::currentBufferChanged(BufferId buffer)
1640 if (buffer.isValid())
1641 Client::instance()->markBufferAsRead(buffer);
1645 void MainWin::clientNetworkCreated(NetworkId id)
1647 const Network *net = Client::network(id);
1648 QAction *act = new QAction(net->networkName(), this);
1649 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1650 act->setData(QVariant::fromValue<NetworkId>(id));
1651 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1652 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1654 QAction *beforeAction = 0;
1655 foreach(QAction *action, _networksMenu->actions()) {
1656 if (!action->data().isValid()) // ignore stock actions
1658 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1659 beforeAction = action;
1663 _networksMenu->insertAction(beforeAction, act);
1667 void MainWin::clientNetworkUpdated()
1669 const Network *net = qobject_cast<const Network *>(sender());
1673 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1677 action->setText(net->networkName());
1679 switch (net->connectionState()) {
1680 case Network::Initialized:
1681 action->setIcon(QIcon::fromTheme("network-connect"));
1682 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1683 if (!bufferWidget()->currentBuffer().isValid()) {
1684 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1685 if (idx.isValid()) {
1686 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1687 Client::bufferModel()->switchToBuffer(statusBufferId);
1691 case Network::Disconnected:
1692 action->setIcon(QIcon::fromTheme("network-disconnect"));
1695 action->setIcon(QIcon::fromTheme("network-wired"));
1700 void MainWin::clientNetworkRemoved(NetworkId id)
1702 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1706 action->deleteLater();
1710 void MainWin::connectOrDisconnectFromNet()
1712 QAction *act = qobject_cast<QAction *>(sender());
1714 const Network *net = Client::network(act->data().value<NetworkId>());
1716 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1717 else net->requestDisconnect();
1721 void MainWin::on_jumpHotBuffer_triggered()
1723 if (!_bufferHotList->rowCount())
1726 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1729 void MainWin::on_bufferSearch_triggered()
1731 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1732 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1736 _bufferViews[_activeBufferViewIndex]->activateFilter();
1740 void MainWin::onJumpKey()
1742 QAction *action = qobject_cast<QAction *>(sender());
1743 if (!action || !Client::bufferModel())
1745 int idx = action->property("Index").toInt();
1747 if (_jumpKeyMap.isEmpty())
1748 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1750 if (!_jumpKeyMap.contains(idx))
1753 BufferId buffer = _jumpKeyMap.value(idx);
1754 if (buffer.isValid())
1755 Client::bufferModel()->switchToBuffer(buffer);
1759 void MainWin::bindJumpKey()
1761 QAction *action = qobject_cast<QAction *>(sender());
1762 if (!action || !Client::bufferModel())
1764 int idx = action->property("Index").toInt();
1766 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1767 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1771 void MainWin::on_actionDebugNetworkModel_triggered()
1773 QTreeView *view = new QTreeView;
1774 view->setAttribute(Qt::WA_DeleteOnClose);
1775 view->setWindowTitle("Debug NetworkModel View");
1776 view->setModel(Client::networkModel());
1777 view->setColumnWidth(0, 250);
1778 view->setColumnWidth(1, 250);
1779 view->setColumnWidth(2, 80);
1780 view->resize(610, 300);
1785 void MainWin::on_actionDebugHotList_triggered()
1787 _bufferHotList->invalidate();
1788 _bufferHotList->sort(0, Qt::DescendingOrder);
1790 QTreeView *view = new QTreeView;
1791 view->setAttribute(Qt::WA_DeleteOnClose);
1792 view->setModel(_bufferHotList);
1797 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1799 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1800 overlay->setAttribute(Qt::WA_DeleteOnClose);
1805 void MainWin::on_actionDebugMessageModel_triggered()
1807 QTableView *view = new QTableView(0);
1808 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1809 filter->setSourceModel(Client::messageModel());
1810 view->setModel(filter);
1811 view->setAttribute(Qt::WA_DeleteOnClose, true);
1812 view->verticalHeader()->hide();
1813 view->horizontalHeader()->setStretchLastSection(true);
1818 void MainWin::on_actionDebugLog_triggered()
1820 DebugLogWidget *logWidget = new DebugLogWidget(0);
1825 void MainWin::showStatusBarMessage(const QString &message)
1827 statusBar()->showMessage(message, 10000);