summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/gdk-pixbuf.c
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2016-06-25 19:43:06 +0200
committerMatthias Clasen <mclasen@redhat.com>2016-08-02 14:49:36 -0400
commit4d05ef0cd85adae74d65c67c8849013b31e194f5 (patch)
tree896926a72547992b259f031253e18e270e0a527d /gdk-pixbuf/gdk-pixbuf.c
parentf2206a38a9a2d90b65e4095294f8505068081bb8 (diff)
downloadgdk-pixbuf-4d05ef0cd85adae74d65c67c8849013b31e194f5.tar.gz
gdk-pixbuf: Add gdk_pixbuf_remove_option() helper
https://bugzilla.gnome.org/show_bug.cgi?id=768043
Diffstat (limited to 'gdk-pixbuf/gdk-pixbuf.c')
-rw-r--r--gdk-pixbuf/gdk-pixbuf.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c
index 8b0dad7d0..e7e389dc1 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.