[gnome-control-center] sharing: Move GTK code that was innappropriately in a helper function



commit 3e4c1d38229a91cf989b00acaaf118147288b876
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Nov 22 11:18:30 2019 +1300

    sharing: Move GTK code that was innappropriately in a helper function

 panels/sharing/cc-gnome-remote-desktop.c | 37 ++++++--------------------------
 panels/sharing/cc-gnome-remote-desktop.h |  8 +++----
 panels/sharing/cc-sharing-panel.c        | 20 ++++++++++++-----
 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
@@ -1075,9 +1075,16 @@ cc_sharing_panel_setup_screen_sharing_dialog_vino (CcSharingPanel *self)
                                            self->screen_sharing_status_label);
 }
 
+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);


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