[gnome-control-center] fingerprint-dialog: Don't limit the number of maximum enroll stages



commit 6bbbd8d04e70be4725c30140f4e1073c6c2eeca1
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Wed Apr 15 00:52:13 2020 +0200

    fingerprint-dialog: Don't limit the number of maximum enroll stages
    
    There are devices with more than 10 enroll stages we should handle, so
    instead of hardcoding a grid of images, let's just build this dynamically
    using a flowbox

 panels/user-accounts/data/account-fingerprint.ui | 124 ++---------------------
 panels/user-accounts/um-fingerprint-dialog.c     |  46 +++++----
 2 files changed, 37 insertions(+), 133 deletions(-)
---
diff --git a/panels/user-accounts/data/account-fingerprint.ui 
b/panels/user-accounts/data/account-fingerprint.ui
index 969f7ca30..1756877df 100644
--- a/panels/user-accounts/data/account-fingerprint.ui
+++ b/panels/user-accounts/data/account-fingerprint.ui
@@ -182,60 +182,20 @@
           </packing>
         </child>
         <child>
-          <object class="GtkHBox" id="enroll_hbox">
+          <object class="GtkFlowBox" id="enroll-flowbox">
             <property name="visible">True</property>
             <property name="margin-top">24</property>
             <property name="margin-bottom">24</property>
-            <child>
-              <object class="GtkImage" id="image1">
-                <property name="visible">True</property>
-                <property name="stock">gtk-no</property>
-                <property name="icon-size">6</property>
-              </object>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkImage" id="image2">
-                <property name="visible">True</property>
-                <property name="stock">gtk-no</property>
-                <property name="icon-size">6</property>
-              </object>
-              <packing>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkImage" id="image3">
-                <property name="visible">True</property>
-                <property name="stock">gtk-no</property>
-                <property name="icon-size">6</property>
-              </object>
-              <packing>
-                <property name="position">3</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkImage" id="image4">
-                <property name="visible">True</property>
-                <property name="stock">gtk-no</property>
-                <property name="icon-size">6</property>
-              </object>
-              <packing>
-                <property name="position">4</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkImage" id="image5">
-                <property name="visible">True</property>
-                <property name="stock">gtk-no</property>
-                <property name="icon-size">6</property>
-              </object>
-              <packing>
-                <property name="position">5</property>
-              </packing>
-            </child>
+            <property name="row-spacing">40</property>
+            <property name="column-spacing">100</property>
+            <property name="homogeneous">True</property>
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+            <property name="min-children-per-line">1</property>
+            <property name="max-children-per-line">5</property>
+            <property name="selection-mode">none</property>
+            <property name="focus-on-click">False</property>
+            <property name="can-focus">False</property>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -243,68 +203,6 @@
             <property name="position">1</property>
           </packing>
         </child>
-        <child>
-          <object class="GtkHBox" id="enroll2_hbox">
-            <property name="visible">True</property>
-            <property name="margin-top">24</property>
-            <property name="margin-bottom">24</property>
-            <child>
-              <object class="GtkImage" id="image6">
-                <property name="visible">True</property>
-                <property name="stock">gtk-no</property>
-                <property name="icon-size">6</property>
-              </object>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkImage" id="image7">
-                <property name="visible">True</property>
-                <property name="stock">gtk-no</property>
-                <property name="icon-size">6</property>
-              </object>
-              <packing>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkImage" id="image8">
-                <property name="visible">True</property>
-                <property name="stock">gtk-no</property>
-                <property name="icon-size">6</property>
-              </object>
-              <packing>
-                <property name="position">3</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkImage" id="image9">
-                <property name="visible">True</property>
-                <property name="stock">gtk-no</property>
-                <property name="icon-size">6</property>
-              </object>
-              <packing>
-                <property name="position">4</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkImage" id="image10">
-                <property name="visible">True</property>
-                <property name="stock">gtk-no</property>
-                <property name="icon-size">6</property>
-              </object>
-              <packing>
-                <property name="position">5</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
         <child>
           <object class="GtkLabel" id="status-label">
             <property name="visible">True</property>
