[gnome-remote-desktop] Add GrdMimeType



commit d6958d2807d59e45395cc2f18c6c4217c458a42d
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Fri Aug 7 19:22:43 2020 +0200

    Add GrdMimeType
    
    In order to be able to handle external clipboard formats from RDP and
    VNC, use an internal mime type, which does not depend on the other
    clipboard implementations.
    This internal mime type is represented by an enum.
    Also add functions to transform a mimestring into GrdMimeType and vice
    versa.

 src/grd-mime-type.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/grd-mime-type.h | 48 +++++++++++++++++++++++++++++
 src/meson.build     |  2 ++
 3 files changed, 137 insertions(+)
---
diff --git a/src/grd-mime-type.c b/src/grd-mime-type.c
new file mode 100644
index 0000000..7da7e7d
--- /dev/null
+++ b/src/grd-mime-type.c
@@ -0,0 +1,87 @@
+/*
+ * 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-mime-type.h"
+
+#include <gio/gio.h>
+
+const char *
+grd_mime_type_to_string (GrdMimeType mime_type)
+{
+  switch (mime_type)
+    {
+    case GRD_MIME_TYPE_TEXT_PLAIN:
+      return "text/plain";
+    case GRD_MIME_TYPE_TEXT_PLAIN_UTF8:
+      return "text/plain;charset=utf-8";
+    case GRD_MIME_TYPE_TEXT_UTF8_STRING:
+      return "UTF8_STRING";
+    case GRD_MIME_TYPE_TEXT_HTML:
+      return "text/html";
+    case GRD_MIME_TYPE_IMAGE_BMP:
+      return "image/bmp";
+    case GRD_MIME_TYPE_IMAGE_TIFF:
+      return "image/tiff";
+    case GRD_MIME_TYPE_IMAGE_GIF:
+      return "image/gif";
+    case GRD_MIME_TYPE_IMAGE_JPEG:
+      return "image/jpeg";
+    case GRD_MIME_TYPE_IMAGE_PNG:
+      return "image/png";
+    case GRD_MIME_TYPE_TEXT_URILIST:
+      return "text/uri-list";
+    case GRD_MIME_TYPE_XS_GNOME_COPIED_FILES:
+      return "x-special/gnome-copied-files";
+    default:
+      return NULL;
+    }
+
+  g_assert_not_reached ();
+}
+
+GrdMimeType
+grd_mime_type_from_string (const char *mime_type_string)
+{
+  if (strcmp (mime_type_string, "text/plain") == 0)
+    return GRD_MIME_TYPE_TEXT_PLAIN;
+  else if (strcmp (mime_type_string, "text/plain;charset=utf-8") == 0)
+    return GRD_MIME_TYPE_TEXT_PLAIN_UTF8;
+  else if (strcmp (mime_type_string, "UTF8_STRING") == 0)
+    return GRD_MIME_TYPE_TEXT_UTF8_STRING;
+  else if (strcmp (mime_type_string, "text/html") == 0)
+    return GRD_MIME_TYPE_TEXT_HTML;
+  else if (strcmp (mime_type_string, "image/bmp") == 0)
+    return GRD_MIME_TYPE_IMAGE_BMP;
+  else if (strcmp (mime_type_string, "image/tiff") == 0)
+    return GRD_MIME_TYPE_IMAGE_TIFF;
+  else if (strcmp (mime_type_string, "image/gif") == 0)
+    return GRD_MIME_TYPE_IMAGE_GIF;
+  else if (strcmp (mime_type_string, "image/jpeg") == 0)
+    return GRD_MIME_TYPE_IMAGE_JPEG;
+  else if (strcmp (mime_type_string, "image/png") == 0)
+    return GRD_MIME_TYPE_IMAGE_PNG;
+  else if (strcmp (mime_type_string, "text/uri-list") == 0)
+    return GRD_MIME_TYPE_TEXT_URILIST;
+  else if (strcmp (mime_type_string, "x-special/gnome-copied-files") == 0)
+    return GRD_MIME_TYPE_XS_GNOME_COPIED_FILES;
+
+  return GRD_MIME_TYPE_NONE;
+}
diff --git a/src/grd-mime-type.h b/src/grd-mime-type.h
new file mode 100644
index 0000000..739b13f
--- /dev/null
+++ b/src/grd-mime-type.h
@@ -0,0 +1,48 @@
+/*
+ * 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_MIME_TYPE_H
+#define GRD_MIME_TYPE_H
+
+typedef enum _GrdMimeType
+{
+  GRD_MIME_TYPE_NONE,
+  GRD_MIME_TYPE_TEXT_PLAIN,            /* text/plain */
+  GRD_MIME_TYPE_TEXT_PLAIN_UTF8,       /* text/plain;charset=utf-8 */
+  GRD_MIME_TYPE_TEXT_UTF8_STRING,      /* UTF8_STRING */
+  GRD_MIME_TYPE_TEXT_HTML,             /* text/html */
+  GRD_MIME_TYPE_IMAGE_BMP,             /* image/bmp */
+  GRD_MIME_TYPE_IMAGE_TIFF,            /* image/tiff */
+  GRD_MIME_TYPE_IMAGE_GIF,             /* image/gif */
+  GRD_MIME_TYPE_IMAGE_JPEG,            /* image/jpeg */
+  GRD_MIME_TYPE_IMAGE_PNG,             /* image/png */
+  GRD_MIME_TYPE_TEXT_URILIST,          /* text/uri-list */
+  GRD_MIME_TYPE_XS_GNOME_COPIED_FILES, /* x-special/gnome-copied-files */
+} GrdMimeType;
+
+typedef struct _GrdMimeTypeTable
+{
+  GrdMimeType mime_type;
+} GrdMimeTypeTable;
+
+const char *grd_mime_type_to_string (GrdMimeType mime_type);
+
+GrdMimeType grd_mime_type_from_string (const char *mime_type_string);
+
+#endif /* GRD_MIME_TYPE_H */
diff --git a/src/meson.build b/src/meson.build
index f657cbb..967c740 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -5,6 +5,8 @@ daemon_sources = files([
   'grd-daemon.h',
   'grd-damage-utils.c',
   'grd-damage-utils.h',
+  'grd-mime-type.c',
+  'grd-mime-type.h',
   'grd-pipewire-utils.c',
   'grd-pipewire-utils.h',
   'grd-private.h',


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