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



commit aabb58a837efe201b5e9d080fef5b546f9a69b01
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

 gnome-initial-setup/pages/account/gis-account-page-local.c | 1 +
 gnome-initial-setup/pages/account/um-photo-dialog.c        | 8 ++++++++
 gnome-initial-setup/pages/account/um-utils.c               | 3 +++
 3 files changed, 12 insertions(+)
---
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 9af4dd7..b957cb4 100644
--- a/gnome-initial-setup/pages/account/gis-account-page-local.c
+++ b/gnome-initial-setup/pages/account/gis-account-page-local.c
@@ -437,6 +437,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 7d758d6..b0168f3 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_choosen;
 
         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_choosen = TRUE;
 
                 g_object_unref (pb2);
                 g_object_unref (pb);
@@ -146,6 +148,7 @@ face_widget_activated (GtkFlowBox      *flowbox,
         filename = g_object_get_data (G_OBJECT (image), "filename");
 
         um->callback (NULL, filename, um->data);
+        um->custom_avatar_was_choosen = TRUE;
 
         gtk_popover_popdown (GTK_POPOVER (um));
 }
@@ -198,6 +201,7 @@ setup_photo_popup (UmPhotoDialog *um)
                                  NULL);
         g_signal_connect (um->recent_pictures, "child-activated",
                           G_CALLBACK (face_widget_activated), um);
+        um->custom_avatar_was_choosen = FALSE;
 
         dirs = g_get_system_data_dirs ();
         for (i = 0; dirs[i] != NULL; i++) {
@@ -299,6 +303,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_choosen) {
+                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 924bd11..c87c27b 100644
--- a/gnome-initial-setup/pages/account/um-utils.c
+++ b/gnome-initial-setup/pages/account/um-utils.c
@@ -546,6 +546,9 @@ get_color_for_name (const gchar *name)
         gint number_of_colors = sizeof (gnome_color_palette)/sizeof (gnome_color_palette[0]);
         gint idx = hash % number_of_colors;
 
+        if (name == NULL || strlen (name) == 0)
+                return color;
+
         color.red   = gnome_color_palette[idx][0];
         color.green = gnome_color_palette[idx][1];
         color.blue  = gnome_color_palette[idx][2];


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