gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis-gtk] branch master updated: more data, less code


From: gnunet
Subject: [taler-anastasis-gtk] branch master updated: more data, less code
Date: Mon, 08 Mar 2021 10:26:15 +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 dc505f0  more data, less code
dc505f0 is described below

commit dc505f002d8274394df87f7ba8c4ee6b5553f320
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Mar 8 10:26:09 2021 +0100

    more data, less code
---
 contrib/anastasis_gtk_main_window.glade            |   2 +-
 src/anastasis/anastasis-gtk.c                      | 115 +++++++++++----------
 src/anastasis/anastasis-gtk_action.c               |  55 +++++++---
 ...anastasis-gtk_handle-main-window-back-clicked.c |   1 -
 ...stasis-gtk_handle-main-window-forward-clicked.c |  13 ++-
 5 files changed, 114 insertions(+), 72 deletions(-)

diff --git a/contrib/anastasis_gtk_main_window.glade 
b/contrib/anastasis_gtk_main_window.glade
index fe56068..61d4621 100644
--- a/contrib/anastasis_gtk_main_window.glade
+++ b/contrib/anastasis_gtk_main_window.glade
@@ -1025,7 +1025,7 @@ Provider</property>
           <object class="GtkBox" id="anastasis_gtk_main_control_vbox">
             <property name="can-focus">False</property>
             <child>
-              <object class="GtkButton" id="anastasis_gtk_main_prev_button">
+              <object class="GtkButton" 
id="anastasis_gtk_main_window_prev_button">
                 <property name="label">gtk-go-back</property>
                 <property name="visible">True</property>
                 <property name="can-focus">True</property>