diff --git a/panels/user-accounts/um-fingerprint-dialog.c b/panels/user-accounts/um-fingerprint-dialog.c
index 5ae8f2772..95b46a3b3 100644
--- a/panels/user-accounts/um-fingerprint-dialog.c
+++ b/panels/user-accounts/um-fingerprint-dialog.c
@@ -31,9 +31,6 @@
 #define TR(s) dgettext("fprintd", s)
 #include "fingerprint-strings.h"
 
-/* This must match the number of images on the 2nd page in the UI file */
-#define MAX_ENROLL_STAGES 10
-
 static GDBusProxy *manager = NULL;
 static GDBusConnection *connection = NULL;
 static gboolean is_disable = FALSE;
@@ -513,14 +510,17 @@ enroll_result (EnrollData *data, const char *result, gboolean done)
         char *msg;
 
         if (g_str_equal (result, "enroll-completed") || g_str_equal (result, "enroll-stage-passed")) {
-                char *name, *path;
+                GtkFlowBoxChild *child;
+                const char *path;
 
                 data->num_stages_done++;
-                name = g_strdup_printf ("image%d", data->num_stages_done);
-                path = g_strdup_printf ("/org/gnome/control-center/user-accounts/print_ok.png");
-                gtk_image_set_from_resource (GTK_IMAGE (WID (name)), path);
-                g_free (name);
-                g_free (path);
+                path = "/org/gnome/control-center/user-accounts/print_ok.png";
+                child = gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (WID ("enroll-flowbox")),
+                                                         data->num_stages_done - 1);
+                if (child) {
+                        GtkImage *image = GTK_IMAGE (gtk_bin_get_child (GTK_BIN (child)));
+                        gtk_image_set_from_resource (image, path);
+                }
         }
         if (g_str_equal (result, "enroll-completed")) {
                 gtk_label_set_text (GTK_LABEL (WID ("status-label")), _("Done!"));
@@ -572,6 +572,7 @@ assistant_prepare (GtkAssistant *ass, GtkWidget *page, EnrollData *data)
         if (g_str_equal (name, "enroll")) {
                 GError *error = NULL;
                 GtkBuilder *dialog = data->dialog;
+                GtkWidget *enroll_flowbox;
                 char *path;
                 guint i;
                 GVariant *result;
@@ -637,24 +638,29 @@ assistant_prepare (GtkAssistant *ass, GtkWidget *page, EnrollData *data)
                 }
 
                 data->num_enroll_stages = num_enroll_stages;
+                enroll_flowbox = WID ("enroll-flowbox");
 
                 /* Hide the extra "bulbs" if not needed */
-                for (i = MAX_ENROLL_STAGES; i > data->num_enroll_stages; i--) {
-                        char *name;
-
-                        name = g_strdup_printf ("image%d", i);
-                        gtk_widget_hide (WID (name));
-                        g_free (name);
-                }
                 /* And set the right image */
                 {
                         path = g_strdup_printf ("/org/gnome/control-center/user-accounts/%s.png", 
data->finger);
                 }
                 for (i = 1; i <= data->num_enroll_stages; i++) {
-                        char *name;
-                        name = g_strdup_printf ("image%d", i);
-                        gtk_image_set_from_resource (GTK_IMAGE (WID (name)), path);
-                        g_free (name);
+                        GtkWidget *image;
+                        GtkFlowBoxChild *child;
+
+                        child = gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (enroll_flowbox), i-1);
+                        if (child) {
+                                image = gtk_bin_get_child (GTK_BIN (child));
+                                gtk_image_set_from_resource (GTK_IMAGE (image), path);
+                        } else {
+                                child = GTK_FLOW_BOX_CHILD (gtk_flow_box_child_new ());
+                                image = gtk_image_new_from_resource (path);
+                                gtk_widget_set_can_focus (GTK_WIDGET (child), FALSE);
+                                gtk_container_add (GTK_CONTAINER (child), image);
+                                gtk_container_add (GTK_CONTAINER (enroll_flowbox), GTK_WIDGET (child));
+                                gtk_widget_show_all (GTK_WIDGET (child));
+                        }
                 }
                 g_free (path);
 


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