[Xfce4-commits] <thunar-volman:master> Delay notification initialization until we show one.
Nick Schermer
noreply at xfce.org
Wed Nov 17 19:52:01 CET 2010
Updating branch refs/heads/master
to 84b88eb4825af54c236d0ded4d230cdda413ed02 (commit)
from eb9066c6863aed3f61c29ea8930d39d3c4072059 (commit)
commit 84b88eb4825af54c236d0ded4d230cdda413ed02
Author: Nick Schermer <nick at xfce.org>
Date: Wed Nov 17 19:50:12 2010 +0100
Delay notification initialization until we show one.
thunar-volman/main.c | 21 ++-------------------
thunar-volman/tvm-notify.c | 36 ++++++++++++++++++++++++++++++++++++
thunar-volman/tvm-notify.h | 2 ++
3 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/thunar-volman/main.c b/thunar-volman/main.c
index 2256163..511bca8 100644
--- a/thunar-volman/main.c
+++ b/thunar-volman/main.c
@@ -34,7 +34,7 @@
#include <gudev/gudev.h>
#ifdef HAVE_LIBNOTIFY
-#include <libnotify/notify.h>
+#include <thunar-volman/tvm-notify.h>
#endif
#include <libxfce4util/libxfce4util.h>
@@ -85,9 +85,6 @@ main (int argc,
GMainLoop *loop = NULL;
GError *error = NULL;
gint exit_code = EXIT_SUCCESS;
-#ifdef HAVE_LIBNOTIFY
- gchar *spec_version = NULL;;
-#endif
/* setup translation domain */
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
@@ -104,19 +101,6 @@ main (int argc,
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... */
- notify_get_server_info (NULL, NULL, NULL, &spec_version);
- g_free (spec_version);
- }
-#endif
-
/* initialize GTK+ */
if (!gtk_init_with_args (&argc, &argv, NULL, option_entries, GETTEXT_PACKAGE, &error))
{
@@ -217,8 +201,7 @@ main (int argc,
}
#ifdef HAVE_LIBNOTIFY
- if (notify_is_initted ())
- notify_uninit ();
+ tvm_notify_uninit ();
#endif
/* release the device context */
diff --git a/thunar-volman/tvm-notify.c b/thunar-volman/tvm-notify.c
index 1b30505..8947b87 100644
--- a/thunar-volman/tvm-notify.c
+++ b/thunar-volman/tvm-notify.c
@@ -32,12 +32,38 @@
+static gboolean tvm_notify_initted = FALSE;
+
+
+
void
tvm_notify (const gchar *icon,
const gchar *summary,
const gchar *message)
{
NotifyNotification *notification;
+ gchar *spec_version = NULL;
+
+ if (G_UNLIKELY (!tvm_notify_initted))
+ {
+ 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... */
+ notify_get_server_info (NULL, NULL, NULL, &spec_version);
+ g_free (spec_version);
+
+ tvm_notify_initted = TRUE;
+ }
+ else
+ {
+ /* initialization failed; don't bother about the notification */
+ return;
+ }
+ }
notification = notify_notification_new (summary, message, icon, NULL);
notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);
@@ -81,3 +107,13 @@ tvm_notify_decode (const gchar *str)
return result;
}
+
+
+
+void
+tvm_notify_uninit (void)
+{
+ if (tvm_notify_initted
+ && notify_is_initted ())
+ notify_uninit ();
+}
diff --git a/thunar-volman/tvm-notify.h b/thunar-volman/tvm-notify.h
index 9d1c578..3010b31 100644
--- a/thunar-volman/tvm-notify.h
+++ b/thunar-volman/tvm-notify.h
@@ -31,6 +31,8 @@ void tvm_notify (const gchar *icon,
gchar *tvm_notify_decode (const gchar *str);
+void tvm_notify_uninit (void);
+
G_END_DECLS
#endif /* !__TVM_NOTIFY_H__ */
More information about the Xfce4-commits
mailing list