X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Findicatornotificationbackend.cpp;h=4fc0bb8ab2dbcf25b653af259701c002a540845a;hp=84e767e6e78e382b5f2c9afa81cba49061bf0736;hb=f04db2cb802b1296ca739c823495930c71d3b4ab;hpb=5c2708b1ae748cf1626229d27342d07638d126ff diff --git a/src/qtui/indicatornotificationbackend.cpp b/src/qtui/indicatornotificationbackend.cpp index 84e767e6..4fc0bb8a 100644 --- a/src/qtui/indicatornotificationbackend.cpp +++ b/src/qtui/indicatornotificationbackend.cpp @@ -1,22 +1,22 @@ /*************************************************************************** -* Copyright (C) 2005-09 Canonical Ltd * -* author: aurelien.gateau@canonical.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) version 3. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ + * Copyright (C) 2005-09 Canonical Ltd * + * author: aurelien.gateau@canonical.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ #include "indicatornotificationbackend.h" @@ -25,6 +25,7 @@ #include "client.h" #include "clientsettings.h" +#include "iconloader.h" #include "mainwin.h" #include "networkmodel.h" #include "qtui.h" @@ -32,153 +33,193 @@ #define STR(x) #x #define XSTR(x) STR(x) -class Indicator : public QIndicate::Indicator { +class Indicator : public QIndicate::Indicator +{ public: - uint lastNotificationId; + uint lastNotificationId; }; + IndicatorNotificationBackend::IndicatorNotificationBackend(QObject *parent) - : AbstractNotificationBackend(parent) + : AbstractNotificationBackend(parent) { - NotificationSettings notificationSettings; - _enabled = notificationSettings.value("Indicator/Enabled", false).toBool(); + NotificationSettings notificationSettings; + _enabled = notificationSettings.value("Indicator/Enabled", false).toBool(); - notificationSettings.notify("Indicator/Enabled", this, SLOT(enabledChanged(const QVariant &))); + notificationSettings.notify("Indicator/Enabled", this, SLOT(enabledChanged(const QVariant &))); - _server = QIndicate::Server::defaultInstance(); - _server->setType("message.irc"); - _server->setDesktopFile(XSTR(DESKTOP_FILE)); - connect(_server, SIGNAL(serverDisplay()), QtUi::mainWindow(), SLOT(toggleMinimizedToTray())); + _server = QIndicate::Server::defaultInstance(); + _server->setType("message.irc"); + QString desktopFile = QString("%1/%2.desktop") + .arg(XSTR(XDG_APPS_INSTALL_DIR)) + .arg(QCoreApplication::applicationFilePath().section('/', -1)); + _server->setDesktopFile(desktopFile); + connect(_server, SIGNAL(serverDisplay()), SLOT(activateMainWidget())); - if (_enabled) { - _server->show(); - } + if (_enabled) { + _server->show(); + } } -IndicatorNotificationBackend::~IndicatorNotificationBackend() { - qDeleteAll(_indicatorHash); + +IndicatorNotificationBackend::~IndicatorNotificationBackend() +{ + qDeleteAll(_indicatorHash); } -void IndicatorNotificationBackend::notify(const Notification ¬ification) { - if(!_enabled) { - return; - } - if (notification.type != Highlight && notification.type != PrivMsg) { - return; - } - BufferId bufferId = notification.bufferId; - Indicator *indicator = _indicatorHash.value(bufferId); - if(!indicator) { - indicator = new Indicator; - _indicatorHash.insert(bufferId, indicator); - connect(indicator, SIGNAL(display(QIndicate::Indicator*)), - SLOT(indicatorDisplayed(QIndicate::Indicator*))); - } - indicator->lastNotificationId = notification.notificationId; - - BufferInfo::Type type = Client::networkModel()->bufferType(bufferId); - QString name; - if (type == BufferInfo::QueryBuffer) { - name = notification.sender; - } else { - name = QString("%1 (%2)") - .arg(Client::networkModel()->bufferName(bufferId)) - .arg(notification.sender); - } - indicator->setNameProperty(name); - - indicator->setTimeProperty(QDateTime::currentDateTime()); - - QModelIndex index = Client::networkModel()->bufferIndex(bufferId); - QVariant icon = QtUi::style()->bufferViewItemData(index, Qt::DecorationRole); - if (icon.canConvert()) { - QImage image = icon.value().toImage(); - indicator->setIconProperty(image); - } - - indicator->setDrawAttentionProperty(true); - indicator->show(); + +void IndicatorNotificationBackend::activateMainWidget() +{ + GraphicalUi::activateMainWidget(); } -void IndicatorNotificationBackend::close(uint notificationId) { - // If we find an indicator whose lastNotificationId is notificationId, we - // delete it - IndicatorHash::Iterator - it = _indicatorHash.begin(), - end = _indicatorHash.end(); - for (; it != end; ++it) { - if (it.value()->lastNotificationId == notificationId) { - break; +void IndicatorNotificationBackend::notify(const Notification ¬ification) +{ + if (!_enabled) { + return; } - } - if (it == end) { - // Not found, maybe there was no indicator for this notification or another - // notification happened after - return; - } - _indicatorHash.erase(it); - delete it.value(); + if (notification.type != Highlight && notification.type != PrivMsg) { + return; + } + BufferId bufferId = notification.bufferId; + Indicator *indicator = _indicatorHash.value(bufferId); + if (!indicator) { + indicator = new Indicator; + _indicatorHash.insert(bufferId, indicator); + connect(indicator, SIGNAL(display(QIndicate::Indicator *)), + SLOT(indicatorDisplayed(QIndicate::Indicator *))); + } + indicator->lastNotificationId = notification.notificationId; + + BufferInfo::Type type = Client::networkModel()->bufferType(bufferId); + QString name; + if (type == BufferInfo::QueryBuffer) { + name = notification.sender; + } + else { + name = QString("%1 (%2)") + .arg(Client::networkModel()->bufferName(bufferId)) + .arg(notification.sender); + } + indicator->setNameProperty(name); + + indicator->setTimeProperty(QDateTime::currentDateTime()); + + QModelIndex index = Client::networkModel()->bufferIndex(bufferId); + QVariant icon = QtUi::style()->bufferViewItemData(index, Qt::DecorationRole); + if (icon.canConvert()) { + QImage image = icon.value().toImage(); + indicator->setIconProperty(image); + } + + indicator->setDrawAttentionProperty(true); + indicator->show(); } -void IndicatorNotificationBackend::enabledChanged(const QVariant &v) { - _enabled = v.toBool(); - if (_enabled) { - _server->show(); - // TODO: Create indicators for existing highlighted buffers? - } else { - _server->hide(); - qDeleteAll(_indicatorHash); - } + +void IndicatorNotificationBackend::close(uint notificationId) +{ + // If we find an indicator whose lastNotificationId is notificationId, we + // delete it + + IndicatorHash::Iterator + it = _indicatorHash.begin(), + end = _indicatorHash.end(); + for (; it != end; ++it) { + if (it.value()->lastNotificationId == notificationId) { + break; + } + } + if (it == end) { + // Not found, maybe there was no indicator for this notification or another + // notification happened after + return; + } + _indicatorHash.erase(it); + delete it.value(); } -void IndicatorNotificationBackend::indicatorDisplayed(QIndicate::Indicator *_indicator) { - Indicator *indicator = static_cast(_indicator); - emit activated(indicator->lastNotificationId); + +void IndicatorNotificationBackend::enabledChanged(const QVariant &v) +{ + _enabled = v.toBool(); + if (_enabled) { + _server->show(); + // TODO: Create indicators for existing highlighted buffers? + } + else { + _server->hide(); + qDeleteAll(_indicatorHash); + } +} + + +void IndicatorNotificationBackend::indicatorDisplayed(QIndicate::Indicator *_indicator) +{ + Indicator *indicator = static_cast(_indicator); + emit activated(indicator->lastNotificationId); } -SettingsPage *IndicatorNotificationBackend::createConfigWidget() const { - return new ConfigWidget(); + +SettingsPage *IndicatorNotificationBackend::createConfigWidget() const +{ + return new ConfigWidget(); } + /***************************************************************************/ IndicatorNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) -: SettingsPage("Internal", "IndicatorNotification", parent) + : SettingsPage("Internal", "IndicatorNotification", parent) { - ui.setupUi(this); + ui.setupUi(this); + // FIXME find proper icon (this one is used by the plasmoid as well) + ui.enabled->setIcon(SmallIcon("mail-message-new")); - connect(ui.enabled, SIGNAL(toggled(bool)), SLOT(widgetChanged())); + connect(ui.enabled, SIGNAL(toggled(bool)), SLOT(widgetChanged())); } -IndicatorNotificationBackend::ConfigWidget::~ConfigWidget() { + +IndicatorNotificationBackend::ConfigWidget::~ConfigWidget() +{ } -void IndicatorNotificationBackend::ConfigWidget::widgetChanged() { - bool changed = enabled != ui.enabled->isChecked(); - if(changed != hasChanged()) setChangedState(changed); +void IndicatorNotificationBackend::ConfigWidget::widgetChanged() +{ + bool changed = enabled != ui.enabled->isChecked(); + + if (changed != hasChanged()) setChangedState(changed); } -bool IndicatorNotificationBackend::ConfigWidget::hasDefaults() const { - return true; + +bool IndicatorNotificationBackend::ConfigWidget::hasDefaults() const +{ + return true; } -void IndicatorNotificationBackend::ConfigWidget::defaults() { - ui.enabled->setChecked(false); - widgetChanged(); + +void IndicatorNotificationBackend::ConfigWidget::defaults() +{ + ui.enabled->setChecked(false); + widgetChanged(); } -void IndicatorNotificationBackend::ConfigWidget::load() { - NotificationSettings s; - enabled = s.value("Indicator/Enabled", false).toBool(); - ui.enabled->setChecked(enabled); - setChangedState(false); +void IndicatorNotificationBackend::ConfigWidget::load() +{ + NotificationSettings s; + enabled = s.value("Indicator/Enabled", false).toBool(); + + ui.enabled->setChecked(enabled); + setChangedState(false); } -void IndicatorNotificationBackend::ConfigWidget::save() { - NotificationSettings s; - s.setValue("Indicator/Enabled", ui.enabled->isChecked()); - load(); + +void IndicatorNotificationBackend::ConfigWidget::save() +{ + NotificationSettings s; + s.setValue("Indicator/Enabled", ui.enabled->isChecked()); + load(); }