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

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