diff --git a/src/anastasis/anastasis-gtk.c b/src/anastasis/anastasis-gtk.c
index 1955ad2..17e7ab7 100644
--- a/src/anastasis/anastasis-gtk.c
+++ b/src/anastasis/anastasis-gtk.c
@@ -70,67 +70,62 @@ void
 anastasis_gtk_animation_activate_cb (GtkMenuItem *menuitem,
                                      gpointer user_data)
 {
+  static const struct
+  {
+    const char *png;
+    const char *widget;
+  } map[] = {
+    { .png = "continent_selection.png",
+      .widget = "anastasis_gtk_continent_selection_image" },
+    { .png = "country_selection.png",
+      .widget = "anastasis_gtk_country_selection_image" },
+    { .png = "user_attributes.png",
+      .widget = "anastasis_gtk_user_attributes_image" },
+    { .png = "authentication_methods.png",
+      .widget = "anastasis_gtk_b_authentication_methods_image" },
+    { .png = NULL,
+      .widget = NULL }
+  };
+  char *path;
+
   if (gtk_widget_is_visible (GTK_WIDGET (GCG_get_main_window_object (
                                            
"anastasis_gtk_illustration_vbox"))))
-    gtk_widget_hide (GTK_WIDGET (GCG_get_main_window_object (
-                                   "anastasis_gtk_illustration_vbox")));
-  else
   {
-    gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object (
-                                   "anastasis_gtk_illustration_vbox")));
-    // init pictures
+    AG_hide ("anastasis_gtk_illustration_vbox");
+    return;
+  }
+  AG_show ("anastasis_gtk_illustration_vbox");
+  path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_PREFIX);
+  if (NULL == path)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  for (unsigned int i = 0; NULL != map[i].png; i++)
+  {
+    GObject *img;
+
+    img = GCG_get_main_window_object (map[i].widget);
+    if (NULL == img)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Could not find widget `%s' to set image path\n",
+                  map[i].widget);
+    }
+    else
     {
-      char *path;
-      path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_PREFIX);
-      if (NULL == path)
-      {
-        GNUNET_break (0);
-        return;
-      }
-
-      // continent selection
-      char *con_sel_path;
-      GNUNET_asprintf (&con_sel_path,
-                       "%s/share/anastasis/continent_selection.png",
-                       path);
-      GObject *con_sel_img = GCG_get_main_window_object (
-        "anastasis_gtk_continent_selection_image");
-      gtk_image_set_from_file (GTK_IMAGE (con_sel_img), con_sel_path);
-      GNUNET_free (con_sel_path);
-
-      // country selection
-      char *cou_sel_path;
-      GNUNET_asprintf (&cou_sel_path,
-                       "%s/share/anastasis/country_selection.png",
-                       path);
-      GObject *cou_sel_img = GCG_get_main_window_object (
-        "anastasis_gtk_country_selection_image");
-      gtk_image_set_from_file (GTK_IMAGE (cou_sel_img), cou_sel_path);
-      GNUNET_free (cou_sel_path);
-
-      // user attributes
-      char *user_attr_path;
-      GNUNET_asprintf (&user_attr_path,
-                       "%s/share/anastasis/user_attributes.png",
-                       path);
-      GObject *user_attr_img = GCG_get_main_window_object (
-        "anastasis_gtk_user_attributes_image");
-      gtk_image_set_from_file (GTK_IMAGE (user_attr_img), user_attr_path);
-      GNUNET_free (user_attr_path);
-
-      // authentication methods
-      char *auth_meth_path;
-      GNUNET_asprintf (&auth_meth_path,
-                       "%s/share/anastasis/authentication_methods.png",
-                       path);
-      GObject *auth_meth_img = GCG_get_main_window_object (
-        "anastasis_gtk_b_authentication_methods_image");
-      gtk_image_set_from_file (GTK_IMAGE (auth_meth_img), auth_meth_path);
-      GNUNET_free (auth_meth_path);
-
-      GNUNET_free (path);
+      char *ip;
+
+      GNUNET_asprintf (&ip,
+                       "%s/share/anastasis/%s",
+                       path,
+                       map[i].png);
+      gtk_image_set_from_file (GTK_IMAGE (img),
+                               ip);
+      GNUNET_free (ip);
     }
   }
+  GNUNET_free (path);
 }
 
 
@@ -234,6 +229,16 @@ shutdown_task (void *cls)
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Shutdown initiated\n");
   ANASTASIS_redux_done ();
+  if (NULL != ctx)
+  {
+    GNUNET_CURL_fini (ctx);
+    ctx = NULL;
+  }
+  if (NULL != rc)
+  {
+    GNUNET_CURL_gnunet_rc_destroy (rc);
+    rc = NULL;
+  }
   GNUNET_GTK_main_loop_quit (ml);
   ml = NULL;
   if (NULL != ra)
diff --git a/src/anastasis/anastasis-gtk_action.c 
b/src/anastasis/anastasis-gtk_action.c
index 2952737..bf06886 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -70,9 +70,16 @@ persist_state (json_t *state)
                      mode);
     GNUNET_free (path);
   }
-  return json_dump_file (state,
-                         dn,
-                         JSON_COMPACT);
+
+  {
+    int ret;
+
+    ret = json_dump_file (state,
+                          dn,
+                          JSON_COMPACT);
+    GNUNET_free (dn);
+    return (0 == ret) ? GNUNET_OK : GNUNET_NO;
+  }
 }
 
 
@@ -87,6 +94,7 @@ action_continent_selecting (void)
 
   AG_hide_all_frames ();
   gtk_list_store_clear (country_liststore);
+  AG_insensitive ("anastasis_gtk_main_window_prev_button");
   AG_insensitive ("anastasis_gtk_main_window_forward_button");
   {
     GtkListStore *continent_liststore;
@@ -128,16 +136,16 @@ action_continent_selecting (void)
 static void
 action_country_selecting (void)
 {
-  const char *continent;
   GtkListStore *country_liststore;
   json_t *countries;
+  const char *selected_country;
 
   AG_hide_all_frames ();
-  continent = json_string_value (json_object_get (
-                                   redux_state,
-                                   "selected_continent"));
   countries = json_object_get (redux_state,
                                "countries");
+  selected_country
+    = json_string_value (json_object_get (redux_state,
+                                          "selected_country"));
   country_liststore = GTK_LIST_STORE (
     GCG_get_main_window_object ("country_liststore"));
   gtk_list_store_clear (country_liststore);
@@ -148,8 +156,11 @@ action_country_selecting (void)
     json_array_foreach (countries, index, country)
     {
       GtkTreeIter iter;
+      const char *code;
 
       /* FIXME: use proper enum for columns instead of 0/1/2 */
+      code = json_string_value (json_object_get (country,
+                                                 "code"));
       gtk_list_store_insert_with_values (
         country_liststore,
         &iter,
@@ -157,14 +168,28 @@ action_country_selecting (void)
         0,
         json_string_value (json_object_get (country, "name")),
         1,
-        json_string_value (json_object_get (country, "code")),
+        code,
         2,
         json_string_value (json_object_get (country, "currency")),
         -1);
-      /* FIXME: select this country IF state says so! */
+      if ( (NULL != selected_country) &&
+           (NULL != code) &&
+           (0 == strcmp (code,
+                         selected_country)) )
+      {
+        GtkTreeView *tv;
+        GtkTreeSelection *sel;
+
+        tv = GTK_TREE_VIEW (GCG_get_main_window_object (
+                              "anastasis_gtk_country_treeview"));
+        sel = gtk_tree_view_get_selection (tv);
+        gtk_tree_selection_select_iter (sel,
+                                        &iter);
+      }
     }
   }
 
+  AG_insensitive ("anastasis_gtk_main_window_prev_button");
   AG_insensitive ("anastasis_gtk_main_window_forward_button");
   AG_show ("anastasis_gtk_country_selection_image");
   AG_show ("anastasis_gtk_continent_frame");
@@ -180,9 +205,6 @@ action_user_attributes_collecting (void)
   const json_t *id_attributes;
 
   AG_hide_all_frames ();
-  AG_show ("anastasis_gtk_identity_frame");
-  AG_insensitive ("anastasis_gtk_main_window_forward_button");
-  AG_show ("anastasis_gtk_user_attributes_image");
 
   country = json_string_value (json_object_get (redux_state,
                                                 "selected_country"));
@@ -247,7 +269,11 @@ action_user_attributes_collecting (void)
     }
   }
 
-  AG_sensitive ("anastasis_gtk_main_window_forward_button");
+  AG_sensitive ("anastasis_gtk_main_window_prev_button");
+  // FIXME: check if dialog state is consistent, if so, enable forward button!
+  AG_insensitive ("anastasis_gtk_main_window_forward_button");
+  AG_show ("anastasis_gtk_identity_frame");
+  AG_show ("anastasis_gtk_user_attributes_image");
 }
 
 
@@ -326,7 +352,8 @@ AG_action_cb (void *cls,
   {
     json_decref (redux_state);
     redux_state = json_incref (response);
-    GNUNET_assert (0 == persist_state (redux_state));
+    GNUNET_break (GNUNET_SYSERR !=
+                  persist_state (redux_state));
   }
   if (GNUNET_OK ==
       AG_dispatch (actions))
diff --git a/src/anastasis/anastasis-gtk_handle-main-window-back-clicked.c 
b/src/anastasis/anastasis-gtk_handle-main-window-back-clicked.c
index a3c0279..41cb512 100644
--- a/src/anastasis/anastasis-gtk_handle-main-window-back-clicked.c
+++ b/src/anastasis/anastasis-gtk_handle-main-window-back-clicked.c
@@ -47,5 +47,4 @@ anastasis_gtk_main_window_back_clicked (GObject *object,
                                NULL,
                                &AG_action_cb,
                                NULL);
-  GNUNET_assert (NULL != ra);
 }
diff --git a/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c 
b/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
index 008ed0d..ee1b25f 100644
--- a/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
+++ b/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
@@ -35,13 +35,24 @@ void
 AG_forward_country_selecting (void)
 {
   GtkTreeIter iter;
+  GtkTreeView *tv;
   GtkTreeModel *model;
+  GtkTreeSelection *sel;
   gchar *country_name;
   gchar *country_code;
   gchar *country_currency;
   json_t *arguments;
 
-  model = GTK_TREE_MODEL (GCG_get_main_window_object ("country_liststore"));
+  tv = GTK_TREE_VIEW (GCG_get_main_window_object (
+                        "anastasis_gtk_country_treeview"));
+  sel = gtk_tree_view_get_selection (tv);
+  if (! gtk_tree_selection_get_selected (sel,
+                                         &model,
+                                         &iter))
+  {
+    GNUNET_break (0);
+    return;
+  }
   gtk_tree_model_get (model,
                       &iter,
                       0, &country_name,

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