[gnome-initial-setup/fix-blank-avatar: 68/68] Change generated avatar for empty name



commit 6dbacc681ccef502a0aafe7684b07f625c527819
Author: Philip Chimento <philip endlessm com>
Date:   Mon Aug 5 17:41:48 2019 -0700

    Change generated avatar for empty name
    
    The default generated avatar consisting of a white circle looks broken
    at first sight. We special-case an empty name to be a monochrome "bust
    in silhouette" character on a turquoise background, to show that the
    circle contains an avatar and hopefully make it seem more clickable.

 gnome-initial-setup/pages/account/um-utils.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/gnome-initial-setup/pages/account/um-utils.c b/gnome-initial-setup/pages/account/um-utils.c
index 5fd215e..ee04f60 100644
--- a/gnome-initial-setup/pages/account/um-utils.c
+++ b/gnome-initial-setup/pages/account/um-utils.c
@@ -479,6 +479,11 @@ generate_username_choices (const gchar  *name,
 
 #define IMAGE_SIZE 512
 
+/* U+1F464 "bust in silhouette"
+ * U+FE0E Variant Selector 15 to force text style (monochrome) emoji
+ */
+#define PLACEHOLDER "\U0001F464\U0000FE0E"
+
 static gchar *
 extract_initials_from_name (const gchar *name)
 {
@@ -487,13 +492,18 @@ extract_initials_from_name (const gchar *name)
         gchar *normalized;
         gunichar unichar;
 
+        if (name == NULL || name[0] == '\0') {
+            g_string_free (initials, TRUE);
+            return g_strdup (PLACEHOLDER);
+        }
+
         p = g_utf8_strup (name, -1);
         normalized = g_utf8_normalize (g_strstrip (p), -1, G_NORMALIZE_DEFAULT_COMPOSE);
         g_clear_pointer (&p, g_free);
         if (normalized == NULL) {
                 g_free (normalized);
-
-                return NULL;
+                g_string_free (initials, TRUE);
+                return g_strdup (PLACEHOLDER);
         }
 
         unichar = g_utf8_get_char (normalized);
@@ -552,12 +562,13 @@ get_color_for_name (const gchar *name)
         gint number_of_colors;
         gint idx;
 
-        if (name == NULL || strlen (name) == 0)
-                return color;
-
-        hash = g_str_hash (name);
-        number_of_colors = G_N_ELEMENTS (gnome_color_palette);
-        idx = hash % number_of_colors;
+        if (name == NULL || name[0] == '\0') {
+                idx = 5;
+        } else {
+                hash = g_str_hash (name);
+                number_of_colors = G_N_ELEMENTS (gnome_color_palette);
+                idx = hash % number_of_colors;
+        }
 
         color.red   = gnome_color_palette[idx][0];
         color.green = gnome_color_palette[idx][1];


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