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)));
464 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
465 const int jumpModifier = Qt::ControlModifier;
467 const int bindModifier = Qt::ControlModifier;
468 const int jumpModifier = Qt::AltModifier;
471 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
472 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
473 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
474 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
475 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
476 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
477 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
478 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
479 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
480 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
481 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
482 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
483 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
484 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
485 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
486 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
487 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
488 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
489 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
490 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
492 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
493 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
494 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
495 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
496 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
497 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
498 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
499 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
500 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
501 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
502 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
503 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
504 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
505 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
506 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
507 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
508 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
509 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
510 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
511 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
514 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
515 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
516 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
517 this, SLOT(previousBufferView()), QKeySequence::Back));
518 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
519 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
520 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
521 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
525 void MainWin::setupMenus()
527 ActionCollection *coll = QtUi::actionCollection("General");
529 _fileMenu = menuBar()->addMenu(tr("&File"));
531 static const QStringList coreActions = QStringList()
532 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
535 foreach(QString actionName, coreActions) {
536 coreAction = coll->action(actionName);
537 _fileMenu->addAction(coreAction);
538 flagRemoteCoreOnly(coreAction);
540 flagRemoteCoreOnly(_fileMenu->addSeparator());
542 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
543 _networksMenu->addAction(coll->action("ConfigureNetworks"));
544 _networksMenu->addSeparator();
545 _fileMenu->addSeparator();
546 _fileMenu->addAction(coll->action("Quit"));
548 _viewMenu = menuBar()->addMenu(tr("&View"));
549 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
550 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
551 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
552 _viewMenu->addSeparator();
554 _viewMenu->addAction(coll->action("ToggleMenuBar"));
555 _viewMenu->addAction(coll->action("ToggleStatusBar"));
556 _viewMenu->addAction(coll->action("ToggleSearchBar"));
558 coreAction = coll->action("ShowAwayLog");
559 flagRemoteCoreOnly(coreAction);
560 _viewMenu->addAction(coreAction);
562 _viewMenu->addSeparator();
563 _viewMenu->addAction(coll->action("LockLayout"));
565 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
567 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
568 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
570 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
572 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
575 _helpMenu = menuBar()->addMenu(tr("&Help"));
577 _helpMenu->addAction(coll->action("AboutQuassel"));
579 _helpMenu->addAction(coll->action("AboutQt"));
581 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
583 _helpMenu->addSeparator();
584 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
585 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
586 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
587 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
588 _helpDebugMenu->addAction(coll->action("DebugHotList"));
589 _helpDebugMenu->addAction(coll->action("DebugLog"));
590 _helpDebugMenu->addSeparator();
591 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
594 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
596 QtUiSettings uiSettings;
597 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
598 showMenuBar->setChecked(enabled);
599 enabled ? menuBar()->show() : menuBar()->hide();
601 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
602 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
606 void MainWin::setupBufferWidget()
608 _bufferWidget = new BufferWidget(this);
609 _bufferWidget->setModel(Client::bufferModel());
610 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
611 setCentralWidget(_bufferWidget);
615 void MainWin::addBufferView(int bufferViewConfigId)
617 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
621 void MainWin::addBufferView(ClientBufferViewConfig *config)
626 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
627 BufferViewDock *dock = new BufferViewDock(config, this);
629 //create the view and initialize it's filter
630 BufferView *view = new BufferView(dock);
631 view->setFilteredModel(Client::bufferModel(), config);
632 view->installEventFilter(_inputWidget); // for key presses
634 Client::bufferModel()->synchronizeView(view);
636 dock->setWidget(view);
637 dock->setVisible(_layoutLoaded); // don't show before state has been restored
639 addDockWidget(Qt::LeftDockWidgetArea, dock);
640 _bufferViewsMenu->addAction(dock->toggleViewAction());
642 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
643 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
644 _bufferViews.append(dock);
646 if (!activeBufferView())
651 void MainWin::removeBufferView(int bufferViewConfigId)
654 BufferViewDock *dock;
655 foreach(QAction *action, _bufferViewsMenu->actions()) {
656 actionData = action->data();
657 if (!actionData.isValid())
660 dock = qobject_cast<BufferViewDock *>(action->parent());
661 if (dock && actionData.toInt() == bufferViewConfigId) {
662 removeAction(action);
663 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
664 _bufferViews.removeAll(dock);
666 if (dock->isActive()) {
667 dock->setActive(false);
668 _activeBufferViewIndex = -1;
678 void MainWin::bufferViewToggled(bool enabled)
680 if (!enabled && !isMinimized()) {
681 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
682 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
685 QAction *action = qobject_cast<QAction *>(sender());
687 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
690 // Make sure we don't toggle backlog fetch for a view we've already removed
691 if (!_bufferViews.contains(dock))
695 Client::bufferViewOverlay()->addView(dock->bufferViewId());
697 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
701 void MainWin::bufferViewVisibilityChanged(bool visible)
704 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
706 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
711 BufferView *MainWin::allBuffersView() const
713 // "All Buffers" is always the first dock created
714 if (_bufferViews.count() > 0)
715 return _bufferViews[0]->bufferView();
720 BufferView *MainWin::activeBufferView() const
722 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
724 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
725 return dock->isActive() ? qobject_cast<BufferView *>(dock->widget()) : 0;
729 void MainWin::changeActiveBufferView(int bufferViewId)
731 if (bufferViewId < 0)
734 BufferView *current = activeBufferView();
736 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
737 _activeBufferViewIndex = -1;
740 for (int i = 0; i < _bufferViews.count(); i++) {
741 BufferViewDock *dock = _bufferViews.at(i);
742 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
743 _activeBufferViewIndex = i;
744 dock->setActive(true);
749 nextBufferView(); // fallback
753 void MainWin::showPasswordChangeDlg()
755 if((Client::coreFeatures() & Quassel::PasswordChange)) {
756 PasswordChangeDlg dlg(this);
760 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
761 tr("<b>Your Quassel Core does not support this feature</b>"),
762 QMessageBox::Ok, this);
763 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
769 void MainWin::changeActiveBufferView(bool backwards)
771 BufferView *current = activeBufferView();
773 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
775 if (!_bufferViews.count())
778 int c = _bufferViews.count();
779 while (c--) { // yes, this will reactivate the current active one if all others fail
781 if (--_activeBufferViewIndex < 0)
782 _activeBufferViewIndex = _bufferViews.count()-1;
785 if (++_activeBufferViewIndex >= _bufferViews.count())
786 _activeBufferViewIndex = 0;
789 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
790 if (dock->isHidden())
793 dock->setActive(true);
797 _activeBufferViewIndex = -1;
801 void MainWin::nextBufferView()
803 changeActiveBufferView(false);
807 void MainWin::previousBufferView()
809 changeActiveBufferView(true);
813 void MainWin::nextBuffer()
815 BufferView *view = activeBufferView();
821 void MainWin::previousBuffer()
823 BufferView *view = activeBufferView();
825 view->previousBuffer();
829 void MainWin::hideCurrentBuffer()
831 BufferView *view = activeBufferView();
833 view->hideCurrentBuffer();
837 void MainWin::showNotificationsDlg()
839 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
844 void MainWin::on_actionConfigureNetworks_triggered()
846 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
851 void MainWin::on_actionConfigureViews_triggered()
853 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
858 void MainWin::on_actionLockLayout_toggled(bool lock)
860 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
861 foreach(VerticalDock *dock, docks) {
862 dock->showTitle(!lock);
864 if (Client::bufferViewManager()) {
865 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
866 config->setLocked(lock);
869 QtUiSettings().setValue("LockLayout", lock);
873 void MainWin::setupNickWidget()
876 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
877 nickDock->setObjectName("NickDock");
878 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
880 _nickListWidget = new NickListWidget(nickDock);
881 nickDock->setWidget(_nickListWidget);
883 addDockWidget(Qt::RightDockWidgetArea, nickDock);
884 _viewMenu->addAction(nickDock->toggleViewAction());
885 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
887 // See NickListDock::NickListDock();
888 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
890 // attach the NickListWidget to the BufferModel and the default selection
891 _nickListWidget->setModel(Client::bufferModel());
892 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
894 _nickListWidget->setVisible(false);
898 void MainWin::setupChatMonitor()
900 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
901 dock->setObjectName("ChatMonitorDock");
903 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
904 _chatMonitorView = new ChatMonitorView(filter, this);
905 _chatMonitorView->setFocusProxy(_inputWidget);
906 _chatMonitorView->show();
907 dock->setWidget(_chatMonitorView);
910 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
911 _viewMenu->addAction(dock->toggleViewAction());
912 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
916 void MainWin::setupInputWidget()
918 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
919 dock->setObjectName("InputDock");
921 _inputWidget = new InputWidget(dock);
922 dock->setWidget(_inputWidget);
924 addDockWidget(Qt::BottomDockWidgetArea, dock);
926 _viewMenu->addAction(dock->toggleViewAction());
927 dock->toggleViewAction()->setText(tr("Show Input Line"));
929 _inputWidget->setModel(Client::bufferModel());
930 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
932 _bufferWidget->setFocusProxy(_inputWidget);
934 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
936 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
940 void MainWin::setupTopicWidget()
942 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
943 dock->setObjectName("TopicDock");
944 _topicWidget = new TopicWidget(dock);
946 dock->setWidget(_topicWidget);
948 _topicWidget->setModel(Client::bufferModel());
949 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
951 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
953 _viewMenu->addAction(dock->toggleViewAction());
954 dock->toggleViewAction()->setText(tr("Show Topic Line"));
958 void MainWin::setupViewMenuTail()
960 _viewMenu->addSeparator();
961 _viewMenu->addAction(_fullScreenAction);
965 void MainWin::setupTitleSetter()
967 _titleSetter.setModel(Client::bufferModel());
968 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
972 void MainWin::setupStatusBar()
974 // MessageProcessor progress
975 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
978 _coreConnectionStatusWidget->update();
979 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
981 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
983 QtUiSettings uiSettings;
985 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
986 showStatusbar->setChecked(enabled);
987 enabled ? statusBar()->show() : statusBar()->hide();
989 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
990 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
992 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
996 void MainWin::setupHotList()
998 FlatProxyModel *flatProxy = new FlatProxyModel(this);
999 flatProxy->setSourceModel(Client::bufferModel());
1000 _bufferHotList = new BufferHotListFilter(flatProxy);
1004 void MainWin::saveMenuBarStatus(bool enabled)
1006 QtUiSettings uiSettings;
1007 uiSettings.setValue("ShowMenuBar", enabled);
1011 void MainWin::saveStatusBarStatus(bool enabled)
1013 QtUiSettings uiSettings;
1014 uiSettings.setValue("ShowStatusBar", enabled);
1018 void MainWin::setupSystray()
1021 _systemTray = new StatusNotifierItem(this);
1022 #elif !defined QT_NO_SYSTEMTRAYICON
1023 _systemTray = new LegacySystemTray(this);
1025 _systemTray = new SystemTray(this); // dummy
1027 _systemTray->init();
1031 void MainWin::setupToolBars()
1033 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1034 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1035 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1036 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1039 setUnifiedTitleAndToolBarOnMac(true);
1043 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1045 _mainToolBar = new QToolBar(this);
1046 _mainToolBar->setObjectName("MainToolBar");
1048 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1049 addToolBar(_mainToolBar);
1051 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1052 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1055 QtUiSettings uiSettings;
1057 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1058 _mainToolBar->setVisible(visible);
1059 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1063 void MainWin::saveMainToolBarStatus(bool enabled)
1066 QtUiSettings uiSettings;
1067 uiSettings.setValue("ShowMainToolBar", enabled);
1074 void MainWin::connectedToCore()
1076 Q_CHECK_PTR(Client::bufferViewManager());
1077 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1078 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1079 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1081 connect(Client::transferManager(), SIGNAL(transferAdded(QUuid)), SLOT(showNewTransferDlg(QUuid)));
1083 setConnectedState();
1087 void MainWin::setConnectedState()
1089 ActionCollection *coll = QtUi::actionCollection("General");
1091 coll->action("ConnectCore")->setEnabled(false);
1092 coll->action("DisconnectCore")->setEnabled(true);
1093 coll->action("ChangePassword")->setEnabled(true);
1094 coll->action("CoreInfo")->setEnabled(true);
1096 foreach(QAction *action, _fileMenu->actions()) {
1097 if (isRemoteCoreOnly(action))
1098 action->setVisible(!Client::internalCore());
1101 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1102 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1103 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1104 if (!Client::internalCore()) {
1105 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1106 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1107 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1110 // _viewMenu->setEnabled(true);
1111 if (!Client::internalCore())
1112 statusBar()->showMessage(tr("Connected to core."));
1114 statusBar()->clearMessage();
1116 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1118 systemTray()->setState(SystemTray::Active);
1120 if (Client::networkIds().isEmpty()) {
1121 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1125 // Monolithic always preselects last used buffer - Client only if the connection died
1126 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1128 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1129 if (lastUsedBufferId.isValid())
1130 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1136 void MainWin::loadLayout()
1139 int accountId = Client::currentCoreAccount().accountId().toInt();
1140 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1141 if (state.isEmpty()) {
1142 foreach(BufferViewDock *view, _bufferViews)
1144 _layoutLoaded = true;
1147 _nickListWidget->setVisible(true);
1148 restoreState(state, accountId);
1149 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1150 if (bufferViewId >= 0)
1151 changeActiveBufferView(bufferViewId);
1153 _layoutLoaded = true;
1157 void MainWin::saveLayout()
1160 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1161 if (accountId > 0) {
1162 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1163 BufferView *view = activeBufferView();
1164 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1169 void MainWin::disconnectedFromCore()
1171 // save core specific layout and remove bufferviews;
1173 _layoutLoaded = false;
1175 QVariant actionData;
1176 BufferViewDock *dock;
1177 foreach(QAction *action, _bufferViewsMenu->actions()) {
1178 actionData = action->data();
1179 if (!actionData.isValid())
1182 dock = qobject_cast<BufferViewDock *>(action->parent());
1183 if (dock && actionData.toInt() != -1) {
1184 removeAction(action);
1185 _bufferViews.removeAll(dock);
1186 dock->deleteLater();
1190 // store last active buffer
1192 BufferId lastBufId = _bufferWidget->currentBuffer();
1193 if (lastBufId.isValid()) {
1194 s.setValue("LastUsedBufferId", lastBufId.toInt());
1195 // clear the current selection
1196 Client::bufferModel()->standardSelectionModel()->clearSelection();
1198 restoreState(s.value("MainWinState").toByteArray());
1199 setDisconnectedState();
1203 void MainWin::setDisconnectedState()
1205 ActionCollection *coll = QtUi::actionCollection("General");
1206 //ui.menuCore->setEnabled(false);
1207 coll->action("ConnectCore")->setEnabled(true);
1208 coll->action("DisconnectCore")->setEnabled(false);
1209 coll->action("CoreInfo")->setEnabled(false);
1210 coll->action("ChangePassword")->setEnabled(false);
1211 //_viewMenu->setEnabled(false);
1212 statusBar()->showMessage(tr("Not connected to core."));
1213 if (_msgProcessorStatusWidget)
1214 _msgProcessorStatusWidget->setProgress(0, 0);
1216 systemTray()->setState(SystemTray::Passive);
1217 _nickListWidget->setVisible(false);
1221 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1223 Q_UNUSED(errorMessage)
1224 CoreConnectAuthDlg dlg(account, this);
1225 *valid = (dlg.exec() == QDialog::Accepted);
1229 void MainWin::handleNoSslInClient(bool *accepted)
1231 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1232 QMessageBox::Ignore|QMessageBox::Cancel, this);
1233 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1234 box.setDefaultButton(QMessageBox::Ignore);
1235 *accepted = box.exec() == QMessageBox::Ignore;
1239 void MainWin::handleNoSslInCore(bool *accepted)
1241 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1242 QMessageBox::Ignore|QMessageBox::Cancel, this);
1243 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1244 box.setDefaultButton(QMessageBox::Ignore);
1245 *accepted = box.exec() == QMessageBox::Ignore;
1251 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1253 QString errorString = "<ul>";
1254 foreach(const QSslError error, socket->sslErrors())
1255 errorString += QString("<li>%1</li>").arg(error.errorString());
1256 errorString += "</ul>";
1258 QMessageBox box(QMessageBox::Warning,
1259 tr("Untrusted Security Certificate"),
1260 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1261 QMessageBox::Cancel, this);
1262 box.setInformativeText(errorString);
1263 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1264 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1266 QMessageBox::ButtonRole role;
1269 role = box.buttonRole(box.clickedButton());
1270 if (role == QMessageBox::HelpRole) {
1271 SslInfoDlg dlg(socket, this);
1275 while (role == QMessageBox::HelpRole);
1277 *accepted = role == QMessageBox::AcceptRole;
1279 QMessageBox box2(QMessageBox::Warning,
1280 tr("Untrusted Security Certificate"),
1281 tr("Would you like to accept this certificate forever without being prompted?"),
1283 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1284 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1286 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1291 #endif /* HAVE_SSL */
1293 void MainWin::handleCoreConnectionError(const QString &error)
1295 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1299 void MainWin::showCoreConnectionDlg()
1301 CoreConnectDlg dlg(this);
1302 if (dlg.exec() == QDialog::Accepted) {
1303 AccountId accId = dlg.selectedAccount();
1304 if (accId.isValid())
1305 Client::coreConnection()->connectToCore(accId);
1310 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1312 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1318 void MainWin::showChannelList(NetworkId netId)
1320 ChannelListDlg *channelListDlg = new ChannelListDlg();
1322 if (!netId.isValid()) {
1323 QAction *action = qobject_cast<QAction *>(sender());
1325 netId = action->data().value<NetworkId>();
1328 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1329 channelListDlg->setNetwork(netId);
1330 channelListDlg->show();
1334 void MainWin::showIgnoreList(QString newRule)
1336 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1337 // prepare config dialog for new rule
1338 if (!newRule.isEmpty())
1339 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1344 void MainWin::showCoreInfoDlg()
1346 CoreInfoDlg(this).exec();
1350 void MainWin::showAwayLog()
1354 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1355 _awayLog = new AwayLogView(filter, 0);
1356 filter->setParent(_awayLog);
1357 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1358 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1363 void MainWin::awayLogDestroyed()
1369 void MainWin::showSettingsDlg()
1371 SettingsDlg *dlg = new SettingsDlg();
1373 //Category: Interface
1374 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1375 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1376 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1377 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1378 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1379 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1380 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1382 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1384 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1385 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1386 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1389 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1390 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1391 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1392 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1393 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1395 // Category: Remote Cores
1396 if (Quassel::runMode() != Quassel::Monolithic) {
1397 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1398 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1405 void MainWin::showAboutDlg()
1407 AboutDlg(this).exec();
1411 void MainWin::showShortcutsDlg()
1414 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1415 foreach(KActionCollection *coll, QtUi::actionCollections())
1416 dlg.addCollection(coll, coll->property("Category").toString());
1417 dlg.configure(true);
1419 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1425 void MainWin::showNewTransferDlg(const QUuid &transferId)
1427 auto transfer = Client::transferManager()->transfer(transferId);
1429 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1433 qWarning() << "Unknown transfer ID" << transferId;
1438 void MainWin::onFullScreenToggled()
1440 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1441 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1444 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1446 if (_fullScreenAction->isChecked())
1447 setWindowState(windowState() | Qt::WindowFullScreen);
1449 setWindowState(windowState() & ~Qt::WindowFullScreen);
1454 /********************************************************************************************************/
1456 bool MainWin::event(QEvent *event)
1458 switch(event->type()) {
1459 case QEvent::WindowActivate: {
1460 BufferId bufferId = Client::bufferModel()->currentBuffer();
1461 if (bufferId.isValid())
1462 Client::instance()->markBufferAsRead(bufferId);
1465 case QEvent::WindowDeactivate:
1466 if (bufferWidget()->autoMarkerLineOnLostFocus())
1467 bufferWidget()->setMarkerLine();
1472 return QMainWindow::event(event);
1476 void MainWin::moveEvent(QMoveEvent *event)
1478 if (!(windowState() & Qt::WindowMaximized))
1479 _normalPos = event->pos();
1481 QMainWindow::moveEvent(event);
1485 void MainWin::resizeEvent(QResizeEvent *event)
1487 if (!(windowState() & Qt::WindowMaximized))
1488 _normalSize = event->size();
1490 QMainWindow::resizeEvent(event);
1494 void MainWin::closeEvent(QCloseEvent *event)
1497 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1499 if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1500 QtUi::hideMainWidget();
1510 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1514 bool hasFocus = QApplication::activeWindow() != 0;
1516 for (int i = start; i <= end; i++) {
1517 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1518 if (!idx.isValid()) {
1519 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1522 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1523 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1526 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1527 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1529 // check if bufferId belongs to the shown chatlists
1530 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1531 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1534 // check if it's the buffer currently displayed
1535 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1538 // only show notifications for higlights or queries
1539 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1542 // and of course: don't notify for ignored messages
1543 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1546 // seems like we have a legit notification candidate!
1547 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1548 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1549 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1550 AbstractNotificationBackend::NotificationType type;
1552 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1553 type = AbstractNotificationBackend::PrivMsg;
1554 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1555 type = AbstractNotificationBackend::PrivMsgFocused;
1556 else if (flags & Message::Highlight && !hasFocus)
1557 type = AbstractNotificationBackend::Highlight;
1559 type = AbstractNotificationBackend::HighlightFocused;
1561 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1566 void MainWin::currentBufferChanged(BufferId buffer)
1568 if (buffer.isValid())
1569 Client::instance()->markBufferAsRead(buffer);
1573 void MainWin::clientNetworkCreated(NetworkId id)
1575 const Network *net = Client::network(id);
1576 QAction *act = new QAction(net->networkName(), this);
1577 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1578 act->setData(QVariant::fromValue<NetworkId>(id));
1579 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1580 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1582 QAction *beforeAction = 0;
1583 foreach(QAction *action, _networksMenu->actions()) {
1584 if (!action->data().isValid()) // ignore stock actions
1586 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1587 beforeAction = action;
1591 _networksMenu->insertAction(beforeAction, act);
1595 void MainWin::clientNetworkUpdated()
1597 const Network *net = qobject_cast<const Network *>(sender());
1601 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1605 action->setText(net->networkName());
1607 switch (net->connectionState()) {
1608 case Network::Initialized:
1609 action->setIcon(QIcon::fromTheme("network-connect"));
1610 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1611 if (!bufferWidget()->currentBuffer().isValid()) {
1612 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1613 if (idx.isValid()) {
1614 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1615 Client::bufferModel()->switchToBuffer(statusBufferId);
1619 case Network::Disconnected:
1620 action->setIcon(QIcon::fromTheme("network-disconnect"));
1623 action->setIcon(QIcon::fromTheme("network-wired"));
1628 void MainWin::clientNetworkRemoved(NetworkId id)
1630 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1634 action->deleteLater();
1638 void MainWin::connectOrDisconnectFromNet()
1640 QAction *act = qobject_cast<QAction *>(sender());
1642 const Network *net = Client::network(act->data().value<NetworkId>());
1644 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1645 else net->requestDisconnect();
1649 void MainWin::on_jumpHotBuffer_triggered()
1651 if (!_bufferHotList->rowCount())
1654 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1658 void MainWin::onJumpKey()
1660 QAction *action = qobject_cast<QAction *>(sender());
1661 if (!action || !Client::bufferModel())
1663 int idx = action->property("Index").toInt();
1665 if (_jumpKeyMap.isEmpty())
1666 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1668 if (!_jumpKeyMap.contains(idx))
1671 BufferId buffer = _jumpKeyMap.value(idx);
1672 if (buffer.isValid())
1673 Client::bufferModel()->switchToBuffer(buffer);
1677 void MainWin::bindJumpKey()
1679 QAction *action = qobject_cast<QAction *>(sender());
1680 if (!action || !Client::bufferModel())
1682 int idx = action->property("Index").toInt();
1684 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1685 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1689 void MainWin::on_actionDebugNetworkModel_triggered()
1691 QTreeView *view = new QTreeView;
1692 view->setAttribute(Qt::WA_DeleteOnClose);
1693 view->setWindowTitle("Debug NetworkModel View");
1694 view->setModel(Client::networkModel());
1695 view->setColumnWidth(0, 250);
1696 view->setColumnWidth(1, 250);
1697 view->setColumnWidth(2, 80);
1698 view->resize(610, 300);
1703 void MainWin::on_actionDebugHotList_triggered()
1705 _bufferHotList->invalidate();
1706 _bufferHotList->sort(0, Qt::DescendingOrder);
1708 QTreeView *view = new QTreeView;
1709 view->setAttribute(Qt::WA_DeleteOnClose);
1710 view->setModel(_bufferHotList);
1715 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1717 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1718 overlay->setAttribute(Qt::WA_DeleteOnClose);
1723 void MainWin::on_actionDebugMessageModel_triggered()
1725 QTableView *view = new QTableView(0);
1726 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1727 filter->setSourceModel(Client::messageModel());
1728 view->setModel(filter);
1729 view->setAttribute(Qt::WA_DeleteOnClose, true);
1730 view->verticalHeader()->hide();
1731 view->horizontalHeader()->setStretchLastSection(true);
1736 void MainWin::on_actionDebugLog_triggered()
1738 DebugLogWidget *logWidget = new DebugLogWidget(0);
1743 void MainWin::showStatusBarMessage(const QString &message)
1745 statusBar()->showMessage(message, 10000);