Commit 3023d254 authored by Benjamin Otte's avatar Benjamin Otte
Browse files

clipboard: Make value getters set the passed in value

Don't return a const GValue, that's ugly API. Instead require people to
pass in a preinitialized GValue and set that one.
parent 9b78d768
......@@ -347,13 +347,14 @@ gdk_clipboard_read_value_done (GObject *source,
GTask *task = data;
GError *error = NULL;
const GValue *value;
GValue *value;
value = g_task_get_task_data (task);
value = gdk_content_deserialize_finish (result, &error);
if (value == NULL)
if (!gdk_content_deserialize_finish (result, value, &error))
g_task_return_error (task, error);
g_task_return_pointer (task, (gpointer) value, NULL);
g_task_return_pointer (task, value, NULL);
g_object_unref (task);
......@@ -377,7 +378,7 @@ gdk_clipboard_read_value_got_stream (GObject *source,
gdk_content_deserialize_async (stream,
GPOINTER_TO_SIZE (g_task_get_task_data (task)),
G_VALUE_TYPE (g_task_get_task_data (task)),
g_task_get_priority (task),
g_task_get_cancellable (task),
......@@ -385,6 +386,13 @@ gdk_clipboard_read_value_got_stream (GObject *source,
g_object_unref (stream);
static void
free_value (gpointer value)
g_value_unset (value);
g_slice_free (GValue, value);
static void
gdk_clipboard_read_value_internal (GdkClipboard *clipboard,
GType type,
......@@ -396,6 +404,7 @@ gdk_clipboard_read_value_internal (GdkClipboard *clipboard,
GdkContentFormatsBuilder *builder;
GdkContentFormats *formats;
GValue *value;
GTask *task;
builder = gdk_content_formats_builder_new ();
......@@ -406,7 +415,9 @@ gdk_clipboard_read_value_internal (GdkClipboard *clipboard,
task = g_task_new (clipboard, cancellable, callback, user_data);
g_task_set_priority (task, io_priority);
g_task_set_source_tag (task, source_tag);
g_task_set_task_data (task, GSIZE_TO_POINTER (type), NULL);
value = g_slice_new0 (GValue);
g_value_init (value, type);
g_task_set_task_data (task, value, free_value);
gdk_clipboard_read_internal (clipboard,
......@@ -380,25 +380,27 @@ gdk_content_deserialize_async (GInputStream *stream,
const GValue *
gdk_content_deserialize_finish (GAsyncResult *result,
GValue *value,
GError **error)
GdkContentDeserializer *deserializer;
g_return_val_if_fail (GDK_IS_CONTENT_DESERIALIZER (result), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
g_return_val_if_fail (GDK_IS_CONTENT_DESERIALIZER (result), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
deserializer = GDK_CONTENT_DESERIALIZER (result);
g_return_val_if_fail (G_VALUE_HOLDS (value, G_VALUE_TYPE (&deserializer->value)), FALSE);
if (deserializer->error)
if (error)
*error = g_error_copy (deserializer->error);
return NULL;
return FALSE;
return &deserializer->value;
g_value_copy (&deserializer->value, value);
return TRUE;
......@@ -81,7 +81,8 @@ void gdk_content_deserialize_async (GInputS
GAsyncReadyCallback callback,
gpointer user_data);
const GValue * gdk_content_deserialize_finish (GAsyncResult *result,
gboolean gdk_content_deserialize_finish (GAsyncResult *result,
GValue *value,
GError **error);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment