[ekiga] Notifications: Use GLIB notifications.



commit 9519519496f70addad384ada4cf95cb04eff476f
Author: Damien Sandras <dsandras seconix com>
Date:   Sat Oct 31 18:42:27 2015 +0100

    Notifications: Use GLIB notifications.
    
    We got rid of LIBNotify.

 configure.ac                                       |   31 +--
 lib/Makefile.am                                    |    9 +
 .../components/glib-notify/glib-notify-main.cpp    |  245 ++++++++++++++++
 .../components/glib-notify/glib-notify-main.h      |   54 ++++
 lib/engine/engine.cpp                              |    3 +
 plugins/Makefile.am                                |    4 -
 plugins/libnotify/Makefile.am                      |   18 --
 plugins/libnotify/libnotify-main.cpp               |  307 --------------------
 8 files changed, 313 insertions(+), 358 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5d34e85..d4fd0b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -138,7 +138,7 @@ if test "x${gm_platform}" = "xmingw" ; then
 else
    PKG_CHECK_MODULES([GTK], [gtk+-3.0 >= 3.12.0 gnome-icon-theme >= 3.0.0])
 fi
-PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.24.0 gmodule-2.0 gobject-2.0 gthread-2.0 gio-2.0])
+PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.40.0 gmodule-2.0 gobject-2.0 gthread-2.0 gio-2.0])
 
 PKG_CHECK_MODULES([GTK_SIDEBAR], [gtk+-3.0 >=  3.16.0], [have_sidebar="yes"], [have_sidebar="no"])
 if test "x${have_sidebar}" = "xyes" ; then
@@ -249,31 +249,6 @@ AM_CONDITIONAL(HAVE_EDS, test "x$found_eds" = "xyes")
 
 
 dnl ###############################
-dnl   NOTIFY support
-dnl ###############################
-NOTIFY="disabled"
-
-if test "x${gm_platform}" != "xmingw" ; then
-  AC_ARG_ENABLE(notify, AS_HELP_STRING([--enable-notify],[enable libnotify support (default is enabled)]),
-[if test "x$enableval" = "xyes"; then
-  enable_notify=yes
-fi],enable_notify=yes)
-
-  if test "x$enable_notify" = "xyes"; then
-    PKG_CHECK_MODULES([NOTIFY], [libnotify], [found_notify=yes], foo=bar)
-    if test "x$found_notify" = "xyes"; then
-      AC_SUBST(NOTIFY_CFLAGS)
-      AC_SUBST(NOTIFY_LIBS)
-      NOTIFY="enabled"
-      AC_DEFINE(HAVE_NOTIFY,1,[NOTIFY support])
-    fi
-  fi
-fi
-
-AM_CONDITIONAL(HAVE_NOTIFY, test "x$found_notify" = "xyes")
-
-
-dnl ###############################
 dnl   LDAP support
 dnl ###############################
 LDAP="disabled"
