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(Client::instance(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
207 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
208 connect(Client::instance(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
210 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList, QVariantList)), SLOT(showCoreConfigWizard(QVariantList, QVariantList)));
211 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
212 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
213 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
214 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
216 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
220 setDockNestingEnabled(true);
221 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
222 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
223 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
224 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
226 // Order is sometimes important
230 // setupTransferWidget(); not ready yet
242 _bufferWidget->setFocusProxy(_inputWidget);
243 _chatMonitorView->setFocusProxy(_inputWidget);
246 # ifdef HAVE_QTMULTIMEDIA
247 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
250 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
252 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
254 QtUi::registerNotificationBackend(new KNotificationBackend(this));
255 #endif /* HAVE_KDE */
259 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
260 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
261 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
264 #ifdef HAVE_INDICATEQT
265 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
268 #ifdef HAVE_NOTIFICATION_CENTER
269 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
273 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
276 // we assume that at this point, all configurable actions are defined!
277 QtUi::loadShortcuts();
279 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
281 setDisconnectedState(); // Disable menus and stuff
284 setAutoSaveSettings();
287 // restore mainwin state
289 restoreStateFromSettings(s);
291 // restore locked state of docks
292 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
294 CoreConnection *conn = Client::coreConnection();
295 if (!conn->connectToCore()) {
296 // No autoconnect selected (or no accounts)
297 showCoreConnectionDlg();
310 saveStateToSettings(s);
312 QApplication::quit();
316 void MainWin::saveStateToSettings(UiSettings &s)
318 s.setValue("MainWinSize", _normalSize);
319 s.setValue("MainWinPos", _normalPos);
320 s.setValue("MainWinState", saveState());
321 s.setValue("MainWinGeometry", saveGeometry());
322 s.setValue("MainWinMinimized", isMinimized());
323 s.setValue("MainWinMaximized", isMaximized());
324 s.setValue("MainWinHidden", !isVisible());
325 BufferId lastBufId = Client::bufferModel()->currentBuffer();
326 if (lastBufId.isValid())
327 s.setValue("LastUsedBufferId", lastBufId.toInt());
330 saveAutoSaveSettings();
335 void MainWin::restoreStateFromSettings(UiSettings &s)
337 _normalSize = s.value("MainWinSize", size()).toSize();
338 _normalPos = s.value("MainWinPos", pos()).toPoint();
339 bool maximized = s.value("MainWinMaximized", false).toBool();
342 restoreGeometry(s.value("MainWinGeometry").toByteArray());
345 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
350 restoreState(s.value("MainWinState").toByteArray());
356 if ((Quassel::isOptionSet("hidewindow")
357 || s.value("MainWinHidden").toBool())
358 && _systemTray->isSystemTrayAvailable())
359 QtUi::hideMainWidget();
360 else if (s.value("MainWinMinimized").toBool())
368 QMenu *MainWin::createPopupMenu()
370 QMenu *popupMenu = QMainWindow::createPopupMenu();
371 popupMenu->addSeparator();
372 ActionCollection *coll = QtUi::actionCollection("General");
373 popupMenu->addAction(coll->action("ToggleMenuBar"));
378 void MainWin::updateIcon()
381 if (Client::isConnected())
382 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
384 icon = QIcon::fromTheme("inactive-quassel", QIcon(":/icons/inactive-quassel.png"));
386 qApp->setWindowIcon(icon);
390 void MainWin::setupActions()
392 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
394 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("connect-quassel", QIcon(":/icons/connect-quassel.png")), tr("&Connect to Core..."), coll,
395 this, SLOT(showCoreConnectionDlg())));
396 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("disconnect-quassel", QIcon(":/icons/disconnect-quassel.png")), tr("&Disconnect from Core"), coll,
397 Client::instance(), SLOT(disconnectFromCore())));
398 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
399 this, SLOT(showPasswordChangeDlg())));
400 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
401 this, SLOT(showCoreInfoDlg())));
402 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
403 this, SLOT(on_actionConfigureNetworks_triggered())));
404 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
405 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
406 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
409 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
410 this, SLOT(on_actionConfigureViews_triggered())));
412 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
413 lockAct->setCheckable(true);
414 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
416 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
417 0, 0, QKeySequence::Find))->setCheckable(true);
418 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
419 this, SLOT(showAwayLog())));
420 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
421 0, 0))->setCheckable(true);
423 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
424 0, 0))->setCheckable(true);
427 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
429 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
430 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
431 _fullScreenAction->setCheckable(true);
432 coll->addAction("ToggleFullScreen", _fullScreenAction);
436 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
437 this, SLOT(showShortcutsDlg()));
438 configureShortcutsAct->setMenuRole(QAction::NoRole);
439 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
442 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
443 this, SLOT(showSettingsDlg()));
444 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
446 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
447 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
449 coll->addAction("ConfigureQuassel", configureQuasselAct);
452 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
453 this, SLOT(showAboutDlg()));
454 aboutQuasselAct->setMenuRole(QAction::AboutRole);
455 coll->addAction("AboutQuassel", aboutQuasselAct);
457 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
458 qApp, SLOT(aboutQt()));
459 aboutQtAct->setMenuRole(QAction::AboutQtRole);
460 coll->addAction("AboutQt", aboutQtAct);
461 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
462 this, SLOT(on_actionDebugNetworkModel_triggered())));
463 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
464 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
465 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
466 this, SLOT(on_actionDebugMessageModel_triggered())));
467 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
468 this, SLOT(on_actionDebugHotList_triggered())));
469 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
470 this, SLOT(on_actionDebugLog_triggered())));
471 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
472 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
474 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
475 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
478 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
480 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
481 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
483 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
484 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
488 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
489 const int jumpModifier = Qt::ControlModifier;
491 const int bindModifier = Qt::ControlModifier;
492 const int jumpModifier = Qt::AltModifier;
495 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
496 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
497 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
498 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
499 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
500 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
501 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
502 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
503 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
504 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
505 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
506 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
507 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
508 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
509 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
510 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
511 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
512 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
513 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
514 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
516 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
517 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
518 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
519 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
520 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
521 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
522 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
523 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
524 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
525 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
526 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
527 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
528 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
529 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
530 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
531 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
532 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
533 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
534 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
535 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
538 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
539 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
540 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
541 this, SLOT(previousBufferView()), QKeySequence::Back));
542 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
543 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
544 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
545 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
549 void MainWin::setupMenus()
551 ActionCollection *coll = QtUi::actionCollection("General");
553 _fileMenu = menuBar()->addMenu(tr("&File"));
555 static const QStringList coreActions = QStringList()
556 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
559 foreach(QString actionName, coreActions) {
560 coreAction = coll->action(actionName);
561 _fileMenu->addAction(coreAction);
562 flagRemoteCoreOnly(coreAction);
564 flagRemoteCoreOnly(_fileMenu->addSeparator());
566 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
567 _networksMenu->addAction(coll->action("ConfigureNetworks"));
568 _networksMenu->addSeparator();
569 _fileMenu->addSeparator();
570 _fileMenu->addAction(coll->action("Quit"));
572 _viewMenu = menuBar()->addMenu(tr("&View"));
573 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
574 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
575 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
576 _viewMenu->addSeparator();
578 _viewMenu->addAction(coll->action("ToggleMenuBar"));
579 _viewMenu->addAction(coll->action("ToggleStatusBar"));
580 _viewMenu->addAction(coll->action("ToggleSearchBar"));
582 coreAction = coll->action("ShowAwayLog");
583 flagRemoteCoreOnly(coreAction);
584 _viewMenu->addAction(coreAction);
586 _viewMenu->addSeparator();
587 _viewMenu->addAction(coll->action("LockLayout"));
589 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
591 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
592 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
594 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
596 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
599 _helpMenu = menuBar()->addMenu(tr("&Help"));
601 _helpMenu->addAction(coll->action("AboutQuassel"));
603 _helpMenu->addAction(coll->action("AboutQt"));
605 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
607 _helpMenu->addSeparator();
608 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
609 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
610 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
611 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
612 _helpDebugMenu->addAction(coll->action("DebugHotList"));
613 _helpDebugMenu->addAction(coll->action("DebugLog"));
614 _helpDebugMenu->addSeparator();
615 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
618 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
620 QtUiSettings uiSettings;
621 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
622 showMenuBar->setChecked(enabled);
623 enabled ? menuBar()->show() : menuBar()->hide();
625 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
626 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
630 void MainWin::setupBufferWidget()
632 _bufferWidget = new BufferWidget(this);
633 _bufferWidget->setModel(Client::bufferModel());
634 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
635 setCentralWidget(_bufferWidget);
639 void MainWin::addBufferView(int bufferViewConfigId)
641 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
645 void MainWin::addBufferView(ClientBufferViewConfig *config)
650 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
651 BufferViewDock *dock = new BufferViewDock(config, this);
653 //create the view and initialize it's filter
654 BufferView *view = new BufferView(dock);
655 view->setFilteredModel(Client::bufferModel(), config);
656 view->installEventFilter(_inputWidget); // for key presses
658 Client::bufferModel()->synchronizeView(view);
660 dock->setWidget(view);
661 dock->setVisible(_layoutLoaded); // don't show before state has been restored
663 addDockWidget(Qt::LeftDockWidgetArea, dock);
664 _bufferViewsMenu->addAction(dock->toggleViewAction());
666 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
667 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
668 _bufferViews.append(dock);
670 if (!activeBufferView())
675 void MainWin::removeBufferView(int bufferViewConfigId)
678 BufferViewDock *dock;
679 foreach(QAction *action, _bufferViewsMenu->actions()) {
680 actionData = action->data();
681 if (!actionData.isValid())
684 dock = qobject_cast<BufferViewDock *>(action->parent());
685 if (dock && actionData.toInt() == bufferViewConfigId) {
686 removeAction(action);
687 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
688 _bufferViews.removeAll(dock);
690 if (dock->isActive()) {
691 dock->setActive(false);
692 _activeBufferViewIndex = -1;
702 void MainWin::bufferViewToggled(bool enabled)
704 if (!enabled && !isMinimized()) {
705 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
706 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
709 QAction *action = qobject_cast<QAction *>(sender());
711 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
714 // Make sure we don't toggle backlog fetch for a view we've already removed
715 if (!_bufferViews.contains(dock))
719 Client::bufferViewOverlay()->addView(dock->bufferViewId());
721 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
725 void MainWin::bufferViewVisibilityChanged(bool visible)
728 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
730 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
735 BufferView *MainWin::allBuffersView() const
737 // "All Buffers" is always the first dock created
738 if (_bufferViews.count() > 0)
739 return _bufferViews[0]->bufferView();
744 BufferView *MainWin::activeBufferView() const
746 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
748 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
749 return dock->isActive() ? dock->bufferView() : 0;
753 void MainWin::changeActiveBufferView(int bufferViewId)
755 if (bufferViewId < 0)
758 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
759 _bufferViews[_activeBufferViewIndex]->setActive(false);
760 _activeBufferViewIndex = -1;
763 for (int i = 0; i < _bufferViews.count(); i++) {
764 BufferViewDock *dock = _bufferViews.at(i);
765 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
766 _activeBufferViewIndex = i;
767 dock->setActive(true);
772 nextBufferView(); // fallback
776 void MainWin::showPasswordChangeDlg()
778 if(Client::isCoreFeatureEnabled(Quassel::Feature::PasswordChange)) {
779 PasswordChangeDlg dlg(this);
783 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
784 tr("<b>Your Quassel Core does not support this feature</b>"),
785 QMessageBox::Ok, this);
786 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
792 void MainWin::changeActiveBufferView(bool backwards)
794 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
795 _bufferViews[_activeBufferViewIndex]->setActive(false);
798 if (!_bufferViews.count())
801 int c = _bufferViews.count();
802 while (c--) { // yes, this will reactivate the current active one if all others fail
804 if (--_activeBufferViewIndex < 0)
805 _activeBufferViewIndex = _bufferViews.count()-1;
808 if (++_activeBufferViewIndex >= _bufferViews.count())
809 _activeBufferViewIndex = 0;
812 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
813 if (dock->isHidden())
816 dock->setActive(true);
820 _activeBufferViewIndex = -1;
824 void MainWin::nextBufferView()
826 changeActiveBufferView(false);
830 void MainWin::previousBufferView()
832 changeActiveBufferView(true);
836 void MainWin::nextBuffer()
838 BufferView *view = activeBufferView();
844 void MainWin::previousBuffer()
846 BufferView *view = activeBufferView();
848 view->previousBuffer();
852 void MainWin::hideCurrentBuffer()
854 BufferView *view = activeBufferView();
856 view->hideCurrentBuffer();
860 void MainWin::showNotificationsDlg()
862 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
867 void MainWin::on_actionConfigureNetworks_triggered()
869 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
874 void MainWin::on_actionConfigureViews_triggered()
876 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
881 void MainWin::on_actionLockLayout_toggled(bool lock)
883 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
884 foreach(VerticalDock *dock, docks) {
885 dock->showTitle(!lock);
887 if (Client::bufferViewManager()) {
888 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
889 config->setLocked(lock);
892 QtUiSettings().setValue("LockLayout", lock);
896 void MainWin::setupNickWidget()
899 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
900 nickDock->setObjectName("NickDock");
901 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
903 _nickListWidget = new NickListWidget(nickDock);
904 nickDock->setWidget(_nickListWidget);
906 addDockWidget(Qt::RightDockWidgetArea, nickDock);
907 _viewMenu->addAction(nickDock->toggleViewAction());
908 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
910 // See NickListDock::NickListDock();
911 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
913 // attach the NickListWidget to the BufferModel and the default selection
914 _nickListWidget->setModel(Client::bufferModel());
915 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
917 _nickListWidget->setVisible(false);
921 void MainWin::setupChatMonitor()
923 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
924 dock->setObjectName("ChatMonitorDock");
926 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
927 _chatMonitorView = new ChatMonitorView(filter, this);
928 _chatMonitorView->show();
929 dock->setWidget(_chatMonitorView);
932 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
933 _viewMenu->addAction(dock->toggleViewAction());
934 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
938 void MainWin::setupInputWidget()
940 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
941 dock->setObjectName("InputDock");
943 _inputWidget = new InputWidget(dock);
944 dock->setWidget(_inputWidget);
946 addDockWidget(Qt::BottomDockWidgetArea, dock);
948 _viewMenu->addAction(dock->toggleViewAction());
949 dock->toggleViewAction()->setText(tr("Show Input Line"));
951 _inputWidget->setModel(Client::bufferModel());
952 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
954 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
956 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
960 void MainWin::setupTopicWidget()
962 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
963 dock->setObjectName("TopicDock");
964 _topicWidget = new TopicWidget(dock);
966 dock->setWidget(_topicWidget);
968 _topicWidget->setModel(Client::bufferModel());
969 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
971 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
973 _viewMenu->addAction(dock->toggleViewAction());
974 dock->toggleViewAction()->setText(tr("Show Topic Line"));
978 void MainWin::setupTransferWidget()
980 auto dock = new QDockWidget(tr("Transfers"), this);
981 dock->setObjectName("TransferDock");
982 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
984 auto view = new QTableView(dock); // to be replaced by the real thing
985 view->setModel(Client::transferModel());
986 dock->setWidget(view);
987 dock->hide(); // hidden by default
988 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
990 auto action = dock->toggleViewAction();
991 action->setText(tr("Show File Transfers"));
992 action->setIcon(QIcon::fromTheme("download"));
993 action->setShortcut(QKeySequence(Qt::Key_F6));
994 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
995 _viewMenu->addAction(action);
999 void MainWin::setupViewMenuTail()
1001 _viewMenu->addSeparator();
1002 _viewMenu->addAction(_fullScreenAction);
1006 void MainWin::setupTitleSetter()
1008 _titleSetter.setModel(Client::bufferModel());
1009 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1013 void MainWin::setupStatusBar()
1015 // MessageProcessor progress
1016 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1019 _coreConnectionStatusWidget->update();
1020 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1022 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1024 QtUiSettings uiSettings;
1026 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1027 showStatusbar->setChecked(enabled);
1028 enabled ? statusBar()->show() : statusBar()->hide();
1030 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1031 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1033 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1037 void MainWin::setupHotList()
1039 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1040 flatProxy->setSourceModel(Client::bufferModel());
1041 _bufferHotList = new BufferHotListFilter(flatProxy);
1045 void MainWin::saveMenuBarStatus(bool enabled)
1047 QtUiSettings uiSettings;
1048 uiSettings.setValue("ShowMenuBar", enabled);
1052 void MainWin::saveStatusBarStatus(bool enabled)
1054 QtUiSettings uiSettings;
1055 uiSettings.setValue("ShowStatusBar", enabled);
1059 void MainWin::setupSystray()
1062 _systemTray = new StatusNotifierItem(this);
1063 #elif !defined QT_NO_SYSTEMTRAYICON
1064 _systemTray = new LegacySystemTray(this);
1066 _systemTray = new SystemTray(this); // dummy
1068 _systemTray->init();
1072 void MainWin::setupToolBars()
1074 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1075 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1076 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1077 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1080 setUnifiedTitleAndToolBarOnMac(true);
1084 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1086 _mainToolBar = new QToolBar(this);
1087 _mainToolBar->setObjectName("MainToolBar");
1089 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1090 addToolBar(_mainToolBar);
1092 if (Quassel::runMode() != Quassel::Monolithic) {
1093 ActionCollection *coll = QtUi::actionCollection("General");
1094 _mainToolBar->addAction(coll->action("ConnectCore"));
1095 _mainToolBar->addAction(coll->action("DisconnectCore"));
1098 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1099 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1102 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1104 _nickToolBar = new QToolBar(this);
1105 _nickToolBar->setObjectName("NickToolBar");
1107 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1108 _nickToolBar->setVisible(false); //default: not visible
1109 addToolBar(_nickToolBar);
1111 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1112 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1115 QtUiSettings uiSettings;
1117 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1118 _mainToolBar->setVisible(visible);
1119 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1123 void MainWin::saveMainToolBarStatus(bool enabled)
1126 QtUiSettings uiSettings;
1127 uiSettings.setValue("ShowMainToolBar", enabled);
1134 void MainWin::connectedToCore()
1136 Q_CHECK_PTR(Client::bufferViewManager());
1137 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1138 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1139 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1141 if (Client::transferManager()) {
1142 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1145 setConnectedState();
1149 void MainWin::setConnectedState()
1151 ActionCollection *coll = QtUi::actionCollection("General");
1153 coll->action("ConnectCore")->setEnabled(false);
1154 coll->action("DisconnectCore")->setEnabled(true);
1155 coll->action("ChangePassword")->setEnabled(true);
1156 coll->action("CoreInfo")->setEnabled(true);
1158 foreach(QAction *action, _fileMenu->actions()) {
1159 if (isRemoteCoreOnly(action))
1160 action->setVisible(!Client::internalCore());
1163 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1164 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1165 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1166 if (!Client::internalCore()) {
1167 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1168 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1169 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1172 // _viewMenu->setEnabled(true);
1173 if (!Client::internalCore())
1174 statusBar()->showMessage(tr("Connected to core."));
1176 statusBar()->clearMessage();
1178 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1180 systemTray()->setState(SystemTray::Active);
1182 if (Client::networkIds().isEmpty()) {
1183 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1187 // Monolithic always preselects last used buffer - Client only if the connection died
1188 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1190 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1191 if (lastUsedBufferId.isValid())
1192 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1198 void MainWin::loadLayout()
1201 int accountId = Client::currentCoreAccount().accountId().toInt();
1202 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1203 if (state.isEmpty()) {
1204 foreach(BufferViewDock *view, _bufferViews)
1206 _layoutLoaded = true;
1209 _nickListWidget->setVisible(true);
1210 restoreState(state, accountId);
1211 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1212 if (bufferViewId >= 0)
1213 changeActiveBufferView(bufferViewId);
1215 _layoutLoaded = true;
1219 void MainWin::saveLayout()
1222 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1223 if (accountId > 0) {
1224 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1225 BufferView *view = activeBufferView();
1226 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1231 void MainWin::disconnectedFromCore()
1233 // save core specific layout and remove bufferviews;
1235 _layoutLoaded = false;
1237 QVariant actionData;
1238 BufferViewDock *dock;
1239 foreach(QAction *action, _bufferViewsMenu->actions()) {
1240 actionData = action->data();
1241 if (!actionData.isValid())
1244 dock = qobject_cast<BufferViewDock *>(action->parent());
1245 if (dock && actionData.toInt() != -1) {
1246 removeAction(action);
1247 _bufferViews.removeAll(dock);
1248 dock->deleteLater();
1252 // store last active buffer
1254 BufferId lastBufId = _bufferWidget->currentBuffer();
1255 if (lastBufId.isValid()) {
1256 s.setValue("LastUsedBufferId", lastBufId.toInt());
1257 // clear the current selection
1258 Client::bufferModel()->standardSelectionModel()->clearSelection();
1260 restoreState(s.value("MainWinState").toByteArray());
1261 setDisconnectedState();
1265 void MainWin::setDisconnectedState()
1267 ActionCollection *coll = QtUi::actionCollection("General");
1268 //ui.menuCore->setEnabled(false);
1269 coll->action("ConnectCore")->setEnabled(true);
1270 coll->action("DisconnectCore")->setEnabled(false);
1271 coll->action("CoreInfo")->setEnabled(false);
1272 coll->action("ChangePassword")->setEnabled(false);
1273 //_viewMenu->setEnabled(false);
1274 statusBar()->showMessage(tr("Not connected to core."));
1275 if (_msgProcessorStatusWidget)
1276 _msgProcessorStatusWidget->setProgress(0, 0);
1278 systemTray()->setState(SystemTray::Passive);
1279 _nickListWidget->setVisible(false);
1283 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1285 Q_UNUSED(errorMessage)
1286 CoreConnectAuthDlg dlg(account, this);
1287 *valid = (dlg.exec() == QDialog::Accepted);
1291 void MainWin::handleNoSslInClient(bool *accepted)
1293 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1294 QMessageBox::Ignore|QMessageBox::Cancel, this);
1295 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1296 box.setDefaultButton(QMessageBox::Ignore);
1297 *accepted = box.exec() == QMessageBox::Ignore;
1301 void MainWin::handleNoSslInCore(bool *accepted)
1303 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1304 QMessageBox::Ignore|QMessageBox::Cancel, this);
1305 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1306 box.setDefaultButton(QMessageBox::Ignore);
1307 *accepted = box.exec() == QMessageBox::Ignore;
1313 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1315 QString errorString = "<ul>";
1316 foreach(const QSslError error, socket->sslErrors())
1317 errorString += QString("<li>%1</li>").arg(error.errorString());
1318 errorString += "</ul>";
1320 QMessageBox box(QMessageBox::Warning,
1321 tr("Untrusted Security Certificate"),
1322 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1323 QMessageBox::Cancel, this);
1324 box.setInformativeText(errorString);
1325 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1326 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1328 QMessageBox::ButtonRole role;
1331 role = box.buttonRole(box.clickedButton());
1332 if (role == QMessageBox::HelpRole) {
1333 SslInfoDlg dlg(socket, this);
1337 while (role == QMessageBox::HelpRole);
1339 *accepted = role == QMessageBox::AcceptRole;
1341 QMessageBox box2(QMessageBox::Warning,
1342 tr("Untrusted Security Certificate"),
1343 tr("Would you like to accept this certificate forever without being prompted?"),
1345 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1346 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1348 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1353 #endif /* HAVE_SSL */
1355 void MainWin::handleCoreConnectionError(const QString &error)
1357 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1361 void MainWin::showCoreConnectionDlg()
1363 CoreConnectDlg dlg(this);
1364 if (dlg.exec() == QDialog::Accepted) {
1365 AccountId accId = dlg.selectedAccount();
1366 if (accId.isValid())
1367 Client::coreConnection()->connectToCore(accId);
1372 void MainWin::showCoreConfigWizard(const QVariantList &backends, const QVariantList &authenticators)
1374 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, authenticators, this);
1380 void MainWin::showChannelList(NetworkId netId)
1382 ChannelListDlg *channelListDlg = new ChannelListDlg();
1384 if (!netId.isValid()) {
1385 QAction *action = qobject_cast<QAction *>(sender());
1387 netId = action->data().value<NetworkId>();
1390 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1391 channelListDlg->setNetwork(netId);
1392 channelListDlg->show();
1396 void MainWin::showIgnoreList(QString newRule)
1398 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1399 // prepare config dialog for new rule
1400 if (!newRule.isEmpty())
1401 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1406 void MainWin::showCoreInfoDlg()
1408 CoreInfoDlg(this).exec();
1412 void MainWin::showAwayLog()
1416 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1417 _awayLog = new AwayLogView(filter, 0);
1418 filter->setParent(_awayLog);
1419 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1420 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1425 void MainWin::awayLogDestroyed()
1431 void MainWin::showSettingsDlg()
1433 SettingsDlg *dlg = new SettingsDlg();
1435 //Category: Interface
1436 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1437 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1438 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1439 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1440 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1441 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1442 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1443 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1445 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1447 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1448 dlg->registerSettingsPage(new CoreHighlightSettingsPage(dlg));
1449 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1450 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1453 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1454 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1455 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1456 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1457 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1458 // dlg->registerSettingsPage(new DccSettingsPage(dlg)); not ready yet
1460 // Category: Remote Cores
1461 if (Quassel::runMode() != Quassel::Monolithic) {
1462 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1463 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1470 void MainWin::showAboutDlg()
1472 AboutDlg(this).exec();
1476 void MainWin::showShortcutsDlg()
1479 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1480 foreach(KActionCollection *coll, QtUi::actionCollections())
1481 dlg.addCollection(coll, coll->property("Category").toString());
1482 dlg.configure(true);
1484 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1490 void MainWin::showNewTransferDlg(const QUuid &transferId)
1492 auto transfer = Client::transferManager()->transfer(transferId);
1494 if (transfer->status() == Transfer::Status::New) {
1495 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1500 qWarning() << "Unknown transfer ID" << transferId;
1505 void MainWin::onFullScreenToggled()
1507 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1508 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1511 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1513 if (_fullScreenAction->isChecked())
1514 setWindowState(windowState() | Qt::WindowFullScreen);
1516 setWindowState(windowState() & ~Qt::WindowFullScreen);
1521 /********************************************************************************************************/
1523 bool MainWin::event(QEvent *event)
1525 switch(event->type()) {
1526 case QEvent::WindowActivate: {
1527 BufferId bufferId = Client::bufferModel()->currentBuffer();
1528 if (bufferId.isValid())
1529 Client::instance()->markBufferAsRead(bufferId);
1532 case QEvent::WindowDeactivate:
1533 if (bufferWidget()->autoMarkerLineOnLostFocus())
1534 bufferWidget()->setMarkerLine();
1539 return QMainWindow::event(event);
1543 void MainWin::moveEvent(QMoveEvent *event)
1545 if (!(windowState() & Qt::WindowMaximized))
1546 _normalPos = event->pos();
1548 QMainWindow::moveEvent(event);
1552 void MainWin::resizeEvent(QResizeEvent *event)
1554 if (!(windowState() & Qt::WindowMaximized))
1555 _normalSize = event->size();
1557 QMainWindow::resizeEvent(event);
1561 void MainWin::closeEvent(QCloseEvent *event)
1564 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1566 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1567 // This messes up MainWinState/MainWinHidden save/restore.
1568 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1569 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1570 QtUi::hideMainWidget();
1573 else if(!_aboutToQuit) {
1574 _aboutToQuit = true;
1584 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1588 bool hasFocus = QApplication::activeWindow() != 0;
1590 for (int i = start; i <= end; i++) {
1591 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1592 if (!idx.isValid()) {
1593 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1596 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1597 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1600 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1601 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1603 // check if bufferId belongs to the shown chatlists
1604 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1605 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1608 // check if it's the buffer currently displayed
1609 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1612 // only show notifications for higlights or queries
1613 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1616 // and of course: don't notify for ignored messages
1617 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1620 // seems like we have a legit notification candidate!
1621 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1622 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1623 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1624 AbstractNotificationBackend::NotificationType type;
1626 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1627 type = AbstractNotificationBackend::PrivMsg;
1628 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1629 type = AbstractNotificationBackend::PrivMsgFocused;
1630 else if (flags & Message::Highlight && !hasFocus)
1631 type = AbstractNotificationBackend::Highlight;
1633 type = AbstractNotificationBackend::HighlightFocused;
1635 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1640 void MainWin::currentBufferChanged(BufferId buffer)
1642 if (buffer.isValid())
1643 Client::instance()->markBufferAsRead(buffer);
1647 void MainWin::clientNetworkCreated(NetworkId id)
1649 const Network *net = Client::network(id);
1650 QAction *act = new QAction(net->networkName(), this);
1651 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1652 act->setData(QVariant::fromValue<NetworkId>(id));
1653 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1654 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1656 QAction *beforeAction = 0;
1657 foreach(QAction *action, _networksMenu->actions()) {
1658 if (!action->data().isValid()) // ignore stock actions
1660 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1661 beforeAction = action;
1665 _networksMenu->insertAction(beforeAction, act);
1669 void MainWin::clientNetworkUpdated()
1671 const Network *net = qobject_cast<const Network *>(sender());
1675 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1679 action->setText(net->networkName());
1681 switch (net->connectionState()) {
1682 case Network::Initialized:
1683 action->setIcon(QIcon::fromTheme("network-connect"));
1684 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1685 if (!bufferWidget()->currentBuffer().isValid()) {
1686 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1687 if (idx.isValid()) {
1688 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1689 Client::bufferModel()->switchToBuffer(statusBufferId);
1693 case Network::Disconnected:
1694 action->setIcon(QIcon::fromTheme("network-disconnect"));
1697 action->setIcon(QIcon::fromTheme("network-wired"));
1702 void MainWin::clientNetworkRemoved(NetworkId id)
1704 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1708 action->deleteLater();
1712 void MainWin::connectOrDisconnectFromNet()
1714 QAction *act = qobject_cast<QAction *>(sender());
1716 const Network *net = Client::network(act->data().value<NetworkId>());
1718 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1719 else net->requestDisconnect();
1723 void MainWin::on_jumpHotBuffer_triggered()
1725 if (!_bufferHotList->rowCount())
1728 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1731 void MainWin::on_bufferSearch_triggered()
1733 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1734 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1738 _bufferViews[_activeBufferViewIndex]->activateFilter();
1742 void MainWin::onJumpKey()
1744 QAction *action = qobject_cast<QAction *>(sender());
1745 if (!action || !Client::bufferModel())
1747 int idx = action->property("Index").toInt();
1749 if (_jumpKeyMap.isEmpty())
1750 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1752 if (!_jumpKeyMap.contains(idx))
1755 BufferId buffer = _jumpKeyMap.value(idx);
1756 if (buffer.isValid())
1757 Client::bufferModel()->switchToBuffer(buffer);
1761 void MainWin::bindJumpKey()
1763 QAction *action = qobject_cast<QAction *>(sender());
1764 if (!action || !Client::bufferModel())
1766 int idx = action->property("Index").toInt();
1768 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1769 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1773 void MainWin::on_actionDebugNetworkModel_triggered()
1775 QTreeView *view = new QTreeView;
1776 view->setAttribute(Qt::WA_DeleteOnClose);
1777 view->setWindowTitle("Debug NetworkModel View");
1778 view->setModel(Client::networkModel());
1779 view->setColumnWidth(0, 250);
1780 view->setColumnWidth(1, 250);
1781 view->setColumnWidth(2, 80);
1782 view->resize(610, 300);
1787 void MainWin::on_actionDebugHotList_triggered()
1789 _bufferHotList->invalidate();
1790 _bufferHotList->sort(0, Qt::DescendingOrder);
1792 QTreeView *view = new QTreeView;
1793 view->setAttribute(Qt::WA_DeleteOnClose);
1794 view->setModel(_bufferHotList);
1799 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1801 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1802 overlay->setAttribute(Qt::WA_DeleteOnClose);
1807 void MainWin::on_actionDebugMessageModel_triggered()
1809 QTableView *view = new QTableView(0);
1810 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1811 filter->setSourceModel(Client::messageModel());
1812 view->setModel(filter);
1813 view->setAttribute(Qt::WA_DeleteOnClose, true);
1814 view->verticalHeader()->hide();
1815 view->horizontalHeader()->setStretchLastSection(true);
1820 void MainWin::on_actionDebugLog_triggered()
1822 DebugLogWidget *logWidget = new DebugLogWidget(0);
1827 void MainWin::showStatusBarMessage(const QString &message)
1829 statusBar()->showMessage(message, 10000);