Blame SOURCES/0001-sharing-Enable-settings-widget-for-gnome-remote-desk.patch

45708b
From f135d985e80c85e1578cd60eeb79bd974788031f Mon Sep 17 00:00:00 2001
45708b
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
45708b
Date: Wed, 14 Feb 2018 20:52:37 +0800
45708b
Subject: [PATCH] sharing: Enable settings widget for gnome-remote-desktop
45708b
45708b
Enable support for manipulating GNOME Remote Desktop settings. Settings
45708b
are done via the org.gnome.desktop.remote-desktop.vnc schema.
45708b
Configuring the VNC password is done via libsecret, thus libsecret is
45708b
added as a dependency.
45708b
---
45708b
 meson.build                              |   1 +
45708b
 panels/sharing/cc-gnome-remote-desktop.c | 171 +++++++++++++++++++++++
45708b
 panels/sharing/cc-gnome-remote-desktop.h |  49 +++++++
45708b
 panels/sharing/cc-sharing-panel.c        |  62 +++++++-
45708b
 panels/sharing/meson.build               |   3 +-
45708b
 5 files changed, 282 insertions(+), 4 deletions(-)
45708b
 create mode 100644 panels/sharing/cc-gnome-remote-desktop.c
45708b
 create mode 100644 panels/sharing/cc-gnome-remote-desktop.h
