[Xfce4-commits] <thunar:master> Delay notification initialization until we show one.

Nick Schermer noreply at xfce.org
Wed Nov 17 20:08:02 CET 2010


Updating branch refs/heads/master
         to be3422ba2d3495dd6fe78af8c7e4b604e7990b9d (commit)
       from 1c88058f01cdf07cc1684869fe987d8a75f65d9d (commit)

commit be3422ba2d3495dd6fe78af8c7e4b604e7990b9d
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Nov 17 20:05:41 2010 +0100

    Delay notification initialization until we show one.

 thunar/main.c          |   19 ++-----------------
 thunar/thunar-notify.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 thunar/thunar-notify.h |    3 +--
 3 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/thunar/main.c b/thunar/main.c
index 6225c64..e107ee5 100644
--- a/thunar/main.c
+++ b/thunar/main.c
@@ -34,7 +34,7 @@
 #endif
 
 #ifdef HAVE_LIBNOTIFY
-#include <libnotify/notify.h>
+#include <thunar/thunar-notify.h>
 #endif
 
 #include <thunar/thunar-application.h>
@@ -137,20 +137,6 @@ main (int argc, char **argv)
   /* initialize the GThread system */
   if (!g_thread_supported ())
     g_thread_init (NULL);
-
-#ifdef HAVE_LIBNOTIFY
-  if (notify_init (PACKAGE_NAME))
-    {
-      /* we do this to work around bugs in libnotify < 0.6.0. Older
-       * versions crash in notify_uninit() when no notifications are
-       * displayed before. These versions also segfault when the 
-       * ret_spec_version parameter of notify_get_server_info is 
-       * NULL... */
-      gchar *spec_version = NULL;
-      notify_get_server_info (NULL, NULL, NULL, &spec_version);
-      g_free (spec_version);
-    }
-#endif
     
   /* get the startup notification id */
   startup_id = g_getenv ("DESKTOP_STARTUP_ID");
@@ -319,8 +305,7 @@ error0:
   g_object_unref (G_OBJECT (application));
 
 #ifdef HAVE_LIBNOTIFY
-  if (notify_is_initted ())
-    notify_uninit ();
+  thunar_notify_uninit ();
 #endif
 
   return EXIT_SUCCESS;
diff --git a/thunar/thunar-notify.c b/thunar/thunar-notify.c
index 6e8a406..f6643fe 100644
--- a/thunar/thunar-notify.c
+++ b/thunar/thunar-notify.c
@@ -32,6 +32,33 @@
 #include <thunar/thunar-notify.h>
 
 
+static gboolean thunar_notify_initted = FALSE;
+
+
+
+static gboolean
+thunar_notify_init (void)
+{
+  gchar *spec_version = NULL;
+
+  if (!thunar_notify_initted
+      && notify_init (PACKAGE_NAME))
+    {
+      /* we do this to work around bugs in libnotify < 0.6.0. Older
+       * versions crash in notify_uninit() when no notifications are
+       * displayed before. These versions also segfault when the
+       * ret_spec_version parameter of notify_get_server_info is
+       * NULL... */
+      notify_get_server_info (NULL, NULL, NULL, &spec_version);
+      g_free (spec_version);
+
+      thunar_notify_initted = TRUE;
+    }
+
+  return thunar_notify_initted;
+}
+
+
 
 void
 thunar_notify_unmount (GMount *mount)
@@ -50,6 +77,9 @@ thunar_notify_unmount (GMount *mount)
 
   g_return_if_fail (G_IS_MOUNT (mount));
 
+  if (!thunar_notify_init ())
+    return;
+
   mount_point = g_mount_get_root (mount);
   
   info = g_file_query_info (mount_point, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, 
@@ -154,6 +184,9 @@ thunar_notify_eject (GVolume *volume)
 
   g_return_if_fail (G_IS_VOLUME (volume));
 
+  if (!thunar_notify_init ())
+    return;
+
   mount = g_volume_get_mount (volume);
   if (mount != NULL)
     {
@@ -240,3 +273,13 @@ thunar_notify_eject_finish (GVolume *volume)
       g_object_set_data (G_OBJECT (volume), "thunar-notification", NULL);
     }
 }
+
+
+
+void
+thunar_notify_uninit (void)
+{
+  if (thunar_notify_initted
+      && notify_is_initted ())
+    notify_uninit ();
+}
diff --git a/thunar/thunar-notify.h b/thunar/thunar-notify.h
index 47696ee..596ffa7 100644
--- a/thunar/thunar-notify.h
+++ b/thunar/thunar-notify.h
@@ -24,14 +24,13 @@
 #include <glib.h>
 #include <gio/gio.h>
 
-#include <libnotify/notify.h>
-
 G_BEGIN_DECLS
 
 void thunar_notify_unmount        (GMount  *mount);
 void thunar_notify_unmount_finish (GMount  *mount);
 void thunar_notify_eject          (GVolume *volume);
 void thunar_notify_eject_finish   (GVolume *volume);
+void thunar_notify_uninit         (void);
 
 G_END_DECLS
 



More information about the Xfce4-commits mailing list