@@ -750,7 +725,7 @@ AC_CONFIG_FILES([Makefile
 Doxyfile
 org.gnome.ekiga.gschema.xml.in
 ekiga.convert
-ekiga.desktop.in
+org.gnome.ekiga.desktop.in
 lib/Makefile
 po/Makefile.in
 man/Makefile
@@ -765,7 +740,6 @@ plugins/gstreamer/Makefile
 plugins/kab/Makefile
 plugins/kde/Makefile
 plugins/ldap/Makefile
-plugins/libnotify/Makefile
 plugins/loudmouth/Makefile
 plugins/resource-list/Makefile
 plugins/xcap/Makefile
@@ -785,7 +759,6 @@ echo ""
 if test "x${gm_platform}" != "xmingw" ; then
 echo "                     GDU support  :  $GDU"
 echo "   Evolution-Data-Server support  :  $EDS"
-echo "                  NOTIFY support  :  $NOTIFY"
 echo ""
 echo "             Video4Linux support  :  $VIDEO4LINUX"
 fi
diff --git a/lib/Makefile.am b/lib/Makefile.am
index d46b2f4..9b056cd 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -36,6 +36,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/lib/engine/components/call-history \
        -I$(top_srcdir)/lib/engine/components/echo \
        -I$(top_srcdir)/lib/engine/components/foe-list \
+       -I$(top_srcdir)/lib/engine/components/glib-notify \
        -I$(top_srcdir)/lib/engine/components/gmconf-personal-details \
        -I$(top_srcdir)/lib/engine/components/hal-dbus \
        -I$(top_srcdir)/lib/engine/components/hal-gudev \
@@ -414,6 +415,14 @@ libekiga_la_SOURCES += \
        engine/components/call-history/history-main.cpp
 
 ##
+# Sources of the glib notify component
+##
+
+libekiga_la_SOURCES += \
+       engine/components/glib-notify/glib-notify-main.cpp
+
+
+##
 # Sources of the gmconf personal details component
 ##
 
diff --git a/lib/engine/components/glib-notify/glib-notify-main.cpp 
b/lib/engine/components/glib-notify/glib-notify-main.cpp
new file mode 100644
index 0000000..9fc56e4
--- /dev/null
+++ b/lib/engine/components/glib-notify/glib-notify-main.cpp
@@ -0,0 +1,245 @@
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         glib-notify-main.cpp  -  description
+ *                         ------------------------------------
+ *   begin                : written in 2009 by Damien Sandras
+ *   copyright            : (c) 2009 by Julien Puydt
+ *   description          : code to push user notifications to the desktop
+ *
+ */
+
+#include <map>
+#include <boost/smart_ptr.hpp>
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <glib/gi18n.h>
+
+#include <sstream>
+
+#include "config.h"
+
+#include "kickstart.h"
+#include "notification-core.h"
+#include "call-core.h"
+#include "scoped-connections.h"
+
+
+class GNotify:
+  public Ekiga::Service
+{
+public:
+
+  GNotify (Ekiga::ServiceCore& core);
+
+  ~GNotify ();
+
+  const std::string get_name () const
+  { return "libnotify"; }
+
+  const std::string get_description () const
+  { return "\tService pushing user notifications to the desktop"; }
+
+private:
+
+  Ekiga::scoped_connections connections;
+
+  void on_notification_added (boost::shared_ptr<Ekiga::Notification> notif);
+  void on_notification_removed (boost::shared_ptr<Ekiga::Notification> notif);
+  void on_call_notification (boost::shared_ptr<Ekiga::Call> call);
+  void on_call_notification_closed ();
+
+  typedef std::map<boost::shared_ptr<Ekiga::Notification>, std::pair<boost::signals2::connection, 
boost::shared_ptr<GNotification> > > container_type;
+  container_type live;
+};
+
+
+static void
+g_notification_action_activated_cb (GSimpleAction *action,
+                                    G_GNUC_UNUSED GVariant *variant,
+                                    gpointer data)
+{
+  Ekiga::Notification *notif = (Ekiga::Notification *) data;
+  gchar *name = NULL;
+
+  g_object_get (action, "name", &name, NULL);
+
+  notif->action_trigger ();
+  notif->removed ();
+
+  g_action_map_remove_action (G_ACTION_MAP (g_application_get_default ()), name);
+  g_free (name);
+}
+
+
+struct GNOTIFYSpark: public Ekiga::Spark
+{
+  GNOTIFYSpark (): result(false)
+  {}
+
+  bool try_initialize_more (Ekiga::ServiceCore& core,
+                           int* /*argc*/,
+                           char** /*argv*/[])
+  {
+    Ekiga::ServicePtr service = core.get ("GNOTIFY");
+
+    if (!service) {
+      core.add (Ekiga::ServicePtr (new GNotify (core)));
+      result = true;
+    }
+
+    return result;
+  }
+
+  Ekiga::Spark::state get_state () const
+  { return result?FULL:BLANK; }
+
+  const std::string get_name () const
+  { return "GNOTIFY"; }
+
+  bool result;
+};
+
+
+void
+gnotify_init (Ekiga::KickStart& kickstart)
+{
+  boost::shared_ptr<Ekiga::Spark> spark(new GNOTIFYSpark);
+  kickstart.add_spark (spark);
+}
+
+
+GNotify::GNotify (Ekiga::ServiceCore& core)
+{
+  boost::shared_ptr<Ekiga::NotificationCore> notification_core = core.get<Ekiga::NotificationCore> 
("notification-core");
+  boost::shared_ptr<Ekiga::CallCore> call_core = core.get<Ekiga::CallCore> ("call-core");
+
+  /* Notifications coming from various components */
+  connections.add (notification_core->notification_added.connect (boost::bind 
(&GNotify::on_notification_added, this, _1)));
+
+  /* Specific notifications */
+  connections.add (call_core->setup_call.connect (boost::bind (&GNotify::on_call_notification, this, _1)));
+}
+
+
+GNotify::~GNotify ()
+{
+}
+
+
+void
+GNotify::on_notification_added (boost::shared_ptr<Ekiga::Notification> notification)
+{
+  GNotification* notif = g_notification_new (notification->get_title ().c_str ());
+  GSimpleAction *action = NULL;
+
+  g_notification_set_body (notif, notification->get_body ().c_str ());
+
+  if (notification->get_level () == Ekiga::Notification::Error)
+    g_notification_set_priority (notif, G_NOTIFICATION_PRIORITY_HIGH);
+
+  if (!notification->get_action_name ().empty ()) {
+
+    g_notification_set_priority (notif, G_NOTIFICATION_PRIORITY_URGENT);
+    std::ostringstream id;
+    std::ostringstream action_id;
+
+    id << notification.get ();
+    action = g_simple_action_new (id.str ().c_str (), NULL); // We use a unique ID and not
+                                                             // a global action as the action
+                                                             // will disappear as soon as the notification
+                                                             // disappears.
+    g_action_map_add_action (G_ACTION_MAP (g_application_get_default ()),
+                             G_ACTION (action));
+    g_signal_connect (action, "activate",
+                      G_CALLBACK (g_notification_action_activated_cb),
+                      (gpointer) notification.get ());
+    action_id << "app." << notification.get ();
+    g_notification_add_button (notif,
+                               notification->get_action_name ().c_str (),
+                               action_id.str ().c_str ());
+    g_object_unref (action);
+  }
+
+  boost::signals2::connection conn =
+    notification->removed.connect (boost::bind (&GNotify::on_notification_removed,
+                                                this, notification));
+  live[notification] = std::pair<boost::signals2::connection, boost::shared_ptr<GNotification> > (conn, 
boost::shared_ptr<GNotification> (notif, g_object_unref));
+  g_application_send_notification (g_application_get_default (), NULL, notif);
+}
+
+void
+GNotify::on_notification_removed (boost::shared_ptr<Ekiga::Notification> notification)
+{
+  container_type::iterator iter = live.find (notification);
+
+  if (iter != live.end ()) {
+    iter->second.first.disconnect ();
+    live.erase (iter);
+  }
+}
+
+
+void
+GNotify::on_call_notification_closed ()
+{
+  g_application_withdraw_notification (g_application_get_default (), "ekiga-call-notif");
+}
+
+
+void
+GNotify::on_call_notification (boost::shared_ptr<Ekiga::Call> call)
+{
+  GNotification *notif = NULL;
+
+  if (call->is_outgoing ())
+    return; // Ignore
+
+  gchar *title = g_strdup_printf (_("Incoming call from %s"), call->get_remote_party_name ().c_str ());
+  gchar *body = g_strdup_printf (_("Remote URI: %s"), call->get_remote_uri ().c_str ());
+
+  notif = g_notification_new (title);
+  g_notification_set_body (notif, body);
+
+  g_notification_add_button (notif, _("Reject"), "app.reject");
+  g_notification_add_button (notif, _("Answer"), "app.answer");
+
+  g_notification_set_priority (notif, G_NOTIFICATION_PRIORITY_URGENT);
+
+  connections.add (call->established.connect (boost::bind (&GNotify::on_call_notification_closed, this)));
+  connections.add (call->missed.connect (boost::bind (&GNotify::on_call_notification_closed, this)));
+  connections.add (call->cleared.connect (boost::bind (&GNotify::on_call_notification_closed, this)));
+
+  g_application_send_notification (g_application_get_default (), "ekiga-call-notif", notif);
+
+  g_free (title);
+  g_free (body);
+
+  g_object_unref (notif);
+}
diff --git a/lib/engine/components/glib-notify/glib-notify-main.h 
b/lib/engine/components/glib-notify/glib-notify-main.h
new file mode 100644
index 0000000..6a2ab6b
--- /dev/null
+++ b/lib/engine/components/glib-notify/glib-notify-main.h
@@ -0,0 +1,54 @@
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         glib-notify-main.h  -  description
+ *                         ----------------------------------
+ *   begin                : written in 2015 by Damien Sandras
+ *   copyright            : (c) 2015 Damien Sandras
+ *   description          : code to hook glib notifications to the main program
+ *
+ */
+
+#ifndef __GNOTIFY_MAIN_H__
+#define __GNOTIFY_MAIN_H__
+
+#include "kickstart.h"
+
+/**
+ * @addtogroup contacts
+ * @{
+ */
+
+void gnotify_init (Ekiga::KickStart& kickstart);
+
+/**
+ * @}
+ */
+
+#endif
+
diff --git a/lib/engine/engine.cpp b/lib/engine/engine.cpp
index d33fe69..3fc5a65 100644
--- a/lib/engine/engine.cpp
+++ b/lib/engine/engine.cpp
@@ -55,6 +55,7 @@
 #include "audiooutput-core.h"
 #include "hal-core.h"
 #include "history-main.h"
+#include "glib-notify-main.h"
 #include "gtk-core-main.h"
 #include "gmconf-personal-details.h"
 
@@ -148,6 +149,8 @@ engine_init (Ekiga::ServiceCore& core,
   audioinput_ptlib_init (kickstart);
   audiooutput_ptlib_init (kickstart);
 
+  gnotify_init (kickstart);
+
 #ifdef HAVE_GUDEV
   hal_gudev_init (kickstart);
 #endif
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 99cd1a3..1b421b9 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -26,10 +26,6 @@ if HAVE_LOUDMOUTH
 LOUDMOUTH_DIR = loudmouth
 endif
 
-if HAVE_NOTIFY
-LIBNOTIFY_DIR = libnotify
-endif
-
 if HAVE_XCAP
 XCAP_DIRS = xcap resource-list
 endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]