diff options
Diffstat (limited to 'src/indicator-printers.c')
-rw-r--r-- | src/indicator-printers.c | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/src/indicator-printers.c b/src/indicator-printers.c index 3a642ac..6ae984c 100644 --- a/src/indicator-printers.c +++ b/src/indicator-printers.c @@ -79,6 +79,55 @@ indicator_printers_class_init (IndicatorPrintersClass *klass) } +static GdkPixbuf * +gdk_pixbuf_new_from_encoded_data (guchar *data, + gsize length) +{ + GInputStream * input; + GError *err = NULL; + GdkPixbuf *img; + + input = g_memory_input_stream_new_from_data(data, length, NULL); + if (input == NULL) + return NULL; + + img = gdk_pixbuf_new_from_stream(input, NULL, &err); + if (err) { + g_warning("%s", err->message); + g_error_free(err); + } + + g_object_unref(input); + return img; +} + + +static GdkPixbuf * +g_variant_get_image (GVariant *value) +{ + const gchar *strvalue = NULL; + gsize length = 0; + guchar *icondata; + GdkPixbuf *img; + + if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) + strvalue = g_variant_get_string(value, NULL); + + if (!strvalue || !*strvalue) { + g_warning ("%s: value does not contain a base64 encoded image", + __func__); + return NULL; + } + + icondata = g_base64_decode(strvalue, &length); + img = gdk_pixbuf_new_from_encoded_data (icondata, length); + + g_free(icondata); + return img; +} + + + static gboolean is_string_property (const gchar *name, const gchar *prop, @@ -89,6 +138,16 @@ is_string_property (const gchar *name, } +static gboolean +is_image_property (const gchar *name, + const gchar *prop, + GVariant *value) +{ + return !g_strcmp0 (name, prop) && + g_variant_is_of_type (value, G_VARIANT_TYPE_STRING); +} + + static void indicator_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, @@ -101,6 +160,13 @@ indicator_prop_change_cb (DbusmenuMenuitem *mi, indicator_menu_item_set_label (menuitem, g_variant_get_string (value, NULL)); else if (is_string_property (prop, "indicator-right", value)) indicator_menu_item_set_right (menuitem, g_variant_get_string (value, NULL)); + else if (is_string_property (prop, "indicator-icon-name", value)) + indicator_menu_item_set_icon_name (menuitem, g_variant_get_string (value, NULL)); + else if (is_image_property (prop, "indicator-icon", value)) { + GdkPixbuf *pb = g_variant_get_image (value); + indicator_menu_item_set_icon (menuitem, pb); + g_object_unref (pb); + } } @@ -111,18 +177,27 @@ new_indicator_item (DbusmenuMenuitem *newitem, gpointer user_data) { GtkWidget *menuitem; - const gchar *text, *right_text; + const gchar *icon_name, *text, *right_text; + GVariant *icon; gboolean is_lozenge; + icon_name = dbusmenu_menuitem_property_get (newitem, "indicator-icon-name"); + icon = dbusmenu_menuitem_property_get_variant (newitem, "indicator-icon"); text = dbusmenu_menuitem_property_get (newitem, "indicator-label"); right_text = dbusmenu_menuitem_property_get (newitem, "indicator-right"); is_lozenge = dbusmenu_menuitem_property_get_bool (newitem, "indicator-right-is-lozenge"); menuitem = g_object_new (INDICATOR_TYPE_MENU_ITEM, + "icon-name", icon_name, "label", text, "right", right_text, "right-is-lozenge", is_lozenge, NULL); + if (icon) { + GdkPixbuf *pb = g_variant_get_image (icon); + indicator_menu_item_set_icon (INDICATOR_MENU_ITEM (menuitem), pb); + g_object_unref (pb); + } gtk_widget_show_all (menuitem); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), |