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 # include "systraynotificationbackend.h"
108 # include "taskbarnotificationbackend.h"
110 # include "knotificationbackend.h"
111 #endif /* HAVE_KDE */
115 # include "snorenotificationbackend.h"
119 # include "sslinfodlg.h"
122 #ifdef HAVE_INDICATEQT
123 #include "indicatornotificationbackend.h"
126 #ifdef HAVE_NOTIFICATION_CENTER
127 #include "osxnotificationbackend.h"
131 #include "dockmanagernotificationbackend.h"
134 #include "settingspages/aliasessettingspage.h"
135 #include "settingspages/appearancesettingspage.h"
136 #include "settingspages/backlogsettingspage.h"
137 #include "settingspages/bufferviewsettingspage.h"
138 #include "settingspages/chatmonitorsettingspage.h"
139 #include "settingspages/chatviewsettingspage.h"
140 #include "settingspages/connectionsettingspage.h"
141 #include "settingspages/coreaccountsettingspage.h"
142 #include "settingspages/coreconnectionsettingspage.h"
143 #include "settingspages/highlightsettingspage.h"
144 #include "settingspages/identitiessettingspage.h"
145 #include "settingspages/ignorelistsettingspage.h"
146 #include "settingspages/inputwidgetsettingspage.h"
147 #include "settingspages/itemviewsettingspage.h"
148 #include "settingspages/networkssettingspage.h"
149 #include "settingspages/notificationssettingspage.h"
150 #include "settingspages/topicwidgetsettingspage.h"
153 # include "settingspages/shortcutssettingspage.h"
156 MainWin::MainWin(QWidget *parent)
158 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
160 : QMainWindow(parent),
162 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
163 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
166 _layoutLoaded(false),
167 _activeBufferViewIndex(-1)
169 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
171 QtUiSettings uiSettings;
172 QString style = uiSettings.value("Style", QString()).toString();
173 if (!style.isEmpty()) {
174 QApplication::setStyle(style);
177 QApplication::setQuitOnLastWindowClosed(false);
179 setWindowTitle("Quassel IRC");
180 setWindowIconText("Quassel IRC");
187 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
188 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
189 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
190 SLOT(messagesInserted(const QModelIndex &, int, int)));
191 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
192 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
194 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
195 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
196 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
197 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
198 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
200 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
204 setDockNestingEnabled(true);
205 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
206 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
207 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
208 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
210 // Order is sometimes important
227 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
229 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
231 QtUi::registerNotificationBackend(new KNotificationBackend(this));
232 #endif /* HAVE_KDE */
236 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
237 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
238 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
241 #ifdef HAVE_INDICATEQT
242 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
245 #ifdef HAVE_NOTIFICATION_CENTER
246 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
250 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
253 // we assume that at this point, all configurable actions are defined!
254 QtUi::loadShortcuts();
256 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
258 setDisconnectedState(); // Disable menus and stuff
261 setAutoSaveSettings();
264 // restore mainwin state
266 restoreStateFromSettings(s);
268 // restore locked state of docks
269 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
271 CoreConnection *conn = Client::coreConnection();
272 if (!conn->connectToCore()) {
273 // No autoconnect selected (or no accounts)
274 showCoreConnectionDlg();
287 saveStateToSettings(s);
289 QApplication::quit();
293 void MainWin::saveStateToSettings(UiSettings &s)
295 s.setValue("MainWinSize", _normalSize);
296 s.setValue("MainWinPos", _normalPos);
297 s.setValue("MainWinState", saveState());
298 s.setValue("MainWinGeometry", saveGeometry());
299 s.setValue("MainWinMinimized", isMinimized());
300 s.setValue("MainWinMaximized", isMaximized());
301 s.setValue("MainWinHidden", !isVisible());
302 BufferId lastBufId = Client::bufferModel()->currentBuffer();
303 if (lastBufId.isValid())
304 s.setValue("LastUsedBufferId", lastBufId.toInt());
307 saveAutoSaveSettings();
312 void MainWin::restoreStateFromSettings(UiSettings &s)
314 _normalSize = s.value("MainWinSize", size()).toSize();
315 _normalPos = s.value("MainWinPos", pos()).toPoint();
316 bool maximized = s.value("MainWinMaximized", false).toBool();
319 restoreGeometry(s.value("MainWinGeometry").toByteArray());
322 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
327 restoreState(s.value("MainWinState").toByteArray());
333 if ((Quassel::isOptionSet("hidewindow")
334 || s.value("MainWinHidden").toBool())
335 && _systemTray->isSystemTrayAvailable())
336 QtUi::hideMainWidget();
337 else if (s.value("MainWinMinimized").toBool())
346 void MainWin::updateIcon()
349 if (Client::isConnected())
350 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
352 icon = QIcon::fromTheme("quassel-inactive", QIcon(":/icons/quassel-128.png"));
354 qApp->setWindowIcon(icon);
358 void MainWin::setupActions()
360 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
362 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("network-connect"), tr("&Connect to Core..."), coll,
363 this, SLOT(showCoreConnectionDlg())));
364 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("network-disconnect"), tr("&Disconnect from Core"), coll,
365 Client::instance(), SLOT(disconnectFromCore())));
366 coll->addAction("ChangePassword", new Action(QIcon::fromTheme("dialog-password"), tr("Change &Password..."), coll,
367 this, SLOT(showPasswordChangeDlg())));
368 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
369 this, SLOT(showCoreInfoDlg())));
370 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
371 this, SLOT(on_actionConfigureNetworks_triggered())));
372 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
373 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
374 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
377 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
378 this, SLOT(on_actionConfigureViews_triggered())));
380 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
381 lockAct->setCheckable(true);
382 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
384 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
385 0, 0, QKeySequence::Find))->setCheckable(true);
386 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
387 this, SLOT(showAwayLog())));
388 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
389 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
391 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
392 0, 0))->setCheckable(true);
395 _fullScreenAction = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
397 _fullScreenAction = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
398 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
399 _fullScreenAction->setCheckable(true);
400 coll->addAction("ToggleFullScreen", _fullScreenAction);
404 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
405 this, SLOT(showShortcutsDlg()));
406 configureShortcutsAct->setMenuRole(QAction::NoRole);
407 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
410 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
411 this, SLOT(showSettingsDlg()));
412 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
414 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
415 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
417 coll->addAction("ConfigureQuassel", configureQuasselAct);
420 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
421 this, SLOT(showAboutDlg()));
422 aboutQuasselAct->setMenuRole(QAction::AboutRole);
423 coll->addAction("AboutQuassel", aboutQuasselAct);
425 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
426 qApp, SLOT(aboutQt()));
427 aboutQtAct->setMenuRole(QAction::AboutQtRole);
428 coll->addAction("AboutQt", aboutQtAct);
429 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
430 this, SLOT(on_actionDebugNetworkModel_triggered())));
431 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
432 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
433 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
434 this, SLOT(on_actionDebugMessageModel_triggered())));
435 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
436 this, SLOT(on_actionDebugHotList_triggered())));
437 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
438 this, SLOT(on_actionDebugLog_triggered())));
439 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
440 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
442 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
443 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
446 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
448 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
449 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
453 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
454 const int jumpModifier = Qt::ControlModifier;
456 const int bindModifier = Qt::ControlModifier;
457 const int jumpModifier = Qt::AltModifier;
460 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
461 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
462 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
463 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
464 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
465 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
466 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
467 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
468 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
469 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
470 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
471 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
472 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
473 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
474 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
475 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
476 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
477 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
478 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
479 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
481 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
482 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
483 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
484 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
485 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
486 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
487 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
488 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
489 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
490 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
491 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
492 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
493 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
494 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
495 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
496 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
497 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
498 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
499 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
500 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
503 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
504 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
505 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
506 this, SLOT(previousBufferView()), QKeySequence::Back));
507 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
508 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
509 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
510 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
514 void MainWin::setupMenus()
516 ActionCollection *coll = QtUi::actionCollection("General");
518 _fileMenu = menuBar()->addMenu(tr("&File"));
520 static const QStringList coreActions = QStringList()
521 << "ConnectCore" << "DisconnectCore" << "ChangePassword" << "CoreInfo";
524 foreach(QString actionName, coreActions) {
525 coreAction = coll->action(actionName);
526 _fileMenu->addAction(coreAction);
527 flagRemoteCoreOnly(coreAction);
529 flagRemoteCoreOnly(_fileMenu->addSeparator());
531 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
532 _networksMenu->addAction(coll->action("ConfigureNetworks"));
533 _networksMenu->addSeparator();
534 _fileMenu->addSeparator();
535 _fileMenu->addAction(coll->action("Quit"));
537 _viewMenu = menuBar()->addMenu(tr("&View"));
538 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
539 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
540 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
541 _viewMenu->addSeparator();
543 _viewMenu->addAction(coll->action("ToggleMenuBar"));
544 _viewMenu->addAction(coll->action("ToggleStatusBar"));
545 _viewMenu->addAction(coll->action("ToggleSearchBar"));
547 coreAction = coll->action("ShowAwayLog");
548 flagRemoteCoreOnly(coreAction);
549 _viewMenu->addAction(coreAction);
551 _viewMenu->addSeparator();
552 _viewMenu->addAction(coll->action("LockLayout"));
554 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
556 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
557 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
559 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
561 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
564 _helpMenu = menuBar()->addMenu(tr("&Help"));
566 _helpMenu->addAction(coll->action("AboutQuassel"));
568 _helpMenu->addAction(coll->action("AboutQt"));
570 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
572 _helpMenu->addSeparator();
573 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
574 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
575 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
576 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
577 _helpDebugMenu->addAction(coll->action("DebugHotList"));
578 _helpDebugMenu->addAction(coll->action("DebugLog"));
579 _helpDebugMenu->addSeparator();
580 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
583 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
585 QtUiSettings uiSettings;
586 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
587 showMenuBar->setChecked(enabled);
588 enabled ? menuBar()->show() : menuBar()->hide();
590 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
591 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
595 void MainWin::setupBufferWidget()
597 _bufferWidget = new BufferWidget(this);
598 _bufferWidget->setModel(Client::bufferModel());
599 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
600 setCentralWidget(_bufferWidget);
604 void MainWin::addBufferView(int bufferViewConfigId)
606 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
610 void MainWin::addBufferView(ClientBufferViewConfig *config)
615 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
616 BufferViewDock *dock = new BufferViewDock(config, this);
618 //create the view and initialize it's filter
619 BufferView *view = new BufferView(dock);
620 view->setFilteredModel(Client::bufferModel(), config);
621 view->installEventFilter(_inputWidget); // for key presses
623 Client::bufferModel()->synchronizeView(view);
625 dock->setWidget(view);
626 dock->setVisible(_layoutLoaded); // don't show before state has been restored
628 addDockWidget(Qt::LeftDockWidgetArea, dock);
629 _bufferViewsMenu->addAction(dock->toggleViewAction());
631 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
632 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
633 _bufferViews.append(dock);
635 if (!activeBufferView())
640 void MainWin::removeBufferView(int bufferViewConfigId)
643 BufferViewDock *dock;
644 foreach(QAction *action, _bufferViewsMenu->actions()) {
645 actionData = action->data();
646 if (!actionData.isValid())
649 dock = qobject_cast<BufferViewDock *>(action->parent());
650 if (dock && actionData.toInt() == bufferViewConfigId) {
651 removeAction(action);
652 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
653 _bufferViews.removeAll(dock);
655 if (dock->isActive()) {
656 dock->setActive(false);
657 _activeBufferViewIndex = -1;
667 void MainWin::bufferViewToggled(bool enabled)
669 if (!enabled && !isMinimized()) {
670 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
671 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
674 QAction *action = qobject_cast<QAction *>(sender());
676 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
679 // Make sure we don't toggle backlog fetch for a view we've already removed
680 if (!_bufferViews.contains(dock))
684 Client::bufferViewOverlay()->addView(dock->bufferViewId());
686 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
690 void MainWin::bufferViewVisibilityChanged(bool visible)
693 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
695 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
700 BufferView *MainWin::allBuffersView() const
702 // "All Buffers" is always the first dock created
703 if (_bufferViews.count() > 0)
704 return _bufferViews[0]->bufferView();
709 BufferView *MainWin::activeBufferView() const
711 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
713 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
714 return dock->isActive() ? qobject_cast<BufferView *>(dock->widget()) : 0;
718 void MainWin::changeActiveBufferView(int bufferViewId)
720 if (bufferViewId < 0)
723 BufferView *current = activeBufferView();
725 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
726 _activeBufferViewIndex = -1;
729 for (int i = 0; i < _bufferViews.count(); i++) {
730 BufferViewDock *dock = _bufferViews.at(i);
731 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
732 _activeBufferViewIndex = i;
733 dock->setActive(true);
738 nextBufferView(); // fallback
742 void MainWin::showPasswordChangeDlg()
744 if((Client::coreFeatures() & Quassel::PasswordChange)) {
745 PasswordChangeDlg dlg(this);
749 QMessageBox box(QMessageBox::Warning, tr("Feature Not Supported"),
750 tr("<b>Your Quassel Core does not support this feature</b>"),
751 QMessageBox::Ok, this);
752 box.setInformativeText(tr("You need a Quassel Core v0.12.0 or newer in order to be able to remotely change your password."));
758 void MainWin::changeActiveBufferView(bool backwards)
760 BufferView *current = activeBufferView();
762 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
764 if (!_bufferViews.count())
767 int c = _bufferViews.count();
768 while (c--) { // yes, this will reactivate the current active one if all others fail
770 if (--_activeBufferViewIndex < 0)
771 _activeBufferViewIndex = _bufferViews.count()-1;
774 if (++_activeBufferViewIndex >= _bufferViews.count())
775 _activeBufferViewIndex = 0;
778 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
779 if (dock->isHidden())
782 dock->setActive(true);
786 _activeBufferViewIndex = -1;
790 void MainWin::nextBufferView()
792 changeActiveBufferView(false);
796 void MainWin::previousBufferView()
798 changeActiveBufferView(true);
802 void MainWin::nextBuffer()
804 BufferView *view = activeBufferView();
810 void MainWin::previousBuffer()
812 BufferView *view = activeBufferView();
814 view->previousBuffer();
818 void MainWin::hideCurrentBuffer()
820 BufferView *view = activeBufferView();
822 view->hideCurrentBuffer();
826 void MainWin::showNotificationsDlg()
828 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
833 void MainWin::on_actionConfigureNetworks_triggered()
835 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
840 void MainWin::on_actionConfigureViews_triggered()
842 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
847 void MainWin::on_actionLockLayout_toggled(bool lock)
849 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
850 foreach(VerticalDock *dock, docks) {
851 dock->showTitle(!lock);
853 if (Client::bufferViewManager()) {
854 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
855 config->setLocked(lock);
858 QtUiSettings().setValue("LockLayout", lock);
862 void MainWin::setupNickWidget()
865 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
866 nickDock->setObjectName("NickDock");
867 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
869 _nickListWidget = new NickListWidget(nickDock);
870 nickDock->setWidget(_nickListWidget);
872 addDockWidget(Qt::RightDockWidgetArea, nickDock);
873 _viewMenu->addAction(nickDock->toggleViewAction());
874 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
876 // See NickListDock::NickListDock();
877 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
879 // attach the NickListWidget to the BufferModel and the default selection
880 _nickListWidget->setModel(Client::bufferModel());
881 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
885 void MainWin::setupChatMonitor()
887 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
888 dock->setObjectName("ChatMonitorDock");
890 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
891 _chatMonitorView = new ChatMonitorView(filter, this);
892 _chatMonitorView->setFocusProxy(_inputWidget);
893 _chatMonitorView->show();
894 dock->setWidget(_chatMonitorView);
897 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
898 _viewMenu->addAction(dock->toggleViewAction());
899 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
903 void MainWin::setupInputWidget()
905 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
906 dock->setObjectName("InputDock");
908 _inputWidget = new InputWidget(dock);
909 dock->setWidget(_inputWidget);
911 addDockWidget(Qt::BottomDockWidgetArea, dock);
913 _viewMenu->addAction(dock->toggleViewAction());
914 dock->toggleViewAction()->setText(tr("Show Input Line"));
916 _inputWidget->setModel(Client::bufferModel());
917 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
919 _bufferWidget->setFocusProxy(_inputWidget);
921 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
923 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
927 void MainWin::setupTopicWidget()
929 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
930 dock->setObjectName("TopicDock");
931 _topicWidget = new TopicWidget(dock);
933 dock->setWidget(_topicWidget);
935 _topicWidget->setModel(Client::bufferModel());
936 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
938 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
940 _viewMenu->addAction(dock->toggleViewAction());
941 dock->toggleViewAction()->setText(tr("Show Topic Line"));
945 void MainWin::setupViewMenuTail()
947 _viewMenu->addSeparator();
948 _viewMenu->addAction(_fullScreenAction);
952 void MainWin::setupTitleSetter()
954 _titleSetter.setModel(Client::bufferModel());
955 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
959 void MainWin::setupStatusBar()
961 // MessageProcessor progress
962 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
965 _coreConnectionStatusWidget->update();
966 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
968 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
970 QtUiSettings uiSettings;
972 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
973 showStatusbar->setChecked(enabled);
974 enabled ? statusBar()->show() : statusBar()->hide();
976 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
977 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
979 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
983 void MainWin::setupHotList()
985 FlatProxyModel *flatProxy = new FlatProxyModel(this);
986 flatProxy->setSourceModel(Client::bufferModel());
987 _bufferHotList = new BufferHotListFilter(flatProxy);
991 void MainWin::saveMenuBarStatus(bool enabled)
993 QtUiSettings uiSettings;
994 uiSettings.setValue("ShowMenuBar", enabled);
998 void MainWin::saveStatusBarStatus(bool enabled)
1000 QtUiSettings uiSettings;
1001 uiSettings.setValue("ShowStatusBar", enabled);
1005 void MainWin::setupSystray()
1008 _systemTray = new StatusNotifierItem(this);
1009 #elif !defined QT_NO_SYSTEMTRAYICON
1010 _systemTray = new LegacySystemTray(this);
1012 _systemTray = new SystemTray(this); // dummy
1014 _systemTray->init();
1018 void MainWin::setupToolBars()
1020 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
1021 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1022 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1023 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1026 setUnifiedTitleAndToolBarOnMac(true);
1030 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1032 _mainToolBar = new QToolBar(this);
1033 _mainToolBar->setObjectName("MainToolBar");
1035 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1036 addToolBar(_mainToolBar);
1038 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1039 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1042 QtUiSettings uiSettings;
1044 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1045 _mainToolBar->setVisible(visible);
1046 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1050 void MainWin::saveMainToolBarStatus(bool enabled)
1053 QtUiSettings uiSettings;
1054 uiSettings.setValue("ShowMainToolBar", enabled);
1061 void MainWin::connectedToCore()
1063 Q_CHECK_PTR(Client::bufferViewManager());
1064 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1065 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1066 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1068 connect(Client::transferManager(), SIGNAL(transferAdded(const ClientTransfer*)), SLOT(showNewTransferDlg(const ClientTransfer*)));
1070 setConnectedState();
1074 void MainWin::setConnectedState()
1076 ActionCollection *coll = QtUi::actionCollection("General");
1078 coll->action("ConnectCore")->setEnabled(false);
1079 coll->action("DisconnectCore")->setEnabled(true);
1080 coll->action("ChangePassword")->setEnabled(true);
1081 coll->action("CoreInfo")->setEnabled(true);
1083 foreach(QAction *action, _fileMenu->actions()) {
1084 if (isRemoteCoreOnly(action))
1085 action->setVisible(!Client::internalCore());
1088 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1089 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1090 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1091 if (!Client::internalCore()) {
1092 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1093 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1094 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1097 // _viewMenu->setEnabled(true);
1098 if (!Client::internalCore())
1099 statusBar()->showMessage(tr("Connected to core."));
1101 statusBar()->clearMessage();
1103 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1105 systemTray()->setState(SystemTray::Active);
1107 if (Client::networkIds().isEmpty()) {
1108 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1112 // Monolithic always preselects last used buffer - Client only if the connection died
1113 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1115 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1116 if (lastUsedBufferId.isValid())
1117 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1123 void MainWin::loadLayout()
1126 int accountId = Client::currentCoreAccount().accountId().toInt();
1127 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1128 if (state.isEmpty()) {
1129 foreach(BufferViewDock *view, _bufferViews)
1131 _layoutLoaded = true;
1135 restoreState(state, accountId);
1136 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1137 if (bufferViewId >= 0)
1138 changeActiveBufferView(bufferViewId);
1140 _layoutLoaded = true;
1144 void MainWin::saveLayout()
1147 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1148 if (accountId > 0) {
1149 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1150 BufferView *view = activeBufferView();
1151 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1156 void MainWin::disconnectedFromCore()
1158 // save core specific layout and remove bufferviews;
1160 _layoutLoaded = false;
1162 QVariant actionData;
1163 BufferViewDock *dock;
1164 foreach(QAction *action, _bufferViewsMenu->actions()) {
1165 actionData = action->data();
1166 if (!actionData.isValid())
1169 dock = qobject_cast<BufferViewDock *>(action->parent());
1170 if (dock && actionData.toInt() != -1) {
1171 removeAction(action);
1172 _bufferViews.removeAll(dock);
1173 dock->deleteLater();
1177 // store last active buffer
1179 BufferId lastBufId = _bufferWidget->currentBuffer();
1180 if (lastBufId.isValid()) {
1181 s.setValue("LastUsedBufferId", lastBufId.toInt());
1182 // clear the current selection
1183 Client::bufferModel()->standardSelectionModel()->clearSelection();
1185 restoreState(s.value("MainWinState").toByteArray());
1186 setDisconnectedState();
1190 void MainWin::setDisconnectedState()
1192 ActionCollection *coll = QtUi::actionCollection("General");
1193 //ui.menuCore->setEnabled(false);
1194 coll->action("ConnectCore")->setEnabled(true);
1195 coll->action("DisconnectCore")->setEnabled(false);
1196 coll->action("CoreInfo")->setEnabled(false);
1197 coll->action("ChangePassword")->setEnabled(false);
1198 //_viewMenu->setEnabled(false);
1199 statusBar()->showMessage(tr("Not connected to core."));
1200 if (_msgProcessorStatusWidget)
1201 _msgProcessorStatusWidget->setProgress(0, 0);
1203 systemTray()->setState(SystemTray::Passive);
1207 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1209 Q_UNUSED(errorMessage)
1210 CoreConnectAuthDlg dlg(account, this);
1211 *valid = (dlg.exec() == QDialog::Accepted);
1215 void MainWin::handleNoSslInClient(bool *accepted)
1217 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1218 QMessageBox::Ignore|QMessageBox::Cancel, this);
1219 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1220 box.setDefaultButton(QMessageBox::Ignore);
1221 *accepted = box.exec() == QMessageBox::Ignore;
1225 void MainWin::handleNoSslInCore(bool *accepted)
1227 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1228 QMessageBox::Ignore|QMessageBox::Cancel, this);
1229 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1230 box.setDefaultButton(QMessageBox::Ignore);
1231 *accepted = box.exec() == QMessageBox::Ignore;
1237 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1239 QString errorString = "<ul>";
1240 foreach(const QSslError error, socket->sslErrors())
1241 errorString += QString("<li>%1</li>").arg(error.errorString());
1242 errorString += "</ul>";
1244 QMessageBox box(QMessageBox::Warning,
1245 tr("Untrusted Security Certificate"),
1246 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1247 QMessageBox::Cancel, this);
1248 box.setInformativeText(errorString);
1249 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1250 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1252 QMessageBox::ButtonRole role;
1255 role = box.buttonRole(box.clickedButton());
1256 if (role == QMessageBox::HelpRole) {
1257 SslInfoDlg dlg(socket, this);
1261 while (role == QMessageBox::HelpRole);
1263 *accepted = role == QMessageBox::AcceptRole;
1265 QMessageBox box2(QMessageBox::Warning,
1266 tr("Untrusted Security Certificate"),
1267 tr("Would you like to accept this certificate forever without being prompted?"),
1269 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1270 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1272 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1277 #endif /* HAVE_SSL */
1279 void MainWin::handleCoreConnectionError(const QString &error)
1281 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1285 void MainWin::showCoreConnectionDlg()
1287 CoreConnectDlg dlg(this);
1288 if (dlg.exec() == QDialog::Accepted) {
1289 AccountId accId = dlg.selectedAccount();
1290 if (accId.isValid())
1291 Client::coreConnection()->connectToCore(accId);
1296 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1298 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1304 void MainWin::showChannelList(NetworkId netId)
1306 ChannelListDlg *channelListDlg = new ChannelListDlg();
1308 if (!netId.isValid()) {
1309 QAction *action = qobject_cast<QAction *>(sender());
1311 netId = action->data().value<NetworkId>();
1314 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1315 channelListDlg->setNetwork(netId);
1316 channelListDlg->show();
1320 void MainWin::showIgnoreList(QString newRule)
1322 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1323 // prepare config dialog for new rule
1324 if (!newRule.isEmpty())
1325 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1330 void MainWin::showCoreInfoDlg()
1332 CoreInfoDlg(this).exec();
1336 void MainWin::showAwayLog()
1340 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1341 _awayLog = new AwayLogView(filter, 0);
1342 filter->setParent(_awayLog);
1343 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1344 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1349 void MainWin::awayLogDestroyed()
1355 void MainWin::showSettingsDlg()
1357 SettingsDlg *dlg = new SettingsDlg();
1359 //Category: Interface
1360 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1361 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1362 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1363 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1364 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1365 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1366 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1367 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1368 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1369 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1372 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1373 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1374 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1375 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1376 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1378 // Category: Remote Cores
1379 if (Quassel::runMode() != Quassel::Monolithic) {
1380 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1381 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1388 void MainWin::showAboutDlg()
1390 AboutDlg(this).exec();
1394 void MainWin::showShortcutsDlg()
1397 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1398 foreach(KActionCollection *coll, QtUi::actionCollections())
1399 dlg.addCollection(coll, coll->property("Category").toString());
1400 dlg.configure(true);
1402 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1408 void MainWin::showNewTransferDlg(const ClientTransfer *transfer)
1410 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1415 void MainWin::onFullScreenToggled()
1417 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1418 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1421 static_cast<KToggleFullScreenAction*>(_fullScreenAction)->setFullScreen(this, _fullScreenAction->isChecked());
1423 if (_fullScreenAction->isChecked())
1424 setWindowState(windowState() | Qt::WindowFullScreen);
1426 setWindowState(windowState() & ~Qt::WindowFullScreen);
1431 /********************************************************************************************************/
1433 bool MainWin::event(QEvent *event)
1435 switch(event->type()) {
1436 case QEvent::WindowActivate: {
1437 BufferId bufferId = Client::bufferModel()->currentBuffer();
1438 if (bufferId.isValid())
1439 Client::instance()->markBufferAsRead(bufferId);
1442 case QEvent::WindowDeactivate:
1443 if (bufferWidget()->autoMarkerLineOnLostFocus())
1444 bufferWidget()->setMarkerLine();
1449 return QMainWindow::event(event);
1453 void MainWin::moveEvent(QMoveEvent *event)
1455 if (!(windowState() & Qt::WindowMaximized))
1456 _normalPos = event->pos();
1458 QMainWindow::moveEvent(event);
1462 void MainWin::resizeEvent(QResizeEvent *event)
1464 if (!(windowState() & Qt::WindowMaximized))
1465 _normalSize = event->size();
1467 QMainWindow::resizeEvent(event);
1471 void MainWin::closeEvent(QCloseEvent *event)
1474 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1476 if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1477 QtUi::hideMainWidget();
1487 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1491 bool hasFocus = QApplication::activeWindow() != 0;
1493 for (int i = start; i <= end; i++) {
1494 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1495 if (!idx.isValid()) {
1496 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1499 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1500 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1503 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1504 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1506 // check if bufferId belongs to the shown chatlists
1507 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1508 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1511 // check if it's the buffer currently displayed
1512 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1515 // only show notifications for higlights or queries
1516 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1519 // and of course: don't notify for ignored messages
1520 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1523 // seems like we have a legit notification candidate!
1524 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1525 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1526 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1527 AbstractNotificationBackend::NotificationType type;
1529 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1530 type = AbstractNotificationBackend::PrivMsg;
1531 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1532 type = AbstractNotificationBackend::PrivMsgFocused;
1533 else if (flags & Message::Highlight && !hasFocus)
1534 type = AbstractNotificationBackend::Highlight;
1536 type = AbstractNotificationBackend::HighlightFocused;
1538 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1543 void MainWin::currentBufferChanged(BufferId buffer)
1545 if (buffer.isValid())
1546 Client::instance()->markBufferAsRead(buffer);
1550 void MainWin::clientNetworkCreated(NetworkId id)
1552 const Network *net = Client::network(id);
1553 QAction *act = new QAction(net->networkName(), this);
1554 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1555 act->setData(QVariant::fromValue<NetworkId>(id));
1556 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1557 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1559 QAction *beforeAction = 0;
1560 foreach(QAction *action, _networksMenu->actions()) {
1561 if (!action->data().isValid()) // ignore stock actions
1563 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1564 beforeAction = action;
1568 _networksMenu->insertAction(beforeAction, act);
1572 void MainWin::clientNetworkUpdated()
1574 const Network *net = qobject_cast<const Network *>(sender());
1578 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1582 action->setText(net->networkName());
1584 switch (net->connectionState()) {
1585 case Network::Initialized:
1586 action->setIcon(QIcon::fromTheme("network-connect"));
1587 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1588 if (!bufferWidget()->currentBuffer().isValid()) {
1589 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1590 if (idx.isValid()) {
1591 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1592 Client::bufferModel()->switchToBuffer(statusBufferId);
1596 case Network::Disconnected:
1597 action->setIcon(QIcon::fromTheme("network-disconnect"));
1600 action->setIcon(QIcon::fromTheme("network-wired"));
1605 void MainWin::clientNetworkRemoved(NetworkId id)
1607 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1611 action->deleteLater();
1615 void MainWin::connectOrDisconnectFromNet()
1617 QAction *act = qobject_cast<QAction *>(sender());
1619 const Network *net = Client::network(act->data().value<NetworkId>());
1621 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1622 else net->requestDisconnect();
1626 void MainWin::on_jumpHotBuffer_triggered()
1628 if (!_bufferHotList->rowCount())
1631 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1635 void MainWin::onJumpKey()
1637 QAction *action = qobject_cast<QAction *>(sender());
1638 if (!action || !Client::bufferModel())
1640 int idx = action->property("Index").toInt();
1642 if (_jumpKeyMap.isEmpty())
1643 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1645 if (!_jumpKeyMap.contains(idx))
1648 BufferId buffer = _jumpKeyMap.value(idx);
1649 if (buffer.isValid())
1650 Client::bufferModel()->switchToBuffer(buffer);
1654 void MainWin::bindJumpKey()
1656 QAction *action = qobject_cast<QAction *>(sender());
1657 if (!action || !Client::bufferModel())
1659 int idx = action->property("Index").toInt();
1661 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1662 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1666 void MainWin::on_actionDebugNetworkModel_triggered()
1668 QTreeView *view = new QTreeView;
1669 view->setAttribute(Qt::WA_DeleteOnClose);
1670 view->setWindowTitle("Debug NetworkModel View");
1671 view->setModel(Client::networkModel());
1672 view->setColumnWidth(0, 250);
1673 view->setColumnWidth(1, 250);
1674 view->setColumnWidth(2, 80);
1675 view->resize(610, 300);
1680 void MainWin::on_actionDebugHotList_triggered()
1682 _bufferHotList->invalidate();
1683 _bufferHotList->sort(0, Qt::DescendingOrder);
1685 QTreeView *view = new QTreeView;
1686 view->setAttribute(Qt::WA_DeleteOnClose);
1687 view->setModel(_bufferHotList);
1692 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1694 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1695 overlay->setAttribute(Qt::WA_DeleteOnClose);
1700 void MainWin::on_actionDebugMessageModel_triggered()
1702 QTableView *view = new QTableView(0);
1703 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1704 filter->setSourceModel(Client::messageModel());
1705 view->setModel(filter);
1706 view->setAttribute(Qt::WA_DeleteOnClose, true);
1707 view->verticalHeader()->hide();
1708 view->horizontalHeader()->setStretchLastSection(true);
1713 void MainWin::on_actionDebugLog_triggered()
1715 DebugLogWidget *logWidget = new DebugLogWidget(0);
1720 void MainWin::showStatusBarMessage(const QString &message)
1722 statusBar()->showMessage(message, 10000);