gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis-gtk] 05/07: add prev-/forward-button functionality


From: gnunet
Subject: [taler-anastasis-gtk] 05/07: add prev-/forward-button functionality
Date: Tue, 15 Sep 2020 19:27:15 +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 55536d32eb6b99e06ecd8302dad83638cfc193d0
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Sep 15 18:35:38 2020 +0200

    add prev-/forward-button functionality
---
 contrib/anastasis_gtk_main_window.glade |  43 +++++-----
 src/anastasis/anastasis-gtk.c           |   2 +-
 src/anastasis/anastasis-gtk_backup.c    |  35 +--------
 src/anastasis/anastasis-gtk_helper.c    | 134 ++++++++++++++++++++++++++++----
 src/include/anastasis-gtk_helper.h      |  23 +++++-
 5 files changed, 173 insertions(+), 64 deletions(-)

diff --git a/contrib/anastasis_gtk_main_window.glade 
b/contrib/anastasis_gtk_main_window.glade
index e5548c8..0156671 100644
--- a/contrib/anastasis_gtk_main_window.glade
+++ b/contrib/anastasis_gtk_main_window.glade
@@ -8,21 +8,13 @@
     <property name="stock">gtk-go-up</property>
     <property name="icon_size">6</property>
   </object>
-  <object class="GtkListStore" id="continent_Europe_liststore">
+  <object class="GtkListStore" id="continent_liststore">
     <columns>
-      <!-- column-name country_name -->
-      <column type="gchararray"/>
-      <!-- column-name country_code -->
+      <!-- column-name continent_name -->
       <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_North_America_liststore">
+  <object class="GtkListStore" id="country_liststore">
     <columns>
       <!-- column-name country_name -->
       <column type="gchararray"/>
@@ -36,12 +28,6 @@
       </row>
     </data>
   </object>
-  <object class="GtkListStore" id="continent_liststore">
-    <columns>
-      <!-- column-name continent_name -->
-      <column type="gchararray"/>
-    </columns>
-  </object>
   <object class="GtkImage" id="restore_image">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -251,6 +237,7 @@
                                         <property 
name="enable_search">False</property>
                                         <property 
name="search_column">0</property>
                                         <property 
name="activate_on_single_click">True</property>
+                                        <signal name="row-activated" 
handler="anastasis_gtk_country_activated" swapped="no"/>
                                         <child internal-child="selection">
                                           <object class="GtkTreeSelection"/>
                                         </child>
@@ -291,7 +278,26 @@
                           </packing>
                         </child>
                         <child>
-                          <placeholder/>
+                          <object class="GtkFrame" 
id="anastasis_gtk_identity_frame">
+                            <property name="can_focus">False</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">none</property>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child type="label">
+                              <object class="GtkLabel">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">Who 
are you?</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">2</property>
+                          </packing>
                         </child>
                         <child>
                           <placeholder/>
@@ -419,6 +425,7 @@
               <object class="GtkButton" 
id="anastasis_gtk_main_window_forward_button">
                 <property name="label">gtk-go-forward</property>
                 <property name="visible">True</property>
+                <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_stock">True</property>
diff --git a/src/anastasis/anastasis-gtk.c b/src/anastasis/anastasis-gtk.c
index ed95502..18ab3ab 100644
--- a/src/anastasis/anastasis-gtk.c
+++ b/src/anastasis/anastasis-gtk.c
@@ -43,7 +43,7 @@ struct GNUNET_CONFIGURATION_Handle *cfg;
 /**
  * Actual state.
  */
