diff options
author | William Hua <william.hua@canonical.com> | 2013-05-22 18:08:11 +0000 |
---|---|---|
committer | Tarmac <Unknown> | 2013-05-22 18:08:11 +0000 |
commit | ae198af4a8d3ea34d308aff1754052f364f398d6 (patch) | |
tree | 6409a025b504ff6cf0b2b9e5cf41e1e7c2495f59 /libindicator/indicator-ng.c | |
parent | 5cac96c229ed038b2e21f6a7a2ff08746c488019 (diff) | |
parent | 176ea145dc5f0ee8cc7bff73ccda74d5b90c816e (diff) | |
download | libayatana-indicator-ae198af4a8d3ea34d308aff1754052f364f398d6.tar.gz libayatana-indicator-ae198af4a8d3ea34d308aff1754052f364f398d6.tar.bz2 libayatana-indicator-ae198af4a8d3ea34d308aff1754052f364f398d6.zip |
Use GIcon's serialization/deserialization interface for indicator icons so that we can load icons as PNG data transmitted over the bus.
Approved by Lars Uebernickel, PS Jenkins bot.
Diffstat (limited to 'libindicator/indicator-ng.c')
-rw-r--r-- | libindicator/indicator-ng.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/libindicator/indicator-ng.c b/libindicator/indicator-ng.c index 1e95785..fd78662 100644 --- a/libindicator/indicator-ng.c +++ b/libindicator/indicator-ng.c @@ -179,13 +179,12 @@ indicator_ng_set_accessible_desc (IndicatorNg *self, } static void -indicator_ng_set_icon_from_string (IndicatorNg *self, - const gchar *str) +indicator_ng_set_icon_from_variant (IndicatorNg *self, + GVariant *variant) { GIcon *icon; - GError *error = NULL; - if (str == NULL || *str == '\0') + if (variant == NULL) { if (self->entry.image) { @@ -200,7 +199,7 @@ indicator_ng_set_icon_from_string (IndicatorNg *self, gtk_widget_show (GTK_WIDGET (self->entry.image)); - icon = g_icon_new_for_string (str, &error); + icon = g_icon_deserialize (variant); if (icon) { indicator_image_helper_update_from_gicon (self->entry.image, icon); @@ -208,9 +207,10 @@ indicator_ng_set_icon_from_string (IndicatorNg *self, } else { - g_warning ("invalid icon string '%s': %s", str, error->message); + gchar *text = g_variant_print (variant, TRUE); + g_warning ("invalid icon variant '%s'", text); gtk_image_set_from_stock (self->entry.image, GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_LARGE_TOOLBAR); - g_error_free (error); + g_free (text); } } @@ -237,7 +237,7 @@ indicator_ng_update_entry (IndicatorNg *self) { GVariant *state; const gchar *label = NULL; - const gchar *iconstr = NULL; + GVariant *icon = NULL; const gchar *accessible_desc = NULL; gboolean visible = TRUE; @@ -254,12 +254,20 @@ indicator_ng_update_entry (IndicatorNg *self) state = g_action_group_get_action_state (self->actions, self->header_action); if (state && g_variant_is_of_type (state, G_VARIANT_TYPE ("(sssb)"))) { + gchar *iconstr = NULL; + g_variant_get (state, "(&s&s&sb)", &label, &iconstr, &accessible_desc, &visible); + + if (iconstr) + { + icon = g_variant_ref_sink (g_variant_new_string (iconstr)); + g_free (iconstr); + } } else if (state && g_variant_is_of_type (state, G_VARIANT_TYPE ("a{sv}"))) { g_variant_lookup (state, "label", "&s", &label); - g_variant_lookup (state, "icon", "&s", &iconstr); + g_variant_lookup (state, "icon", "*", &icon); g_variant_lookup (state, "accessible-desc", "&s", &accessible_desc); g_variant_lookup (state, "visible", "b", &visible); } @@ -268,12 +276,14 @@ indicator_ng_update_entry (IndicatorNg *self) if (label) indicator_ng_set_label (self, label); - if (iconstr) - indicator_ng_set_icon_from_string (self, iconstr); + if (icon) + indicator_ng_set_icon_from_variant (self, icon); if (accessible_desc) indicator_ng_set_accessible_desc (self, accessible_desc); indicator_object_set_visible (INDICATOR_OBJECT (self), visible); + if (icon) + g_variant_unref (icon); if (state) g_variant_unref (state); } |