[ekiga] Notifications: Started moving libnotify things in a separate file.



commit ad588b9be00e9799edf2d6df2c341cc1b37cecd8
Author: Damien Sandras <dsandras beip be>
Date:   Sun Mar 18 17:35:20 2012 +0100

    Notifications: Started moving libnotify things in a separate file.
    
    Ultimately, each object will be managing his own notifications, and we
    will have a global one for global notifications.

 src/Makefile.am         |    6 ++
 src/ekiga.cpp           |    3 +
 src/gui/main_window.cpp |  110 +-----------------------------
 src/gui/notify.cpp      |  178 +++++++++++++++++++++++++++++++++++++++++++++++
 src/gui/notify.h        |   56 +++++++++++++++
 5 files changed, 244 insertions(+), 109 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index c660cc1..ae366ee 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -76,6 +76,12 @@ ekiga_SOURCES +=			\
 	gui/statusmenu.h		\
 	gui/statusmenu.cpp
 
+if HAVE_NOTIFY
+ekiga_SOURCES +=               		\
+	gui/notify.h		        \
+	gui/notify.cpp
+endif
+
 # Endpoints
 ekiga_SOURCES +=			\
 	ekiga.h			        \
diff --git a/src/ekiga.cpp b/src/ekiga.cpp
index bba433d..47fa249 100644
--- a/src/ekiga.cpp
+++ b/src/ekiga.cpp
@@ -44,6 +44,7 @@
 #include "accounts.h"
 #include "call_window.h"
 #include "main_window.h"
+#include "notify.h"
 #include "gmstockicons.h"
 
 #ifdef HAVE_DBUS
@@ -190,6 +191,8 @@ void GnomeMeeting::BuildGUI (Ekiga::ServiceCorePtr services)
   // FIXME should be moved in call window
   gtk_window_set_transient_for (GTK_WINDOW (call_window), GTK_WINDOW (main_window));
 
+  notify_start (*services);
+
   /* GM is started */
   PTRACE (1, "Ekiga version "
 	  << MAJOR_VERSION << "." << MINOR_VERSION << "." << BUILD_NUMBER);
diff --git a/src/gui/main_window.cpp b/src/gui/main_window.cpp
index 34d1ac6..a246bed 100644
--- a/src/gui/main_window.cpp
+++ b/src/gui/main_window.cpp
@@ -236,10 +236,6 @@ static void ekiga_main_window_append_call_url (EkigaMainWindow *mw,
 
 static const std::string ekiga_main_window_get_call_url (EkigaMainWindow *mw);
 
-#ifdef HAVE_NOTIFY
-static void ekiga_main_window_incoming_call_notify (EkigaMainWindow *mw,
-                                                    boost::shared_ptr<Ekiga::Call>  call);
-#endif
 
 /* DESCRIPTION  :  This callback is called when the chat window alerts about
  *                 unread messages
@@ -658,9 +654,7 @@ static void on_setup_call_cb (boost::shared_ptr<Ekiga::CallManager> manager,
 
     audiooutput_core->start_play_event ("incoming_call_sound", 4000, 256);
 #ifdef HAVE_NOTIFY
-    if (hasActionsCap ())
-      ekiga_main_window_incoming_call_notify (mw, call);
-    else
+    if (!hasActionsCap ())
       ekiga_main_window_incoming_call_dialog_show (mw, call);
 #else
     ekiga_main_window_incoming_call_dialog_show (mw, call);
@@ -1433,108 +1427,6 @@ ekiga_main_window_incoming_call_dialog_show (EkigaMainWindow *mw,
 }
 
 
-#ifdef HAVE_NOTIFY
-static void
-notify_action_cb (NotifyNotification *notification,
-                  gchar *action,
-                  gpointer main_window)
-{
-  EkigaMainWindow *mw = EKIGA_MAIN_WINDOW (main_window);
-
-  notify_notification_close (notification, NULL);
-
-  if (mw->priv->current_call) {
-
-    if (!strcmp (action, "accept"))
-      mw->priv->current_call->answer ();
-    else
-      mw->priv->current_call->hangup ();
-  }
-}
-
-static void
-closed_cb (NotifyNotification* /*notify*/,
-           gpointer main_window)
-{
-  EkigaMainWindow *mw;
-
-  g_return_if_fail (main_window != NULL);
-
-  mw = EKIGA_MAIN_WINDOW (main_window);
-
-  boost::shared_ptr<Ekiga::AudioOutputCore> audiooutput_core = mw->priv->core->get<Ekiga::AudioOutputCore> ("audiooutput-core");
-  if (audiooutput_core)
-    audiooutput_core->stop_play_event ("incoming_call_sound");
-}
-
-static void
-ekiga_main_window_incoming_call_notify (EkigaMainWindow *mw,
-                                        boost::shared_ptr<Ekiga::Call>  call)
-{
-  NotifyNotification *notify = NULL;
-
-  gchar *uri = NULL;
-  gchar *app = NULL;
-  gchar *body = NULL;
-  gchar *title = NULL;
-
-  const char *utf8_name = call->get_remote_party_name ().c_str ();
-  const char *utf8_app = call->get_remote_application ().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);
-  if (utf8_app)
-    app = g_strdup_printf ("<b>%s</b> %s", _("Remote Application:"), utf8_app);
-
-  body = g_strdup_printf ("%s\n%s", uri, app);
-
-  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, mw, NULL);
-  notify_notification_add_action (notify, "accept", _("Accept"), notify_action_cb, mw, NULL);
-  notify_notification_set_timeout (notify, NOTIFY_EXPIRES_NEVER);
-  notify_notification_set_urgency (notify, NOTIFY_URGENCY_CRITICAL);
-// NOTIFY_CHECK_VERSION appeared in 0.5.2 only
-#ifndef NOTIFY_CHECK_VERSION
-    notify_notification_attach_to_status_icon (notify, statusicon);
-#else
-#if !NOTIFY_CHECK_VERSION(0,7,0)
-    notify_notification_attach_to_status_icon (notify, statusicon);
-#endif
-#endif
-  if (!notify_notification_show (notify, NULL)) {
-    ekiga_main_window_incoming_call_dialog_show (mw, call);
-  }
-  else {
-    call->established.connect (boost::bind (&on_incoming_call_gone_cb,
-                                           (gpointer) notify));
-    call->cleared.connect (boost::bind (&on_cleared_incoming_call_cb, _1,
-                                      (gpointer) notify));
-    call->missed.connect (boost::bind (&on_incoming_call_gone_cb,
-                                     (gpointer) notify));
-  }
-
-  g_signal_connect (notify, "closed", G_CALLBACK (closed_cb), mw);
-
-  g_free (uri);
-  g_free (app);
-  g_free (title);
-  g_free (body);
-}
-#endif
-
-
 static void
 ekiga_main_window_append_call_url (EkigaMainWindow *mw,
 				   const char *url)
