[gnome-initial-setup/wip/pwithnall/misc-fixes: 33/70] account, password: Hide password page for passwordless account




commit 419833d8d101209b697023072035a0d4e7b680a2
Author: Philip Chimento <philip endlessm com>
Date:   Fri Jul 19 14:01:12 2019 -0700

    account,password: Hide password page for passwordless account
    
    Due to the similar mechanism for hiding the password page if there is no
    local username, it seems that the GisDriver is the place to store state
    such as this, that is common to several pages.
    
    Replaced a similar commit from https://phabricator.endlessm.com/T17268
    [94e0b657cd6abed7197207f57e674de711b47a83] that used a different
    mechanism, in the pre-3.34 downstream patches.
    
    (Rebase 3.38: Fix minor rebase conflicts.)
    
    https://phabricator.endlessm.com/T25162

 gnome-initial-setup/gis-driver.c                   | 31 ++++++++++++++++++++++
 gnome-initial-setup/gis-driver.h                   |  5 ++++
 .../pages/account/gis-account-page-local.c         |  1 +
 .../pages/password/gis-password-page.c             | 19 ++++++++-----
 4 files changed, 49 insertions(+), 7 deletions(-)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index 2f546337..56b2de80 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -63,6 +63,7 @@ typedef enum {
   PROP_MODE = 1,
   PROP_LIVE_SESSION,
   PROP_USERNAME,
+  PROP_PASSWORDLESS,
   PROP_SMALL_SCREEN,
   PROP_PARENTAL_CONTROLS_ENABLED,
   PROP_FULL_NAME,
@@ -90,6 +91,7 @@ struct _GisDriverPrivate {
   gchar *lang_id;
   gchar *username;
   gchar *full_name;  /* (owned) (nullable) */
+  gboolean passwordless;
 
   GdkPixbuf *avatar;  /* (owned) (nullable) */
 
@@ -442,6 +444,24 @@ gis_driver_get_avatar (GisDriver *driver)
   return priv->avatar;
 }
 
+void
+gis_driver_set_passwordless (GisDriver *self,
+                             gboolean   passwordless)
+{
+  GisDriverPrivate *priv = gis_driver_get_instance_private (self);
+  gboolean should_notify = (priv->passwordless != passwordless);
+  priv->passwordless = passwordless;
+  if (should_notify)
+    g_object_notify (G_OBJECT (self), "passwordless");
+}
+
+gboolean
+gis_driver_get_passwordless (GisDriver *self)
+{
+  GisDriverPrivate *priv = gis_driver_get_instance_private (self);
+  return priv->passwordless;
+}
+
 void
 gis_driver_set_user_permissions (GisDriver   *driver,
                                  ActUser     *user,
@@ -780,6 +800,9 @@ gis_driver_get_property (GObject      *object,
     case PROP_USERNAME:
       g_value_set_string (value, priv->username);
       break;
+    case PROP_PASSWORDLESS:
+      g_value_set_boolean (value, priv->passwordless);
+      break;
     case PROP_SMALL_SCREEN:
       g_value_set_boolean (value, priv->small_screen);
       break;
@@ -815,6 +838,9 @@ gis_driver_set_property (GObject      *object,
       g_free (priv->username);
       priv->username = g_value_dup_string (value);
       break;
+    case PROP_PASSWORDLESS:
+      priv->passwordless = g_value_get_boolean (value);
+      break;
     case PROP_PARENTAL_CONTROLS_ENABLED:
       gis_driver_set_parental_controls_enabled (driver, g_value_get_boolean (value));
       break;
@@ -1103,6 +1129,11 @@ gis_driver_class_init (GisDriverClass *klass)
                          NULL,
                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
+  obj_props[PROP_PASSWORDLESS] =
+    g_param_spec_boolean ("passwordless", "", "Main user account is passwordless",
+                          FALSE,
+                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
   obj_props[PROP_SMALL_SCREEN] =
     g_param_spec_boolean ("small-screen", "", "",
                           FALSE,
diff --git a/gnome-initial-setup/gis-driver.h b/gnome-initial-setup/gis-driver.h
index 56227afe..dd429747 100644
--- a/gnome-initial-setup/gis-driver.h
+++ b/gnome-initial-setup/gis-driver.h
@@ -111,6 +111,11 @@ void gis_driver_set_avatar (GisDriver *driver,
                             GdkPixbuf *avatar);
 GdkPixbuf *gis_driver_get_avatar (GisDriver *driver);
 
+void gis_driver_set_passwordless (GisDriver *self,
+                                  gboolean   passwordless);
+
+gboolean gis_driver_get_passwordless (GisDriver *self);
+
 gboolean gis_driver_get_gdm_objects (GisDriver        *driver,
                                      GdmGreeter      **greeter,
                                      GdmUserVerifier **user_verifier);
diff --git a/gnome-initial-setup/pages/account/gis-account-page-local.c 
b/gnome-initial-setup/pages/account/gis-account-page-local.c
index c6e54e79..0a552d57 100644
--- a/gnome-initial-setup/pages/account/gis-account-page-local.c
+++ b/gnome-initial-setup/pages/account/gis-account-page-local.c
@@ -730,6 +730,7 @@ gis_account_page_local_apply (GisAccountPageLocal *local, GisPage *page)
 
   username = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (priv->username_combo));
   gis_driver_set_username (GIS_PAGE (page)->driver, username);
+  gis_driver_set_passwordless (page->driver, priv->passwordless);
 
   full_name = gtk_entry_get_text (GTK_ENTRY (priv->fullname_entry));
   gis_driver_set_full_name (GIS_PAGE (page)->driver, full_name);
diff --git a/gnome-initial-setup/pages/password/gis-password-page.c 
b/gnome-initial-setup/pages/password/gis-password-page.c
index 8cc28fba..610a4444 100644
--- a/gnome-initial-setup/pages/password/gis-password-page.c
+++ b/gnome-initial-setup/pages/password/gis-password-page.c
@@ -310,12 +310,13 @@ confirm_changed (GtkWidget      *w,
 }
 
 static void
-username_changed (GObject *obj, GParamSpec *pspec, GisPasswordPage *page)
+username_or_passwordless_changed (GisPasswordPage *page)
 {
   GisPasswordPagePrivate *priv = gis_password_page_get_instance_private (page);
-  priv->username = gis_driver_get_username (GIS_DRIVER (obj));
+  priv->username = gis_driver_get_username (GIS_PAGE (page)->driver);
+  gboolean passwordless = gis_driver_get_passwordless (GIS_PAGE (page)->driver);
 
-  if (priv->username)
+  if (priv->parent_mode || (priv->username && !passwordless))
     gtk_widget_show (GTK_WIDGET (page));
   else
     gtk_widget_hide (GTK_WIDGET (page));  
@@ -368,8 +369,11 @@ gis_password_page_constructed (GObject *object)
   g_signal_connect_swapped (priv->confirm_entry, "activate",
                             G_CALLBACK (confirm), page);
 
-  g_signal_connect (GIS_PAGE (page)->driver, "notify::username",
-                    G_CALLBACK (username_changed), page);
+  g_signal_connect_swapped (GIS_PAGE (page)->driver, "notify::username",
+                            G_CALLBACK (username_or_passwordless_changed), page);
+  g_signal_connect_swapped (GIS_PAGE (page)->driver, "notify::passwordless",
+                            G_CALLBACK (username_or_passwordless_changed), page);
+
   g_signal_connect (GIS_PAGE (page)->driver, "notify::full-name",
                     G_CALLBACK (full_name_or_avatar_changed), page);
   g_signal_connect (GIS_PAGE (page)->driver, "notify::avatar",
@@ -384,7 +388,8 @@ gis_password_page_constructed (GObject *object)
   validate (page);
   update_header (page);
 
-  gtk_widget_show (GTK_WIDGET (page));
+  /* This callback shows the page widget conditionally on if it's needed */
+  username_or_passwordless_changed (page);
 }
 
 static void
@@ -434,7 +439,7 @@ gis_password_page_dispose (GObject *object)
 
   if (GIS_PAGE (object)->driver) {
     g_signal_handlers_disconnect_by_func (GIS_PAGE (object)->driver,
-                                          username_changed, object);
+                                          username_or_passwordless_changed, object);
     g_signal_handlers_disconnect_by_func (GIS_PAGE (object)->driver,
                                           full_name_or_avatar_changed, object);
   }


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