>From fe2e6d17335aa8884f0252784c8148202737b503 Mon Sep 17 00:00:00 2001
From: Salvatore Iovene <salvatore.iovene@linux.intel.com>
Date: Tue, 14 Jun 2011 06:33:18 -0700
Subject: [PATCH 4/7] syncevo-dbus-server: initial implementation of mlite backend.

Show a notification with TransferEvent event type and create an
MRemoteAction that calls a new dbus method which runs sync-ui,
if available.
---
 src/NotificationBackendMLite.cpp            |   17 ++++++++++++-----
 src/dbus/interfaces/syncevo-server-full.xml |    8 ++++++++
 src/syncevo-dbus-server.cpp                 |   12 ++++++++++++
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/NotificationBackendMLite.cpp b/src/NotificationBackendMLite.cpp
index 9469719..7fd70d9 100644
--- a/src/NotificationBackendMLite.cpp
+++ b/src/NotificationBackendMLite.cpp
@@ -41,11 +41,18 @@ void NotificationBackendMLite::publish(
     const std::string& summary, const std::string& body,
     const std::string& viewParams)
 {
-    MNotification notice (MNotification::ImReceivedEvent);
-    notice.setSummary(QString::fromStdString(summary));
-    notice.setBody(QString::fromStdString(body));
-    notice.setImage("");
-    notice.publish();
+    MNotification n (MNotification::TransferEvent);
+
+    n.setSummary(QString::fromStdString(summary));
+    n.setBody(QString::fromStdString(body));
+
+    MRemoteAction action("org.syncevolution",
+                         "/org/syncevolution/Server",
+                         "org.syncevolution.Server",
+                         "org.syncevolution.Server.NotificationAction");
+    n.setAction(action);
+
+    n.publish();
 }
 
 SE_END_CXX
diff --git a/src/dbus/interfaces/syncevo-server-full.xml b/src/dbus/interfaces/syncevo-server-full.xml
index b5c402f..fbe356e 100644
--- a/src/dbus/interfaces/syncevo-server-full.xml
+++ b/src/dbus/interfaces/syncevo-server-full.xml
@@ -190,6 +190,14 @@ sometimes also a beta or alpha suffix),
       </arg>
     </method>
 
+    <method name="NotificationAction">
+      <doc:doc>
+        <doc:description>
+          Launches sync-ui as a reaction of the user activating a notification.
+        </doc:description>
+      </doc:doc>
+    </method>
+
     <method name ="GetConfigs">
       <doc:doc><doc:description>
         <doc:para>
diff --git a/src/syncevo-dbus-server.cpp b/src/syncevo-dbus-server.cpp
index 00f117b..e34ad20 100644
--- a/src/syncevo-dbus-server.cpp
+++ b/src/syncevo-dbus-server.cpp
@@ -1251,6 +1251,17 @@ class DBusServer : public DBusObjectHelper,
         setNotifications(true, caller, notifications);
     }
 
+    /** Server.NotificationAction() */
+    void notificationAction(const Caller_t &caller) {
+        pid_t pid;
+        if((pid = fork()) == 0) {
+            // search sync-ui from $PATH
+            if(execlp("sync-ui", "sync-ui", (const char*)0) < 0) {
+                exit(0);
+            }
+        }
+    }
+
     /** actual implementation of enable and disable */
     void setNotifications(bool enable,
                           const Caller_t &caller,
@@ -5625,6 +5636,7 @@ DBusServer::DBusServer(GMainLoop *loop, const DBusConnectionPtr &conn, int durat
     add(this, &DBusServer::detachClient, "Detach");
     add(this, &DBusServer::enableNotifications, "EnableNotifications");
     add(this, &DBusServer::disableNotifications, "DisableNotifications");
+    add(this, &DBusServer::notificationAction, "NotificationAction");
     add(this, &DBusServer::connect, "Connect");
     add(this, &DBusServer::startSession, "StartSession");
     add(this, &DBusServer::startSessionWithFlags, "StartSessionWithFlags");
-- 
1.7.2.2

