gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis-gtk] branch master updated: implement attribute widget


From: gnunet
Subject: [taler-anastasis-gtk] branch master updated: implement attribute widget restoration after restore from save
Date: Fri, 19 Mar 2021 12:12:01 +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 42e49fb  implement attribute widget restoration after restore from save
42e49fb is described below

commit 42e49fb1ef6a443c182bf54ca9acc8d137875908
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Fri Mar 19 12:11:44 2021 +0100

    implement attribute widget restoration after restore from save
---
 src/anastasis/anastasis-gtk_action.c     | 41 +++++++++----
 src/anastasis/anastasis-gtk_attributes.c | 98 ++++++++++++++++++++++++++++++--
 src/anastasis/anastasis-gtk_attributes.h | 14 +++++
 3 files changed, 138 insertions(+), 15 deletions(-)

diff --git a/src/anastasis/anastasis-gtk_action.c 
b/src/anastasis/anastasis-gtk_action.c
index 11f6e63..4d579bd 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -27,6 +27,7 @@
 #include <gnunet/platform.h>
 #include <gnunet/gnunet_util_lib.h>
 #include "anastasis-gtk_action.h"
+#include "anastasis-gtk_attributes.h"
 #include "anastasis-gtk_dispatch.h"
 #include "anastasis-gtk_helper.h"
 #include "anastasis-gtk_handle-identity-changed.h"
@@ -197,8 +198,9 @@ ctor_date (const json_t *details)
  * @param label label to use
  * @param tooltip tooltip to use
  * @param id_attr potential additional inputs for the widget creation
+ * @return created widget
  */
-static void
+static GtkWidget *
 create_attribute_widget (const struct GNUNET_HashCode *uh,
                          const char *type,
                          const char *label,
@@ -224,7 +226,7 @@ create_attribute_widget (const struct GNUNET_HashCode *uh,
   if (NULL != w)
   {
     gtk_widget_show (w);
-    return;
+    return w;
   }
   for (unsigned int i = 0; NULL != type_map[i].type; i++)
   {
@@ -277,12 +279,13 @@ create_attribute_widget (const struct GNUNET_HashCode *uh,
                         5);   /* padding */
 
     }
-    return;
+    return w;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
               "FATAL: required attribute type `%s' not supported\n",
               type);
   GNUNET_assert (0);
+  return NULL;
 }
 
 
@@ -348,6 +351,7 @@ action_user_attributes_collecting (void)
       const char *attr_label = NULL;
       const char *attr_type;
       const char *attr_uuid;
+      const char *attr_name;
       struct GNUNET_JSON_Specification spec[] = {
         GNUNET_JSON_spec_mark_optional (
           GNUNET_JSON_spec_string ("widget",
@@ -359,7 +363,9 @@ action_user_attributes_collecting (void)
                                  &attr_type),
         GNUNET_JSON_spec_string ("uuid",
                                  &attr_uuid),
-        // FIXME: need i18n variant of spec_string!
+        GNUNET_JSON_spec_string ("name",
+                                 &attr_name),
+        // FIXME-#6749: need i18n variant of spec_string!
         GNUNET_JSON_spec_mark_optional (
           GNUNET_JSON_spec_string ("label",
                                    &attr_label)),
@@ -442,16 +448,29 @@ action_user_attributes_collecting (void)
                                                           w,
                                                           
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
       }
+      if (NULL == w)
+       w = create_attribute_widget (&uh,
+                                    attr_type,
+                                    attr_label,
+                                    attr_tooltip,
+                                    id_attr);
       if (NULL != w)
-        continue;
-      create_attribute_widget (&uh,
-                               attr_type,
-                               attr_label,
-                               attr_tooltip,
-                               id_attr);
+      {
+       json_t *ia;
+       json_t *val;
+
+       ia = json_object_get (redux_state,
+                             "identity_attributes");
+       val = json_object_get (ia,
+                              attr_name);
+       if ( (NULL != val) &&
+            (! json_is_null (val)) )
+         AG_import_attribute_data (w,
+                                   attr_type,
+                                   val);
+      }
     }
   }
