[gnome-remote-desktop] Add clipboard class



commit f26dbc9b7738cc03397a52172e2489735a1acb94
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Tue Aug 11 17:39:52 2020 +0200

    Add clipboard class
    
    In order to have a clipboard implementation for g-r-d that works with
    both the RDP- and VNC-backend, add a clipboard class, which will then
    be derived from the RDP- and VNC-clipboard class.
    Also add APIs to be able to handle SelectionOwnerChanged- and
    SelectionTransfer-signals.

 src/grd-clipboard.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/grd-clipboard.h |  50 ++++++++++++++++++++++++
 src/grd-types.h     |   1 +
 src/meson.build     |   2 +
 4 files changed, 163 insertions(+)
---
diff --git a/src/grd-clipboard.c b/src/grd-clipboard.c
new file mode 100644
index 0000000..a8f87f8
--- /dev/null
+++ b/src/grd-clipboard.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2020 Pascal Nowack
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "grd-clipboard.h"
+
+typedef struct _GrdClipboardPrivate
+{
+  GrdSession *session;
+
+  GHashTable *client_mime_type_tables;
+} GrdClipboardPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GrdClipboard, grd_clipboard, G_TYPE_OBJECT);
+
+void
+grd_clipboard_update_client_mime_type_list (GrdClipboard *clipboard,
+                                            GList        *mime_type_list)
+{
+  GrdClipboardClass *klass = GRD_CLIPBOARD_GET_CLASS (clipboard);
+  GrdClipboardPrivate *priv = grd_clipboard_get_instance_private (clipboard);
+  GList *l;
+
+  if (!klass->update_client_mime_type_list)
+    return;
+
+  for (l = mime_type_list; l; l = l->next)
+    g_hash_table_remove (priv->client_mime_type_tables, l->data);
+
+  klass->update_client_mime_type_list (clipboard, mime_type_list);
+}
+
+uint8_t *
+grd_clipboard_request_client_content_for_mime_type (GrdClipboard *clipboard,
+                                                    GrdMimeType   mime_type,
+                                                    uint32_t     *size)
+{
+  GrdClipboardClass *klass = GRD_CLIPBOARD_GET_CLASS (clipboard);
+  GrdClipboardPrivate *priv = grd_clipboard_get_instance_private (clipboard);
+  GrdMimeTypeTable *mime_type_table = NULL;
+  uint8_t *mime_type_content = NULL;
+
+  *size = 0;
+
+  if (!klass->request_client_content_for_mime_type)
+    return NULL;
+
+  mime_type_table = g_hash_table_lookup (priv->client_mime_type_tables,
+                                         GUINT_TO_POINTER (mime_type));
+  if (mime_type_table)
+    {
+      mime_type_content = klass->request_client_content_for_mime_type (
+                            clipboard, mime_type_table, size);
+    }
+
+  return mime_type_content;
+}
+
+static void
+free_mime_type_table (gpointer data)
+{
+  GrdMimeTypeTable *mime_type_table = data;
+
+  g_free (mime_type_table);
+}
+
+static void
+grd_clipboard_dispose (GObject *object)
+{
+  GrdClipboard *clipboard = GRD_CLIPBOARD (object);
+  GrdClipboardPrivate *priv = grd_clipboard_get_instance_private (clipboard);
+
+  g_clear_pointer (&priv->client_mime_type_tables, g_hash_table_destroy);
+
+  G_OBJECT_CLASS (grd_clipboard_parent_class)->dispose (object);
+}
+
+static void
+grd_clipboard_init (GrdClipboard *clipboard)
+{
+  GrdClipboardPrivate *priv = grd_clipboard_get_instance_private (clipboard);
+
+  priv->client_mime_type_tables = g_hash_table_new_full (NULL, NULL, NULL,
+                                                         free_mime_type_table);
+}
+
+static void
+grd_clipboard_class_init (GrdClipboardClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = grd_clipboard_dispose;
+}
diff --git a/src/grd-clipboard.h b/src/grd-clipboard.h
new file mode 100644
index 0000000..c77746e
--- /dev/null
+++ b/src/grd-clipboard.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2020 Pascal Nowack
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef GRD_CLIPBOARD_H
+#define GRD_CLIPBOARD_H
+
+#include <glib-object.h>
+#include <stdint.h>
+
+#include "grd-mime-type.h"
+#include "grd-types.h"
+
+#define GRD_TYPE_CLIPBOARD (grd_clipboard_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GrdClipboard, grd_clipboard, GRD, CLIPBOARD, GObject);
+
+struct _GrdClipboardClass
+{
+  GObjectClass parent_class;
+
+  void (*update_client_mime_type_list) (GrdClipboard *clipboard,
+                                        GList        *mime_type_list);
+  uint8_t *(*request_client_content_for_mime_type) (GrdClipboard     *clipboard,
+                                                    GrdMimeTypeTable *mime_type_table,
+                                                    uint32_t         *size);
+};
+
+void grd_clipboard_update_client_mime_type_list (GrdClipboard *clipboard,
+                                                 GList        *mime_type_list);
+
+uint8_t *grd_clipboard_request_client_content_for_mime_type (GrdClipboard *clipboard,
+                                                             GrdMimeType   mime_type,
+                                                             uint32_t     *size);
+
+#endif /* GRD_CLIPBOARD_H */
diff --git a/src/grd-types.h b/src/grd-types.h
index 96c3a6a..028c151 100644
--- a/src/grd-types.h
+++ b/src/grd-types.h
@@ -24,6 +24,7 @@
 #define GRD_TYPES_H
 
 typedef struct _GrdContext GrdContext;
+typedef struct _GrdClipboard GrdClipboard;
 typedef struct _GrdRdpSAMFile GrdRdpSAMFile;
 typedef struct _GrdRdpServer GrdRdpServer;
 typedef struct _GrdSession GrdSession;
diff --git a/src/meson.build b/src/meson.build
index 967c740..d281fbd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,4 +1,6 @@
 daemon_sources = files([
+  'grd-clipboard.c',
+  'grd-clipboard.h',
   'grd-context.c',
   'grd-context.h',
   'grd-daemon.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]