>From 9978e870f532cb0787959c32fa4ae8a9e1ffcc17 Mon Sep 17 00:00:00 2001
From: Salvatore Iovene <salvatore.iovene@linux.intel.com>
Date: Mon, 13 Jun 2011 01:27:33 -0700
Subject: [PATCH 1/7] syncevo-dbus-server: notifications system made more generic.

The notifications system has been made template based, and a class
for the libnotify based notifications has been created. A No-op
class has been created too, and stubs for the mlite based notifications.
Notice that at this point the choice of which notifications system
should be used will be made at compile time, based on the availability
of mlite and libnotify.
---
 src/Makefile-gen.am                  |    3 +
 src/NotificationBackendBase.h        |   42 ++++++++++
 src/NotificationBackendLibnotify.cpp |  126 ++++++++++++++++++++++++++++++
 src/NotificationBackendLibnotify.h   |   76 ++++++++++++++++++
 src/NotificationBackendMLite.cpp     |   44 ++++++++++
 src/NotificationBackendMLite.h       |   44 ++++++++++
 src/NotificationBackendNoop.cpp      |   44 ++++++++++
 src/NotificationBackendNoop.h        |   44 ++++++++++
 src/NotificationManager.cpp          |   52 ++++++++++++
 src/NotificationManager.h            |   73 +++++++++++++++++
 src/syncevo-dbus-server.cpp          |  143 ++++------------------------------
 11 files changed, 564 insertions(+), 127 deletions(-)
 create mode 100644 src/NotificationBackendBase.h
 create mode 100644 src/NotificationBackendLibnotify.cpp
 create mode 100644 src/NotificationBackendLibnotify.h
 create mode 100644 src/NotificationBackendMLite.cpp
 create mode 100644 src/NotificationBackendMLite.h
 create mode 100644 src/NotificationBackendNoop.cpp
 create mode 100644 src/NotificationBackendNoop.h
 create mode 100644 src/NotificationManager.cpp
 create mode 100644 src/NotificationManager.h

diff --git a/src/Makefile-gen.am b/src/Makefile-gen.am
index bf8cd26..3f91ba5 100644
--- a/src/Makefile-gen.am
+++ b/src/Makefile-gen.am
@@ -183,6 +183,9 @@ distclean-local:
 
 if COND_DBUS
 syncevo_dbus_server_SOURCES = \
+	NotificationBackendNoop.cpp \
+	NotificationBackendLibnotify.cpp \
+	NotificationBackendMLite.cpp \
 	syncevo-dbus-server.cpp \
 	$(CORE_SOURCES)
 if ENABLE_UNIT_TESTS
