>From 011c750c6c91c735fd2f0bfa52d141f884af92bc Mon Sep 17 00:00:00 2001
From: Salvatore Iovene <salvatore.iovene@linux.intel.com>
Date: Mon, 13 Jun 2011 04:17:07 -0700
Subject: [PATCH 2/7] syncevo-dbus-server: semi-working stub for mlite notifications.

Added mlite dependencies and minimal notification publication code.
---
 configure-pre.in                     |   18 ++++++++++++++++--
 src/Makefile-gen.am                  |    4 ++--
 src/NotificationBackendBase.h        |    2 +-
 src/NotificationBackendLibnotify.cpp |    2 +-
 src/NotificationBackendLibnotify.h   |    2 +-
 src/NotificationBackendMLite.cpp     |    8 ++++++++
 src/NotificationBackendMLite.h       |    2 +-
 src/NotificationBackendNoop.h        |    2 +-
 src/NotificationManager.h            |    2 +-
 src/syncevo-dbus-server.cpp          |    7 ++++---
 10 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/configure-pre.in b/configure-pre.in
index 7400023..65a06b5 100644
--- a/configure-pre.in
+++ b/configure-pre.in
@@ -494,12 +494,24 @@ if test $enable_dbus_service = "yes"; then
     PKG_CHECK_MODULES(LIBNOTIFY, [libnotify gtk+-2.0], HAVE_LIBNOTIFY=yes, HAVE_LIBNOTIFY=no)
     AC_ARG_ENABLE(notify,
                   AS_HELP_STRING([--enable-notify],
-                                 [send notifications for automatic sync events]),
+                                 [send notifications for automatic sync events, using libnotify]),
                   [ test "$enableval" = "no" || test $HAVE_LIBNOTIFY = "yes" || AC_ERROR([required libnotify package not found]) ],
-                  [ test $HAVE_LIBNOTIFY = "yes" || AC_ERROR([required libnotify package not found, use --disable-notify to compile without notifications]) ])
+                  [ test $HAVE_LIBNOTIFY = "yes" || AC_ERROR([required libnotify package not found, use --disable-notify to compile without libnotify based notifications]) ])
     if test $HAVE_LIBNOTIFY = "yes"; then
         AC_DEFINE(HAS_NOTIFY, 1, [define if libnotify could be used in dbus service])
     fi
+
+    # Here we're using QtGui too because mlite fails to depend on it,
+    # despite using QAction.
+    PKG_CHECK_MODULES(MLITE, [mlite QtGui], HAVE_MLITE=yes, HAVE_MLITE=no)
+    AC_ARG_ENABLE(mlite,
+                  AS_HELP_STRING([--enable-mlite],
+                                 [send notifications for automatic sync events, using mlite]),
+                  [ test "$enableval" = "no" || test $HAVE_MLITE = "yes" || AC_ERROR([required mlite package not found]) ],
+                  [ test $HAVE_MLITE = "yes" || AC_ERROR([required mlite package not found, use --disable-mlite to compile without mlite based notifications]) ])
+    if test $HAVE_MLITE = "yes"; then
+        AC_DEFINE(HAS_MLITE, 1, [define if mlite could be used in dbus service])
+    fi
     AC_DEFINE(DBUS_SERVICE, 1, [define if dbus service is enabled])
 fi
 AC_SUBST(DBUS_CFLAGS)
@@ -510,6 +522,8 @@ AC_SUBST(KEYRING_CFLAGS)
 AC_SUBST(KEYRING_LIBS) 
 AC_SUBST(LIBNOTIFY_CFLAGS)
 AC_SUBST(LIBNOTIFY_LIBS)
+AC_SUBST(MLITE_CFLAGS)
+AC_SUBST(MLITE_LIBS)
 AC_SUBST(LIBEXECDIR)
 AC_SUBST(BUTEOSYNCPROFILE_LIBS)
 AC_SUBST(BUTEOSYNCPROFILE_CFLAGS)
diff --git a/src/Makefile-gen.am b/src/Makefile-gen.am
index 3f91ba5..7f1881e 100644
--- a/src/Makefile-gen.am
+++ b/src/Makefile-gen.am
@@ -192,9 +192,9 @@ if ENABLE_UNIT_TESTS
 nodist_syncevo_dbus_server_SOURCES = ../test/test.cpp
 endif
 
-syncevo_dbus_server_LDADD = gdbus/libgdbussyncevo.la $(CORE_LDADD) $(KEYRING_LIBS) $(LIBNOTIFY_LIBS) $(KDE_KWALLET_LIBS) $(DBUS_LIBS)
+syncevo_dbus_server_LDADD = gdbus/libgdbussyncevo.la $(CORE_LDADD) $(KEYRING_LIBS) $(LIBNOTIFY_LIBS) $(MLITE_LIBS) $(KDE_KWALLET_LIBS) $(DBUS_LIBS)
 syncevo_dbus_server_CPPFLAGS = -DHAVE_CONFIG_H -I$(srcdir)/gdbus $(AM_CPPFLAGS) -DSYNCEVOLUTION_LOCALEDIR=\"${SYNCEVOLUTION_LOCALEDIR}\"
