[gnome-control-center/T20818: 31/54] user-accounts: Fall back to "user" as the default login name



commit c78b875debd3829430fcd38513334754c94301d1
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Mon May 16 14:34:25 2016 -0500

    user-accounts: Fall back to "user" as the default login name
    
    This is a straight copy of Juan's code from gnome-initial-setup.
    https://phabricator.endlessm.com/T3597

 panels/user-accounts/um-utils.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/panels/user-accounts/um-utils.c b/panels/user-accounts/um-utils.c
index 6225189..3763285 100644
--- a/panels/user-accounts/um-utils.c
+++ b/panels/user-accounts/um-utils.c
@@ -36,6 +36,8 @@
 
 #include "um-utils.h"
 
+#define DEFAULT_USERNAME "user"
+
 typedef struct {
         gchar *text;
         gchar *placeholder_str;
@@ -517,6 +519,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;
@@ -526,7 +529,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);
@@ -560,7 +563,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
@@ -725,7 +728,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);
@@ -734,6 +736,22 @@ 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);
+        }
 }
 
 static gboolean


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