gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis-gtk] branch master updated: finish user attributes entr


From: gnunet
Subject: [taler-anastasis-gtk] branch master updated: finish user attributes entry logic
Date: Mon, 08 Mar 2021 22:46:05 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository anastasis-gtk.

The following commit(s) were added to refs/heads/master by this push:
     new e6e5204  finish user attributes entry logic
e6e5204 is described below

commit e6e520406e58fb88bd32448e44e88d92a7c82a35
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Mar 8 22:46:03 2021 +0100

    finish user attributes entry logic
---
 contrib/anastasis_gtk_main_window.glade            |  19 ++-
 src/anastasis/anastasis-gtk_action.c               | 134 +++++++++++++++++----
 src/anastasis/anastasis-gtk_attributes.c           | 111 +++++------------
 ...astasis-gtk_handle-auth-delete-button-clicked.c |   4 +-
 .../anastasis-gtk_handle-identity-changed.c        |   2 +-
 5 files changed, 155 insertions(+), 115 deletions(-)

diff --git a/contrib/anastasis_gtk_main_window.glade 
b/contrib/anastasis_gtk_main_window.glade
index ef4c42a..e776f81 100644
--- a/contrib/anastasis_gtk_main_window.glade
+++ b/contrib/anastasis_gtk_main_window.glade
@@ -196,6 +196,7 @@
                                             <property 
name="visible">True</property>
                                             <property 
name="can-focus">True</property>
                                             <property 
name="receives-default">True</property>
+                                            <property name="tooltip-text" 
translatable="yes">Begin fresh backup process</property>
                                             <property 
name="image">backup_image</property>
                                             <signal name="clicked" 
handler="anastasis_gtk_backup_button_clicked" swapped="no"/>
                                           </object>
@@ -212,7 +213,7 @@
                                             <property 
name="visible">True</property>
                                             <property 
name="can-focus">True</property>
                                             <property 
name="receives-default">True</property>
-                                            <property name="tooltip-text" 
translatable="yes">Load file with safed Anastasis state</property>
+                                            <property name="tooltip-text" 
translatable="yes">Continue from file with saved Anastasis state</property>
                                             <property 
name="use-stock">True</property>
                                             <signal name="clicked" 
handler="anastasis_gtk_open_state_clicked_cb" swapped="no"/>
                                           </object>
@@ -229,6 +230,7 @@
                                             <property 
name="visible">True</property>
                                             <property 
name="can-focus">True</property>
                                             <property 
name="receives-default">True</property>
+                                            <property name="tooltip-text" 
translatable="yes">Begin secret recovery process</property>
                                             <property 
name="image">restore_image</property>
                                           </object>
                                           <packing>
@@ -374,6 +376,7 @@
                                         <property 
name="orientation">vertical</property>
                                         <child>
                                           <object class="GtkBox" 
id="anastasis_gtk_ia_full_name_box">
+                                            <property 
name="visible">True</property>
                                             <property 
name="can-focus">False</property>
                                             <child>
                                               <object class="GtkLabel" 
id="anastasis_gtk_ia_full_name_label">
@@ -483,11 +486,11 @@
                                               <object class="GtkEntry" 
id="anastasis_gtk_ia_ahv_entry">
                                                 <property 
name="visible">True</property>
                                                 <property 
name="can-focus">True</property>
-                                                <property 
name="max-length">13</property>
-                                                <property 
name="width-chars">14</property>
-                                                <property 
name="max-width-chars">13</property>
+                                                <property 
name="max-length">16</property>
+                                                <property 
name="width-chars">17</property>
+                                                <property 
name="max-width-chars">16</property>
                                                 <property 
name="caps-lock-warning">False</property>
-                                                <property 
name="placeholder-text" translatable="yes">7561234567897</property>
+                                                <property 
name="placeholder-text" translatable="yes">756.1222.3425.89</property>
                                                 <property 
name="input-purpose">number</property>
                                                 <signal name="changed" 
handler="AG_identity_changed" swapped="no"/>
                                               </object>
@@ -1071,7 +1074,6 @@ Providers</property>
                             </child>
                             <child>
                               <object class="GtkFrame" 
id="anastasis_gtk_enter_secret_frame">
-                                <property name="visible">True</property>
                                 <property name="can-focus">False</property>
                                 <property name="label-xalign">0</property>
                                 <property name="shadow-type">none</property>
@@ -1185,7 +1187,6 @@ Providers</property>
                             </child>
                             <child>
                               <object class="GtkFrame" 
id="anastasis_gtk_pay_frame">
-                                <property name="visible">True</property>
                                 <property name="can-focus">False</property>
                                 <property name="label-xalign">0</property>
                                 <property name="shadow-type">none</property>
