From 1f70c55fcaab52f5d81650b98c05fec134861b9f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 2 Sep 2009 13:44:40 -0500 Subject: Fleshing out the get function again stealing code from libindicate-gtk. --- libdbusmenu-gtk/menuitem.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index f3d9668..48576f9 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -64,8 +64,42 @@ dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property) { + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), NULL); + g_return_val_if_fail(property != NULL && property[0] != '\0', NULL); + const gchar * value = dbusmenu_menuitem_property_get(menuitem, property); - return NULL; + /* There is no icon */ + if (value == NULL || value[0] == '\0') { + return NULL; + } + + gsize length = 0; + guchar * icondata = g_base64_decode(value, &length); + + GInputStream * input = g_memory_input_stream_new_from_data(icondata, length, NULL); + if (input == NULL) { + g_warning("Cound not create input stream from icon property data"); + g_free(icondata); + return NULL; + } + + GError * error = NULL; + GdkPixbuf * icon = gdk_pixbuf_new_from_stream(input, NULL, &error); + + if (error != NULL) { + g_warning("Unable to build Pixbuf from icon data: %s", error->message); + g_error_free(error); + } + + error = NULL; + g_input_stream_close(input, NULL, &error); + if (error != NULL) { + g_warning("Unable to close input stream: %s", error->message); + g_error_free(error); + } + g_free(icondata); + + return icon; } -- cgit v1.2.3