aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdbusmenu-glib/menuitem.c51
-rw-r--r--libdbusmenu-glib/menuitem.h2
-rw-r--r--libdbusmenu-gtk/menuitem.c14
3 files changed, 57 insertions, 10 deletions
diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c
index c9c7736..30ae277 100644
--- a/libdbusmenu-glib/menuitem.c
+++ b/libdbusmenu-glib/menuitem.c
@@ -1127,6 +1127,32 @@ dbusmenu_menuitem_property_set_int (DbusmenuMenuitem * mi, const gchar * propert
}
/**
+ * dbusmenu_menuitem_property_set_byte_array:
+ * @mi: The #DbusmenuMenuitem to set the property on.
+ * @property: Name of the property to set.
+ * @value: The byte array.
+ * @nelements: The number of elements in the byte array.
+ *
+ * Takes a byte array @value and sets it on @property as a
+ * property on @mi. If a property already exists by that name,
+ * then the value is set to the new value. If not, the property
+ * is added. If the value is changed or the property was previously
+ * unset then the signal #DbusmenuMenuitem::prop-changed will be
+ * emitted by this function.
+ *
+ * Return value: A boolean representing if the property value was set.
+ */
+gboolean
+dbusmenu_menuitem_property_set_byte_array (DbusmenuMenuitem * mi, const gchar * property, const guchar * value, gsize nelements)
+{
+ GVariant * variant = NULL;
+ if (value != NULL) {
+ variant = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, value, nelements, sizeof(guchar));
+ }
+ return dbusmenu_menuitem_property_set_variant(mi, property, variant);
+}
+
+/**
* dbusmenu_menuitem_property_set_variant:
* @mi: The #DbusmenuMenuitem to set the property on.
* @property: Name of the property to set.
@@ -1360,6 +1386,31 @@ dbusmenu_menuitem_property_get_int (DbusmenuMenuitem * mi, const gchar * propert
return 0;
}
+/**
+ * dbusmenu_menuitem_property_get_byte_array:
+ * @mi: The #DbusmenuMenuitem to look for the property on.
+ * @property: The property to grab.
+ * @nelements: A pointer to the location to store the number of items (out)
+ *
+ * Look up a property on @mi and return the value of it if
+ * it exits. #NULL will be returned if the property doesn't
+ * exist.
+ *
+ * Return value: (array length=nelements)(element-type guint8)(transfer none): A byte array with the
+ * value of the property that shouldn't be free'd. Or #NULL if the property
+ * is not set or is not a byte array.
+ */
+const guchar *
+dbusmenu_menuitem_property_get_byte_array (DbusmenuMenuitem * mi, const gchar * property, gsize * nelements)
+{
+ GVariant * variant = dbusmenu_menuitem_property_get_variant(mi, property);
+ if (variant == NULL) {
+ *nelements = 0;
+ return NULL;
+ }
+ if (!g_variant_type_equal(g_variant_get_type(variant), G_VARIANT_TYPE("ay"))) return NULL;
+ return g_variant_get_fixed_array(variant, nelements, sizeof(guchar));
+}
/**
* dbusmenu_menuitem_property_exist:
diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h
index 985e1a3..64dc87c 100644
--- a/libdbusmenu-glib/menuitem.h
+++ b/libdbusmenu-glib/menuitem.h
@@ -485,10 +485,12 @@ gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * pr
gboolean dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * property, GVariant * value);
gboolean dbusmenu_menuitem_property_set_bool (DbusmenuMenuitem * mi, const gchar * property, const gboolean value);
gboolean dbusmenu_menuitem_property_set_int (DbusmenuMenuitem * mi, const gchar * property, const gint value);
+gboolean dbusmenu_menuitem_property_set_byte_array (DbusmenuMenuitem * mi, const gchar * property, const guchar * value, gsize nelements);
const gchar * dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property);
GVariant * dbusmenu_menuitem_property_get_variant (DbusmenuMenuitem * mi, const gchar * property);
gboolean dbusmenu_menuitem_property_get_bool (DbusmenuMenuitem * mi, const gchar * property);
gint dbusmenu_menuitem_property_get_int (DbusmenuMenuitem * mi, const gchar * property);
+const guchar * dbusmenu_menuitem_property_get_byte_array (DbusmenuMenuitem * mi, const gchar * property, gsize * nelements);
gboolean dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property);
GList * dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi) G_GNUC_WARN_UNUSED_RESULT;
GHashTable * dbusmenu_menuitem_properties_copy (DbusmenuMenuitem * mi);
diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c
index 0f511bc..19ea1a0 100644
--- a/libdbusmenu-gtk/menuitem.c
+++ b/libdbusmenu-gtk/menuitem.c
@@ -66,11 +66,9 @@ dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar *
return FALSE;
}
- gchar * prop_str = g_base64_encode((guchar *)png_data, png_data_len);
gboolean propreturn = FALSE;
- propreturn = dbusmenu_menuitem_property_set(menuitem, property, prop_str);
+ propreturn = dbusmenu_menuitem_property_set_byte_array(menuitem, property, (guchar *)png_data, png_data_len);
- g_free(prop_str);
g_free(png_data);
return propreturn;
@@ -94,20 +92,17 @@ dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar *
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);
+ gsize length = 0;
+ const guchar * icondata = dbusmenu_menuitem_property_get_byte_array(menuitem, property, &length);
/* There is no icon */
- if (value == NULL || value[0] == '\0') {
+ if (length == 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;
}
@@ -120,7 +115,6 @@ dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar *
}
g_object_unref(input);
- g_free(icondata);
return icon;
}