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/corehighlightsettingspage.h>
150 #include "settingspages/dccsettingspage.h"
151 #include "settingspages/highlightsettingspage.h"
152 #include "settingspages/identitiessettingspage.h"
153 #include "settingspages/ignorelistsettingspage.h"
154 #include "settingspages/inputwidgetsettingspage.h"
155 #include "settingspages/itemviewsettingspage.h"
156 #include "settingspages/networkssettingspage.h"
157 #include "settingspages/notificationssettingspage.h"
158 #include "settingspages/topicwidgetsettingspage.h"
161 # include "settingspages/shortcutssettingspage.h"
165 # include "settingspages/sonnetsettingspage.h"
169 MainWin::MainWin(QWidget *parent)
171 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
173 : QMainWindow(parent),
175 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
176 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
179 _layoutLoaded(false),
180 _activeBufferViewIndex(-1),
183 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
185 QtUiSettings uiSettings;
186 QString style = uiSettings.value("Style", QString()).toString();
187 if (!style.isEmpty()) {
188 QApplication::setStyle(style);
191 QApplication::setQuitOnLastWindowClosed(false);
193 setWindowTitle("Quassel IRC");
194 setWindowIconText("Quassel IRC");
201 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
202 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
203 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
204 SLOT(messagesInserted(const QModelIndex &, int, int)));
205 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
206 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
207 connect(Client::instance(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
209 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList, QVariantList)), SLOT(showCoreConfigWizard(QVariantList, QVariantList)));
210 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
211 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
212 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
213 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
215 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
219 setDockNestingEnabled(true);
220 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
221 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
222 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
223 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
225 // Order is sometimes important
229 // setupTransferWidget(); not ready yet
241 _bufferWidget->setFocusProxy(_inputWidget);
242 _chatMonitorView->setFocusProxy(_inputWidget);
245 # ifdef HAVE_QTMULTIMEDIA
246 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
249 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
251 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
253 QtUi::registerNotificationBackend(new KNotificationBackend(this));
254 #endif /* HAVE_KDE */
258 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
259 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
260 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
263 #ifdef HAVE_INDICATEQT
264 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
267 #ifdef HAVE_NOTIFICATION_CENTER
268 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
272 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
275 // we assume that at this point, all configurable actions are defined!
276 QtUi::loadShortcuts();
278 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
280 setDisconnectedState(); // Disable menus and stuff
283 setAutoSaveSettings();
286 // restore mainwin state
288 restoreStateFromSettings(s);
290 // restore locked state of docks
291 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
293 CoreConnection *conn = Client::coreConnection();
294 if (!conn->connectToCore()) {
295 // No autoconnect selected (or no accounts)
296 showCoreConnectionDlg();
309 saveStateToSettings(s);
311 QApplication::quit();
315 void MainWin::saveStateToSettings(UiSettings &s)
317 s.setValue("MainWinSize", _normalSize);
318 s.setValue("MainWinPos", _normalPos);
319 s.setValue("MainWinState", saveState());
320 s.setValue("MainWinGeometry", saveGeometry());
321 s.setValue("MainWinMinimized", isMinimized());
322 s.setValue("MainWinMaximized", isMaximized());
323 s.setValue("MainWinHidden", !isVisible());
324 BufferId lastBufId = Client::bufferModel()->currentBuffer();
325 if (lastBufId.isValid())
326 s.setValue("LastUsedBufferId", lastBufId.toInt());
329 saveAutoSaveSettings();
334 void MainWin::restoreStateFromSettings(UiSettings &s)
336 _normalSize = s.value("MainWinSize", size()).toSize();
337 _normalPos = s.value("MainWinPos", pos()).toPoint();
338 bool maximized = s.value("MainWinMaximized", false).toBool();
341 restoreGeometry(s.value("MainWinGeometry").toByteArray());
344 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
349 restoreState(s.value("MainWinState").toByteArray());
355 if ((Quassel::isOptionSet("hidewindow")
356 || s.value("MainWinHidden").toBool())
357 && _systemTray->isSystemTrayAvailable())
358 QtUi::hideMainWidget();
359 else if (s.value("MainWinMinimized").toBool())
367 QMenu *MainWin::createPopupMenu()
369 QMenu *popupMenu = QMainWindow::createPopupMenu();
370 popupMenu->addSeparator();
371 ActionCollection *coll = QtUi::actionCollection("General");
372 popupMenu->addAction(coll->action("ToggleMenuBar"));
377 void MainWin::updateIcon()
380 if (Client::isConnected())
381 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
383 icon = QIcon::fromTheme("inactive-quassel", QIcon(":/icons/inactive-quassel.png"));
385 qApp->setWindowIcon(icon);
389 void MainWin::setupActions()
391 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
393 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("connect-quassel", QIcon(":/icons/connect-quassel.png")), tr("&Connect to Core..."), coll,
394 this, SLOT(showCoreConnectionDlg())));
395 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("disconnect-quassel", QIcon(":/icons/disconnect-quassel.png")), tr("&Disconnect from Core"), coll,
396 Client::instance(), SLOT(disconnectFromCore())));
397 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
398 this, SLOT(showPasswordChangeDlg())));
399 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
400 this, SLOT(showCoreInfoDlg())));
401 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
402 this, SLOT(on_actionConfigureNetworks_triggered())));
403 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
404 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
405 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
408 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
409 this, SLOT(on_actionConfigureViews_triggered())));
411 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
412 lockAct->setCheckable(true);
413 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
415 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
416 0, 0, QKeySequence::Find))->setCheckable(true);
417 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
418 this, SLOT(showAwayLog())));
419 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
420 0, 0))->setCheckable(true);
422 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
423 0, 0))->setCheckable(true);
426 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
428 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
429 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
430 _fullScreenAction->setCheckable(true);
431 coll->addAction("ToggleFullScreen", _fullScreenAction);
435 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
436 this, SLOT(showShortcutsDlg()));
437 configureShortcutsAct->setMenuRole(QAction::NoRole);
438 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
441 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
442 this, SLOT(showSettingsDlg()));
443 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
445 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
446 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
448 coll->addAction("ConfigureQuassel", configureQuasselAct);
451 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
452 this, SLOT(showAboutDlg()));
453 aboutQuasselAct->setMenuRole(QAction::AboutRole);
454 coll->addAction("AboutQuassel", aboutQuasselAct);
456 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
457 qApp, SLOT(aboutQt()));
458 aboutQtAct->setMenuRole(QAction::AboutQtRole);
459 coll->addAction("AboutQt", aboutQtAct);
460 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
461 this, SLOT(on_actionDebugNetworkModel_triggered())));
462 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
463 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
464 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
465 this, SLOT(on_actionDebugMessageModel_triggered())));
466 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
467 this, SLOT(on_actionDebugHotList_triggered())));
468 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
469 this, SLOT(on_actionDebugLog_triggered())));
470 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
471 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
473 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
474 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
477 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
479 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
480 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
482 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
483 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
487 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
488 const int jumpModifier = Qt::ControlModifier;
490 const int bindModifier = Qt::ControlModifier;
491 const int jumpModifier = Qt::AltModifier;
494 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
495 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
496 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
497 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
498 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
499 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
500 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
501 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
502 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
503 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
504 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
505 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
506 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
507 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
508 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
509 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
510 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
511 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
512 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
513 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
515 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
516 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
517 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
518 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
519 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
520 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
521 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
522 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
523 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
524 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
525 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
526 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
527 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
528 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
529 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
530 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
531 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
532 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
533 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
534 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
537 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
538 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
539 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
540 this, SLOT(previousBufferView()), QKeySequence::Back));
541 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
542 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
543 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
544 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
548 void MainWin::setupMenus()
550 ActionCollection *coll = QtUi::actionCollection("General");
552 _fileMenu = menuBar()->addMenu(tr("&File"));
554 static const QStringList coreActions = QStringList()
555 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
558 foreach(QString actionName, coreActions) {
559 coreAction = coll->action(actionName);
560 _fileMenu->addAction(coreAction);
561 flagRemoteCoreOnly(coreAction);
563 flagRemoteCoreOnly(_fileMenu->addSeparator());
565 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
566 _networksMenu->addAction(coll->action("ConfigureNetworks"));
567 _networksMenu->addSeparator();
568 _fileMenu->addSeparator();
569 _fileMenu->addAction(coll->action("Quit"));
571 _viewMenu = menuBar()->addMenu(tr("&View"));
572 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
573 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
574 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
575 _viewMenu->addSeparator();
577 _viewMenu->addAction(coll->action("ToggleMenuBar"));
578 _viewMenu->addAction(coll->action("ToggleStatusBar"));
579 _viewMenu->addAction(coll->action("ToggleSearchBar"));
581 coreAction = coll->action("ShowAwayLog");
582 flagRemoteCoreOnly(coreAction);
583 _viewMenu->addAction(coreAction);
585 _viewMenu->addSeparator();
586 _viewMenu->addAction(coll->action("LockLayout"));
588 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
590 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
591 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
593 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
595 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
598 _helpMenu = menuBar()->addMenu(tr("&Help"));
600 _helpMenu->addAction(coll->action("AboutQuassel"));
602 _helpMenu->addAction(coll->action("AboutQt"));
604 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
606 _helpMenu->addSeparator();
607 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
608 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
609 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
610 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
611 _helpDebugMenu->addAction(coll->action("DebugHotList"));
612 _helpDebugMenu->addAction(coll->action("DebugLog"));
613 _helpDebugMenu->addSeparator();
614 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
617 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
619 QtUiSettings uiSettings;
620 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
621 showMenuBar->setChecked(enabled);
622 enabled ? menuBar()->show() : menuBar()->hide();
624 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
625 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
629 void MainWin::setupBufferWidget()
631 _bufferWidget = new BufferWidget(this);
632 _bufferWidget->setModel(Client::bufferModel());
633 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
634 setCentralWidget(_bufferWidget);
638 void MainWin::addBufferView(int bufferViewConfigId)
640 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
644 void MainWin::addBufferView(ClientBufferViewConfig *config)
649 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
650 BufferViewDock *dock = new BufferViewDock(config, this);
652 //create the view and initialize it's filter
653 BufferView *view = new BufferView(dock);
654 view->setFilteredModel(Client::bufferModel(), config);
655 view->installEventFilter(_inputWidget); // for key presses
657 Client::bufferModel()->synchronizeView(view);
659 dock->setWidget(view);
660 dock->setVisible(_layoutLoaded); // don't show before state has been restored
662 addDockWidget(Qt::LeftDockWidgetArea, dock);
663 _bufferViewsMenu->addAction(dock->toggleViewAction());
665 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
666 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
667 _bufferViews.append(dock);
669 if (!activeBufferView())
674 void MainWin::removeBufferView(int bufferViewConfigId)
677 BufferViewDock *dock;
678 foreach(QAction *action, _bufferViewsMenu->actions()) {
679 actionData = action->data();
680 if (!actionData.isValid())
683 dock = qobject_cast<BufferViewDock *>(action->parent());
684 if (dock && actionData.toInt() == bufferViewConfigId) {
685 removeAction(action);
686 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
687 _bufferViews.removeAll(dock);
689 if (dock->isActive()) {
690 dock->setActive(false);
691 _activeBufferViewIndex = -1;
701 void MainWin::bufferViewToggled(bool enabled)
703 if (!enabled && !isMinimized()) {
704 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
705 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
708 QAction *action = qobject_cast<QAction *>(sender());
710 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
713 // Make sure we don't toggle backlog fetch for a view we've already removed
714 if (!_bufferViews.contains(dock))
718 Client::bufferViewOverlay()->addView(dock->bufferViewId());
720 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
724 void MainWin::bufferViewVisibilityChanged(bool visible)
727 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
729 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
734 BufferView *MainWin::allBuffersView() const
736 // "All Buffers" is always the first dock created
737 if (_bufferViews.count() > 0)
738 return _bufferViews[0]->bufferView();
743 BufferView *MainWin::activeBufferView() const
745 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
747 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
748 return dock->isActive() ? dock->bufferView() : 0;
752 void MainWin::changeActiveBufferView(int bufferViewId)
754 if (bufferViewId < 0)
757 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
758 _bufferViews[_activeBufferViewIndex]->setActive(false);
759 _activeBufferViewIndex = -1;
762 for (int i = 0; i < _bufferViews.count(); i++) {
763 BufferViewDock *dock = _bufferViews.at(i);
764 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
765 _activeBufferViewIndex = i;
766 dock->setActive(true);
771 nextBufferView(); // fallback
775 void MainWin::showPasswordChangeDlg()
777 if((Client::coreFeatures() & Quassel::PasswordChange)) {
778 PasswordChangeDlg dlg(this);
782 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
783 tr("<b>Your Quassel Core does not support this feature</b>"),
784 QMessageBox::Ok, this);
785 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
791 void MainWin::changeActiveBufferView(bool backwards)
793 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
794 _bufferViews[_activeBufferViewIndex]->setActive(false);
797 if (!_bufferViews.count())
800 int c = _bufferViews.count();
801 while (c--) { // yes, this will reactivate the current active one if all others fail
803 if (--_activeBufferViewIndex < 0)
804 _activeBufferViewIndex = _bufferViews.count()-1;
807 if (++_activeBufferViewIndex >= _bufferViews.count())
808 _activeBufferViewIndex = 0;
811 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
812 if (dock->isHidden())
815 dock->setActive(true);
819 _activeBufferViewIndex = -1;
823 void MainWin::nextBufferView()
825 changeActiveBufferView(false);
829 void MainWin::previousBufferView()
831 changeActiveBufferView(true);
835 void MainWin::nextBuffer()
837 BufferView *view = activeBufferView();
843 void MainWin::previousBuffer()
845 BufferView *view = activeBufferView();
847 view->previousBuffer();
851 void MainWin::hideCurrentBuffer()
853 BufferView *view = activeBufferView();
855 view->hideCurrentBuffer();
859 void MainWin::showNotificationsDlg()
861 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
866 void MainWin::on_actionConfigureNetworks_triggered()
868 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
873 void MainWin::on_actionConfigureViews_triggered()
875 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
880 void MainWin::on_actionLockLayout_toggled(bool lock)
882 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
883 foreach(VerticalDock *dock, docks) {
884 dock->showTitle(!lock);
886 if (Client::bufferViewManager()) {
887 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
888 config->setLocked(lock);
891 QtUiSettings().setValue("LockLayout", lock);
895 void MainWin::setupNickWidget()
898 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
899 nickDock->setObjectName("NickDock");
900 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
902 _nickListWidget = new NickListWidget(nickDock);
903 nickDock->setWidget(_nickListWidget);
905 addDockWidget(Qt::RightDockWidgetArea, nickDock);
906 _viewMenu->addAction(nickDock->toggleViewAction());
907 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
909 // See NickListDock::NickListDock();
910 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
912 // attach the NickListWidget to the BufferModel and the default selection
913 _nickListWidget->setModel(Client::bufferModel());
914 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
916 _nickListWidget->setVisible(false);
920 void MainWin::setupChatMonitor()
922 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
923 dock->setObjectName("ChatMonitorDock");
925 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
926 _chatMonitorView = new ChatMonitorView(filter, this);
927 _chatMonitorView->show();
928 dock->setWidget(_chatMonitorView);
931 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
932 _viewMenu->addAction(dock->toggleViewAction());
933 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
937 void MainWin::setupInputWidget()
939 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
940 dock->setObjectName("InputDock");
942 _inputWidget = new InputWidget(dock);
943 dock->setWidget(_inputWidget);
945 addDockWidget(Qt::BottomDockWidgetArea, dock);
947 _viewMenu->addAction(dock->toggleViewAction());
948 dock->toggleViewAction()->setText(tr("Show Input Line"));
950 _inputWidget->setModel(Client::bufferModel());
951 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
953 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
955 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
959 void MainWin::setupTopicWidget()
961 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
962 dock->setObjectName("TopicDock");
963 _topicWidget = new TopicWidget(dock);
965 dock->setWidget(_topicWidget);
967 _topicWidget->setModel(Client::bufferModel());
968 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
970 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
972 _viewMenu->addAction(dock->toggleViewAction());
973 dock->toggleViewAction()->setText(tr("Show Topic Line"));
977 void MainWin::setupTransferWidget()
979 auto dock = new QDockWidget(tr("Transfers"), this);
980 dock->setObjectName("TransferDock");
981 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
983 auto view = new QTableView(dock); // to be replaced by the real thing
984 view->setModel(Client::transferModel());
985 dock->setWidget(view);
986 dock->hide(); // hidden by default
987 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
989 auto action = dock->toggleViewAction();
990 action->setText(tr("Show File Transfers"));
991 action->setIcon(QIcon::fromTheme("download"));
992 action->setShortcut(QKeySequence(Qt::Key_F6));
993 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
994 _viewMenu->addAction(action);
998 void MainWin::setupViewMenuTail()
1000 _viewMenu->addSeparator();
1001 _viewMenu->addAction(_fullScreenAction);
1005 void MainWin::setupTitleSetter()
1007 _titleSetter.setModel(Client::bufferModel());
1008 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1012 void MainWin::setupStatusBar()
1014 // MessageProcessor progress
1015 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1018 _coreConnectionStatusWidget->update();
1019 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1021 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1023 QtUiSettings uiSettings;
1025 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1026 showStatusbar->setChecked(enabled);
1027 enabled ? statusBar()->show() : statusBar()->hide();
1029 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1030 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1032 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1036 void MainWin::setupHotList()
1038 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1039 flatProxy->setSourceModel(Client::bufferModel());
1040 _bufferHotList = new BufferHotListFilter(flatProxy);
1044 void MainWin::saveMenuBarStatus(bool enabled)
1046 QtUiSettings uiSettings;
1047 uiSettings.setValue("ShowMenuBar", enabled);
1051 void MainWin::saveStatusBarStatus(bool enabled)
1053 QtUiSettings uiSettings;
1054 uiSettings.setValue("ShowStatusBar", enabled);
1058 void MainWin::setupSystray()
1061 _systemTray = new StatusNotifierItem(this);
1062 #elif !defined QT_NO_SYSTEMTRAYICON
1063 _systemTray = new LegacySystemTray(this);
1065 _systemTray = new SystemTray(this); // dummy
1067 _systemTray->init();
1071 void MainWin::setupToolBars()
1073 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1074 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1075 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1076 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1079 setUnifiedTitleAndToolBarOnMac(true);
1083 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1085 _mainToolBar = new QToolBar(this);
1086 _mainToolBar->setObjectName("MainToolBar");
1088 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1089 addToolBar(_mainToolBar);
1091 if (Quassel::runMode() != Quassel::Monolithic) {
1092 ActionCollection *coll = QtUi::actionCollection("General");
1093 _mainToolBar->addAction(coll->action("ConnectCore"));
1094 _mainToolBar->addAction(coll->action("DisconnectCore"));
1097 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1098 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1101 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1103 _nickToolBar = new QToolBar(this);
1104 _nickToolBar->setObjectName("NickToolBar");
1106 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1107 _nickToolBar->setVisible(false); //default: not visible
1108 addToolBar(_nickToolBar);
1110 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1111 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1114 QtUiSettings uiSettings;
1116 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1117 _mainToolBar->setVisible(visible);
1118 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1122 void MainWin::saveMainToolBarStatus(bool enabled)
1125 QtUiSettings uiSettings;
1126 uiSettings.setValue("ShowMainToolBar", enabled);
1133 void MainWin::connectedToCore()
1135 Q_CHECK_PTR(Client::bufferViewManager());
1136 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1137 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1138 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1140 if (Client::transferManager()) {
1141 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1144 setConnectedState();
1148 void MainWin::setConnectedState()
1150 ActionCollection *coll = QtUi::actionCollection("General");
1152 coll->action("ConnectCore")->setEnabled(false);
1153 coll->action("DisconnectCore")->setEnabled(true);
1154 coll->action("ChangePassword")->setEnabled(true);
1155 coll->action("CoreInfo")->setEnabled(true);
1157 foreach(QAction *action, _fileMenu->actions()) {
1158 if (isRemoteCoreOnly(action))
1159 action->setVisible(!Client::internalCore());
1162 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1163 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1164 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1165 if (!Client::internalCore()) {
1166 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1167 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1168 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1171 // _viewMenu->setEnabled(true);
1172 if (!Client::internalCore())
1173 statusBar()->showMessage(tr("Connected to core."));
1175 statusBar()->clearMessage();
1177 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1179 systemTray()->setState(SystemTray::Active);
1181 if (Client::networkIds().isEmpty()) {
1182 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1186 // Monolithic always preselects last used buffer - Client only if the connection died
1187 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1189 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1190 if (lastUsedBufferId.isValid())
1191 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1197 void MainWin::loadLayout()
1200 int accountId = Client::currentCoreAccount().accountId().toInt();
1201 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1202 if (state.isEmpty()) {
1203 foreach(BufferViewDock *view, _bufferViews)
1205 _layoutLoaded = true;
1208 _nickListWidget->setVisible(true);
1209 restoreState(state, accountId);
1210 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1211 if (bufferViewId >= 0)
1212 changeActiveBufferView(bufferViewId);
1214 _layoutLoaded = true;
1218 void MainWin::saveLayout()
1221 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1222 if (accountId > 0) {
1223 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1224 BufferView *view = activeBufferView();
1225 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1230 void MainWin::disconnectedFromCore()
1232 // save core specific layout and remove bufferviews;
1234 _layoutLoaded = false;
1236 QVariant actionData;
1237 BufferViewDock *dock;
1238 foreach(QAction *action, _bufferViewsMenu->actions()) {
1239 actionData = action->data();
1240 if (!actionData.isValid())
1243 dock = qobject_cast<BufferViewDock *>(action->parent());
1244 if (dock && actionData.toInt() != -1) {
1245 removeAction(action);
1246 _bufferViews.removeAll(dock);
1247 dock->deleteLater();
1251 // store last active buffer
1253 BufferId lastBufId = _bufferWidget->currentBuffer();
1254 if (lastBufId.isValid()) {
1255 s.setValue("LastUsedBufferId", lastBufId.toInt());
1256 // clear the current selection
1257 Client::bufferModel()->standardSelectionModel()->clearSelection();
1259 restoreState(s.value("MainWinState").toByteArray());
1260 setDisconnectedState();
1264 void MainWin::setDisconnectedState()
1266 ActionCollection *coll = QtUi::actionCollection("General");
1267 //ui.menuCore->setEnabled(false);
1268 coll->action("ConnectCore")->setEnabled(true);
1269 coll->action("DisconnectCore")->setEnabled(false);
1270 coll->action("CoreInfo")->setEnabled(false);
1271 coll->action("ChangePassword")->setEnabled(false);
1272 //_viewMenu->setEnabled(false);
1273 statusBar()->showMessage(tr("Not connected to core."));
1274 if (_msgProcessorStatusWidget)
1275 _msgProcessorStatusWidget->setProgress(0, 0);
1277 systemTray()->setState(SystemTray::Passive);
1278 _nickListWidget->setVisible(false);
1282 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1284 Q_UNUSED(errorMessage)
1285 CoreConnectAuthDlg dlg(account, this);
1286 *valid = (dlg.exec() == QDialog::Accepted);
1290 void MainWin::handleNoSslInClient(bool *accepted)
1292 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1293 QMessageBox::Ignore|QMessageBox::Cancel, this);
1294 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1295 box.setDefaultButton(QMessageBox::Ignore);
1296 *accepted = box.exec() == QMessageBox::Ignore;
1300 void MainWin::handleNoSslInCore(bool *accepted)
1302 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1303 QMessageBox::Ignore|QMessageBox::Cancel, this);
1304 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1305 box.setDefaultButton(QMessageBox::Ignore);
1306 *accepted = box.exec() == QMessageBox::Ignore;
1312 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1314 QString errorString = "<ul>";
1315 foreach(const QSslError error, socket->sslErrors())
1316 errorString += QString("<li>%1</li>").arg(error.errorString());
1317 errorString += "</ul>";
1319 QMessageBox box(QMessageBox::Warning,
1320 tr("Untrusted Security Certificate"),
1321 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1322 QMessageBox::Cancel, this);
1323 box.setInformativeText(errorString);
1324 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1325 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1327 QMessageBox::ButtonRole role;
1330 role = box.buttonRole(box.clickedButton());
1331 if (role == QMessageBox::HelpRole) {
1332 SslInfoDlg dlg(socket, this);
1336 while (role == QMessageBox::HelpRole);
1338 *accepted = role == QMessageBox::AcceptRole;
1340 QMessageBox box2(QMessageBox::Warning,
1341 tr("Untrusted Security Certificate"),
1342 tr("Would you like to accept this certificate forever without being prompted?"),
1344 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1345 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1347 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1352 #endif /* HAVE_SSL */
1354 void MainWin::handleCoreConnectionError(const QString &error)
1356 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1360 void MainWin::showCoreConnectionDlg()
1362 CoreConnectDlg dlg(this);
1363 if (dlg.exec() == QDialog::Accepted) {
1364 AccountId accId = dlg.selectedAccount();
1365 if (accId.isValid())
1366 Client::coreConnection()->connectToCore(accId);
1371 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1373 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1379 void MainWin::showChannelList(NetworkId netId)
1381 ChannelListDlg *channelListDlg = new ChannelListDlg();
1383 if (!netId.isValid()) {
1384 QAction *action = qobject_cast<QAction *>(sender());
1386 netId = action->data().value<NetworkId>();
1389 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1390 channelListDlg->setNetwork(netId);
1391 channelListDlg->show();
1395 void MainWin::showIgnoreList(QString newRule)
1397 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1398 // prepare config dialog for new rule
1399 if (!newRule.isEmpty())
1400 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1405 void MainWin::showCoreInfoDlg()
1407 CoreInfoDlg(this).exec();
1411 void MainWin::showAwayLog()
1415 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1416 _awayLog = new AwayLogView(filter, 0);
1417 filter->setParent(_awayLog);
1418 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1419 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1424 void MainWin::awayLogDestroyed()
1430 void MainWin::showSettingsDlg()
1432 SettingsDlg *dlg = new SettingsDlg();
1434 //Category: Interface
1435 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1436 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1437 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1438 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1439 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1440 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1441 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1442 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1444 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1446 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1447 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1448 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1449 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1452 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1453 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1454 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1455 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1456 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1457 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1459 // Category: Remote Cores
1460 if (Quassel::runMode() != Quassel::Monolithic) {
1461 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1462 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1469 void MainWin::showAboutDlg()
1471 AboutDlg(this).exec();
1475 void MainWin::showShortcutsDlg()
1478 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1479 foreach(KActionCollection *coll, QtUi::actionCollections())
1480 dlg.addCollection(coll, coll->property("Category").toString());
1481 dlg.configure(true);
1483 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1489 void MainWin::showNewTransferDlg(const QUuid &transferId)
1491 auto transfer = Client::transferManager()->transfer(transferId);
1493 if (transfer->status() == Transfer::Status::New) {
1494 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1499 qWarning() << "Unknown transfer ID" << transferId;
1504 void MainWin::onFullScreenToggled()
1506 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1507 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1510 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1512 if (_fullScreenAction->isChecked())
1513 setWindowState(windowState() | Qt::WindowFullScreen);
1515 setWindowState(windowState() & ~Qt::WindowFullScreen);
1520 /********************************************************************************************************/
1522 bool MainWin::event(QEvent *event)
1524 switch(event->type()) {
1525 case QEvent::WindowActivate: {
1526 BufferId bufferId = Client::bufferModel()->currentBuffer();
1527 if (bufferId.isValid())
1528 Client::instance()->markBufferAsRead(bufferId);
1531 case QEvent::WindowDeactivate:
1532 if (bufferWidget()->autoMarkerLineOnLostFocus())
1533 bufferWidget()->setMarkerLine();
1538 return QMainWindow::event(event);
1542 void MainWin::moveEvent(QMoveEvent *event)
1544 if (!(windowState() & Qt::WindowMaximized))
1545 _normalPos = event->pos();
1547 QMainWindow::moveEvent(event);
1551 void MainWin::resizeEvent(QResizeEvent *event)
1553 if (!(windowState() & Qt::WindowMaximized))
1554 _normalSize = event->size();
1556 QMainWindow::resizeEvent(event);
1560 void MainWin::closeEvent(QCloseEvent *event)
1563 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1565 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1566 // This messes up MainWinState/MainWinHidden save/restore.
1567 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1568 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1569 QtUi::hideMainWidget();
1572 else if(!_aboutToQuit) {
1573 _aboutToQuit = true;
1583 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1587 bool hasFocus = QApplication::activeWindow() != 0;
1589 for (int i = start; i <= end; i++) {
1590 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1591 if (!idx.isValid()) {
1592 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1595 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1596 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1599 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1600 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1602 // check if bufferId belongs to the shown chatlists
1603 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1604 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1607 // check if it's the buffer currently displayed
1608 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1611 // only show notifications for higlights or queries
1612 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1615 // and of course: don't notify for ignored messages
1616 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1619 // seems like we have a legit notification candidate!
1620 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1621 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1622 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1623 AbstractNotificationBackend::NotificationType type;
1625 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1626 type = AbstractNotificationBackend::PrivMsg;
1627 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1628 type = AbstractNotificationBackend::PrivMsgFocused;
1629 else if (flags & Message::Highlight && !hasFocus)
1630 type = AbstractNotificationBackend::Highlight;
1632 type = AbstractNotificationBackend::HighlightFocused;
1634 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1639 void MainWin::currentBufferChanged(BufferId buffer)
1641 if (buffer.isValid())
1642 Client::instance()->markBufferAsRead(buffer);
1646 void MainWin::clientNetworkCreated(NetworkId id)
1648 const Network *net = Client::network(id);
1649 QAction *act = new QAction(net->networkName(), this);
1650 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1651 act->setData(QVariant::fromValue<NetworkId>(id));
1652 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1653 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1655 QAction *beforeAction = 0;
1656 foreach(QAction *action, _networksMenu->actions()) {
1657 if (!action->data().isValid()) // ignore stock actions
1659 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1660 beforeAction = action;
1664 _networksMenu->insertAction(beforeAction, act);
1668 void MainWin::clientNetworkUpdated()
1670 const Network *net = qobject_cast<const Network *>(sender());
1674 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1678 action->setText(net->networkName());
1680 switch (net->connectionState()) {
1681 case Network::Initialized:
1682 action->setIcon(QIcon::fromTheme("network-connect"));
1683 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1684 if (!bufferWidget()->currentBuffer().isValid()) {
1685 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1686 if (idx.isValid()) {
1687 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1688 Client::bufferModel()->switchToBuffer(statusBufferId);
1692 case Network::Disconnected:
1693 action->setIcon(QIcon::fromTheme("network-disconnect"));
1696 action->setIcon(QIcon::fromTheme("network-wired"));
1701 void MainWin::clientNetworkRemoved(NetworkId id)
1703 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1707 action->deleteLater();
1711 void MainWin::connectOrDisconnectFromNet()
1713 QAction *act = qobject_cast<QAction *>(sender());
1715 const Network *net = Client::network(act->data().value<NetworkId>());
1717 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1718 else net->requestDisconnect();
1722 void MainWin::on_jumpHotBuffer_triggered()
1724 if (!_bufferHotList->rowCount())
1727 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1730 void MainWin::on_bufferSearch_triggered()
1732 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1733 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1737 _bufferViews[_activeBufferViewIndex]->activateFilter();
1741 void MainWin::onJumpKey()
1743 QAction *action = qobject_cast<QAction *>(sender());
1744 if (!action || !Client::bufferModel())
1746 int idx = action->property("Index").toInt();
1748 if (_jumpKeyMap.isEmpty())
1749 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1751 if (!_jumpKeyMap.contains(idx))
1754 BufferId buffer = _jumpKeyMap.value(idx);
1755 if (buffer.isValid())
1756 Client::bufferModel()->switchToBuffer(buffer);
1760 void MainWin::bindJumpKey()
1762 QAction *action = qobject_cast<QAction *>(sender());
1763 if (!action || !Client::bufferModel())
1765 int idx = action->property("Index").toInt();
1767 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1768 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1772 void MainWin::on_actionDebugNetworkModel_triggered()
1774 QTreeView *view = new QTreeView;
1775 view->setAttribute(Qt::WA_DeleteOnClose);
1776 view->setWindowTitle("Debug NetworkModel View");
1777 view->setModel(Client::networkModel());
1778 view->setColumnWidth(0, 250);
1779 view->setColumnWidth(1, 250);
1780 view->setColumnWidth(2, 80);
1781 view->resize(610, 300);
1786 void MainWin::on_actionDebugHotList_triggered()
1788 _bufferHotList->invalidate();
1789 _bufferHotList->sort(0, Qt::DescendingOrder);
1791 QTreeView *view = new QTreeView;
1792 view->setAttribute(Qt::WA_DeleteOnClose);
1793 view->setModel(_bufferHotList);
1798 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1800 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1801 overlay->setAttribute(Qt::WA_DeleteOnClose);
1806 void MainWin::on_actionDebugMessageModel_triggered()
1808 QTableView *view = new QTableView(0);
1809 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1810 filter->setSourceModel(Client::messageModel());
1811 view->setModel(filter);
1812 view->setAttribute(Qt::WA_DeleteOnClose, true);
1813 view->verticalHeader()->hide();
1814 view->horizontalHeader()->setStretchLastSection(true);
1819 void MainWin::on_actionDebugLog_triggered()
1821 DebugLogWidget *logWidget = new DebugLogWidget(0);
1826 void MainWin::showStatusBarMessage(const QString &message)
1828 statusBar()->showMessage(message, 10000);