-json_t *backup_state;
+json_t *redux_state;
 
 
 /**
diff --git a/src/anastasis/anastasis-gtk_backup.c 
b/src/anastasis/anastasis-gtk_backup.c
index e6f362a..7046f43 100644
--- a/src/anastasis/anastasis-gtk_backup.c
+++ b/src/anastasis/anastasis-gtk_backup.c
@@ -42,12 +42,12 @@ void
 anastasis_gtk_backup_button_clicked (GObject *object,
                                      gpointer user_data)
 {
-     backup_state = ANASTASIS_backup_start (cfg);
-     GNUNET_assert (0 == persist_state (backup_state));
+     redux_state = ANASTASIS_backup_start (cfg);
+     GNUNET_assert (0 == persist_state (redux_state));
 
-     if (check_state (backup_state, "ReduxInitialBackupState"))
+     if (check_state (redux_state, "ReduxInitialBackupState"))
      {
-          init_continent_list (backup_state);
+          init_continent_list (redux_state);
      
           gtk_widget_hide (GTK_WIDGET (GCG_get_main_window_object (
                                         "anastasis_gtk_start_frame")));
@@ -58,31 +58,4 @@ anastasis_gtk_backup_button_clicked (GObject *object,
      }
 }
 
-/**
- * Callback invoked if the the "back"-button is clicked.
- *
- * @param object
- * @param user_data unused
- */
-void
-anastasis_gtk_main_window_back_clicked (GObject *object,
-                                        gpointer user_data)
-{
-
-}
-
-
-/**
- * Callback invoked if the the "forward"-button is clicked.
- *
- * @param object
- * @param user_data unused
- */
-void
-anastasis_gtk_main_window_forward_clicked (GObject *object,
-                                           gpointer user_data)
-{
-
-}
-
 
diff --git a/src/anastasis/anastasis-gtk_helper.c 
b/src/anastasis/anastasis-gtk_helper.c
index c04d54e..daea5f5 100644
--- a/src/anastasis/anastasis-gtk_helper.c
+++ b/src/anastasis/anastasis-gtk_helper.c
@@ -102,11 +102,14 @@ action_cb (void *cls,
 {
     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")));
+        redux_state = json_deep_copy (result_state);
+        if (check_state (redux_state, "ReduxContinentSelectedState"))
+            init_country_list (redux_state, json_string_value (json_object_get 
(redux_state, "selected_continent")));
+        if (check_state (redux_state, "ReduxCountrySelectedState"))
+            gtk_widget_set_sensitive (GTK_WIDGET (GCG_get_main_window_object (
+                                        
"anastasis_gtk_main_window_forward_button")), true);
 
-        if (0 == persist_state (backup_state))
+        if (0 == persist_state (redux_state))
             return;
         else
             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -174,16 +177,12 @@ init_country_list (json_t *continent_selected_state,
     GtkTreeView *tree_view;
     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));
+        GCG_get_main_window_object ("country_liststore"));
     tree_view = GTK_TREE_VIEW (GCG_get_main_window_object 
("anastasis_gtk_country_treeview"));
     gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (country_liststore));
     gtk_list_store_clear (country_liststore);
@@ -195,7 +194,6 @@ init_country_list (json_t *continent_selected_state,
                             1, json_string_value (json_object_get (country, 
"code")),
                             -1);
     }
-    GNUNET_free (country_list);
 }
 
 
@@ -228,13 +226,123 @@ anastasis_gtk_continent_activated (GtkTreeView 
*tree_view,
             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,
+            if (check_state (redux_state, "ReduxContinentSelectedState"))
+                redux_state = ANASTASIS_backup_start (cfg);
+            ANASTASIS_backup_action (redux_state,
                                      "selection_continent",
                                      arguments,
                                      &action_cb,
                                      NULL);
             g_free(continent_name);
         }
