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/dccsettingspage.h"
150 #include "settingspages/highlightsettingspage.h"
151 #include "settingspages/identitiessettingspage.h"
152 #include "settingspages/ignorelistsettingspage.h"
153 #include "settingspages/inputwidgetsettingspage.h"
154 #include "settingspages/itemviewsettingspage.h"
155 #include "settingspages/networkssettingspage.h"
156 #include "settingspages/notificationssettingspage.h"
157 #include "settingspages/topicwidgetsettingspage.h"
160 # include "settingspages/shortcutssettingspage.h"
164 # include "settingspages/sonnetsettingspage.h"
168 MainWin::MainWin(QWidget *parent)
170 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
172 : QMainWindow(parent),
174 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
175 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
178 _layoutLoaded(false),
179 _activeBufferViewIndex(-1),
182 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
184 QtUiSettings uiSettings;
185 QString style = uiSettings.value("Style", QString()).toString();
186 if (!style.isEmpty()) {
187 QApplication::setStyle(style);
190 QApplication::setQuitOnLastWindowClosed(false);
192 setWindowTitle("Quassel IRC");
193 setWindowIconText("Quassel IRC");
200 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
201 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
202 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
203 SLOT(messagesInserted(const QModelIndex &, int, int)));
204 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
205 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
207 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
208 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
209 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
210 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
211 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
213 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
217 setDockNestingEnabled(true);
218 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
219 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
220 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
221 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
223 // Order is sometimes important
227 setupTransferWidget();
239 _bufferWidget->setFocusProxy(_inputWidget);
240 _chatMonitorView->setFocusProxy(_inputWidget);
243 # ifdef HAVE_QTMULTIMEDIA
244 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
247 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
249 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
251 QtUi::registerNotificationBackend(new KNotificationBackend(this));
252 #endif /* HAVE_KDE */
256 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
257 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
258 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
261 #ifdef HAVE_INDICATEQT
262 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
265 #ifdef HAVE_NOTIFICATION_CENTER
266 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
270 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
273 // we assume that at this point, all configurable actions are defined!
274 QtUi::loadShortcuts();
276 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
278 setDisconnectedState(); // Disable menus and stuff
281 setAutoSaveSettings();
284 // restore mainwin state
286 restoreStateFromSettings(s);
288 // restore locked state of docks
289 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
291 CoreConnection *conn = Client::coreConnection();
292 if (!conn->connectToCore()) {
293 // No autoconnect selected (or no accounts)
294 showCoreConnectionDlg();
307 saveStateToSettings(s);
309 QApplication::quit();
313 void MainWin::saveStateToSettings(UiSettings &s)
315 s.setValue("MainWinSize", _normalSize);
316 s.setValue("MainWinPos", _normalPos);
317 s.setValue("MainWinState", saveState());
318 s.setValue("MainWinGeometry", saveGeometry());
319 s.setValue("MainWinMinimized", isMinimized());
320 s.setValue("MainWinMaximized", isMaximized());
321 s.setValue("MainWinHidden", !isVisible());
322 BufferId lastBufId = Client::bufferModel()->currentBuffer();
323 if (lastBufId.isValid())
324 s.setValue("LastUsedBufferId", lastBufId.toInt());
327 saveAutoSaveSettings();
332 void MainWin::restoreStateFromSettings(UiSettings &s)
334 _normalSize = s.value("MainWinSize", size()).toSize();
335 _normalPos = s.value("MainWinPos", pos()).toPoint();
336 bool maximized = s.value("MainWinMaximized", false).toBool();
339 restoreGeometry(s.value("MainWinGeometry").toByteArray());
342 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
347 restoreState(s.value("MainWinState").toByteArray());
353 if ((Quassel::isOptionSet("hidewindow")
354 || s.value("MainWinHidden").toBool())
355 && _systemTray->isSystemTrayAvailable())
356 QtUi::hideMainWidget();
357 else if (s.value("MainWinMinimized").toBool())
365 QMenu *MainWin::createPopupMenu()
367 QMenu *popupMenu = QMainWindow::createPopupMenu();
368 popupMenu->addSeparator();
369 ActionCollection *coll = QtUi::actionCollection("General");
370 popupMenu->addAction(coll->action("ToggleMenuBar"));
375 void MainWin::updateIcon()
378 if (Client::isConnected())
379 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
381 icon = QIcon::fromTheme("quassel-inactive", QIcon(":/icons/quassel-128.png"));
383 qApp->setWindowIcon(icon);
387 void MainWin::setupActions()
389 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
391 coll->addAction("ConnectCore", new Action(QIcon(":/icons/quassel-128.png"), tr("&Connect to Core..."), coll,
392 this, SLOT(showCoreConnectionDlg())));
393 coll->addAction("DisconnectCore", new Action(QIcon(":/icons/quassel-disconnect.png"), tr("&Disconnect from Core"), coll,
394 Client::instance(), SLOT(disconnectFromCore())));
395 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
396 this, SLOT(showPasswordChangeDlg())));
397 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
398 this, SLOT(showCoreInfoDlg())));
399 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
400 this, SLOT(on_actionConfigureNetworks_triggered())));
401 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
402 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
403 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
406 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
407 this, SLOT(on_actionConfigureViews_triggered())));
409 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
410 lockAct->setCheckable(true);
411 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
413 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
414 0, 0, QKeySequence::Find))->setCheckable(true);
415 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
416 this, SLOT(showAwayLog())));
417 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
418 0, 0))->setCheckable(true);
420 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
421 0, 0))->setCheckable(true);
424 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
426 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
427 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
428 _fullScreenAction->setCheckable(true);
429 coll->addAction("ToggleFullScreen", _fullScreenAction);
433 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
434 this, SLOT(showShortcutsDlg()));
435 configureShortcutsAct->setMenuRole(QAction::NoRole);
436 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
439 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
440 this, SLOT(showSettingsDlg()));
441 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
443 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
444 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
446 coll->addAction("ConfigureQuassel", configureQuasselAct);
449 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
450 this, SLOT(showAboutDlg()));
451 aboutQuasselAct->setMenuRole(QAction::AboutRole);
452 coll->addAction("AboutQuassel", aboutQuasselAct);
454 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
455 qApp, SLOT(aboutQt()));
456 aboutQtAct->setMenuRole(QAction::AboutQtRole);
457 coll->addAction("AboutQt", aboutQtAct);
458 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
459 this, SLOT(on_actionDebugNetworkModel_triggered())));
460 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
461 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
462 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
463 this, SLOT(on_actionDebugMessageModel_triggered())));
464 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
465 this, SLOT(on_actionDebugHotList_triggered())));
466 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
467 this, SLOT(on_actionDebugLog_triggered())));
468 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
469 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
471 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
472 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
475 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
477 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
478 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
480 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
481 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
485 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
486 const int jumpModifier = Qt::ControlModifier;
488 const int bindModifier = Qt::ControlModifier;
489 const int jumpModifier = Qt::AltModifier;
492 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
493 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
494 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
495 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
496 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
497 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
498 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
499 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
500 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
501 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
502 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
503 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
504 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
505 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
506 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
507 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
508 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
509 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
510 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
511 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
513 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
514 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
515 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
516 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
517 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
518 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
519 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
520 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
521 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
522 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
523 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
524 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
525 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
526 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
527 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
528 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
529 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
530 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
531 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
532 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
535 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
536 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
537 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
538 this, SLOT(previousBufferView()), QKeySequence::Back));
539 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
540 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
541 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
542 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
546 void MainWin::setupMenus()
548 ActionCollection *coll = QtUi::actionCollection("General");
550 _fileMenu = menuBar()->addMenu(tr("&File"));
552 static const QStringList coreActions = QStringList()
553 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
556 foreach(QString actionName, coreActions) {
557 coreAction = coll->action(actionName);
558 _fileMenu->addAction(coreAction);
559 flagRemoteCoreOnly(coreAction);
561 flagRemoteCoreOnly(_fileMenu->addSeparator());
563 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
564 _networksMenu->addAction(coll->action("ConfigureNetworks"));
565 _networksMenu->addSeparator();
566 _fileMenu->addSeparator();
567 _fileMenu->addAction(coll->action("Quit"));
569 _viewMenu = menuBar()->addMenu(tr("&View"));
570 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
571 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
572 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
573 _viewMenu->addSeparator();
575 _viewMenu->addAction(coll->action("ToggleMenuBar"));
576 _viewMenu->addAction(coll->action("ToggleStatusBar"));
577 _viewMenu->addAction(coll->action("ToggleSearchBar"));
579 coreAction = coll->action("ShowAwayLog");
580 flagRemoteCoreOnly(coreAction);
581 _viewMenu->addAction(coreAction);
583 _viewMenu->addSeparator();
584 _viewMenu->addAction(coll->action("LockLayout"));
586 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
588 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
589 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
591 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
593 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
596 _helpMenu = menuBar()->addMenu(tr("&Help"));
598 _helpMenu->addAction(coll->action("AboutQuassel"));
600 _helpMenu->addAction(coll->action("AboutQt"));
602 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
604 _helpMenu->addSeparator();
605 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
606 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
607 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
608 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
609 _helpDebugMenu->addAction(coll->action("DebugHotList"));
610 _helpDebugMenu->addAction(coll->action("DebugLog"));
611 _helpDebugMenu->addSeparator();
612 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
615 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
617 QtUiSettings uiSettings;
618 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
619 showMenuBar->setChecked(enabled);
620 enabled ? menuBar()->show() : menuBar()->hide();
622 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
623 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
627 void MainWin::setupBufferWidget()
629 _bufferWidget = new BufferWidget(this);
630 _bufferWidget->setModel(Client::bufferModel());
631 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
632 setCentralWidget(_bufferWidget);
636 void MainWin::addBufferView(int bufferViewConfigId)
638 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
642 void MainWin::addBufferView(ClientBufferViewConfig *config)
647 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
648 BufferViewDock *dock = new BufferViewDock(config, this);
650 //create the view and initialize it's filter
651 BufferView *view = new BufferView(dock);
652 view->setFilteredModel(Client::bufferModel(), config);
653 view->installEventFilter(_inputWidget); // for key presses
655 Client::bufferModel()->synchronizeView(view);
657 dock->setWidget(view);
658 dock->setVisible(_layoutLoaded); // don't show before state has been restored
660 addDockWidget(Qt::LeftDockWidgetArea, dock);
661 _bufferViewsMenu->addAction(dock->toggleViewAction());
663 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
664 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
665 _bufferViews.append(dock);
667 if (!activeBufferView())
672 void MainWin::removeBufferView(int bufferViewConfigId)
675 BufferViewDock *dock;
676 foreach(QAction *action, _bufferViewsMenu->actions()) {
677 actionData = action->data();
678 if (!actionData.isValid())
681 dock = qobject_cast<BufferViewDock *>(action->parent());
682 if (dock && actionData.toInt() == bufferViewConfigId) {
683 removeAction(action);
684 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
685 _bufferViews.removeAll(dock);
687 if (dock->isActive()) {
688 dock->setActive(false);
689 _activeBufferViewIndex = -1;
699 void MainWin::bufferViewToggled(bool enabled)
701 if (!enabled && !isMinimized()) {
702 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
703 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
706 QAction *action = qobject_cast<QAction *>(sender());
708 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
711 // Make sure we don't toggle backlog fetch for a view we've already removed
712 if (!_bufferViews.contains(dock))
716 Client::bufferViewOverlay()->addView(dock->bufferViewId());
718 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
722 void MainWin::bufferViewVisibilityChanged(bool visible)
725 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
727 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
732 BufferView *MainWin::allBuffersView() const
734 // "All Buffers" is always the first dock created
735 if (_bufferViews.count() > 0)
736 return _bufferViews[0]->bufferView();
741 BufferView *MainWin::activeBufferView() const
743 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
745 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
746 return dock->isActive() ? dock->bufferView() : 0;
750 void MainWin::changeActiveBufferView(int bufferViewId)
752 if (bufferViewId < 0)
755 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
756 _bufferViews[_activeBufferViewIndex]->setActive(false);
757 _activeBufferViewIndex = -1;
760 for (int i = 0; i < _bufferViews.count(); i++) {
761 BufferViewDock *dock = _bufferViews.at(i);
762 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
763 _activeBufferViewIndex = i;
764 dock->setActive(true);
769 nextBufferView(); // fallback
773 void MainWin::showPasswordChangeDlg()
775 if((Client::coreFeatures() & Quassel::PasswordChange)) {
776 PasswordChangeDlg dlg(this);
780 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
781 tr("<b>Your Quassel Core does not support this feature</b>"),
782 QMessageBox::Ok, this);
783 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
789 void MainWin::changeActiveBufferView(bool backwards)
791 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
792 _bufferViews[_activeBufferViewIndex]->setActive(false);
795 if (!_bufferViews.count())
798 int c = _bufferViews.count();
799 while (c--) { // yes, this will reactivate the current active one if all others fail
801 if (--_activeBufferViewIndex < 0)
802 _activeBufferViewIndex = _bufferViews.count()-1;
805 if (++_activeBufferViewIndex >= _bufferViews.count())
806 _activeBufferViewIndex = 0;
809 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
810 if (dock->isHidden())
813 dock->setActive(true);
817 _activeBufferViewIndex = -1;
821 void MainWin::nextBufferView()
823 changeActiveBufferView(false);
827 void MainWin::previousBufferView()
829 changeActiveBufferView(true);
833 void MainWin::nextBuffer()
835 BufferView *view = activeBufferView();
841 void MainWin::previousBuffer()
843 BufferView *view = activeBufferView();
845 view->previousBuffer();
849 void MainWin::hideCurrentBuffer()
851 BufferView *view = activeBufferView();
853 view->hideCurrentBuffer();
857 void MainWin::showNotificationsDlg()
859 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
864 void MainWin::on_actionConfigureNetworks_triggered()
866 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
871 void MainWin::on_actionConfigureViews_triggered()
873 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
878 void MainWin::on_actionLockLayout_toggled(bool lock)
880 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
881 foreach(VerticalDock *dock, docks) {
882 dock->showTitle(!lock);
884 if (Client::bufferViewManager()) {
885 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
886 config->setLocked(lock);
889 QtUiSettings().setValue("LockLayout", lock);
893 void MainWin::setupNickWidget()
896 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
897 nickDock->setObjectName("NickDock");
898 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
900 _nickListWidget = new NickListWidget(nickDock);
901 nickDock->setWidget(_nickListWidget);
903 addDockWidget(Qt::RightDockWidgetArea, nickDock);
904 _viewMenu->addAction(nickDock->toggleViewAction());
905 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
907 // See NickListDock::NickListDock();
908 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
910 // attach the NickListWidget to the BufferModel and the default selection
911 _nickListWidget->setModel(Client::bufferModel());
912 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
914 _nickListWidget->setVisible(false);
918 void MainWin::setupChatMonitor()
920 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
921 dock->setObjectName("ChatMonitorDock");
923 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
924 _chatMonitorView = new ChatMonitorView(filter, this);
925 _chatMonitorView->show();
926 dock->setWidget(_chatMonitorView);
929 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
930 _viewMenu->addAction(dock->toggleViewAction());
931 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
935 void MainWin::setupInputWidget()
937 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
938 dock->setObjectName("InputDock");
940 _inputWidget = new InputWidget(dock);
941 dock->setWidget(_inputWidget);
943 addDockWidget(Qt::BottomDockWidgetArea, dock);
945 _viewMenu->addAction(dock->toggleViewAction());
946 dock->toggleViewAction()->setText(tr("Show Input Line"));
948 _inputWidget->setModel(Client::bufferModel());
949 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
951 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
953 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
957 void MainWin::setupTopicWidget()
959 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
960 dock->setObjectName("TopicDock");
961 _topicWidget = new TopicWidget(dock);
963 dock->setWidget(_topicWidget);
965 _topicWidget->setModel(Client::bufferModel());
966 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
968 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
970 _viewMenu->addAction(dock->toggleViewAction());
971 dock->toggleViewAction()->setText(tr("Show Topic Line"));
975 void MainWin::setupTransferWidget()
977 auto dock = new QDockWidget(tr("Transfers"), this);
978 dock->setObjectName("TransferDock");
979 dock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea);
981 auto view = new QTableView(dock); // to be replaced by the real thing
982 view->setModel(Client::transferModel());
983 dock->setWidget(view);
984 dock->hide(); // hidden by default
985 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
987 auto action = dock->toggleViewAction();
988 action->setText(tr("Show File Transfers"));
989 action->setIcon(QIcon::fromTheme("download"));
990 action->setShortcut(QKeySequence(Qt::Key_F6));
991 QtUi::actionCollection("General")->addAction("ShowTransferWidget", action);
992 _viewMenu->addAction(action);
996 void MainWin::setupViewMenuTail()
998 _viewMenu->addSeparator();
999 _viewMenu->addAction(_fullScreenAction);
1003 void MainWin::setupTitleSetter()
1005 _titleSetter.setModel(Client::bufferModel());
1006 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
1010 void MainWin::setupStatusBar()
1012 // MessageProcessor progress
1013 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
1016 _coreConnectionStatusWidget->update();
1017 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
1019 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
1021 QtUiSettings uiSettings;
1023 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
1024 showStatusbar->setChecked(enabled);
1025 enabled ? statusBar()->show() : statusBar()->hide();
1027 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1028 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1030 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1034 void MainWin::setupHotList()
1036 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1037 flatProxy->setSourceModel(Client::bufferModel());
1038 _bufferHotList = new BufferHotListFilter(flatProxy);
1042 void MainWin::saveMenuBarStatus(bool enabled)
1044 QtUiSettings uiSettings;
1045 uiSettings.setValue("ShowMenuBar", enabled);
1049 void MainWin::saveStatusBarStatus(bool enabled)
1051 QtUiSettings uiSettings;
1052 uiSettings.setValue("ShowStatusBar", enabled);
1056 void MainWin::setupSystray()
1059 _systemTray = new StatusNotifierItem(this);
1060 #elif !defined QT_NO_SYSTEMTRAYICON
1061 _systemTray = new LegacySystemTray(this);
1063 _systemTray = new SystemTray(this); // dummy
1065 _systemTray->init();
1069 void MainWin::setupToolBars()
1071 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1072 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1073 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1074 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1077 setUnifiedTitleAndToolBarOnMac(true);
1081 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1083 _mainToolBar = new QToolBar(this);
1084 _mainToolBar->setObjectName("MainToolBar");
1086 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1087 addToolBar(_mainToolBar);
1089 if (Quassel::runMode() != Quassel::Monolithic) {
1090 ActionCollection *coll = QtUi::actionCollection("General");
1091 _mainToolBar->addAction(coll->action("ConnectCore"));
1092 _mainToolBar->addAction(coll->action("DisconnectCore"));
1095 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1096 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1099 _nickToolBar = new KToolBar("NickToolBar", this, Qt::TopToolBarArea, false, true, true);
1101 _nickToolBar = new QToolBar(this);
1102 _nickToolBar->setObjectName("NickToolBar");
1104 _nickToolBar->setWindowTitle(tr("Nick Toolbar"));
1105 _nickToolBar->setVisible(false); //default: not visible
1106 addToolBar(_nickToolBar);
1108 QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
1109 _toolbarMenu->addAction(_nickToolBar->toggleViewAction());
1112 QtUiSettings uiSettings;
1114 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1115 _mainToolBar->setVisible(visible);
1116 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1120 void MainWin::saveMainToolBarStatus(bool enabled)
1123 QtUiSettings uiSettings;
1124 uiSettings.setValue("ShowMainToolBar", enabled);
1131 void MainWin::connectedToCore()
1133 Q_CHECK_PTR(Client::bufferViewManager());
1134 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1135 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1136 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1138 if (Client::transferManager()) {
1139 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1142 setConnectedState();
1146 void MainWin::setConnectedState()
1148 ActionCollection *coll = QtUi::actionCollection("General");
1150 coll->action("ConnectCore")->setEnabled(false);
1151 coll->action("DisconnectCore")->setEnabled(true);
1152 coll->action("ChangePassword")->setEnabled(true);
1153 coll->action("CoreInfo")->setEnabled(true);
1155 foreach(QAction *action, _fileMenu->actions()) {
1156 if (isRemoteCoreOnly(action))
1157 action->setVisible(!Client::internalCore());
1160 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1161 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1162 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1163 if (!Client::internalCore()) {
1164 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1165 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1166 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1169 // _viewMenu->setEnabled(true);
1170 if (!Client::internalCore())
1171 statusBar()->showMessage(tr("Connected to core."));
1173 statusBar()->clearMessage();
1175 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1177 systemTray()->setState(SystemTray::Active);
1179 if (Client::networkIds().isEmpty()) {
1180 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1184 // Monolithic always preselects last used buffer - Client only if the connection died
1185 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1187 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1188 if (lastUsedBufferId.isValid())
1189 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1195 void MainWin::loadLayout()
1198 int accountId = Client::currentCoreAccount().accountId().toInt();
1199 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1200 if (state.isEmpty()) {
1201 foreach(BufferViewDock *view, _bufferViews)
1203 _layoutLoaded = true;
1206 _nickListWidget->setVisible(true);
1207 restoreState(state, accountId);
1208 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1209 if (bufferViewId >= 0)
1210 changeActiveBufferView(bufferViewId);
1212 _layoutLoaded = true;
1216 void MainWin::saveLayout()
1219 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1220 if (accountId > 0) {
1221 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1222 BufferView *view = activeBufferView();
1223 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1228 void MainWin::disconnectedFromCore()
1230 // save core specific layout and remove bufferviews;
1232 _layoutLoaded = false;
1234 QVariant actionData;
1235 BufferViewDock *dock;
1236 foreach(QAction *action, _bufferViewsMenu->actions()) {
1237 actionData = action->data();
1238 if (!actionData.isValid())
1241 dock = qobject_cast<BufferViewDock *>(action->parent());
1242 if (dock && actionData.toInt() != -1) {
1243 removeAction(action);
1244 _bufferViews.removeAll(dock);
1245 dock->deleteLater();
1249 // store last active buffer
1251 BufferId lastBufId = _bufferWidget->currentBuffer();
1252 if (lastBufId.isValid()) {
1253 s.setValue("LastUsedBufferId", lastBufId.toInt());
1254 // clear the current selection
1255 Client::bufferModel()->standardSelectionModel()->clearSelection();
1257 restoreState(s.value("MainWinState").toByteArray());
1258 setDisconnectedState();
1262 void MainWin::setDisconnectedState()
1264 ActionCollection *coll = QtUi::actionCollection("General");
1265 //ui.menuCore->setEnabled(false);
1266 coll->action("ConnectCore")->setEnabled(true);
1267 coll->action("DisconnectCore")->setEnabled(false);
1268 coll->action("CoreInfo")->setEnabled(false);
1269 coll->action("ChangePassword")->setEnabled(false);
1270 //_viewMenu->setEnabled(false);
1271 statusBar()->showMessage(tr("Not connected to core."));
1272 if (_msgProcessorStatusWidget)
1273 _msgProcessorStatusWidget->setProgress(0, 0);
1275 systemTray()->setState(SystemTray::Passive);
1276 _nickListWidget->setVisible(false);
1280 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1282 Q_UNUSED(errorMessage)
1283 CoreConnectAuthDlg dlg(account, this);
1284 *valid = (dlg.exec() == QDialog::Accepted);
1288 void MainWin::handleNoSslInClient(bool *accepted)
1290 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1291 QMessageBox::Ignore|QMessageBox::Cancel, this);
1292 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1293 box.setDefaultButton(QMessageBox::Ignore);
1294 *accepted = box.exec() == QMessageBox::Ignore;
1298 void MainWin::handleNoSslInCore(bool *accepted)
1300 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1301 QMessageBox::Ignore|QMessageBox::Cancel, this);
1302 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1303 box.setDefaultButton(QMessageBox::Ignore);
1304 *accepted = box.exec() == QMessageBox::Ignore;
1310 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1312 QString errorString = "<ul>";
1313 foreach(const QSslError error, socket->sslErrors())
1314 errorString += QString("<li>%1</li>").arg(error.errorString());
1315 errorString += "</ul>";
1317 QMessageBox box(QMessageBox::Warning,
1318 tr("Untrusted Security Certificate"),
1319 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1320 QMessageBox::Cancel, this);
1321 box.setInformativeText(errorString);
1322 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1323 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1325 QMessageBox::ButtonRole role;
1328 role = box.buttonRole(box.clickedButton());
1329 if (role == QMessageBox::HelpRole) {
1330 SslInfoDlg dlg(socket, this);
1334 while (role == QMessageBox::HelpRole);
1336 *accepted = role == QMessageBox::AcceptRole;
1338 QMessageBox box2(QMessageBox::Warning,
1339 tr("Untrusted Security Certificate"),
1340 tr("Would you like to accept this certificate forever without being prompted?"),
1342 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1343 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1345 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1350 #endif /* HAVE_SSL */
1352 void MainWin::handleCoreConnectionError(const QString &error)
1354 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1358 void MainWin::showCoreConnectionDlg()
1360 CoreConnectDlg dlg(this);
1361 if (dlg.exec() == QDialog::Accepted) {
1362 AccountId accId = dlg.selectedAccount();
1363 if (accId.isValid())
1364 Client::coreConnection()->connectToCore(accId);
1369 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1371 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1377 void MainWin::showChannelList(NetworkId netId)
1379 ChannelListDlg *channelListDlg = new ChannelListDlg();
1381 if (!netId.isValid()) {
1382 QAction *action = qobject_cast<QAction *>(sender());
1384 netId = action->data().value<NetworkId>();
1387 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1388 channelListDlg->setNetwork(netId);
1389 channelListDlg->show();
1393 void MainWin::showIgnoreList(QString newRule)
1395 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1396 // prepare config dialog for new rule
1397 if (!newRule.isEmpty())
1398 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1403 void MainWin::showCoreInfoDlg()
1405 CoreInfoDlg(this).exec();
1409 void MainWin::showAwayLog()
1413 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1414 _awayLog = new AwayLogView(filter, 0);
1415 filter->setParent(_awayLog);
1416 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1417 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1422 void MainWin::awayLogDestroyed()
1428 void MainWin::showSettingsDlg()
1430 SettingsDlg *dlg = new SettingsDlg();
1432 //Category: Interface
1433 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1434 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1435 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1436 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1437 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1438 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1439 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1440 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1442 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1444 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1445 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1446 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1449 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1450 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1451 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1452 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1453 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1454 dlg->registerSettingsPage(new DccSettingsPage(dlg));
1456 // Category: Remote Cores
1457 if (Quassel::runMode() != Quassel::Monolithic) {
1458 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1459 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1466 void MainWin::showAboutDlg()
1468 AboutDlg(this).exec();
1472 void MainWin::showShortcutsDlg()
1475 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1476 foreach(KActionCollection *coll, QtUi::actionCollections())
1477 dlg.addCollection(coll, coll->property("Category").toString());
1478 dlg.configure(true);
1480 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1486 void MainWin::showNewTransferDlg(const QUuid &transferId)
1488 auto transfer = Client::transferManager()->transfer(transferId);
1490 if (transfer->status() == Transfer::Status::New) {
1491 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1496 qWarning() << "Unknown transfer ID" << transferId;
1501 void MainWin::onFullScreenToggled()
1503 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1504 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1507 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1509 if (_fullScreenAction->isChecked())
1510 setWindowState(windowState() | Qt::WindowFullScreen);
1512 setWindowState(windowState() & ~Qt::WindowFullScreen);
1517 /********************************************************************************************************/
1519 bool MainWin::event(QEvent *event)
1521 switch(event->type()) {
1522 case QEvent::WindowActivate: {
1523 BufferId bufferId = Client::bufferModel()->currentBuffer();
1524 if (bufferId.isValid())
1525 Client::instance()->markBufferAsRead(bufferId);
1528 case QEvent::WindowDeactivate:
1529 if (bufferWidget()->autoMarkerLineOnLostFocus())
1530 bufferWidget()->setMarkerLine();
1535 return QMainWindow::event(event);
1539 void MainWin::moveEvent(QMoveEvent *event)
1541 if (!(windowState() & Qt::WindowMaximized))
1542 _normalPos = event->pos();
1544 QMainWindow::moveEvent(event);
1548 void MainWin::resizeEvent(QResizeEvent *event)
1550 if (!(windowState() & Qt::WindowMaximized))
1551 _normalSize = event->size();
1553 QMainWindow::resizeEvent(event);
1557 void MainWin::closeEvent(QCloseEvent *event)
1560 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1562 // On OSX it can happen that the closeEvent occurs twice. (Especially if packaged with Frameworks)
1563 // This messes up MainWinState/MainWinHidden save/restore.
1564 // It's a bug in Qt: https://bugreports.qt.io/browse/QTBUG-43344
1565 if (!_aboutToQuit && !app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1566 QtUi::hideMainWidget();
1569 else if(!_aboutToQuit) {
1570 _aboutToQuit = true;
1580 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1584 bool hasFocus = QApplication::activeWindow() != 0;
1586 for (int i = start; i <= end; i++) {
1587 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1588 if (!idx.isValid()) {
1589 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1592 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1593 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1596 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1597 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1599 // check if bufferId belongs to the shown chatlists
1600 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1601 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1604 // check if it's the buffer currently displayed
1605 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1608 // only show notifications for higlights or queries
1609 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1612 // and of course: don't notify for ignored messages
1613 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1616 // seems like we have a legit notification candidate!
1617 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1618 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1619 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1620 AbstractNotificationBackend::NotificationType type;
1622 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1623 type = AbstractNotificationBackend::PrivMsg;
1624 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1625 type = AbstractNotificationBackend::PrivMsgFocused;
1626 else if (flags & Message::Highlight && !hasFocus)
1627 type = AbstractNotificationBackend::Highlight;
1629 type = AbstractNotificationBackend::HighlightFocused;
1631 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1636 void MainWin::currentBufferChanged(BufferId buffer)
1638 if (buffer.isValid())
1639 Client::instance()->markBufferAsRead(buffer);
1643 void MainWin::clientNetworkCreated(NetworkId id)
1645 const Network *net = Client::network(id);
1646 QAction *act = new QAction(net->networkName(), this);
1647 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1648 act->setData(QVariant::fromValue<NetworkId>(id));
1649 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1650 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1652 QAction *beforeAction = 0;
1653 foreach(QAction *action, _networksMenu->actions()) {
1654 if (!action->data().isValid()) // ignore stock actions
1656 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1657 beforeAction = action;
1661 _networksMenu->insertAction(beforeAction, act);
1665 void MainWin::clientNetworkUpdated()
1667 const Network *net = qobject_cast<const Network *>(sender());
1671 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1675 action->setText(net->networkName());
1677 switch (net->connectionState()) {
1678 case Network::Initialized:
1679 action->setIcon(QIcon::fromTheme("network-connect"));
1680 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1681 if (!bufferWidget()->currentBuffer().isValid()) {
1682 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1683 if (idx.isValid()) {
1684 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1685 Client::bufferModel()->switchToBuffer(statusBufferId);
1689 case Network::Disconnected:
1690 action->setIcon(QIcon::fromTheme("network-disconnect"));
1693 action->setIcon(QIcon::fromTheme("network-wired"));
1698 void MainWin::clientNetworkRemoved(NetworkId id)
1700 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1704 action->deleteLater();
1708 void MainWin::connectOrDisconnectFromNet()
1710 QAction *act = qobject_cast<QAction *>(sender());
1712 const Network *net = Client::network(act->data().value<NetworkId>());
1714 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1715 else net->requestDisconnect();
1719 void MainWin::on_jumpHotBuffer_triggered()
1721 if (!_bufferHotList->rowCount())
1724 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1727 void MainWin::on_bufferSearch_triggered()
1729 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1730 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1734 _bufferViews[_activeBufferViewIndex]->activateFilter();
1738 void MainWin::onJumpKey()
1740 QAction *action = qobject_cast<QAction *>(sender());
1741 if (!action || !Client::bufferModel())
1743 int idx = action->property("Index").toInt();
1745 if (_jumpKeyMap.isEmpty())
1746 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1748 if (!_jumpKeyMap.contains(idx))
1751 BufferId buffer = _jumpKeyMap.value(idx);
1752 if (buffer.isValid())
1753 Client::bufferModel()->switchToBuffer(buffer);
1757 void MainWin::bindJumpKey()
1759 QAction *action = qobject_cast<QAction *>(sender());
1760 if (!action || !Client::bufferModel())
1762 int idx = action->property("Index").toInt();
1764 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1765 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1769 void MainWin::on_actionDebugNetworkModel_triggered()
1771 QTreeView *view = new QTreeView;
1772 view->setAttribute(Qt::WA_DeleteOnClose);
1773 view->setWindowTitle("Debug NetworkModel View");
1774 view->setModel(Client::networkModel());
1775 view->setColumnWidth(0, 250);
1776 view->setColumnWidth(1, 250);
1777 view->setColumnWidth(2, 80);
1778 view->resize(610, 300);
1783 void MainWin::on_actionDebugHotList_triggered()
1785 _bufferHotList->invalidate();
1786 _bufferHotList->sort(0, Qt::DescendingOrder);
1788 QTreeView *view = new QTreeView;
1789 view->setAttribute(Qt::WA_DeleteOnClose);
1790 view->setModel(_bufferHotList);
1795 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1797 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1798 overlay->setAttribute(Qt::WA_DeleteOnClose);
1803 void MainWin::on_actionDebugMessageModel_triggered()
1805 QTableView *view = new QTableView(0);
1806 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1807 filter->setSourceModel(Client::messageModel());
1808 view->setModel(filter);
1809 view->setAttribute(Qt::WA_DeleteOnClose, true);
1810 view->verticalHeader()->hide();
1811 view->horizontalHeader()->setStretchLastSection(true);
1816 void MainWin::on_actionDebugLog_triggered()
1818 DebugLogWidget *logWidget = new DebugLogWidget(0);
1823 void MainWin::showStatusBarMessage(const QString &message)
1825 statusBar()->showMessage(message, 10000);