aboutsummaryrefslogtreecommitdiff
path: root/libindicator
diff options
context:
space:
mode:
Diffstat (limited to 'libindicator')
-rw-r--r--libindicator/indicator-image-helper.c68
-rw-r--r--libindicator/indicator-ng.c32
2 files changed, 66 insertions, 34 deletions
diff --git a/libindicator/indicator-image-helper.c b/libindicator/indicator-image-helper.c
index 382d0c9..aff9e39 100644
--- a/libindicator/indicator-image-helper.c
+++ b/libindicator/indicator-image-helper.c
@@ -63,42 +63,64 @@ 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 or image data */
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) {
+ GError * error = NULL;
+ GInputStream * stream = g_loadable_icon_load (G_LOADABLE_ICON (icon_names), icon_size, NULL, NULL, &error);
+
+ if (stream != NULL) {
+ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &error);
+ g_input_stream_close (stream, NULL, NULL);
+ g_object_unref (stream);
+
+ if (pixbuf == NULL) {
+ g_warning ("Unable to load icon from data: %s", error->message);
+ g_error_free (error);
+ }
+ } else {
+ g_warning ("Unable to load icon from data: %s", error->message);
+ g_error_free (error);
+ }
+ } else {
+ GError * error = NULL;
- 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;
+ pixbuf = gdk_pixbuf_new_from_file (icon_filename, &error);
+
+ if (pixbuf == NULL) {
+ g_warning ("Unable to load icon from file '%s': %s", icon_filename, error->message);
+ g_error_free (error);
+ }
}
- /* Scale icon if all we get is something too big. */
- if (gdk_pixbuf_get_height(pixbuf) > icon_size) {
- gfloat scale = (gfloat)icon_size / (gfloat)gdk_pixbuf_get_height(pixbuf);
- gint width = round(gdk_pixbuf_get_width(pixbuf) * scale);
+ if (pixbuf != NULL) {
+ /* Scale icon if all we get is something too big. */
+ if (gdk_pixbuf_get_height(pixbuf) > icon_size) {
+ gfloat scale = (gfloat)icon_size / (gfloat)gdk_pixbuf_get_height(pixbuf);
+ gint width = round(gdk_pixbuf_get_width(pixbuf) * scale);
+
+ GdkPixbuf * scaled = gdk_pixbuf_scale_simple(pixbuf, width, icon_size, GDK_INTERP_BILINEAR);
+ g_object_unref(G_OBJECT(pixbuf));
+ pixbuf = scaled;
+ }
- GdkPixbuf * scaled = gdk_pixbuf_scale_simple(pixbuf, width, icon_size, GDK_INTERP_BILINEAR);
+ /* Put the pixbuf on the image */
+ gtk_image_set_from_pixbuf(image, pixbuf);
g_object_unref(G_OBJECT(pixbuf));
- pixbuf = scaled;
+ } else {
+ gtk_image_set_from_stock (image, GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_LARGE_TOOLBAR);
}
- /* Put the pixbuf on the image */
- gtk_image_set_from_pixbuf(image, pixbuf);
- g_object_unref(G_OBJECT(pixbuf));
-
- return;
+ if (icon_info != NULL) {
+ gtk_icon_info_free (icon_info);
+ }
}
/* Handles the theme changed signal to refresh the icon to make
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);
}