[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis-gtk] 03/07: fix continent selection
From: |
gnunet |
Subject: |
[taler-anastasis-gtk] 03/07: fix continent selection |
Date: |
Tue, 15 Sep 2020 19:27:13 +0200 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis-gtk.
commit c7f23efd50ac4d9fd49d02d5518bc76d3713fa5d
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Sep 15 15:44:30 2020 +0200
fix continent selection
---
contrib/anastasis_gtk_main_window.glade | 14 ++++
src/anastasis/anastasis-gtk_backup.c | 19 +++--
src/anastasis/anastasis-gtk_helper.c | 141 +++++++++++++++++---------------
3 files changed, 98 insertions(+), 76 deletions(-)
diff --git a/contrib/anastasis_gtk_main_window.glade
b/contrib/anastasis_gtk_main_window.glade
index 4618da6..37e6033 100644
--- a/contrib/anastasis_gtk_main_window.glade
+++ b/contrib/anastasis_gtk_main_window.glade
@@ -22,6 +22,20 @@
</row>
</data>
</object>
+ <object class="GtkListStore" id="continent_North_America_liststore">
+ <columns>
+ <!-- column-name country_name -->
+ <column type="gchararray"/>
+ <!-- column-name country_code -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0" translatable="yes">Germany</col>
+ <col id="1" translatable="yes">de</col>
+ </row>
+ </data>
+ </object>
<object class="GtkListStore" id="continent_liststore">
<columns>
<!-- column-name continent_name -->
diff --git a/src/anastasis/anastasis-gtk_backup.c
b/src/anastasis/anastasis-gtk_backup.c
index b465357..e6f362a 100644
--- a/src/anastasis/anastasis-gtk_backup.c
+++ b/src/anastasis/anastasis-gtk_backup.c
@@ -43,18 +43,19 @@ anastasis_gtk_backup_button_clicked (GObject *object,
gpointer user_data)
{
backup_state = ANASTASIS_backup_start (cfg);
-
- GNUNET_assert (check_state (backup_state, "ReduxInitialBackupState"));
GNUNET_assert (0 == persist_state (backup_state));
- init_continent_list (backup_state);
+ if (check_state (backup_state, "ReduxInitialBackupState"))
+ {
+ init_continent_list (backup_state);
- gtk_widget_hide (GTK_WIDGET (GCG_get_main_window_object (
- "anastasis_gtk_start_frame")));
- gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object (
- "anastasis_gtk_main_control_vbox")));
- gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object (
- "anastasis_gtk_continent_frame")));
+ gtk_widget_hide (GTK_WIDGET (GCG_get_main_window_object (
+ "anastasis_gtk_start_frame")));
+ gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object (
+ "anastasis_gtk_main_control_vbox")));
+ gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object (
+ "anastasis_gtk_continent_frame")));
+ }
}
/**
diff --git a/src/anastasis/anastasis-gtk_helper.c
b/src/anastasis/anastasis-gtk_helper.c
index fadcdc8..ee2322e 100644
--- a/src/anastasis/anastasis-gtk_helper.c
+++ b/src/anastasis/anastasis-gtk_helper.c
@@ -47,31 +47,6 @@ GCG_get_main_window_object (const char *name)
}
-/**
- * Function called with the results of #ANASTASIS_backup_action
- * or #ANASTASIS_recovery_action.
- *
- * @param cls closure
- * @param error_code Error code
- * @param new_state new state as result
- */
-static void
-action_cb (void *cls,
- enum ANASTASIS_ErrorCode error_code,
- json_t *result_state)
-{
- if (NULL != result_state)
- {
- backup_state = result_state;
- if (0 == persist_state (backup_state))
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to persist new state! \n");
- GNUNET_SCHEDULER_shutdown ();
-}
-
-
/**
* Function to persist a state.
*
@@ -112,6 +87,35 @@ persist_state (json_t *state)
}
+/**
+ * Function called with the results of #ANASTASIS_backup_action
+ * or #ANASTASIS_recovery_action.
+ *
+ * @param cls closure
+ * @param error_code Error code
+ * @param new_state new state as result
+ */
+static void
+action_cb (void *cls,
+ enum ANASTASIS_ErrorCode error_code,
+ json_t *result_state)
+{
+ if (NULL != result_state)
+ {
+ backup_state = json_deep_copy (result_state);
+ if (check_state (backup_state, "ReduxContinentSelectedState"))
+ init_country_list (backup_state, json_string_value
(json_object_get (backup_state, "selected_continent")));
+
+ if (0 == persist_state (backup_state))
+ return;
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to persist new state! \n");
+ }
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
/**
* Checks the actual state. True, if state is correct, else false.
*
@@ -167,31 +171,32 @@ void
init_country_list (json_t *continent_selected_state,
const char *continent)
{
- if (check_state (backup_state, "ReduxContinentSelectedState"))
+
+ GtkListStore *country_liststore;
+ GtkTreeIter iter;
+ char *country_list;
+ json_t *country;
+ size_t index;
+ json_t *countries = json_object_get (continent_selected_state,
"countries");
+
+ GNUNET_asprintf (&country_list,
+ "continent_%s_liststore",
+ continent);
+ country_liststore = GTK_LIST_STORE (
+ GCG_get_main_window_object (country_list));
+ gtk_list_store_clear (country_liststore);
+ json_array_foreach (countries, index, country)
{
- GtkListStore *country_liststore;
- GtkTreeIter iter;
- char *country_list;
- json_t *country;
- size_t index;
- json_t *countries = json_object_get (continent_selected_state,
"countries");
-
- sprintf (country_list,
- "continent_%s_liststore",
- continent);
- country_liststore = GTK_LIST_STORE (
- GCG_get_main_window_object (country_list));
- gtk_list_store_clear (country_liststore);
- json_array_foreach (countries, index, country)
- {
- gtk_list_store_append (country_liststore, &iter);
- gtk_list_store_set (country_liststore, &iter,
- 0, json_string_value (json_object_get
(country, "name")), //FIXME implement i18n
- 1, json_string_value (json_object_get
(country, "code")),
- -1);
- }
- GNUNET_free (country_list);
+ gtk_list_store_append (country_liststore, &iter);
+ gtk_list_store_set (country_liststore, &iter,
+ 0, json_string_value (json_object_get (country,
"name")), //FIXME implement i18n
+ 1, json_string_value (json_object_get (country,
"code")),
+ -1);
+ gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object (
+ "anastasis_gtk_country_treeview")));
}
+ GNUNET_free (country_list);
+
}
@@ -209,26 +214,28 @@ anastasis_gtk_continent_activated (GtkTreeView *tree_view,
GtkTreeViewColumn *column,
gpointer user_data)
{
- GtkTreeIter iter;
- GtkTreeModel *model= gtk_tree_view_get_model (tree_view);
-
- if (gtk_tree_model_get_iter(model, &iter, path))
- {
- gchar *continent_name;
- json_t *arguments = json_object ();
+ GtkTreeIter iter;
+ GtkTreeModel *model= gtk_tree_view_get_model (tree_view);
- if (NULL == arguments)
+ if (gtk_tree_model_get_iter(model, &iter, path))
{
- GNUNET_break (0);
+ gchar *continent_name;
+ json_t *arguments = json_object ();
+
+ if (NULL == arguments)
+ {
+ GNUNET_break (0);
+ }
+ gtk_tree_model_get (model, &iter, 0, &continent_name, -1);
+ json_object_set (arguments, "continent", json_string
(continent_name));
+
+ if (check_state (backup_state, "ReduxContinentSelectedState"))
+ backup_state = ANASTASIS_backup_start (cfg);
+ ANASTASIS_backup_action (backup_state,
+ "selection_continent",
+ arguments,
+ &action_cb,
+ NULL);
+ g_free(continent_name);
}
- gtk_tree_model_get (model, &iter, 0, &continent_name, -1);
- json_object_set (arguments, "continent", json_string (continent_name));
- ANASTASIS_backup_action (backup_state,
- "selection_continent",
- arguments,
- &action_cb,
- NULL);
- init_country_list (backup_state, continent_name);
- g_free(continent_name);
- }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-anastasis-gtk] branch master updated (9ca91ba -> 560ddb0), gnunet, 2020/09/15
- [taler-anastasis-gtk] 04/07: fix country list, gnunet, 2020/09/15
- [taler-anastasis-gtk] 01/07: show continent list, gnunet, 2020/09/15
- [taler-anastasis-gtk] 03/07: fix continent selection,
gnunet <=
- [taler-anastasis-gtk] 02/07: worked on select country, gnunet, 2020/09/15
- [taler-anastasis-gtk] 07/07: start with identity attributes, gnunet, 2020/09/15
- [taler-anastasis-gtk] 06/07: fix country selection, gnunet, 2020/09/15
- [taler-anastasis-gtk] 05/07: add prev-/forward-button functionality, gnunet, 2020/09/15