[ekiga] Statusicon: Do not rely on notifications persistence to show it.



commit 5602db0484865f146870b6c999a53ffb7938ab66
Author: Damien Sandras <dsandras beip be>
Date:   Sat Jun 9 13:39:22 2012 +0200

    Statusicon: Do not rely on notifications persistence to show it.
    
    The problem is that GNOME 3 Fallback also supports persistence, but has
    a notification area.
    
    Now, if gnome-shell is running, the status icon is not shown. Closing
    the window hides it. We expect the user to launch ekiga again or to wait
    for some action to show it back.
    
    If gnome-shell is not running, we display the statusicon in the status
    area and we expect him to click on it to show it back.

 lib/engine/gui/gtk-frontend/statusicon.cpp |   59 ++++++++++++++++++++--------
 1 files changed, 42 insertions(+), 17 deletions(-)
---
diff --git a/lib/engine/gui/gtk-frontend/statusicon.cpp b/lib/engine/gui/gtk-frontend/statusicon.cpp
index 982bc6d..a6aab19 100644
--- a/lib/engine/gui/gtk-frontend/statusicon.cpp
+++ b/lib/engine/gui/gtk-frontend/statusicon.cpp
@@ -58,6 +58,9 @@
 #include <libnotify/notify.h>
 #endif
 
+#ifdef HAVE_DBUS
+#include <dbus/dbus-glib.h>
+#endif
 
 /*
  * The StatusIcon
@@ -492,27 +495,49 @@ statusicon_on_notification_added (boost::shared_ptr<Ekiga::Notification> notific
 
 
 static bool
-notify_has_persistence (void)
+statusicon_should_run (void)
 {
-  gboolean has = false;
-#ifdef HAVE_NOTIFY
-  GList   *caps;
-  GList   *l;
-
-  caps = notify_get_server_caps ();
-  if (caps == NULL) {
-    fprintf (stderr, "Failed to receive server caps.\n");
-    return FALSE;
+  bool shell_running = false;
+
+#ifdef HAVE_DBUS
+  DBusGConnection *connection = NULL;
+  GError *error = NULL;
+  DBusGProxy *proxy = NULL;
+  char **name_list = NULL;
+  char **name_list_ptr = NULL;
+
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+  if (connection == NULL) {
+    g_error_free (error);
+    return true;
   }
 
-  l = g_list_find_custom (caps, "persistence", (GCompareFunc)strcmp);
-  has = l != NULL;
+  /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
+  proxy = dbus_g_proxy_new_for_name (connection,
+                                     DBUS_SERVICE_DBUS,
+                                     DBUS_PATH_DBUS,
+                                     DBUS_INTERFACE_DBUS);
+
+  /* Call ListNames method, wait for reply */
+  error = NULL;
+  if (!dbus_g_proxy_call (proxy, "ListNames", &error, G_TYPE_INVALID,
+                          G_TYPE_STRV, &name_list, G_TYPE_INVALID)) {
+      g_error_free (error);
+      return true;
+  }
 
-  g_list_foreach (caps, (GFunc) g_free, NULL);
-  g_list_free (caps);
+  /* Print the results */
+  for (name_list_ptr = name_list; *name_list_ptr; name_list_ptr++) {
+    if (!strcmp (*name_list_ptr, "org.gnome.Shell")) {
+      shell_running = true;
+      break;
+    }
+  }
+  g_strfreev (name_list);
+  g_object_unref (proxy);
 #endif
 
-  return has;
+  return !shell_running;
 }
 
 
@@ -524,8 +549,8 @@ status_icon_new (Ekiga::ServiceCore & core)
 {
   StatusIcon *self = NULL;
 
-  if (notify_has_persistence ())
-    return NULL;
+  if (!statusicon_should_run ())
+    return self;
 
   boost::signals::connection conn;
 



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