• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

dbusnotificationprotocol.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   fdoprotocol.cpp                                                       *
00003  *                                                                         *
00004  *   Copyright (C) 2008 Jason Stubbs <jasonbstubbs@gmail.com>              *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  *   This program is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU General Public License for more details.                          *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this program; if not, write to the                         *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00020  ***************************************************************************/
00021 
00022 #include "dbusnotification.h"
00023 #include "dbusnotificationprotocol.h"
00024 
00025 #include <KConfigGroup>
00026 #include <KIcon>
00027 
00028 #include <plasma/dataenginemanager.h>
00029 #include <plasma/service.h>
00030 
00031 
00032 namespace SystemTray
00033 {
00034 
00035 static const char *engineName = "notifications";
00036 
00037 DBusNotificationProtocol::DBusNotificationProtocol(QObject *parent)
00038     : Protocol(parent),
00039       m_engine(0)
00040 {
00041 }
00042 
00043 
00044 DBusNotificationProtocol::~DBusNotificationProtocol()
00045 {
00046     if (m_engine) {
00047         Plasma::DataEngineManager::self()->unloadEngine(engineName);
00048     }
00049 }
00050 
00051 
00052 void DBusNotificationProtocol::init()
00053 {
00054     m_engine = Plasma::DataEngineManager::self()->loadEngine(engineName);
00055 
00056     if (!m_engine->isValid()) {
00057         m_engine = 0;
00058         return;
00059     }
00060 
00061     connect(m_engine, SIGNAL(sourceAdded(const QString&)),
00062             this, SLOT(prepareNotification(const QString&)));
00063     connect(m_engine, SIGNAL(sourceRemoved(const QString&)),
00064             this, SLOT(removeNotification(const QString&)));
00065 }
00066 
00067 
00068 void DBusNotificationProtocol::prepareNotification(const QString &source)
00069 {
00070     m_engine->connectSource(source, this);
00071 }
00072 
00073 
00074 void DBusNotificationProtocol::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
00075 {
00076     bool isNew = !m_notifications.contains(source);
00077 
00078     if (isNew) {
00079         m_notifications[source] = new DBusNotification(source, this);
00080         connect(m_notifications[source], SIGNAL(notificationDeleted(const QString&)),
00081                 this, SLOT(removeNotification(const QString&)));
00082         connect(m_notifications[source], SIGNAL(actionTriggered(const QString&, const QString&)),
00083                 this, SLOT(relayAction(const QString&, const QString&)));
00084     }
00085 
00086     DBusNotification* notification = m_notifications[source];
00087     notification->setApplicationName(data.value("appName").toString());
00088     notification->setApplicationIcon(KIcon(data.value("appIcon").toString()));
00089     notification->setEventId(data.value("eventId").toString());
00090     notification->setSummary(data.value("summary").toString());
00091     notification->setMessage(data.value("body").toString());
00092     notification->setTimeout(data.value("expireTimeout").toInt());
00093 
00094     QStringList codedActions = data.value("actions").toStringList();
00095     if (codedActions.count() % 2 != 0) {
00096         kDebug() << "Invalid actions" << codedActions << "from" << notification->applicationName();
00097         codedActions.clear();
00098     }
00099 
00100     QHash<QString, QString> actions;
00101     QStringList actionOrder;
00102 
00103     while (!codedActions.isEmpty()) {
00104         QString actionId = codedActions.takeFirst();
00105         QString actionName = codedActions.takeFirst();
00106         actions.insert(actionId, actionName);
00107         actionOrder.append(actionId);
00108     }
00109 
00110     notification->setActions(actions);
00111     notification->setActionOrder(actionOrder);
00112 
00113     if (isNew) {
00114         emit notificationCreated(notification);
00115     } else {
00116         emit notification->changed(notification);
00117     }
00118 }
00119 
00120 
00121 void DBusNotificationProtocol::relayAction(const QString &source, const QString &actionId)
00122 {
00123     Plasma::Service *service = m_engine->serviceForSource(source);
00124     KConfigGroup op = service->operationDescription("invokeAction");
00125 
00126     if (op.isValid()) {
00127         op.writeEntry("actionId", actionId);
00128         service->startOperationCall(op);
00129     } else {
00130         kDebug() << "invalid operation";
00131     }
00132 }
00133 
00134 
00135 void DBusNotificationProtocol::removeNotification(const QString &source)
00136 {
00137     if (m_notifications.contains(source)) {
00138         m_notifications.take(source)->deleteLater();
00139     }
00140 }
00141 
00142 }
00143 
00144 #include "dbusnotificationprotocol.moc"

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal