[ekiga] Libnotify: Moved incoming call notifications to the engine.



commit 224a9664eba88a034516694800c5ed1406d9a0a7
Author: Damien Sandras <dsandras beip be>
Date:   Tue May 1 13:26:11 2012 +0200

    Libnotify: Moved incoming call notifications to the engine.
    
    We have a nice libnotify component displaying notifications coming from
    various parts of the engine core.
    
    Incoming call notifications require a bit more knowledge of what happens
    with the call and need to be able to act on it. Nevertheless, the engine
    libnotify component is the right place for this.

 lib/engine/components/libnotify/libnotify-main.cpp |   94 +++++++++++++++++--
 src/gui/notify.cpp                                 |   98 --------------------
 2 files changed, 84 insertions(+), 108 deletions(-)
---
diff --git a/lib/engine/components/libnotify/libnotify-main.cpp b/lib/engine/components/libnotify/libnotify-main.cpp
index 21129aa..c2bf9ea 100644
--- a/lib/engine/components/libnotify/libnotify-main.cpp
+++ b/lib/engine/components/libnotify/libnotify-main.cpp
@@ -40,8 +40,13 @@
 
 #include <libnotify/notify.h>
 
+#include <glib/gi18n.h>
+
+#include "config.h"
+
 #include "services.h"
 #include "notification-core.h"
+#include "call-core.h"
 
 #include "libnotify-main.h"
 
@@ -52,7 +57,7 @@ class LibNotify:
 {
 public:
 
-  LibNotify (boost::shared_ptr<Ekiga::NotificationCore> core);
+  LibNotify (Ekiga::ServiceCore& core);
 
   ~LibNotify ();
 
@@ -66,11 +71,28 @@ private:
 
   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::CallManager> manager,
+                             boost::shared_ptr<Ekiga::Call>  call);
+  void on_call_notification_closed (gpointer self);
 
   typedef std::map<boost::shared_ptr<Ekiga::Notification>, std::pair<boost::signals::connection, boost::shared_ptr<NotifyNotification> > > container_type;
   container_type live;
 };
 
