aboutsummaryrefslogtreecommitdiff
path: root/libindicator/indicator-ng.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-01-25 10:46:58 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-01-25 10:46:58 +0100
commit70480923e6151c8173032710beb99707bb5b9485 (patch)
treefaaf73152eafe378c0f9e9e7e6ae7b7d7031a633 /libindicator/indicator-ng.c
parent82ecfaaa89684a7504913fb039d0dd8302c82ec9 (diff)
downloadlibayatana-indicator-70480923e6151c8173032710beb99707bb5b9485.tar.gz
libayatana-indicator-70480923e6151c8173032710beb99707bb5b9485.tar.bz2
libayatana-indicator-70480923e6151c8173032710beb99707bb5b9485.zip
indicator-ng: lazily allocate entry.label and entry.image
Most indicators only need one of those.
Diffstat (limited to 'libindicator/indicator-ng.c')
-rw-r--r--libindicator/indicator-ng.c34
1 files 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);
@@ -183,6 +189,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)
{
GVariant *state;
@@ -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