[nautilus] Lazily initialize notification service



commit 1df7de8a1ab643ebefe3d8df7ab0343f36687299
Author: Martin Pitt <martin pitt ubuntu com>
Date:   Thu Jan 5 10:07:57 2012 +0100

    Lazily initialize notification service
    
    Avoid spawning the notification daemon at startup through querying server caps.
    Instead, cache the result in server_has_persistence() and initialize it lazily.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=667342

 src/nautilus-progress-ui-handler.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/src/nautilus-progress-ui-handler.c b/src/nautilus-progress-ui-handler.c
index 060a3c0..803ccfe 100644
--- a/src/nautilus-progress-ui-handler.c
+++ b/src/nautilus-progress-ui-handler.c
@@ -45,7 +45,6 @@ struct _NautilusProgressUIHandlerPriv {
 	GtkWidget *window_vbox;
 	guint active_infos;
 
-	gboolean notification_supports_persistence;
 	NotifyNotification *progress_notification;
 	GtkStatusIcon *status_icon;
 };
@@ -71,6 +70,8 @@ G_DEFINE_TYPE (NautilusProgressUIHandler, nautilus_progress_ui_handler, G_TYPE_O
 
 #define ACTION_DETAILS "details"
 
+static gboolean server_has_persistence (void);
+
 static void
 status_icon_activate_cb (GtkStatusIcon *icon,
 			 NautilusProgressUIHandler *self)
@@ -187,7 +188,7 @@ progress_window_delete_event (GtkWidget *widget,
 {
 	gtk_widget_hide (widget);
 
-	if (self->priv->notification_supports_persistence) {
+	if (server_has_persistence ()) {
 		progress_ui_handler_update_notification (self);
 	} else {
 		progress_ui_handler_update_status_icon (self);
@@ -235,7 +236,7 @@ progress_ui_handler_ensure_window (NautilusProgressUIHandler *self)
 static void
 progress_ui_handler_update_notification_or_status (NautilusProgressUIHandler *self)
 {
-	if (self->priv->notification_supports_persistence) {
+	if (server_has_persistence ()) {
 		progress_ui_handler_update_notification (self);
 	} else {
 		progress_ui_handler_update_status_icon (self);
@@ -264,7 +265,7 @@ progress_ui_handler_show_complete_notification (NautilusProgressUIHandler *self)
 	NotifyNotification *complete_notification;
 
 	/* don't display the notification if we'd be using a status icon */
-	if (!self->priv->notification_supports_persistence) {
+	if (!server_has_persistence ()) {
 		return;
 	}
 
@@ -432,8 +433,14 @@ nautilus_progress_ui_handler_dispose (GObject *obj)
 static gboolean
 server_has_persistence (void)
 {
-        gboolean retval;
+        static gboolean retval = FALSE;
         GList *caps, *l;
+        static gboolean initialized = FALSE;
+
+        if (initialized) {
+                return retval;
+        }
+        initialized = TRUE;
 
         caps = notify_get_server_caps ();
         if (caps == NULL) {
@@ -457,8 +464,6 @@ nautilus_progress_ui_handler_init (NautilusProgressUIHandler *self)
 	self->priv->manager = nautilus_progress_info_manager_new ();
 	g_signal_connect (self->priv->manager, "new-progress-info",
 			  G_CALLBACK (new_progress_info_cb), self);
-
-	self->priv->notification_supports_persistence = server_has_persistence ();
 }
 
 static void



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