diff options
author | Ted Gould <ted@canonical.com> | 2009-09-02 13:44:40 -0500 |
---|---|---|
committer | Ted Gould <ted@canonical.com> | 2009-09-02 13:44:40 -0500 |
commit | 1f70c55fcaab52f5d81650b98c05fec134861b9f (patch) | |
tree | 92e9054d30d217d6503cdde7a81246478b75d244 | |
parent | 9cdda2c381c667563edce05889dd6cfb735cf020 (diff) | |
download | libdbusmenu-1f70c55fcaab52f5d81650b98c05fec134861b9f.tar.gz libdbusmenu-1f70c55fcaab52f5d81650b98c05fec134861b9f.tar.bz2 libdbusmenu-1f70c55fcaab52f5d81650b98c05fec134861b9f.zip |
Fleshing out the get function again stealing code from libindicate-gtk.
-rw-r--r-- | libdbusmenu-gtk/menuitem.c | 36 |
1 files changed, 35 insertions, 1 deletions
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; } |