@@ -1218,7 +1219,6 @@ Providers</property>
                             </child>
                             <child>
                               <object class="GtkFrame" 
id="anastasis_gtk_completed_frame">
-                                <property name="visible">True</property>
                                 <property name="can-focus">False</property>
                                 <property name="label-xalign">0</property>
                                 <property name="shadow-type">none</property>
@@ -1233,7 +1233,6 @@ Providers</property>
                                         <property 
name="can-focus">False</property>
                                         <child>
                                           <object class="GtkLabel" 
id="anastasis_gtk_success_backup_label">
-                                            <property 
name="visible">True</property>
                                             <property 
name="can-focus">False</property>
                                             <property name="label" 
translatable="yes">Your backup is complete.</property>
                                             <property 
name="justify">center</property>
@@ -1247,7 +1246,7 @@ Providers</property>
                                         </child>
                                         <child>
                                           <object class="GtkBox">
-                                            <property 
name="visible">True</property>
+                                            <property 
name="name">anastasis_gtk_success_recovery_box</property>
                                             <property 
name="can-focus">False</property>
                                             <property 
name="orientation">vertical</property>
                                             <child>
diff --git a/src/anastasis/anastasis-gtk_action.c 
b/src/anastasis/anastasis-gtk_action.c
index 15f4b94..b1709e6 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -233,14 +233,14 @@ ctor_date (const json_t *details)
  * in the #AG_entry_attributes and ensures that we never create the same
  * widget (by @a uuid) twice.
  *
- * @param uuid unique ID of the widget, only create one per UUID
+ * @param uh hash of unique ID of the widget, only create one per UUID
  * @param type type of the widget to create
  * @param label label to use
  * @param tooltip tooltip to use
  * @param id_attr potential additional inputs for the widget creation
  */
 static void
