Engines
notificationsengine.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "notificationsengine.h"
00021 #include "notificationservice.h"
00022 #include "visualnotificationsadaptor.h"
00023
00024 #include <Plasma/Service>
00025
00026 NotificationsEngine::NotificationsEngine( QObject* parent, const QVariantList& args )
00027 : Plasma::DataEngine( parent, args ), m_nextId( 1 )
00028 {
00029 VisualNotificationsAdaptor* adaptor = new VisualNotificationsAdaptor(this);
00030 connect(this, SIGNAL(NotificationClosed(uint, uint)),
00031 adaptor, SIGNAL(NotificationClosed(uint,uint)));
00032 connect(this, SIGNAL(ActionInvoked(uint, const QString&)),
00033 adaptor, SIGNAL(ActionInvoked(uint, const QString&)));
00034
00035 QDBusConnection dbus = QDBusConnection::sessionBus();
00036 dbus.registerService( "org.kde.VisualNotifications" );
00037 dbus.registerObject( "/VisualNotifications", this );
00038 }
00039
00040 NotificationsEngine::~NotificationsEngine()
00041 {
00042 QDBusConnection dbus = QDBusConnection::sessionBus();
00043 dbus.unregisterService( "org.kde.VisualNotifications" );
00044 }
00045
00046 void NotificationsEngine::init()
00047 {
00048 }
00049
00050 uint NotificationsEngine::Notify(const QString &app_name, uint replaces_id, const QString &event_id,
00051 const QString &app_icon, const QString &summary, const QString &body,
00052 const QStringList &actions, const QVariantMap &hints, int timeout)
00053 {
00054 uint id = 0;
00055 if (replaces_id == 0) {
00056
00057
00058 id = m_nextId++;
00059
00060
00061 Q_UNUSED(hints)
00062
00063 QString appname_str = app_name;
00064 if (appname_str.isEmpty()) {
00065 appname_str = i18n("unknown app");
00066 }
00067
00068 Plasma::DataEngine::Data notificationData;
00069 notificationData.insert("id", QString::number(id ));
00070 notificationData.insert("appName", appname_str );
00071 notificationData.insert("appIcon", app_icon );
00072 notificationData.insert("eventId", event_id );
00073 notificationData.insert("summary", summary );
00074 notificationData.insert("body", body );
00075 notificationData.insert("actions", actions );
00076 notificationData.insert("expireTimeout", timeout );
00077
00078 setData(QString("notification %1").arg(id), notificationData );
00079 } else {
00080 id = replaces_id;
00081
00082 kDebug() << "notice: updating notifications isn't implemented yet";
00083 }
00084
00085 return id;
00086 }
00087
00088 void NotificationsEngine::CloseNotification(uint id)
00089 {
00090 removeSource(QString("notification %1").arg(id));
00091 emit NotificationClosed(id,0);
00092 }
00093
00094 Plasma::Service* NotificationsEngine::serviceForSource(const QString& source)
00095 {
00096 return new NotificationService(this, source);
00097 }
00098
00099 K_EXPORT_PLASMA_DATAENGINE(notifications, NotificationsEngine)
00100
00101 #include "notificationsengine.moc"