1 /***************************************************************************
2 * Copyright (C) 2005-2015 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"
105 # include "phononnotificationbackend.h"
107 # ifdef HAVE_LIBSNORE
108 # include "snorenotificationbackend.h"
110 # include "systraynotificationbackend.h"
111 # include "taskbarnotificationbackend.h"
113 # include "knotificationbackend.h"
114 #endif /* HAVE_KDE */
117 # include "sslinfodlg.h"
120 #ifdef HAVE_INDICATEQT
121 #include "indicatornotificationbackend.h"
124 #ifdef HAVE_NOTIFICATION_CENTER
125 #include "osxnotificationbackend.h"
129 #include "dockmanagernotificationbackend.h"
132 #include "settingspages/aliasessettingspage.h"
133 #include "settingspages/appearancesettingspage.h"
134 #include "settingspages/backlogsettingspage.h"
135 #include "settingspages/bufferviewsettingspage.h"
136 #include "settingspages/chatmonitorsettingspage.h"
137 #include "settingspages/chatviewsettingspage.h"
138 #include "settingspages/connectionsettingspage.h"
139 #include "settingspages/coreaccountsettingspage.h"
140 #include "settingspages/coreconnectionsettingspage.h"
141 #include "settingspages/highlightsettingspage.h"
142 #include "settingspages/identitiessettingspage.h"
143 #include "settingspages/ignorelistsettingspage.h"
144 #include "settingspages/inputwidgetsettingspage.h"
145 #include "settingspages/itemviewsettingspage.h"
146 #include "settingspages/networkssettingspage.h"
147 #include "settingspages/notificationssettingspage.h"
148 #include "settingspages/topicwidgetsettingspage.h"
151 # include "settingspages/shortcutssettingspage.h"
155 # include "settingspages/sonnetsettingspage.h"
159 MainWin::MainWin(QWidget *parent)
161 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
163 : QMainWindow(parent),
165 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
166 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
169 _layoutLoaded(false),
170 _activeBufferViewIndex(-1)
172 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
174 QtUiSettings uiSettings;
175 QString style = uiSettings.value("Style", QString()).toString();
176 if (!style.isEmpty()) {
177 QApplication::setStyle(style);
180 QApplication::setQuitOnLastWindowClosed(false);
182 setWindowTitle("Quassel IRC");
183 setWindowIconText("Quassel IRC");
190 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
191 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
192 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
193 SLOT(messagesInserted(const QModelIndex &, int, int)));
194 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
195 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
197 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
198 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
199 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
200 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
201 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
203 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
207 setDockNestingEnabled(true);
208 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
209 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
210 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
211 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
213 // Order is sometimes important
230 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
232 # ifdef HAVE_LIBSNORE
233 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
234 # elif !defined(QT_NO_SYSTEMTRAYICON)
235 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
238 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
241 QtUi::registerNotificationBackend(new KNotificationBackend(this));
242 #endif /* HAVE_KDE */
244 #ifdef HAVE_INDICATEQT
245 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
248 #ifdef HAVE_NOTIFICATION_CENTER
249 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
253 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
256 // we assume that at this point, all configurable actions are defined!
257 QtUi::loadShortcuts();
259 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
261 setDisconnectedState(); // Disable menus and stuff
264 setAutoSaveSettings();
267 // restore mainwin state
269 restoreStateFromSettings(s);
271 // restore locked state of docks
272 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
274 CoreConnection *conn = Client::coreConnection();
275 if (!conn->connectToCore()) {
276 // No autoconnect selected (or no accounts)
277 showCoreConnectionDlg();
290 saveStateToSettings(s);
292 QApplication::quit();
296 void MainWin::saveStateToSettings(UiSettings &s)
298 s.setValue("MainWinSize", _normalSize);
299 s.setValue("MainWinPos", _normalPos);
300 s.setValue("MainWinState", saveState());
301 s.setValue("MainWinGeometry", saveGeometry());
302 s.setValue("MainWinMinimized", isMinimized());
303 s.setValue("MainWinMaximized", isMaximized());
304 s.setValue("MainWinHidden", !isVisible());
305 BufferId lastBufId = Client::bufferModel()->currentBuffer();
306 if (lastBufId.isValid())
307 s.setValue("LastUsedBufferId", lastBufId.toInt());
310 saveAutoSaveSettings();
315 void MainWin::restoreStateFromSettings(UiSettings &s)
317 _normalSize = s.value("MainWinSize", size()).toSize();
318 _normalPos = s.value("MainWinPos", pos()).toPoint();
319 bool maximized = s.value("MainWinMaximized", false).toBool();
322 restoreGeometry(s.value("MainWinGeometry").toByteArray());
325 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
330 restoreState(s.value("MainWinState").toByteArray());
336 if ((Quassel::isOptionSet("hidewindow")
337 || s.value("MainWinHidden").toBool())
338 && _systemTray->isSystemTrayAvailable())
339 QtUi::hideMainWidget();
340 else if (s.value("MainWinMinimized").toBool())
349 void MainWin::updateIcon()
352 if (Client::isConnected())
353 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
355 icon = QIcon::fromTheme("quassel-inactive", QIcon(":/icons/quassel-128.png"));
357 qApp->setWindowIcon(icon);
361 void MainWin::setupActions()
363 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
365 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("network-connect"), tr("&Connect to Core..."), coll,
366 this, SLOT(showCoreConnectionDlg())));
367 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("network-disconnect"), tr("&Disconnect from Core"), coll,
368 Client::instance(), SLOT(disconnectFromCore())));
369 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
370 this, SLOT(showPasswordChangeDlg())));
371 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
372 this, SLOT(showCoreInfoDlg())));
373 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
374 this, SLOT(on_actionConfigureNetworks_triggered())));
375 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
376 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
377 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
380 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
381 this, SLOT(on_actionConfigureViews_triggered())));
383 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
384 lockAct->setCheckable(true);
385 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
387 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
388 0, 0, QKeySequence::Find))->setCheckable(true);
389 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
390 this, SLOT(showAwayLog())));
391 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
392 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
394 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
395 0, 0))->setCheckable(true);
398 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
400 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
401 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
402 _fullScreenAction->setCheckable(true);
403 coll->addAction("ToggleFullScreen", _fullScreenAction);
407 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
408 this, SLOT(showShortcutsDlg()));
409 configureShortcutsAct->setMenuRole(QAction::NoRole);
410 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
413 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
414 this, SLOT(showSettingsDlg()));
415 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
417 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
418 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
420 coll->addAction("ConfigureQuassel", configureQuasselAct);
423 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
424 this, SLOT(showAboutDlg()));
425 aboutQuasselAct->setMenuRole(QAction::AboutRole);
426 coll->addAction("AboutQuassel", aboutQuasselAct);
428 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
429 qApp, SLOT(aboutQt()));
430 aboutQtAct->setMenuRole(QAction::AboutQtRole);
431 coll->addAction("AboutQt", aboutQtAct);
432 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
433 this, SLOT(on_actionDebugNetworkModel_triggered())));
434 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
435 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
436 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
437 this, SLOT(on_actionDebugMessageModel_triggered())));
438 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
439 this, SLOT(on_actionDebugHotList_triggered())));
440 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
441 this, SLOT(on_actionDebugLog_triggered())));
442 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
443 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
445 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
446 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
449 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
451 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
452 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
456 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
457 const int jumpModifier = Qt::ControlModifier;
459 const int bindModifier = Qt::ControlModifier;
460 const int jumpModifier = Qt::AltModifier;
463 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
464 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
465 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
466 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
467 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
468 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
469 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
470 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
471 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
472 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
473 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
474 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
475 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
476 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
477 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
478 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
479 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
480 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
481 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
482 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
484 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
485 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
486 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
487 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
488 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
489 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
490 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
491 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
492 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
493 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
494 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
495 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
496 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
497 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
498 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
499 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
500 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
501 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
502 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
503 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
506 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
507 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
508 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
509 this, SLOT(previousBufferView()), QKeySequence::Back));
510 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
511 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
512 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
513 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
517 void MainWin::setupMenus()
519 ActionCollection *coll = QtUi::actionCollection("General");
521 _fileMenu = menuBar()->addMenu(tr("&File"));
523 static const QStringList coreActions = QStringList()
524 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
527 foreach(QString actionName, coreActions) {
528 coreAction = coll->action(actionName);
529 _fileMenu->addAction(coreAction);
530 flagRemoteCoreOnly(coreAction);
532 flagRemoteCoreOnly(_fileMenu->addSeparator());
534 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
535 _networksMenu->addAction(coll->action("ConfigureNetworks"));
536 _networksMenu->addSeparator();
537 _fileMenu->addSeparator();
538 _fileMenu->addAction(coll->action("Quit"));
540 _viewMenu = menuBar()->addMenu(tr("&View"));
541 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
542 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
543 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
544 _viewMenu->addSeparator();
546 _viewMenu->addAction(coll->action("ToggleMenuBar"));
547 _viewMenu->addAction(coll->action("ToggleStatusBar"));
548 _viewMenu->addAction(coll->action("ToggleSearchBar"));
550 coreAction = coll->action("ShowAwayLog");
551 flagRemoteCoreOnly(coreAction);
552 _viewMenu->addAction(coreAction);
554 _viewMenu->addSeparator();
555 _viewMenu->addAction(coll->action("LockLayout"));
557 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
559 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
560 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
562 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
564 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
567 _helpMenu = menuBar()->addMenu(tr("&Help"));
569 _helpMenu->addAction(coll->action("AboutQuassel"));
571 _helpMenu->addAction(coll->action("AboutQt"));
573 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
575 _helpMenu->addSeparator();
576 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
577 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
578 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
579 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
580 _helpDebugMenu->addAction(coll->action("DebugHotList"));
581 _helpDebugMenu->addAction(coll->action("DebugLog"));
582 _helpDebugMenu->addSeparator();
583 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
586 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
588 QtUiSettings uiSettings;
589 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
590 showMenuBar->setChecked(enabled);
591 enabled ? menuBar()->show() : menuBar()->hide();
593 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
594 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
598 void MainWin::setupBufferWidget()
600 _bufferWidget = new BufferWidget(this);
601 _bufferWidget->setModel(Client::bufferModel());
602 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
603 setCentralWidget(_bufferWidget);
607 void MainWin::addBufferView(int bufferViewConfigId)
609 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
613 void MainWin::addBufferView(ClientBufferViewConfig *config)
618 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
619 BufferViewDock *dock = new BufferViewDock(config, this);
621 //create the view and initialize it's filter
622 BufferView *view = new BufferView(dock);
623 view->setFilteredModel(Client::bufferModel(), config);
624 view->installEventFilter(_inputWidget); // for key presses
626 Client::bufferModel()->synchronizeView(view);
628 dock->setWidget(view);
629 dock->setVisible(_layoutLoaded); // don't show before state has been restored
631 addDockWidget(Qt::LeftDockWidgetArea, dock);
632 _bufferViewsMenu->addAction(dock->toggleViewAction());
634 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
635 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
636 _bufferViews.append(dock);
638 if (!activeBufferView())
643 void MainWin::removeBufferView(int bufferViewConfigId)
646 BufferViewDock *dock;
647 foreach(QAction *action, _bufferViewsMenu->actions()) {
648 actionData = action->data();
649 if (!actionData.isValid())
652 dock = qobject_cast<BufferViewDock *>(action->parent());
653 if (dock && actionData.toInt() == bufferViewConfigId) {
654 removeAction(action);
655 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
656 _bufferViews.removeAll(dock);
658 if (dock->isActive()) {
659 dock->setActive(false);
660 _activeBufferViewIndex = -1;
670 void MainWin::bufferViewToggled(bool enabled)
672 if (!enabled && !isMinimized()) {
673 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
674 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
677 QAction *action = qobject_cast<QAction *>(sender());
679 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
682 // Make sure we don't toggle backlog fetch for a view we've already removed
683 if (!_bufferViews.contains(dock))
687 Client::bufferViewOverlay()->addView(dock->bufferViewId());
689 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
693 void MainWin::bufferViewVisibilityChanged(bool visible)
696 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
698 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
703 BufferView *MainWin::allBuffersView() const
705 // "All Buffers" is always the first dock created
706 if (_bufferViews.count() > 0)
707 return _bufferViews[0]->bufferView();
712 BufferView *MainWin::activeBufferView() const
714 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
716 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
717 return dock->isActive() ? qobject_cast<BufferView *>(dock->widget()) : 0;
721 void MainWin::changeActiveBufferView(int bufferViewId)
723 if (bufferViewId < 0)
726 BufferView *current = activeBufferView();
728 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
729 _activeBufferViewIndex = -1;
732 for (int i = 0; i < _bufferViews.count(); i++) {
733 BufferViewDock *dock = _bufferViews.at(i);
734 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
735 _activeBufferViewIndex = i;
736 dock->setActive(true);
741 nextBufferView(); // fallback
745 void MainWin::showPasswordChangeDlg()
747 if((Client::coreFeatures() & Quassel::PasswordChange)) {
748 PasswordChangeDlg dlg(this);
752 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
753 tr("<b>Your Quassel Core does not support this feature</b>"),
754 QMessageBox::Ok, this);
755 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
761 void MainWin::changeActiveBufferView(bool backwards)
763 BufferView *current = activeBufferView();
765 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
767 if (!_bufferViews.count())
770 int c = _bufferViews.count();
771 while (c--) { // yes, this will reactivate the current active one if all others fail
773 if (--_activeBufferViewIndex < 0)
774 _activeBufferViewIndex = _bufferViews.count()-1;
777 if (++_activeBufferViewIndex >= _bufferViews.count())
778 _activeBufferViewIndex = 0;
781 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
782 if (dock->isHidden())
785 dock->setActive(true);
789 _activeBufferViewIndex = -1;
793 void MainWin::nextBufferView()
795 changeActiveBufferView(false);
799 void MainWin::previousBufferView()
801 changeActiveBufferView(true);
805 void MainWin::nextBuffer()
807 BufferView *view = activeBufferView();
813 void MainWin::previousBuffer()
815 BufferView *view = activeBufferView();
817 view->previousBuffer();
821 void MainWin::hideCurrentBuffer()
823 BufferView *view = activeBufferView();
825 view->hideCurrentBuffer();
829 void MainWin::showNotificationsDlg()
831 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
836 void MainWin::on_actionConfigureNetworks_triggered()
838 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
843 void MainWin::on_actionConfigureViews_triggered()
845 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
850 void MainWin::on_actionLockLayout_toggled(bool lock)
852 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
853 foreach(VerticalDock *dock, docks) {
854 dock->showTitle(!lock);
856 if (Client::bufferViewManager()) {
857 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
858 config->setLocked(lock);
861 QtUiSettings().setValue("LockLayout", lock);
865 void MainWin::setupNickWidget()
868 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
869 nickDock->setObjectName("NickDock");
870 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
872 _nickListWidget = new NickListWidget(nickDock);
873 nickDock->setWidget(_nickListWidget);
875 addDockWidget(Qt::RightDockWidgetArea, nickDock);
876 _viewMenu->addAction(nickDock->toggleViewAction());
877 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
879 // See NickListDock::NickListDock();
880 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
882 // attach the NickListWidget to the BufferModel and the default selection
883 _nickListWidget->setModel(Client::bufferModel());
884 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
888 void MainWin::setupChatMonitor()
890 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
891 dock->setObjectName("ChatMonitorDock");
893 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
894 _chatMonitorView = new ChatMonitorView(filter, this);
895 _chatMonitorView->setFocusProxy(_inputWidget);
896 _chatMonitorView->show();
897 dock->setWidget(_chatMonitorView);
900 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
901 _viewMenu->addAction(dock->toggleViewAction());
902 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
906 void MainWin::setupInputWidget()
908 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
909 dock->setObjectName("InputDock");
911 _inputWidget = new InputWidget(dock);
912 dock->setWidget(_inputWidget);
914 addDockWidget(Qt::BottomDockWidgetArea, dock);
916 _viewMenu->addAction(dock->toggleViewAction());
917 dock->toggleViewAction()->setText(tr("Show Input Line"));
919 _inputWidget->setModel(Client::bufferModel());
920 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
922 _bufferWidget->setFocusProxy(_inputWidget);
924 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
926 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
930 void MainWin::setupTopicWidget()
932 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
933 dock->setObjectName("TopicDock");
934 _topicWidget = new TopicWidget(dock);
936 dock->setWidget(_topicWidget);
938 _topicWidget->setModel(Client::bufferModel());
939 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
941 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
943 _viewMenu->addAction(dock->toggleViewAction());
944 dock->toggleViewAction()->setText(tr("Show Topic Line"));
948 void MainWin::setupViewMenuTail()
950 _viewMenu->addSeparator();
951 _viewMenu->addAction(_fullScreenAction);
955 void MainWin::setupTitleSetter()
957 _titleSetter.setModel(Client::bufferModel());
958 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
962 void MainWin::setupStatusBar()
964 // MessageProcessor progress
965 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
968 _coreConnectionStatusWidget->update();
969 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
971 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
973 QtUiSettings uiSettings;
975 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
976 showStatusbar->setChecked(enabled);
977 enabled ? statusBar()->show() : statusBar()->hide();
979 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
980 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
982 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
986 void MainWin::setupHotList()
988 FlatProxyModel *flatProxy = new FlatProxyModel(this);
989 flatProxy->setSourceModel(Client::bufferModel());
990 _bufferHotList = new BufferHotListFilter(flatProxy);
994 void MainWin::saveMenuBarStatus(bool enabled)
996 QtUiSettings uiSettings;
997 uiSettings.setValue("ShowMenuBar", enabled);
1001 void MainWin::saveStatusBarStatus(bool enabled)
1003 QtUiSettings uiSettings;
1004 uiSettings.setValue("ShowStatusBar", enabled);
1008 void MainWin::setupSystray()
1011 _systemTray = new StatusNotifierItem(this);
1012 #elif !defined QT_NO_SYSTEMTRAYICON
1013 _systemTray = new LegacySystemTray(this);
1015 _systemTray = new SystemTray(this); // dummy
1017 _systemTray->init();
1021 void MainWin::setupToolBars()
1023 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1024 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1025 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1026 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1029 setUnifiedTitleAndToolBarOnMac(true);
1033 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1035 _mainToolBar = new QToolBar(this);
1036 _mainToolBar->setObjectName("MainToolBar");
1038 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1039 addToolBar(_mainToolBar);
1041 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1042 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1045 QtUiSettings uiSettings;
1047 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1048 _mainToolBar->setVisible(visible);
1049 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1053 void MainWin::saveMainToolBarStatus(bool enabled)
1056 QtUiSettings uiSettings;
1057 uiSettings.setValue("ShowMainToolBar", enabled);
1064 void MainWin::connectedToCore()
1066 Q_CHECK_PTR(Client::bufferViewManager());
1067 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1068 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1069 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1071 connect(Client::transferManager(), SIGNAL(transferAdded(const ClientTransfer*)), SLOT(showNewTransferDlg(const ClientTransfer*)));
1073 setConnectedState();
1077 void MainWin::setConnectedState()
1079 ActionCollection *coll = QtUi::actionCollection("General");
1081 coll->action("ConnectCore")->setEnabled(false);
1082 coll->action("DisconnectCore")->setEnabled(true);
1083 coll->action("ChangePassword")->setEnabled(true);
1084 coll->action("CoreInfo")->setEnabled(true);
1086 foreach(QAction *action, _fileMenu->actions()) {
1087 if (isRemoteCoreOnly(action))
1088 action->setVisible(!Client::internalCore());
1091 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1092 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1093 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1094 if (!Client::internalCore()) {
1095 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1096 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1097 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1100 // _viewMenu->setEnabled(true);
1101 if (!Client::internalCore())
1102 statusBar()->showMessage(tr("Connected to core."));
1104 statusBar()->clearMessage();
1106 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1108 systemTray()->setState(SystemTray::Active);
1110 if (Client::networkIds().isEmpty()) {
1111 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1115 // Monolithic always preselects last used buffer - Client only if the connection died
1116 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1118 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1119 if (lastUsedBufferId.isValid())
1120 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1126 void MainWin::loadLayout()
1129 int accountId = Client::currentCoreAccount().accountId().toInt();
1130 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1131 if (state.isEmpty()) {
1132 foreach(BufferViewDock *view, _bufferViews)
1134 _layoutLoaded = true;
1138 restoreState(state, accountId);
1139 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1140 if (bufferViewId >= 0)
1141 changeActiveBufferView(bufferViewId);
1143 _layoutLoaded = true;
1147 void MainWin::saveLayout()
1150 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1151 if (accountId > 0) {
1152 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1153 BufferView *view = activeBufferView();
1154 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1159 void MainWin::disconnectedFromCore()
1161 // save core specific layout and remove bufferviews;
1163 _layoutLoaded = false;
1165 QVariant actionData;
1166 BufferViewDock *dock;
1167 foreach(QAction *action, _bufferViewsMenu->actions()) {
1168 actionData = action->data();
1169 if (!actionData.isValid())
1172 dock = qobject_cast<BufferViewDock *>(action->parent());
1173 if (dock && actionData.toInt() != -1) {
1174 removeAction(action);
1175 _bufferViews.removeAll(dock);
1176 dock->deleteLater();
1180 // store last active buffer
1182 BufferId lastBufId = _bufferWidget->currentBuffer();
1183 if (lastBufId.isValid()) {
1184 s.setValue("LastUsedBufferId", lastBufId.toInt());
1185 // clear the current selection
1186 Client::bufferModel()->standardSelectionModel()->clearSelection();
1188 restoreState(s.value("MainWinState").toByteArray());
1189 setDisconnectedState();
1193 void MainWin::setDisconnectedState()
1195 ActionCollection *coll = QtUi::actionCollection("General");
1196 //ui.menuCore->setEnabled(false);
1197 coll->action("ConnectCore")->setEnabled(true);
1198 coll->action("DisconnectCore")->setEnabled(false);
1199 coll->action("CoreInfo")->setEnabled(false);
1200 coll->action("ChangePassword")->setEnabled(false);
1201 //_viewMenu->setEnabled(false);
1202 statusBar()->showMessage(tr("Not connected to core."));
1203 if (_msgProcessorStatusWidget)
1204 _msgProcessorStatusWidget->setProgress(0, 0);
1206 systemTray()->setState(SystemTray::Passive);
1210 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1212 Q_UNUSED(errorMessage)
1213 CoreConnectAuthDlg dlg(account, this);
1214 *valid = (dlg.exec() == QDialog::Accepted);
1218 void MainWin::handleNoSslInClient(bool *accepted)
1220 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1221 QMessageBox::Ignore|QMessageBox::Cancel, this);
1222 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1223 box.setDefaultButton(QMessageBox::Ignore);
1224 *accepted = box.exec() == QMessageBox::Ignore;
1228 void MainWin::handleNoSslInCore(bool *accepted)
1230 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1231 QMessageBox::Ignore|QMessageBox::Cancel, this);
1232 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1233 box.setDefaultButton(QMessageBox::Ignore);
1234 *accepted = box.exec() == QMessageBox::Ignore;
1240 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1242 QString errorString = "<ul>";
1243 foreach(const QSslError error, socket->sslErrors())
1244 errorString += QString("<li>%1</li>").arg(error.errorString());
1245 errorString += "</ul>";
1247 QMessageBox box(QMessageBox::Warning,
1248 tr("Untrusted Security Certificate"),
1249 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1250 QMessageBox::Cancel, this);
1251 box.setInformativeText(errorString);
1252 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1253 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1255 QMessageBox::ButtonRole role;
1258 role = box.buttonRole(box.clickedButton());
1259 if (role == QMessageBox::HelpRole) {
1260 SslInfoDlg dlg(socket, this);
1264 while (role == QMessageBox::HelpRole);
1266 *accepted = role == QMessageBox::AcceptRole;
1268 QMessageBox box2(QMessageBox::Warning,
1269 tr("Untrusted Security Certificate"),
1270 tr("Would you like to accept this certificate forever without being prompted?"),
1272 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1273 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1275 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1280 #endif /* HAVE_SSL */
1282 void MainWin::handleCoreConnectionError(const QString &error)
1284 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1288 void MainWin::showCoreConnectionDlg()
1290 CoreConnectDlg dlg(this);
1291 if (dlg.exec() == QDialog::Accepted) {
1292 AccountId accId = dlg.selectedAccount();
1293 if (accId.isValid())
1294 Client::coreConnection()->connectToCore(accId);
1299 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1301 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1307 void MainWin::showChannelList(NetworkId netId)
1309 ChannelListDlg *channelListDlg = new ChannelListDlg();
1311 if (!netId.isValid()) {
1312 QAction *action = qobject_cast<QAction *>(sender());
1314 netId = action->data().value<NetworkId>();
1317 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1318 channelListDlg->setNetwork(netId);
1319 channelListDlg->show();
1323 void MainWin::showIgnoreList(QString newRule)
1325 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1326 // prepare config dialog for new rule
1327 if (!newRule.isEmpty())
1328 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1333 void MainWin::showCoreInfoDlg()
1335 CoreInfoDlg(this).exec();
1339 void MainWin::showAwayLog()
1343 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1344 _awayLog = new AwayLogView(filter, 0);
1345 filter->setParent(_awayLog);
1346 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1347 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1352 void MainWin::awayLogDestroyed()
1358 void MainWin::showSettingsDlg()
1360 SettingsDlg *dlg = new SettingsDlg();
1362 //Category: Interface
1363 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1364 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1365 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1366 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1367 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1368 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1369 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1371 dlg->registerSettingsPage(new SonnetSettingsPage(dlg));
1373 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1374 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1375 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1378 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1379 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1380 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1381 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1382 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1384 // Category: Remote Cores
1385 if (Quassel::runMode() != Quassel::Monolithic) {
1386 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1387 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1394 void MainWin::showAboutDlg()
1396 AboutDlg(this).exec();
1400 void MainWin::showShortcutsDlg()
1403 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1404 foreach(KActionCollection *coll, QtUi::actionCollections())
1405 dlg.addCollection(coll, coll->property("Category").toString());
1406 dlg.configure(true);
1408 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1414 void MainWin::showNewTransferDlg(const ClientTransfer *transfer)
1416 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1421 void MainWin::onFullScreenToggled()
1423 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1424 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1427 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1429 if (_fullScreenAction->isChecked())
1430 setWindowState(windowState() | Qt::WindowFullScreen);
1432 setWindowState(windowState() & ~Qt::WindowFullScreen);
1437 /********************************************************************************************************/
1439 bool MainWin::event(QEvent *event)
1441 switch(event->type()) {
1442 case QEvent::WindowActivate: {
1443 BufferId bufferId = Client::bufferModel()->currentBuffer();
1444 if (bufferId.isValid())
1445 Client::instance()->markBufferAsRead(bufferId);
1448 case QEvent::WindowDeactivate:
1449 if (bufferWidget()->autoMarkerLineOnLostFocus())
1450 bufferWidget()->setMarkerLine();
1455 return QMainWindow::event(event);
1459 void MainWin::moveEvent(QMoveEvent *event)
1461 if (!(windowState() & Qt::WindowMaximized))
1462 _normalPos = event->pos();
1464 QMainWindow::moveEvent(event);
1468 void MainWin::resizeEvent(QResizeEvent *event)
1470 if (!(windowState() & Qt::WindowMaximized))
1471 _normalSize = event->size();
1473 QMainWindow::resizeEvent(event);
1477 void MainWin::closeEvent(QCloseEvent *event)
1480 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1482 if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1483 QtUi::hideMainWidget();
1493 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1497 bool hasFocus = QApplication::activeWindow() != 0;
1499 for (int i = start; i <= end; i++) {
1500 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1501 if (!idx.isValid()) {
1502 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1505 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1506 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1509 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1510 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1512 // check if bufferId belongs to the shown chatlists
1513 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1514 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1517 // check if it's the buffer currently displayed
1518 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1521 // only show notifications for higlights or queries
1522 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1525 // and of course: don't notify for ignored messages
1526 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1529 // seems like we have a legit notification candidate!
1530 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1531 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1532 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1533 AbstractNotificationBackend::NotificationType type;
1535 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1536 type = AbstractNotificationBackend::PrivMsg;
1537 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1538 type = AbstractNotificationBackend::PrivMsgFocused;
1539 else if (flags & Message::Highlight && !hasFocus)
1540 type = AbstractNotificationBackend::Highlight;
1542 type = AbstractNotificationBackend::HighlightFocused;
1544 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1549 void MainWin::currentBufferChanged(BufferId buffer)
1551 if (buffer.isValid())
1552 Client::instance()->markBufferAsRead(buffer);
1556 void MainWin::clientNetworkCreated(NetworkId id)
1558 const Network *net = Client::network(id);
1559 QAction *act = new QAction(net->networkName(), this);
1560 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1561 act->setData(QVariant::fromValue<NetworkId>(id));
1562 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1563 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1565 QAction *beforeAction = 0;
1566 foreach(QAction *action, _networksMenu->actions()) {
1567 if (!action->data().isValid()) // ignore stock actions
1569 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1570 beforeAction = action;
1574 _networksMenu->insertAction(beforeAction, act);
1578 void MainWin::clientNetworkUpdated()
1580 const Network *net = qobject_cast<const Network *>(sender());
1584 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1588 action->setText(net->networkName());
1590 switch (net->connectionState()) {
1591 case Network::Initialized:
1592 action->setIcon(QIcon::fromTheme("network-connect"));
1593 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1594 if (!bufferWidget()->currentBuffer().isValid()) {
1595 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1596 if (idx.isValid()) {
1597 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1598 Client::bufferModel()->switchToBuffer(statusBufferId);
1602 case Network::Disconnected:
1603 action->setIcon(QIcon::fromTheme("network-disconnect"));
1606 action->setIcon(QIcon::fromTheme("network-wired"));
1611 void MainWin::clientNetworkRemoved(NetworkId id)
1613 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1617 action->deleteLater();
1621 void MainWin::connectOrDisconnectFromNet()
1623 QAction *act = qobject_cast<QAction *>(sender());
1625 const Network *net = Client::network(act->data().value<NetworkId>());
1627 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1628 else net->requestDisconnect();
1632 void MainWin::on_jumpHotBuffer_triggered()
1634 if (!_bufferHotList->rowCount())
1637 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1641 void MainWin::onJumpKey()
1643 QAction *action = qobject_cast<QAction *>(sender());
1644 if (!action || !Client::bufferModel())
1646 int idx = action->property("Index").toInt();
1648 if (_jumpKeyMap.isEmpty())
1649 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1651 if (!_jumpKeyMap.contains(idx))
1654 BufferId buffer = _jumpKeyMap.value(idx);
1655 if (buffer.isValid())
1656 Client::bufferModel()->switchToBuffer(buffer);
1660 void MainWin::bindJumpKey()
1662 QAction *action = qobject_cast<QAction *>(sender());
1663 if (!action || !Client::bufferModel())
1665 int idx = action->property("Index").toInt();
1667 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1668 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1672 void MainWin::on_actionDebugNetworkModel_triggered()
1674 QTreeView *view = new QTreeView;
1675 view->setAttribute(Qt::WA_DeleteOnClose);
1676 view->setWindowTitle("Debug NetworkModel View");
1677 view->setModel(Client::networkModel());
1678 view->setColumnWidth(0, 250);
1679 view->setColumnWidth(1, 250);
1680 view->setColumnWidth(2, 80);
1681 view->resize(610, 300);
1686 void MainWin::on_actionDebugHotList_triggered()
1688 _bufferHotList->invalidate();
1689 _bufferHotList->sort(0, Qt::DescendingOrder);
1691 QTreeView *view = new QTreeView;
1692 view->setAttribute(Qt::WA_DeleteOnClose);
1693 view->setModel(_bufferHotList);
1698 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1700 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1701 overlay->setAttribute(Qt::WA_DeleteOnClose);
1706 void MainWin::on_actionDebugMessageModel_triggered()
1708 QTableView *view = new QTableView(0);
1709 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1710 filter->setSourceModel(Client::messageModel());
1711 view->setModel(filter);
1712 view->setAttribute(Qt::WA_DeleteOnClose, true);
1713 view->verticalHeader()->hide();
1714 view->horizontalHeader()->setStretchLastSection(true);
1719 void MainWin::on_actionDebugLog_triggered()
1721 DebugLogWidget *logWidget = new DebugLogWidget(0);
1726 void MainWin::showStatusBarMessage(const QString &message)
1728 statusBar()->showMessage(message, 10000);