From 5396553577a4ecd2b75dd5a1bb398b5e92a0e076 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Feb 2012 17:39:50 -0600 Subject: when a new entry is added, ensure that its accessible_string is properly set --- src/indicator-power.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/indicator-power.c b/src/indicator-power.c index cd691d8..6140c54 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -103,6 +103,8 @@ static const gchar* get_name_hint (IndicatorObject * io); static void update_visibility (IndicatorPower * self); static gboolean should_be_visible (IndicatorPower * self); +static void on_entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data); + static void gsd_appeared_callback (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data); G_DEFINE_TYPE (IndicatorPower, indicator_power, INDICATOR_OBJECT_TYPE); @@ -144,6 +146,9 @@ indicator_power_init (IndicatorPower *self) g_object_set (G_OBJECT(self), INDICATOR_OBJECT_DEFAULT_VISIBILITY, FALSE, NULL); + + g_signal_connect (INDICATOR_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, + G_CALLBACK(on_entry_added), NULL); } static void @@ -398,26 +403,48 @@ build_device_time_details (const gchar *device_name, } } +/* ensure that the entry is using self's accessible description */ +static void +refresh_entry_accessible_desc (IndicatorPower * self, IndicatorObjectEntry * entry) +{ + const char * newval = self->accessible_desc; + + if (entry->accessible_desc != newval) + { + g_debug ("%s: setting entry %p accessible description to '%s'", G_STRFUNC, entry, newval); + entry->accessible_desc = newval; + g_signal_emit (self, INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, 0, entry); + } +} + +static void +on_entry_added (IndicatorObject * io, + IndicatorObjectEntry * entry, + gpointer user_data G_GNUC_UNUSED) +{ + refresh_entry_accessible_desc (INDICATOR_POWER(io), entry); +} + static void -set_accessible_desc (IndicatorPower *self, - const gchar *desc) +set_accessible_desc (IndicatorPower *self, const gchar *desc) { + g_debug ("%s: setting accessible description to '%s'", G_STRFUNC, desc); + if (desc && *desc) { /* update our copy of the string */ - char * old_desc = self->accessible_desc; + char * oldval = self->accessible_desc; self->accessible_desc = g_strdup (desc); - g_free (old_desc); - /* have the entries use our string */ + /* ensure that the entries are using self's accessible description */ GList * l; GList * entries = indicator_object_get_entries(INDICATOR_OBJECT(self)); - for (l=entries; l!=NULL; l=l->next) { - IndicatorObjectEntry * entry = l->data; - entry->accessible_desc = self->accessible_desc; - g_signal_emit (self, INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, 0, entry); - } + for (l=entries; l!=NULL; l=l->next) + refresh_entry_accessible_desc (self, l->data); + + /* cleanup */ g_list_free (entries); + g_free (oldval); } } -- cgit v1.2.3