-create_attribute_widget (const char *uuid,
+create_attribute_widget (const struct GNUNET_HashCode *uh,
                          const char *type,
                          const char *label,
                          const char *tooltip,
@@ -258,14 +258,10 @@ create_attribute_widget (const char *uuid,
     { .type = NULL,
       .ctor = NULL }
   };
-  struct GNUNET_HashCode uh;
   GtkWidget *w;
 
-  GNUNET_CRYPTO_hash (uuid,
-                      strlen (uuid),
-                      &uh);
   w = GNUNET_CONTAINER_multihashmap_get (AG_entry_attributes,
-                                         &uh);
+                                         uh);
   if (NULL != w)
   {
     gtk_widget_show (w);
@@ -307,7 +303,7 @@ create_attribute_widget (const char *uuid,
                       5);        /* padding */
     GNUNET_assert (GNUNET_OK ==
                    GNUNET_CONTAINER_multihashmap_put (AG_entry_attributes,
-                                                      &uh,
+                                                      uh,
                                                       w,
                                                       
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
     {
@@ -331,6 +327,47 @@ create_attribute_widget (const char *uuid,
 }
 
 
+/**
+ * Expand base @a name of a widget based on the @a type to
+ * create the name of the widget with the data.
+ *
+ * @param name base name of the widget
+ * @param type type of the widget
+ * @return NULL on error
+ */
+static char *
+expand_name (const char *name,
+             const char *type)
+{
+  static struct
+  {
+    const char *type;
+    const char *suffix;
+  } type_map [] = {
+    { .type = "string",
+      .suffix = "entry" },
+    { .type = "date",
+      .suffix = "cal" },
+    { .type = NULL,
+      .suffix = NULL }
+  };
+  char *data_widget;
+
+  for (unsigned int i = 0; NULL != type_map[i].type; i++)
+  {
+    if (0 != strcmp (type_map[i].type,
+                     type))
+      continue;
+    GNUNET_asprintf (&data_widget,
+                     "%s_%s",
+                     name,
+                     type_map[i].suffix);
+    return data_widget;
+  }
+  return NULL;
+}
+
+
 static void
 action_user_attributes_collecting (void)
 {
@@ -349,8 +386,8 @@ action_user_attributes_collecting (void)
     {
       const char *widget_name = NULL;
       const char *attr_tooltip = NULL;
+      const char *attr_label = NULL;
       const char *attr_type;
-      const char *attr_label;
       const char *attr_uuid;
       struct GNUNET_JSON_Specification spec[] = {
         GNUNET_JSON_spec_mark_optional (
@@ -364,52 +401,103 @@ action_user_attributes_collecting (void)
         GNUNET_JSON_spec_string ("uuid",
                                  &attr_uuid),
         // FIXME: need i18n variant of spec_string!
-        GNUNET_JSON_spec_string ("label",
-                                 &attr_label),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_string ("label",
+                                   &attr_label)),
         GNUNET_JSON_spec_end ()
       };
+      struct GNUNET_HashCode uh;
+      GtkWidget *w = NULL;
 
+      json_dumpf (id_attr,
+                  stderr,
+                  JSON_INDENT (2));
       GNUNET_assert (GNUNET_OK ==
                      GNUNET_JSON_parse (id_attr,
                                         spec,
                                         NULL, NULL));
+      GNUNET_CRYPTO_hash (attr_uuid,
+                          strlen (attr_uuid),
+                          &uh);
       if (NULL != widget_name)
+      {
+        char *data_name;
+
+        data_name = expand_name (widget_name,
+                                 attr_type);
+        w = GTK_WIDGET (GCG_get_main_window_object (data_name));
+        if (NULL == w)
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                      "Widget `%s' not found, will try to create dynamic 
replacement\n",
+                      data_name);
+        }
+        GNUNET_free (data_name);
+      }
+      if ( (NULL != widget_name) &&
+           (NULL != w) &&
+           (NULL != attr_label) )
       {
         char *label_widget;
-        char *box_widget;
         GObject *label;
-        GObject *box;
 
         GNUNET_asprintf (&label_widget,
                          "%s_label",
                          widget_name);
         label = GCG_get_main_window_object (label_widget);
         if (NULL != label)
+        {
           gtk_label_set_text (GTK_LABEL (label),
                               attr_label);
+          AG_show (label_widget); /* should not be required */
+        }
+        GNUNET_free (label_widget);
+      }
+      if ( (NULL != widget_name) &&
+           (NULL != w) )
+      {
+        char *box_widget;
+        GObject *box;
+
         GNUNET_asprintf (&box_widget,
                          "%s_box",
                          widget_name);
-        AG_show (label_widget);
         box = GCG_get_main_window_object (box_widget);
-        if (NULL != box)
+        if (NULL == box)
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                      "Widget `%s' not found, cannot show entry element. 
BAD.\n",
+                      box_widget);
+        }
+        else
+        {
+          AG_show (box_widget);
           AG_show_children (box_widget);
-        GNUNET_free (label_widget);
+        }
         GNUNET_free (box_widget);
       }
-      else
+      if ( (NULL != w) &&
+           (! GNUNET_CONTAINER_multihashmap_contains (AG_entry_attributes,
+                                                      &uh)) )
       {
-        create_attribute_widget (attr_uuid,
-                                 attr_type,
-                                 attr_label,
-                                 attr_tooltip,
-                                 id_attr);
+        GNUNET_assert (GNUNET_OK ==
+                       GNUNET_CONTAINER_multihashmap_put (AG_entry_attributes,
+                                                          &uh,
+                                                          w,
+                                                          
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
       }
+      if (NULL != w)
+        continue;
+      create_attribute_widget (&uh,
+                               attr_type,
+                               attr_label,
+                               attr_tooltip,
+                               id_attr);
     }
   }
 
   AG_sensitive ("anastasis_gtk_main_window_prev_button");
-  AG_identity_changed ();
+  // AG_identity_changed ();
   AG_show ("anastasis_gtk_identity_frame");
   AG_show ("anastasis_gtk_user_attributes_image");
 }
diff --git a/src/anastasis/anastasis-gtk_attributes.c 
b/src/anastasis/anastasis-gtk_attributes.c
index 55153e0..34a039a 100644
--- a/src/anastasis/anastasis-gtk_attributes.c
+++ b/src/anastasis/anastasis-gtk_attributes.c
@@ -69,6 +69,18 @@ extract_cal (GtkWidget *cal)
 json_t *
 AG_collect_attributes ()
 {
+  static struct
+  {
+    const char *type;
+    json_t * (*extract)(GtkWidget *w);
+  } e_map [] = {
+    { .type = "string",
+      .extract = &extract_entry },
+    { .type = "date",
+      .extract = &extract_cal },
+    { .type = NULL,
+      .extract = NULL }
+  };
   const json_t *id_attributes;
   json_t *result;
   size_t index;
@@ -81,15 +93,12 @@ AG_collect_attributes ()
   GNUNET_assert (NULL != result);
   json_array_foreach (id_attributes, index, id_attr)
   {
+    json_t *val = NULL;
     GtkWidget *w;
-    const char *widget_name = NULL;
     const char *attr_name;
     const char *attr_type;
     const char *attr_uuid;
     struct GNUNET_JSON_Specification spec[] = {
-      GNUNET_JSON_spec_mark_optional (
-        GNUNET_JSON_spec_string ("widget",
-                                 &widget_name)),
       GNUNET_JSON_spec_string ("type",
                                &attr_type),
       GNUNET_JSON_spec_string ("name",
@@ -98,90 +107,34 @@ AG_collect_attributes ()
                                &attr_uuid),
       GNUNET_JSON_spec_end ()
     };
+    struct GNUNET_HashCode uh;
 
     GNUNET_assert (GNUNET_OK ==
                    GNUNET_JSON_parse (id_attr,
                                       spec,
                                       NULL, NULL));
-    if (NULL != widget_name)
-    {
-      static struct
-      {
-        const char *type;
-        const char *suffix;
-      } type_map [] = {
-        { .type = "string",
-          .suffix = "entry" },
-        { .type = "date",
-          .suffix = "cal" },
-        { .type = NULL,
-          .suffix = NULL }
-      };
-      char *data_widget;
-      bool found = false;
-
-      for (unsigned int i = 0; NULL != type_map[i].type; i++)
-      {
-        if (0 != strcmp (type_map[i].type,
-                         attr_type))
-          continue;
-        GNUNET_asprintf (&data_widget,
-                         "%s_%s",
-                         widget_name,
-                         type_map[i].suffix);
-        w = GTK_WIDGET (GCG_get_main_window_object (data_widget));
-        GNUNET_assert (NULL != w);
-        GNUNET_free (data_widget);
-        found = true;
-        break;
-      }
-      GNUNET_assert (found);
-    }
-    else
+    GNUNET_CRYPTO_hash (attr_uuid,
+                        strlen (attr_uuid),
+                        &uh);
+    w = GNUNET_CONTAINER_multihashmap_get (AG_entry_attributes,
+                                           &uh);
+    for (unsigned int i = 0; NULL != e_map[i].type; i++)
     {
-      struct GNUNET_HashCode uh;
-
-      GNUNET_CRYPTO_hash (attr_uuid,
-                          strlen (attr_uuid),
-                          &uh);
-      w = GNUNET_CONTAINER_multihashmap_get (AG_entry_attributes,
-                                             &uh);
-
+      if (0 != strcmp (e_map[i].type,
+                       attr_type))
+        continue;
+      val = e_map[i].extract (w);
+      break;
     }
-
+    if (NULL == val)
     {
-      static struct
-      {
-        const char *type;
-        json_t * (*extract)(GtkWidget *w);
-      } e_map [] = {
-        { .type = "string",
-          .extract = &extract_entry },
-        { .type = "date",
-          .extract = &extract_cal },
-        { .type = NULL,
-          .extract = NULL }
-      };
-      json_t *val = NULL;
-
-      for (unsigned int i = 0; NULL != e_map[i].type; i++)
-      {
-        if (0 != strcmp (e_map[i].type,
-                         attr_type))
-          continue;
-        val = e_map[i].extract (w);
-        break;
-      }
-      if (NULL == val)
-      {
-        json_decref (result);
-        return NULL;
-      }
-      GNUNET_assert (0 ==
-                     json_object_set_new (result,
-                                          attr_name,
-                                          val));
+      json_decref (result);
+      return NULL;
     }
+    GNUNET_assert (0 ==
+                   json_object_set_new (result,
+                                        attr_name,
+                                        val));
   }
   return json_pack ("{s:o}",
                     "identity_attributes",
diff --git a/src/anastasis/anastasis-gtk_handle-auth-delete-button-clicked.c 
b/src/anastasis/anastasis-gtk_handle-auth-delete-button-clicked.c
index d79fe82..38feb3f 100644
--- a/src/anastasis/anastasis-gtk_handle-auth-delete-button-clicked.c
+++ b/src/anastasis/anastasis-gtk_handle-auth-delete-button-clicked.c
@@ -111,8 +111,8 @@ delete_auth_method (gpointer user_data)
  * @param user_data unused
  */
 void
-anastasis_gtk_b_auth_method_btn_delete_clicked_cb (GObject *object,
-                                                   gpointer user_data)
+anastasis_gtk_authentication_method_delete_button_clicked_cb (GObject *object,
+                                                              gpointer 
user_data)
 {
 #if 0
   delete_auth_method (user_data);
diff --git a/src/anastasis/anastasis-gtk_handle-identity-changed.c 
b/src/anastasis/anastasis-gtk_handle-identity-changed.c
index 34a795b..e0a1735 100644
--- a/src/anastasis/anastasis-gtk_handle-identity-changed.c
+++ b/src/anastasis/anastasis-gtk_handle-identity-changed.c
@@ -74,7 +74,7 @@ check_attributes_fullfilled (void)
                                &result);
   if (NULL != ta)
   {
-    GNUNET_break (0);
+    result = true;
     ANASTASIS_redux_action_cancel (ta);
   }
   json_decref (args);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]