[gdk-pixbuf] gdk-pixbuf: Add gdk_pixbuf_remove_option() helper
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf] gdk-pixbuf: Add gdk_pixbuf_remove_option() helper
- Date: Tue, 2 Aug 2016 18:51:26 +0000 (UTC)
commit 4d05ef0cd85adae74d65c67c8849013b31e194f5
Author: Bastien Nocera <hadess hadess net>
Date: Sat Jun 25 19:43:06 2016 +0200
gdk-pixbuf: Add gdk_pixbuf_remove_option() helper
https://bugzilla.gnome.org/show_bug.cgi?id=768043
gdk-pixbuf/gdk-pixbuf-core.h | 3 ++
gdk-pixbuf/gdk-pixbuf.c | 66 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/gdk-pixbuf/gdk-pixbuf-core.h b/gdk-pixbuf/gdk-pixbuf-core.h
index 30ef57e..ae3bf1a 100644
--- a/gdk-pixbuf/gdk-pixbuf-core.h
+++ b/gdk-pixbuf/gdk-pixbuf-core.h
@@ -537,6 +537,9 @@ GdkPixbuf *gdk_pixbuf_apply_embedded_orientation (GdkPixbuf *src);
GDK_PIXBUF_AVAILABLE_IN_ALL
const gchar * gdk_pixbuf_get_option (GdkPixbuf *pixbuf,
const gchar *key);
+GDK_PIXBUF_AVAILABLE_IN_2_36
+gboolean gdk_pixbuf_remove_option (GdkPixbuf *pixbuf,
+ const gchar *key);
GDK_PIXBUF_AVAILABLE_IN_2_32
GHashTable * gdk_pixbuf_get_options (GdkPixbuf *pixbuf);
GDK_PIXBUF_AVAILABLE_IN_2_36
diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c
index 8b0dad7..e7e389d 100644
--- a/gdk-pixbuf/gdk-pixbuf.c
+++ b/gdk-pixbuf/gdk-pixbuf.c
@@ -970,6 +970,72 @@ gdk_pixbuf_get_options (GdkPixbuf *pixbuf)
}
/**
+ * gdk_pixbuf_remove_option:
+ * @pixbuf: a #GdkPixbuf
+ * @key: a nul-terminated string representing the key to remove.
+ *
+ * Remove the key/value pair option attached to a #GdkPixbuf.
+ *
+ * Return value: %TRUE if an option was removed, %FALSE if not.
+ *
+ * Since: 2.36
+ **/
+gboolean
+gdk_pixbuf_remove_option (GdkPixbuf *pixbuf,
+ const gchar *key)
+{
+ GQuark quark;
+ gchar **options;
+ guint n;
+ GPtrArray *array;
+ gboolean found;
+
+ g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
+
+ quark = g_quark_from_static_string ("gdk_pixbuf_options");
+
+ options = g_object_get_qdata (G_OBJECT (pixbuf), quark);
+ if (!options)
+ return FALSE;
+
+ g_object_steal_qdata (G_OBJECT (pixbuf), quark);
+
+ /* There's at least a nul-terminator */
+ array = g_ptr_array_new_full (1, g_free);
+
+ found = FALSE;
+ for (n = 0; options[2*n]; n++) {
+ if (strcmp (options[2*n], key) != 0) {
+ g_ptr_array_add (array, g_strdup (options[2*n])); /* key */
+ g_ptr_array_add (array, g_strdup (options[2*n+1])); /* value */
+ } else {
+ found = TRUE;
+ }
+ }
+
+ if (array->len == 0) {
+ g_ptr_array_unref (array);
+ g_strfreev (options);
+ return found;
+ }
+
+ if (!found) {
+ g_ptr_array_free (array, TRUE);
+ g_object_set_qdata_full (G_OBJECT (pixbuf), quark,
+ options, (GDestroyNotify) g_strfreev);
+ return FALSE;
+ }
+
+ g_ptr_array_add (array, NULL);
+ g_object_set_qdata_full (G_OBJECT (pixbuf), quark,
+ g_ptr_array_free (array, FALSE), (GDestroyNotify) g_strfreev);
+ g_strfreev (options);
+
+ return TRUE;
+}
+
+/**
* gdk_pixbuf_set_option:
* @pixbuf: a #GdkPixbuf
* @key: a nul-terminated string.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]