aboutsummaryrefslogtreecommitdiff
path: root/libindicator
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-04-22 11:50:51 -0400
committerWilliam Hua <william.hua@canonical.com>2013-04-22 11:50:51 -0400
commit19ec64915aac1ecf55f5b5aaa26358578dd2ac34 (patch)
tree57d0081c6f6fa26e9c304e3bd2e362614cfed108 /libindicator
parent5cac96c229ed038b2e21f6a7a2ff08746c488019 (diff)
downloadlibayatana-indicator-19ec64915aac1ecf55f5b5aaa26358578dd2ac34.tar.gz
libayatana-indicator-19ec64915aac1ecf55f5b5aaa26358578dd2ac34.tar.bz2
libayatana-indicator-19ec64915aac1ecf55f5b5aaa26358578dd2ac34.zip
[ William Hua ]
* debian/control: - Bump GLib to 2.37. * configure.ac: - Bump GLib to 2.37. * libindicator/indicator-image-helper.c: - Support display of GBytesIcons. * libindicator/indicator-ng.c: - Change action state icon type to GVariant.
Diffstat (limited to 'libindicator')
-rw-r--r--libindicator/indicator-image-helper.c57
-rw-r--r--libindicator/indicator-ng.c39
2 files changed, 72 insertions, 24 deletions
diff --git a/libindicator/indicator-image-helper.c b/libindicator/indicator-image-helper.c
index 382d0c9..ab09050 100644
--- a/libindicator/indicator-image-helper.c
+++ b/libindicator/indicator-image-helper.c
@@ -63,25 +63,60 @@ refresh_image (GtkImage * image)
icon_filename = gtk_icon_info_get_filename(icon_info);
}
- /* show a broken image if we don't have a filename */
- if (icon_filename == NULL) {
+ if (icon_filename == NULL && !G_IS_BYTES_ICON (icon_names)) {
+ /* show a broken image if we don't have a filename */
gtk_image_set_from_stock (image, GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_LARGE_TOOLBAR);
return;
}
/* Build a pixbuf */
GError * error = NULL;
- GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(icon_filename, &error);
+ GdkPixbuf * pixbuf = NULL;
- if (icon_info != NULL) {
- gtk_icon_info_free(icon_info);
- }
+ if (icon_filename == NULL) {
+ GInputStream * stream = g_loadable_icon_load (G_LOADABLE_ICON (icon_names), icon_size, NULL, NULL, &error);
- if (pixbuf == NULL) {
- g_warning("Unable to load icon from file '%s' because: %s", icon_filename, error == NULL ? "I don't know" : error->message);
- g_clear_error (&error);
- gtk_image_clear(image);
- return;
+ if (error == NULL) {
+ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &error);
+ }
+
+ if (error != NULL) {
+ if (stream != NULL) {
+ g_input_stream_close (stream, NULL, NULL);
+ g_object_unref (stream);
+ }
+
+ if (icon_info != NULL) {
+ g_object_unref (icon_info);
+ }
+
+ g_warning ("Unable to load icon from data: %s", error->message);
+ g_clear_error (&error);
+ gtk_image_clear (image);
+ return;
+ }
+
+ g_input_stream_close (stream, NULL, &error);
+
+ if (error != NULL) {
+ g_warning ("Unable to close input stream: %s", error->message);
+ g_clear_error (&error);
+ }
+
+ g_object_unref (stream);
+ } else {
+ pixbuf = gdk_pixbuf_new_from_file (icon_filename, &error);
+
+ if (icon_info != NULL) {
+ g_object_unref (icon_info);
+ }
+
+ if (pixbuf == NULL) {
+ g_warning ("Unable to load icon from file '%s' because: %s", icon_filename, error == NULL ? "I don't know" : error->message);
+ g_clear_error (&error);
+ gtk_image_clear (image);
+ return;
+ }
}
/* Scale icon if all we get is something too big. */
diff --git a/libindicator/indicator-ng.c b/libindicator/indicator-ng.c
index 1e95785..966e93f 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);
}
}
@@ -236,9 +236,9 @@ static void
indicator_ng_update_entry (IndicatorNg *self)
{
GVariant *state;
- const gchar *label = NULL;
- const gchar *iconstr = NULL;
- const gchar *accessible_desc = NULL;
+ gchar *label = NULL;
+ GVariant *icon = NULL;
+ gchar *accessible_desc = NULL;
gboolean visible = TRUE;
g_return_if_fail (self->menu != NULL);
@@ -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,17 @@ 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);
+ g_free (accessible_desc);
+ g_free (label);
+
+ if (icon)
+ g_variant_unref (icon);
if (state)
g_variant_unref (state);
}