[network-manager-applet] applet: lazily initialize notification service (bgo #667400)



commit f79aef0a3ade0eb1438904395638d4ac5d7f08f0
Author: Martin Pitt <martin pitt ubuntu com>
Date:   Fri Jan 6 11:57:29 2012 +0100

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

 src/applet.c |   11 +++++++----
 src/applet.h |    1 -
 2 files changed, 7 insertions(+), 5 deletions(-)
---
diff --git a/src/applet.c b/src/applet.c
index 47ce4bf..5dd93dc 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -798,9 +798,14 @@ applet_clear_notify (NMApplet *applet)
 static gboolean
 applet_notify_server_has_actions (void)
 {
-	gboolean has_actions = FALSE;
+	static gboolean has_actions = FALSE;
+	static gboolean initialized = FALSE;
 	GList *server_caps, *iter;
 
+	if (initialized)
+		return has_actions;
+	initialized = TRUE;
+
 	server_caps = notify_get_server_caps();
 	for (iter = server_caps; iter; iter = g_list_next (iter)) {
 		if (!strcmp ((const char *) iter->data, NOTIFY_CAPS_ACTIONS_KEY)) {
@@ -858,7 +863,7 @@ applet_do_notify (NMApplet *applet,
 	notify_notification_set_urgency (notify, urgency);
 	notify_notification_set_timeout (notify, NOTIFY_EXPIRES_DEFAULT);
 
-	if (applet->notify_actions && action1) {
+	if (applet_notify_server_has_actions () && action1) {
 		notify_notification_add_action (notify, action1, action1_label,
 		                                action1_cb, action1_user_data, NULL);
 	}
@@ -3329,8 +3334,6 @@ constructor (GType type,
 	                  G_CALLBACK (applet_embedded_cb), NULL);
 	applet_embedded_cb (G_OBJECT (applet->status_icon), NULL, NULL);
 
-	applet->notify_actions = applet_notify_server_has_actions ();
-
 	return G_OBJECT (applet);
 
 error:
diff --git a/src/applet.h b/src/applet.h
index a9d07bc..4f8b901 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -166,7 +166,6 @@ typedef struct
 
 	GtkBuilder *	info_dialog_ui;
 	NotifyNotification*	notification;
-	gboolean        notify_actions;
 
 	/* Tracker objects for secrets requests */
 	GSList *        secrets_reqs;



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