diff --git a/src/gui/notify.cpp b/src/gui/notify.cpp
new file mode 100644
index 0000000..145cef2
--- /dev/null
+++ b/src/gui/notify.cpp
@@ -0,0 +1,178 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2012 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.
+ */
+
+
+/*
+ *                         notify.cpp  -  description
+ *                         --------------------------
+ *   begin                : Sun Mar 18 2012
+ *   copyright            : (C) 2000-2012 by Damien Sandras
+ *   description          : Global notifications based on libnotify
+ */
+
+
+#include <libnotify/notify.h>
+#include <glib/gi18n.h>
+
+#include "config.h"
+
+#include "notify.h"
+
+#include "services.h"
+#include "call-core.h"
+
+struct CallNotificationInfo
+{
+  boost::shared_ptr<Ekiga::Call> call;
+};
+
+// return if the notify server accepts actions (i.e. buttons)
+// taken from https://wiki.ubuntu.com/NotificationDevelopmentGuidelines#Avoiding%20actions
+static int
+hasActionsCap (void)
+{
+  static int accepts_actions = -1;
+  if (accepts_actions == -1) {  // initialise accepts_actions at the first call
+    accepts_actions = 0;
+    GList *capabilities = notify_get_server_caps ();
+    if (capabilities != NULL) {
+      for (GList *c = capabilities ; c != NULL ; c = c->next) {
+        if (strcmp ((char*)c->data, "actions") == 0 ) {
+          accepts_actions = 1;
+          break;
+        }
+      }
+      g_list_foreach (capabilities, (GFunc)g_free, NULL);
+      g_list_free (capabilities);
+    }
+  }
+  return accepts_actions;
+}
+
+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
+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
+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->cleared.connect (boost::bind (&on_incoming_call_gone_cb,
+                                      (gpointer) notify));
+  call->missed.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 () && hasActionsCap ())
+    ekiga_incoming_call_notify (call);
+}
+
+
+/*
+ * Public API
+ */
+void
+notify_start (Ekiga::ServiceCore & core)
+{
+  boost::shared_ptr<Ekiga::CallCore> call_core = core.get<Ekiga::CallCore> ("call-core");
+
+  call_core->setup_call.connect (boost::bind (&on_setup_call_cb, _1, _2));
+}
diff --git a/src/gui/notify.h b/src/gui/notify.h
new file mode 100644
index 0000000..84148b6
--- /dev/null
+++ b/src/gui/notify.h
@@ -0,0 +1,56 @@
+
+/* 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.
+ */
+
+
+/*
+ *                         notify.h  -  description
+ *                         ------------------------
+ *   begin                : Sun Mar 18 2012
+ *   copyright            : (C) 2000-2012 by Damien Sandras
+ *   description          : Global notifications based on libnotify
+ */
+
+
+#ifndef _NOTIFY_H_
+#define _NOTIFY_H_
+
+#include <glib.h>
+
+#include "services.h"
+
+G_BEGIN_DECLS
+
+/* Public API */
+
+/* DESCRIPTION  : /
+ * BEHAVIOR     : Start the notifications monitoring
+ */
+void notify_start (Ekiga::ServiceCore & core);
+
+G_END_DECLS
+
+#endif



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