+}
+
+
+/**
+ * Callback invoked if a country is selected (row-activated signal).
+ *
+ * @param tree_view the object on which the signal is emitted
+ * @param path the GtkTreePath for the activated row
+ * @param column the GtkTreeViewColumn in which the activation occurred
+ * @param user_data user data set when the signal handler was connected 
(unused)
+ */
+void
+anastasis_gtk_country_activated (GtkTreeView *tree_view,
+                                 GtkTreePath *path,
+                                 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 *country_name;
+            gchar *country_code;
+            json_t *arguments = json_object ();
+
+            if (NULL == arguments)
+            {
+                GNUNET_break (0);
+            }
+            gtk_tree_model_get (model, &iter, 
+                                0, &country_name, 
+                                1, &country_code, 
+                                -1);
+            json_object_set (arguments, "country", json_string (country_name));
+
+            if (check_state (redux_state, "ReduxCountrySelectedState"))
+            {
+                /** FIXME: Do something (modify json state) */
+            }
+            ANASTASIS_backup_action (redux_state,
+                                     "selection_country",
+                                     arguments,
+                                     &action_cb,
+                                     NULL);
+            g_free(country_name);
+            g_free(country_code);
+        }
+}
+
+
+/**
+ * Callback invoked if the the "back"-button is clicked.
+ *
+ * @param object
+ * @param user_data unused
+ */
+void
+anastasis_gtk_main_window_back_clicked (GObject *object,
+                                        gpointer user_data)
+{
+    char *state = json_string_value (json_object_get (redux_state, 
"backup-state"));
+    if (!state)
+        state = json_string_value (json_object_get (redux_state, 
"recovery-state"));
+    GNUNET_assert (state);
+
+    if (gtk_widget_is_visible (GTK_WIDGET (GCG_get_main_window_object (
+                                        "anastasis_gtk_continent_frame"))))
+    {
+        /** FIXME: Show warning in this case, because state is lost afterwards 
*/
+        gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object (
+                                        "anastasis_gtk_start_frame")));
+        gtk_widget_hide (GTK_WIDGET (GCG_get_main_window_object (
+                                        "anastasis_gtk_main_control_vbox")));
+        gtk_widget_hide (GTK_WIDGET (GCG_get_main_window_object (
+                                        "anastasis_gtk_continent_frame")));
+        gtk_widget_set_sensitive (GTK_WIDGET (GCG_get_main_window_object (
+                                        
"anastasis_gtk_main_window_forward_button")), false);
+    }
+    if (gtk_widget_is_visible (GTK_WIDGET (GCG_get_main_window_object (
+                                        "anastasis_gtk_identity_frame"))))
+    {
+        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_identity_frame")));
+    }
+    
+}
+
+
+/**
+ * Callback invoked if the the "forward"-button is clicked.
+ *
+ * @param object
+ * @param user_data unused
+ */
+void
+anastasis_gtk_main_window_forward_clicked (GObject *object,
+                                           gpointer user_data)
+{
+    if (check_state (redux_state, "ReduxCountrySelectedState"))
+    {
+        gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object (
+                                        "anastasis_gtk_identity_frame")));
+        gtk_widget_hide (GTK_WIDGET (GCG_get_main_window_object (
+                                        "anastasis_gtk_continent_frame")));
+        gtk_widget_set_sensitive (GTK_WIDGET (GCG_get_main_window_object (
+                                        
"anastasis_gtk_main_window_forward_button")), false);
+    }
 }
\ No newline at end of file
diff --git a/src/include/anastasis-gtk_helper.h 
b/src/include/anastasis-gtk_helper.h
index 270472d..5d8d4a0 100644
--- a/src/include/anastasis-gtk_helper.h
+++ b/src/include/anastasis-gtk_helper.h
@@ -41,7 +41,7 @@ extern struct GNUNET_CONFIGURATION_Handle *cfg;
 /**
  * Actual state.
  */
-extern json_t *backup_state;
+extern json_t *redux_state;
 
 
 /**
@@ -107,3 +107,24 @@ void
 init_country_list (json_t *init_state,
                    const char *continent);
 
+
+/**
+ * Callback invoked if the the "back"-button is clicked.
+ *
+ * @param object
+ * @param user_data unused
+ */
+void
+anastasis_gtk_main_window_back_clicked (GObject *object,
+                                        gpointer user_data);
+
+
+/**
+ * Callback invoked if the the "forward"-button is clicked.
+ *
+ * @param object
+ * @param user_data unused
+ */
+void
+anastasis_gtk_main_window_forward_clicked (GObject *object,
+                                           gpointer user_data);
\ No newline at end of file

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