1 /***************************************************************************
2 * Copyright (C) 2005-2015 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
25 #include <QMessageBox>
31 # include <KActionCollection>
34 # include <KShortcutsDialog>
35 # include <KStatusBar>
36 # include <KToggleFullScreenAction>
38 # include <KWindowSystem>
42 # include <KConfigWidgets/KStandardAction>
43 # include <KXmlGui/KHelpMenu>
44 # include <KXmlGui/KShortcutsDialog>
52 #include "awaylogfilter.h"
53 #include "awaylogview.h"
55 #include "actioncollection.h"
56 #include "bufferhotlistfilter.h"
57 #include "buffermodel.h"
58 #include "bufferview.h"
59 #include "bufferviewoverlay.h"
60 #include "bufferviewoverlayfilter.h"
61 #include "bufferwidget.h"
62 #include "channellistdlg.h"
63 #include "chatlinemodel.h"
64 #include "chatmonitorfilter.h"
65 #include "chatmonitorview.h"
68 #include "clientbacklogmanager.h"
69 #include "clientbufferviewconfig.h"
70 #include "clientbufferviewmanager.h"
71 #include "clientignorelistmanager.h"
72 #include "clienttransfer.h"
73 #include "clienttransfermanager.h"
74 #include "coreconfigwizard.h"
75 #include "coreconnectdlg.h"
76 #include "coreconnection.h"
77 #include "coreconnectionstatuswidget.h"
78 #include "coreinfodlg.h"
79 #include "contextmenuactionprovider.h"
80 #include "debugbufferviewoverlay.h"
81 #include "debuglogwidget.h"
82 #include "debugmessagemodelfilter.h"
83 #include "flatproxymodel.h"
84 #include "inputwidget.h"
85 #include "irclistmodel.h"
86 #include "ircconnectionwizard.h"
87 #include "legacysystemtray.h"
88 #include "msgprocessorstatuswidget.h"
89 #include "nicklistwidget.h"
90 #include "qtuiapplication.h"
91 #include "qtuimessageprocessor.h"
92 #include "qtuisettings.h"
93 #include "qtuistyle.h"
94 #include "receivefiledlg.h"
95 #include "settingsdlg.h"
96 #include "settingspagedlg.h"
97 #include "statusnotifieritem.h"
98 #include "toolbaractionprovider.h"
99 #include "topicwidget.h"
100 #include "verticaldock.h"
104 # include "phononnotificationbackend.h"
106 # ifdef HAVE_LIBSNORE
107 # include "snorenotificationbackend.h"
109 # include "systraynotificationbackend.h"
110 # include "taskbarnotificationbackend.h"
112 # include "knotificationbackend.h"
113 #endif /* HAVE_KDE */
116 # include "sslinfodlg.h"
119 #ifdef HAVE_INDICATEQT
120 #include "indicatornotificationbackend.h"
123 #ifdef HAVE_NOTIFICATION_CENTER
124 #include "osxnotificationbackend.h"
128 #include "dockmanagernotificationbackend.h"
131 #include "settingspages/aliasessettingspage.h"
132 #include "settingspages/appearancesettingspage.h"
133 #include "settingspages/backlogsettingspage.h"
134 #include "settingspages/bufferviewsettingspage.h"
135 #include "settingspages/chatmonitorsettingspage.h"
136 #include "settingspages/chatviewsettingspage.h"
137 #include "settingspages/connectionsettingspage.h"
138 #include "settingspages/coreaccountsettingspage.h"
139 #include "settingspages/coreconnectionsettingspage.h"
140 #include "settingspages/highlightsettingspage.h"
141 #include "settingspages/identitiessettingspage.h"
142 #include "settingspages/ignorelistsettingspage.h"
143 #include "settingspages/inputwidgetsettingspage.h"
144 #include "settingspages/itemviewsettingspage.h"
145 #include "settingspages/networkssettingspage.h"
146 #include "settingspages/notificationssettingspage.h"
147 #include "settingspages/topicwidgetsettingspage.h"
150 # include "settingspages/shortcutssettingspage.h"
153 MainWin::MainWin(QWidget *parent)
155 : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)),
157 : QMainWindow(parent),
159 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
160 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
163 _layoutLoaded(false),
164 _activeBufferViewIndex(-1)
166 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
168 QtUiSettings uiSettings;
169 QString style = uiSettings.value("Style", QString()).toString();
170 if (!style.isEmpty()) {
171 QApplication::setStyle(style);
174 QApplication::setQuitOnLastWindowClosed(false);
176 setWindowTitle("Quassel IRC");
177 setWindowIconText("Quassel IRC");
184 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
185 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
186 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
187 SLOT(messagesInserted(const QModelIndex &, int, int)));
188 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
189 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
191 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
192 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
193 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
194 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool *)), SLOT(handleNoSslInClient(bool *)));
195 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool *)), SLOT(handleNoSslInCore(bool *)));
197 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
201 setDockNestingEnabled(true);
202 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
203 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
204 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
205 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
207 // Order is sometimes important
224 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
226 # ifdef HAVE_LIBSNORE
227 QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
228 # elif !defined(QT_NO_SYSTEMTRAYICON)
229 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
232 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
235 QtUi::registerNotificationBackend(new KNotificationBackend(this));
236 #endif /* HAVE_KDE */
238 #ifdef HAVE_INDICATEQT
239 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
242 #ifdef HAVE_NOTIFICATION_CENTER
243 QtUi::registerNotificationBackend(new OSXNotificationBackend(this));
247 QtUi::registerNotificationBackend(new DockManagerNotificationBackend(this));
250 // we assume that at this point, all configurable actions are defined!
251 QtUi::loadShortcuts();
253 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
255 setDisconnectedState(); // Disable menus and stuff
258 setAutoSaveSettings();
261 // restore mainwin state
263 restoreStateFromSettings(s);
265 // restore locked state of docks
266 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
268 CoreConnection *conn = Client::coreConnection();
269 if (!conn->connectToCore()) {
270 // No autoconnect selected (or no accounts)
271 showCoreConnectionDlg();
284 saveStateToSettings(s);
286 QApplication::quit();
290 void MainWin::saveStateToSettings(UiSettings &s)
292 s.setValue("MainWinSize", _normalSize);
293 s.setValue("MainWinPos", _normalPos);
294 s.setValue("MainWinState", saveState());
295 s.setValue("MainWinGeometry", saveGeometry());
296 s.setValue("MainWinMinimized", isMinimized());
297 s.setValue("MainWinMaximized", isMaximized());
298 s.setValue("MainWinHidden", !isVisible());
299 BufferId lastBufId = Client::bufferModel()->currentBuffer();
300 if (lastBufId.isValid())
301 s.setValue("LastUsedBufferId", lastBufId.toInt());
304 saveAutoSaveSettings();
309 void MainWin::restoreStateFromSettings(UiSettings &s)
311 _normalSize = s.value("MainWinSize", size()).toSize();
312 _normalPos = s.value("MainWinPos", pos()).toPoint();
313 bool maximized = s.value("MainWinMaximized", false).toBool();
316 restoreGeometry(s.value("MainWinGeometry").toByteArray());
319 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
324 restoreState(s.value("MainWinState").toByteArray());
330 if ((Quassel::isOptionSet("hidewindow")
331 || s.value("MainWinHidden").toBool())
332 && _systemTray->isSystemTrayAvailable())
333 QtUi::hideMainWidget();
334 else if (s.value("MainWinMinimized").toBool())
343 void MainWin::updateIcon()
346 if (Client::isConnected())
347 icon = QIcon::fromTheme("quassel", QIcon(":/icons/quassel-128.png"));
349 icon = QIcon::fromTheme("quassel-inactive", QIcon(":/icons/quassel-128.png"));
351 qApp->setWindowIcon(icon);
355 void MainWin::setupActions()
357 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
359 coll->addAction("ConnectCore", new Action(QIcon::fromTheme("network-connect"), tr("&Connect to Core..."), coll,
360 this, SLOT(showCoreConnectionDlg())));
361 coll->addAction("DisconnectCore", new Action(QIcon::fromTheme("network-disconnect"), tr("&Disconnect from Core"), coll,
362 Client::instance(), SLOT(disconnectFromCore())));
363 coll->addAction("CoreInfo", new Action(QIcon::fromTheme("help-about"), tr("Core &Info..."), coll,
364 this, SLOT(showCoreInfoDlg())));
365 coll->addAction("ConfigureNetworks", new Action(QIcon::fromTheme("configure"), tr("Configure &Networks..."), coll,
366 this, SLOT(on_actionConfigureNetworks_triggered())));
367 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
368 coll->addAction("Quit", new Action(QIcon::fromTheme("application-exit"), tr("&Quit"), coll,
369 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
372 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
373 this, SLOT(on_actionConfigureViews_triggered())));
375 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
376 lockAct->setCheckable(true);
377 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
379 coll->addAction("ToggleSearchBar", new Action(QIcon::fromTheme("edit-find"), tr("Show &Search Bar"), coll,
380 0, 0, QKeySequence::Find))->setCheckable(true);
381 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
382 this, SLOT(showAwayLog())));
383 coll->addAction("ToggleMenuBar", new Action(QIcon::fromTheme("show-menu"), tr("Show &Menubar"), coll,
384 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
386 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
387 0, 0))->setCheckable(true);
390 QAction *fullScreenAct = KStandardAction::fullScreen(this, SLOT(onFullScreenToggled()), this, coll);
392 QAction *fullScreenAct = new Action(QIcon::fromTheme("view-fullscreen"), tr("&Full Screen Mode"), coll,
393 this, SLOT(onFullScreenToggled()), QKeySequence(Qt::Key_F11));
394 fullScreenAct->setCheckable(true);
396 coll->addAction("ToggleFullScreen", fullScreenAct);
399 QAction *configureShortcutsAct = new Action(QIcon::fromTheme("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
400 this, SLOT(showShortcutsDlg()));
401 configureShortcutsAct->setMenuRole(QAction::NoRole);
402 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
405 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
406 this, SLOT(showSettingsDlg()));
407 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
409 QAction *configureQuasselAct = new Action(QIcon::fromTheme("configure"), tr("&Configure Quassel..."), coll,
410 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
412 coll->addAction("ConfigureQuassel", configureQuasselAct);
415 QAction *aboutQuasselAct = new Action(QIcon(":/icons/quassel.png"), tr("&About Quassel"), coll,
416 this, SLOT(showAboutDlg()));
417 aboutQuasselAct->setMenuRole(QAction::AboutRole);
418 coll->addAction("AboutQuassel", aboutQuasselAct);
420 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
421 qApp, SLOT(aboutQt()));
422 aboutQtAct->setMenuRole(QAction::AboutQtRole);
423 coll->addAction("AboutQt", aboutQtAct);
424 coll->addAction("DebugNetworkModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &NetworkModel"), coll,
425 this, SLOT(on_actionDebugNetworkModel_triggered())));
426 coll->addAction("DebugBufferViewOverlay", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
427 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
428 coll->addAction("DebugMessageModel", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &MessageModel"), coll,
429 this, SLOT(on_actionDebugMessageModel_triggered())));
430 coll->addAction("DebugHotList", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &HotList"), coll,
431 this, SLOT(on_actionDebugHotList_triggered())));
432 coll->addAction("DebugLog", new Action(QIcon::fromTheme("tools-report-bug"), tr("Debug &Log"), coll,
433 this, SLOT(on_actionDebugLog_triggered())));
434 coll->addAction("ReloadStyle", new Action(QIcon::fromTheme("view-refresh"), tr("Reload Stylesheet"), coll,
435 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
437 coll->addAction("HideCurrentBuffer", new Action(tr("Hide Current Buffer"), coll,
438 this, SLOT(hideCurrentBuffer()), QKeySequence::Close));
441 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
443 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
444 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
448 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
449 const int jumpModifier = Qt::ControlModifier;
451 const int bindModifier = Qt::ControlModifier;
452 const int jumpModifier = Qt::AltModifier;
455 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
456 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
457 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
458 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
459 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
460 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
461 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
462 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
463 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
464 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
465 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
466 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
467 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
468 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
469 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
470 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
471 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
472 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
473 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
474 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
476 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
477 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
478 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
479 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
480 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
481 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
482 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
483 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
484 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
485 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
486 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
487 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
488 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
489 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
490 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
491 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
492 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
493 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
494 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
495 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
498 coll->addAction("NextBufferView", new Action(QIcon::fromTheme("go-next-view"), tr("Activate Next Chat List"), coll,
499 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
500 coll->addAction("PreviousBufferView", new Action(QIcon::fromTheme("go-previous-view"), tr("Activate Previous Chat List"), coll,
501 this, SLOT(previousBufferView()), QKeySequence::Back));
502 coll->addAction("NextBuffer", new Action(QIcon::fromTheme("go-down"), tr("Go to Next Chat"), coll,
503 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
504 coll->addAction("PreviousBuffer", new Action(QIcon::fromTheme("go-up"), tr("Go to Previous Chat"), coll,
505 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
509 void MainWin::setupMenus()
511 ActionCollection *coll = QtUi::actionCollection("General");
513 _fileMenu = menuBar()->addMenu(tr("&File"));
515 static const QStringList coreActions = QStringList()
516 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
519 foreach(QString actionName, coreActions) {
520 coreAction = coll->action(actionName);
521 _fileMenu->addAction(coreAction);
522 flagRemoteCoreOnly(coreAction);
524 flagRemoteCoreOnly(_fileMenu->addSeparator());
526 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
527 _networksMenu->addAction(coll->action("ConfigureNetworks"));
528 _networksMenu->addSeparator();
529 _fileMenu->addSeparator();
530 _fileMenu->addAction(coll->action("Quit"));
532 _viewMenu = menuBar()->addMenu(tr("&View"));
533 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
534 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
535 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
536 _viewMenu->addSeparator();
538 _viewMenu->addAction(coll->action("ToggleMenuBar"));
539 _viewMenu->addAction(coll->action("ToggleStatusBar"));
540 _viewMenu->addAction(coll->action("ToggleSearchBar"));
542 coreAction = coll->action("ShowAwayLog");
543 flagRemoteCoreOnly(coreAction);
544 _viewMenu->addAction(coreAction);
546 _viewMenu->addSeparator();
547 _viewMenu->addAction(coll->action("LockLayout"));
549 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
551 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
552 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
554 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
556 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
558 _helpMenu = menuBar()->addMenu(tr("&Help"));
560 _helpMenu->addAction(coll->action("AboutQuassel"));
562 _helpMenu->addAction(coll->action("AboutQt"));
564 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
566 _helpMenu->addSeparator();
567 _helpDebugMenu = _helpMenu->addMenu(QIcon::fromTheme("tools-report-bug"), tr("Debug"));
568 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
569 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
570 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
571 _helpDebugMenu->addAction(coll->action("DebugHotList"));
572 _helpDebugMenu->addAction(coll->action("DebugLog"));
573 _helpDebugMenu->addSeparator();
574 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
577 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
579 QtUiSettings uiSettings;
580 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
581 showMenuBar->setChecked(enabled);
582 enabled ? menuBar()->show() : menuBar()->hide();
584 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
585 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
589 void MainWin::setupBufferWidget()
591 _bufferWidget = new BufferWidget(this);
592 _bufferWidget->setModel(Client::bufferModel());
593 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
594 setCentralWidget(_bufferWidget);
598 void MainWin::addBufferView(int bufferViewConfigId)
600 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
604 void MainWin::addBufferView(ClientBufferViewConfig *config)
609 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
610 BufferViewDock *dock = new BufferViewDock(config, this);
612 //create the view and initialize it's filter
613 BufferView *view = new BufferView(dock);
614 view->setFilteredModel(Client::bufferModel(), config);
615 view->installEventFilter(_inputWidget); // for key presses
617 Client::bufferModel()->synchronizeView(view);
619 dock->setWidget(view);
620 dock->setVisible(_layoutLoaded); // don't show before state has been restored
622 addDockWidget(Qt::LeftDockWidgetArea, dock);
623 _bufferViewsMenu->addAction(dock->toggleViewAction());
625 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
626 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
627 _bufferViews.append(dock);
629 if (!activeBufferView())
634 void MainWin::removeBufferView(int bufferViewConfigId)
637 BufferViewDock *dock;
638 foreach(QAction *action, _bufferViewsMenu->actions()) {
639 actionData = action->data();
640 if (!actionData.isValid())
643 dock = qobject_cast<BufferViewDock *>(action->parent());
644 if (dock && actionData.toInt() == bufferViewConfigId) {
645 removeAction(action);
646 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
647 _bufferViews.removeAll(dock);
649 if (dock->isActive()) {
650 dock->setActive(false);
651 _activeBufferViewIndex = -1;
661 void MainWin::bufferViewToggled(bool enabled)
663 if (!enabled && !isMinimized()) {
664 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
665 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
668 QAction *action = qobject_cast<QAction *>(sender());
670 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
673 // Make sure we don't toggle backlog fetch for a view we've already removed
674 if (!_bufferViews.contains(dock))
678 Client::bufferViewOverlay()->addView(dock->bufferViewId());
680 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
684 void MainWin::bufferViewVisibilityChanged(bool visible)
687 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
689 if ((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
694 BufferView *MainWin::allBuffersView() const
696 // "All Buffers" is always the first dock created
697 if (_bufferViews.count() > 0)
698 return _bufferViews[0]->bufferView();
703 BufferView *MainWin::activeBufferView() const
705 if (_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
707 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
708 return dock->isActive() ? qobject_cast<BufferView *>(dock->widget()) : 0;
712 void MainWin::changeActiveBufferView(int bufferViewId)
714 if (bufferViewId < 0)
717 BufferView *current = activeBufferView();
719 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
720 _activeBufferViewIndex = -1;
723 for (int i = 0; i < _bufferViews.count(); i++) {
724 BufferViewDock *dock = _bufferViews.at(i);
725 if (dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
726 _activeBufferViewIndex = i;
727 dock->setActive(true);
732 nextBufferView(); // fallback
736 void MainWin::changeActiveBufferView(bool backwards)
738 BufferView *current = activeBufferView();
740 qobject_cast<BufferViewDock *>(current->parent())->setActive(false);
742 if (!_bufferViews.count())
745 int c = _bufferViews.count();
746 while (c--) { // yes, this will reactivate the current active one if all others fail
748 if (--_activeBufferViewIndex < 0)
749 _activeBufferViewIndex = _bufferViews.count()-1;
752 if (++_activeBufferViewIndex >= _bufferViews.count())
753 _activeBufferViewIndex = 0;
756 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
757 if (dock->isHidden())
760 dock->setActive(true);
764 _activeBufferViewIndex = -1;
768 void MainWin::nextBufferView()
770 changeActiveBufferView(false);
774 void MainWin::previousBufferView()
776 changeActiveBufferView(true);
780 void MainWin::nextBuffer()
782 BufferView *view = activeBufferView();
788 void MainWin::previousBuffer()
790 BufferView *view = activeBufferView();
792 view->previousBuffer();
796 void MainWin::hideCurrentBuffer()
798 BufferView *view = activeBufferView();
800 view->hideCurrentBuffer();
804 void MainWin::showNotificationsDlg()
806 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
811 void MainWin::on_actionConfigureNetworks_triggered()
813 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
818 void MainWin::on_actionConfigureViews_triggered()
820 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
825 void MainWin::on_actionLockLayout_toggled(bool lock)
827 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
828 foreach(VerticalDock *dock, docks) {
829 dock->showTitle(!lock);
831 if (Client::bufferViewManager()) {
832 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
833 config->setLocked(lock);
836 QtUiSettings().setValue("LockLayout", lock);
840 void MainWin::setupNickWidget()
843 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
844 nickDock->setObjectName("NickDock");
845 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
847 _nickListWidget = new NickListWidget(nickDock);
848 nickDock->setWidget(_nickListWidget);
850 addDockWidget(Qt::RightDockWidgetArea, nickDock);
851 _viewMenu->addAction(nickDock->toggleViewAction());
852 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
854 // See NickListDock::NickListDock();
855 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
857 // attach the NickListWidget to the BufferModel and the default selection
858 _nickListWidget->setModel(Client::bufferModel());
859 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
863 void MainWin::setupChatMonitor()
865 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
866 dock->setObjectName("ChatMonitorDock");
868 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
869 _chatMonitorView = new ChatMonitorView(filter, this);
870 _chatMonitorView->setFocusProxy(_inputWidget);
871 _chatMonitorView->show();
872 dock->setWidget(_chatMonitorView);
875 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
876 _viewMenu->addAction(dock->toggleViewAction());
877 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
881 void MainWin::setupInputWidget()
883 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
884 dock->setObjectName("InputDock");
886 _inputWidget = new InputWidget(dock);
887 dock->setWidget(_inputWidget);
889 addDockWidget(Qt::BottomDockWidgetArea, dock);
891 _viewMenu->addAction(dock->toggleViewAction());
892 dock->toggleViewAction()->setText(tr("Show Input Line"));
894 _inputWidget->setModel(Client::bufferModel());
895 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
897 _bufferWidget->setFocusProxy(_inputWidget);
899 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
901 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
905 void MainWin::setupTopicWidget()
907 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
908 dock->setObjectName("TopicDock");
909 _topicWidget = new TopicWidget(dock);
911 dock->setWidget(_topicWidget);
913 _topicWidget->setModel(Client::bufferModel());
914 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
916 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
918 _viewMenu->addAction(dock->toggleViewAction());
919 dock->toggleViewAction()->setText(tr("Show Topic Line"));
923 void MainWin::setupViewMenuTail()
925 _viewMenu->addSeparator();
926 _viewMenu->addAction(QtUi::actionCollection("General")->action("ToggleFullScreen"));
930 void MainWin::setupTitleSetter()
932 _titleSetter.setModel(Client::bufferModel());
933 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
937 void MainWin::setupStatusBar()
939 // MessageProcessor progress
940 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
943 _coreConnectionStatusWidget->update();
944 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
946 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
948 QtUiSettings uiSettings;
950 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
951 showStatusbar->setChecked(enabled);
952 enabled ? statusBar()->show() : statusBar()->hide();
954 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
955 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
957 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
961 void MainWin::setupHotList()
963 FlatProxyModel *flatProxy = new FlatProxyModel(this);
964 flatProxy->setSourceModel(Client::bufferModel());
965 _bufferHotList = new BufferHotListFilter(flatProxy);
969 void MainWin::saveMenuBarStatus(bool enabled)
971 QtUiSettings uiSettings;
972 uiSettings.setValue("ShowMenuBar", enabled);
976 void MainWin::saveStatusBarStatus(bool enabled)
978 QtUiSettings uiSettings;
979 uiSettings.setValue("ShowStatusBar", enabled);
983 void MainWin::setupSystray()
986 _systemTray = new StatusNotifierItem(this);
987 #elif !defined QT_NO_SYSTEMTRAYICON
988 _systemTray = new LegacySystemTray(this);
990 _systemTray = new SystemTray(this); // dummy
996 void MainWin::setupToolBars()
998 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
999 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
1000 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
1001 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
1004 setUnifiedTitleAndToolBarOnMac(true);
1008 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
1010 _mainToolBar = new QToolBar(this);
1011 _mainToolBar->setObjectName("MainToolBar");
1013 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
1014 addToolBar(_mainToolBar);
1016 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
1017 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
1020 QtUiSettings uiSettings;
1022 bool visible = uiSettings.value("ShowMainToolBar", QVariant(true)).toBool();
1023 _mainToolBar->setVisible(visible);
1024 connect(_mainToolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(saveMainToolBarStatus(bool)));
1028 void MainWin::saveMainToolBarStatus(bool enabled)
1031 QtUiSettings uiSettings;
1032 uiSettings.setValue("ShowMainToolBar", enabled);
1039 void MainWin::connectedToCore()
1041 Q_CHECK_PTR(Client::bufferViewManager());
1042 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
1043 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
1044 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
1046 connect(Client::transferManager(), SIGNAL(transferAdded(const ClientTransfer*)), SLOT(showNewTransferDlg(const ClientTransfer*)));
1048 setConnectedState();
1052 void MainWin::setConnectedState()
1054 ActionCollection *coll = QtUi::actionCollection("General");
1056 coll->action("ConnectCore")->setEnabled(false);
1057 coll->action("DisconnectCore")->setEnabled(true);
1058 coll->action("CoreInfo")->setEnabled(true);
1060 foreach(QAction *action, _fileMenu->actions()) {
1061 if (isRemoteCoreOnly(action))
1062 action->setVisible(!Client::internalCore());
1065 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1066 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1067 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1068 if (!Client::internalCore()) {
1069 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
1070 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1071 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
1074 // _viewMenu->setEnabled(true);
1075 if (!Client::internalCore())
1076 statusBar()->showMessage(tr("Connected to core."));
1078 statusBar()->clearMessage();
1080 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
1082 systemTray()->setState(SystemTray::Active);
1084 if (Client::networkIds().isEmpty()) {
1085 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
1089 // Monolithic always preselects last used buffer - Client only if the connection died
1090 if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
1092 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
1093 if (lastUsedBufferId.isValid())
1094 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
1100 void MainWin::loadLayout()
1103 int accountId = Client::currentCoreAccount().accountId().toInt();
1104 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
1105 if (state.isEmpty()) {
1106 foreach(BufferViewDock *view, _bufferViews)
1108 _layoutLoaded = true;
1112 restoreState(state, accountId);
1113 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
1114 if (bufferViewId >= 0)
1115 changeActiveBufferView(bufferViewId);
1117 _layoutLoaded = true;
1121 void MainWin::saveLayout()
1124 int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
1125 if (accountId > 0) {
1126 s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
1127 BufferView *view = activeBufferView();
1128 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
1133 void MainWin::disconnectedFromCore()
1135 // save core specific layout and remove bufferviews;
1137 _layoutLoaded = false;
1139 QVariant actionData;
1140 BufferViewDock *dock;
1141 foreach(QAction *action, _bufferViewsMenu->actions()) {
1142 actionData = action->data();
1143 if (!actionData.isValid())
1146 dock = qobject_cast<BufferViewDock *>(action->parent());
1147 if (dock && actionData.toInt() != -1) {
1148 removeAction(action);
1149 _bufferViews.removeAll(dock);
1150 dock->deleteLater();
1154 // store last active buffer
1156 BufferId lastBufId = _bufferWidget->currentBuffer();
1157 if (lastBufId.isValid()) {
1158 s.setValue("LastUsedBufferId", lastBufId.toInt());
1159 // clear the current selection
1160 Client::bufferModel()->standardSelectionModel()->clearSelection();
1162 restoreState(s.value("MainWinState").toByteArray());
1163 setDisconnectedState();
1167 void MainWin::setDisconnectedState()
1169 ActionCollection *coll = QtUi::actionCollection("General");
1170 //ui.menuCore->setEnabled(false);
1171 coll->action("ConnectCore")->setEnabled(true);
1172 coll->action("DisconnectCore")->setEnabled(false);
1173 coll->action("CoreInfo")->setEnabled(false);
1174 //_viewMenu->setEnabled(false);
1175 statusBar()->showMessage(tr("Not connected to core."));
1176 if (_msgProcessorStatusWidget)
1177 _msgProcessorStatusWidget->setProgress(0, 0);
1179 systemTray()->setState(SystemTray::Passive);
1183 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
1185 Q_UNUSED(errorMessage)
1186 CoreConnectAuthDlg dlg(account, this);
1187 *valid = (dlg.exec() == QDialog::Accepted);
1191 void MainWin::handleNoSslInClient(bool *accepted)
1193 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1194 QMessageBox::Ignore|QMessageBox::Cancel, this);
1195 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1196 box.setDefaultButton(QMessageBox::Ignore);
1197 *accepted = box.exec() == QMessageBox::Ignore;
1201 void MainWin::handleNoSslInCore(bool *accepted)
1203 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1204 QMessageBox::Ignore|QMessageBox::Cancel, this);
1205 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1206 box.setDefaultButton(QMessageBox::Ignore);
1207 *accepted = box.exec() == QMessageBox::Ignore;
1213 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
1215 QString errorString = "<ul>";
1216 foreach(const QSslError error, socket->sslErrors())
1217 errorString += QString("<li>%1</li>").arg(error.errorString());
1218 errorString += "</ul>";
1220 QMessageBox box(QMessageBox::Warning,
1221 tr("Untrusted Security Certificate"),
1222 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1223 QMessageBox::Cancel, this);
1224 box.setInformativeText(errorString);
1225 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1226 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1228 QMessageBox::ButtonRole role;
1231 role = box.buttonRole(box.clickedButton());
1232 if (role == QMessageBox::HelpRole) {
1233 SslInfoDlg dlg(socket, this);
1237 while (role == QMessageBox::HelpRole);
1239 *accepted = role == QMessageBox::AcceptRole;
1241 QMessageBox box2(QMessageBox::Warning,
1242 tr("Untrusted Security Certificate"),
1243 tr("Would you like to accept this certificate forever without being prompted?"),
1245 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1246 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1248 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1253 #endif /* HAVE_SSL */
1255 void MainWin::handleCoreConnectionError(const QString &error)
1257 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1261 void MainWin::showCoreConnectionDlg()
1263 CoreConnectDlg dlg(this);
1264 if (dlg.exec() == QDialog::Accepted) {
1265 AccountId accId = dlg.selectedAccount();
1266 if (accId.isValid())
1267 Client::coreConnection()->connectToCore(accId);
1272 void MainWin::showCoreConfigWizard(const QVariantList &backends)
1274 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1280 void MainWin::showChannelList(NetworkId netId)
1282 ChannelListDlg *channelListDlg = new ChannelListDlg();
1284 if (!netId.isValid()) {
1285 QAction *action = qobject_cast<QAction *>(sender());
1287 netId = action->data().value<NetworkId>();
1290 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1291 channelListDlg->setNetwork(netId);
1292 channelListDlg->show();
1296 void MainWin::showIgnoreList(QString newRule)
1298 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1299 // prepare config dialog for new rule
1300 if (!newRule.isEmpty())
1301 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1306 void MainWin::showCoreInfoDlg()
1308 CoreInfoDlg(this).exec();
1312 void MainWin::showAwayLog()
1316 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1317 _awayLog = new AwayLogView(filter, 0);
1318 filter->setParent(_awayLog);
1319 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1320 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1325 void MainWin::awayLogDestroyed()
1331 void MainWin::showSettingsDlg()
1333 SettingsDlg *dlg = new SettingsDlg();
1335 //Category: Interface
1336 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1337 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1338 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1339 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1340 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1341 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1342 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1343 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1344 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1345 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1348 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1349 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1350 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1351 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1352 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1354 // Category: Remote Cores
1355 if (Quassel::runMode() != Quassel::Monolithic) {
1356 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1357 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1364 void MainWin::showAboutDlg()
1366 AboutDlg(this).exec();
1370 void MainWin::showShortcutsDlg()
1373 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1374 foreach(KActionCollection *coll, QtUi::actionCollections())
1375 dlg.addCollection(coll, coll->property("Category").toString());
1376 dlg.configure(true);
1378 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1384 void MainWin::showNewTransferDlg(const ClientTransfer *transfer)
1386 ReceiveFileDlg *dlg = new ReceiveFileDlg(transfer, this);
1391 void MainWin::onFullScreenToggled()
1393 // Relying on QWidget::isFullScreen is discouraged, see the KToggleFullScreenAction docs
1394 // Also, one should not use showFullScreen() or showNormal(), as those reset all other window flags
1396 QAction *action = QtUi::actionCollection("General")->action("ToggleFullScreen");
1401 KToggleFullScreenAction *kAct = static_cast<KToggleFullScreenAction *>(action);
1402 kAct->setFullScreen(this, kAct->isChecked());
1404 if (action->isChecked())
1405 setWindowState(windowState() | Qt::WindowFullScreen);
1407 setWindowState(windowState() & ~Qt::WindowFullScreen);
1412 /********************************************************************************************************/
1414 bool MainWin::event(QEvent *event)
1416 switch(event->type()) {
1417 case QEvent::WindowActivate: {
1418 BufferId bufferId = Client::bufferModel()->currentBuffer();
1419 if (bufferId.isValid())
1420 Client::instance()->markBufferAsRead(bufferId);
1423 case QEvent::WindowDeactivate:
1424 if (bufferWidget()->autoMarkerLineOnLostFocus())
1425 bufferWidget()->setMarkerLine();
1430 return QMainWindow::event(event);
1434 void MainWin::moveEvent(QMoveEvent *event)
1436 if (!(windowState() & Qt::WindowMaximized))
1437 _normalPos = event->pos();
1439 QMainWindow::moveEvent(event);
1443 void MainWin::resizeEvent(QResizeEvent *event)
1445 if (!(windowState() & Qt::WindowMaximized))
1446 _normalSize = event->size();
1448 QMainWindow::resizeEvent(event);
1452 void MainWin::closeEvent(QCloseEvent *event)
1455 QtUiApplication *app = qobject_cast<QtUiApplication *> qApp;
1457 if (!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1458 QtUi::hideMainWidget();
1468 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end)
1472 bool hasFocus = QApplication::activeWindow() != 0;
1474 for (int i = start; i <= end; i++) {
1475 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1476 if (!idx.isValid()) {
1477 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1480 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1481 if (flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1484 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1485 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1487 // check if bufferId belongs to the shown chatlists
1488 if (!(Client::bufferViewOverlay()->bufferIds().contains(bufId) ||
1489 Client::bufferViewOverlay()->tempRemovedBufferIds().contains(bufId)))
1492 // check if it's the buffer currently displayed
1493 if (hasFocus && bufId == Client::bufferModel()->currentBuffer())
1496 // only show notifications for higlights or queries
1497 if (bufType != BufferInfo::QueryBuffer && !(flags & Message::Highlight))
1500 // and of course: don't notify for ignored messages
1501 if (Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufId)))
1504 // seems like we have a legit notification candidate!
1505 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1506 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1507 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1508 AbstractNotificationBackend::NotificationType type;
1510 if (bufType == BufferInfo::QueryBuffer && !hasFocus)
1511 type = AbstractNotificationBackend::PrivMsg;
1512 else if (bufType == BufferInfo::QueryBuffer && hasFocus)
1513 type = AbstractNotificationBackend::PrivMsgFocused;
1514 else if (flags & Message::Highlight && !hasFocus)
1515 type = AbstractNotificationBackend::Highlight;
1517 type = AbstractNotificationBackend::HighlightFocused;
1519 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1524 void MainWin::currentBufferChanged(BufferId buffer)
1526 if (buffer.isValid())
1527 Client::instance()->markBufferAsRead(buffer);
1531 void MainWin::clientNetworkCreated(NetworkId id)
1533 const Network *net = Client::network(id);
1534 QAction *act = new QAction(net->networkName(), this);
1535 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1536 act->setData(QVariant::fromValue<NetworkId>(id));
1537 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1538 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1540 QAction *beforeAction = 0;
1541 foreach(QAction *action, _networksMenu->actions()) {
1542 if (!action->data().isValid()) // ignore stock actions
1544 if (net->networkName().localeAwareCompare(action->text()) < 0) {
1545 beforeAction = action;
1549 _networksMenu->insertAction(beforeAction, act);
1553 void MainWin::clientNetworkUpdated()
1555 const Network *net = qobject_cast<const Network *>(sender());
1559 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1563 action->setText(net->networkName());
1565 switch (net->connectionState()) {
1566 case Network::Initialized:
1567 action->setIcon(QIcon::fromTheme("network-connect"));
1568 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1569 if (!bufferWidget()->currentBuffer().isValid()) {
1570 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1571 if (idx.isValid()) {
1572 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1573 Client::bufferModel()->switchToBuffer(statusBufferId);
1577 case Network::Disconnected:
1578 action->setIcon(QIcon::fromTheme("network-disconnect"));
1581 action->setIcon(QIcon::fromTheme("network-wired"));
1586 void MainWin::clientNetworkRemoved(NetworkId id)
1588 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1592 action->deleteLater();
1596 void MainWin::connectOrDisconnectFromNet()
1598 QAction *act = qobject_cast<QAction *>(sender());
1600 const Network *net = Client::network(act->data().value<NetworkId>());
1602 if (net->connectionState() == Network::Disconnected) net->requestConnect();
1603 else net->requestDisconnect();
1607 void MainWin::on_jumpHotBuffer_triggered()
1609 if (!_bufferHotList->rowCount())
1612 Client::bufferModel()->switchToBuffer(_bufferHotList->hottestBuffer());
1616 void MainWin::onJumpKey()
1618 QAction *action = qobject_cast<QAction *>(sender());
1619 if (!action || !Client::bufferModel())
1621 int idx = action->property("Index").toInt();
1623 if (_jumpKeyMap.isEmpty())
1624 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1626 if (!_jumpKeyMap.contains(idx))
1629 BufferId buffer = _jumpKeyMap.value(idx);
1630 if (buffer.isValid())
1631 Client::bufferModel()->switchToBuffer(buffer);
1635 void MainWin::bindJumpKey()
1637 QAction *action = qobject_cast<QAction *>(sender());
1638 if (!action || !Client::bufferModel())
1640 int idx = action->property("Index").toInt();
1642 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1643 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1647 void MainWin::on_actionDebugNetworkModel_triggered()
1649 QTreeView *view = new QTreeView;
1650 view->setAttribute(Qt::WA_DeleteOnClose);
1651 view->setWindowTitle("Debug NetworkModel View");
1652 view->setModel(Client::networkModel());
1653 view->setColumnWidth(0, 250);
1654 view->setColumnWidth(1, 250);
1655 view->setColumnWidth(2, 80);
1656 view->resize(610, 300);
1661 void MainWin::on_actionDebugHotList_triggered()
1663 _bufferHotList->invalidate();
1664 _bufferHotList->sort(0, Qt::DescendingOrder);
1666 QTreeView *view = new QTreeView;
1667 view->setAttribute(Qt::WA_DeleteOnClose);
1668 view->setModel(_bufferHotList);
1673 void MainWin::on_actionDebugBufferViewOverlay_triggered()
1675 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1676 overlay->setAttribute(Qt::WA_DeleteOnClose);
1681 void MainWin::on_actionDebugMessageModel_triggered()
1683 QTableView *view = new QTableView(0);
1684 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1685 filter->setSourceModel(Client::messageModel());
1686 view->setModel(filter);
1687 view->setAttribute(Qt::WA_DeleteOnClose, true);
1688 view->verticalHeader()->hide();
1689 view->horizontalHeader()->setStretchLastSection(true);
1694 void MainWin::on_actionDebugLog_triggered()
1696 DebugLogWidget *logWidget = new DebugLogWidget(0);
1701 void MainWin::showStatusBarMessage(const QString &message)
1703 statusBar()->showMessage(message, 10000);