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.
This commit is contained in:
Benjamin Otte 2017-11-24 06:07:09 +01:00
parent 9b78d76873
commit 3023d254dd
3 changed files with 27 additions and 13 deletions

View File

@ -347,13 +347,14 @@ gdk_clipboard_read_value_done (GObject *source,
{
GTask *task = data;
GError *error = NULL;
const GValue *value;
GValue *value;
value = gdk_content_deserialize_finish (result, &error);
if (value == NULL)
value = g_task_get_task_data (task);
if (!gdk_content_deserialize_finish (result, value, &error))
g_task_return_error (task, error);
else
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,
mime_type,
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),
gdk_clipboard_read_value_done,
@ -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,
formats,

View File

@ -380,25 +380,27 @@ gdk_content_deserialize_async (GInputStream *stream,
user_data);
}
const GValue *
gboolean
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;
}
/*** DESERIALIZERS ***/

View File

@ -81,7 +81,8 @@ void gdk_content_deserialize_async (GInputS
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_3_94
const GValue * gdk_content_deserialize_finish (GAsyncResult *result,
gboolean gdk_content_deserialize_finish (GAsyncResult *result,
GValue *value,
GError **error);