1 /***************************************************************************
2 * Copyright (C) 2005-2013 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 ***************************************************************************/
24 #include <QMessageBox>
30 # include <KActionCollection>
33 # include <KShortcutsDialog>
34 # include <KStatusBar>
35 # include <KToggleFullScreenAction>
37 # include <KWindowSystem>
45 #include "awaylogfilter.h"
46 #include "awaylogview.h"
48 #include "actioncollection.h"
49 #include "bufferhotlistfilter.h"
50 #include "buffermodel.h"
51 #include "bufferview.h"
52 #include "bufferviewoverlay.h"
53 #include "bufferviewoverlayfilter.h"
54 #include "bufferwidget.h"
55 #include "channellistdlg.h"
56 #include "chatlinemodel.h"
57 #include "chatmonitorfilter.h"
58 #include "chatmonitorview.h"
61 #include "clientbacklogmanager.h"
62 #include "clientbufferviewconfig.h"
63 #include "clientbufferviewmanager.h"
64 #include "clientignorelistmanager.h"
65 #include "coreconfigwizard.h"
66 #include "coreconnectdlg.h"
67 #include "coreconnection.h"
68 #include "coreconnectionstatuswidget.h"
69 #include "coreinfodlg.h"
70 #include "contextmenuactionprovider.h"
71 #include "debugbufferviewoverlay.h"
72 #include "debuglogwidget.h"
73 #include "debugmessagemodelfilter.h"
74 #include "flatproxymodel.h"
75 #include "iconloader.h"
76 #include "inputwidget.h"
77 #include "irclistmodel.h"
78 #include "ircconnectionwizard.h"
79 #include "legacysystemtray.h"
80 #include "msgprocessorstatuswidget.h"
81 #include "nicklistwidget.h"
82 #include "qtuiapplication.h"
83 #include "qtuimessageprocessor.h"
84 #include "qtuisettings.h"
85 #include "qtuistyle.h"
86 #include "settingsdlg.h"
87 #include "settingspagedlg.h"
88 #include "statusnotifieritem.h"
89 #include "toolbaractionprovider.h"
90 #include "topicwidget.h"
91 #include "verticaldock.h"
95 # include "phononnotificationbackend.h"
97 # include "systraynotificationbackend.h"
98 # include "taskbarnotificationbackend.h"
100 # include "knotificationbackend.h"
101 #endif /* HAVE_KDE */
104 # include "sslinfodlg.h"
107 #ifdef HAVE_INDICATEQT
108 #include "indicatornotificationbackend.h"
111 #include "settingspages/aliasessettingspage.h"
112 #include "settingspages/appearancesettingspage.h"
113 #include "settingspages/backlogsettingspage.h"
114 #include "settingspages/bufferviewsettingspage.h"
115 #include "settingspages/chatmonitorsettingspage.h"
116 #include "settingspages/chatviewsettingspage.h"
117 #include "settingspages/connectionsettingspage.h"
118 #include "settingspages/coreaccountsettingspage.h"
119 #include "settingspages/coreconnectionsettingspage.h"
120 #include "settingspages/highlightsettingspage.h"
121 #include "settingspages/identitiessettingspage.h"
122 #include "settingspages/ignorelistsettingspage.h"
123 #include "settingspages/inputwidgetsettingspage.h"
124 #include "settingspages/itemviewsettingspage.h"
125 #include "settingspages/networkssettingspage.h"
126 #include "settingspages/notificationssettingspage.h"
127 #include "settingspages/topicwidgetsettingspage.h"
130 # include "settingspages/shortcutssettingspage.h"
133 MainWin::MainWin(QWidget *parent)
135 : KMainWindow(parent),
136 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
138 : QMainWindow(parent),
140 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
141 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
144 _layoutLoaded(false),
145 _activeBufferViewIndex(-1)
147 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
149 QtUiSettings uiSettings;
150 QString style = uiSettings.value("Style", QString()).toString();
151 if (!style.isEmpty()) {
152 QApplication::setStyle(style);
155 QApplication::setQuitOnLastWindowClosed(false);
157 setWindowTitle("Quassel IRC");
158 setWindowIconText("Quassel IRC");
165 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
166 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
167 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
168 SLOT(messagesInserted(const QModelIndex &, int, int)));
169 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
170 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
172 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
173 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
174 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
175 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
176 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
178 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
182 setDockNestingEnabled(true);
183 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
184 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
185 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
186 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
188 // Order is sometimes important
205 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
207 # ifndef QT_NO_SYSTEMTRAYICON
208 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
211 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
214 QtUi::registerNotificationBackend(new KNotificationBackend(this));
215 #endif /* HAVE_KDE */
217 #ifdef HAVE_INDICATEQT
218 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
221 // we assume that at this point, all configurable actions are defined!
222 QtUi::loadShortcuts();
224 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
226 setDisconnectedState(); // Disable menus and stuff
229 setAutoSaveSettings();
232 // restore mainwin state
234 restoreStateFromSettings(s);
236 // restore locked state of docks
237 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
239 CoreConnection *conn = Client::coreConnection();
240 if (!conn->connectToCore()) {
241 // No autoconnect selected (or no accounts)
242 showCoreConnectionDlg();
255 saveStateToSettings(s);
257 QApplication::quit();
261 void MainWin::saveStateToSettings(UiSettings &s)
263 s.setValue("MainWinSize", _normalSize);
264 s.setValue("MainWinPos", _normalPos);
265 s.setValue("MainWinState", saveState());
266 s.setValue("MainWinGeometry", saveGeometry());
267 s.setValue("MainWinMinimized", isMinimized());
268 s.setValue("MainWinMaximized", isMaximized());
269 s.setValue("MainWinHidden", !isVisible());
270 BufferId lastBufId = Client::bufferModel()->currentBuffer();
271 if (lastBufId.isValid())
272 s.setValue("LastUsedBufferId", lastBufId.toInt());
275 saveAutoSaveSettings();
280 void MainWin::restoreStateFromSettings(UiSettings &s)
282 _normalSize = s.value("MainWinSize", size()).toSize();
283 _normalPos = s.value("MainWinPos", pos()).toPoint();
284 bool maximized = s.value("MainWinMaximized", false).toBool();
287 restoreGeometry(s.value("MainWinGeometry").toByteArray());
290 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
295 restoreState(s.value("MainWinState").toByteArray());
301 if (s.value("MainWinHidden").toBool() && QtUi::haveSystemTray())
302 QtUi::hideMainWidget();
303 else if (s.value("MainWinMinimized").toBool())
312 void MainWin::updateIcon()
315 const int size = 128;
321 if (Client::isConnected())
322 icon = DesktopIcon("quassel", size);
324 icon = DesktopIcon("quassel-inactive", size);
326 qApp->setWindowIcon(icon);
330 void MainWin::setupActions()
332 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
334 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
335 this, SLOT(showCoreConnectionDlg())));
336 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
337 Client::instance(), SLOT(disconnectFromCore())));
338 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
339 this, SLOT(showCoreInfoDlg())));
340 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
341 this, SLOT(on_actionConfigureNetworks_triggered())));
342 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
343 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
344 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
347 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
348 this, SLOT(on_actionConfigureViews_triggered())));
350 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
351 lockAct->setCheckable(true);
352 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
354 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
355 0, 0, QKeySequence::Find))->setCheckable(true);
356 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
357 this, SLOT(showAwayLog())));
358 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
359 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
361 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
362 0, 0))->setCheckable(true);
365 QAction *fullScreenAct = KStandardAction::fullScreen(this, SLOT(toggleFullscreen()), this, coll);
367 QAction *fullScreenAct = new Action(SmallIcon("view-fullscreen"), tr("&Full Screen Mode"), coll,
368 this, SLOT(toggleFullscreen()), QKeySequence(Qt::Key_F11));
369 fullScreenAct->setCheckable(true);
371 coll->addAction("ToggleFullscreen", fullScreenAct);
374 QAction *configureShortcutsAct = new Action(SmallIcon("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
375 this, SLOT(showShortcutsDlg()));
376 configureShortcutsAct->setMenuRole(QAction::NoRole);
377 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
380 QAction *configureQuasselAct = new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
381 this, SLOT(showSettingsDlg()));
382 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
384 QAction *configureQuasselAct = new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
385 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
387 coll->addAction("ConfigureQuassel", configureQuasselAct);
390 QAction *aboutQuasselAct = new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
391 this, SLOT(showAboutDlg()));
392 aboutQuasselAct->setMenuRole(QAction::AboutRole);
393 coll->addAction("AboutQuassel", aboutQuasselAct);
395 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
396 qApp, SLOT(aboutQt()));
397 aboutQtAct->setMenuRole(QAction::AboutQtRole);
398 coll->addAction("AboutQt", aboutQtAct);
399 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
400 this, SLOT(on_actionDebugNetworkModel_triggered())));
401 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
402 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
403 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
404 this, SLOT(on_actionDebugMessageModel_triggered())));
405 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
406 this, SLOT(on_actionDebugHotList_triggered())));
407 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
408 this, SLOT(on_actionDebugLog_triggered())));
409 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
410 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
412 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
413 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
416 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
418 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
419 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
423 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
424 const int jumpModifier = Qt::ControlModifier;
426 const int bindModifier = Qt::ControlModifier;
427 const int jumpModifier = Qt::AltModifier;
430 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
431 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
432 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
433 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
434 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
435 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
436 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
437 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
438 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
439 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
440 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
441 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
442 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
443 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
444 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
445 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
446 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
447 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
448 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
449 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
451 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
452 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
453 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
454 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
455 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
456 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
457 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
458 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
459 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
460 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
461 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
462 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
463 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
464 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
465 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
466 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
467 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
468 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
469 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
470 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
473 coll->addAction("NextBufferView", new Action(SmallIcon("go-next-view"), tr("Activate Next Chat List"), coll,
474 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
475 coll->addAction("PreviousBufferView", new Action(SmallIcon("go-previous-view"), tr("Activate Previous Chat List"), coll,
476 this, SLOT(previousBufferView()), QKeySequence::Back));
477 coll->addAction("NextBuffer", new Action(SmallIcon("go-down"), tr("Go to Next Chat"), coll,
478 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
479 coll->addAction("PreviousBuffer", new Action(SmallIcon("go-up"), tr("Go to Previous Chat"), coll,
480 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
484 void MainWin::setupMenus()
486 ActionCollection *coll = QtUi::actionCollection("General");
488 _fileMenu = menuBar()->addMenu(tr("&File"));
490 static const QStringList coreActions = QStringList()
491 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
494 foreach(QString actionName, coreActions) {
495 coreAction = coll->action(actionName);
496 _fileMenu->addAction(coreAction);
497 flagRemoteCoreOnly(coreAction);
499 flagRemoteCoreOnly(_fileMenu->addSeparator());
501 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
502 _networksMenu->addAction(coll->action("ConfigureNetworks"));
503 _networksMenu->addSeparator();
504 _fileMenu->addSeparator();
505 _fileMenu->addAction(coll->action("Quit"));
507 _viewMenu = menuBar()->addMenu(tr("&View"));
508 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
509 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
510 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
511 _viewMenu->addSeparator();
513 _viewMenu->addAction(coll->action("ToggleMenuBar"));
514 _viewMenu->addAction(coll->action("ToggleStatusBar"));
515 _viewMenu->addAction(coll->action("ToggleSearchBar"));
517 coreAction = coll->action("ShowAwayLog");
518 flagRemoteCoreOnly(coreAction);
519 _viewMenu->addAction(coreAction);
521 _viewMenu->addSeparator();
522 _viewMenu->addAction(coll->action("LockLayout"));
524 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
526 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
527 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
529 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
531 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
533 _helpMenu = menuBar()->addMenu(tr("&Help"));
534 _helpMenu->addAction(coll->action("AboutQuassel"));
536 _helpMenu->addAction(coll->action("AboutQt"));
538 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
540 _helpMenu->addSeparator();
541 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
542 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
543 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
544 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
545 _helpDebugMenu->addAction(coll->action("DebugHotList"));
546 _helpDebugMenu->addAction(coll->action("DebugLog"));
547 _helpDebugMenu->addSeparator();
548 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
551 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
553 QtUiSettings uiSettings;
554 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
555 showMenuBar->setChecked(enabled);
556 enabled ? menuBar()->show() : menuBar()->hide();
558 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
559 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
563 void MainWin::setupBufferWidget()
565 _bufferWidget = new BufferWidget(this);
566 _bufferWidget->setModel(Client::bufferModel());
567 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
568 setCentralWidget(_bufferWidget);
572 void MainWin::addBufferView(int bufferViewConfigId)
574 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
578 void MainWin::addBufferView(ClientBufferViewConfig *config)
583 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
584 BufferViewDock *dock = new BufferViewDock(config, this);
586 //create the view and initialize it's filter
587 BufferView *view = new BufferView(dock);
588 view->setFilteredModel(Client::bufferModel(), config);
589 view->installEventFilter(_inputWidget); // for key presses
591 Client::bufferModel()->synchronizeView(view);
593 dock->setWidget(view);
594 dock->setVisible(_layoutLoaded); // don't show before state has been restored
596 addDockWidget(Qt::LeftDockWidgetArea, dock);
597 _bufferViewsMenu->addAction(dock->toggleViewAction());
599 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
600 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
601 _bufferViews.append(dock);
603 if (!activeBufferView())
608 void MainWin::removeBufferView(int bufferViewConfigId)
611 BufferViewDock *dock;
612 foreach(QAction *action, _bufferViewsMenu->actions()) {
613 actionData = action->data();
614 if (!actionData.isValid())
617 dock = qobject_cast<BufferViewDock *>(action->parent());
618 if (dock && actionData.toInt() == bufferViewConfigId) {
619 removeAction(action);
620 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
621 _bufferViews.removeAll(dock);
623 if (dock->isActive()) {
624 dock->setActive(false);
625 _activeBufferViewIndex = -1;
635 void MainWin::bufferViewToggled(bool enabled)
637 if (!enabled && !isVisible()) {
638 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
639 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
642 QAction *action = qobject_cast<QAction *>(sender());
644 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
647 // Make sure we don't toggle backlog fetch for a view we've already removed
648 if (!_bufferViews.contains(dock))
652 Client::bufferViewOverlay()->addView(dock->bufferViewId());
654 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
658 void MainWin::bufferViewVisibilityChanged(bool visible)
661 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
663 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
668 BufferView *MainWin::allBuffersView() const
670 // "All Buffers" is always the first dock created
671 if (_bufferViews.count() > 0)
672 return _bufferViews[0]->bufferView();
677 BufferView *MainWin::activeBufferView() const
679 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
681 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
682 return dock->isActive() ? qobject_cast<BufferView *>(dock->widget()) : 0;
686 void MainWin::changeActiveBufferView(int bufferViewId)
688 if (bufferViewId < 0)
691 BufferView *current = activeBufferView();
693 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
694 _activeBufferViewIndex = -1;
697 for (int i = 0; i < _bufferViews.count(); i++) {
698 BufferViewDock *dock = _bufferViews.at(i);
699 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
700 _activeBufferViewIndex = i;
701 dock->setActive(true);
706 nextBufferView(); // fallback
710 void MainWin::changeActiveBufferView(bool backwards)
712 BufferView *current = activeBufferView();
714 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
716 if (!_bufferViews.count())
719 int c = _bufferViews.count();
720 while (c--) { // yes, this will reactivate the current active one if all others fail
722 if (--_activeBufferViewIndex < 0)
723 _activeBufferViewIndex = _bufferViews.count()-1;
726 if (++_activeBufferViewIndex >= _bufferViews.count())
727 _activeBufferViewIndex = 0;
730 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
731 if (dock->isHidden())
734 dock->setActive(true);
738 _activeBufferViewIndex = -1;
742 void MainWin::nextBufferView()
744 changeActiveBufferView(false);
748 void MainWin::previousBufferView()
750 changeActiveBufferView(true);
754 void MainWin::nextBuffer()
756 BufferView *view = activeBufferView();
762 void MainWin::previousBuffer()
764 BufferView *view = activeBufferView();
766 view->previousBuffer();
770 void MainWin::hideCurrentBuffer()
772 BufferView *view = activeBufferView();
774 view->hideCurrentBuffer();
778 void MainWin::showNotificationsDlg()
780 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
785 void MainWin::on_actionConfigureNetworks_triggered()
787 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
792 void MainWin::on_actionConfigureViews_triggered()
794 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
799 void MainWin::on_actionLockLayout_toggled(bool lock)
801 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
802 foreach(VerticalDock *dock, docks) {
803 dock->showTitle(!lock);
805 if (Client::bufferViewManager()) {
806 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
807 config->setLocked(lock);
810 QtUiSettings().setValue("LockLayout", lock);
814 void MainWin::setupNickWidget()
817 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
818 nickDock->setObjectName("NickDock");
819 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
821 _nickListWidget = new NickListWidget(nickDock);
822 nickDock->setWidget(_nickListWidget);
824 addDockWidget(Qt::RightDockWidgetArea, nickDock);
825 _viewMenu->addAction(nickDock->toggleViewAction());
826 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
828 // See NickListDock::NickListDock();
829 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
831 // attach the NickListWidget to the BufferModel and the default selection
832 _nickListWidget->setModel(Client::bufferModel());
833 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
837 void MainWin::setupChatMonitor()
839 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
840 dock->setObjectName("ChatMonitorDock");
842 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
843 _chatMonitorView = new ChatMonitorView(filter, this);
844 _chatMonitorView->setFocusProxy(_inputWidget);
845 _chatMonitorView->show();
846 dock->setWidget(_chatMonitorView);
849 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
850 _viewMenu->addAction(dock->toggleViewAction());
851 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
855 void MainWin::setupInputWidget()
857 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
858 dock->setObjectName("InputDock");
860 _inputWidget = new InputWidget(dock);
861 dock->setWidget(_inputWidget);
863 addDockWidget(Qt::BottomDockWidgetArea, dock);
865 _viewMenu->addAction(dock->toggleViewAction());
866 dock->toggleViewAction()->setText(tr("Show Input Line"));
868 _inputWidget->setModel(Client::bufferModel());
869 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
871 _bufferWidget->setFocusProxy(_inputWidget);
873 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
875 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
879 void MainWin::setupTopicWidget()
881 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
882 dock->setObjectName("TopicDock");
883 _topicWidget = new TopicWidget(dock);
885 dock->setWidget(_topicWidget);
887 _topicWidget->setModel(Client::bufferModel());
888 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
890 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
892 _viewMenu->addAction(dock->toggleViewAction());
893 dock->toggleViewAction()->setText(tr("Show Topic Line"));
897 void MainWin::setupViewMenuTail()
899 _viewMenu->addSeparator();
900 _viewMenu->addAction(QtUi::actionCollection("General")->action("ToggleFullscreen"));
904 void MainWin::setupTitleSetter()
906 _titleSetter.setModel(Client::bufferModel());
907 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
911 void MainWin::setupStatusBar()
913 // MessageProcessor progress
914 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
917 _coreConnectionStatusWidget->update();
918 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
920 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
922 QtUiSettings uiSettings;
924 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
925 showStatusbar->setChecked(enabled);
926 enabled ? statusBar()->show() : statusBar()->hide();
928 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
929 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
931 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
935 void MainWin::setupHotList()
937 FlatProxyModel *flatProxy = new FlatProxyModel(this);
938 flatProxy->setSourceModel(Client::bufferModel());
939 _bufferHotList = new BufferHotListFilter(flatProxy);
943 void MainWin::saveMenuBarStatus(bool enabled)
945 QtUiSettings uiSettings;
946 uiSettings.setValue("ShowMenuBar", enabled);
950 void MainWin::saveStatusBarStatus(bool enabled)
952 QtUiSettings uiSettings;
953 uiSettings.setValue("ShowStatusBar", enabled);
957 void MainWin::setupSystray()
960 _systemTray = new StatusNotifierItem(this);
961 #elif !defined QT_NO_SYSTEMTRAYICON
962 _systemTray = new LegacySystemTray(this);
964 _systemTray = new SystemTray(this); // dummy
970 void MainWin::setupToolBars()
972 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
973 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
974 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
975 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
978 setUnifiedTitleAndToolBarOnMac(true);
982 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
984 _mainToolBar = new QToolBar(this);
985 _mainToolBar->setObjectName("MainToolBar");
987 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
988 addToolBar(_mainToolBar);
990 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
991 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
995 void MainWin::connectedToCore()
997 Q_CHECK_PTR(Client::bufferViewManager());
998 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
999 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1000 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1002 setConnectedState();
1006 void MainWin::setConnectedState()
1008 ActionCollection *coll = QtUi::actionCollection("General");
1010 coll->action("ConnectCore")->setEnabled(false);
1011 coll->action("DisconnectCore")->setEnabled(true);
1012 coll->action("CoreInfo")->setEnabled(true);
1014 foreach(QAction *action, _fileMenu->actions()) {
1015 if (isRemoteCoreOnly(action))
1016 action->setVisible(!Client::internalCore());
1019 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1020 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1021 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1022 if (!Client::internalCore()) {
1023 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1024 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1025 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1028 // _viewMenu->setEnabled(true);
1029 if (!Client::internalCore())
1030 statusBar()->showMessage(tr("Connected to core."));
1032 statusBar()->clearMessage();
1034 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1036 systemTray()->setState(SystemTray::Active);
1038 if (Client::networkIds().isEmpty()) {
1039 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1043 // Monolithic always preselects last used buffer - Client only if the connection died
1044 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1046 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1047 if (lastUsedBufferId.isValid())
1048 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1054 void MainWin::loadLayout()
1057 int accountId = Client::currentCoreAccount().accountId().toInt();
1058 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1059 if (state.isEmpty()) {
1060 foreach(BufferViewDock *view, _bufferViews)
1062 _layoutLoaded = true;
1066 restoreState(state, accountId);
1067 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1068 if (bufferViewId >= 0)
1069 changeActiveBufferView(bufferViewId);
1071 _layoutLoaded = true;
1075 void MainWin::saveLayout()
1078 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1079 if (accountId > 0) {
1080 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1081 BufferView *view = activeBufferView();
1082 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1087 void MainWin::disconnectedFromCore()
1089 // save core specific layout and remove bufferviews;
1091 _layoutLoaded = false;
1093 QVariant actionData;
1094 BufferViewDock *dock;
1095 foreach(QAction *action, _bufferViewsMenu->actions()) {
1096 actionData = action->data();
1097 if (!actionData.isValid())
1100 dock = qobject_cast<BufferViewDock *>(action->parent());
1101 if (dock && actionData.toInt() != -1) {
1102 removeAction(action);
1103 _bufferViews.removeAll(dock);
1104 dock->deleteLater();
1108 // store last active buffer
1110 BufferId lastBufId = _bufferWidget->currentBuffer();
1111 if (lastBufId.isValid()) {
1112 s.setValue("LastUsedBufferId", lastBufId.toInt());
1113 // clear the current selection
1114 Client::bufferModel()->standardSelectionModel()->clearSelection();
1116 restoreState(s.value("MainWinState").toByteArray());
1117 setDisconnectedState();
1121 void MainWin::setDisconnectedState()
1123 ActionCollection *coll = QtUi::actionCollection("General");
1124 //ui.menuCore->setEnabled(false);
1125 coll->action("ConnectCore")->setEnabled(true);
1126 coll->action("DisconnectCore")->setEnabled(false);
1127 coll->action("CoreInfo")->setEnabled(false);
1128 //_viewMenu->setEnabled(false);
1129 statusBar()->showMessage(tr("Not connected to core."));
1130 if (_msgProcessorStatusWidget)
1131 _msgProcessorStatusWidget->setProgress(0, 0);
1133 systemTray()->setState(SystemTray::Passive);
1137 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1139 Q_UNUSED(errorMessage)
1140 CoreConnectAuthDlg dlg(account, this);
1141 *valid = (dlg.exec() == QDialog::Accepted);
1145 void MainWin::handleNoSslInClient(bool *accepted)
1147 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1148 QMessageBox::Ignore|QMessageBox::Cancel, this);
1149 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1150 box.setDefaultButton(QMessageBox::Ignore);
1151 *accepted = box.exec() == QMessageBox::Ignore;
1155 void MainWin::handleNoSslInCore(bool *accepted)
1157 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1158 QMessageBox::Ignore|QMessageBox::Cancel, this);
1159 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1160 box.setDefaultButton(QMessageBox::Ignore);
1161 *accepted = box.exec() == QMessageBox::Ignore;
1167 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1169 QString errorString = "<ul>";
1170 foreach(const QSslError error, socket->sslErrors())
1171 errorString += QString("<li>%1</li>").arg(error.errorString());
1172 errorString += "</ul>";
1174 QMessageBox box(QMessageBox::Warning,
1175 tr("Untrusted Security Certificate"),
1176 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1177 QMessageBox::Cancel, this);
1178 box.setInformativeText(errorString);
1179 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1180 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1182 QMessageBox::ButtonRole role;
1185 role = box.buttonRole(box.clickedButton());
1186 if (role == QMessageBox::HelpRole) {
1187 SslInfoDlg dlg(socket, this);
1191 while (role == QMessageBox::HelpRole);
1193 *accepted = role == QMessageBox::AcceptRole;
1195 QMessageBox box2(QMessageBox::Warning,
1196 tr("Untrusted Security Certificate"),
1197 tr("Would you like to accept this certificate forever without being prompted?"),
1199 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1200 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1202 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1207 #endif /* HAVE_SSL */
1209 void MainWin::handleCoreConnectionError(const QString &error)
1211 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1215 void MainWin::showCoreConnectionDlg()
1217 CoreConnectDlg dlg(this);
1218 if (dlg.exec() == QDialog::Accepted) {
1219 AccountId accId = dlg.selectedAccount();
1220 if (accId.isValid())
1221 Client::coreConnection()->connectToCore(accId);
1226 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1228 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1234 void MainWin::showChannelList(NetworkId netId)
1236 ChannelListDlg *channelListDlg = new ChannelListDlg();
1238 if (!netId.isValid()) {
1239 QAction *action = qobject_cast<QAction *>(sender());
1241 netId = action->data().value<NetworkId>();
1244 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1245 channelListDlg->setNetwork(netId);
1246 channelListDlg->show();
1250 void MainWin::showIgnoreList(QString newRule)
1252 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1253 // prepare config dialog for new rule
1254 if (!newRule.isEmpty())
1255 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1260 void MainWin::showCoreInfoDlg()
1262 CoreInfoDlg(this).exec();
1266 void MainWin::showAwayLog()
1270 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1271 _awayLog = new AwayLogView(filter, 0);
1272 filter->setParent(_awayLog);
1273 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1274 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1279 void MainWin::awayLogDestroyed()
1285 void MainWin::showSettingsDlg()
1287 SettingsDlg *dlg = new SettingsDlg();
1289 //Category: Interface
1290 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1291 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1292 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1293 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1294 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1295 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1296 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1297 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1298 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1299 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1302 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1303 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1304 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1305 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1306 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1308 // Category: Remote Cores
1309 if (Quassel::runMode() != Quassel::Monolithic) {
1310 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1311 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1318 void MainWin::showAboutDlg()
1320 AboutDlg(this).exec();
1324 void MainWin::showShortcutsDlg()
1327 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1328 foreach(KActionCollection *coll, QtUi::actionCollections())
1329 dlg.addCollection(coll, coll->property("Category").toString());
1332 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1338 void MainWin::toggleFullscreen()
1347 /********************************************************************************************************/
1349 bool MainWin::event(QEvent *event)
1351 if (event->type() == QEvent::WindowActivate) {
1352 BufferId buffer = Client::bufferModel()->currentBuffer();
1353 if (buffer.isValid())
1354 Client::instance()->markBufferAsRead(buffer);
1356 return QMainWindow::event(event);
1360 void MainWin::moveEvent(QMoveEvent *event)
1362 if (!(windowState() & Qt::WindowMaximized))
1363 _normalPos = event->pos();
1365 QMainWindow::moveEvent(event);
1369 void MainWin::resizeEvent(QResizeEvent *event)
1371 if (!(windowState() & Qt::WindowMaximized))
1372 _normalSize = event->size();
1374 QMainWindow::resizeEvent(event);
1378 void MainWin::closeEvent(QCloseEvent *event)
1381 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1383 if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1384 QtUi::hideMainWidget();
1394 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1398 bool hasFocus = QApplication::activeWindow() != 0;
1400 for (int i = start; i <= end; i++) {
1401 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1402 if (!idx.isValid()) {
1403 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1406 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1407 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1410 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1411 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1413 // check if bufferId belongs to the shown chatlists
1414 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1415 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1418 // check if it's the buffer currently displayed
1419 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1422 // only show notifications for higlights or queries
1423 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1426 // and of course: don't notify for ignored messages
1427 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1430 // seems like we have a legit notification candidate!
1431 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1432 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1433 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1434 AbstractNotificationBackend::NotificationType type;
1436 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1437 type = AbstractNotificationBackend::PrivMsg;
1438 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1439 type = AbstractNotificationBackend::PrivMsgFocused;
1440 else if (flags & Message::Highlight && !hasFocus)
1441 type = AbstractNotificationBackend::Highlight;
1443 type = AbstractNotificationBackend::HighlightFocused;
1445 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1450 void MainWin::currentBufferChanged(BufferId buffer)
1452 if (buffer.isValid())
1453 Client::instance()->markBufferAsRead(buffer);
1457 void MainWin::clientNetworkCreated(NetworkId id)
1459 const Network *net = Client::network(id);
1460 QAction *act = new QAction(net->networkName(), this);
1461 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1462 act->setData(QVariant::fromValue<NetworkId>(id));
1463 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1464 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1466 QAction *beforeAction = 0;
1467 foreach(QAction *action, _networksMenu->actions()) {
1468 if (!action->data().isValid()) // ignore stock actions
1470 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1471 beforeAction = action;
1475 _networksMenu->insertAction(beforeAction, act);
1479 void MainWin::clientNetworkUpdated()
1481 const Network *net = qobject_cast<const Network *>(sender());
1485 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1489 action->setText(net->networkName());
1491 switch (net->connectionState()) {
1492 case Network::Initialized:
1493 action->setIcon(SmallIcon("network-connect"));
1494 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1495 if (!bufferWidget()->currentBuffer().isValid()) {
1496 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1497 if (idx.isValid()) {
1498 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1499 Client::bufferModel()->switchToBuffer(statusBufferId);
1503 case Network::Disconnected:
1504 action->setIcon(SmallIcon("network-disconnect"));
1507 action->setIcon(SmallIcon("network-wired"));
1512 void MainWin::clientNetworkRemoved(NetworkId id)
1514 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1518 action->deleteLater();
1522 void MainWin::connectOrDisconnectFromNet()
1524 QAction *act = qobject_cast<QAction *>(sender());
1526 const Network *net = Client::network(act->data().value<NetworkId>());
1528 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1529 else net->requestDisconnect();
1533 void MainWin::on_jumpHotBuffer_triggered()
1535 if (!_bufferHotList->rowCount())
1538 QModelIndex topIndex = _bufferHotList->index(0, 0);
1539 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1540 Client::bufferModel()->switchToBuffer(bufferId);
1544 void MainWin::onJumpKey()
1546 QAction *action = qobject_cast<QAction *>(sender());
1547 if (!action || !Client::bufferModel())
1549 int idx = action->property("Index").toInt();
1551 if (_jumpKeyMap.isEmpty())
1552 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1554 if (!_jumpKeyMap.contains(idx))
1557 BufferId buffer = _jumpKeyMap.value(idx);
1558 if (buffer.isValid())
1559 Client::bufferModel()->switchToBuffer(buffer);
1563 void MainWin::bindJumpKey()
1565 QAction *action = qobject_cast<QAction *>(sender());
1566 if (!action || !Client::bufferModel())
1568 int idx = action->property("Index").toInt();
1570 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1571 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1575 void MainWin::on_actionDebugNetworkModel_triggered()
1577 QTreeView *view = new QTreeView;
1578 view->setAttribute(Qt::WA_DeleteOnClose);
1579 view->setWindowTitle("Debug NetworkModel View");
1580 view->setModel(Client::networkModel());
1581 view->setColumnWidth(0, 250);
1582 view->setColumnWidth(1, 250);
1583 view->setColumnWidth(2, 80);
1584 view->resize(610, 300);
1589 void MainWin::on_actionDebugHotList_triggered()
1591 QTreeView *view = new QTreeView;
1592 view->setAttribute(Qt::WA_DeleteOnClose);
1593 view->setModel(_bufferHotList);
1598 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1600 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1601 overlay->setAttribute(Qt::WA_DeleteOnClose);
1606 void MainWin::on_actionDebugMessageModel_triggered()
1608 QTableView *view = new QTableView(0);
1609 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1610 filter->setSourceModel(Client::messageModel());
1611 view->setModel(filter);
1612 view->setAttribute(Qt::WA_DeleteOnClose, true);
1613 view->verticalHeader()->hide();
1614 view->horizontalHeader()->setStretchLastSection(true);
1619 void MainWin::on_actionDebugLog_triggered()
1621 DebugLogWidget *logWidget = new DebugLogWidget(0);
1626 void MainWin::showStatusBarMessage(const QString &message)
1628 statusBar()->showMessage(message, 10000);