diff --git a/src/NotificationBackendBase.h b/src/NotificationBackendBase.h
new file mode 100644
index 0000000..33a7c39
--- /dev/null
+++ b/src/NotificationBackendBase.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#ifndef __NOTIFICATION_BACKEND_BASE_H
+#define __NOTIFICATION_BACKEND_BASE_H
+
+#include "syncevo/declarations.h"
+
+#include <string>
+
+SE_BEGIN_CXX
+
+class NotificationBackendBase {
+    public:
+        /** Performs the initialization. */
+        virtual bool init() = 0;
+
+        /** Publishes the notification. */
+        virtual void publish(const std::string& summary,
+                             const std::string& body,
+                             const std::string& viewParams = 0) = 0;
+};
+
+SE_END_CXX
+
+#endif
diff --git a/src/NotificationBackendLibnotify.cpp b/src/NotificationBackendLibnotify.cpp
new file mode 100644
index 0000000..5721625
--- /dev/null
+++ b/src/NotificationBackendLibnotify.cpp
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAS_NOTIFY
+
+#include "NotificationBackendLibnotify.h"
+
+#include <stdlib.h>
+#include <glib/gi18n.h>
+#include <boost/algorithm/string/predicate.hpp>
+
+SE_BEGIN_CXX
+
+NotificationBackendLibnotify::NotificationBackendLibnotify()
+    : m_initialized(false),
+      m_acceptsActions(false),
+      m_notification(false)
+{
+}
+
+NotificationBackendLibnotify::~NotificationBackendLibnotify()
+{
+}
+
+void NotificationBackendLibnotify::notifyAction(
+    NotifyNotification *notify,
+    gchar *action, gpointer userData)
+{
+    if(boost::iequals(action, "view")) {
+        pid_t pid;
+        if((pid = fork()) == 0) {
+            // search sync-ui from $PATH
+            if(execlp("sync-ui", "sync-ui", (const char*)0) < 0) {
+                exit(0);
+            }
+        }
+    }
+    // if dismissed, ignore.
+}
+
+bool NotificationBackendLibnotify::init()
+{
+    bindtextdomain (GETTEXT_PACKAGE, SYNCEVOLUTION_LOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    m_initialized = notify_init("SyncEvolution");
+    if(m_initialized) {
+        GList *list = notify_get_server_caps();
+        if(list) {
+            for(; list != NULL; list = list->next) {
+                if(boost::iequals((char *)list->data, "actions")) {
+                    m_acceptsActions = true;
+                }
+            }
+        }
+        return true;
+    }
+
+    return false;
+}
+
+void NotificationBackendLibnotify::publish(
+    const std::string& summary, const std::string& body,
+             const std::string& viewParams)
+{
+    if(!m_initialized)
+        return;
+
+    if(m_notification) {
+        notify_notification_clear_actions(m_notification);
+        notify_notification_close(m_notification, NULL);
+    }
+#ifndef NOTIFY_CHECK_VERSION
+# define NOTIFY_CHECK_VERSION(_x,_y,_z) 0
+#endif
+#if !NOTIFY_CHECK_VERSION(0,7,0)
+    m_notification = notify_notification_new(summary.c_str(), body.c_str(), NULL, NULL);
+#else
+    m_notification = notify_notification_new(summary.c_str(), body.c_str(), NULL);
+#endif
+    //if actions are not supported, don't add actions
+    //An example is Ubuntu Notify OSD. It uses an alert box
+    //instead of a bubble when a notification is appended with actions.
+    //the alert box won't be closed until user inputs.
+    //so disable it in case of no support of actions
+    if(m_acceptsActions) {
+        notify_notification_add_action(m_notification, "view",
+                                       _("View"), notifyAction,
+                                       (gpointer)viewParams.c_str(),
+                                       NULL);
+        // Use "default" as ID because that is what mutter-moblin
+        // recognizes: it then skips the action instead of adding it
+        // in addition to its own "Dismiss" button (always added).
+        notify_notification_add_action(m_notification, "default",
+                                       _("Dismiss"), notifyAction,
+                                       (gpointer)viewParams.c_str(),
+                                       NULL);
+    }
+    notify_notification_show(m_notification, NULL);
+}
+
+SE_END_CXX
+
+#endif // HAS_NOTIFY
+
diff --git a/src/NotificationBackendLibnotify.h b/src/NotificationBackendLibnotify.h
new file mode 100644
index 0000000..47411b8
--- /dev/null
+++ b/src/NotificationBackendLibnotify.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#ifndef __NOTIFICATION_BACKEND_LIBNOTIFY_H
+#define __NOTIFICATION_BACKEND_LIBNOTIFY_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if HAS_NOTIFY
+
+#include "syncevo/declarations.h"
+#include "NotificationBackendBase.h"
+
+#include <libnotify/notify.h>
+
+SE_BEGIN_CXX
+
+class NotificationBackendLibnotify : public NotificationBackendBase {
+    public:
+        NotificationBackendLibnotify();
+        virtual ~NotificationBackendLibnotify();
+
+        /**
+         * Callback for the notification action.
+         */
+        static void notifyAction(NotifyNotification *notify,
+                                 gchar *action, gpointer userData);
+        /** Performs the initialization. */
+        bool init();
+
+        /** Publishes the notification. */
+        void publish(const std::string& summary, const std::string& body,
+                     const std::string& viewParams = 0);
+
+    private:
+        /**
+         * Flag to indicate whether libnotify has been successfully
+         * initialized.
+         */
+        bool m_initialized;
+
+        /**
+         * Flag to indicate whether libnotify accepts actions.
+         */
+        bool m_acceptsActions;
+
+        /**
+         * The current notification.
+         */
+        NotifyNotification *m_notification;
+};
+
+SE_END_CXX
+
+#endif // HAS_NOTIFY
+
+#endif // __NOTIFICATION_BACKEND_LIBNOTIFY_H
+
diff --git a/src/NotificationBackendMLite.cpp b/src/NotificationBackendMLite.cpp
new file mode 100644
index 0000000..f0e917b
--- /dev/null
+++ b/src/NotificationBackendMLite.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#include "NotificationBackendMLite.h"
+
+SE_BEGIN_CXX
+
+NotificationBackendMLite::NotificationBackendMLite()
+{
+}
+
+NotificationBackendMLite::~NotificationBackendMLite()
+{
+}
+
+bool NotificationBackendMLite::init()
+{
+    return true;
+}
+
+void NotificationBackendMLite::publish(
+    const std::string& summary, const std::string& body,
+    const std::string& viewParams)
+{
+}
+
+SE_END_CXX
+
diff --git a/src/NotificationBackendMLite.h b/src/NotificationBackendMLite.h
new file mode 100644
index 0000000..317ea68
--- /dev/null
+++ b/src/NotificationBackendMLite.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#ifndef __NOTIFICATION_BACKEND_MLITE_H
+#define __NOTIFICATION_BACKEND_MLITE_H
+
+#include "syncevo/declarations.h"
+#include "NotificationBackendBase.h"
+
+SE_BEGIN_CXX
+
+class NotificationBackendMLite : public NotificationBackendBase {
+    public:
+        NotificationBackendMLite();
+        virtual ~NotificationBackendMLite();
+
+        /** Performs the initialization. */
+        bool init();
+
+        /** Publishes the notification. */
+        void publish(const std::string& summary, const std::string& body,
+                     const std::string& viewParams = 0);
+};
+
+SE_END_CXX
+
+#endif // __NOTIFICATION_BACKEND_MLITE_H
+
diff --git a/src/NotificationBackendNoop.cpp b/src/NotificationBackendNoop.cpp
new file mode 100644
index 0000000..8532106
--- /dev/null
+++ b/src/NotificationBackendNoop.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#include "NotificationBackendNoop.h"
+
+SE_BEGIN_CXX
+
+NotificationBackendNoop::NotificationBackendNoop()
+{
+}
+
+NotificationBackendNoop::~NotificationBackendNoop()
+{
+}
+
+bool NotificationBackendNoop::init()
+{
+    return true;
+}
+
+void NotificationBackendNoop::publish(
+    const std::string& summary, const std::string& body,
+    const std::string& viewParams)
+{
+}
+
+SE_END_CXX
+
diff --git a/src/NotificationBackendNoop.h b/src/NotificationBackendNoop.h
new file mode 100644
index 0000000..38ede1f
--- /dev/null
+++ b/src/NotificationBackendNoop.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#ifndef __NOTIFICATION_BACKEND_NOOP_H
+#define __NOTIFICATION_BACKEND_NOOP_H
+
+#include "syncevo/declarations.h"
+#include "NotificationBackendBase.h"
+
+SE_BEGIN_CXX
+
+class NotificationBackendNoop : public NotificationBackendBase {
+    public:
+        NotificationBackendNoop();
+        virtual ~NotificationBackendNoop();
+
+        /** Performs the initialization. */
+        bool init();
+
+        /** Publishes the notification. */
+        void publish(const std::string& summary, const std::string& body,
+                     const std::string& viewParams = 0);
+};
+
+SE_END_CXX
+
+#endif // __NOTIFICATION_BACKEND_NOOP_H
+
diff --git a/src/NotificationManager.cpp b/src/NotificationManager.cpp
new file mode 100644
index 0000000..921dc6b
--- /dev/null
+++ b/src/NotificationManager.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#include "NotificationManager.h"
+#include "syncevo/declarations.h"
+
+#include <string>
+
+SE_BEGIN_CXX
+
+template <class T>
+NotificationManager<T>::NotificationManager()
+{
+}
+
+template <class T>
+NotificationManager<T>::~NotificationManager()
+{
+}
+
+template <class T>
+bool NotificationManager<T>::init()
+{
+    return m_backend->init();
+}
+
+template <class T>
+void NotificationManager<T>::publish(const std::string& summary,
+                                     const std::string& body,
+                                     const std::string& viewParams)
+{
+    m_backend->publish(summary, body, viewParams);
+}
+
+SE_END_CXX
+
diff --git a/src/NotificationManager.h b/src/NotificationManager.h
new file mode 100644
index 0000000..f2b4df9
--- /dev/null
+++ b/src/NotificationManager.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#ifndef __NOTIFICATION_MANAGER_H
+#define __NOTIFICATION_MANAGER_H
+
+#include "syncevo/declarations.h"
+
+#include <string>
+
+SE_BEGIN_CXX
+
+template <class T>
+class NotificationManager {
+    public:
+        NotificationManager();
+        virtual ~NotificationManager();
+
+        /** Initializes the backend. */
+        bool init();
+
+        /** Publishes the notification through the backend. */
+        void publish(const std::string& summary, const std::string& body,
+                     const std::string& viewParam = 0);
+
+    private:
+        T m_backend;
+};
+
+template <class T>
+NotificationManager<T>::NotificationManager()
+{
+}
+
+template <class T>
+NotificationManager<T>::~NotificationManager()
+{
+}
+
+template <class T>
+bool NotificationManager<T>::init()
+{
+    return m_backend.init();
+}
+
+template <class T>
+void NotificationManager<T>::publish(const std::string& summary,
+                                     const std::string& body,
+                                     const std::string& viewParams)
+{
+    m_backend.publish(summary, body, viewParams);
+}
+
+SE_END_CXX
+
+#endif
+
diff --git a/src/syncevo-dbus-server.cpp b/src/syncevo-dbus-server.cpp
index 3fe370e..21dac37 100644
--- a/src/syncevo-dbus-server.cpp
+++ b/src/syncevo-dbus-server.cpp
@@ -92,9 +92,8 @@ extern "C" {
 #include <kwallet.h>
 #endif
 
-#ifdef HAS_NOTIFY
-#include <libnotify/notify.h>
-#endif
+#include "NotificationBackendLibnotify.h"
+#include "NotificationManager.h"
 
 using namespace GDBusCXX;
 using namespace SyncEvo;
@@ -710,6 +709,7 @@ class AutoSyncManager : public SessionListener
 {
     DBusServer &m_server;
 
+    public:
     /**
      * A single task for automatic sync.
      * Each task maintain one task for only one sync URL, which never combines
@@ -733,7 +733,8 @@ class AutoSyncManager : public SessionListener
 
         AutoSyncTask(const string &peer, unsigned int delay, const string &url)
             : m_peer(peer), m_delay(delay), m_url(url)
-        {}
+        {
+        }
 
         /** compare whether two tasks are the same. May refine it later with more information */
         bool operator==(const AutoSyncTask &right) const
@@ -779,40 +780,6 @@ class AutoSyncManager : public SessionListener
         void scheduleTaskList();
     };
 
-#ifdef HAS_NOTIFY
-    /**
-     * This class is to send notifications to notification server.
-     * Notifications are sent via 'send'. Once a new noficication is
-     * to be sent, the old notification will be closed and a new one
-     * is created for the new requirement.
-     */
-    class Notification
-    {
-    public:
-        Notification(); 
-        ~Notification();
-
-        /** callback of click button(actions) of notification */
-        static void notifyAction(NotifyNotification *notify, gchar *action, gpointer userData);
-
-        /**
-         * send a notification in the notification server
-         * Action for 'view' may pop up a sync-ui, but needs some
-         * parameters. 'viewParams' is the params used by sync-ui.
-         */
-        void send(const char *summary, const char *body, const char *viewParams = NULL);
-    private:
-        /** flag to indicate whether libnotify is initalized successfully */
-        bool m_init;
-
-        /** flag to indicate whether libnotify accepts actions */
-        bool m_actions;
-
-        /** the current notification */
-        NotifyNotification *m_notification;
-    };
-#endif
-
     /** init a config and set up auto sync task for it */
     void initConfig(const string &configName);
 
@@ -843,9 +810,13 @@ class AutoSyncManager : public SessionListener
     /** the current sync of session is successfully started */
     bool m_syncSuccessStart;
 
-#ifdef HAS_NOTIFY
     /** used to send notifications */
-    Notification m_notify;
+#if(defined(HAS_NOTIFY))
+    NotificationManager<NotificationBackendLibnotify> m_notify; 
+#elif(defined(HAS_MLITE))
+    NotificationManager<NotificationBackendMLite> m_notify;
+#else
+    NotificationManager<NotificationBackendNoop> m_notify;
 #endif
 
     /** 
@@ -6445,6 +6416,8 @@ void AutoSyncManager::init()
     BOOST_FOREACH(const SyncConfig::ConfigList::value_type &server, list) {
         initConfig(server.first);
     }
+
+    m_notify.init();
 }
 
 void AutoSyncManager::initConfig(const string &configName)
@@ -6648,20 +6621,17 @@ void AutoSyncManager::syncSuccessStart()
 {
     m_syncSuccessStart = true;
     SE_LOG_INFO(NULL, NULL,"Automatic sync for '%s' has been successfully started.\n", m_activeTask->m_peer.c_str());
-#ifdef HAS_NOTIFY
     if (m_server.notificationsEnabled()) {
         string summary = StringPrintf(_("%s is syncing"), m_activeTask->m_peer.c_str());
         string body = StringPrintf(_("We have just started to sync your computer with the %s sync service."), m_activeTask->m_peer.c_str());
         //TODO: set config information for 'sync-ui'
-        m_notify.send(summary.c_str(), body.c_str());
+        m_notify.publish(summary, body);
     }
-#endif
 }
 
 void AutoSyncManager::syncDone(SyncMLStatus status)
 {
     SE_LOG_INFO(NULL, NULL,"Automatic sync for '%s' has been done.\n", m_activeTask->m_peer.c_str());
-#ifdef HAS_NOTIFY
     if (m_server.notificationsEnabled()) {
         // send a notification to notification server
         string summary, body;
@@ -6670,101 +6640,20 @@ void AutoSyncManager::syncDone(SyncMLStatus status)
             summary = StringPrintf(_("%s sync complete"), m_activeTask->m_peer.c_str());
             body = StringPrintf(_("We have just finished syncing your computer with the %s sync service."), m_activeTask->m_peer.c_str());
             //TODO: set config information for 'sync-ui'
-            m_notify.send(summary.c_str(), body.c_str());
+            m_notify.publish(summary, body);
         } else if(m_syncSuccessStart || (!m_syncSuccessStart && status == STATUS_FATAL)) {
             //if sync is successfully started and has errors, or not started successful with a fatal problem
             summary = StringPrintf(_("Sync problem."));
             body = StringPrintf(_("Sorry, there's a problem with your sync that you need to attend to."));
             //TODO: set config information for 'sync-ui'
-            m_notify.send(summary.c_str(), body.c_str());
+            m_notify.publish(summary, body);
         }
     }
-#endif
     m_session.reset();
     m_activeTask.reset();
     m_syncSuccessStart = false;
 }
 
-#ifdef HAS_NOTIFY
-AutoSyncManager::Notification::Notification()
-{
-    bindtextdomain (GETTEXT_PACKAGE, SYNCEVOLUTION_LOCALEDIR);
-    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-    textdomain (GETTEXT_PACKAGE);
-    m_init = notify_init("SyncEvolution");
-    m_actions = false;
-    m_notification = NULL;
-    // check whether 'actions' are supported by notification server 
-    if(m_init) {
-        GList *list = notify_get_server_caps();
-        if(list) {
-            for(; list != NULL; list = list->next) {
-                if(boost::iequals((char *)list->data, "actions")) {
-                    m_actions = true;
-                }
-            }
-        }
-    }
-}
-
-AutoSyncManager::Notification::~Notification()
-{
-    if(m_init) {
-        notify_uninit();
-    }
-}
-
-void AutoSyncManager::Notification::notifyAction(NotifyNotification *notify,
-                                                 gchar *action,
-                                                 gpointer userData)
-{
-    if(boost::iequals("view", action)) {
-        pid_t pid;
-        if((pid = fork()) == 0) {
-            //search sync-ui from $PATH
-            if(execlp("sync-ui", "sync-ui", (const char*)0) < 0) {
-                exit(0);
-            }
-        }
-    } 
-    //if dismiss, ignore
-}
-
-void AutoSyncManager::Notification::send(const char *summary,
-                                         const char *body,
-                                         const char *viewParams)
-{
-    if(!m_init)
-        return;
-
-    if(m_notification) {
-        notify_notification_clear_actions(m_notification);
-        notify_notification_close(m_notification, NULL);
-    }
-#ifndef NOTIFY_CHECK_VERSION
-# define NOTIFY_CHECK_VERSION(_x,_y,_z) 0
-#endif
-#if !NOTIFY_CHECK_VERSION(0,7,0)
-    m_notification = notify_notification_new(summary, body, NULL, NULL);
-#else
-    m_notification = notify_notification_new(summary, body, NULL);
-#endif
-    //if actions are not supported, don't add actions
-    //An example is Ubuntu Notify OSD. It uses an alert box
-    //instead of a bubble when a notification is appended with actions.
-    //the alert box won't be closed until user inputs.
-    //so disable it in case of no support of actions
-    if(m_actions) {
-        notify_notification_add_action(m_notification, "view", _("View"), notifyAction, (gpointer)viewParams, NULL);
-        // Use "default" as ID because that is what mutter-moblin
-        // recognizes: it then skips the action instead of adding it
-        // in addition to its own "Dismiss" button (always added).
-        notify_notification_add_action(m_notification, "default", _("Dismiss"), notifyAction, (gpointer)viewParams, NULL);
-    }
-    notify_notification_show(m_notification, NULL);
-}
-#endif
-
 void AutoSyncManager::AutoSyncTaskList::createTimeoutSource()
 {
     //if interval is 0, only run auto sync when changes are detected.
-- 
1.7.2.2

