1 /***************************************************************************
2 * Copyright (C) 2005-2012 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
23 #include <QMessageBox>
29 # include <KActionCollection>
32 # include <KShortcutsDialog>
33 # include <KStatusBar>
34 # include <KToggleFullScreenAction>
36 # include <KWindowSystem>
44 #include "awaylogfilter.h"
45 #include "awaylogview.h"
47 #include "actioncollection.h"
48 #include "bufferhotlistfilter.h"
49 #include "buffermodel.h"
50 #include "bufferview.h"
51 #include "bufferviewoverlay.h"
52 #include "bufferviewoverlayfilter.h"
53 #include "bufferwidget.h"
54 #include "channellistdlg.h"
55 #include "chatlinemodel.h"
56 #include "chatmonitorfilter.h"
57 #include "chatmonitorview.h"
60 #include "clientbacklogmanager.h"
61 #include "clientbufferviewconfig.h"
62 #include "clientbufferviewmanager.h"
63 #include "clientignorelistmanager.h"
64 #include "coreconfigwizard.h"
65 #include "coreconnectdlg.h"
66 #include "coreconnection.h"
67 #include "coreconnectionstatuswidget.h"
68 #include "coreinfodlg.h"
69 #include "contextmenuactionprovider.h"
70 #include "debugbufferviewoverlay.h"
71 #include "debuglogwidget.h"
72 #include "debugmessagemodelfilter.h"
73 #include "flatproxymodel.h"
74 #include "iconloader.h"
75 #include "inputwidget.h"
76 #include "irclistmodel.h"
77 #include "ircconnectionwizard.h"
78 #include "legacysystemtray.h"
79 #include "msgprocessorstatuswidget.h"
80 #include "nicklistwidget.h"
81 #include "qtuiapplication.h"
82 #include "qtuimessageprocessor.h"
83 #include "qtuisettings.h"
84 #include "qtuistyle.h"
85 #include "settingsdlg.h"
86 #include "settingspagedlg.h"
87 #include "statusnotifieritem.h"
88 #include "toolbaractionprovider.h"
89 #include "topicwidget.h"
90 #include "verticaldock.h"
94 # include "phononnotificationbackend.h"
96 # include "systraynotificationbackend.h"
97 # include "taskbarnotificationbackend.h"
99 # include "knotificationbackend.h"
100 #endif /* HAVE_KDE */
103 # include "sslinfodlg.h"
106 #ifdef HAVE_INDICATEQT
107 #include "indicatornotificationbackend.h"
110 #include "settingspages/aliasessettingspage.h"
111 #include "settingspages/appearancesettingspage.h"
112 #include "settingspages/backlogsettingspage.h"
113 #include "settingspages/bufferviewsettingspage.h"
114 #include "settingspages/chatmonitorsettingspage.h"
115 #include "settingspages/chatviewsettingspage.h"
116 #include "settingspages/connectionsettingspage.h"
117 #include "settingspages/coreaccountsettingspage.h"
118 #include "settingspages/coreconnectionsettingspage.h"
119 #include "settingspages/highlightsettingspage.h"
120 #include "settingspages/identitiessettingspage.h"
121 #include "settingspages/ignorelistsettingspage.h"
122 #include "settingspages/inputwidgetsettingspage.h"
123 #include "settingspages/itemviewsettingspage.h"
124 #include "settingspages/networkssettingspage.h"
125 #include "settingspages/notificationssettingspage.h"
126 #include "settingspages/topicwidgetsettingspage.h"
129 # include "settingspages/shortcutssettingspage.h"
132 MainWin::MainWin(QWidget *parent)
134 : KMainWindow(parent),
135 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
137 : QMainWindow(parent),
139 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
140 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
143 _layoutLoaded(false),
144 _activeBufferViewIndex(-1)
146 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
148 QtUiSettings uiSettings;
149 QString style = uiSettings.value("Style", QString()).toString();
150 if (!style.isEmpty()) {
151 QApplication::setStyle(style);
154 QApplication::setQuitOnLastWindowClosed(false);
156 setWindowTitle("Quassel IRC");
157 setWindowIconText("Quassel IRC");
164 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
165 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
166 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
167 SLOT(messagesInserted(const QModelIndex &, int, int)));
168 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
169 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
171 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
172 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
173 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
174 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
175 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
177 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
181 setDockNestingEnabled(true);
182 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
183 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
184 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
185 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
187 // Order is sometimes important
204 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
206 # ifndef QT_NO_SYSTEMTRAYICON
207 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
210 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
213 QtUi::registerNotificationBackend(new KNotificationBackend(this));
214 #endif /* HAVE_KDE */
216 #ifdef HAVE_INDICATEQT
217 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
220 // we assume that at this point, all configurable actions are defined!
221 QtUi::loadShortcuts();
223 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
225 setDisconnectedState(); // Disable menus and stuff
228 setAutoSaveSettings();
231 // restore mainwin state
233 restoreStateFromSettings(s);
235 // restore locked state of docks
236 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
238 CoreConnection *conn = Client::coreConnection();
239 if (!conn->connectToCore()) {
240 // No autoconnect selected (or no accounts)
241 showCoreConnectionDlg();
254 saveStateToSettings(s);
256 QApplication::quit();
260 void MainWin::saveStateToSettings(UiSettings &s)
262 s.setValue("MainWinSize", _normalSize);
263 s.setValue("MainWinPos", _normalPos);
264 s.setValue("MainWinState", saveState());
265 s.setValue("MainWinGeometry", saveGeometry());
266 s.setValue("MainWinMinimized", isMinimized());
267 s.setValue("MainWinMaximized", isMaximized());
268 s.setValue("MainWinHidden", !isVisible());
269 BufferId lastBufId = Client::bufferModel()->currentBuffer();
270 if (lastBufId.isValid())
271 s.setValue("LastUsedBufferId", lastBufId.toInt());
274 saveAutoSaveSettings();
279 void MainWin::restoreStateFromSettings(UiSettings &s)
281 _normalSize = s.value("MainWinSize", size()).toSize();
282 _normalPos = s.value("MainWinPos", pos()).toPoint();
283 bool maximized = s.value("MainWinMaximized", false).toBool();
286 restoreGeometry(s.value("MainWinGeometry").toByteArray());
289 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
294 restoreState(s.value("MainWinState").toByteArray());
300 if (s.value("MainWinHidden").toBool() && QtUi::haveSystemTray())
301 QtUi::hideMainWidget();
302 else if (s.value("MainWinMinimized").toBool())
311 void MainWin::updateIcon()
314 const int size = 128;
320 if (Client::isConnected())
321 icon = DesktopIcon("quassel", size);
323 icon = DesktopIcon("quassel-inactive", size);
325 qApp->setWindowIcon(icon);
329 void MainWin::setupActions()
331 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
333 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
334 this, SLOT(showCoreConnectionDlg())));
335 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
336 Client::instance(), SLOT(disconnectFromCore())));
337 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
338 this, SLOT(showCoreInfoDlg())));
339 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
340 this, SLOT(on_actionConfigureNetworks_triggered())));
341 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
342 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
343 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
346 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
347 this, SLOT(on_actionConfigureViews_triggered())));
349 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
350 lockAct->setCheckable(true);
351 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
353 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
354 0, 0, QKeySequence::Find))->setCheckable(true);
355 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
356 this, SLOT(showAwayLog())));
357 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
358 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
360 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
361 0, 0))->setCheckable(true);
364 QAction *fullScreenAct = KStandardAction::fullScreen(this, SLOT(toggleFullscreen()), this, coll);
366 QAction *fullScreenAct = new Action(SmallIcon("view-fullscreen"), tr("&Full Screen Mode"), coll,
367 this, SLOT(toggleFullscreen()), QKeySequence(Qt::Key_F11));
368 fullScreenAct->setCheckable(true);
370 coll->addAction("ToggleFullscreen", fullScreenAct);
373 QAction *configureShortcutsAct = new Action(SmallIcon("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
374 this, SLOT(showShortcutsDlg()));
375 configureShortcutsAct->setMenuRole(QAction::NoRole);
376 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
379 QAction *configureQuasselAct = new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
380 this, SLOT(showSettingsDlg()));
381 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
383 QAction *configureQuasselAct = new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
384 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
386 coll->addAction("ConfigureQuassel", configureQuasselAct);
389 QAction *aboutQuasselAct = new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
390 this, SLOT(showAboutDlg()));
391 aboutQuasselAct->setMenuRole(QAction::AboutRole);
392 coll->addAction("AboutQuassel", aboutQuasselAct);
394 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
395 qApp, SLOT(aboutQt()));
396 aboutQtAct->setMenuRole(QAction::AboutQtRole);
397 coll->addAction("AboutQt", aboutQtAct);
398 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
399 this, SLOT(on_actionDebugNetworkModel_triggered())));
400 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
401 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
402 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
403 this, SLOT(on_actionDebugMessageModel_triggered())));
404 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
405 this, SLOT(on_actionDebugHotList_triggered())));
406 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
407 this, SLOT(on_actionDebugLog_triggered())));
408 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
409 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
411 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
412 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
415 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
417 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
418 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
422 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
423 const int jumpModifier = Qt::ControlModifier;
425 const int bindModifier = Qt::ControlModifier;
426 const int jumpModifier = Qt::AltModifier;
429 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
430 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
431 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
432 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
433 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
434 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
435 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
436 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
437 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
438 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
439 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
440 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
441 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
442 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
443 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
444 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
445 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
446 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
447 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
448 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
450 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
451 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
452 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
453 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
454 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
455 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
456 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
457 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
458 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
459 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
460 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
461 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
462 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
463 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
464 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
465 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
466 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
467 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
468 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
469 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
472 coll->addAction("NextBufferView", new Action(SmallIcon("go-next-view"), tr("Activate Next Chat List"), coll,
473 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
474 coll->addAction("PreviousBufferView", new Action(SmallIcon("go-previous-view"), tr("Activate Previous Chat List"), coll,
475 this, SLOT(previousBufferView()), QKeySequence::Back));
476 coll->addAction("NextBuffer", new Action(SmallIcon("go-down"), tr("Go to Next Chat"), coll,
477 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
478 coll->addAction("PreviousBuffer", new Action(SmallIcon("go-up"), tr("Go to Previous Chat"), coll,
479 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
483 void MainWin::setupMenus()
485 ActionCollection *coll = QtUi::actionCollection("General");
487 _fileMenu = menuBar()->addMenu(tr("&File"));
489 static const QStringList coreActions = QStringList()
490 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
493 foreach(QString actionName, coreActions) {
494 coreAction = coll->action(actionName);
495 _fileMenu->addAction(coreAction);
496 flagRemoteCoreOnly(coreAction);
498 flagRemoteCoreOnly(_fileMenu->addSeparator());
500 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
501 _networksMenu->addAction(coll->action("ConfigureNetworks"));
502 _networksMenu->addSeparator();
503 _fileMenu->addSeparator();
504 _fileMenu->addAction(coll->action("Quit"));
506 _viewMenu = menuBar()->addMenu(tr("&View"));
507 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
508 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
509 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
510 _viewMenu->addSeparator();
512 _viewMenu->addAction(coll->action("ToggleMenuBar"));
513 _viewMenu->addAction(coll->action("ToggleStatusBar"));
514 _viewMenu->addAction(coll->action("ToggleSearchBar"));
516 coreAction = coll->action("ShowAwayLog");
517 flagRemoteCoreOnly(coreAction);
518 _viewMenu->addAction(coreAction);
520 _viewMenu->addSeparator();
521 _viewMenu->addAction(coll->action("LockLayout"));
523 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
525 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
526 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
528 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
530 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
532 _helpMenu = menuBar()->addMenu(tr("&Help"));
533 _helpMenu->addAction(coll->action("AboutQuassel"));
535 _helpMenu->addAction(coll->action("AboutQt"));
537 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
539 _helpMenu->addSeparator();
540 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
541 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
542 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
543 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
544 _helpDebugMenu->addAction(coll->action("DebugHotList"));
545 _helpDebugMenu->addAction(coll->action("DebugLog"));
546 _helpDebugMenu->addSeparator();
547 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
550 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
552 QtUiSettings uiSettings;
553 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
554 showMenuBar->setChecked(enabled);
555 enabled ? menuBar()->show() : menuBar()->hide();
557 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
558 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
562 void MainWin::setupBufferWidget()
564 _bufferWidget = new BufferWidget(this);
565 _bufferWidget->setModel(Client::bufferModel());
566 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
567 setCentralWidget(_bufferWidget);
571 void MainWin::addBufferView(int bufferViewConfigId)
573 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
577 void MainWin::addBufferView(ClientBufferViewConfig *config)
582 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
583 BufferViewDock *dock = new BufferViewDock(config, this);
585 //create the view and initialize it's filter
586 BufferView *view = new BufferView(dock);
587 view->setFilteredModel(Client::bufferModel(), config);
588 view->installEventFilter(_inputWidget); // for key presses
590 Client::bufferModel()->synchronizeView(view);
592 dock->setWidget(view);
593 dock->setVisible(_layoutLoaded); // don't show before state has been restored
595 addDockWidget(Qt::LeftDockWidgetArea, dock);
596 _bufferViewsMenu->addAction(dock->toggleViewAction());
598 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
599 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
600 _bufferViews.append(dock);
602 if (!activeBufferView())
607 void MainWin::removeBufferView(int bufferViewConfigId)
610 BufferViewDock *dock;
611 foreach(QAction *action, _bufferViewsMenu->actions()) {
612 actionData = action->data();
613 if (!actionData.isValid())
616 dock = qobject_cast<BufferViewDock *>(action->parent());
617 if (dock && actionData.toInt() == bufferViewConfigId) {
618 removeAction(action);
619 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
620 _bufferViews.removeAll(dock);
622 if (dock->isActive()) {
623 dock->setActive(false);
624 _activeBufferViewIndex = -1;
634 void MainWin::bufferViewToggled(bool enabled)
636 if (!enabled && !isVisible()) {
637 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
638 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
641 QAction *action = qobject_cast<QAction *>(sender());
643 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
646 // Make sure we don't toggle backlog fetch for a view we've already removed
647 if (!_bufferViews.contains(dock))
651 Client::bufferViewOverlay()->addView(dock->bufferViewId());
653 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
657 void MainWin::bufferViewVisibilityChanged(bool visible)
660 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
662 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
667 BufferView *MainWin::allBuffersView() const
669 // "All Buffers" is always the first dock created
670 if (_bufferViews.count() > 0)
671 return _bufferViews[0]->bufferView();
676 BufferView *MainWin::activeBufferView() const
678 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
680 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
681 return dock->isActive() ? qobject_cast<BufferView *>(dock->widget()) : 0;
685 void MainWin::changeActiveBufferView(int bufferViewId)
687 if (bufferViewId < 0)
690 BufferView *current = activeBufferView();
692 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
693 _activeBufferViewIndex = -1;
696 for (int i = 0; i < _bufferViews.count(); i++) {
697 BufferViewDock *dock = _bufferViews.at(i);
698 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
699 _activeBufferViewIndex = i;
700 dock->setActive(true);
705 nextBufferView(); // fallback
709 void MainWin::changeActiveBufferView(bool backwards)
711 BufferView *current = activeBufferView();
713 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
715 if (!_bufferViews.count())
718 int c = _bufferViews.count();
719 while (c--) { // yes, this will reactivate the current active one if all others fail
721 if (--_activeBufferViewIndex < 0)
722 _activeBufferViewIndex = _bufferViews.count()-1;
725 if (++_activeBufferViewIndex >= _bufferViews.count())
726 _activeBufferViewIndex = 0;
729 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
730 if (dock->isHidden())
733 dock->setActive(true);
737 _activeBufferViewIndex = -1;
741 void MainWin::nextBufferView()
743 changeActiveBufferView(false);
747 void MainWin::previousBufferView()
749 changeActiveBufferView(true);
753 void MainWin::nextBuffer()
755 BufferView *view = activeBufferView();
761 void MainWin::previousBuffer()
763 BufferView *view = activeBufferView();
765 view->previousBuffer();
769 void MainWin::hideCurrentBuffer()
771 BufferView *view = activeBufferView();
773 view->hideCurrentBuffer();
777 void MainWin::showNotificationsDlg()
779 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
784 void MainWin::on_actionConfigureNetworks_triggered()
786 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
791 void MainWin::on_actionConfigureViews_triggered()
793 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
798 void MainWin::on_actionLockLayout_toggled(bool lock)
800 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
801 foreach(VerticalDock *dock, docks) {
802 dock->showTitle(!lock);
804 if (Client::bufferViewManager()) {
805 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
806 config->setLocked(lock);
809 QtUiSettings().setValue("LockLayout", lock);
813 void MainWin::setupNickWidget()
816 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
817 nickDock->setObjectName("NickDock");
818 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
820 _nickListWidget = new NickListWidget(nickDock);
821 nickDock->setWidget(_nickListWidget);
823 addDockWidget(Qt::RightDockWidgetArea, nickDock);
824 _viewMenu->addAction(nickDock->toggleViewAction());
825 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
827 // See NickListDock::NickListDock();
828 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
830 // attach the NickListWidget to the BufferModel and the default selection
831 _nickListWidget->setModel(Client::bufferModel());
832 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
836 void MainWin::setupChatMonitor()
838 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
839 dock->setObjectName("ChatMonitorDock");
841 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
842 _chatMonitorView = new ChatMonitorView(filter, this);
843 _chatMonitorView->setFocusProxy(_inputWidget);
844 _chatMonitorView->show();
845 dock->setWidget(_chatMonitorView);
848 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
849 _viewMenu->addAction(dock->toggleViewAction());
850 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
854 void MainWin::setupInputWidget()
856 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
857 dock->setObjectName("InputDock");
859 _inputWidget = new InputWidget(dock);
860 dock->setWidget(_inputWidget);
862 addDockWidget(Qt::BottomDockWidgetArea, dock);
864 _viewMenu->addAction(dock->toggleViewAction());
865 dock->toggleViewAction()->setText(tr("Show Input Line"));
867 _inputWidget->setModel(Client::bufferModel());
868 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
870 _bufferWidget->setFocusProxy(_inputWidget);
872 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
874 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
878 void MainWin::setupTopicWidget()
880 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
881 dock->setObjectName("TopicDock");
882 _topicWidget = new TopicWidget(dock);
884 dock->setWidget(_topicWidget);
886 _topicWidget->setModel(Client::bufferModel());
887 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
889 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
891 _viewMenu->addAction(dock->toggleViewAction());
892 dock->toggleViewAction()->setText(tr("Show Topic Line"));
896 void MainWin::setupViewMenuTail()
898 _viewMenu->addSeparator();
899 _viewMenu->addAction(QtUi::actionCollection("General")->action("ToggleFullscreen"));
903 void MainWin::setupTitleSetter()
905 _titleSetter.setModel(Client::bufferModel());
906 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
910 void MainWin::setupStatusBar()
912 // MessageProcessor progress
913 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
916 _coreConnectionStatusWidget->update();
917 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
919 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
921 QtUiSettings uiSettings;
923 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
924 showStatusbar->setChecked(enabled);
925 enabled ? statusBar()->show() : statusBar()->hide();
927 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
928 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
930 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
934 void MainWin::setupHotList()
936 FlatProxyModel *flatProxy = new FlatProxyModel(this);
937 flatProxy->setSourceModel(Client::bufferModel());
938 _bufferHotList = new BufferHotListFilter(flatProxy);
942 void MainWin::saveMenuBarStatus(bool enabled)
944 QtUiSettings uiSettings;
945 uiSettings.setValue("ShowMenuBar", enabled);
949 void MainWin::saveStatusBarStatus(bool enabled)
951 QtUiSettings uiSettings;
952 uiSettings.setValue("ShowStatusBar", enabled);
956 void MainWin::setupSystray()
959 _systemTray = new StatusNotifierItem(this);
960 #elif !defined QT_NO_SYSTEMTRAYICON
961 _systemTray = new LegacySystemTray(this);
963 _systemTray = new SystemTray(this); // dummy
969 void MainWin::setupToolBars()
971 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
972 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
973 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
974 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
977 setUnifiedTitleAndToolBarOnMac(true);
981 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
983 _mainToolBar = new QToolBar(this);
984 _mainToolBar->setObjectName("MainToolBar");
986 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
987 addToolBar(_mainToolBar);
989 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
990 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
994 void MainWin::connectedToCore()
996 Q_CHECK_PTR(Client::bufferViewManager());
997 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
998 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
999 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1001 setConnectedState();
1005 void MainWin::setConnectedState()
1007 ActionCollection *coll = QtUi::actionCollection("General");
1009 coll->action("ConnectCore")->setEnabled(false);
1010 coll->action("DisconnectCore")->setEnabled(true);
1011 coll->action("CoreInfo")->setEnabled(true);
1013 foreach(QAction *action, _fileMenu->actions()) {
1014 if (isRemoteCoreOnly(action))
1015 action->setVisible(!Client::internalCore());
1018 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1019 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1020 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1021 if (!Client::internalCore()) {
1022 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1023 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1024 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1027 // _viewMenu->setEnabled(true);
1028 if (!Client::internalCore())
1029 statusBar()->showMessage(tr("Connected to core."));
1031 statusBar()->clearMessage();
1033 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1035 systemTray()->setState(SystemTray::Active);
1037 if (Client::networkIds().isEmpty()) {
1038 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1042 // Monolithic always preselects last used buffer - Client only if the connection died
1043 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1045 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1046 if (lastUsedBufferId.isValid())
1047 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1053 void MainWin::loadLayout()
1056 int accountId = Client::currentCoreAccount().accountId().toInt();
1057 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1058 if (state.isEmpty()) {
1059 foreach(BufferViewDock *view, _bufferViews)
1061 _layoutLoaded = true;
1065 restoreState(state, accountId);
1066 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1067 if (bufferViewId >= 0)
1068 changeActiveBufferView(bufferViewId);
1070 _layoutLoaded = true;
1074 void MainWin::saveLayout()
1077 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1078 if (accountId > 0) {
1079 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1080 BufferView *view = activeBufferView();
1081 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1086 void MainWin::disconnectedFromCore()
1088 // save core specific layout and remove bufferviews;
1090 _layoutLoaded = false;
1092 QVariant actionData;
1093 BufferViewDock *dock;
1094 foreach(QAction *action, _bufferViewsMenu->actions()) {
1095 actionData = action->data();
1096 if (!actionData.isValid())
1099 dock = qobject_cast<BufferViewDock *>(action->parent());
1100 if (dock && actionData.toInt() != -1) {
1101 removeAction(action);
1102 _bufferViews.removeAll(dock);
1103 dock->deleteLater();
1107 // store last active buffer
1109 BufferId lastBufId = _bufferWidget->currentBuffer();
1110 if (lastBufId.isValid()) {
1111 s.setValue("LastUsedBufferId", lastBufId.toInt());
1112 // clear the current selection
1113 Client::bufferModel()->standardSelectionModel()->clearSelection();
1115 restoreState(s.value("MainWinState").toByteArray());
1116 setDisconnectedState();
1120 void MainWin::setDisconnectedState()
1122 ActionCollection *coll = QtUi::actionCollection("General");
1123 //ui.menuCore->setEnabled(false);
1124 coll->action("ConnectCore")->setEnabled(true);
1125 coll->action("DisconnectCore")->setEnabled(false);
1126 coll->action("CoreInfo")->setEnabled(false);
1127 //_viewMenu->setEnabled(false);
1128 statusBar()->showMessage(tr("Not connected to core."));
1129 if (_msgProcessorStatusWidget)
1130 _msgProcessorStatusWidget->setProgress(0, 0);
1132 systemTray()->setState(SystemTray::Passive);
1136 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1138 Q_UNUSED(errorMessage)
1139 CoreConnectAuthDlg dlg(account, this);
1140 *valid = (dlg.exec() == QDialog::Accepted);
1144 void MainWin::handleNoSslInClient(bool *accepted)
1146 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1147 QMessageBox::Ignore|QMessageBox::Cancel, this);
1148 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1149 box.setDefaultButton(QMessageBox::Ignore);
1150 *accepted = box.exec() == QMessageBox::Ignore;
1154 void MainWin::handleNoSslInCore(bool *accepted)
1156 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1157 QMessageBox::Ignore|QMessageBox::Cancel, this);
1158 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1159 box.setDefaultButton(QMessageBox::Ignore);
1160 *accepted = box.exec() == QMessageBox::Ignore;
1166 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1168 QString errorString = "<ul>";
1169 foreach(const QSslError error, socket->sslErrors())
1170 errorString += QString("<li>%1</li>").arg(error.errorString());
1171 errorString += "</ul>";
1173 QMessageBox box(QMessageBox::Warning,
1174 tr("Untrusted Security Certificate"),
1175 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1176 QMessageBox::Cancel, this);
1177 box.setInformativeText(errorString);
1178 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1179 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1181 QMessageBox::ButtonRole role;
1184 role = box.buttonRole(box.clickedButton());
1185 if (role == QMessageBox::HelpRole) {
1186 SslInfoDlg dlg(socket, this);
1190 while (role == QMessageBox::HelpRole);
1192 *accepted = role == QMessageBox::AcceptRole;
1194 QMessageBox box2(QMessageBox::Warning,
1195 tr("Untrusted Security Certificate"),
1196 tr("Would you like to accept this certificate forever without being prompted?"),
1198 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1199 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1201 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1206 #endif /* HAVE_SSL */
1208 void MainWin::handleCoreConnectionError(const QString &error)
1210 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1214 void MainWin::showCoreConnectionDlg()
1216 CoreConnectDlg dlg(this);
1217 if (dlg.exec() == QDialog::Accepted) {
1218 AccountId accId = dlg.selectedAccount();
1219 if (accId.isValid())
1220 Client::coreConnection()->connectToCore(accId);
1225 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1227 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1233 void MainWin::showChannelList(NetworkId netId)
1235 ChannelListDlg *channelListDlg = new ChannelListDlg();
1237 if (!netId.isValid()) {
1238 QAction *action = qobject_cast<QAction *>(sender());
1240 netId = action->data().value<NetworkId>();
1243 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1244 channelListDlg->setNetwork(netId);
1245 channelListDlg->show();
1249 void MainWin::showIgnoreList(QString newRule)
1251 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1252 // prepare config dialog for new rule
1253 if (!newRule.isEmpty())
1254 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1259 void MainWin::showCoreInfoDlg()
1261 CoreInfoDlg(this).exec();
1265 void MainWin::showAwayLog()
1269 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1270 _awayLog = new AwayLogView(filter, 0);
1271 filter->setParent(_awayLog);
1272 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1273 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1278 void MainWin::awayLogDestroyed()
1284 void MainWin::showSettingsDlg()
1286 SettingsDlg *dlg = new SettingsDlg();
1288 //Category: Interface
1289 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1290 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1291 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1292 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1293 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1294 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1295 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1296 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1297 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1298 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1301 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1302 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1303 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1304 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1305 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1307 // Category: Remote Cores
1308 if (Quassel::runMode() != Quassel::Monolithic) {
1309 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1310 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1317 void MainWin::showAboutDlg()
1319 AboutDlg(this).exec();
1323 void MainWin::showShortcutsDlg()
1326 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1327 foreach(KActionCollection *coll, QtUi::actionCollections())
1328 dlg.addCollection(coll, coll->property("Category").toString());
1331 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1337 void MainWin::toggleFullscreen()
1346 /********************************************************************************************************/
1348 bool MainWin::event(QEvent *event)
1350 if (event->type() == QEvent::WindowActivate) {
1351 BufferId buffer = Client::bufferModel()->currentBuffer();
1352 if (buffer.isValid())
1353 Client::instance()->markBufferAsRead(buffer);
1355 return QMainWindow::event(event);
1359 void MainWin::moveEvent(QMoveEvent *event)
1361 if (!(windowState() & Qt::WindowMaximized))
1362 _normalPos = event->pos();
1364 QMainWindow::moveEvent(event);
1368 void MainWin::resizeEvent(QResizeEvent *event)
1370 if (!(windowState() & Qt::WindowMaximized))
1371 _normalSize = event->size();
1373 QMainWindow::resizeEvent(event);
1377 void MainWin::closeEvent(QCloseEvent *event)
1380 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1382 if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1383 QtUi::hideMainWidget();
1393 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1397 bool hasFocus = QApplication::activeWindow() != 0;
1399 for (int i = start; i <= end; i++) {
1400 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1401 if (!idx.isValid()) {
1402 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1405 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1406 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1409 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1410 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1412 // check if bufferId belongs to the shown chatlists
1413 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1414 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1417 // check if it's the buffer currently displayed
1418 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1421 // only show notifications for higlights or queries
1422 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1425 // and of course: don't notify for ignored messages
1426 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1429 // seems like we have a legit notification candidate!
1430 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1431 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1432 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1433 AbstractNotificationBackend::NotificationType type;
1435 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1436 type = AbstractNotificationBackend::PrivMsg;
1437 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1438 type = AbstractNotificationBackend::PrivMsgFocused;
1439 else if (flags & Message::Highlight && !hasFocus)
1440 type = AbstractNotificationBackend::Highlight;
1442 type = AbstractNotificationBackend::HighlightFocused;
1444 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1449 void MainWin::currentBufferChanged(BufferId buffer)
1451 if (buffer.isValid())
1452 Client::instance()->markBufferAsRead(buffer);
1456 void MainWin::clientNetworkCreated(NetworkId id)
1458 const Network *net = Client::network(id);
1459 QAction *act = new QAction(net->networkName(), this);
1460 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1461 act->setData(QVariant::fromValue<NetworkId>(id));
1462 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1463 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1465 QAction *beforeAction = 0;
1466 foreach(QAction *action, _networksMenu->actions()) {
1467 if (!action->data().isValid()) // ignore stock actions
1469 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1470 beforeAction = action;
1474 _networksMenu->insertAction(beforeAction, act);
1478 void MainWin::clientNetworkUpdated()
1480 const Network *net = qobject_cast<const Network *>(sender());
1484 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1488 action->setText(net->networkName());
1490 switch (net->connectionState()) {
1491 case Network::Initialized:
1492 action->setIcon(SmallIcon("network-connect"));
1493 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1494 if (!bufferWidget()->currentBuffer().isValid()) {
1495 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1496 if (idx.isValid()) {
1497 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1498 Client::bufferModel()->switchToBuffer(statusBufferId);
1502 case Network::Disconnected:
1503 action->setIcon(SmallIcon("network-disconnect"));
1506 action->setIcon(SmallIcon("network-wired"));
1511 void MainWin::clientNetworkRemoved(NetworkId id)
1513 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1517 action->deleteLater();
1521 void MainWin::connectOrDisconnectFromNet()
1523 QAction *act = qobject_cast<QAction *>(sender());
1525 const Network *net = Client::network(act->data().value<NetworkId>());
1527 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1528 else net->requestDisconnect();
1532 void MainWin::on_jumpHotBuffer_triggered()
1534 if (!_bufferHotList->rowCount())
1537 QModelIndex topIndex = _bufferHotList->index(0, 0);
1538 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1539 Client::bufferModel()->switchToBuffer(bufferId);
1543 void MainWin::onJumpKey()
1545 QAction *action = qobject_cast<QAction *>(sender());
1546 if (!action || !Client::bufferModel())
1548 int idx = action->property("Index").toInt();
1550 if (_jumpKeyMap.isEmpty())
1551 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1553 if (!_jumpKeyMap.contains(idx))
1556 BufferId buffer = _jumpKeyMap.value(idx);
1557 if (buffer.isValid())
1558 Client::bufferModel()->switchToBuffer(buffer);
1562 void MainWin::bindJumpKey()
1564 QAction *action = qobject_cast<QAction *>(sender());
1565 if (!action || !Client::bufferModel())
1567 int idx = action->property("Index").toInt();
1569 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1570 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1574 void MainWin::on_actionDebugNetworkModel_triggered()
1576 QTreeView *view = new QTreeView;
1577 view->setAttribute(Qt::WA_DeleteOnClose);
1578 view->setWindowTitle("Debug NetworkModel View");
1579 view->setModel(Client::networkModel());
1580 view->setColumnWidth(0, 250);
1581 view->setColumnWidth(1, 250);
1582 view->setColumnWidth(2, 80);
1583 view->resize(610, 300);
1588 void MainWin::on_actionDebugHotList_triggered()
1590 QTreeView *view = new QTreeView;
1591 view->setAttribute(Qt::WA_DeleteOnClose);
1592 view->setModel(_bufferHotList);
1597 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1599 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1600 overlay->setAttribute(Qt::WA_DeleteOnClose);
1605 void MainWin::on_actionDebugMessageModel_triggered()
1607 QTableView *view = new QTableView(0);
1608 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1609 filter->setSourceModel(Client::messageModel());
1610 view->setModel(filter);
1611 view->setAttribute(Qt::WA_DeleteOnClose, true);
1612 view->verticalHeader()->hide();
1613 view->horizontalHeader()->setStretchLastSection(true);
1618 void MainWin::on_actionDebugLog_triggered()
1620 DebugLogWidget *logWidget = new DebugLogWidget(0);
1625 void MainWin::showStatusBarMessage(const QString &message)
1627 statusBar()->showMessage(message, 10000);