[gnome-initial-setup/shell/4765: 204/362] Suggest "user" as default login name



commit 5c7bb37616aba552cf88b0d20936b7b5cf5952e6
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Mon Sep 8 08:23:49 2014 +0000

    Suggest "user" as default login name
    
    When obtaining a list of suggested login names from the full user name, if no
    one can be obtained use "user" as default one, so there is always at least one
    suggestion.
    
    [endlessm/eos-shell#3534]

 .../pages/account/gis-account-page.c               |    8 ++----
 gnome-initial-setup/pages/account/um-utils.c       |   24 +++++++++++++++++--
 2 files changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/gnome-initial-setup/pages/account/gis-account-page.c 
b/gnome-initial-setup/pages/account/gis-account-page.c
index 4d54c37..426ee25 100644
--- a/gnome-initial-setup/pages/account/gis-account-page.c
+++ b/gnome-initial-setup/pages/account/gis-account-page.c
@@ -142,7 +142,8 @@ clear_account_page (GisAccountPage *page)
   priv->account_type = ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR;
 
   gtk_entry_set_text (GTK_ENTRY (fullname_entry), "");
-  gtk_list_store_clear (GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (username_combo))));
+  generate_username_choices ("", GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (username_combo))));
+  gtk_combo_box_set_active (GTK_COMBO_BOX (username_combo), 0);
   gtk_entry_set_text (GTK_ENTRY (password_entry), "");
   gtk_entry_set_text (GTK_ENTRY (confirm_entry), "");
 }
@@ -263,16 +264,13 @@ fullname_changed (GtkWidget      *w,
   entry = gtk_bin_get_child (GTK_BIN (combo));
   model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
 
-  gtk_list_store_clear (GTK_LIST_STORE (model));
-
   priv->valid_name = is_valid_name (name);
 
   if (!priv->valid_name) {
     gtk_entry_set_text (GTK_ENTRY (entry), "");
-    return;
   }
 
-  generate_username_choices (name, GTK_LIST_STORE (model));
+  generate_username_choices (priv->valid_name ? name : "", GTK_LIST_STORE (model));
 
   gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
 
diff --git a/gnome-initial-setup/pages/account/um-utils.c b/gnome-initial-setup/pages/account/um-utils.c
index 6853455..594814b 100644
--- a/gnome-initial-setup/pages/account/um-utils.c
+++ b/gnome-initial-setup/pages/account/um-utils.c
@@ -33,6 +33,8 @@
 
 #include "um-utils.h"
 
+#define DEFAULT_USERNAME "user"
+
 void
 set_entry_validation_error (GtkEntry    *entry,
                             const gchar *text)
@@ -174,6 +176,7 @@ generate_username_choices (const gchar  *name,
 {
         gboolean in_use, same_as_initial;
         char *lc_name, *ascii_name, *stripped_name;
+        char *default_username;
         char **words1;
         char **words2 = NULL;
         char **w1, **w2;
@@ -183,7 +186,7 @@ generate_username_choices (const gchar  *name,
         GString *item0, *item1, *item2, *item3, *item4;
         int len;
         int nwords1, nwords2, i;
-        GHashTable *items;
+        GHashTable *items = NULL;
         GtkTreeIter iter;
 
         gtk_list_store_clear (store);
@@ -217,7 +220,7 @@ generate_username_choices (const gchar  *name,
                 g_free (ascii_name);
                 g_free (lc_name);
                 g_free (stripped_name);
-                return;
+                goto bailout;
         }
 
         /* we split name on spaces, and then on dashes, so that we can treat
@@ -373,7 +376,6 @@ generate_username_choices (const gchar  *name,
                 }
         }
 
-        g_hash_table_destroy (items);
         g_strfreev (words1);
         g_string_free (first_word, TRUE);
         g_string_free (last_word, TRUE);
@@ -382,4 +384,20 @@ generate_username_choices (const gchar  *name,
         g_string_free (item2, TRUE);
         g_string_free (item3, TRUE);
         g_string_free (item4, TRUE);
+
+ bailout:
+        if (items == NULL || g_hash_table_size (items) == 0) {
+                gtk_list_store_append (store, &iter);
+                default_username = g_strdup (DEFAULT_USERNAME);
+                i = 0;
+                while (is_username_used (default_username)) {
+                        g_free (default_username);
+                        default_username = g_strdup_printf (DEFAULT_USERNAME "%d", ++i);
+                }
+                gtk_list_store_set (store, &iter, 0, default_username, -1);
+                g_free (default_username);
+        }
+        if (items != NULL) {
+                g_hash_table_destroy (items);
+        }
 }


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