[gtk+/wip/otte/clipboard: 87/102] clipboard: Add infrastructure to store clipboards
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/clipboard: 87/102] clipboard: Add infrastructure to store clipboards
- Date: Sat, 2 Dec 2017 15:35:55 +0000 (UTC)
commit d1f12777e7a61d11bf36101d6044f3c943e76c98
Author: Benjamin Otte <otte redhat com>
Date: Wed Nov 29 23:23:36 2017 +0100
clipboard: Add infrastructure to store clipboards
Clipboard managers will be so happy once the backends actually implement
it!
gdk/gdkclipboard.c | 119 +++++++++++++++++++++++++++++++++++++++++++++
gdk/gdkclipboard.h | 11 ++++
gdk/gdkclipboardprivate.h | 8 +++
3 files changed, 138 insertions(+), 0 deletions(-)
---
diff --git a/gdk/gdkclipboard.c b/gdk/gdkclipboard.c
index b51e99a..1e723d3 100644
--- a/gdk/gdkclipboard.c
+++ b/gdk/gdkclipboard.c
@@ -187,6 +187,44 @@ gdk_clipboard_real_claim (GdkClipboard *clipboard,
}
static void
+gdk_clipboard_store_default_async (GdkClipboard *clipboard,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
+ GTask *task;
+
+ task = g_task_new (clipboard, cancellable, callback, user_data);
+ g_task_set_priority (task, io_priority);
+ g_task_set_source_tag (task, gdk_clipboard_store_default_async);
+
+ if (priv->local)
+ {
+ g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("This clipboard cannot store data."));
+ }
+ else
+ {
+ g_task_return_boolean (task, TRUE);
+ }
+
+ g_object_unref (task);
+}
+
+static gboolean
+gdk_clipboard_store_default_finish (GdkClipboard *clipboard,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (g_task_is_valid (result, clipboard), FALSE);
+ g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gdk_clipboard_store_default_async, FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
+
+static void
gdk_clipboard_read_local_write_done (GObject *clipboard,
GAsyncResult *result,
gpointer stream)
@@ -283,6 +321,8 @@ gdk_clipboard_class_init (GdkClipboardClass *class)
object_class->finalize = gdk_clipboard_finalize;
class->claim = gdk_clipboard_real_claim;
+ class->store_async = gdk_clipboard_store_default_async;
+ class->store_finish = gdk_clipboard_store_default_finish;
class->read_async = gdk_clipboard_read_local_async;
class->read_finish = gdk_clipboard_read_local_finish;
@@ -451,6 +491,84 @@ gdk_clipboard_get_content (GdkClipboard *clipboard)
return priv->content;
}
+/**
+ * gdk_clipboard_store_async:
+ * @clipboard: a #GdkClipboard
+ * @io_priority: the [I/O priority][io-priority]
+ * of the request.
+ * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
+ * @callback: (scope async): callback to call when the request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * Asynchronously instructs the @clipboard to store its contents remotely to
+ * preserve them for later usage. If the clipboard is not local, this function
+ * does nothing but report success.
+ *
+ * This function is called automatically when gtk_main() or #GtkApplication
+ * exit, so you likely don't need to call it.
+ **/
+void
+gdk_clipboard_store_async (GdkClipboard *clipboard,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
+
+ g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+ g_return_if_fail (callback != NULL);
+
+ if (priv->local)
+ {
+ return GDK_CLIPBOARD_GET_CLASS (clipboard)->store_async (clipboard,
+ io_priority,
+ cancellable,
+ callback,
+ user_data);
+ }
+ else
+ {
+ return gdk_clipboard_store_default_async (clipboard,
+ io_priority,
+ cancellable,
+ callback,
+ user_data);
+ }
+}
+
+/**
+ * gdk_clipboard_store_finish:
+ * @clipboard: a #GdkClipboard
+ * @result: a #GAsyncResult
+ * @error: a #GError location to store the error occurring, or %NULL to
+ * ignore.
+ *
+ * Finishes an asynchronous clipboard store started with gdk_clipboard_store_async().
+ *
+ * Returns: %TRUE if storing was successful.
+ **/
+gboolean
+gdk_clipboard_store_finish (GdkClipboard *clipboard,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (GDK_IS_CLIPBOARD (clipboard), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ /* don't check priv->local here because it might have changed while the
+ * read was ongoing */
+ if (g_async_result_is_tagged (result, gdk_clipboard_store_default_async))
+ {
+ return gdk_clipboard_store_default_finish (clipboard, result, error);
+ }
+ else
+ {
+ return GDK_CLIPBOARD_GET_CLASS (clipboard)->store_finish (clipboard, result, error);
+ }
+}
+
static void
gdk_clipboard_read_internal (GdkClipboard *clipboard,
GdkContentFormats *formats,
@@ -511,6 +629,7 @@ gdk_clipboard_read_async (GdkClipboard *clipboard,
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
g_return_if_fail (mime_types != NULL && mime_types[0] != NULL);
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
g_return_if_fail (callback != NULL);
formats = gdk_content_formats_new (mime_types, g_strv_length ((char **) mime_types));
diff --git a/gdk/gdkclipboard.h b/gdk/gdkclipboard.h
index 61dad18..87f873a 100644
--- a/gdk/gdkclipboard.h
+++ b/gdk/gdkclipboard.h
@@ -47,6 +47,17 @@ GDK_AVAILABLE_IN_3_94
GdkContentProvider * gdk_clipboard_get_content (GdkClipboard *clipboard);
GDK_AVAILABLE_IN_3_94
+void gdk_clipboard_store_async (GdkClipboard *clipboard,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+GDK_AVAILABLE_IN_3_94
+gboolean gdk_clipboard_store_finish (GdkClipboard *clipboard,
+ GAsyncResult *result,
+ GError **error);
+
+GDK_AVAILABLE_IN_3_94
void gdk_clipboard_read_async (GdkClipboard *clipboard,
const char **mime_types,
int io_priority,
diff --git a/gdk/gdkclipboardprivate.h b/gdk/gdkclipboardprivate.h
index ec6dc20..1a511a1 100644
--- a/gdk/gdkclipboardprivate.h
+++ b/gdk/gdkclipboardprivate.h
@@ -45,6 +45,14 @@ struct _GdkClipboardClass
GdkContentFormats *formats,
gboolean local,
GdkContentProvider *content);
+ void (* store_async) (GdkClipboard *clipboard,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (* store_finish) (GdkClipboard *clipboard,
+ GAsyncResult *result,
+ GError **error);
void (* read_async) (GdkClipboard *clipboard,
GdkContentFormats *formats,
int io_priority,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]