-syncevo_dbus_server_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) $(LIBSOUP_CFLAGS) $(KEYRING_CFLAGS) $(LIBNOTIFY_CFLAGS) $(KDE_KWALLET_CFLAGS)
+syncevo_dbus_server_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) $(LIBSOUP_CFLAGS) $(KEYRING_CFLAGS) $(LIBNOTIFY_CFLAGS) $(MLITE_CFLAGS) $(KDE_KWALLET_CFLAGS)
 syncevo_dbus_server_LDFLAGS = $(CORE_LD_FLAGS) $(LIBSOUP_LIBS)
 syncevo_dbus_server_DEPENDENCIES = gdbus/libgdbussyncevo.la $(EXTRA_LTLIBRARIES) $(CORE_DEP) $(SYNTHESIS_DEP)
 endif
diff --git a/src/NotificationBackendBase.h b/src/NotificationBackendBase.h
index 33a7c39..6a25b9e 100644
--- a/src/NotificationBackendBase.h
+++ b/src/NotificationBackendBase.h
@@ -34,7 +34,7 @@ class NotificationBackendBase {
         /** Publishes the notification. */
         virtual void publish(const std::string& summary,
                              const std::string& body,
-                             const std::string& viewParams = 0) = 0;
+                             const std::string& viewParams = std::string()) = 0;
 };
 
 SE_END_CXX
diff --git a/src/NotificationBackendLibnotify.cpp b/src/NotificationBackendLibnotify.cpp
index 5721625..f5f6a8c 100644
--- a/src/NotificationBackendLibnotify.cpp
+++ b/src/NotificationBackendLibnotify.cpp
@@ -82,7 +82,7 @@ bool NotificationBackendLibnotify::init()
 
 void NotificationBackendLibnotify::publish(
     const std::string& summary, const std::string& body,
-             const std::string& viewParams)
+    const std::string& viewParams)
 {
     if(!m_initialized)
         return;
diff --git a/src/NotificationBackendLibnotify.h b/src/NotificationBackendLibnotify.h
index 47411b8..b13e910 100644
--- a/src/NotificationBackendLibnotify.h
+++ b/src/NotificationBackendLibnotify.h
@@ -48,7 +48,7 @@ class NotificationBackendLibnotify : public NotificationBackendBase {
 
         /** Publishes the notification. */
         void publish(const std::string& summary, const std::string& body,
-                     const std::string& viewParams = 0);
+                     const std::string& viewParams = std::string());
 
     private:
         /**
diff --git a/src/NotificationBackendMLite.cpp b/src/NotificationBackendMLite.cpp
index f0e917b..9469719 100644
--- a/src/NotificationBackendMLite.cpp
+++ b/src/NotificationBackendMLite.cpp
@@ -19,6 +19,9 @@
 
 #include "NotificationBackendMLite.h"
 
+#include <mlite/MNotification>
+#include <QString>
+
 SE_BEGIN_CXX
 
 NotificationBackendMLite::NotificationBackendMLite()
@@ -38,6 +41,11 @@ 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();
 }
 
 SE_END_CXX
diff --git a/src/NotificationBackendMLite.h b/src/NotificationBackendMLite.h
index 317ea68..15b0f83 100644
--- a/src/NotificationBackendMLite.h
+++ b/src/NotificationBackendMLite.h
@@ -35,7 +35,7 @@ class NotificationBackendMLite : public NotificationBackendBase {
 
         /** Publishes the notification. */
         void publish(const std::string& summary, const std::string& body,
-                     const std::string& viewParams = 0);
+                     const std::string& viewParams = std::string());
 };
 
 SE_END_CXX
diff --git a/src/NotificationBackendNoop.h b/src/NotificationBackendNoop.h
index 38ede1f..d385b84 100644
--- a/src/NotificationBackendNoop.h
+++ b/src/NotificationBackendNoop.h
@@ -35,7 +35,7 @@ class NotificationBackendNoop : public NotificationBackendBase {
 
         /** Publishes the notification. */
         void publish(const std::string& summary, const std::string& body,
-                     const std::string& viewParams = 0);
+                     const std::string& viewParams = std::string());
 };
 
 SE_END_CXX
diff --git a/src/NotificationManager.h b/src/NotificationManager.h
index f2b4df9..659f11a 100644
--- a/src/NotificationManager.h
+++ b/src/NotificationManager.h
@@ -37,7 +37,7 @@ class NotificationManager {
 
         /** Publishes the notification through the backend. */
         void publish(const std::string& summary, const std::string& body,
-                     const std::string& viewParam = 0);
+                     const std::string& viewParam = std::string());
 
     private:
         T m_backend;
diff --git a/src/syncevo-dbus-server.cpp b/src/syncevo-dbus-server.cpp
index 21dac37..496f942 100644
--- a/src/syncevo-dbus-server.cpp
+++ b/src/syncevo-dbus-server.cpp
@@ -92,6 +92,7 @@ extern "C" {
 #include <kwallet.h>
 #endif
 
+#include "NotificationBackendMLite.h"
 #include "NotificationBackendLibnotify.h"
 #include "NotificationManager.h"
 
@@ -811,10 +812,10 @@ class AutoSyncManager : public SessionListener
     bool m_syncSuccessStart;
 
     /** used to send notifications */
-#if(defined(HAS_NOTIFY))
-    NotificationManager<NotificationBackendLibnotify> m_notify; 
-#elif(defined(HAS_MLITE))
+#if(defined(HAS_MLITE))
     NotificationManager<NotificationBackendMLite> m_notify;
+#elif(defined(HAS_LIBNOTIFY))
+    NotificationManager<NotificationBackendLibnotify> m_notify; 
 #else
     NotificationManager<NotificationBackendNoop> m_notify;
 #endif
-- 
1.7.2.2

