1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 # include <KActionCollection>
27 # include <KShortcutsDialog>
28 # include <KStatusBar>
30 # include <KWindowSystem>
38 #include "awaylogfilter.h"
39 #include "awaylogview.h"
41 #include "actioncollection.h"
42 #include "bufferhotlistfilter.h"
43 #include "buffermodel.h"
44 #include "bufferview.h"
45 #include "bufferviewoverlay.h"
46 #include "bufferviewoverlayfilter.h"
47 #include "bufferwidget.h"
48 #include "channellistdlg.h"
49 #include "chatlinemodel.h"
50 #include "chatmonitorfilter.h"
51 #include "chatmonitorview.h"
54 #include "clientbacklogmanager.h"
55 #include "clientbufferviewconfig.h"
56 #include "clientbufferviewmanager.h"
57 #include "clientignorelistmanager.h"
58 #include "coreconnectdlg.h"
59 #include "coreconnection.h"
60 #include "coreconnectionstatuswidget.h"
61 #include "coreinfodlg.h"
62 #include "contextmenuactionprovider.h"
63 #include "debugbufferviewoverlay.h"
64 #include "debuglogwidget.h"
65 #include "debugmessagemodelfilter.h"
66 #include "flatproxymodel.h"
67 #include "iconloader.h"
68 #include "inputwidget.h"
69 #include "irclistmodel.h"
70 #include "ircconnectionwizard.h"
71 #include "jumpkeyhandler.h"
72 #include "msgprocessorstatuswidget.h"
73 #include "nicklistwidget.h"
74 #include "qtuiapplication.h"
75 #include "qtuimessageprocessor.h"
76 #include "qtuisettings.h"
77 #include "qtuistyle.h"
78 #include "settingsdlg.h"
79 #include "settingspagedlg.h"
80 #include "systemtray.h"
81 #include "toolbaractionprovider.h"
82 #include "topicwidget.h"
83 #include "verticaldock.h"
87 # include "desktopnotificationbackend.h"
90 # include "phononnotificationbackend.h"
92 # include "systraynotificationbackend.h"
93 # include "taskbarnotificationbackend.h"
95 # include "knotificationbackend.h"
99 # include "sslinfodlg.h"
102 #ifdef HAVE_INDICATEQT
103 #include "indicatornotificationbackend.h"
106 #include "settingspages/aliasessettingspage.h"
107 #include "settingspages/appearancesettingspage.h"
108 #include "settingspages/backlogsettingspage.h"
109 #include "settingspages/bufferviewsettingspage.h"
110 #include "settingspages/chatmonitorsettingspage.h"
111 #include "settingspages/chatviewsettingspage.h"
112 #include "settingspages/connectionsettingspage.h"
113 #include "settingspages/coreaccountsettingspage.h"
114 #include "settingspages/generalsettingspage.h"
115 #include "settingspages/highlightsettingspage.h"
116 #include "settingspages/identitiessettingspage.h"
117 #include "settingspages/ignorelistsettingspage.h"
118 #include "settingspages/inputwidgetsettingspage.h"
119 #include "settingspages/itemviewsettingspage.h"
120 #include "settingspages/networkssettingspage.h"
121 #include "settingspages/notificationssettingspage.h"
122 #include "settingspages/topicwidgetsettingspage.h"
124 MainWin::MainWin(QWidget *parent)
126 : KMainWindow(parent),
127 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
129 : QMainWindow(parent),
131 coreLagLabel(new QLabel()),
132 sslLabel(new QLabel()),
133 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
134 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
143 QtUiSettings uiSettings;
144 QString style = uiSettings.value("Style", QString()).toString();
145 if(!style.isEmpty()) {
146 QApplication::setStyle(style);
149 QApplication::setQuitOnLastWindowClosed(false);
151 setWindowTitle("Quassel IRC");
152 setWindowIconText("Quassel IRC");
155 installEventFilter(new JumpKeyHandler(this));
158 void MainWin::init() {
159 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
160 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
161 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
162 SLOT(messagesInserted(const QModelIndex &, int, int)));
163 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
164 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
165 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
166 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool*)), SLOT(handleNoSslInClient(bool *)));
167 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool*)), SLOT(handleNoSslInCore(bool *)));
169 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
173 setDockNestingEnabled(true);
174 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
175 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
176 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
177 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
179 // Order is sometimes important
194 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
195 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
197 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
200 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
204 QtUi::registerNotificationBackend(new KNotificationBackend(this));
205 #endif /* HAVE_KDE */
207 #ifdef HAVE_INDICATEQT
208 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
211 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
213 setDisconnectedState(); // Disable menus and stuff
216 setAutoSaveSettings();
219 // restore mainwin state
221 restoreStateFromSettings(s);
223 // restore locked state of docks
224 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
226 CoreConnection *conn = Client::coreConnection();
227 if(!conn->connectToCore()) {
228 // No autoconnect selected (or no accounts)
229 showCoreConnectionDlg();
233 MainWin::~MainWin() {
237 void MainWin::quit() {
239 saveStateToSettings(s);
241 QApplication::quit();
244 void MainWin::saveStateToSettings(UiSettings &s) {
245 s.setValue("MainWinSize", _normalSize);
246 s.setValue("MainWinPos", _normalPos);
247 s.setValue("MainWinState", saveState());
248 s.setValue("MainWinGeometry", saveGeometry());
249 s.setValue("MainWinMinimized", isMinimized());
250 s.setValue("MainWinMaximized", isMaximized());
251 s.setValue("MainWinHidden", !isVisible());
254 saveAutoSaveSettings();
258 void MainWin::restoreStateFromSettings(UiSettings &s) {
259 _normalSize = s.value("MainWinSize", size()).toSize();
260 _normalPos = s.value("MainWinPos", pos()).toPoint();
261 bool maximized = s.value("MainWinMaximized", false).toBool();
264 restoreGeometry(s.value("MainWinGeometry").toByteArray());
267 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
272 restoreState(s.value("MainWinState").toByteArray());
278 if(s.value("MainWinHidden").toBool())
280 else if(s.value("MainWinMinimized").toBool())
288 void MainWin::updateIcon() {
290 const int size = 128;
296 if(Client::isConnected())
297 icon = DesktopIcon("quassel", size);
299 icon = DesktopIcon("quassel_inactive", size);
301 qApp->setWindowIcon(icon);
304 void MainWin::setupActions() {
305 ActionCollection *coll = QtUi::actionCollection("General");
307 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
308 this, SLOT(showCoreConnectionDlg())));
309 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
310 Client::instance(), SLOT(disconnectFromCore())));
311 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
312 this, SLOT(showCoreInfoDlg())));
313 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
314 this, SLOT(on_actionConfigureNetworks_triggered())));
315 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
316 this, SLOT(quit()), tr("Ctrl+Q")));
319 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
320 this, SLOT(on_actionConfigureViews_triggered())));
322 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
323 lockAct->setCheckable(true);
324 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
326 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
327 0, 0, QKeySequence::Find))->setCheckable(true);
328 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
329 this, SLOT(showAwayLog())));
330 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
331 0, 0, tr("Ctrl+M")))->setCheckable(true);
333 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
334 0, 0))->setCheckable(true);
337 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
338 this, SLOT(showSettingsDlg()), tr("F7")));
341 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
342 this, SLOT(showAboutDlg())));
343 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
344 qApp, SLOT(aboutQt())));
345 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
346 this, SLOT(on_actionDebugNetworkModel_triggered())));
347 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
348 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
349 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
350 this, SLOT(on_actionDebugMessageModel_triggered())));
351 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
352 this, SLOT(on_actionDebugHotList_triggered())));
353 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
354 this, SLOT(on_actionDebugLog_triggered())));
355 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
356 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
359 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
360 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
363 void MainWin::setupMenus() {
364 ActionCollection *coll = QtUi::actionCollection("General");
366 _fileMenu = menuBar()->addMenu(tr("&File"));
368 static const QStringList coreActions = QStringList()
369 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
372 foreach(QString actionName, coreActions) {
373 coreAction = coll->action(actionName);
374 _fileMenu->addAction(coreAction);
375 flagRemoteCoreOnly(coreAction);
377 flagRemoteCoreOnly(_fileMenu->addSeparator());
379 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
380 _networksMenu->addAction(coll->action("ConfigureNetworks"));
381 _networksMenu->addSeparator();
382 _fileMenu->addSeparator();
383 _fileMenu->addAction(coll->action("Quit"));
385 _viewMenu = menuBar()->addMenu(tr("&View"));
386 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
387 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
388 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
389 _viewMenu->addSeparator();
391 _viewMenu->addAction(coll->action("ToggleMenuBar"));
392 _viewMenu->addAction(coll->action("ToggleStatusBar"));
393 _viewMenu->addAction(coll->action("ToggleSearchBar"));
395 coreAction = coll->action("ShowAwayLog");
396 flagRemoteCoreOnly(coreAction);
397 _viewMenu->addAction(coreAction);
399 _viewMenu->addSeparator();
400 _viewMenu->addAction(coll->action("LockLayout"));
402 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
404 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
405 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
407 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
409 _helpMenu = menuBar()->addMenu(tr("&Help"));
410 _helpMenu->addAction(coll->action("AboutQuassel"));
412 _helpMenu->addAction(coll->action("AboutQt"));
414 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
416 _helpMenu->addSeparator();
417 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
418 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
419 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
420 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
421 _helpDebugMenu->addAction(coll->action("DebugHotList"));
422 _helpDebugMenu->addAction(coll->action("DebugLog"));
423 _helpDebugMenu->addSeparator();
424 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
427 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
429 QtUiSettings uiSettings;
430 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
431 showMenuBar->setChecked(enabled);
432 enabled ? menuBar()->show() : menuBar()->hide();
434 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
435 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
438 void MainWin::setupBufferWidget() {
439 _bufferWidget = new BufferWidget(this);
440 _bufferWidget->setModel(Client::bufferModel());
441 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
442 setCentralWidget(_bufferWidget);
445 void MainWin::addBufferView(int bufferViewConfigId) {
446 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
449 void MainWin::addBufferView(ClientBufferViewConfig *config) {
453 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
454 BufferViewDock *dock = new BufferViewDock(config, this);
456 //create the view and initialize it's filter
457 BufferView *view = new BufferView(dock);
458 view->setFilteredModel(Client::bufferModel(), config);
459 view->installEventFilter(_inputWidget); // for key presses
461 Client::bufferModel()->synchronizeView(view);
463 dock->setWidget(view);
464 dock->setVisible(_layoutLoaded); // don't show before state has been restored
466 addDockWidget(Qt::LeftDockWidgetArea, dock);
467 _bufferViewsMenu->addAction(dock->toggleViewAction());
469 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
470 _bufferViews.append(dock);
473 void MainWin::removeBufferView(int bufferViewConfigId) {
475 BufferViewDock *dock;
476 foreach(QAction *action, _bufferViewsMenu->actions()) {
477 actionData = action->data();
478 if(!actionData.isValid())
481 dock = qobject_cast<BufferViewDock *>(action->parent());
482 if(dock && actionData.toInt() == bufferViewConfigId) {
483 removeAction(action);
484 _bufferViews.removeAll(dock);
485 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
491 void MainWin::bufferViewToggled(bool enabled) {
492 QAction *action = qobject_cast<QAction *>(sender());
494 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
497 // Make sure we don't toggle backlog fetch for a view we've already removed
498 if(!_bufferViews.contains(dock))
502 Client::bufferViewOverlay()->addView(dock->bufferViewId());
503 BufferViewConfig *config = dock->config();
504 if(config && config->isInitialized()) {
505 BufferIdList buffers;
506 if(config->networkId().isValid()) {
507 foreach(BufferId bufferId, config->bufferList()) {
508 if(Client::networkModel()->networkId(bufferId) == config->networkId())
511 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
512 if(Client::networkModel()->networkId(bufferId) == config->networkId())
516 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
518 Client::backlogManager()->checkForBacklog(buffers);
521 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
525 BufferView *MainWin::allBuffersView() const {
526 // "All Buffers" is always the first dock created
527 if(_bufferViews.count() > 0)
528 return _bufferViews[0]->bufferView();
532 void MainWin::showNotificationsDlg() {
533 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
537 void MainWin::on_actionConfigureNetworks_triggered() {
538 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
542 void MainWin::on_actionConfigureViews_triggered() {
543 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
547 void MainWin::on_actionLockLayout_toggled(bool lock) {
548 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
549 foreach(VerticalDock *dock, docks) {
550 dock->showTitle(!lock);
552 if(Client::bufferViewManager()) {
553 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
554 config->setLocked(lock);
557 QtUiSettings().setValue("LockLayout", lock);
560 void MainWin::setupNickWidget() {
562 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
563 nickDock->setObjectName("NickDock");
564 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
566 _nickListWidget = new NickListWidget(nickDock);
567 nickDock->setWidget(_nickListWidget);
569 addDockWidget(Qt::RightDockWidgetArea, nickDock);
570 _viewMenu->addAction(nickDock->toggleViewAction());
571 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
573 // See NickListDock::NickListDock();
574 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
576 // attach the NickListWidget to the BufferModel and the default selection
577 _nickListWidget->setModel(Client::bufferModel());
578 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
581 void MainWin::setupChatMonitor() {
582 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
583 dock->setObjectName("ChatMonitorDock");
585 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
586 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
588 dock->setWidget(chatView);
591 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
592 _viewMenu->addAction(dock->toggleViewAction());
593 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
596 void MainWin::setupInputWidget() {
597 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
598 dock->setObjectName("InputDock");
600 _inputWidget = new InputWidget(dock);
601 dock->setWidget(_inputWidget);
603 addDockWidget(Qt::BottomDockWidgetArea, dock);
605 _viewMenu->addAction(dock->toggleViewAction());
606 dock->toggleViewAction()->setText(tr("Show Input Line"));
608 _inputWidget->setModel(Client::bufferModel());
609 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
611 _bufferWidget->setFocusProxy(_inputWidget);
613 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
616 void MainWin::setupTopicWidget() {
617 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
618 dock->setObjectName("TopicDock");
619 TopicWidget *topicwidget = new TopicWidget(dock);
621 dock->setWidget(topicwidget);
623 topicwidget->setModel(Client::bufferModel());
624 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
626 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
628 _viewMenu->addAction(dock->toggleViewAction());
629 dock->toggleViewAction()->setText(tr("Show Topic Line"));
632 void MainWin::setupTitleSetter() {
633 _titleSetter.setModel(Client::bufferModel());
634 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
637 void MainWin::setupStatusBar() {
638 // MessageProcessor progress
639 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
642 _coreConnectionStatusWidget->update();
643 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
646 updateLagIndicator();
647 statusBar()->addPermanentWidget(coreLagLabel);
648 coreLagLabel->hide();
649 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
652 sslLabel->setPixmap(QPixmap());
653 statusBar()->addPermanentWidget(sslLabel);
656 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
658 QtUiSettings uiSettings;
660 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
661 showStatusbar->setChecked(enabled);
662 enabled ? statusBar()->show() : statusBar()->hide();
664 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
665 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
667 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
670 void MainWin::setupHotList() {
671 FlatProxyModel *flatProxy = new FlatProxyModel(this);
672 flatProxy->setSourceModel(Client::bufferModel());
673 _bufferHotList = new BufferHotListFilter(flatProxy);
676 void MainWin::saveMenuBarStatus(bool enabled) {
677 QtUiSettings uiSettings;
678 uiSettings.setValue("ShowMenuBar", enabled);
681 void MainWin::saveStatusBarStatus(bool enabled) {
682 QtUiSettings uiSettings;
683 uiSettings.setValue("ShowStatusBar", enabled);
686 void MainWin::setupSystray() {
687 _systemTray = new SystemTray(this);
690 void MainWin::setupToolBars() {
691 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
692 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
693 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
694 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
697 setUnifiedTitleAndToolBarOnMac(true);
701 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
703 _mainToolBar = new QToolBar(this);
704 _mainToolBar->setObjectName("MainToolBar");
706 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
707 addToolBar(_mainToolBar);
709 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
710 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
713 void MainWin::connectedToCore() {
714 Q_CHECK_PTR(Client::bufferViewManager());
715 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
716 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
717 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
722 void MainWin::setConnectedState() {
723 ActionCollection *coll = QtUi::actionCollection("General");
725 coll->action("ConnectCore")->setEnabled(false);
726 coll->action("DisconnectCore")->setEnabled(true);
727 coll->action("CoreInfo")->setEnabled(true);
729 foreach(QAction *action, _fileMenu->actions()) {
730 if(isRemoteCoreOnly(action))
731 action->setVisible(!Client::internalCore());
734 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
735 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
736 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
737 if(!Client::internalCore()) {
738 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
739 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
740 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
743 // _viewMenu->setEnabled(true);
744 if(!Client::internalCore())
745 statusBar()->showMessage(tr("Connected to core."));
747 statusBar()->clearMessage();
749 if(Client::signalProxy()->isSecure()) {
750 sslLabel->setPixmap(SmallIcon("security-high"));
752 sslLabel->setPixmap(SmallIcon("security-low"));
755 sslLabel->setVisible(!Client::internalCore());
756 coreLagLabel->setVisible(!Client::internalCore());
758 systemTray()->setState(SystemTray::Active);
760 if(Client::networkIds().isEmpty()) {
761 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
766 void MainWin::loadLayout() {
768 int accountId = Client::currentCoreAccount().accountId().toInt();
769 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
770 if(state.isEmpty()) {
771 // Make sure that the default bufferview is shown
772 if(_bufferViews.count())
773 _bufferViews.at(0)->show();
777 restoreState(state, accountId);
778 _layoutLoaded = true;
781 void MainWin::saveLayout() {
783 int accountId = Client::currentCoreAccount().accountId().toInt();
784 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
787 void MainWin::updateLagIndicator(int lag) {
788 QString text = tr("Core Lag: %1");
790 text = text.arg('-');
792 text = text.arg("%1 msec").arg(lag);
793 coreLagLabel->setText(text);
796 void MainWin::disconnectedFromCore() {
797 // save core specific layout and remove bufferviews;
799 _layoutLoaded = false;
802 BufferViewDock *dock;
803 foreach(QAction *action, _bufferViewsMenu->actions()) {
804 actionData = action->data();
805 if(!actionData.isValid())
808 dock = qobject_cast<BufferViewDock *>(action->parent());
809 if(dock && actionData.toInt() != -1) {
810 removeAction(action);
811 _bufferViews.removeAll(dock);
812 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
818 restoreState(s.value("MainWinState").toByteArray());
819 setDisconnectedState();
822 void MainWin::setDisconnectedState() {
823 ActionCollection *coll = QtUi::actionCollection("General");
824 //ui.menuCore->setEnabled(false);
825 coll->action("ConnectCore")->setEnabled(true);
826 coll->action("DisconnectCore")->setEnabled(false);
827 coll->action("CoreInfo")->setEnabled(false);
828 //_viewMenu->setEnabled(false);
829 statusBar()->showMessage(tr("Not connected to core."));
830 sslLabel->setPixmap(QPixmap());
832 updateLagIndicator();
833 coreLagLabel->hide();
834 if(_msgProcessorStatusWidget)
835 _msgProcessorStatusWidget->setProgress(0, 0);
837 systemTray()->setState(SystemTray::Inactive);
840 void MainWin::startInternalCore() {
844 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
845 Q_UNUSED(errorMessage)
846 CoreConnectAuthDlg dlg(account, this);
847 *valid = (dlg.exec() == QDialog::Accepted);
850 void MainWin::handleNoSslInClient(bool *accepted) {
851 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
852 QMessageBox::Ignore|QMessageBox::Cancel, this);
853 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
854 box.setDefaultButton(QMessageBox::Ignore);
855 *accepted = box.exec() == QMessageBox::Ignore;
858 void MainWin::handleNoSslInCore(bool *accepted) {
859 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
860 QMessageBox::Ignore|QMessageBox::Cancel, this);
861 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
862 box.setDefaultButton(QMessageBox::Ignore);
863 *accepted = box.exec() == QMessageBox::Ignore;
869 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently) {
870 QString errorString = "<ul>";
871 foreach(const QSslError error, socket->sslErrors())
872 errorString += QString("<li>%1</li>").arg(error.errorString());
873 errorString += "</ul>";
875 QMessageBox box(QMessageBox::Warning,
876 tr("Untrusted Security Certificate"),
877 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
878 QMessageBox::Cancel, this);
879 box.setInformativeText(errorString);
880 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
881 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
883 QMessageBox::ButtonRole role;
886 role = box.buttonRole(box.clickedButton());
887 if(role == QMessageBox::HelpRole) {
888 SslInfoDlg dlg(socket, this);
891 } while(role == QMessageBox::HelpRole);
893 *accepted = role == QMessageBox::AcceptRole;
895 QMessageBox box2(QMessageBox::Warning,
896 tr("Untrusted Security Certificate"),
897 tr("Would you like to accept this certificate forever without being prompted?"),
899 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
900 box2.addButton(tr("Forever"), QMessageBox::YesRole);
902 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
906 #endif /* HAVE_SSL */
908 void MainWin::showCoreConnectionDlg() {
909 CoreConnectDlg dlg(this);
910 if(dlg.exec() == QDialog::Accepted) {
911 AccountId accId = dlg.selectedAccount();
913 Client::coreConnection()->connectToCore(accId);
917 void MainWin::showChannelList(NetworkId netId) {
918 ChannelListDlg *channelListDlg = new ChannelListDlg();
920 if(!netId.isValid()) {
921 QAction *action = qobject_cast<QAction *>(sender());
923 netId = action->data().value<NetworkId>();
926 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
927 channelListDlg->setNetwork(netId);
928 channelListDlg->show();
931 void MainWin::showIgnoreList(QString newRule) {
932 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
933 // prepare config dialog for new rule
934 if(!newRule.isEmpty())
935 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
939 void MainWin::showCoreInfoDlg() {
940 CoreInfoDlg(this).exec();
943 void MainWin::showAwayLog() {
946 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
947 _awayLog = new AwayLogView(filter, 0);
948 filter->setParent(_awayLog);
949 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
950 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
954 void MainWin::awayLogDestroyed() {
958 void MainWin::showSettingsDlg() {
959 SettingsDlg *dlg = new SettingsDlg();
961 //Category: Interface
962 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
963 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
964 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
965 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
966 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
967 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
968 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
969 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
970 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
971 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
974 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
975 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
976 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
977 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
978 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
979 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
981 if(Quassel::runMode() != Quassel::Monolithic) {
982 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
988 void MainWin::showAboutDlg() {
989 AboutDlg(this).exec();
993 void MainWin::showShortcutsDlg() {
994 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
998 /********************************************************************************************************/
1000 bool MainWin::event(QEvent *event) {
1001 if(event->type() == QEvent::WindowActivate) {
1002 BufferId buffer = Client::bufferModel()->currentBuffer();
1003 if(buffer.isValid())
1004 QtUi::closeNotifications(buffer);
1006 return QMainWindow::event(event);
1009 void MainWin::moveEvent(QMoveEvent *event) {
1010 if(!(windowState() & Qt::WindowMaximized))
1011 _normalPos = event->pos();
1013 QMainWindow::moveEvent(event);
1016 void MainWin::resizeEvent(QResizeEvent *event) {
1017 if(!(windowState() & Qt::WindowMaximized))
1018 _normalSize = event->size();
1020 QMainWindow::resizeEvent(event);
1023 void MainWin::closeEvent(QCloseEvent *event) {
1025 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
1027 if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
1036 void MainWin::changeEvent(QEvent *event) {
1038 if(event->type() == QEvent::ActivationChange)
1039 dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray()
1042 QMainWindow::changeEvent(event);
1045 void MainWin::hideToTray() {
1046 if(!systemTray()->isSystemTrayAvailable()) {
1047 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
1051 systemTray()->setIconVisible();
1054 void MainWin::toggleMinimizedToTray() {
1056 // the problem is that we lose focus when the systray icon is activated
1057 // and we don't know the former active window
1058 // therefore we watch for activation event and use our stopwatch :)
1059 // courtesy: KSystemTrayIcon
1060 if(GetTickCount() - dwTickCount >= 300)
1061 // we weren't active in the last 300ms -> activate
1068 if(!isVisible() || isMinimized())
1077 void MainWin::forceActivated() {
1080 KWindowSystem::forceActiveWindow(winId());
1084 // Bypass focus stealing prevention
1085 QX11Info::setAppUserTime(QX11Info::appTime());
1088 if(windowState() & Qt::WindowMinimized) {
1090 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
1093 // this does not actually work on all platforms... and causes more evil than good
1094 // move(frameGeometry().topLeft()); // avoid placement policies
1098 #endif /* HAVE_KDE */
1101 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1104 bool hasFocus = QApplication::activeWindow() != 0;
1106 for(int i = start; i <= end; i++) {
1107 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1108 if(!idx.isValid()) {
1109 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1112 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1113 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1116 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1117 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1119 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1122 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1123 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1124 Client::networkModel()->networkName(bufId))))
1126 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1127 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1128 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1129 AbstractNotificationBackend::NotificationType type;
1131 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1132 type = AbstractNotificationBackend::PrivMsg;
1133 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1134 type = AbstractNotificationBackend::PrivMsgFocused;
1135 else if(flags & Message::Highlight && !hasFocus)
1136 type = AbstractNotificationBackend::Highlight;
1138 type = AbstractNotificationBackend::HighlightFocused;
1140 QtUi::invokeNotification(bufId, type, sender, contents);
1145 void MainWin::currentBufferChanged(BufferId buffer) {
1146 if(buffer.isValid())
1147 QtUi::closeNotifications(buffer);
1150 void MainWin::clientNetworkCreated(NetworkId id) {
1151 const Network *net = Client::network(id);
1152 QAction *act = new QAction(net->networkName(), this);
1153 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1154 act->setData(QVariant::fromValue<NetworkId>(id));
1155 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1156 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1158 QAction *beforeAction = 0;
1159 foreach(QAction *action, _networksMenu->actions()) {
1160 if(!action->data().isValid()) // ignore stock actions
1162 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1163 beforeAction = action;
1167 _networksMenu->insertAction(beforeAction, act);
1170 void MainWin::clientNetworkUpdated() {
1171 const Network *net = qobject_cast<const Network *>(sender());
1175 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1179 action->setText(net->networkName());
1181 switch(net->connectionState()) {
1182 case Network::Initialized:
1183 action->setIcon(SmallIcon("network-connect"));
1185 case Network::Disconnected:
1186 action->setIcon(SmallIcon("network-disconnect"));
1189 action->setIcon(SmallIcon("network-wired"));
1193 void MainWin::clientNetworkRemoved(NetworkId id) {
1194 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1198 action->deleteLater();
1201 void MainWin::connectOrDisconnectFromNet() {
1202 QAction *act = qobject_cast<QAction *>(sender());
1204 const Network *net = Client::network(act->data().value<NetworkId>());
1206 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1207 else net->requestDisconnect();
1210 void MainWin::on_jumpHotBuffer_triggered() {
1211 if(!_bufferHotList->rowCount())
1214 QModelIndex topIndex = _bufferHotList->index(0, 0);
1215 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1216 Client::bufferModel()->switchToBuffer(bufferId);
1219 void MainWin::on_actionDebugNetworkModel_triggered() {
1220 QTreeView *view = new QTreeView;
1221 view->setAttribute(Qt::WA_DeleteOnClose);
1222 view->setWindowTitle("Debug NetworkModel View");
1223 view->setModel(Client::networkModel());
1224 view->setColumnWidth(0, 250);
1225 view->setColumnWidth(1, 250);
1226 view->setColumnWidth(2, 80);
1227 view->resize(610, 300);
1231 void MainWin::on_actionDebugHotList_triggered() {
1232 QTreeView *view = new QTreeView;
1233 view->setAttribute(Qt::WA_DeleteOnClose);
1234 view->setModel(_bufferHotList);
1238 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1239 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1240 overlay->setAttribute(Qt::WA_DeleteOnClose);
1244 void MainWin::on_actionDebugMessageModel_triggered() {
1245 QTableView *view = new QTableView(0);
1246 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1247 filter->setSourceModel(Client::messageModel());
1248 view->setModel(filter);
1249 view->setAttribute(Qt::WA_DeleteOnClose, true);
1250 view->verticalHeader()->hide();
1251 view->horizontalHeader()->setStretchLastSection(true);
1255 void MainWin::on_actionDebugLog_triggered() {
1256 DebugLogWidget *logWidget = new DebugLogWidget(0);
1260 void MainWin::showStatusBarMessage(const QString &message) {
1261 statusBar()->showMessage(message, 10000);