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>
28 #include <QInputDialog>
33 # include <KShortcutsDialog>
34 # include <KStatusBar>
35 # include <KToggleFullScreenAction>
40 # include <KConfigWidgets/KStandardAction>
41 # include <KXmlGui/KHelpMenu>
42 # include <KXmlGui/KShortcutsDialog>
43 # include <KXmlGui/KToolBar>
44 # include <KWidgetsAddons/KToggleFullScreenAction>
52 #include "awaylogfilter.h"
53 #include "awaylogview.h"
55 #include "actioncollection.h"
56 #include "bufferhotlistfilter.h"
57 #include "buffermodel.h"
58 #include "bufferview.h"
59 #include "bufferviewoverlay.h"
60 #include "bufferviewoverlayfilter.h"
61 #include "bufferwidget.h"
62 #include "channellistdlg.h"
63 #include "chatlinemodel.h"
64 #include "chatmonitorfilter.h"
65 #include "chatmonitorview.h"
68 #include "clientbacklogmanager.h"
69 #include "clientbufferviewconfig.h"
70 #include "clientbufferviewmanager.h"
71 #include "clientignorelistmanager.h"
72 #include "clienttransfer.h"
73 #include "clienttransfermanager.h"
74 #include "coreconfigwizard.h"
75 #include "coreconnectdlg.h"
76 #include "coreconnection.h"
77 #include "coreconnectionstatuswidget.h"
78 #include "coreinfodlg.h"
79 #include "contextmenuactionprovider.h"
80 #include "debugbufferviewoverlay.h"
81 #include "debuglogwidget.h"
82 #include "debugmessagemodelfilter.h"
83 #include "flatproxymodel.h"
84 #include "inputwidget.h"
85 #include "irclistmodel.h"
86 #include "ircconnectionwizard.h"
87 #include "legacysystemtray.h"
88 #include "msgprocessorstatuswidget.h"
89 #include "nicklistwidget.h"
90 #include "passwordchangedlg.h"
91 #include "qtuiapplication.h"
92 #include "qtuimessageprocessor.h"
93 #include "qtuisettings.h"
94 #include "qtuistyle.h"
95 #include "receivefiledlg.h"
96 #include "settingsdlg.h"
97 #include "settingspagedlg.h"
98 #include "statusnotifieritem.h"
99 #include "toolbaractionprovider.h"
100 #include "topicwidget.h"
101 #include "verticaldock.h"
104 # ifdef HAVE_QTMULTIMEDIA
105 # include "qtmultimedianotificationbackend.h"
108 # include "phononnotificationbackend.h"
110 # include "systraynotificationbackend.h"
111 # include "taskbarnotificationbackend.h"
113 # include "knotificationbackend.h"
114 #endif /* HAVE_KDE */
118 # include "snorenotificationbackend.h"
122 # include "sslinfodlg.h"
125 #ifdef HAVE_INDICATEQT
126 #include "indicatornotificationbackend.h"
129 #ifdef HAVE_NOTIFICATION_CENTER
130 #include "osxnotificationbackend.h"
134 #include "dockmanagernotificationbackend.h"
137 #include "settingspages/aliasessettingspage.h"
138 #include "settingspages/appearancesettingspage.h"
139 #include "settingspages/backlogsettingspage.h"
140 #include "settingspages/bufferviewsettingspage.h"
141 #include "settingspages/chatmonitorsettingspage.h"
142 #include "settingspages/chatviewsettingspage.h"
143 #include "settingspages/connectionsettingspage.h"
144 #include "settingspages/coreaccountsettingspage.h"
145 #include "settingspages/coreconnectionsettingspage.h"
146 #include "settingspages/highlightsettingspage.h"
147 #include "settingspages/identitiessettingspage.h"
148 #include "settingspages/ignorelistsettingspage.h"
149 #include "settingspages/inputwidgetsettingspage.h"
150 #include "settingspages/itemviewsettingspage.h"
151 #include "settingspages/networkssettingspage.h"
152 #include "settingspages/notificationssettingspage.h"
153 #include "settingspages/topicwidgetsettingspage.h"
156 # include "settingspages/shortcutssettingspage.h"
160 # include "settingspages/sonnetsettingspage.h"
164 MainWin::MainWin(QWidget *parent)
166 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
168 : QMainWindow(parent),
170 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
171 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
174 _layoutLoaded(false),
175 _activeBufferViewIndex(-1)
177 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
179 QtUiSettings uiSettings;
180 QString style = uiSettings.value("Style", QString()).toString();
181 if (!style.isEmpty()) {
182 QApplication::setStyle(style);
185 QApplication::setQuitOnLastWindowClosed(false);
187 setWindowTitle("Quassel IRC");
188 setWindowIconText("Quassel IRC");
195 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
196 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
197 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
198 SLOT(messagesInserted(const QModelIndex &, int, int)));
199 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
200 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
202 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
203 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
204 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
205 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
206 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
208 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
212 setDockNestingEnabled(true);
213 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
214 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
215 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
216 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
218 // Order is sometimes important
234 # ifdef HAVE_QTMULTIMEDIA
235 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
238 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
240 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
242 QtUi::registerNotificationBackend(new KNotificationBackend(this));
243 #endif /* HAVE_KDE */
247 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
248 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
249 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
252 #ifdef HAVE_INDICATEQT
253 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
256 #ifdef HAVE_NOTIFICATION_CENTER
257 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
261 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
264 // we assume that at this point, all configurable actions are defined!
265 QtUi::loadShortcuts();
267 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
269 setDisconnectedState(); // Disable menus and stuff
272 setAutoSaveSettings();
275 // restore mainwin state
277 restoreStateFromSettings(s);
279 // restore locked state of docks
280 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
282 CoreConnection *conn = Client::coreConnection();
283 if (!conn->connectToCore()) {
284 // No autoconnect selected (or no accounts)
285 showCoreConnectionDlg();
298 saveStateToSettings(s);
300 QApplication::quit();
304 void MainWin::saveStateToSettings(UiSettings &s)
306 s.setValue("MainWinSize", _normalSize);
307 s.setValue("MainWinPos", _normalPos);
308 s.setValue("MainWinState", saveState());
309 s.setValue("MainWinGeometry", saveGeometry());
310 s.setValue("MainWinMinimized", isMinimized());
311 s.setValue("MainWinMaximized", isMaximized());
312 s.setValue("MainWinHidden", !isVisible());
313 BufferId lastBufId = Client::bufferModel()->currentBuffer();
314 if (lastBufId.isValid())
315 s.setValue("LastUsedBufferId", lastBufId.toInt());
318 saveAutoSaveSettings();
323 void MainWin::restoreStateFromSettings(UiSettings &s)
325 _normalSize = s.value("MainWinSize", size()).toSize();
326 _normalPos = s.value("MainWinPos", pos()).toPoint();
327 bool maximized = s.value("MainWinMaximized", false).toBool();
330 restoreGeometry(s.value("MainWinGeometry").toByteArray());
333 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
338 restoreState(s.value("MainWinState").toByteArray());
344 if ((Quassel::isOptionSet("hidewindow")
345 || s.value("MainWinHidden").toBool())
346 && _systemTray->isSystemTrayAvailable())
347 QtUi::hideMainWidget();
348 else if (s.value("MainWinMinimized").toBool())
357 void MainWin::updateIcon()
360 if (Client::isConnected())
361 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
363 icon = QIcon::fromTheme("quassel-inactive", QIcon(":/icons/quassel-128.png"));
365 qApp->setWindowIcon(icon);
369 void MainWin::setupActions()
371 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
373 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("network-connect"), tr("&Connect to Core..."), coll,
374 this, SLOT(showCoreConnectionDlg())));
375 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("network-disconnect"), tr("&Disconnect from Core"), coll,
376 Client::instance(), SLOT(disconnectFromCore())));
377 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
378 this, SLOT(showPasswordChangeDlg())));
379 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
380 this, SLOT(showCoreInfoDlg())));
381 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
382 this, SLOT(on_actionConfigureNetworks_triggered())));
383 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
384 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
385 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
388 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
389 this, SLOT(on_actionConfigureViews_triggered())));
391 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
392 lockAct->setCheckable(true);
393 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
395 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
396 0, 0, QKeySequence::Find))->setCheckable(true);
397 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
398 this, SLOT(showAwayLog())));
399 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
400 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
402 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
403 0, 0))->setCheckable(true);
406 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
408 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
409 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
410 _fullScreenAction->setCheckable(true);
411 coll->addAction("ToggleFullScreen", _fullScreenAction);
415 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
416 this, SLOT(showShortcutsDlg()));
417 configureShortcutsAct->setMenuRole(QAction::NoRole);
418 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
421 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
422 this, SLOT(showSettingsDlg()));
423 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
425 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
426 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
428 coll->addAction("ConfigureQuassel", configureQuasselAct);
431 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
432 this, SLOT(showAboutDlg()));
433 aboutQuasselAct->setMenuRole(QAction::AboutRole);
434 coll->addAction("AboutQuassel", aboutQuasselAct);
436 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
437 qApp, SLOT(aboutQt()));
438 aboutQtAct->setMenuRole(QAction::AboutQtRole);
439 coll->addAction("AboutQt", aboutQtAct);
440 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
441 this, SLOT(on_actionDebugNetworkModel_triggered())));
442 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
443 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
444 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
445 this, SLOT(on_actionDebugMessageModel_triggered())));
446 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
447 this, SLOT(on_actionDebugHotList_triggered())));
448 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
449 this, SLOT(on_actionDebugLog_triggered())));
450 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
451 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
453 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
454 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
457 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
459 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
460 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
462 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
463 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
467 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
468 const int jumpModifier = Qt::ControlModifier;
470 const int bindModifier = Qt::ControlModifier;
471 const int jumpModifier = Qt::AltModifier;
474 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
475 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
476 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
477 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
478 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
479 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
480 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
481 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
482 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
483 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
484 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
485 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
486 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
487 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
488 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
489 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
490 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
491 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
492 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
493 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
495 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
496 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
497 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
498 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
499 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
500 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
501 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
502 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
503 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
504 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
505 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
506 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
507 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
508 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
509 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
510 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
511 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
512 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
513 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
514 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
517 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
518 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
519 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
520 this, SLOT(previousBufferView()), QKeySequence::Back));
521 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
522 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
523 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
524 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
528 void MainWin::setupMenus()
530 ActionCollection *coll = QtUi::actionCollection("General");
532 _fileMenu = menuBar()->addMenu(tr("&File"));
534 static const QStringList coreActions = QStringList()
535 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
538 foreach(QString actionName, coreActions) {
539 coreAction = coll->action(actionName);
540 _fileMenu->addAction(coreAction);
541 flagRemoteCoreOnly(coreAction);
543 flagRemoteCoreOnly(_fileMenu->addSeparator());
545 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
546 _networksMenu->addAction(coll->action("ConfigureNetworks"));
547 _networksMenu->addSeparator();
548 _fileMenu->addSeparator();
549 _fileMenu->addAction(coll->action("Quit"));
551 _viewMenu = menuBar()->addMenu(tr("&View"));
552 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
553 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
554 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
555 _viewMenu->addSeparator();
557 _viewMenu->addAction(coll->action("ToggleMenuBar"));
558 _viewMenu->addAction(coll->action("ToggleStatusBar"));
559 _viewMenu->addAction(coll->action("ToggleSearchBar"));
561 coreAction = coll->action("ShowAwayLog");
562 flagRemoteCoreOnly(coreAction);
563 _viewMenu->addAction(coreAction);
565 _viewMenu->addSeparator();
566 _viewMenu->addAction(coll->action("LockLayout"));
568 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
570 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
571 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
573 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
575 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
578 _helpMenu = menuBar()->addMenu(tr("&Help"));
580 _helpMenu->addAction(coll->action("AboutQuassel"));
582 _helpMenu->addAction(coll->action("AboutQt"));
584 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
586 _helpMenu->addSeparator();
587 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
588 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
589 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
590 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
591 _helpDebugMenu->addAction(coll->action("DebugHotList"));
592 _helpDebugMenu->addAction(coll->action("DebugLog"));
593 _helpDebugMenu->addSeparator();
594 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
597 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
599 QtUiSettings uiSettings;
600 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
601 showMenuBar->setChecked(enabled);
602 enabled ? menuBar()->show() : menuBar()->hide();
604 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
605 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
609 void MainWin::setupBufferWidget()
611 _bufferWidget = new BufferWidget(this);
612 _bufferWidget->setModel(Client::bufferModel());
613 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
614 setCentralWidget(_bufferWidget);
618 void MainWin::addBufferView(int bufferViewConfigId)
620 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
624 void MainWin::addBufferView(ClientBufferViewConfig *config)
629 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
630 BufferViewDock *dock = new BufferViewDock(config, this);
632 //create the view and initialize it's filter
633 BufferView *view = new BufferView(dock);
634 view->setFilteredModel(Client::bufferModel(), config);
635 view->installEventFilter(_inputWidget); // for key presses
637 Client::bufferModel()->synchronizeView(view);
639 dock->setWidget(view);
640 dock->setVisible(_layoutLoaded); // don't show before state has been restored
642 addDockWidget(Qt::LeftDockWidgetArea, dock);
643 _bufferViewsMenu->addAction(dock->toggleViewAction());
645 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
646 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
647 _bufferViews.append(dock);
649 if (!activeBufferView())
654 void MainWin::removeBufferView(int bufferViewConfigId)
657 BufferViewDock *dock;
658 foreach(QAction *action, _bufferViewsMenu->actions()) {
659 actionData = action->data();
660 if (!actionData.isValid())
663 dock = qobject_cast<BufferViewDock *>(action->parent());
664 if (dock && actionData.toInt() == bufferViewConfigId) {
665 removeAction(action);
666 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
667 _bufferViews.removeAll(dock);
669 if (dock->isActive()) {
670 dock->setActive(false);
671 _activeBufferViewIndex = -1;
681 void MainWin::bufferViewToggled(bool enabled)
683 if (!enabled && !isMinimized()) {
684 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
685 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
688 QAction *action = qobject_cast<QAction *>(sender());
690 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
693 // Make sure we don't toggle backlog fetch for a view we've already removed
694 if (!_bufferViews.contains(dock))
698 Client::bufferViewOverlay()->addView(dock->bufferViewId());
700 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
704 void MainWin::bufferViewVisibilityChanged(bool visible)
707 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
709 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
714 BufferView *MainWin::allBuffersView() const
716 // "All Buffers" is always the first dock created
717 if (_bufferViews.count() > 0)
718 return _bufferViews[0]->bufferView();
723 BufferView *MainWin::activeBufferView() const
725 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
727 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
728 return dock->isActive() ? dock->bufferView() : 0;
732 void MainWin::changeActiveBufferView(int bufferViewId)
734 if (bufferViewId < 0)
737 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
738 _bufferViews[_activeBufferViewIndex]->setActive(false);
739 _activeBufferViewIndex = -1;
742 for (int i = 0; i < _bufferViews.count(); i++) {
743 BufferViewDock *dock = _bufferViews.at(i);
744 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
745 _activeBufferViewIndex = i;
746 dock->setActive(true);
751 nextBufferView(); // fallback
755 void MainWin::showPasswordChangeDlg()
757 if((Client::coreFeatures() & Quassel::PasswordChange)) {
758 PasswordChangeDlg dlg(this);
762 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
763 tr("<b>Your Quassel Core does not support this feature</b>"),
764 QMessageBox::Ok, this);
765 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
771 void MainWin::changeActiveBufferView(bool backwards)
773 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
774 _bufferViews[_activeBufferViewIndex]->setActive(false);
777 if (!_bufferViews.count())
780 int c = _bufferViews.count();
781 while (c--) { // yes, this will reactivate the current active one if all others fail
783 if (--_activeBufferViewIndex < 0)
784 _activeBufferViewIndex = _bufferViews.count()-1;
787 if (++_activeBufferViewIndex >= _bufferViews.count())
788 _activeBufferViewIndex = 0;
791 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
792 if (dock->isHidden())
795 dock->setActive(true);
799 _activeBufferViewIndex = -1;
803 void MainWin::nextBufferView()
805 changeActiveBufferView(false);
809 void MainWin::previousBufferView()
811 changeActiveBufferView(true);
815 void MainWin::nextBuffer()
817 BufferView *view = activeBufferView();
823 void MainWin::previousBuffer()
825 BufferView *view = activeBufferView();
827 view->previousBuffer();
831 void MainWin::hideCurrentBuffer()
833 BufferView *view = activeBufferView();
835 view->hideCurrentBuffer();
839 void MainWin::showNotificationsDlg()
841 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
846 void MainWin::on_actionConfigureNetworks_triggered()
848 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
853 void MainWin::on_actionConfigureViews_triggered()
855 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
860 void MainWin::on_actionLockLayout_toggled(bool lock)
862 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
863 foreach(VerticalDock *dock, docks) {
864 dock->showTitle(!lock);
866 if (Client::bufferViewManager()) {
867 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
868 config->setLocked(lock);
871 QtUiSettings().setValue("LockLayout", lock);
875 void MainWin::setupNickWidget()
878 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
879 nickDock->setObjectName("NickDock");
880 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
882 _nickListWidget = new NickListWidget(nickDock);
883 nickDock->setWidget(_nickListWidget);
885 addDockWidget(Qt::RightDockWidgetArea, nickDock);
886 _viewMenu->addAction(nickDock->toggleViewAction());
887 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
889 // See NickListDock::NickListDock();
890 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
892 // attach the NickListWidget to the BufferModel and the default selection
893 _nickListWidget->setModel(Client::bufferModel());
894 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
896 _nickListWidget->setVisible(false);
900 void MainWin::setupChatMonitor()
902 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
903 dock->setObjectName("ChatMonitorDock");
905 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
906 _chatMonitorView = new ChatMonitorView(filter, this);
907 _chatMonitorView->setFocusProxy(_inputWidget);
908 _chatMonitorView->show();
909 dock->setWidget(_chatMonitorView);
912 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
913 _viewMenu->addAction(dock->toggleViewAction());
914 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
918 void MainWin::setupInputWidget()
920 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
921 dock->setObjectName("InputDock");
923 _inputWidget = new InputWidget(dock);
924 dock->setWidget(_inputWidget);
926 addDockWidget(Qt::BottomDockWidgetArea, dock);
928 _viewMenu->addAction(dock->toggleViewAction());
929 dock->toggleViewAction()->setText(tr("Show Input Line"));
931 _inputWidget->setModel(Client::bufferModel());
932 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
934 _bufferWidget->setFocusProxy(_inputWidget);
936 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
938 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
942 void MainWin::setupTopicWidget()
944 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
945 dock->setObjectName("TopicDock");
946 _topicWidget = new TopicWidget(dock);
948 dock->setWidget(_topicWidget);
950 _topicWidget->setModel(Client::bufferModel());
951 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
953 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
955 _viewMenu->addAction(dock->toggleViewAction());
956 dock->toggleViewAction()->setText(tr("Show Topic Line"));
960 void MainWin::setupViewMenuTail()
962 _viewMenu->addSeparator();
963 _viewMenu->addAction(_fullScreenAction);
967 void MainWin::setupTitleSetter()
969 _titleSetter.setModel(Client::bufferModel());
970 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
974 void MainWin::setupStatusBar()
976 // MessageProcessor progress
977 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
980 _coreConnectionStatusWidget->update();
981 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
983 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
985 QtUiSettings uiSettings;
987 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
988 showStatusbar->setChecked(enabled);
989 enabled ? statusBar()->show() : statusBar()->hide();
991 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
992 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
994 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
998 void MainWin::setupHotList()
1000 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1001 flatProxy->setSourceModel(Client::bufferModel());
1002 _bufferHotList = new BufferHotListFilter(flatProxy);
1006 void MainWin::saveMenuBarStatus(bool enabled)
1008 QtUiSettings uiSettings;
1009 uiSettings.setValue("ShowMenuBar", enabled);
1013 void MainWin::saveStatusBarStatus(bool enabled)
1015 QtUiSettings uiSettings;
1016 uiSettings.setValue("ShowStatusBar", enabled);
1020 void MainWin::setupSystray()
1023 _systemTray = new StatusNotifierItem(this);
1024 #elif !defined QT_NO_SYSTEMTRAYICON
1025 _systemTray = new LegacySystemTray(this);
1027 _systemTray = new SystemTray(this); // dummy
1029 _systemTray->init();
1033 void MainWin::setupToolBars()
1035 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1036 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1037 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1038 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1041 setUnifiedTitleAndToolBarOnMac(true);
1045 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1047 _mainToolBar = new QToolBar(this);
1048 _mainToolBar->setObjectName("MainToolBar");
1050 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1051 addToolBar(_mainToolBar);
1053 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1054 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1057 QtUiSettings uiSettings;
1059 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1060 _mainToolBar->setVisible(visible);
1061 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1065 void MainWin::saveMainToolBarStatus(bool enabled)
1068 QtUiSettings uiSettings;
1069 uiSettings.setValue("ShowMainToolBar", enabled);
1076 void MainWin::connectedToCore()
1078 Q_CHECK_PTR(Client::bufferViewManager());
1079 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1080 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1081 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1083 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1085 setConnectedState();
1089 void MainWin::setConnectedState()
1091 ActionCollection *coll = QtUi::actionCollection("General");
1093 coll->action("ConnectCore")->setEnabled(false);
1094 coll->action("DisconnectCore")->setEnabled(true);
1095 coll->action("ChangePassword")->setEnabled(true);
1096 coll->action("CoreInfo")->setEnabled(true);
1098 foreach(QAction *action, _fileMenu->actions()) {
1099 if (isRemoteCoreOnly(action))
1100 action->setVisible(!Client::internalCore());
1103 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1104 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1105 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1106 if (!Client::internalCore()) {
1107 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1108 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1109 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1112 // _viewMenu->setEnabled(true);
1113 if (!Client::internalCore())
1114 statusBar()->showMessage(tr("Connected to core."));
1116 statusBar()->clearMessage();
1118 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1120 systemTray()->setState(SystemTray::Active);
1122 if (Client::networkIds().isEmpty()) {
1123 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1127 // Monolithic always preselects last used buffer - Client only if the connection died
1128 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1130 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1131 if (lastUsedBufferId.isValid())
1132 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1138 void MainWin::loadLayout()
1141 int accountId = Client::currentCoreAccount().accountId().toInt();
1142 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1143 if (state.isEmpty()) {
1144 foreach(BufferViewDock *view, _bufferViews)
1146 _layoutLoaded = true;
1149 _nickListWidget->setVisible(true);
1150 restoreState(state, accountId);
1151 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1152 if (bufferViewId >= 0)
1153 changeActiveBufferView(bufferViewId);
1155 _layoutLoaded = true;
1159 void MainWin::saveLayout()
1162 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1163 if (accountId > 0) {
1164 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1165 BufferView *view = activeBufferView();
1166 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1171 void MainWin::disconnectedFromCore()
1173 // save core specific layout and remove bufferviews;
1175 _layoutLoaded = false;
1177 QVariant actionData;
1178 BufferViewDock *dock;
1179 foreach(QAction *action, _bufferViewsMenu->actions()) {
1180 actionData = action->data();
1181 if (!actionData.isValid())
1184 dock = qobject_cast<BufferViewDock *>(action->parent());
1185 if (dock && actionData.toInt() != -1) {
1186 removeAction(action);
1187 _bufferViews.removeAll(dock);
1188 dock->deleteLater();
1192 // store last active buffer
1194 BufferId lastBufId = _bufferWidget->currentBuffer();
1195 if (lastBufId.isValid()) {
1196 s.setValue("LastUsedBufferId", lastBufId.toInt());
1197 // clear the current selection
1198 Client::bufferModel()->standardSelectionModel()->clearSelection();
1200 restoreState(s.value("MainWinState").toByteArray());
1201 setDisconnectedState();
1205 void MainWin::setDisconnectedState()
1207 ActionCollection *coll = QtUi::actionCollection("General");
1208 //ui.menuCore->setEnabled(false);
1209 coll->action("ConnectCore")->setEnabled(true);
1210 coll->action("DisconnectCore")->setEnabled(false);
1211 coll->action("CoreInfo")->setEnabled(false);
1212 coll->action("ChangePassword")->setEnabled(false);
1213 //_viewMenu->setEnabled(false);
1214 statusBar()->showMessage(tr("Not connected to core."));
1215 if (_msgProcessorStatusWidget)
1216 _msgProcessorStatusWidget->setProgress(0, 0);
1218 systemTray()->setState(SystemTray::Passive);
1219 _nickListWidget->setVisible(false);
1223 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1225 Q_UNUSED(errorMessage)
1226 CoreConnectAuthDlg dlg(account, this);
1227 *valid = (dlg.exec() == QDialog::Accepted);
1231 void MainWin::handleNoSslInClient(bool *accepted)
1233 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1234 QMessageBox::Ignore|QMessageBox::Cancel, this);
1235 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1236 box.setDefaultButton(QMessageBox::Ignore);
1237 *accepted = box.exec() == QMessageBox::Ignore;
1241 void MainWin::handleNoSslInCore(bool *accepted)
1243 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1244 QMessageBox::Ignore|QMessageBox::Cancel, this);
1245 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1246 box.setDefaultButton(QMessageBox::Ignore);
1247 *accepted = box.exec() == QMessageBox::Ignore;
1253 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1255 QString errorString = "<ul>";
1256 foreach(const QSslError error, socket->sslErrors())
1257 errorString += QString("<li>%1</li>").arg(error.errorString());
1258 errorString += "</ul>";
1260 QMessageBox box(QMessageBox::Warning,
1261 tr("Untrusted Security Certificate"),
1262 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1263 QMessageBox::Cancel, this);
1264 box.setInformativeText(errorString);
1265 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1266 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1268 QMessageBox::ButtonRole role;
1271 role = box.buttonRole(box.clickedButton());
1272 if (role == QMessageBox::HelpRole) {
1273 SslInfoDlg dlg(socket, this);
1277 while (role == QMessageBox::HelpRole);
1279 *accepted = role == QMessageBox::AcceptRole;
1281 QMessageBox box2(QMessageBox::Warning,
1282 tr("Untrusted Security Certificate"),
1283 tr("Would you like to accept this certificate forever without being prompted?"),
1285 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1286 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1288 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1293 #endif /* HAVE_SSL */
1295 void MainWin::handleCoreConnectionError(const QString &error)
1297 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1301 void MainWin::showCoreConnectionDlg()
1303 CoreConnectDlg dlg(this);
1304 if (dlg.exec() == QDialog::Accepted) {
1305 AccountId accId = dlg.selectedAccount();
1306 if (accId.isValid())
1307 Client::coreConnection()->connectToCore(accId);
1312 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1314 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1320 void MainWin::showChannelList(NetworkId netId)
1322 ChannelListDlg *channelListDlg = new ChannelListDlg();
1324 if (!netId.isValid()) {
1325 QAction *action = qobject_cast<QAction *>(sender());
1327 netId = action->data().value<NetworkId>();
1330 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1331 channelListDlg->setNetwork(netId);
1332 channelListDlg->show();
1336 void MainWin::showIgnoreList(QString newRule)
1338 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1339 // prepare config dialog for new rule
1340 if (!newRule.isEmpty())
1341 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1346 void MainWin::showCoreInfoDlg()
1348 CoreInfoDlg(this).exec();
1352 void MainWin::showAwayLog()
1356 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1357 _awayLog = new AwayLogView(filter, 0);
1358 filter->setParent(_awayLog);
1359 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1360 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1365 void MainWin::awayLogDestroyed()
1371 void MainWin::showSettingsDlg()
1373 SettingsDlg *dlg = new SettingsDlg();
1375 //Category: Interface
1376 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1377 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1378 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1379 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1380 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1381 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1382 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1384 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1386 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1387 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1388 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1391 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1392 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1393 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1394 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1395 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1397 // Category: Remote Cores
1398 if (Quassel::runMode() != Quassel::Monolithic) {
1399 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1400 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1407 void MainWin::showAboutDlg()
1409 AboutDlg(this).exec();
1413 void MainWin::showShortcutsDlg()
1416 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1417 foreach(KActionCollection *coll, QtUi::actionCollections())
1418 dlg.addCollection(coll, coll->property("Category").toString());
1419 dlg.configure(true);
1421 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1427 void MainWin::showNewTransferDlg(const QUuid &transferId)
1429 auto transfer = Client::transferManager()->transfer(transferId);
1431 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1435 qWarning() << "Unknown transfer ID" << transferId;
1440 void MainWin::onFullScreenToggled()
1442 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1443 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1446 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1448 if (_fullScreenAction->isChecked())
1449 setWindowState(windowState() | Qt::WindowFullScreen);
1451 setWindowState(windowState() & ~Qt::WindowFullScreen);
1456 /********************************************************************************************************/
1458 bool MainWin::event(QEvent *event)
1460 switch(event->type()) {
1461 case QEvent::WindowActivate: {
1462 BufferId bufferId = Client::bufferModel()->currentBuffer();
1463 if (bufferId.isValid())
1464 Client::instance()->markBufferAsRead(bufferId);
1467 case QEvent::WindowDeactivate:
1468 if (bufferWidget()->autoMarkerLineOnLostFocus())
1469 bufferWidget()->setMarkerLine();
1474 return QMainWindow::event(event);
1478 void MainWin::moveEvent(QMoveEvent *event)
1480 if (!(windowState() & Qt::WindowMaximized))
1481 _normalPos = event->pos();
1483 QMainWindow::moveEvent(event);
1487 void MainWin::resizeEvent(QResizeEvent *event)
1489 if (!(windowState() & Qt::WindowMaximized))
1490 _normalSize = event->size();
1492 QMainWindow::resizeEvent(event);
1496 void MainWin::closeEvent(QCloseEvent *event)
1499 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1501 if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1502 QtUi::hideMainWidget();
1512 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1516 bool hasFocus = QApplication::activeWindow() != 0;
1518 for (int i = start; i <= end; i++) {
1519 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1520 if (!idx.isValid()) {
1521 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1524 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1525 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1528 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1529 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1531 // check if bufferId belongs to the shown chatlists
1532 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1533 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1536 // check if it's the buffer currently displayed
1537 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1540 // only show notifications for higlights or queries
1541 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1544 // and of course: don't notify for ignored messages
1545 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1548 // seems like we have a legit notification candidate!
1549 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1550 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1551 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1552 AbstractNotificationBackend::NotificationType type;
1554 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1555 type = AbstractNotificationBackend::PrivMsg;
1556 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1557 type = AbstractNotificationBackend::PrivMsgFocused;
1558 else if (flags & Message::Highlight && !hasFocus)
1559 type = AbstractNotificationBackend::Highlight;
1561 type = AbstractNotificationBackend::HighlightFocused;
1563 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1568 void MainWin::currentBufferChanged(BufferId buffer)
1570 if (buffer.isValid())
1571 Client::instance()->markBufferAsRead(buffer);
1575 void MainWin::clientNetworkCreated(NetworkId id)
1577 const Network *net = Client::network(id);
1578 QAction *act = new QAction(net->networkName(), this);
1579 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1580 act->setData(QVariant::fromValue<NetworkId>(id));
1581 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1582 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1584 QAction *beforeAction = 0;
1585 foreach(QAction *action, _networksMenu->actions()) {
1586 if (!action->data().isValid()) // ignore stock actions
1588 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1589 beforeAction = action;
1593 _networksMenu->insertAction(beforeAction, act);
1597 void MainWin::clientNetworkUpdated()
1599 const Network *net = qobject_cast<const Network *>(sender());
1603 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1607 action->setText(net->networkName());
1609 switch (net->connectionState()) {
1610 case Network::Initialized:
1611 action->setIcon(QIcon::fromTheme("network-connect"));
1612 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1613 if (!bufferWidget()->currentBuffer().isValid()) {
1614 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1615 if (idx.isValid()) {
1616 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1617 Client::bufferModel()->switchToBuffer(statusBufferId);
1621 case Network::Disconnected:
1622 action->setIcon(QIcon::fromTheme("network-disconnect"));
1625 action->setIcon(QIcon::fromTheme("network-wired"));
1630 void MainWin::clientNetworkRemoved(NetworkId id)
1632 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1636 action->deleteLater();
1640 void MainWin::connectOrDisconnectFromNet()
1642 QAction *act = qobject_cast<QAction *>(sender());
1644 const Network *net = Client::network(act->data().value<NetworkId>());
1646 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1647 else net->requestDisconnect();
1651 void MainWin::on_jumpHotBuffer_triggered()
1653 if (!_bufferHotList->rowCount())
1656 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1659 void MainWin::on_bufferSearch_triggered()
1661 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1662 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1666 _bufferViews[_activeBufferViewIndex]->activateFilter();
1670 void MainWin::onJumpKey()
1672 QAction *action = qobject_cast<QAction *>(sender());
1673 if (!action || !Client::bufferModel())
1675 int idx = action->property("Index").toInt();
1677 if (_jumpKeyMap.isEmpty())
1678 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1680 if (!_jumpKeyMap.contains(idx))
1683 BufferId buffer = _jumpKeyMap.value(idx);
1684 if (buffer.isValid())
1685 Client::bufferModel()->switchToBuffer(buffer);
1689 void MainWin::bindJumpKey()
1691 QAction *action = qobject_cast<QAction *>(sender());
1692 if (!action || !Client::bufferModel())
1694 int idx = action->property("Index").toInt();
1696 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1697 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1701 void MainWin::on_actionDebugNetworkModel_triggered()
1703 QTreeView *view = new QTreeView;
1704 view->setAttribute(Qt::WA_DeleteOnClose);
1705 view->setWindowTitle("Debug NetworkModel View");
1706 view->setModel(Client::networkModel());
1707 view->setColumnWidth(0, 250);
1708 view->setColumnWidth(1, 250);
1709 view->setColumnWidth(2, 80);
1710 view->resize(610, 300);
1715 void MainWin::on_actionDebugHotList_triggered()
1717 _bufferHotList->invalidate();
1718 _bufferHotList->sort(0, Qt::DescendingOrder);
1720 QTreeView *view = new QTreeView;
1721 view->setAttribute(Qt::WA_DeleteOnClose);
1722 view->setModel(_bufferHotList);
1727 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1729 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1730 overlay->setAttribute(Qt::WA_DeleteOnClose);
1735 void MainWin::on_actionDebugMessageModel_triggered()
1737 QTableView *view = new QTableView(0);
1738 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1739 filter->setSourceModel(Client::messageModel());
1740 view->setModel(filter);
1741 view->setAttribute(Qt::WA_DeleteOnClose, true);
1742 view->verticalHeader()->hide();
1743 view->horizontalHeader()->setStretchLastSection(true);
1748 void MainWin::on_actionDebugLog_triggered()
1750 DebugLogWidget *logWidget = new DebugLogWidget(0);
1755 void MainWin::showStatusBarMessage(const QString &message)
1757 statusBar()->showMessage(message, 10000);