[gnome-initial-setup/wip/feborges/generate-user-pics: 3/4] accounts: Set generated user pic when no pic is set



commit 21d2056ba283fba5ddf3f70f0e69e5373ae4a728
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Oct 23 12:15:12 2018 +0200

    accounts: Set generated user pic when no pic is set
    
    The default user picture is blank.
    
    https://wiki.gnome.org/Design/OS/AvatarChooser#Tentative_Design
    
    Fixes #6

 .../pages/account/gis-account-page-local.c            |  1 +
 gnome-initial-setup/pages/account/um-photo-dialog.c   | 19 ++++++++++++++++++-
 gnome-initial-setup/pages/account/um-utils.c          | 13 ++++++++++---
 3 files changed, 29 insertions(+), 4 deletions(-)
---
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 d8273a9..70a8242 100644
--- a/gnome-initial-setup/pages/account/gis-account-page-local.c
+++ b/gnome-initial-setup/pages/account/gis-account-page-local.c
@@ -433,6 +433,7 @@ gis_account_page_local_constructed (GObject *object)
   priv->photo_dialog = um_photo_dialog_new (priv->avatar_button,
                                             avatar_callback,
                                             page);
+  um_photo_dialog_generate_avatar (priv->photo_dialog, "");
 
   validate (page);
 
diff --git a/gnome-initial-setup/pages/account/um-photo-dialog.c 
b/gnome-initial-setup/pages/account/um-photo-dialog.c
index e4ac51b..f7bd5ee 100644
--- a/gnome-initial-setup/pages/account/um-photo-dialog.c
+++ b/gnome-initial-setup/pages/account/um-photo-dialog.c
@@ -56,6 +56,7 @@ struct _UmPhotoDialog {
         GListStore *recent_faces;
         GListStore *faces;
         GFile *generated_avatar;
+        gboolean custom_avatar_was_chosen;
 
         SelectAvatarCallback *callback;
         gpointer              data;
@@ -83,6 +84,7 @@ webcam_response_cb (GtkDialog     *dialog,
                 pb2 = gdk_pixbuf_scale_simple (pb, 96, 96, GDK_INTERP_BILINEAR);
 
                 um->callback (pb2, NULL, um->data);
+                um->custom_avatar_was_chosen = TRUE;
 
                 g_object_unref (pb2);
                 g_object_unref (pb);
@@ -146,10 +148,20 @@ face_widget_activated (GtkFlowBox      *flowbox,
         filename = g_object_get_data (G_OBJECT (image), "filename");
 
         um->callback (NULL, filename, um->data);
+        um->custom_avatar_was_chosen = TRUE;
 
         gtk_popover_popdown (GTK_POPOVER (um));
 }
 
+static void
+generated_avatar_activated (GtkFlowBox      *flowbox,
+                            GtkFlowBoxChild *child,
+                            UmPhotoDialog   *um)
+{
+        face_widget_activated (flowbox, child, um);
+        um->custom_avatar_was_chosen = FALSE;
+}
+
 static GtkWidget *
 create_face_widget (gpointer item,
                     gpointer user_data)
@@ -197,7 +209,8 @@ setup_photo_popup (UmPhotoDialog *um)
                                  um,
                                  NULL);
         g_signal_connect (um->recent_pictures, "child-activated",
-                          G_CALLBACK (face_widget_activated), um);
+                          G_CALLBACK (generated_avatar_activated), um);
+        um->custom_avatar_was_chosen = FALSE;
 
         dirs = g_get_system_data_dirs ();
         for (i = 0; dirs[i] != NULL; i++) {
@@ -301,6 +314,10 @@ um_photo_dialog_generate_avatar (UmPhotoDialog *um,
         g_list_store_insert (um->recent_faces, 0,
                              um->generated_avatar);
         gtk_widget_show_all (um->recent_pictures);
+
+        if (!um->custom_avatar_was_chosen) {
+                um->callback (NULL, g_file_get_path (um->generated_avatar), um->data);
+        }
 }
 
 UmPhotoDialog *
diff --git a/gnome-initial-setup/pages/account/um-utils.c b/gnome-initial-setup/pages/account/um-utils.c
index 94accd4..aab54f5 100644
--- a/gnome-initial-setup/pages/account/um-utils.c
+++ b/gnome-initial-setup/pages/account/um-utils.c
@@ -547,9 +547,16 @@ get_color_for_name (const gchar *name)
         };
 
         GdkRGBA color = { 255, 255, 255, 1.0 };
-        guint hash = g_str_hash (name);
-        gint number_of_colors = G_N_ELEMENTS (gnome_color_palette);
-        gint idx = hash % number_of_colors;
+        guint hash;
+        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;
 
         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]