[gnome-control-center] sharing: Enable settings widget for gnome-remote-desktop
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] sharing: Enable settings widget for gnome-remote-desktop
- Date: Tue, 10 Jul 2018 21:39:01 +0000 (UTC)
commit 49ef965dc7805a174e0b8c3f22de37aaddd627a6
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Wed Feb 14 20:52:37 2018 +0800
sharing: Enable settings widget for gnome-remote-desktop
Enable support for manipulating GNOME Remote Desktop settings. Settings
are done via the org.gnome.desktop.remote-desktop.vnc schema.
Configuring the VNC password is done via libsecret, thus libsecret is
added as a dependency.
panels/sharing/cc-gnome-remote-desktop.c | 171 +++++++++++++++++++++++++++++++
panels/sharing/cc-gnome-remote-desktop.h | 49 +++++++++
panels/sharing/cc-sharing-panel.c | 76 +++++++++++++-
panels/sharing/meson.build | 5 +-
4 files changed, 298 insertions(+), 3 deletions(-)
---
diff --git a/panels/sharing/cc-gnome-remote-desktop.c b/panels/sharing/cc-gnome-remote-desktop.c
new file mode 100644
index 000000000..8420fddca
--- /dev/null
+++ b/panels/sharing/cc-gnome-remote-desktop.c
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include "config.h"
+
+#include "cc-gnome-remote-desktop.h"
+
+const SecretSchema *
+cc_grd_vnc_password_get_schema (void)
+{
+ static const SecretSchema grd_vnc_password_schema = {
+ .name = "org.gnome.RemoteDesktop.VncPassword",
+ .flags = SECRET_SCHEMA_NONE,
+ .attributes = {
+ { "password", SECRET_SCHEMA_ATTRIBUTE_STRING },
+ { "NULL", 0 },
+ },
+ };
+
+ return &grd_vnc_password_schema;
+}
+
+gboolean
+cc_grd_get_is_auth_method_prompt (GValue *value,
+ GVariant *variant,
+ gpointer user_data)
+{
+ const char * auth_method;
+
+ auth_method = g_variant_get_string (variant, NULL);
+
+ if (g_strcmp0 (auth_method, "prompt") == 0)
+ {
+ g_value_set_boolean (value, TRUE);
+ }
+ else if (g_strcmp0 (auth_method, "password") == 0)
+ {
+ g_value_set_boolean (value, FALSE);
+ }
+ else
+ {
+ g_warning ("Unhandled VNC auth method %s", auth_method);
+ g_value_set_boolean (value, FALSE);
+ }
+
+ return TRUE;
+}
+
+GVariant *
+cc_grd_set_is_auth_method_prompt (const GValue *value,
+ const GVariantType *type,
+ gpointer user_data)
+{
+ char *auth_method;
+
+ if (g_value_get_boolean (value))
+ auth_method = "prompt";
+ else
+ auth_method = "password";
+
+ return g_variant_new_string (auth_method);
+}
+
+gboolean
+cc_grd_get_is_auth_method_password (GValue *value,
+ GVariant *variant,
+ gpointer user_data)
+{
+ const char *auth_method;
+
+ auth_method = g_variant_get_string (variant, NULL);
+
+ if (g_strcmp0 (auth_method, "prompt") == 0)
+ {
+ g_value_set_boolean (value, FALSE);
+ }
+ else if (g_strcmp0 (auth_method, "password") == 0)
+ {
+ g_value_set_boolean (value, TRUE);
+ }
+ else
+ {
+ g_warning ("Unhandled VNC auth method %s", auth_method);
+ g_value_set_boolean (value, FALSE);
+ }
+
+ return TRUE;
+}
+
+GVariant *
+cc_grd_set_is_auth_method_password (const GValue *value,
+ const GVariantType *type,
+ gpointer user_data)
+{
+ char *auth_method;
+
+ if (g_value_get_boolean (value))
+ auth_method = "password";
+ else
+ auth_method = "prompt";
+
+ return g_variant_new_string (auth_method);
+}
+
+static void
+on_password_stored (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GtkEntry *entry = GTK_ENTRY (user_data);
+ GError *error = NULL;
+
+ if (!secret_password_store_finish (result, &error))
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ {
+ g_warning ("Failed to store VNC password: %s", error->message);
+ g_object_set_data (G_OBJECT (entry),
+ "vnc-password-cancellable", NULL);
+ }
+ g_error_free (error);
+ }
+ else
+ {
+ g_object_set_data (G_OBJECT (entry),
+ "vnc-password-cancellable", NULL);
+ }
+}
+
+void
+cc_grd_on_vnc_password_entry_notify_text (GtkEntry *entry,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ GCancellable *cancellable;
+ const char *password;
+
+ cancellable = g_object_get_data (G_OBJECT (entry), "vnc-password-cancellable");
+ if (cancellable)
+ g_cancellable_cancel (cancellable);
+
+ cancellable = g_cancellable_new ();
+ g_object_set_data_full (G_OBJECT (entry),
+ "vnc-password-cancellable",
+ cancellable, g_object_unref);
+
+ password = gtk_entry_get_text (entry);
+
+ secret_password_store (CC_GRD_VNC_PASSWORD_SCHEMA,
+ SECRET_COLLECTION_DEFAULT,
+ "GNOME Remote Desktop VNC password",
+ password,
+ cancellable, on_password_stored, entry,
+ NULL);
+}
diff --git a/panels/sharing/cc-gnome-remote-desktop.h b/panels/sharing/cc-gnome-remote-desktop.h
new file mode 100644
index 000000000..2a4819986
--- /dev/null
+++ b/panels/sharing/cc-gnome-remote-desktop.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifndef CC_GNOME_REMOTE_DESKTOP_H
+#define CC_GNOME_REMOTE_DESKTOP_H
+
+#include <gtk/gtk.h>
+#include <libsecret/secret.h>
+
+const SecretSchema * cc_grd_vnc_password_get_schema (void);
+#define CC_GRD_VNC_PASSWORD_SCHEMA cc_grd_vnc_password_get_schema ()
+
+gboolean cc_grd_get_is_auth_method_prompt (GValue *value,
+ GVariant *variant,
+ gpointer user_data);
+
+GVariant * cc_grd_set_is_auth_method_prompt (const GValue *value,
+ const GVariantType *type,
+ gpointer user_data);
+
+gboolean cc_grd_get_is_auth_method_password (GValue *value,
+ GVariant *variant,
+ gpointer user_data);
+
+GVariant * cc_grd_set_is_auth_method_password (const GValue *value,
+ const GVariantType *type,
+ gpointer user_data);
+
+void cc_grd_on_vnc_password_entry_notify_text (GtkEntry *entry,
+ GParamSpec *pspec,
+ gpointer user_data);
+
+#endif /* CC_GNOME_REMOTE_DESKTOP_H */
diff --git a/panels/sharing/cc-sharing-panel.c b/panels/sharing/cc-sharing-panel.c
index 207ed746f..6d0141b99 100644
--- a/panels/sharing/cc-sharing-panel.c
+++ b/panels/sharing/cc-sharing-panel.c
@@ -30,6 +30,7 @@
#include "cc-media-sharing.h"
#include "cc-sharing-networks.h"
#include "cc-sharing-switch.h"
+#include "cc-gnome-remote-desktop.h"
#include "org.gnome.SettingsDaemon.Sharing.h"
#ifdef GDK_WINDOWING_WAYLAND
@@ -45,6 +46,13 @@ static GtkWidget *cc_sharing_panel_new_media_sharing_row (const char *uri_or
#define VINO_SCHEMA_ID "org.gnome.Vino"
#define FILE_SHARING_SCHEMA_ID "org.gnome.desktop.file-sharing"
#define GNOME_REMOTE_DESKTOP_SCHEMA_ID "org.gnome.desktop.remote-desktop"
+#define GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID "org.gnome.desktop.remote-desktop.vnc"
+
+typedef enum
+{
+ GRD_VNC_AUTH_METHOD_PROMPT,
+ GRD_VNC_AUTH_METHOD_PASSWORD
+} GrdVncAuthMethod;
struct _CcSharingPanel
{
@@ -1078,11 +1086,72 @@ cc_sharing_panel_setup_screen_sharing_dialog_vino (CcSharingPanel *self)
static void
cc_sharing_panel_setup_screen_sharing_dialog_gnome_remote_desktop (CcSharingPanel *self)
{
+ g_autoptr(GSettings) vnc_settings = NULL;
GtkWidget *networks, *w;
+ cc_sharing_panel_bind_switch_to_widgets (self->require_password_radiobutton, self->password_grid, NULL);
+
+ cc_sharing_panel_setup_label_with_hostname (self, self->screen_sharing_label);
+
+ g_object_bind_property (self->show_password_checkbutton,
+ "active",
+ self->remote_control_password_entry,
+ "visibility",
+ G_BINDING_SYNC_CREATE);
+
+ /* make sure the password entry is hidden by default */
+ g_signal_connect (self->screen_sharing_dialog,
+ "show",
+ G_CALLBACK (screen_sharing_show_cb),
+ self);
+
+ g_signal_connect (self->screen_sharing_dialog,
+ "hide",
+ G_CALLBACK (screen_sharing_hide_cb),
+ self);
+
+ /* accept at most 8 bytes in password entry */
+ g_signal_connect (self->remote_control_password_entry,
+ "insert-text",
+ G_CALLBACK (screen_sharing_password_insert_text_cb),
+ self);
+
+ /* Bind settings to widgets */
+ vnc_settings = g_settings_new (GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID);
+
+ g_settings_bind (vnc_settings,
+ "view-only",
+ self->remote_control_checkbutton,
+ "active",
+ G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN);
+
+ g_settings_bind_with_mapping (vnc_settings,
+ "auth-method",
+ self->approve_connections_radiobutton,
+ "active",
+ G_SETTINGS_BIND_DEFAULT,
+ cc_grd_get_is_auth_method_prompt,
+ cc_grd_set_is_auth_method_prompt,
+ NULL,
+ NULL);
+
+ g_settings_bind_with_mapping (vnc_settings,
+ "auth-method",
+ self->require_password_radiobutton,
+ "active",
+ G_SETTINGS_BIND_DEFAULT,
+ cc_grd_get_is_auth_method_password,
+ cc_grd_set_is_auth_method_password,
+ NULL,
+ NULL);
+
+ g_signal_connect (self->remote_control_password_entry,
+ "notify::text",
+ G_CALLBACK (cc_grd_on_vnc_password_entry_notify_text),
+ self);
+
networks = cc_sharing_networks_new (self->sharing_proxy, "gnome-remote-desktop");
- gtk_widget_hide (self->remote_control_box);
- gtk_grid_attach (GTK_GRID (self->screen_sharing_grid), networks, 0, 1, 2, 1);
+ gtk_box_pack_end (GTK_BOX (self->remote_control_box), networks, TRUE, TRUE, 0);
gtk_widget_show (networks);
w = cc_sharing_switch_new (networks);
@@ -1114,6 +1183,9 @@ check_remote_desktop_available (CcSharingPanel *self)
if (!cc_sharing_panel_check_schema_available (self, GNOME_REMOTE_DESKTOP_SCHEMA_ID))
return;
+ if (!cc_sharing_panel_check_schema_available (self, GNOME_REMOTE_DESKTOP_VNC_SCHEMA_ID))
+ return;
+
self->remote_desktop_name_watch = g_bus_watch_name (G_BUS_TYPE_SESSION,
"org.gnome.Mutter.RemoteDesktop",
G_BUS_NAME_WATCHER_FLAGS_NONE,
diff --git a/panels/sharing/meson.build b/panels/sharing/meson.build
index 236458171..73a03b095 100644
--- a/panels/sharing/meson.build
+++ b/panels/sharing/meson.build
@@ -43,6 +43,7 @@ sources = files(
'cc-remote-login.c',
'cc-sharing-networks.c',
'cc-sharing-switch.c',
+ 'cc-gnome-remote-desktop.c',
'file-share-properties.c',
'vino-preferences.c'
)
@@ -75,11 +76,13 @@ cflags += [
'-DSYSCONFDIR="@0@"'.format(control_center_sysconfdir)
]
+libsecret_dep = dependency('libsecret-1')
+
panels_libs += static_library(
cappletname,
sources: sources,
include_directories: [ top_inc, common_inc ],
- dependencies: common_deps,
+ dependencies: [common_deps, libsecret_dep],
c_args: cflags
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]