-  // FIXME: add KNOWN attributes from state to widgets!
 
   AG_sensitive ("anastasis_gtk_main_window_prev_button");
   AG_identity_changed ();
diff --git a/src/anastasis/anastasis-gtk_attributes.c 
b/src/anastasis/anastasis-gtk_attributes.c
index 34a039a..f57e3bb 100644
--- a/src/anastasis/anastasis-gtk_attributes.c
+++ b/src/anastasis/anastasis-gtk_attributes.c
@@ -36,7 +36,8 @@ extract_entry (GtkWidget *entry)
   const gchar *txt;
 
   txt = gtk_entry_get_text (GTK_ENTRY (entry));
-  if (0 == strlen (txt))
+  if ( (NULL ==  txt) ||
+       (0 == strlen (txt)) )
     return NULL;
   return json_string (txt);
 }
@@ -45,9 +46,9 @@ extract_entry (GtkWidget *entry)
 static json_t *
 extract_cal (GtkWidget *cal)
 {
-  guint day;
-  guint month;
-  guint year;
+  guint day = 0;
+  guint month = 0;
+  guint year = 0;
   char txt[12];
 
   gtk_calendar_get_date (GTK_CALENDAR (cal),
@@ -140,3 +141,92 @@ AG_collect_attributes ()
                     "identity_attributes",
                     result);
 }
+
+
+/**
+ * Import string value into a GtkEntry.
+ *
+ * @param w should be a GtkEntry
+ * @param value should be a string value
+ */
+static void
+import_entry (GtkWidget *w,
+             const json_t *value)
+{
+  GNUNET_break (json_is_string (value));
+  gtk_entry_set_text (GTK_ENTRY (w),
+                     json_string_value (value));
+}
+
+
+/**
+ * Import date value into a GtkCalendar.
+ *
+ * @param w should be a GtkCalendar
+ * @param value should be a date value
+ */
+static void
+import_cal (GtkWidget *w,
+           const json_t *value)
+{
+  const char *s;
+  guint day;
+  guint month;
+  guint year;
+  char dummy;
+
+  s = json_string_value (value);
+  if (NULL == s)
+    {
+      GNUNET_break (0);
+      return;
+    }
+  if (3 !=
+      sscanf (s,
+             "%04u-%02u-%02u%c",
+             &year,
+             &month,
+             &day,
+             &dummy))
+    {
+      GNUNET_break (0);
+      return;
+    }
+  gtk_calendar_select_day (GTK_CALENDAR (w),
+                         day);
+  gtk_calendar_select_month (GTK_CALENDAR (w),
+                            month,
+                            year);
+}
+
+
+void
+AG_import_attribute_data (GtkWidget *w,
+                         const char *type,
+                         const json_t *value)
+{
+  static struct
+  {
+    const char *type;
+    void (*import)(GtkWidget *w,
+                  const json_t *value);
+  } i_map [] = {
+    { .type = "string",
+      .import = &import_entry },
+    { .type = "date",
+      .import = &import_cal },
+    { .type = NULL,
+      .import = NULL }
+  };
+
+  for (unsigned int i = 0; NULL != i_map[i].type; i++)
+  {
+    if (0 != strcmp (i_map[i].type,
+                    type))
+      continue;
+    i_map[i].import (w,
+                    value);
+    return;
+  }
+
+}
diff --git a/src/anastasis/anastasis-gtk_attributes.h 
b/src/anastasis/anastasis-gtk_attributes.h
index e6480e8..5171e27 100644
--- a/src/anastasis/anastasis-gtk_attributes.h
+++ b/src/anastasis/anastasis-gtk_attributes.h
@@ -36,4 +36,18 @@
 json_t *
 AG_collect_attributes (void);
 
+
+/**
+ * Set widget @a w value from a the @a value. 
+ *
+ * @param w a widget to initialize
+ * @param type the attribute type of the widget and the value
+ * @param value the value to restore to the widget @a w
+ */
+void
+AG_import_attribute_data (GtkWidget *w,
+                         const char *type,
+                         const json_t *value);
+
+
 #endif

-- 
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]