summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2019-11-22 11:18:30 +1300
committerRobert Ancell <robert.ancell@canonical.com>2020-03-30 16:18:49 +1300
commit3e4c1d38229a91cf989b00acaaf118147288b876 (patch)
tree3a73b4baf53a0cc6abc9fe499f0d5dbeed209b99
parent10e73b733bf0ad0512e0da2913731cae4c1e9d72 (diff)
downloadgnome-control-center-3e4c1d38229a91cf989b00acaaf118147288b876.tar.gz
sharing: Move GTK code that was innappropriately in a helper function
-rw-r--r--panels/sharing/cc-gnome-remote-desktop.c37
-rw-r--r--panels/sharing/cc-gnome-remote-desktop.h8
-rw-r--r--panels/sharing/cc-sharing-panel.c20
3 files changed, 24 insertions, 41 deletions
diff --git a/panels/sharing/cc-gnome-remote-desktop.c b/panels/sharing/cc-gnome-remote-desktop.c
index 7ab1b2e0d..c59f3b0eb 100644
--- a/panels/sharing/cc-gnome-remote-desktop.c
+++ b/panels/sharing/cc-gnome-remote-desktop.c
@@ -123,7 +123,6 @@ 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))
@@ -131,57 +130,33 @@ on_password_stored (GObject *source,
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)
+cc_grd_store_vnc_password (const gchar *password, GCancellable *cancellable)
{
- 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,
+ cancellable, on_password_stored, NULL,
NULL);
}
-void
-cc_grd_update_password_entry (GtkEntry *entry)
+gchar *
+cc_grd_lookup_vnc_password (GCancellable *cancellable)
{
g_autoptr(GError) error = NULL;
g_autofree gchar *password = NULL;
password = secret_password_lookup_sync (CC_GRD_VNC_PASSWORD_SCHEMA,
- NULL, &error,
+ cancellable, &error,
NULL);
if (error)
g_warning ("Failed to get password: %s", error->message);
- if (password)
- gtk_entry_set_text (entry, password);
+ return g_steal_pointer (&password);
}
diff --git a/panels/sharing/cc-gnome-remote-desktop.h b/panels/sharing/cc-gnome-remote-desktop.h
index ce30036f7..a3a99aed4 100644
--- a/panels/sharing/cc-gnome-remote-desktop.h
+++ b/panels/sharing/cc-gnome-remote-desktop.h
@@ -19,7 +19,6 @@
#pragma once
-#include <gtk/gtk.h>
#include <libsecret/secret.h>
G_BEGIN_DECLS
@@ -43,10 +42,9 @@ 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);
+void cc_grd_store_vnc_password (const gchar *password,
+ GCancellable *cancellable);
-void cc_grd_update_password_entry (GtkEntry *entry);
+gchar * cc_grd_lookup_vnc_password (GCancellable *cancellable);
G_END_DECLS
diff --git a/panels/sharing/cc-sharing-panel.c b/panels/sharing/cc-sharing-panel.c
index 3d4483a23..7238f205d 100644
--- a/panels/sharing/cc-sharing-panel.c
+++ b/panels/sharing/cc-sharing-panel.c
@@ -1076,8 +1076,15 @@ cc_sharing_panel_setup_screen_sharing_dialog_vino (CcSharingPanel *self)
}
static void
+on_vnc_password_entry_notify_text (CcSharingPanel *self)
+{
+ cc_grd_store_vnc_password (gtk_entry_get_text (GTK_ENTRY (self->remote_control_password_entry)), cc_panel_get_cancellable (CC_PANEL (self)));
+}
+
+static void
cc_sharing_panel_setup_screen_sharing_dialog_gnome_remote_desktop (CcSharingPanel *self)
{
+ g_autofree gchar *password = NULL;
g_autoptr(GSettings) vnc_settings = NULL;
GtkWidget *networks, *w;
@@ -1104,7 +1111,9 @@ cc_sharing_panel_setup_screen_sharing_dialog_gnome_remote_desktop (CcSharingPane
self,
G_CONNECT_SWAPPED);
- cc_grd_update_password_entry (GTK_ENTRY (self->remote_control_password_entry));
+ password = cc_grd_lookup_vnc_password (cc_panel_get_cancellable (CC_PANEL (self)));
+ if (password != NULL)
+ gtk_entry_set_text (GTK_ENTRY (self->remote_control_password_entry), password);
/* accept at most 8 bytes in password entry */
g_signal_connect_object (self->remote_control_password_entry,
@@ -1142,10 +1151,11 @@ cc_sharing_panel_setup_screen_sharing_dialog_gnome_remote_desktop (CcSharingPane
NULL,
NULL);
- g_signal_connect (self->remote_control_password_entry,
- "notify::text",
- G_CALLBACK (cc_grd_on_vnc_password_entry_notify_text),
- self);
+ g_signal_connect_object (self->remote_control_password_entry,
+ "notify::text",
+ G_CALLBACK (on_vnc_password_entry_notify_text),
+ self,
+ G_CONNECT_SWAPPED);
networks = cc_sharing_networks_new (self->sharing_proxy, "gnome-remote-desktop");
gtk_box_pack_end (GTK_BOX (self->remote_control_box), networks, TRUE, TRUE, 0);