45708b
45708b
diff --git a/meson.build b/meson.build
45708b
index 84e04334c..3017b180a 100644
45708b
--- a/meson.build
45708b
+++ b/meson.build
45708b
@@ -109,6 +109,7 @@ pulse_mainloop_dep = dependency('libpulse-mainloop-glib', version: pulse_req_ver
45708b
 upower_glib_dep = dependency('upower-glib', version: '>= 0.99.6')
45708b
 x11_dep = dependency('x11')
45708b
 xi_dep = dependency('xi', version: '>= 1.2')
45708b
+libsecret_dep = dependency('libsecret-1')
45708b
 
45708b
 m_dep = cc.find_library('m')
45708b
 
45708b
diff --git a/panels/sharing/cc-gnome-remote-desktop.c b/panels/sharing/cc-gnome-remote-desktop.c
45708b
new file mode 100644
45708b
index 000000000..8420fddca
45708b
--- /dev/null
45708b
+++ b/panels/sharing/cc-gnome-remote-desktop.c
45708b
@@ -0,0 +1,171 @@
45708b
+/*
45708b
+ * Copyright (C) 2018 Red Hat, Inc.
45708b
+ *
45708b
+ * This program is free software; you can redistribute it and/or modify
45708b
+ * it under the terms of the GNU General Public License as published by
45708b
+ * the Free Software Foundation; either version 2 of the License, or
45708b
+ * (at your option) any later version.
45708b
+ *
45708b
+ * This program is distributed in the hope that it will be useful,
45708b
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
45708b
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45708b
+ * GNU General Public License for more details.
45708b
+ *
45708b
+ * You should have received a copy of the GNU General Public License
45708b
+ * along with this program; if not, write to the Free Software
45708b
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
45708b
+ *
45708b
+ */
45708b
+
45708b
+#include "config.h"
45708b
+
45708b
+#include "cc-gnome-remote-desktop.h"
45708b
+
45708b
+const SecretSchema *
45708b
+cc_grd_vnc_password_get_schema (void)
45708b
+{
45708b
+  static const SecretSchema grd_vnc_password_schema = {
45708b
+    .name = "org.gnome.RemoteDesktop.VncPassword",
45708b
+    .flags = SECRET_SCHEMA_NONE,
45708b
+    .attributes = {
45708b
+      { "password", SECRET_SCHEMA_ATTRIBUTE_STRING },
45708b
+      { "NULL", 0 },
45708b
+    },
45708b
+  };
45708b
+
45708b
+  return &grd_vnc_password_schema;
45708b
+}
45708b
+
45708b
+gboolean
45708b
+cc_grd_get_is_auth_method_prompt (GValue   *value,
45708b
+                                  GVariant *variant,
45708b
+                                  gpointer  user_data)
45708b
+{
45708b
+  const char * auth_method;
45708b
+
45708b
+  auth_method = g_variant_get_string (variant, NULL);
45708b
+
45708b
+  if (g_strcmp0 (auth_method, "prompt") == 0)
45708b
+    {
45708b
+      g_value_set_boolean (value, TRUE);
45708b
+    }
45708b
+  else if (g_strcmp0 (auth_method, "password") == 0)
45708b
+    {
45708b
+      g_value_set_boolean (value, FALSE);
45708b
+    }
45708b
+  else
45708b
+    {
45708b
+      g_warning ("Unhandled VNC auth method %s", auth_method);
45708b
+      g_value_set_boolean (value, FALSE);
45708b
+    }
45708b
+
45708b
+  return TRUE;
45708b
+}
45708b
+
45708b
+GVariant *
45708b
+cc_grd_set_is_auth_method_prompt (const GValue       *value,
45708b
+                                  const GVariantType *type,
45708b
+                                  gpointer            user_data)
45708b
+{
45708b
+  char *auth_method;
45708b
+
45708b
+  if (g_value_get_boolean (value))
45708b
+    auth_method = "prompt";
45708b
+  else
45708b
+    auth_method = "password";
45708b
+
45708b
+  return g_variant_new_string (auth_method);
45708b
+}
45708b
+
45708b
+gboolean
45708b
+cc_grd_get_is_auth_method_password (GValue   *value,
45708b
+                                    GVariant *variant,
45708b
+                                    gpointer  user_data)
45708b
+{
45708b
+  const char *auth_method;
45708b
+
45708b
+  auth_method = g_variant_get_string (variant, NULL);
45708b
+
45708b
+  if (g_strcmp0 (auth_method, "prompt") == 0)
45708b
+    {
45708b
+      g_value_set_boolean (value, FALSE);
45708b
+    }
45708b
+  else if (g_strcmp0 (auth_method, "password") == 0)
45708b
+    {
45708b
+      g_value_set_boolean (value, TRUE);
45708b
+    }
45708b
+  else
45708b
+    {
45708b
+      g_warning ("Unhandled VNC auth method %s", auth_method);
45708b
+      g_value_set_boolean (value, FALSE);
45708b
+    }
45708b
+
45708b
+  return TRUE;
45708b
+}
45708b
+
45708b
+GVariant *
45708b
+cc_grd_set_is_auth_method_password (const GValue       *value,
45708b
+                                    const GVariantType *type,
45708b
+                                    gpointer            user_data)
45708b
+{
45708b
+  char *auth_method;
45708b
+
45708b
+  if (g_value_get_boolean (value))
45708b
+    auth_method = "password";
45708b
+  else
45708b
+    auth_method = "prompt";
45708b
+
45708b
+  return g_variant_new_string (auth_method);
45708b
+}
45708b
+
45708b
+static void
45708b
+on_password_stored (GObject      *source,
45708b
+                    GAsyncResult *result,
45708b
+                    gpointer      user_data)
45708b
+{
45708b
+  GtkEntry *entry = GTK_ENTRY (user_data);
45708b
+  GError *error = NULL;
45708b
+
45708b
+  if (!secret_password_store_finish (result, &error))
45708b
+    {
45708b
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
45708b
+        {
45708b
+          g_warning ("Failed to store VNC password: %s", error->message);
45708b
+          g_object_set_data (G_OBJECT (entry),
45708b
+                             "vnc-password-cancellable", NULL);
45708b
+        }
45708b
+      g_error_free (error);
45708b
+    }
45708b
+  else
45708b
+    {
45708b
+      g_object_set_data (G_OBJECT (entry),
45708b
+                         "vnc-password-cancellable", NULL);
45708b
+    }
45708b
+}
45708b
+
45708b
+void
45708b
+cc_grd_on_vnc_password_entry_notify_text (GtkEntry   *entry,
45708b
+                                          GParamSpec *pspec,
45708b
+                                          gpointer    user_data)
45708b
+{
45708b
+  GCancellable *cancellable;
45708b
+  const char *password;
45708b
+
45708b
+  cancellable = g_object_get_data (G_OBJECT (entry), "vnc-password-cancellable");
45708b
+  if (cancellable)
45708b
+    g_cancellable_cancel (cancellable);
45708b
+
45708b
+  cancellable = g_cancellable_new ();
45708b
+  g_object_set_data_full (G_OBJECT (entry),
45708b
+                          "vnc-password-cancellable",
45708b
+                          cancellable, g_object_unref);
45708b
+
45708b
+  password = gtk_entry_get_text (entry);
45708b
+
45708b
+  secret_password_store (CC_GRD_VNC_PASSWORD_SCHEMA,
45708b
+                         SECRET_COLLECTION_DEFAULT,
45708b
+                         "GNOME Remote Desktop VNC password",
45708b
+                         password,
45708b
+                         cancellable, on_password_stored, entry,
45708b
+                         NULL);
45708b
+}
45708b
diff --git a/panels/sharing/cc-gnome-remote-desktop.h b/panels/sharing/cc-gnome-remote-desktop.h
45708b
new file mode 100644
45708b
index 000000000..2a4819986
45708b
--- /dev/null
45708b
+++ b/panels/sharing/cc-gnome-remote-desktop.h
45708b
@@ -0,0 +1,49 @@
45708b
+/*
45708b
+ * Copyright (C) 2018 Red Hat, Inc.
45708b
+ *
45708b
+ * This program is free software; you can redistribute it and/or modify
45708b
+ * it under the terms of the GNU General Public License as published by
45708b
+ * the Free Software Foundation; either version 2 of the License, or
45708b
+ * (at your option) any later version.
45708b
+ *
45708b
+ * This program is distributed in the hope that it will be useful,
45708b
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
45708b
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45708b
+ * GNU General Public License for more details.
45708b
+ *
45708b
+ * You should have received a copy of the GNU General Public License
45708b
+ * along with this program; if not, write to the Free Software
45708b
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
45708b
+ *
45708b
+ */
45708b
+
45708b
+#ifndef CC_GNOME_REMOTE_DESKTOP_H
45708b
+#define CC_GNOME_REMOTE_DESKTOP_H
45708b
+
45708b
+#include <gtk/gtk.h>
45708b
+#include <libsecret/secret.h>
45708b
+
45708b
+const SecretSchema * cc_grd_vnc_password_get_schema (void);
45708b
+#define CC_GRD_VNC_PASSWORD_SCHEMA cc_grd_vnc_password_get_schema ()
45708b
+
45708b
+gboolean cc_grd_get_is_auth_method_prompt (GValue   *value,
45708b
+                                           GVariant *variant,
45708b
+                                           gpointer  user_data);
45708b
+
45708b
+GVariant * cc_grd_set_is_auth_method_prompt (const GValue       *value,
45708b
+                                             const GVariantType *type,
45708b
+                                             gpointer            user_data);
45708b
+
45708b
+gboolean cc_grd_get_is_auth_method_password (GValue   *value,
45708b
+                                             GVariant *variant,
45708b
+                                             gpointer  user_data);
45708b
+
45708b
+GVariant * cc_grd_set_is_auth_method_password (const GValue       *value,
45708b
+                                               const GVariantType *type,
45708b
+                                               gpointer            user_data);
45708b
+
45708b
+void cc_grd_on_vnc_password_entry_notify_text (GtkEntry   *entry,
45708b
+                                               GParamSpec *pspec,
45708b
+                                               gpointer    user_data);
45708b
+
45708b
+#endif /* CC_GNOME_REMOTE_DESKTOP_H */
45708b
diff --git a/panels/sharing/cc-sharing-panel.c b/panels/sharing/cc-sharing-panel.c
45708b
index 8b35c9a31..adcbcdc86 100644
45708b
--- a/panels/sharing/cc-sharing-panel.c
45708b
+++ b/panels/sharing/cc-sharing-panel.c
45708b
@@ -30,6 +30,7 @@
45708b
 #include "cc-media-sharing.h"
45708b
 #include "cc-sharing-networks.h"
45708b
 #include "cc-sharing-switch.h"
45708b
+#include "cc-gnome-remote-desktop.h"
45708b
 #include "org.gnome.SettingsDaemon.Sharing.h"
45708b
 
45708b
 #ifdef GDK_WINDOWING_WAYLAND
45708b
@@ -66,6 +67,13 @@ _gtk_builder_get_widget (GtkBuilder  *builder,
45708b
 #define VINO_SCHEMA_ID "org.gnome.Vino"
45708b
 #define FILE_SHARING_SCHEMA_ID "org.gnome.desktop.file-sharing"
45708b
 #define GNOME_REMOTE_DESKTOP_SCHEMA_ID "org.gnome.desktop.remote-desktop"
45708b
+#define GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID "org.gnome.desktop.remote-desktop.vnc"
45708b
+
45708b
+typedef enum
45708b
+{
45708b
+  GRD_VNC_AUTH_METHOD_PROMPT,
45708b
+  GRD_VNC_AUTH_METHOD_PASSWORD
45708b
+} GrdVncAuthMethod;
45708b
 
45708b
 struct _CcSharingPanelPrivate
45708b
 {
45708b
@@ -1077,11 +1085,56 @@ static void
45708b
 cc_sharing_panel_setup_screen_sharing_dialog_gnome_remote_desktop (CcSharingPanel *self)
45708b
 {
45708b
   CcSharingPanelPrivate *priv = self->priv;
45708b
-  GtkWidget *networks, *w;
45708b
+  GSettings *vnc_settings;
45708b
+  GtkWidget *networks, *box, *w;
45708b
+
45708b
+  cc_sharing_panel_bind_switch_to_widgets (WID ("require-password-radiobutton"),
45708b
+                                           WID ("password-grid"),
45708b
+                                           NULL);
45708b
+
45708b
+  cc_sharing_panel_setup_label_with_hostname (self,
45708b
+                                              WID ("screen-sharing-label"));
45708b
+
45708b
+  g_object_bind_property (WID ("show-password-checkbutton"), "active",
45708b
+                          WID ("remote-control-password-entry"), "visibility",
45708b
+                          G_BINDING_SYNC_CREATE);
45708b
+
45708b
+  /* make sure the password entry is hidden by default */
45708b
+  g_signal_connect (priv->screen_sharing_dialog, "show",
45708b
+                    G_CALLBACK (screen_sharing_show_cb), self);
45708b
+
45708b
+  g_signal_connect (priv->screen_sharing_dialog, "hide",
45708b
+                    G_CALLBACK (screen_sharing_hide_cb), self);
45708b
+
45708b
+  /* accept at most 8 bytes in password entry */
45708b
+  g_signal_connect (WID ("remote-control-password-entry"), "insert-text",
45708b
+                    G_CALLBACK (screen_sharing_password_insert_text_cb), self);
45708b
+
45708b
+  /* Bind settings to widgets */
45708b
+  vnc_settings = g_settings_new (GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID);
45708b
+  g_settings_bind (vnc_settings, "view-only",
45708b
+                   WID ("remote-control-checkbutton"), "active",
45708b
+                   G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN);
45708b
+  g_settings_bind_with_mapping (vnc_settings, "auth-method",
45708b
+                                WID ("approve-connections-radiobutton"), "active",
45708b
+                                G_SETTINGS_BIND_DEFAULT,
45708b
+                                cc_grd_get_is_auth_method_prompt,
45708b
+                                cc_grd_set_is_auth_method_prompt,
45708b
+                                NULL, NULL);
45708b
+  g_settings_bind_with_mapping (vnc_settings, "auth-method",
45708b
+                                WID ("require-password-radiobutton"), "active",
45708b
+                                G_SETTINGS_BIND_DEFAULT,
45708b
+                                cc_grd_get_is_auth_method_password,
45708b
+                                cc_grd_set_is_auth_method_password,
45708b
+                                NULL, NULL);
45708b
+  g_signal_connect (WID ("remote-control-password-entry"),
45708b
+                    "notify::text",
45708b
+                    G_CALLBACK (cc_grd_on_vnc_password_entry_notify_text),
45708b
+                    self);
45708b
 
45708b
   networks = cc_sharing_networks_new (self->priv->sharing_proxy, "gnome-remote-desktop");
45708b
-  gtk_widget_hide (WID ("remote-control-box"));
45708b
-  gtk_grid_attach (GTK_GRID (WID ("grid3")), networks, 0, 1, 2, 1);
45708b
+  box = WID ("remote-control-box");
45708b
+  gtk_box_pack_end (GTK_BOX (box), networks, TRUE, TRUE, 0);
45708b
   gtk_widget_show (networks);
45708b
 
45708b
   w = cc_sharing_switch_new (networks);
45708b
@@ -1116,6 +1169,9 @@ check_remote_desktop_available (CcSharingPanel *self)
45708b
   if (!cc_sharing_panel_check_schema_available (self, GNOME_REMOTE_DESKTOP_SCHEMA_ID))
45708b
     return;
45708b
 
45708b
+  if (!cc_sharing_panel_check_schema_available (self, GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID))
45708b
+    return;
45708b
+
45708b
   priv->remote_desktop_name_watch = g_bus_watch_name (G_BUS_TYPE_SESSION,
45708b
                                                       "org.gnome.Mutter.RemoteDesktop",
45708b
                                                       G_BUS_NAME_WATCHER_FLAGS_NONE,
45708b
diff --git a/panels/sharing/meson.build b/panels/sharing/meson.build
45708b
index 5caac36c0..1565a089a 100644
45708b
--- a/panels/sharing/meson.build
45708b
+++ b/panels/sharing/meson.build
45708b
@@ -43,6 +43,7 @@ sources = files(
45708b
   'cc-remote-login.c',
45708b
   'cc-sharing-networks.c',
45708b
   'cc-sharing-switch.c',
45708b
+  'cc-gnome-remote-desktop.c',
45708b
   'file-share-properties.c',
45708b
   'vino-preferences.c'
45708b
 )
45708b
@@ -79,7 +80,7 @@ panels_libs += static_library(
45708b
   cappletname,
45708b
   sources: sources,
45708b
   include_directories: top_inc,
45708b
-  dependencies: common_deps,
45708b
+  dependencies: [common_deps, libsecret_dep],
45708b
   c_args: cflags
45708b
 )
45708b
 
45708b
-- 
45708b
2.17.1
45708b