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>
32 #include "awaylogfilter.h"
33 #include "awaylogview.h"
35 #include "actioncollection.h"
36 #include "buffermodel.h"
37 #include "bufferview.h"
38 #include "bufferwidget.h"
39 #include "channellistdlg.h"
40 #include "chatlinemodel.h"
41 #include "chatmonitorfilter.h"
42 #include "chatmonitorview.h"
45 #include "clientsyncer.h"
46 #include "clientbacklogmanager.h"
47 #include "clientbufferviewconfig.h"
48 #include "clientbufferviewmanager.h"
49 #include "coreinfodlg.h"
50 #include "coreconnectdlg.h"
51 #include "contextmenuactionprovider.h"
52 #include "debuglogwidget.h"
53 #include "debugmessagemodelfilter.h"
54 #include "iconloader.h"
55 #include "inputwidget.h"
56 #include "inputline.h"
57 #include "irclistmodel.h"
58 #include "ircconnectionwizard.h"
59 #include "jumpkeyhandler.h"
60 #include "msgprocessorstatuswidget.h"
61 #include "nicklistwidget.h"
62 #include "qtuiapplication.h"
63 #include "qtuimessageprocessor.h"
64 #include "qtuisettings.h"
65 #include "sessionsettings.h"
66 #include "settingsdlg.h"
67 #include "settingspagedlg.h"
68 #include "systemtray.h"
69 #include "toolbaractionprovider.h"
70 #include "topicwidget.h"
71 #include "verticaldock.h"
75 # include "desktopnotificationbackend.h"
78 # include "phononnotificationbackend.h"
80 # include "systraynotificationbackend.h"
81 # include "taskbarnotificationbackend.h"
83 # include "knotificationbackend.h"
86 #include "settingspages/aliasessettingspage.h"
87 #include "settingspages/appearancesettingspage.h"
88 #include "settingspages/backlogsettingspage.h"
89 #include "settingspages/bufferviewsettingspage.h"
90 #include "settingspages/chatmonitorsettingspage.h"
91 #include "settingspages/colorsettingspage.h"
92 #include "settingspages/fontssettingspage.h"
93 #include "settingspages/generalsettingspage.h"
94 #include "settingspages/highlightsettingspage.h"
95 #include "settingspages/identitiessettingspage.h"
96 #include "settingspages/networkssettingspage.h"
97 #include "settingspages/notificationssettingspage.h"
99 MainWin::MainWin(QWidget *parent)
101 : KMainWindow(parent),
102 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
104 : QMainWindow(parent),
106 coreLagLabel(new QLabel()),
107 sslLabel(new QLabel()),
108 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
112 QtUiSettings uiSettings;
113 QString style = uiSettings.value("Style", QString()).toString();
114 if(!style.isEmpty()) {
115 QApplication::setStyle(style);
118 QApplication::setQuitOnLastWindowClosed(false);
120 setWindowTitle("Quassel IRC");
121 setWindowIconText("Quassel IRC");
124 installEventFilter(new JumpKeyHandler(this));
126 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
127 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
128 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
131 void MainWin::init() {
133 if(s.value("MainWinSize").isValid())
134 resize(s.value("MainWinSize").toSize());
136 resize(QSize(800, 500));
138 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
139 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
140 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
141 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
142 SLOT(messagesInserted(const QModelIndex &, int, int)));
143 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
146 setDockNestingEnabled(true);
147 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
148 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
149 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
150 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
152 // Order is sometimes important
166 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
167 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
169 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
172 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
176 QtUi::registerNotificationBackend(new KNotificationBackend(this));
177 #endif /* HAVE_KDE */
179 // restore mainwin state
180 restoreState(s.value("MainWinState").toByteArray());
182 // restore locked state of docks
183 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
185 setDisconnectedState(); // Disable menus and stuff
189 if(Quassel::runMode() != Quassel::Monolithic) {
190 showCoreConnectionDlg(true); // autoconnect if appropriate
196 MainWin::~MainWin() {
198 s.setValue("MainWinSize", size());
199 s.setValue("MainWinPos", pos());
200 s.setValue("MainWinState", saveState());
203 void MainWin::updateIcon() {
205 const int size = 128;
211 if(Client::isConnected())
212 icon = DesktopIcon("quassel", size);
214 icon = DesktopIcon("quassel_inactive", size);
216 qApp->setWindowIcon(icon);
219 void MainWin::setupActions() {
220 ActionCollection *coll = QtUi::actionCollection("General");
222 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
223 this, SLOT(showCoreConnectionDlg())));
224 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
225 Client::instance(), SLOT(disconnectFromCore())));
226 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
227 this, SLOT(showCoreInfoDlg())));
228 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
229 this, SLOT(on_actionConfigureNetworks_triggered())));
230 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
231 qApp, SLOT(quit()), tr("Ctrl+Q")));
234 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
235 this, SLOT(on_actionConfigureViews_triggered())));
237 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
238 lockAct->setCheckable(true);
239 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
241 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
242 0, 0, tr("Ctrl+F")))->setCheckable(true);
243 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
244 this, SLOT(showAwayLog())));
245 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
246 0, 0))->setCheckable(true);
249 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
250 this, SLOT(showSettingsDlg()), tr("F7")));
253 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
254 this, SLOT(showAboutDlg())));
255 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
256 qApp, SLOT(aboutQt())));
257 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
258 this, SLOT(on_actionDebugNetworkModel_triggered())));
259 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
260 this, SLOT(on_actionDebugMessageModel_triggered())));
261 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
262 this, SLOT(on_actionDebugLog_triggered())));
265 void MainWin::setupMenus() {
266 ActionCollection *coll = QtUi::actionCollection("General");
268 _fileMenu = menuBar()->addMenu(tr("&File"));
270 static const QStringList coreActions = QStringList()
271 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
274 foreach(QString actionName, coreActions) {
275 coreAction = coll->action(actionName);
276 _fileMenu->addAction(coreAction);
277 flagRemoteCoreOnly(coreAction);
279 flagRemoteCoreOnly(_fileMenu->addSeparator());
281 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
282 _networksMenu->addAction(coll->action("ConfigureNetworks"));
283 _networksMenu->addSeparator();
284 _fileMenu->addSeparator();
285 _fileMenu->addAction(coll->action("Quit"));
287 _viewMenu = menuBar()->addMenu(tr("&View"));
288 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
289 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
290 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
291 _viewMenu->addSeparator();
292 _viewMenu->addAction(coll->action("ToggleSearchBar"));
294 coreAction = coll->action("ShowAwayLog");
295 flagRemoteCoreOnly(coreAction);
296 _viewMenu->addAction(coreAction);
298 _viewMenu->addAction(coll->action("ToggleStatusBar"));
299 _viewMenu->addSeparator();
300 _viewMenu->addAction(coll->action("LockLayout"));
302 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
304 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
305 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
307 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
309 _helpMenu = menuBar()->addMenu(tr("&Help"));
310 _helpMenu->addAction(coll->action("AboutQuassel"));
312 _helpMenu->addAction(coll->action("AboutQt"));
314 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
316 _helpMenu->addSeparator();
317 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
318 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
319 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
320 _helpDebugMenu->addAction(coll->action("DebugLog"));
323 void MainWin::setupBufferWidget() {
324 _bufferWidget = new BufferWidget(this);
325 _bufferWidget->setModel(Client::bufferModel());
326 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
327 setCentralWidget(_bufferWidget);
330 void MainWin::addBufferView(int bufferViewConfigId) {
331 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
334 void MainWin::addBufferView(ClientBufferViewConfig *config) {
338 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
339 BufferViewDock *dock = new BufferViewDock(config, this);
341 //create the view and initialize it's filter
342 BufferView *view = new BufferView(dock);
343 view->setFilteredModel(Client::bufferModel(), config);
344 view->installEventFilter(_inputWidget->inputLine()); // for key presses
347 Client::bufferModel()->synchronizeView(view);
349 dock->setWidget(view);
352 addDockWidget(Qt::LeftDockWidgetArea, dock);
353 _bufferViewsMenu->addAction(dock->toggleViewAction());
355 _bufferViews.append(dock);
358 void MainWin::removeBufferView(int bufferViewConfigId) {
360 BufferViewDock *dock;
361 foreach(QAction *action, _bufferViewsMenu->actions()) {
362 actionData = action->data();
363 if(!actionData.isValid())
366 dock = qobject_cast<BufferViewDock *>(action->parent());
367 if(dock && actionData.toInt() == bufferViewConfigId) {
368 removeAction(action);
374 BufferView *MainWin::allBuffersView() const {
375 // "All Buffers" is always the first dock created
376 if(_bufferViews.count() > 0)
377 return _bufferViews[0]->bufferView();
381 void MainWin::showNotificationsDlg() {
382 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
386 void MainWin::on_actionConfigureNetworks_triggered() {
387 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
391 void MainWin::on_actionConfigureViews_triggered() {
392 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
396 void MainWin::on_actionLockLayout_toggled(bool lock) {
397 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
398 foreach(VerticalDock *dock, docks) {
399 dock->showTitle(!lock);
401 if(Client::bufferViewManager()) {
402 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
403 config->setLocked(lock);
406 QtUiSettings().setValue("LockLayout", lock);
409 void MainWin::setupNickWidget() {
411 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
412 nickDock->setObjectName("NickDock");
413 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
415 _nickListWidget = new NickListWidget(nickDock);
416 nickDock->setWidget(_nickListWidget);
418 addDockWidget(Qt::RightDockWidgetArea, nickDock);
419 _viewMenu->addAction(nickDock->toggleViewAction());
420 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
422 // See NickListDock::NickListDock();
423 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
425 // attach the NickListWidget to the BufferModel and the default selection
426 _nickListWidget->setModel(Client::bufferModel());
427 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
430 void MainWin::setupChatMonitor() {
431 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
432 dock->setObjectName("ChatMonitorDock");
434 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
435 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
437 dock->setWidget(chatView);
440 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
441 _viewMenu->addAction(dock->toggleViewAction());
442 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
445 void MainWin::setupInputWidget() {
446 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
447 dock->setObjectName("InputDock");
449 _inputWidget = new InputWidget(dock);
450 dock->setWidget(_inputWidget);
452 addDockWidget(Qt::BottomDockWidgetArea, dock);
454 _viewMenu->addAction(dock->toggleViewAction());
455 dock->toggleViewAction()->setText(tr("Show Input Line"));
457 _inputWidget->setModel(Client::bufferModel());
458 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
460 _bufferWidget->setFocusProxy(_inputWidget);
462 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
465 void MainWin::setupTopicWidget() {
466 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
467 dock->setObjectName("TopicDock");
468 TopicWidget *topicwidget = new TopicWidget(dock);
470 dock->setWidget(topicwidget);
472 topicwidget->setModel(Client::bufferModel());
473 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
475 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
477 _viewMenu->addAction(dock->toggleViewAction());
478 dock->toggleViewAction()->setText(tr("Show Topic Line"));
481 void MainWin::setupTitleSetter() {
482 _titleSetter.setModel(Client::bufferModel());
483 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
486 void MainWin::setupStatusBar() {
487 // MessageProcessor progress
488 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
491 updateLagIndicator();
492 statusBar()->addPermanentWidget(coreLagLabel);
493 coreLagLabel->hide();
494 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
497 sslLabel->setPixmap(QPixmap());
498 statusBar()->addPermanentWidget(sslLabel);
501 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
503 QtUiSettings uiSettings;
505 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
506 showStatusbar->setChecked(enabled);
507 enabled ? statusBar()->show() : statusBar()->hide();
509 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
510 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
513 void MainWin::saveStatusBarStatus(bool enabled) {
514 QtUiSettings uiSettings;
515 uiSettings.setValue("ShowStatusBar", enabled);
518 void MainWin::setupSystray() {
519 _systemTray = new SystemTray(this);
522 connect(systemTray(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systrayActivated(QSystemTrayIcon::ActivationReason)));
527 void MainWin::setupToolBars() {
528 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
529 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
530 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
531 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
534 setUnifiedTitleAndToolBarOnMac(true);
536 _mainToolBar = addToolBar("Main Toolbar");
537 _mainToolBar->setObjectName("MainToolBar");
539 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
540 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
542 //_nickToolBar = addToolBar("User");
543 //_nickToolBar->setObjectName("NickToolBar");
544 //QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
547 _mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
548 //_nickToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
552 void MainWin::changeEvent(QEvent *event) {
553 if(event->type() == QEvent::WindowStateChange) {
554 if(windowState() & Qt::WindowMinimized) {
556 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
564 void MainWin::connectedToCore() {
565 Q_CHECK_PTR(Client::bufferViewManager());
566 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
567 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
568 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
573 void MainWin::setConnectedState() {
574 ActionCollection *coll = QtUi::actionCollection("General");
576 coll->action("ConnectCore")->setEnabled(false);
577 coll->action("DisconnectCore")->setEnabled(true);
578 coll->action("CoreInfo")->setEnabled(true);
580 foreach(QAction *action, _fileMenu->actions()) {
581 if(isRemoteCoreOnly(action))
582 action->setVisible(!Client::internalCore());
585 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
586 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
587 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
588 if(!Client::internalCore()) {
589 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
590 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
591 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
594 // _viewMenu->setEnabled(true);
595 if(!Client::internalCore())
596 statusBar()->showMessage(tr("Connected to core."));
598 statusBar()->clearMessage();
600 if(Client::signalProxy()->isSecure()) {
601 sslLabel->setPixmap(SmallIcon("security-high"));
603 sslLabel->setPixmap(SmallIcon("security-low"));
606 sslLabel->setVisible(!Client::internalCore());
607 coreLagLabel->setVisible(!Client::internalCore());
609 systemTray()->setState(SystemTray::Active);
611 if(Client::networkIds().isEmpty()) {
612 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
617 void MainWin::loadLayout() {
619 int accountId = Client::currentCoreAccount().toInt();
620 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
623 void MainWin::saveLayout() {
625 int accountId = Client::currentCoreAccount().toInt();
626 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
629 void MainWin::updateLagIndicator(int lag) {
630 QString text = tr("Core Lag: %1");
632 text = text.arg('-');
634 text = text.arg("%1 msec").arg(lag);
635 coreLagLabel->setText(text);
638 void MainWin::disconnectedFromCore() {
639 // save core specific layout and remove bufferviews;
642 BufferViewDock *dock;
643 foreach(QAction *action, _bufferViewsMenu->actions()) {
644 actionData = action->data();
645 if(!actionData.isValid())
648 dock = qobject_cast<BufferViewDock *>(action->parent());
649 if(dock && actionData.toInt() != -1) {
650 removeAction(action);
655 restoreState(s.value("MainWinState").toByteArray());
656 setDisconnectedState();
659 void MainWin::setDisconnectedState() {
660 ActionCollection *coll = QtUi::actionCollection("General");
661 //ui.menuCore->setEnabled(false);
662 coll->action("ConnectCore")->setEnabled(true);
663 coll->action("DisconnectCore")->setEnabled(false);
664 coll->action("CoreInfo")->setEnabled(false);
665 //_viewMenu->setEnabled(false);
666 statusBar()->showMessage(tr("Not connected to core."));
667 sslLabel->setPixmap(QPixmap());
669 updateLagIndicator();
670 coreLagLabel->hide();
671 if(msgProcessorStatusWidget)
672 msgProcessorStatusWidget->setProgress(0, 0);
674 systemTray()->setState(SystemTray::Inactive);
677 void MainWin::startInternalCore() {
678 ClientSyncer *syncer = new ClientSyncer();
679 Client::registerClientSyncer(syncer);
680 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
681 syncer->useInternalCore();
684 void MainWin::showCoreConnectionDlg(bool autoConnect) {
685 CoreConnectDlg(autoConnect, this).exec();
688 void MainWin::showChannelList(NetworkId netId) {
689 ChannelListDlg *channelListDlg = new ChannelListDlg();
691 if(!netId.isValid()) {
692 QAction *action = qobject_cast<QAction *>(sender());
694 netId = action->data().value<NetworkId>();
697 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
698 channelListDlg->setNetwork(netId);
699 channelListDlg->show();
702 void MainWin::showCoreInfoDlg() {
703 CoreInfoDlg(this).exec();
706 void MainWin::showAwayLog() {
709 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
710 _awayLog = new AwayLogView(filter, 0);
711 filter->setParent(_awayLog);
712 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
713 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
717 void MainWin::awayLogDestroyed() {
721 void MainWin::showSettingsDlg() {
722 SettingsDlg *dlg = new SettingsDlg();
724 //Category: Appearance
725 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
726 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
727 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
728 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
729 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
730 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
731 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
732 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
735 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
736 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
737 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
738 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
743 void MainWin::showAboutDlg() {
744 AboutDlg(this).exec();
748 void MainWin::showShortcutsDlg() {
749 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
753 void MainWin::closeEvent(QCloseEvent *event) {
755 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
757 if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
758 toggleMinimizedToTray();
762 QApplication::quit();
766 void MainWin::systrayActivated(QSystemTrayIcon::ActivationReason activationReason) {
767 if(activationReason == QSystemTrayIcon::Trigger) {
768 toggleMinimizedToTray();
772 void MainWin::hideToTray() {
773 if(!systemTray()->isSystemTrayAvailable()) {
774 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
779 systemTray()->setIconVisible();
782 void MainWin::toggleMinimizedToTray() {
783 if(windowState() & Qt::WindowMinimized) {
785 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
790 setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized);
795 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
798 if(QApplication::activeWindow() != 0)
801 for(int i = start; i <= end; i++) {
802 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
804 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
807 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
808 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self)) continue;
809 flags |= Message::Backlog; // we only want to trigger a highlight once!
810 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
812 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
813 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
815 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
816 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
817 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
818 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
819 QtUi::invokeNotification(bufId, sender, contents);
824 bool MainWin::event(QEvent *event) {
825 if(event->type() == QEvent::WindowActivate)
826 QtUi::closeNotifications();
827 return QMainWindow::event(event);
830 void MainWin::clientNetworkCreated(NetworkId id) {
831 const Network *net = Client::network(id);
832 QAction *act = new QAction(net->networkName(), this);
833 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
834 act->setData(QVariant::fromValue<NetworkId>(id));
835 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
836 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
838 QAction *beforeAction = 0;
839 foreach(QAction *action, _networksMenu->actions()) {
840 if(!action->data().isValid()) // ignore stock actions
842 if(net->networkName().localeAwareCompare(action->text()) < 0) {
843 beforeAction = action;
847 _networksMenu->insertAction(beforeAction, act);
850 void MainWin::clientNetworkUpdated() {
851 const Network *net = qobject_cast<const Network *>(sender());
855 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
859 action->setText(net->networkName());
861 switch(net->connectionState()) {
862 case Network::Initialized:
863 action->setIcon(SmallIcon("network-connect"));
865 case Network::Disconnected:
866 action->setIcon(SmallIcon("network-disconnect"));
869 action->setIcon(SmallIcon("network-wired"));
873 void MainWin::clientNetworkRemoved(NetworkId id) {
874 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
878 action->deleteLater();
881 void MainWin::connectOrDisconnectFromNet() {
882 QAction *act = qobject_cast<QAction *>(sender());
884 const Network *net = Client::network(act->data().value<NetworkId>());
886 if(net->connectionState() == Network::Disconnected) net->requestConnect();
887 else net->requestDisconnect();
890 void MainWin::on_actionDebugNetworkModel_triggered() {
891 QTreeView *view = new QTreeView;
892 view->setAttribute(Qt::WA_DeleteOnClose);
893 view->setWindowTitle("Debug NetworkModel View");
894 view->setModel(Client::networkModel());
895 view->setColumnWidth(0, 250);
896 view->setColumnWidth(1, 250);
897 view->setColumnWidth(2, 80);
898 view->resize(610, 300);
902 void MainWin::on_actionDebugMessageModel_triggered() {
903 QTableView *view = new QTableView(0);
904 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
905 filter->setSourceModel(Client::messageModel());
906 view->setModel(filter);
907 view->setAttribute(Qt::WA_DeleteOnClose, true);
908 view->verticalHeader()->hide();
909 view->horizontalHeader()->setStretchLastSection(true);
913 void MainWin::on_actionDebugLog_triggered() {
914 DebugLogWidget *logWidget = new DebugLogWidget(0);
918 void MainWin::saveStateToSession(const QString &sessionId) {
920 SessionSettings s(sessionId);
922 s.setValue("MainWinSize", size());
923 s.setValue("MainWinPos", pos());
924 s.setValue("MainWinState", saveState());
927 void MainWin::saveStateToSessionSettings(SessionSettings & s)
929 s.setValue("MainWinSize", size());
930 s.setValue("MainWinPos", pos());
931 s.setValue("MainWinState", saveState());
934 void MainWin::showStatusBarMessage(const QString &message) {
935 statusBar()->showMessage(message, 10000);