add more spacing
[personal-kdebase.git] / workspace / plasma / dataengines / notifications / notificationsengine.cpp
blob5d51b882ae3f251f26259e1f41ea1a15148cfcf4
1 /*
2 * Copyright (C) 2008 Dmitry Suzdalev <dimsuz@gmail.com>
4 * This program is free software you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include "notificationsengine.h"
21 #include "notificationservice.h"
22 #include "visualnotificationsadaptor.h"
24 #include <Plasma/Service>
26 NotificationsEngine::NotificationsEngine( QObject* parent, const QVariantList& args )
27 : Plasma::DataEngine( parent, args ), m_nextId( 1 )
29 VisualNotificationsAdaptor* adaptor = new VisualNotificationsAdaptor(this);
30 connect(this, SIGNAL(NotificationClosed(uint, uint)),
31 adaptor, SIGNAL(NotificationClosed(uint,uint)));
32 connect(this, SIGNAL(ActionInvoked(uint, const QString&)),
33 adaptor, SIGNAL(ActionInvoked(uint, const QString&)));
35 QDBusConnection dbus = QDBusConnection::sessionBus();
36 dbus.registerService( "org.kde.VisualNotifications" );
37 dbus.registerObject( "/VisualNotifications", this );
40 NotificationsEngine::~NotificationsEngine()
42 QDBusConnection dbus = QDBusConnection::sessionBus();
43 dbus.unregisterService( "org.kde.VisualNotifications" );
46 void NotificationsEngine::init()
50 uint NotificationsEngine::Notify(const QString &app_name, uint replaces_id, const QString &event_id,
51 const QString &app_icon, const QString &summary, const QString &body,
52 const QStringList &actions, const QVariantMap &hints, int timeout)
54 uint id = 0;
55 if (replaces_id == 0) {
56 // new notification
58 id = m_nextId++;
60 // TODO implement hints support
61 Q_UNUSED(hints)
63 QString appname_str = app_name;
64 if (appname_str.isEmpty()) {
65 appname_str = i18n("unknown app");
68 Plasma::DataEngine::Data notificationData;
69 notificationData.insert("id", QString::number(id ));
70 notificationData.insert("appName", appname_str );
71 notificationData.insert("appIcon", app_icon );
72 notificationData.insert("eventId", event_id );
73 notificationData.insert("summary", summary );
74 notificationData.insert("body", body );
75 notificationData.insert("actions", actions );
76 notificationData.insert("expireTimeout", timeout );
78 setData(QString("notification %1").arg(id), notificationData );
79 } else {
80 id = replaces_id;
81 // TODO: update existing source
82 kDebug() << "notice: updating notifications isn't implemented yet";
85 return id;
88 void NotificationsEngine::CloseNotification(uint id)
90 removeSource(QString("notification %1").arg(id));
91 emit NotificationClosed(id,0);
94 Plasma::Service* NotificationsEngine::serviceForSource(const QString& source)
96 return new NotificationService(this, source);
99 K_EXPORT_PLASMA_DATAENGINE(notifications, NotificationsEngine)
101 #include "notificationsengine.moc"