From 70480923e6151c8173032710beb99707bb5b9485 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 25 Jan 2013 10:46:58 +0100 Subject: indicator-ng: lazily allocate entry.label and entry.image Most indicators only need one of those. --- libindicator/indicator-ng.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/libindicator/indicator-ng.c b/libindicator/indicator-ng.c index 05ece8d..f27fbf0 100644 --- a/libindicator/indicator-ng.c +++ b/libindicator/indicator-ng.c @@ -161,11 +161,17 @@ indicator_ng_set_icon_from_string (IndicatorNg *self, if (str == NULL || *str == '\0') { - gtk_image_clear (self->entry.image); - gtk_widget_hide (GTK_WIDGET (self->entry.image)); + if (self->entry.image) + { + gtk_image_clear (self->entry.image); + gtk_widget_hide (GTK_WIDGET (self->entry.image)); + } return; } + if (!self->entry.image) + self->entry.image = g_object_ref_sink (gtk_image_new ()); + gtk_widget_show (GTK_WIDGET (self->entry.image)); icon = g_icon_new_for_string (str, &error); @@ -182,6 +188,24 @@ indicator_ng_set_icon_from_string (IndicatorNg *self, } } +static void +indicator_ng_set_label (IndicatorNg *self, + const gchar *label) +{ + if (label == NULL || *label == '\0') + { + if (self->entry.label) + gtk_widget_hide (GTK_WIDGET (self->entry.label)); + return; + } + + if (!self->entry.label) + self->entry.label = g_object_ref_sink (gtk_label_new (NULL)); + + gtk_label_set_label (GTK_LABEL (self->entry.label), label); + gtk_widget_show (GTK_WIDGET (self->entry.label)); +} + static void indicator_ng_update_entry (IndicatorNg *self) { @@ -207,7 +231,7 @@ indicator_ng_update_entry (IndicatorNg *self) g_variant_get (state, "(&s&s&sb)", &label, &iconstr, &accessible_desc, &visible); - gtk_label_set_label (GTK_LABEL (self->entry.label), label); + indicator_ng_set_label (self, label); indicator_ng_set_icon_from_string (self, iconstr); indicator_ng_set_accessible_desc (self, accessible_desc); indicator_object_set_visible (INDICATOR_OBJECT (self), visible); @@ -407,10 +431,6 @@ indicator_ng_initable_iface_init (GInitableIface *initable) static void indicator_ng_init (IndicatorNg *self) { - self->entry.label = g_object_ref_sink (gtk_label_new (NULL)); - gtk_widget_show (GTK_WIDGET (self->entry.label)); - - self->entry.image = g_object_ref_sink (gtk_image_new ()); self->entry.menu = g_object_ref_sink (gtk_menu_new ()); /* work around IndicatorObject's warning that the accessible -- cgit v1.2.3