+static void
+notify_action_cb (NotifyNotification *notification,
+                  gchar *action,
+                  gpointer data)
+{
+  Ekiga::Call *call = (Ekiga::Call *) data;
+
+  notify_notification_close (notification, NULL);
+  if (!strcmp (action, "accept"))
+    call->answer ();
+  else
+    call->hangup ();
+}
+
 
 struct LIBNOTIFYSpark: public Ekiga::Spark
 {
@@ -81,12 +103,11 @@ struct LIBNOTIFYSpark: public Ekiga::Spark
 			    int* /*argc*/,
 			    char** /*argv*/[])
   {
-    boost::shared_ptr<Ekiga::NotificationCore> notification = core.get<Ekiga::NotificationCore> ("notification-core");
     Ekiga::ServicePtr service = core.get ("libnotify");
 
-    if (notification && !service) {
+    if (!service) {
 
-      core.add (Ekiga::ServicePtr (new LibNotify (notification)));
+      core.add (Ekiga::ServicePtr (new LibNotify (core)));
       result = true;
     }
 
@@ -110,10 +131,19 @@ libnotify_init (Ekiga::KickStart& kickstart)
   kickstart.add_spark (spark);
 }
 
-LibNotify::LibNotify (boost::shared_ptr<Ekiga::NotificationCore> core)
+
+LibNotify::LibNotify (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");
+
   notify_init ("Ekiga");
-  core->notification_added.connect (boost::bind (&LibNotify::on_notification_added, this, _1));
+
+  /* Notifications coming from various components */
+  notification_core->notification_added.connect (boost::bind (&LibNotify::on_notification_added, this, _1));
+
+  /* Specific notifications */
+  call_core->setup_call.connect (boost::bind (&LibNotify::on_call_notification, this, _1, _2));
 }
 
 LibNotify::~LibNotify ()
@@ -149,10 +179,9 @@ LibNotify::on_notification_added (boost::shared_ptr<Ekiga::Notification> notific
   if (notification->get_level () == Ekiga::Notification::Error)
     notify_notification_set_urgency (notif, NOTIFY_URGENCY_CRITICAL);
 
-  g_signal_connect (notif, "closed",
-		    G_CALLBACK (on_notif_closed), notification.get ());
-  boost::signals::connection conn =
-    notification->removed.connect (boost::bind (&LibNotify::on_notification_removed, this, notification));
+  g_signal_connect (notif, "closed", G_CALLBACK (on_notif_closed), notification.get ());
+  boost::signals::connection conn = notification->removed.connect (boost::bind (&LibNotify::on_notification_removed,
+                                                                                this, notification));
 
   live[notification] = std::pair<boost::signals::connection, boost::shared_ptr<NotifyNotification> > (conn, boost::shared_ptr<NotifyNotification> (notif, g_object_unref));
 
@@ -169,3 +198,48 @@ LibNotify::on_notification_removed (boost::shared_ptr<Ekiga::Notification> notif
     live.erase (iter);
   }
 }
+
+void
+LibNotify::on_call_notification_closed (gpointer self)
+{
+  notify_notification_close (NOTIFY_NOTIFICATION (self), NULL);
+}
+
+void
+LibNotify::on_call_notification (boost::shared_ptr<Ekiga::CallManager> manager,
+                                 boost::shared_ptr<Ekiga::Call> call)
+{
+  NotifyNotification *notify = NULL;
+
+  if (call->is_outgoing () || manager->get_auto_answer ())
+    return; // Ignore
+
+  gchar *title = g_strdup_printf (_("Incoming call from %s"), call->get_remote_party_name ().c_str ());
+  gchar *body = g_strdup_printf ("<b>%s</b> %s", _("Remote URI:"), call->get_remote_uri ().c_str ());
+
+  notify = notify_notification_new (title, body, NULL
+// NOTIFY_CHECK_VERSION appeared in 0.5.2 only
+#ifndef NOTIFY_CHECK_VERSION
+                                    , NULL
+#else
+#if !NOTIFY_CHECK_VERSION(0,7,0)
+                                    , NULL
+#endif
+#endif
+                                    );
+  notify_notification_add_action (notify, "reject", _("Reject"), notify_action_cb, call.get (), NULL);
+  notify_notification_add_action (notify, "accept", _("Accept"), notify_action_cb, call.get (), NULL);
+  notify_notification_set_app_name (notify, "Ekiga");
+  notify_notification_set_hint (notify, "transient", g_variant_new_boolean (TRUE));
+  notify_notification_set_timeout (notify, NOTIFY_EXPIRES_NEVER);
+  notify_notification_set_urgency (notify, NOTIFY_URGENCY_CRITICAL);
+
+  call->established.connect (boost::bind (&LibNotify::on_call_notification_closed, this, (gpointer) notify));
+  call->missed.connect (boost::bind (&LibNotify::on_call_notification_closed, this, (gpointer) notify));
+  call->cleared.connect (boost::bind (&LibNotify::on_call_notification_closed, this, (gpointer) notify));
+
+  notify_notification_show (notify, NULL);
+
+  g_free (title);
+  g_free (body);
+}
diff --git a/src/gui/notify.cpp b/src/gui/notify.cpp
index 1ecc79b..4e5c97a 100644
--- a/src/gui/notify.cpp
+++ b/src/gui/notify.cpp
@@ -56,33 +56,6 @@
 #ifdef HAVE_NOTIFY
 #include <libnotify/notify.h>
 
-struct CallNotificationInfo
-{
-  boost::shared_ptr<Ekiga::Call> call;
-};
-
-static void
-notify_action_cb (NotifyNotification *notification,
-                  gchar *action,
-                  gpointer data)
-{
-  CallNotificationInfo *priv = (CallNotificationInfo *) (data);
-  boost::shared_ptr<Ekiga::Call> call = priv->call;
-
-  notify_notification_close (notification, NULL);
-
-  if (call) {
-
-    if (!strcmp (action, "accept"))
-      call->answer ();
-    else
-      call->hangup ();
-  }
-  g_object_set_data (G_OBJECT (notification), "priv", NULL);
-  if (priv)
-    delete priv;
-}
-
 
 static void
 notify_show_window_action_cb (NotifyNotification *notification,
@@ -99,17 +72,6 @@ notify_show_window_action_cb (NotifyNotification *notification,
 }
 
 static void
-on_incoming_call_gone_cb (gpointer self)
-{
-  CallNotificationInfo *priv = (CallNotificationInfo *) (g_object_get_data (G_OBJECT (self), "priv"));
-  notify_notification_close (NOTIFY_NOTIFICATION (self), NULL);
-  g_object_set_data (G_OBJECT (self), "priv", NULL);
-  if (priv)
-    delete priv;
-}
-
-
-static void
 on_unread_count_cb (G_GNUC_UNUSED GtkWidget *widget,
                     guint messages,
                     gpointer data)
@@ -141,63 +103,6 @@ on_unread_count_cb (G_GNUC_UNUSED GtkWidget *widget,
     notify_notification_show (notify, NULL);
   }
 }
-
-static void
-ekiga_incoming_call_notify (boost::shared_ptr<Ekiga::Call> call)
-{
-  NotifyNotification *notify = NULL;
-
-  gchar *uri = NULL;
-  gchar *body = NULL;
-  gchar *title = NULL;
-
-  const char *utf8_name = call->get_remote_party_name ().c_str ();
-  const char *utf8_url = call->get_remote_uri ().c_str ();
-
-  title = g_strdup_printf (_("Incoming call from %s"), (const char*) utf8_name);
-
-  if (utf8_url)
-    uri = g_strdup_printf ("<b>%s</b> %s", _("Remote URI:"), utf8_url);
-
-  body = g_strdup_printf ("%s", uri);
-
-  CallNotificationInfo *priv = new CallNotificationInfo ();
-  priv->call = call;
-
-  notify = notify_notification_new (title, body, NULL
-// NOTIFY_CHECK_VERSION appeared in 0.5.2 only
-#ifndef NOTIFY_CHECK_VERSION
-                                    , NULL
-#else
-#if !NOTIFY_CHECK_VERSION(0,7,0)
-                                    , NULL
-#endif
-#endif
-                                    );
-  g_object_set_data (G_OBJECT (notify), "priv", priv);
-  notify_notification_add_action (notify, "reject", _("Reject"), notify_action_cb, priv, NULL);
-  notify_notification_add_action (notify, "accept", _("Accept"), notify_action_cb, priv, NULL);
-  notify_notification_set_app_name (notify, "ekiga");
-  notify_notification_set_timeout (notify, NOTIFY_EXPIRES_NEVER);
-  notify_notification_set_urgency (notify, NOTIFY_URGENCY_CRITICAL);
-
-  notify_notification_show (notify, NULL);
-
-  call->established.connect (boost::bind (&on_incoming_call_gone_cb, (gpointer) notify));
-  call->missed.connect (boost::bind (&on_incoming_call_gone_cb, (gpointer) notify));
-  call->cleared.connect (boost::bind (&on_incoming_call_gone_cb, (gpointer) notify));
-
-  g_free (uri);
-  g_free (title);
-  g_free (body);
-}
-
-static void on_setup_call_cb (boost::shared_ptr<Ekiga::CallManager> manager,
-                              boost::shared_ptr<Ekiga::Call>  call)
-{
-  if (!call->is_outgoing () && !manager->get_auto_answer () && notify_has_actions ())
-    ekiga_incoming_call_notify (call);
-}
 #endif
 
 /*
@@ -208,13 +113,10 @@ notify_start (Ekiga::ServiceCore & core)
 {
 #ifdef HAVE_NOTIFY
   boost::shared_ptr<GtkFrontend> frontend = core.get<GtkFrontend> ("gtk-frontend");
-  boost::shared_ptr<Ekiga::CallCore> call_core = core.get<Ekiga::CallCore> ("call-core");
   boost::shared_ptr<Ekiga::AccountCore> account_core = core.get<Ekiga::AccountCore> ("account-core");
 
   GtkWidget *chat_window = GTK_WIDGET (frontend->get_chat_window ());
 
-  call_core->setup_call.connect (boost::bind (&on_setup_call_cb, _1, _2));
-
   g_signal_connect (chat_window, "unread-count", G_CALLBACK (on_unread_count_cb), chat_window);
   return true;
 #else



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