1 /***************************************************************************
2 * Copyright (C) 2005-08 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 "actioncollection.h"
25 #include "bufferview.h"
26 #include "bufferviewconfig.h"
27 #include "bufferviewfilter.h"
28 #include "bufferviewmanager.h"
29 #include "channellistdlg.h"
30 #include "chatlinemodel.h"
31 #include "chatmonitorfilter.h"
32 #include "chatmonitorview.h"
34 #include "chatviewsearchbar.h"
36 #include "clientbacklogmanager.h"
37 #include "coreinfodlg.h"
38 #include "coreconnectdlg.h"
39 #include "iconloader.h"
40 #include "msgprocessorstatuswidget.h"
41 #include "qtuimessageprocessor.h"
42 #include "qtuiapplication.h"
43 #include "networkmodel.h"
44 #include "buffermodel.h"
45 #include "nicklistwidget.h"
46 #include "settingsdlg.h"
47 #include "settingspagedlg.h"
48 #include "signalproxy.h"
49 #include "topicwidget.h"
50 #include "inputwidget.h"
51 #include "irclistmodel.h"
52 #include "verticaldock.h"
53 #include "uisettings.h"
54 #include "qtuisettings.h"
55 #include "jumpkeyhandler.h"
56 #include "sessionsettings.h"
58 #include "selectionmodelsynchronizer.h"
59 #include "mappedselectionmodel.h"
61 #include "settingspages/aliasessettingspage.h"
62 #include "settingspages/appearancesettingspage.h"
63 #include "settingspages/bufferviewsettingspage.h"
64 #include "settingspages/colorsettingspage.h"
65 #include "settingspages/fontssettingspage.h"
66 #include "settingspages/generalsettingspage.h"
67 #include "settingspages/highlightsettingspage.h"
68 #include "settingspages/identitiessettingspage.h"
69 #include "settingspages/networkssettingspage.h"
70 #include "settingspages/notificationssettingspage.h"
72 #include "qtuistyle.h"
74 MainWin::MainWin(QWidget *parent)
75 : QMainWindow(parent),
76 coreLagLabel(new QLabel()),
77 sslLabel(new QLabel()),
78 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
81 systray(new QSystemTrayIcon(this)),
83 activeTrayIcon("quassel_newmessage"),
84 onlineTrayIcon("quassel"),
85 offlineTrayIcon("quassel_disconnected"),
86 trayIconActive(false),
88 timer(new QTimer(this)),
89 _actionCollection(new ActionCollection(this))
91 UiSettings uiSettings;
92 QString style = uiSettings.value("Style", QString("")).toString();
94 QApplication::setStyle(style);
97 setWindowTitle("Quassel IRC");
98 setWindowIcon(offlineTrayIcon);
99 qApp->setWindowIcon(offlineTrayIcon);
100 systray->setIcon(offlineTrayIcon);
101 setWindowIconText("Quassel IRC");
103 QtUi::actionCollection()->addAssociatedWidget(this);
105 statusBar()->showMessage(tr("Waiting for core..."));
107 installEventFilter(new JumpKeyHandler(this));
110 desktopNotifications = new org::freedesktop::Notifications(
111 "org.freedesktop.Notifications",
112 "/org/freedesktop/Notifications",
113 QDBusConnection::sessionBus(), this);
115 connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint)));
116 connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&)));
118 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
119 connect(app, SIGNAL(saveStateToSession(const QString&)), this, SLOT(saveStateToSession(const QString&)));
120 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), this, SLOT(saveStateToSessionSettings(SessionSettings&)));
123 void MainWin::init() {
125 if(s.value("MainWinSize").isValid())
126 resize(s.value("MainWinSize").toSize());
128 resize(QSize(800, 500));
130 connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(saveLayout()));
132 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkCreated(NetworkId)));
133 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId)));
137 statusBar()->showMessage(tr("Not connected to core."));
140 setDockNestingEnabled(true);
142 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
143 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
144 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
145 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
158 // restore mainwin state
159 restoreState(s.value("MainWinState").toByteArray());
161 // restore locked state of docks
162 ui.actionLockDockPositions->setChecked(s.value("LockDocks", false).toBool());
164 setDisconnectedState(); // Disable menus and stuff
165 showCoreConnectionDlg(true); // autoconnect if appropriate
167 // attach the BufferWidget to the BufferModel and the default selection
168 ui.bufferWidget->setModel(Client::bufferModel());
169 ui.bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
170 ui.menuViews->addAction(QtUi::actionCollection()->action("toggleSearchBar"));
172 _titleSetter.setModel(Client::bufferModel());
173 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
176 MainWin::~MainWin() {
178 s.setValue("MainWinSize", size());
179 s.setValue("MainWinPos", pos());
180 s.setValue("MainWinState", saveState());
183 void MainWin::setupActions() {
184 // TODO don't get these from *.ui anymore... we shouldn't need one
185 ui.actionQuit->setIcon(SmallIcon("application-exit"));
186 ui.actionSettingsDlg->setIcon(SmallIcon("configure"));
187 ui.actionManageViews->setIcon(SmallIcon("view-tree"));
188 ui.actionManageViews2->setIcon(SmallIcon("view-tree"));
189 ui.actionAboutQt->setIcon(SmallIcon("qt"));
190 ui.actionAboutQuassel->setIcon(SmallIcon("quassel"));
191 ui.actionConnectCore->setIcon(SmallIcon("network-connect"));
192 ui.actionDisconnectCore->setIcon(SmallIcon("network-disconnect"));
193 ui.actionCoreInfo->setIcon(SmallIcon("help-about"));
196 void MainWin::setupMenus() {
197 connect(ui.actionConnectCore, SIGNAL(triggered()), this, SLOT(showCoreConnectionDlg()));
198 connect(ui.actionDisconnectCore, SIGNAL(triggered()), Client::instance(), SLOT(disconnectFromCore()));
199 connect(ui.actionCoreInfo, SIGNAL(triggered()), this, SLOT(showCoreInfoDlg()));
200 connect(ui.actionQuit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()));
201 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
202 connect(ui.actionAboutQuassel, SIGNAL(triggered()), this, SLOT(showAboutDlg()));
203 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
206 void MainWin::setupViews() {
210 void MainWin::addBufferView(int bufferViewConfigId) {
211 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
214 void MainWin::addBufferView(BufferViewConfig *config) {
215 BufferViewDock *dock;
217 dock = new BufferViewDock(config, this);
219 dock = new BufferViewDock(this);
221 //create the view and initialize it's filter
222 BufferView *view = new BufferView(dock);
223 view->setFilteredModel(Client::bufferModel(), config);
226 connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList()));
228 Client::bufferModel()->synchronizeView(view);
230 dock->setWidget(view);
233 addDockWidget(Qt::LeftDockWidgetArea, dock);
234 ui.menuBufferViews->addAction(dock->toggleViewAction());
236 _netViews.append(dock);
239 void MainWin::removeBufferView(int bufferViewConfigId) {
241 BufferViewDock *dock;
242 foreach(QAction *action, ui.menuBufferViews->actions()) {
243 actionData = action->data();
244 if(!actionData.isValid())
247 dock = qobject_cast<BufferViewDock *>(action->parent());
248 if(dock && actionData.toInt() == bufferViewConfigId) {
249 removeAction(action);
255 void MainWin::on_actionEditNetworks_triggered() {
256 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
260 void MainWin::on_actionManageViews_triggered() {
261 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
265 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
266 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
267 foreach(VerticalDock *dock, docks) {
268 dock->showTitle(!lock);
270 QtUiSettings().setValue("LockDocks", lock);
273 void MainWin::setupNickWidget() {
275 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
276 nickDock->setObjectName("NickDock");
277 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
279 nickListWidget = new NickListWidget(nickDock);
280 nickDock->setWidget(nickListWidget);
282 addDockWidget(Qt::RightDockWidgetArea, nickDock);
283 ui.menuViews->addAction(nickDock->toggleViewAction());
284 // See NickListDock::NickListDock();
285 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
287 // attach the NickListWidget to the BufferModel and the default selection
288 nickListWidget->setModel(Client::bufferModel());
289 nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
292 void MainWin::setupChatMonitor() {
293 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
294 dock->setObjectName("ChatMonitorDock");
296 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
297 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
299 dock->setWidget(chatView);
302 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
303 ui.menuViews->addAction(dock->toggleViewAction());
306 void MainWin::setupInputWidget() {
307 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
308 dock->setObjectName("InputDock");
310 InputWidget *inputWidget = new InputWidget(dock);
311 dock->setWidget(inputWidget);
313 addDockWidget(Qt::BottomDockWidgetArea, dock);
315 ui.menuViews->addAction(dock->toggleViewAction());
317 inputWidget->setModel(Client::bufferModel());
318 inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
320 ui.bufferWidget->setFocusProxy(inputWidget);
323 void MainWin::setupTopicWidget() {
324 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
325 dock->setObjectName("TopicDock");
326 TopicWidget *topicwidget = new TopicWidget(dock);
328 dock->setWidget(topicwidget);
330 topicwidget->setModel(Client::bufferModel());
331 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
333 addDockWidget(Qt::TopDockWidgetArea, dock);
335 ui.menuViews->addAction(dock->toggleViewAction());
338 void MainWin::setupStatusBar() {
339 // MessageProcessor progress
340 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
341 connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
344 updateLagIndicator(0);
345 statusBar()->addPermanentWidget(coreLagLabel);
346 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
349 connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
350 sslLabel->setPixmap(QPixmap());
351 statusBar()->addPermanentWidget(sslLabel);
353 ui.menuViews->addSeparator();
354 QAction *showStatusbar = ui.menuViews->addAction(tr("Statusbar"));
355 showStatusbar->setCheckable(true);
357 UiSettings uiSettings;
359 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
360 showStatusbar->setChecked(enabled);
361 enabled ? statusBar()->show() : statusBar()->hide();
363 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
364 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
367 void MainWin::saveStatusBarStatus(bool enabled) {
368 UiSettings uiSettings;
369 uiSettings.setValue("ShowStatusBar", enabled);
372 void MainWin::setupSystray() {
373 connect(timer, SIGNAL(timeout()), this, SLOT(makeTrayIconBlink()));
374 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
375 this, SLOT(messagesInserted(const QModelIndex &, int, int)));
377 systrayMenu = new QMenu(this);
378 systrayMenu->addAction(ui.actionAboutQuassel);
379 systrayMenu->addSeparator();
380 systrayMenu->addAction(ui.actionConnectCore);
381 systrayMenu->addAction(ui.actionDisconnectCore);
382 systrayMenu->addSeparator();
383 systrayMenu->addAction(ui.actionQuit);
385 systray->setContextMenu(systrayMenu);
388 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
393 connect(systray, SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
394 this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
399 void MainWin::changeEvent(QEvent *event) {
400 if(event->type() == QEvent::WindowStateChange) {
401 if(windowState() & Qt::WindowMinimized) {
403 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
411 void MainWin::connectedToCore() {
412 Q_CHECK_PTR(Client::bufferViewManager());
413 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
414 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
415 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
417 Client::backlogManager()->requestInitialBacklog();
421 void MainWin::setConnectedState() {
422 //ui.menuCore->setEnabled(true);
423 ui.actionConnectCore->setEnabled(false);
424 ui.actionDisconnectCore->setEnabled(true);
425 ui.actionCoreInfo->setEnabled(true);
426 ui.menuViews->setEnabled(true);
427 ui.bufferWidget->show();
428 statusBar()->showMessage(tr("Connected to core."));
429 setWindowIcon(onlineTrayIcon);
430 qApp->setWindowIcon(onlineTrayIcon);
431 systray->setIcon(onlineTrayIcon);
432 if(sslLabel->width() == 0)
433 sslLabel->setPixmap(SmallIcon("security-low"));
436 void MainWin::loadLayout() {
438 int accountId = Client::currentCoreAccount().toInt();
439 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
442 void MainWin::saveLayout() {
444 int accountId = Client::currentCoreAccount().toInt();
445 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
448 void MainWin::updateLagIndicator(int lag) {
449 coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag));
453 void MainWin::securedConnection() {
454 // todo: make status bar entry
455 sslLabel->setPixmap(SmallIcon("security-high"));
458 void MainWin::disconnectedFromCore() {
459 // save core specific layout and remove bufferviews;
462 BufferViewDock *dock;
463 foreach(QAction *action, ui.menuBufferViews->actions()) {
464 actionData = action->data();
465 if(!actionData.isValid())
468 dock = qobject_cast<BufferViewDock *>(action->parent());
469 if(dock && actionData.toInt() != -1) {
470 removeAction(action);
475 restoreState(s.value("MainWinState").toByteArray());
476 setDisconnectedState();
479 void MainWin::setDisconnectedState() {
480 //ui.menuCore->setEnabled(false);
481 ui.actionConnectCore->setEnabled(true);
482 ui.actionDisconnectCore->setEnabled(false);
483 ui.actionCoreInfo->setEnabled(false);
484 ui.menuViews->setEnabled(false);
485 ui.bufferWidget->hide();
486 statusBar()->showMessage(tr("Not connected to core."));
487 setWindowIcon(offlineTrayIcon);
488 qApp->setWindowIcon(offlineTrayIcon);
489 systray->setIcon(offlineTrayIcon);
490 sslLabel->setPixmap(QPixmap());
493 void MainWin::showCoreConnectionDlg(bool autoConnect) {
494 CoreConnectDlg(autoConnect, this).exec();
497 void MainWin::showChannelList(NetworkId netId) {
498 ChannelListDlg *channelListDlg = new ChannelListDlg();
500 if(!netId.isValid()) {
501 QAction *action = qobject_cast<QAction *>(sender());
503 netId = action->data().value<NetworkId>();
506 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
507 channelListDlg->setNetwork(netId);
508 channelListDlg->show();
511 void MainWin::showCoreInfoDlg() {
512 CoreInfoDlg(this).exec();
515 void MainWin::showSettingsDlg() {
516 SettingsDlg *dlg = new SettingsDlg();
518 //Category: Appearance
519 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
520 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
521 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
522 //Category: Behaviour
523 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
524 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
525 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
526 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
528 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
529 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
530 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
535 void MainWin::showAboutDlg() {
536 AboutDlg(this).exec();
539 void MainWin::closeEvent(QCloseEvent *event) {
541 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
549 void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
550 if(activationReason == QSystemTrayIcon::Trigger) {
555 void MainWin::toggleVisibility() {
556 if(isHidden() /*|| !isActiveWindow()*/) {
567 // setFocus(); //Qt::ActiveWindowFocusReason
570 if(systray->isSystemTrayAvailable ()) {
573 if(!systray->isVisible()) {
582 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
585 if(QApplication::activeWindow() != 0)
588 for(int i = start; i <= end; i++) {
589 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
591 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
594 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
595 if(flags.testFlag(Message::Backlog)) continue;
596 flags |= Message::Backlog; // we only want to trigger a highlight once!
597 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
599 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
600 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
602 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
603 QString title = Client::networkModel()->networkName(bufId) + " - " + Client::networkModel()->bufferName(bufId);
605 // FIXME Don't instantiate this for every highlight...
606 UiSettings uiSettings;
608 bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool();
609 bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool();
610 if(displayBubble || displayDesktop) {
611 if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) {
612 QString text = idx.data(ChatLineModel::DisplayRole).toString();
613 if(displayBubble) displayTrayIconMessage(title, text);
615 if(displayDesktop) sendDesktopNotification(title, text);
618 if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
619 QApplication::alert(this);
620 setTrayIconActivity(true);
627 bool MainWin::event(QEvent *event) {
628 if(event->type() == QEvent::WindowActivate)
629 setTrayIconActivity(false);
630 return QMainWindow::event(event);
636 Using the notification-daemon from Freedesktop's Galago project
637 http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify
639 void MainWin::sendDesktopNotification(const QString &title, const QString &message) {
641 QMap<QString, QVariant> hints;
642 UiSettings uiSettings;
644 hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up
645 hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up
647 actions << "click" << "Click Me!";
649 QDBusReply<uint> reply = desktopNotifications->Notify(
650 "Quassel", // Application name
651 notificationId, // ID of previous notification to replace
652 "", // Icon to display
653 title, // Summary / Header of the message to display
654 QString("%1: %2:\n%3").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display
655 actions, // Actions from which the user may choose
656 hints, // Hints to the server displaying the message
657 uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds
660 if(!reply.isValid()) {
662 // could also happen if no notification service runs, so... whatever :)
663 //qDebug() << "Error on sending notification..." << reply.error();
667 notificationId = reply.value();
669 // qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString();
673 void MainWin::desktopNotificationClosed(uint id, uint reason) {
674 Q_UNUSED(id); Q_UNUSED(reason);
675 // qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString();
680 void MainWin::desktopNotificationInvoked(uint id, const QString & action) {
681 Q_UNUSED(id); Q_UNUSED(action);
682 // qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString();
685 #endif /* HAVE_DBUS */
687 void MainWin::displayTrayIconMessage(const QString &title, const QString &message) {
688 systray->showMessage(title, message);
691 void MainWin::setTrayIconActivity(bool active) {
693 if(!timer->isActive())
697 systray->setIcon(onlineTrayIcon);
701 void MainWin::makeTrayIconBlink() {
703 systray->setIcon(onlineTrayIcon);
704 trayIconActive = false;
706 systray->setIcon(activeTrayIcon);
707 trayIconActive = true;
711 void MainWin::clientNetworkCreated(NetworkId id) {
712 const Network *net = Client::network(id);
713 QAction *act = new QAction(net->networkName(), this);
714 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
715 act->setData(QVariant::fromValue<NetworkId>(id));
716 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
717 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
719 QAction *beforeAction = 0;
720 foreach(QAction *action, ui.menuNetworks->actions()) {
721 if(action->isSeparator()) {
722 beforeAction = action;
725 if(net->networkName().localeAwareCompare(action->text()) < 0) {
726 beforeAction = action;
730 Q_CHECK_PTR(beforeAction);
731 ui.menuNetworks->insertAction(beforeAction, act);
734 void MainWin::clientNetworkUpdated() {
735 const Network *net = qobject_cast<const Network *>(sender());
739 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
743 action->setText(net->networkName());
745 switch(net->connectionState()) {
746 case Network::Initialized:
747 action->setIcon(SmallIcon("network-connect"));
749 case Network::Disconnected:
750 action->setIcon(SmallIcon("network-disconnect"));
753 action->setIcon(SmallIcon("network-wired"));
757 void MainWin::clientNetworkRemoved(NetworkId id) {
758 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
762 action->deleteLater();
765 void MainWin::connectOrDisconnectFromNet() {
766 QAction *act = qobject_cast<QAction *>(sender());
768 const Network *net = Client::network(act->data().value<NetworkId>());
770 if(net->connectionState() == Network::Disconnected) net->requestConnect();
771 else net->requestDisconnect();
776 void MainWin::on_actionDebugNetworkModel_triggered(bool) {
777 QTreeView *view = new QTreeView;
778 view->setAttribute(Qt::WA_DeleteOnClose);
779 view->setWindowTitle("Debug NetworkModel View");
780 view->setModel(Client::networkModel());
781 view->setColumnWidth(0, 250);
782 view->setColumnWidth(1, 250);
783 view->setColumnWidth(2, 80);
784 view->resize(610, 300);
788 void MainWin::saveStateToSession(const QString &sessionId) {
790 SessionSettings s(sessionId);
792 s.setValue("MainWinSize", size());
793 s.setValue("MainWinPos", pos());
794 s.setValue("MainWinState", saveState());
797 void MainWin::saveStateToSessionSettings(SessionSettings & s)
799 s.setValue("MainWinSize", size());
800 s.setValue("MainWinPos", pos());
801 s.setValue("MainWinState", saveState());