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/chatviewcolorsettingspage.h"
144 #include "settingspages/connectionsettingspage.h"
145 #include "settingspages/coreaccountsettingspage.h"
146 #include "settingspages/coreconnectionsettingspage.h"
147 #include "settingspages/highlightsettingspage.h"
148 #include "settingspages/identitiessettingspage.h"
149 #include "settingspages/ignorelistsettingspage.h"
150 #include "settingspages/inputwidgetsettingspage.h"
151 #include "settingspages/itemviewsettingspage.h"
152 #include "settingspages/networkssettingspage.h"
153 #include "settingspages/notificationssettingspage.h"
154 #include "settingspages/topicwidgetsettingspage.h"
157 # include "settingspages/shortcutssettingspage.h"
161 # include "settingspages/sonnetsettingspage.h"
165 MainWin::MainWin(QWidget *parent)
167 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
169 : QMainWindow(parent),
171 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
172 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
175 _layoutLoaded(false),
176 _activeBufferViewIndex(-1)
178 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
180 QtUiSettings uiSettings;
181 QString style = uiSettings.value("Style", QString()).toString();
182 if (!style.isEmpty()) {
183 QApplication::setStyle(style);
186 QApplication::setQuitOnLastWindowClosed(false);
188 setWindowTitle("Quassel IRC");
189 setWindowIconText("Quassel IRC");
196 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
197 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
198 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
199 SLOT(messagesInserted(const QModelIndex &, int, int)));
200 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
201 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
203 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
204 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
205 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
206 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
207 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
209 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
213 setDockNestingEnabled(true);
214 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
215 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
216 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
217 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
219 // Order is sometimes important
235 # ifdef HAVE_QTMULTIMEDIA
236 QtUi::registerNotificationBackend(new QtMultimediaNotificationBackend(this));
239 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
241 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
243 QtUi::registerNotificationBackend(new KNotificationBackend(this));
244 #endif /* HAVE_KDE */
248 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
249 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
250 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
253 #ifdef HAVE_INDICATEQT
254 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
257 #ifdef HAVE_NOTIFICATION_CENTER
258 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
262 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
265 // we assume that at this point, all configurable actions are defined!
266 QtUi::loadShortcuts();
268 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
270 setDisconnectedState(); // Disable menus and stuff
273 setAutoSaveSettings();
276 // restore mainwin state
278 restoreStateFromSettings(s);
280 // restore locked state of docks
281 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
283 CoreConnection *conn = Client::coreConnection();
284 if (!conn->connectToCore()) {
285 // No autoconnect selected (or no accounts)
286 showCoreConnectionDlg();
299 saveStateToSettings(s);
301 QApplication::quit();
305 void MainWin::saveStateToSettings(UiSettings &s)
307 s.setValue("MainWinSize", _normalSize);
308 s.setValue("MainWinPos", _normalPos);
309 s.setValue("MainWinState", saveState());
310 s.setValue("MainWinGeometry", saveGeometry());
311 s.setValue("MainWinMinimized", isMinimized());
312 s.setValue("MainWinMaximized", isMaximized());
313 s.setValue("MainWinHidden", !isVisible());
314 BufferId lastBufId = Client::bufferModel()->currentBuffer();
315 if (lastBufId.isValid())
316 s.setValue("LastUsedBufferId", lastBufId.toInt());
319 saveAutoSaveSettings();
324 void MainWin::restoreStateFromSettings(UiSettings &s)
326 _normalSize = s.value("MainWinSize", size()).toSize();
327 _normalPos = s.value("MainWinPos", pos()).toPoint();
328 bool maximized = s.value("MainWinMaximized", false).toBool();
331 restoreGeometry(s.value("MainWinGeometry").toByteArray());
334 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
339 restoreState(s.value("MainWinState").toByteArray());
345 if ((Quassel::isOptionSet("hidewindow")
346 || s.value("MainWinHidden").toBool())
347 && _systemTray->isSystemTrayAvailable())
348 QtUi::hideMainWidget();
349 else if (s.value("MainWinMinimized").toBool())
357 QMenu *MainWin::createPopupMenu()
359 QMenu *popupMenu = QMainWindow::createPopupMenu();
360 popupMenu->addSeparator();
361 ActionCollection *coll = QtUi::actionCollection("General");
362 popupMenu->addAction(coll->action("ToggleMenuBar"));
367 void MainWin::updateIcon()
370 if (Client::isConnected())
371 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
373 icon = QIcon::fromTheme("quassel-inactive", QIcon(":/icons/quassel-128.png"));
375 qApp->setWindowIcon(icon);
379 void MainWin::setupActions()
381 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
383 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("network-connect"), tr("&Connect to Core..."), coll,
384 this, SLOT(showCoreConnectionDlg())));
385 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("network-disconnect"), tr("&Disconnect from Core"), coll,
386 Client::instance(), SLOT(disconnectFromCore())));
387 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
388 this, SLOT(showPasswordChangeDlg())));
389 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
390 this, SLOT(showCoreInfoDlg())));
391 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
392 this, SLOT(on_actionConfigureNetworks_triggered())));
393 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
394 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
395 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
398 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
399 this, SLOT(on_actionConfigureViews_triggered())));
401 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
402 lockAct->setCheckable(true);
403 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
405 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
406 0, 0, QKeySequence::Find))->setCheckable(true);
407 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
408 this, SLOT(showAwayLog())));
409 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
410 0, 0))->setCheckable(true);
412 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
413 0, 0))->setCheckable(true);
416 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
418 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
419 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
420 _fullScreenAction->setCheckable(true);
421 coll->addAction("ToggleFullScreen", _fullScreenAction);
425 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
426 this, SLOT(showShortcutsDlg()));
427 configureShortcutsAct->setMenuRole(QAction::NoRole);
428 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
431 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
432 this, SLOT(showSettingsDlg()));
433 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
435 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
436 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
438 coll->addAction("ConfigureQuassel", configureQuasselAct);
441 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
442 this, SLOT(showAboutDlg()));
443 aboutQuasselAct->setMenuRole(QAction::AboutRole);
444 coll->addAction("AboutQuassel", aboutQuasselAct);
446 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
447 qApp, SLOT(aboutQt()));
448 aboutQtAct->setMenuRole(QAction::AboutQtRole);
449 coll->addAction("AboutQt", aboutQtAct);
450 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
451 this, SLOT(on_actionDebugNetworkModel_triggered())));
452 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
453 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
454 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
455 this, SLOT(on_actionDebugMessageModel_triggered())));
456 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
457 this, SLOT(on_actionDebugHotList_triggered())));
458 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
459 this, SLOT(on_actionDebugLog_triggered())));
460 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
461 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
463 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
464 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
467 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
469 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
470 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
472 coll->addAction("ActivateBufferFilter", new Action(tr("Activate the buffer search"), coll,
473 this, SLOT(on_bufferSearch_triggered()), QKeySequence(Qt::CTRL + Qt::Key_S)));
477 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
478 const int jumpModifier = Qt::ControlModifier;
480 const int bindModifier = Qt::ControlModifier;
481 const int jumpModifier = Qt::AltModifier;
484 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
485 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
486 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
487 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
488 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
489 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
490 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
491 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
492 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
493 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
494 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
495 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
496 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
497 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
498 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
499 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
500 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
501 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
502 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
503 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
505 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
506 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
507 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
508 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
509 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
510 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
511 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
512 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
513 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
514 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
515 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
516 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
517 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
518 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
519 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
520 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
521 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
522 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
523 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
524 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
527 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
528 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
529 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
530 this, SLOT(previousBufferView()), QKeySequence::Back));
531 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
532 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
533 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
534 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
538 void MainWin::setupMenus()
540 ActionCollection *coll = QtUi::actionCollection("General");
542 _fileMenu = menuBar()->addMenu(tr("&File"));
544 static const QStringList coreActions = QStringList()
545 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
548 foreach(QString actionName, coreActions) {
549 coreAction = coll->action(actionName);
550 _fileMenu->addAction(coreAction);
551 flagRemoteCoreOnly(coreAction);
553 flagRemoteCoreOnly(_fileMenu->addSeparator());
555 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
556 _networksMenu->addAction(coll->action("ConfigureNetworks"));
557 _networksMenu->addSeparator();
558 _fileMenu->addSeparator();
559 _fileMenu->addAction(coll->action("Quit"));
561 _viewMenu = menuBar()->addMenu(tr("&View"));
562 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
563 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
564 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
565 _viewMenu->addSeparator();
567 _viewMenu->addAction(coll->action("ToggleMenuBar"));
568 _viewMenu->addAction(coll->action("ToggleStatusBar"));
569 _viewMenu->addAction(coll->action("ToggleSearchBar"));
571 coreAction = coll->action("ShowAwayLog");
572 flagRemoteCoreOnly(coreAction);
573 _viewMenu->addAction(coreAction);
575 _viewMenu->addSeparator();
576 _viewMenu->addAction(coll->action("LockLayout"));
578 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
580 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
581 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
583 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
585 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
588 _helpMenu = menuBar()->addMenu(tr("&Help"));
590 _helpMenu->addAction(coll->action("AboutQuassel"));
592 _helpMenu->addAction(coll->action("AboutQt"));
594 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
596 _helpMenu->addSeparator();
597 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
598 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
599 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
600 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
601 _helpDebugMenu->addAction(coll->action("DebugHotList"));
602 _helpDebugMenu->addAction(coll->action("DebugLog"));
603 _helpDebugMenu->addSeparator();
604 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
607 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
609 QtUiSettings uiSettings;
610 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
611 showMenuBar->setChecked(enabled);
612 enabled ? menuBar()->show() : menuBar()->hide();
614 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
615 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
619 void MainWin::setupBufferWidget()
621 _bufferWidget = new BufferWidget(this);
622 _bufferWidget->setModel(Client::bufferModel());
623 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
624 setCentralWidget(_bufferWidget);
628 void MainWin::addBufferView(int bufferViewConfigId)
630 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
634 void MainWin::addBufferView(ClientBufferViewConfig *config)
639 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
640 BufferViewDock *dock = new BufferViewDock(config, this);
642 //create the view and initialize it's filter
643 BufferView *view = new BufferView(dock);
644 view->setFilteredModel(Client::bufferModel(), config);
645 view->installEventFilter(_inputWidget); // for key presses
647 Client::bufferModel()->synchronizeView(view);
649 dock->setWidget(view);
650 dock->setVisible(_layoutLoaded); // don't show before state has been restored
652 addDockWidget(Qt::LeftDockWidgetArea, dock);
653 _bufferViewsMenu->addAction(dock->toggleViewAction());
655 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
656 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
657 _bufferViews.append(dock);
659 if (!activeBufferView())
664 void MainWin::removeBufferView(int bufferViewConfigId)
667 BufferViewDock *dock;
668 foreach(QAction *action, _bufferViewsMenu->actions()) {
669 actionData = action->data();
670 if (!actionData.isValid())
673 dock = qobject_cast<BufferViewDock *>(action->parent());
674 if (dock && actionData.toInt() == bufferViewConfigId) {
675 removeAction(action);
676 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
677 _bufferViews.removeAll(dock);
679 if (dock->isActive()) {
680 dock->setActive(false);
681 _activeBufferViewIndex = -1;
691 void MainWin::bufferViewToggled(bool enabled)
693 if (!enabled && !isMinimized()) {
694 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
695 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
698 QAction *action = qobject_cast<QAction *>(sender());
700 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
703 // Make sure we don't toggle backlog fetch for a view we've already removed
704 if (!_bufferViews.contains(dock))
708 Client::bufferViewOverlay()->addView(dock->bufferViewId());
710 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
714 void MainWin::bufferViewVisibilityChanged(bool visible)
717 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
719 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
724 BufferView *MainWin::allBuffersView() const
726 // "All Buffers" is always the first dock created
727 if (_bufferViews.count() > 0)
728 return _bufferViews[0]->bufferView();
733 BufferView *MainWin::activeBufferView() const
735 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
737 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
738 return dock->isActive() ? dock->bufferView() : 0;
742 void MainWin::changeActiveBufferView(int bufferViewId)
744 if (bufferViewId < 0)
747 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
748 _bufferViews[_activeBufferViewIndex]->setActive(false);
749 _activeBufferViewIndex = -1;
752 for (int i = 0; i < _bufferViews.count(); i++) {
753 BufferViewDock *dock = _bufferViews.at(i);
754 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
755 _activeBufferViewIndex = i;
756 dock->setActive(true);
761 nextBufferView(); // fallback
765 void MainWin::showPasswordChangeDlg()
767 if((Client::coreFeatures() & Quassel::PasswordChange)) {
768 PasswordChangeDlg dlg(this);
772 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
773 tr("<b>Your Quassel Core does not support this feature</b>"),
774 QMessageBox::Ok, this);
775 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
781 void MainWin::changeActiveBufferView(bool backwards)
783 if (_activeBufferViewIndex >= 0 && _activeBufferViewIndex < _bufferViews.count()) {
784 _bufferViews[_activeBufferViewIndex]->setActive(false);
787 if (!_bufferViews.count())
790 int c = _bufferViews.count();
791 while (c--) { // yes, this will reactivate the current active one if all others fail
793 if (--_activeBufferViewIndex < 0)
794 _activeBufferViewIndex = _bufferViews.count()-1;
797 if (++_activeBufferViewIndex >= _bufferViews.count())
798 _activeBufferViewIndex = 0;
801 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
802 if (dock->isHidden())
805 dock->setActive(true);
809 _activeBufferViewIndex = -1;
813 void MainWin::nextBufferView()
815 changeActiveBufferView(false);
819 void MainWin::previousBufferView()
821 changeActiveBufferView(true);
825 void MainWin::nextBuffer()
827 BufferView *view = activeBufferView();
833 void MainWin::previousBuffer()
835 BufferView *view = activeBufferView();
837 view->previousBuffer();
841 void MainWin::hideCurrentBuffer()
843 BufferView *view = activeBufferView();
845 view->hideCurrentBuffer();
849 void MainWin::showNotificationsDlg()
851 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
856 void MainWin::on_actionConfigureNetworks_triggered()
858 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
863 void MainWin::on_actionConfigureViews_triggered()
865 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
870 void MainWin::on_actionLockLayout_toggled(bool lock)
872 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
873 foreach(VerticalDock *dock, docks) {
874 dock->showTitle(!lock);
876 if (Client::bufferViewManager()) {
877 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
878 config->setLocked(lock);
881 QtUiSettings().setValue("LockLayout", lock);
885 void MainWin::setupNickWidget()
888 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
889 nickDock->setObjectName("NickDock");
890 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
892 _nickListWidget = new NickListWidget(nickDock);
893 nickDock->setWidget(_nickListWidget);
895 addDockWidget(Qt::RightDockWidgetArea, nickDock);
896 _viewMenu->addAction(nickDock->toggleViewAction());
897 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
899 // See NickListDock::NickListDock();
900 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
902 // attach the NickListWidget to the BufferModel and the default selection
903 _nickListWidget->setModel(Client::bufferModel());
904 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
906 _nickListWidget->setVisible(false);
910 void MainWin::setupChatMonitor()
912 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
913 dock->setObjectName("ChatMonitorDock");
915 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
916 _chatMonitorView = new ChatMonitorView(filter, this);
917 _chatMonitorView->setFocusProxy(_inputWidget);
918 _chatMonitorView->show();
919 dock->setWidget(_chatMonitorView);
922 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
923 _viewMenu->addAction(dock->toggleViewAction());
924 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
928 void MainWin::setupInputWidget()
930 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
931 dock->setObjectName("InputDock");
933 _inputWidget = new InputWidget(dock);
934 dock->setWidget(_inputWidget);
936 addDockWidget(Qt::BottomDockWidgetArea, dock);
938 _viewMenu->addAction(dock->toggleViewAction());
939 dock->toggleViewAction()->setText(tr("Show Input Line"));
941 _inputWidget->setModel(Client::bufferModel());
942 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
944 _bufferWidget->setFocusProxy(_inputWidget);
946 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
948 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
952 void MainWin::setupTopicWidget()
954 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
955 dock->setObjectName("TopicDock");
956 _topicWidget = new TopicWidget(dock);
958 dock->setWidget(_topicWidget);
960 _topicWidget->setModel(Client::bufferModel());
961 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
963 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
965 _viewMenu->addAction(dock->toggleViewAction());
966 dock->toggleViewAction()->setText(tr("Show Topic Line"));
970 void MainWin::setupViewMenuTail()
972 _viewMenu->addSeparator();
973 _viewMenu->addAction(_fullScreenAction);
977 void MainWin::setupTitleSetter()
979 _titleSetter.setModel(Client::bufferModel());
980 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
984 void MainWin::setupStatusBar()
986 // MessageProcessor progress
987 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
990 _coreConnectionStatusWidget->update();
991 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
993 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
995 QtUiSettings uiSettings;
997 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
998 showStatusbar->setChecked(enabled);
999 enabled ? statusBar()->show() : statusBar()->hide();
1001 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
1002 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
1004 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
1008 void MainWin::setupHotList()
1010 FlatProxyModel *flatProxy = new FlatProxyModel(this);
1011 flatProxy->setSourceModel(Client::bufferModel());
1012 _bufferHotList = new BufferHotListFilter(flatProxy);
1016 void MainWin::saveMenuBarStatus(bool enabled)
1018 QtUiSettings uiSettings;
1019 uiSettings.setValue("ShowMenuBar", enabled);
1023 void MainWin::saveStatusBarStatus(bool enabled)
1025 QtUiSettings uiSettings;
1026 uiSettings.setValue("ShowStatusBar", enabled);
1030 void MainWin::setupSystray()
1033 _systemTray = new StatusNotifierItem(this);
1034 #elif !defined QT_NO_SYSTEMTRAYICON
1035 _systemTray = new LegacySystemTray(this);
1037 _systemTray = new SystemTray(this); // dummy
1039 _systemTray->init();
1043 void MainWin::setupToolBars()
1045 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1046 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1047 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1048 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1051 setUnifiedTitleAndToolBarOnMac(true);
1055 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1057 _mainToolBar = new QToolBar(this);
1058 _mainToolBar->setObjectName("MainToolBar");
1060 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1061 addToolBar(_mainToolBar);
1063 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1064 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1067 QtUiSettings uiSettings;
1069 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1070 _mainToolBar->setVisible(visible);
1071 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1075 void MainWin::saveMainToolBarStatus(bool enabled)
1078 QtUiSettings uiSettings;
1079 uiSettings.setValue("ShowMainToolBar", enabled);
1086 void MainWin::connectedToCore()
1088 Q_CHECK_PTR(Client::bufferViewManager());
1089 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1090 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1091 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1093 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1095 setConnectedState();
1099 void MainWin::setConnectedState()
1101 ActionCollection *coll = QtUi::actionCollection("General");
1103 coll->action("ConnectCore")->setEnabled(false);
1104 coll->action("DisconnectCore")->setEnabled(true);
1105 coll->action("ChangePassword")->setEnabled(true);
1106 coll->action("CoreInfo")->setEnabled(true);
1108 foreach(QAction *action, _fileMenu->actions()) {
1109 if (isRemoteCoreOnly(action))
1110 action->setVisible(!Client::internalCore());
1113 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1114 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1115 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1116 if (!Client::internalCore()) {
1117 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1118 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1119 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1122 // _viewMenu->setEnabled(true);
1123 if (!Client::internalCore())
1124 statusBar()->showMessage(tr("Connected to core."));
1126 statusBar()->clearMessage();
1128 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1130 systemTray()->setState(SystemTray::Active);
1132 if (Client::networkIds().isEmpty()) {
1133 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1137 // Monolithic always preselects last used buffer - Client only if the connection died
1138 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1140 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1141 if (lastUsedBufferId.isValid())
1142 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1148 void MainWin::loadLayout()
1151 int accountId = Client::currentCoreAccount().accountId().toInt();
1152 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1153 if (state.isEmpty()) {
1154 foreach(BufferViewDock *view, _bufferViews)
1156 _layoutLoaded = true;
1159 _nickListWidget->setVisible(true);
1160 restoreState(state, accountId);
1161 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1162 if (bufferViewId >= 0)
1163 changeActiveBufferView(bufferViewId);
1165 _layoutLoaded = true;
1169 void MainWin::saveLayout()
1172 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1173 if (accountId > 0) {
1174 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1175 BufferView *view = activeBufferView();
1176 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1181 void MainWin::disconnectedFromCore()
1183 // save core specific layout and remove bufferviews;
1185 _layoutLoaded = false;
1187 QVariant actionData;
1188 BufferViewDock *dock;
1189 foreach(QAction *action, _bufferViewsMenu->actions()) {
1190 actionData = action->data();
1191 if (!actionData.isValid())
1194 dock = qobject_cast<BufferViewDock *>(action->parent());
1195 if (dock && actionData.toInt() != -1) {
1196 removeAction(action);
1197 _bufferViews.removeAll(dock);
1198 dock->deleteLater();
1202 // store last active buffer
1204 BufferId lastBufId = _bufferWidget->currentBuffer();
1205 if (lastBufId.isValid()) {
1206 s.setValue("LastUsedBufferId", lastBufId.toInt());
1207 // clear the current selection
1208 Client::bufferModel()->standardSelectionModel()->clearSelection();
1210 restoreState(s.value("MainWinState").toByteArray());
1211 setDisconnectedState();
1215 void MainWin::setDisconnectedState()
1217 ActionCollection *coll = QtUi::actionCollection("General");
1218 //ui.menuCore->setEnabled(false);
1219 coll->action("ConnectCore")->setEnabled(true);
1220 coll->action("DisconnectCore")->setEnabled(false);
1221 coll->action("CoreInfo")->setEnabled(false);
1222 coll->action("ChangePassword")->setEnabled(false);
1223 //_viewMenu->setEnabled(false);
1224 statusBar()->showMessage(tr("Not connected to core."));
1225 if (_msgProcessorStatusWidget)
1226 _msgProcessorStatusWidget->setProgress(0, 0);
1228 systemTray()->setState(SystemTray::Passive);
1229 _nickListWidget->setVisible(false);
1233 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1235 Q_UNUSED(errorMessage)
1236 CoreConnectAuthDlg dlg(account, this);
1237 *valid = (dlg.exec() == QDialog::Accepted);
1241 void MainWin::handleNoSslInClient(bool *accepted)
1243 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client 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;
1251 void MainWin::handleNoSslInCore(bool *accepted)
1253 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1254 QMessageBox::Ignore|QMessageBox::Cancel, this);
1255 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1256 box.setDefaultButton(QMessageBox::Ignore);
1257 *accepted = box.exec() == QMessageBox::Ignore;
1263 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1265 QString errorString = "<ul>";
1266 foreach(const QSslError error, socket->sslErrors())
1267 errorString += QString("<li>%1</li>").arg(error.errorString());
1268 errorString += "</ul>";
1270 QMessageBox box(QMessageBox::Warning,
1271 tr("Untrusted Security Certificate"),
1272 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1273 QMessageBox::Cancel, this);
1274 box.setInformativeText(errorString);
1275 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1276 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1278 QMessageBox::ButtonRole role;
1281 role = box.buttonRole(box.clickedButton());
1282 if (role == QMessageBox::HelpRole) {
1283 SslInfoDlg dlg(socket, this);
1287 while (role == QMessageBox::HelpRole);
1289 *accepted = role == QMessageBox::AcceptRole;
1291 QMessageBox box2(QMessageBox::Warning,
1292 tr("Untrusted Security Certificate"),
1293 tr("Would you like to accept this certificate forever without being prompted?"),
1295 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1296 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1298 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1303 #endif /* HAVE_SSL */
1305 void MainWin::handleCoreConnectionError(const QString &error)
1307 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1311 void MainWin::showCoreConnectionDlg()
1313 CoreConnectDlg dlg(this);
1314 if (dlg.exec() == QDialog::Accepted) {
1315 AccountId accId = dlg.selectedAccount();
1316 if (accId.isValid())
1317 Client::coreConnection()->connectToCore(accId);
1322 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1324 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1330 void MainWin::showChannelList(NetworkId netId)
1332 ChannelListDlg *channelListDlg = new ChannelListDlg();
1334 if (!netId.isValid()) {
1335 QAction *action = qobject_cast<QAction *>(sender());
1337 netId = action->data().value<NetworkId>();
1340 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1341 channelListDlg->setNetwork(netId);
1342 channelListDlg->show();
1346 void MainWin::showIgnoreList(QString newRule)
1348 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1349 // prepare config dialog for new rule
1350 if (!newRule.isEmpty())
1351 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1356 void MainWin::showCoreInfoDlg()
1358 CoreInfoDlg(this).exec();
1362 void MainWin::showAwayLog()
1366 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1367 _awayLog = new AwayLogView(filter, 0);
1368 filter->setParent(_awayLog);
1369 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1370 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1375 void MainWin::awayLogDestroyed()
1381 void MainWin::showSettingsDlg()
1383 SettingsDlg *dlg = new SettingsDlg();
1385 //Category: Interface
1386 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1387 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1388 dlg->registerSettingsPage(new ChatViewColorSettingsPage(dlg));
1389 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1390 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1391 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1392 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1393 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1395 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1397 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1398 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1399 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1402 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1403 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1404 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1405 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1406 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1408 // Category: Remote Cores
1409 if (Quassel::runMode() != Quassel::Monolithic) {
1410 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1411 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1418 void MainWin::showAboutDlg()
1420 AboutDlg(this).exec();
1424 void MainWin::showShortcutsDlg()
1427 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1428 foreach(KActionCollection *coll, QtUi::actionCollections())
1429 dlg.addCollection(coll, coll->property("Category").toString());
1430 dlg.configure(true);
1432 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1438 void MainWin::showNewTransferDlg(const QUuid &transferId)
1440 auto transfer = Client::transferManager()->transfer(transferId);
1442 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1446 qWarning() << "Unknown transfer ID" << transferId;
1451 void MainWin::onFullScreenToggled()
1453 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1454 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1457 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1459 if (_fullScreenAction->isChecked())
1460 setWindowState(windowState() | Qt::WindowFullScreen);
1462 setWindowState(windowState() & ~Qt::WindowFullScreen);
1467 /********************************************************************************************************/
1469 bool MainWin::event(QEvent *event)
1471 switch(event->type()) {
1472 case QEvent::WindowActivate: {
1473 BufferId bufferId = Client::bufferModel()->currentBuffer();
1474 if (bufferId.isValid())
1475 Client::instance()->markBufferAsRead(bufferId);
1478 case QEvent::WindowDeactivate:
1479 if (bufferWidget()->autoMarkerLineOnLostFocus())
1480 bufferWidget()->setMarkerLine();
1485 return QMainWindow::event(event);
1489 void MainWin::moveEvent(QMoveEvent *event)
1491 if (!(windowState() & Qt::WindowMaximized))
1492 _normalPos = event->pos();
1494 QMainWindow::moveEvent(event);
1498 void MainWin::resizeEvent(QResizeEvent *event)
1500 if (!(windowState() & Qt::WindowMaximized))
1501 _normalSize = event->size();
1503 QMainWindow::resizeEvent(event);
1507 void MainWin::closeEvent(QCloseEvent *event)
1510 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1512 if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1513 QtUi::hideMainWidget();
1523 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1527 bool hasFocus = QApplication::activeWindow() != 0;
1529 for (int i = start; i <= end; i++) {
1530 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1531 if (!idx.isValid()) {
1532 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1535 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1536 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1539 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1540 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1542 // check if bufferId belongs to the shown chatlists
1543 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1544 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1547 // check if it's the buffer currently displayed
1548 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1551 // only show notifications for higlights or queries
1552 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1555 // and of course: don't notify for ignored messages
1556 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1559 // seems like we have a legit notification candidate!
1560 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1561 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1562 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1563 AbstractNotificationBackend::NotificationType type;
1565 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1566 type = AbstractNotificationBackend::PrivMsg;
1567 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1568 type = AbstractNotificationBackend::PrivMsgFocused;
1569 else if (flags & Message::Highlight && !hasFocus)
1570 type = AbstractNotificationBackend::Highlight;
1572 type = AbstractNotificationBackend::HighlightFocused;
1574 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1579 void MainWin::currentBufferChanged(BufferId buffer)
1581 if (buffer.isValid())
1582 Client::instance()->markBufferAsRead(buffer);
1586 void MainWin::clientNetworkCreated(NetworkId id)
1588 const Network *net = Client::network(id);
1589 QAction *act = new QAction(net->networkName(), this);
1590 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1591 act->setData(QVariant::fromValue<NetworkId>(id));
1592 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1593 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1595 QAction *beforeAction = 0;
1596 foreach(QAction *action, _networksMenu->actions()) {
1597 if (!action->data().isValid()) // ignore stock actions
1599 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1600 beforeAction = action;
1604 _networksMenu->insertAction(beforeAction, act);
1608 void MainWin::clientNetworkUpdated()
1610 const Network *net = qobject_cast<const Network *>(sender());
1614 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1618 action->setText(net->networkName());
1620 switch (net->connectionState()) {
1621 case Network::Initialized:
1622 action->setIcon(QIcon::fromTheme("network-connect"));
1623 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1624 if (!bufferWidget()->currentBuffer().isValid()) {
1625 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1626 if (idx.isValid()) {
1627 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1628 Client::bufferModel()->switchToBuffer(statusBufferId);
1632 case Network::Disconnected:
1633 action->setIcon(QIcon::fromTheme("network-disconnect"));
1636 action->setIcon(QIcon::fromTheme("network-wired"));
1641 void MainWin::clientNetworkRemoved(NetworkId id)
1643 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1647 action->deleteLater();
1651 void MainWin::connectOrDisconnectFromNet()
1653 QAction *act = qobject_cast<QAction *>(sender());
1655 const Network *net = Client::network(act->data().value<NetworkId>());
1657 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1658 else net->requestDisconnect();
1662 void MainWin::on_jumpHotBuffer_triggered()
1664 if (!_bufferHotList->rowCount())
1667 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1670 void MainWin::on_bufferSearch_triggered()
1672 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count()) {
1673 qWarning() << "Tried to activate filter on invalid bufferview:" << _activeBufferViewIndex;
1677 _bufferViews[_activeBufferViewIndex]->activateFilter();
1681 void MainWin::onJumpKey()
1683 QAction *action = qobject_cast<QAction *>(sender());
1684 if (!action || !Client::bufferModel())
1686 int idx = action->property("Index").toInt();
1688 if (_jumpKeyMap.isEmpty())
1689 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1691 if (!_jumpKeyMap.contains(idx))
1694 BufferId buffer = _jumpKeyMap.value(idx);
1695 if (buffer.isValid())
1696 Client::bufferModel()->switchToBuffer(buffer);
1700 void MainWin::bindJumpKey()
1702 QAction *action = qobject_cast<QAction *>(sender());
1703 if (!action || !Client::bufferModel())
1705 int idx = action->property("Index").toInt();
1707 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1708 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1712 void MainWin::on_actionDebugNetworkModel_triggered()
1714 QTreeView *view = new QTreeView;
1715 view->setAttribute(Qt::WA_DeleteOnClose);
1716 view->setWindowTitle("Debug NetworkModel View");
1717 view->setModel(Client::networkModel());
1718 view->setColumnWidth(0, 250);
1719 view->setColumnWidth(1, 250);
1720 view->setColumnWidth(2, 80);
1721 view->resize(610, 300);
1726 void MainWin::on_actionDebugHotList_triggered()
1728 _bufferHotList->invalidate();
1729 _bufferHotList->sort(0, Qt::DescendingOrder);
1731 QTreeView *view = new QTreeView;
1732 view->setAttribute(Qt::WA_DeleteOnClose);
1733 view->setModel(_bufferHotList);
1738 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1740 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1741 overlay->setAttribute(Qt::WA_DeleteOnClose);
1746 void MainWin::on_actionDebugMessageModel_triggered()
1748 QTableView *view = new QTableView(0);
1749 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1750 filter->setSourceModel(Client::messageModel());
1751 view->setModel(filter);
1752 view->setAttribute(Qt::WA_DeleteOnClose, true);
1753 view->verticalHeader()->hide();
1754 view->horizontalHeader()->setStretchLastSection(true);
1759 void MainWin::on_actionDebugLog_triggered()
1761 DebugLogWidget *logWidget = new DebugLogWidget(0);
1766 void MainWin::showStatusBarMessage(const QString &message)
1768 statusBar()->showMessage(message, 10000);