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 open/save/edit pr


From: gnunet
Subject: [taler-anastasis-gtk] branch master updated: implement open/save/edit providers
Date: Tue, 09 Mar 2021 21:14:00 +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 cf165bd  implement open/save/edit providers
cf165bd is described below

commit cf165bde9b0602d9f7c5c916a6f55b7e96b44bfe
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Mar 9 21:13:58 2021 +0100

    implement open/save/edit providers
---
 contrib/Makefile.am                                |   4 +-
 contrib/anastasis_gtk_edit_providers.glade         | 216 +++++++++++++++++--
 contrib/anastasis_gtk_main_window.glade            |  38 +++-
 src/anastasis/Makefile.am                          |   1 +
 src/anastasis/anastasis-gtk.c                      |  55 ++---
 src/anastasis/anastasis-gtk.h                      |   8 +
 src/anastasis/anastasis-gtk_action.c               |  87 +++-----
 ...astasis-gtk_handle-auth-edit-provider-clicked.c | 230 ++++++++++++++++++++-
 ...stasis-gtk_handle-main-window-forward-clicked.c |   6 +-
 ...stasis-gtk_handle-main-window-forward-clicked.h |   5 +
 src/anastasis/anastasis-gtk_helper.c               |  32 +++
 src/anastasis/anastasis-gtk_helper.h               |  11 +
 12 files changed, 572 insertions(+), 121 deletions(-)

diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index b33d453..49a6b64 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -26,4 +26,6 @@ pkgdata_DATA = \
   anastasis_gtk_auth_add_sms.glade \
   anastasis_gtk_auth_add_video.glade \
   anastasis_gtk_edit_providers.glade \
-  anastasis_gtk_main_window.glade
+  anastasis_gtk_open_file_dialog.glade \
+  anastasis_gtk_main_window.glade \
+  anastasis_gtk_save_file_dialog.glade
diff --git a/contrib/anastasis_gtk_edit_providers.glade 
b/contrib/anastasis_gtk_edit_providers.glade
index 08ab86f..593aa01 100644
--- a/contrib/anastasis_gtk_edit_providers.glade
+++ b/contrib/anastasis_gtk_edit_providers.glade
@@ -1,26 +1,59 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.38.2 
+
+Copyright (C) Anastasis SARL
+
+This file is part of Anastasis-gtk.
+
+Anastasis-gtk is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Anastasis-gtk is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with Anastasis-gtk.  If not, see <http://www.gnu.org/licenses/>.
+
+-->
 <interface>
-  <requires lib="gtk+" version="3.0"/>
-  <object class="GtkListStore" id="provider_liststore"/>
-  <object class="GtkDialog" id="anastasis_gtk_b_edit_provider_dialog">
+  <requires lib="gtk+" version="3.2"/>
+  <!-- interface-license-type lgplv3 -->
+  <!-- interface-name Anastasis-gtk -->
+  <!-- interface-copyright Anastasis SARL -->
+  <object class="GtkListStore" id="provider_liststore">
+    <columns>
+      <!-- column-name url -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <object class="GtkDialog" id="edit_provider_dialog">
     <property name="can-focus">False</property>
+    <property name="modal">True</property>
+    <property name="window-position">center</property>
     <property name="type-hint">dialog</property>
+    <signal name="response" handler="edit_provider_dialog_response_cb" 
swapped="no"/>
     <child internal-child="vbox">
       <object class="GtkBox">
+        <property name="visible">True</property>
         <property name="can-focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child internal-child="action_area">
           <object class="GtkButtonBox">
+            <property name="visible">True</property>
             <property name="can-focus">False</property>
             <property name="layout-style">end</property>
             <child>
-              <object class="GtkButton">
-                <property name="label" translatable="yes">Cancel</property>
+              <object class="GtkButton" id="cancel_button">
+                <property name="label">gtk-cancel</property>
                 <property name="visible">True</property>
-                <property name="can-focus">True</property>
-                <property name="receives-default">True</property>
+                <property name="can-focus">False</property>
+                <property name="receives-default">False</property>
+                <property name="use-stock">True</property>
               </object>
               <packing>
                 <property name="expand">True</property>
@@ -29,11 +62,12 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton">
-                <property name="label" translatable="yes">OK</property>
+              <object class="GtkButton" id="close_button">
+                <property name="label">gtk-apply</property>
                 <property name="visible">True</property>
-                <property name="can-focus">True</property>
-                <property name="receives-default">True</property>
+                <property name="can-focus">False</property>
+                <property name="receives-default">False</property>
+                <property name="use-stock">True</property>
               </object>
               <packing>
                 <property name="expand">True</property>
@@ -49,28 +83,174 @@
           </packing>
         </child>
         <child>
-          <object class="GtkTreeView">
+          <object class="GtkBox">
             <property name="visible">True</property>
             <property name="can-focus">True</property>
-            <property name="model">provider_liststore</property>
-            <child internal-child="selection">
-              <object class="GtkTreeSelection"/>
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="margin-left">10</property>
+                    <property name="label" translatable="yes">Provider 
URL:</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="padding">5</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="url_entry">
+                    <property name="visible">True</property>
+                    <property name="can-focus">True</property>
+                    <property name="has-focus">True</property>
+                    <property name="is-focus">True</property>
+                    <property name="activates-default">True</property>
+                    <property name="width-chars">54</property>
+                    <property name="primary-icon-stock">gtk-edit</property>
+                    <property 
name="secondary-icon-activatable">False</property>
+                    <property name="secondary-icon-sensitive">False</property>
+                    <property name="placeholder-text" 
translatable="yes">https://</property>
+                    <signal name="changed" handler="url_entry_changed_cb" 
swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="padding">5</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="add_button">
+                    <property name="label">gtk-add</property>
+                    <property name="visible">True</property>
+                    <property name="sensitive">False</property>
+                    <property name="can-focus">False</property>
+                    <property name="can-default">True</property>
+                    <property name="has-default">True</property>
+                    <property name="receives-default">True</property>
+                    <property name="use-stock">True</property>
+                    <signal name="clicked" handler="url_add_button_clicked_cb" 
swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="padding">5</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <child>
+                  <object class="GtkFrame">
+                    <property name="visible">True</property>
+                    <property name="sensitive">False</property>
+                    <property name="can-focus">False</property>
+                    <property name="margin-top">10</property>
+                    <property name="label-xalign">0</property>
+                    <property name="shadow-type">none</property>
+                    <child>
+                      <object class="GtkAlignment">
+                        <property name="visible">True</property>
+                        <property name="can-focus">False</property>
+                        <property name="left-padding">12</property>
+                        <child>
+                          <object class="GtkViewport">
+                            <property name="visible">True</property>
+                            <property name="can-focus">False</property>
+                            <child>
+                              <object class="GtkTreeView" 
id="provider_tree_view">
+                                <property name="height-request">300</property>
+                                <property name="visible">True</property>
+                                <property name="can-focus">False</property>
+                                <property 
name="model">provider_liststore</property>
+                                <child internal-child="selection">
+                                  <object class="GtkTreeSelection">
+                                    <property name="mode">browse</property>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="GtkTreeViewColumn">
+                                    <property name="sizing">autosize</property>
+                                    <property name="title" 
translatable="yes">URL</property>
+                                    <child>
+                                      <object class="GtkCellRendererText" 
id="url_renderer"/>
+                                      <attributes>
+                                        <attribute name="text">0</attribute>
+                                      </attributes>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child type="label">
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="sensitive">False</property>
+                        <property name="can-focus">False</property>
+                        <property name="label" translatable="yes">Known 
providers</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                        </attributes>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="padding">5</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
             </child>
           </object>
           <packing>
-            <property name="expand">False</property>
+            <property name="expand">True</property>
             <property name="fill">True</property>
             <property name="position">0</property>
           </packing>
         </child>
       </object>
     </child>
+    <action-widgets>
+      <action-widget response="-6">cancel_button</action-widget>
+      <action-widget response="-10">close_button</action-widget>
+    </action-widgets>
     <child type="titlebar">
       <object class="GtkLabel">
         <property name="visible">True</property>
         <property name="can-focus">False</property>
-        <property name="label" translatable="yes">Edit Provider</property>
+        <property name="label" translatable="yes">Add Anastasis 
provider</property>
       </object>
     </child>
+    <action-widgets>
+      <action-widget response="-6">cancel_button</action-widget>
+      <action-widget response="-10">close_button</action-widget>
+    </action-widgets>
   </object>
 </interface>
diff --git a/contrib/anastasis_gtk_main_window.glade 
b/contrib/anastasis_gtk_main_window.glade
index 6498d3a..e8332ac 100644
--- a/contrib/anastasis_gtk_main_window.glade
+++ b/contrib/anastasis_gtk_main_window.glade
@@ -1,7 +1,33 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.38.2 
+
+Copyright (C) Anastasis SARL
+
+This file is part of anastasis-gtk.
+
+anastasis-gtk is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+anastasis-gtk is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with anastasis-gtk.  If not, see <http://www.gnu.org/licenses/>.
+
+Author: Christian Grothoff, Dennis Neufeld
+
+-->
 <interface>
-  <requires lib="gtk+" version="3.0"/>
+  <requires lib="gtk+" version="3.12"/>
+  <!-- interface-license-type gplv3 -->
+  <!-- interface-name anastasis-gtk -->
+  <!-- interface-description Key backup and recovery -->
+  <!-- interface-copyright Anastasis SARL -->
+  <!-- interface-authors Christian Grothoff, Dennis Neufeld -->
   <object class="GtkImage" id="add_image">
     <property name="visible">True</property>
     <property name="can-focus">False</property>
@@ -189,6 +215,7 @@
                               <object class="GtkFrame" 
id="anastasis_gtk_start_frame">
                                 <property name="visible">True</property>
                                 <property name="can-focus">False</property>
+                                <property name="margin-top">10</property>
                                 <property name="label-xalign">0</property>
                                 <property name="shadow-type">none</property>
                                 <child>
@@ -200,6 +227,10 @@
                                       <object class="GtkBox" 
id="anastasis_gtk_primary_action_hbox">
                                         <property 
name="visible">True</property>
                                         <property 
name="can-focus">False</property>
+                                        <property 
name="margin-start">10</property>
+                                        <property 
name="margin-end">10</property>
+                                        <property 
name="margin-top">10</property>
+                                        <property 
name="margin-bottom">10</property>
                                         <child>
                                           <object class="GtkButton">
                                             <property name="label" 
translatable="yes">Backup</property>
@@ -268,6 +299,7 @@
                               <packing>
                                 <property name="expand">True</property>
                                 <property name="fill">True</property>
+                                <property name="padding">10</property>
                                 <property name="position">1</property>
                               </packing>
                             </child>
@@ -1022,7 +1054,7 @@
                             </child>
                             <child>
                               <object class="GtkFrame">
-                                <property name="visible">True</property>
+                                <property 
name="name">anastasis_gtk_challenge_frame</property>
                                 <property name="can-focus">False</property>
                                 <property name="label-xalign">0</property>
                                 <property name="shadow-type">none</property>
diff --git a/src/anastasis/Makefile.am b/src/anastasis/Makefile.am
index 6c6609f..b5a4956 100644
--- a/src/anastasis/Makefile.am
+++ b/src/anastasis/Makefile.am
@@ -16,6 +16,7 @@ anastasis_gtk_SOURCES = \
   anastasis-gtk_action.c anastasis-gtk_action.h \
   anastasis-gtk_attributes.c anastasis-gtk_attributes.h \
   anastasis-gtk_dispatch.c anastasis-gtk_dispatch.h \
+  anastasis-gtk_io.c \
   anastasis-gtk_handle-auth-delete-button-clicked.c \
   anastasis-gtk_handle-auth-edit-provider-clicked.c \
   anastasis-gtk_handle-backup-button-clicked.c \
diff --git a/src/anastasis/anastasis-gtk.c b/src/anastasis/anastasis-gtk.c
index d455380..e924e1f 100644
--- a/src/anastasis/anastasis-gtk.c
+++ b/src/anastasis/anastasis-gtk.c
@@ -26,6 +26,7 @@
  */
 #include <gnunet/platform.h>
 #include <gnunet/gnunet_util_lib.h>
+#include "anastasis-gtk_action.h"
 #include "anastasis-gtk_helper.h"
 #include <jansson.h>
 
@@ -198,36 +199,28 @@ anastasis_gtk_main_window_quit_button_clicked_cb 
(GtkButton *button,
 }
 
 
-/**
- * User clicked the "save as" button.
- *
- * @param button the button
- * @param user_data unused
- */
 void
-anastasis_gtk_open_state_clicked_cb (GtkButton *button,
-                                     gpointer user_data)
+AG_load (const char *filename)
 {
-  // FIXME: open dialog
-  // load state from file
-  GNUNET_break (0);
-}
-
+  json_error_t error;
+  json_t *in;
 
-/**
- * User clicked the "save as" button.
- *
- * @param button the button
- * @param user_data unused
- */
-void
-anastasis_gtk_main_window_save_as_button_clicked_cb (GtkButton *button,
-                                                     gpointer user_data)
-{
-  // FIXME: open save-as dialog
-  // dump state to file
-  // +exit?
-  GNUNET_break (0);
+  in = json_load_file (filename,
+                       JSON_REJECT_DUPLICATES,
+                       &error);
+  if (NULL == in)
+  {
+    AG_error ("Failed to parse file `%s' at %d:%d: %s\n",
+              filename,
+              error.line,
+              error.column,
+              error.text);
+    return;
+  }
+  AG_action_cb (NULL,
+                TALER_EC_NONE,
+                in);
+  json_decref (in);
 }
 
 
@@ -241,6 +234,8 @@ static void
 run (void *cls)
 {
   GtkWidget *main_window;
+  int argc;
+  char *const *argv;
 
   ml = cls;
   AG_entry_attributes = GNUNET_CONTAINER_multihashmap_create (16,
@@ -252,6 +247,12 @@ run (void *cls)
   cfg = GNUNET_GTK_main_loop_get_configuration (ml);
   GNUNET_GTK_set_icon_search_path ();
   GNUNET_GTK_setup_nls ();
+
+  GNUNET_GTK_main_loop_get_args (ml,
+                                 &argc,
+                                 &argv);
+  if (0 != argc)
+    AG_load (argv[0]);
   /* setup main window */
   main_window = GTK_WIDGET (
     GCG_get_main_window_object ("anastasis_gtk_main_window"));
diff --git a/src/anastasis/anastasis-gtk.h b/src/anastasis/anastasis-gtk.h
index df90378..80e858d 100644
--- a/src/anastasis/anastasis-gtk.h
+++ b/src/anastasis/anastasis-gtk.h
@@ -57,4 +57,12 @@ extern json_t *redux_state;
 extern struct ANASTASIS_ReduxAction *ra;
 
 
+/**
+ * Load #redux_state from @a filename.
+ *
+ * @param filename to load
+ */
+void
+AG_load (const char *filename);
+
 #endif
diff --git a/src/anastasis/anastasis-gtk_action.c 
b/src/anastasis/anastasis-gtk_action.c
index 7d6004b..1729ca7 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -32,58 +32,6 @@
 #include <jansson.h>
 
 
-/**
- * Function to persist a state.
- * FIXME: Don't use this like its used right now (=>PRIVACY)!
- *
- * @param state state to persist
- */
-static int
-persist_state (json_t *state)
-{
-  char *dn;
-
-  {
-    char *path;
-    char *mode;
-
-    if (NULL != json_object_get (state,
-                                 "backup_state"))
-      mode = "backup";
-    else if (NULL != json_object_get (state,
-                                      "recovery_state"))
-      mode = "recovery";
-    else
-    {
-      GNUNET_break (0);
-      return GNUNET_SYSERR;
-    }
-
-    path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_PREFIX);
-    if (NULL == path)
-    {
-      GNUNET_break (0);
-      return GNUNET_SYSERR;
-    }
-    GNUNET_asprintf (&dn,
-                     "%s/share/anastasis/%s_state.json",
-                     path,
-                     mode);
-    GNUNET_free (path);
-  }
-
-  {
-    int ret;
-
-    ret = json_dump_file (state,
-                          dn,
-                          JSON_COMPACT);
-    GNUNET_free (dn);
-    return (0 == ret) ? GNUNET_OK : GNUNET_NO;
-  }
-}
-
-
 /**
  * Prepare window for selection of the continent.
  */
@@ -125,6 +73,10 @@ action_continent_selecting (void)
     }
   }
 
+  AG_insensitive ("anastasis_gtk_main_window_prev_button");
+  AG_insensitive ("anastasis_gtk_main_window_forward_button");
+  AG_hide ("anastasis_gtk_main_window_prev_button");
+  AG_show ("anastasis_gtk_main_window_forward_button");
   AG_show ("anastasis_gtk_main_control_vbox");
   AG_show ("anastasis_gtk_continent_frame");
   AG_show ("anastasis_gtk_continent_selection_image");
@@ -192,6 +144,9 @@ action_country_selecting (void)
 
   AG_insensitive ("anastasis_gtk_main_window_prev_button");
   AG_insensitive ("anastasis_gtk_main_window_forward_button");
+  AG_show ("anastasis_gtk_main_control_vbox");
+  AG_hide ("anastasis_gtk_main_window_prev_button");
+  AG_show ("anastasis_gtk_main_window_forward_button");
   AG_show ("anastasis_gtk_country_selection_image");
   AG_show ("anastasis_gtk_continent_frame");
   AG_show ("anastasis_gtk_continent_selection_image");
@@ -494,7 +449,10 @@ action_user_attributes_collecting (void)
   }
 
   AG_sensitive ("anastasis_gtk_main_window_prev_button");
-  // AG_identity_changed ();
+  AG_show ("anastasis_gtk_main_control_vbox");
+  AG_show ("anastasis_gtk_main_window_prev_button");
+  AG_show ("anastasis_gtk_main_window_forward_button");
+  AG_identity_changed ();
   AG_show ("anastasis_gtk_identity_frame");
   AG_show ("anastasis_gtk_user_attributes_image");
 }
@@ -610,8 +568,11 @@ action_authentications_editing (void)
   }
   // FIXME: add logic to check if auth methods WERE added,
   // and if so, make button sensitive!
+  AG_sensitive ("anastasis_gtk_main_window_prev_button");
   AG_insensitive ("anastasis_gtk_main_window_forward_button");
-
+  AG_show ("anastasis_gtk_main_control_vbox");
+  AG_show ("anastasis_gtk_main_window_prev_button");
+  AG_show ("anastasis_gtk_main_window_forward_button");
   AG_show ("anastasis_gtk_b_authentication_frame");
   AG_show ("anastasis_gtk_b_authentication_methods_image");
 
@@ -661,29 +622,29 @@ AG_action_cb (void *cls,
       .action = NULL }
   };
 
+  (void) cls;
   ra = NULL;
   AG_thaw ();
   if (TALER_EC_NONE != error_code)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Error: %d\n",
-                error_code);
-    /* FIXME: show error nicely in UI! */
+    AG_error ("Error: %d\n",
+              error_code);
+    /* FIXME: show error *nicely* in UI! */
   }
   else
   {
     json_decref (redux_state);
     redux_state = json_incref (response);
-    GNUNET_break (GNUNET_SYSERR !=
-                  persist_state (redux_state));
   }
   if (GNUNET_OK ==
       AG_dispatch (actions))
     return;
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Unhandled state, terminating\n");
+  AG_error ("Unhandled state");
   json_dumpf (redux_state,
               stderr,
               JSON_INDENT (2));
-  GNUNET_SCHEDULER_shutdown ();
+  json_decref (redux_state);
+  redux_state = NULL;
+  AG_hide_all_frames ();
+  AG_show ("anastasis_gtk_start_frame");
 }
diff --git a/src/anastasis/anastasis-gtk_handle-auth-edit-provider-clicked.c 
b/src/anastasis/anastasis-gtk_handle-auth-edit-provider-clicked.c
index 0acf4d1..f76b11f 100644
--- a/src/anastasis/anastasis-gtk_handle-auth-edit-provider-clicked.c
+++ b/src/anastasis/anastasis-gtk_handle-auth-edit-provider-clicked.c
@@ -1,6 +1,6 @@
 /*
      This file is part of anastasis-gtk.
-     Copyright (C) 2020 Anastasis SARL
+     Copyright (C) 2021 Anastasis SARL
 
      Anastasis is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -28,9 +28,194 @@
 #include <gnunet/gnunet_util_lib.h>
 #include "anastasis-gtk_action.h"
 #include "anastasis-gtk_helper.h"
+#include "anastasis-gtk_handle-main-window-forward-clicked.h"
 #include <jansson.h>
 
 
+void
+url_add_button_clicked_cb (GtkButton *button,
+                           gpointer user_data)
+{
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkListStore *ls;
+  GtkEntry *entry;
+  const char *url;
+
+  ls = GTK_LIST_STORE (gtk_builder_get_object (builder,
+                                               "provider_liststore"));
+  GNUNET_assert (NULL != ls);
+  entry = GTK_ENTRY (gtk_builder_get_object (builder,
+                                             "url_entry"));
+  url = gtk_entry_get_text (entry);
+  gtk_list_store_insert_with_values (ls,
+                                     NULL,
+                                     -1,
+                                     0, url,
+                                     -1);
+  gtk_entry_set_text (entry,
+                      "");
+}
+
+
+void
+url_entry_changed_cb (GtkEntry *entry,
+                      gpointer user_data)
+{
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkWidget *button;
+  const char *url;
+
+  button = GTK_WIDGET (gtk_builder_get_object (builder,
+                                               "add_button"));
+  url = gtk_entry_get_text (entry);
+  gtk_widget_set_sensitive (button,
+                            (0 == strncasecmp (url,
+                                               "http://";,
+                                               strlen ("http://";))) ||
+                            (0 == strncasecmp (url,
+                                               "https://";,
+                                               strlen ("https://";))));
+}
+
+
+/**
+ * Function called with the results of "back" action.
+ *
+ * @param cls json array with arguments to apply to the action
+ * @param error_code Error code
+ * @param response new state as result or config information of provider
+ */
+static void
+added_providers (void *cls,
+                 enum TALER_ErrorCode error_code,
+                 json_t *response)
+{
+  if (TALER_EC_NONE != error_code)
+  {
+    AG_error ("Unexpected result from 'add_providers' operation");
+    return;
+  }
+  /* simulate forward click */
+  fprintf (stderr,
+           "Added providers\n");
+  json_decref (redux_state);
+  redux_state = json_incref (response);
+  AG_forward_user_attributes_collecting ();
+}
+
+
+/**
+ * Function called with the results of "back" action.
+ *
+ * @param cls json array with arguments to apply to the action
+ * @param error_code Error code
+ * @param response new state as result or config information of provider
+ */
+static void
+add_providers (void *cls,
+               enum TALER_ErrorCode error_code,
+               json_t *response)
+{
+  json_t *args = cls;
+
+  if (TALER_EC_NONE != error_code)
+  {
+    AG_error ("Unexpected result from 'back' operation");
+    json_decref (args);
+    return;
+  }
+  GNUNET_assert (NULL ==
+                 ANASTASIS_redux_action (response,
+                                         "add_provider",
+                                         args,
+                                         &added_providers,
+                                         NULL));
+  json_decref (args);
+}
+
+
+/**
+ * Function called from the edit-provider dialog upon completion.
+ *
+ * @param dialog the pseudonym selection dialog
+ * @param response_id response code from the dialog
+ * @param user_data the builder of the dialog
+ */
+void
+edit_provider_dialog_response_cb (GtkDialog *dialog,
+                                  gint response_id,
+                                  gpointer user_data)
+{
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkTreeModel *tm;
+  GtkTreeIter iter;
+  const json_t *providers;
+  json_t *urls;
+
+  if (GTK_RESPONSE_APPLY != response_id)
+  {
+    gtk_widget_destroy (GTK_WIDGET (dialog));
+    g_object_unref (G_OBJECT (builder));
+    return;
+  }
+  tm = GTK_TREE_MODEL (gtk_builder_get_object (builder,
+                                               "provider_liststore"));
+  if (NULL == tm)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  providers = json_object_get (redux_state,
+                               "authentication_providers");
+  urls = json_array ();
+  if (gtk_tree_model_get_iter_first (tm,
+                                     &iter))
+    do {
+      gchar *url;
+
+      gtk_tree_model_get (tm,
+                          &iter,
+                          0, &url,
+                          -1);
+      if (NULL == json_object_get (providers,
+                                   url))
+      {
+        fprintf (stderr,
+                 "Adding %s\n",
+                 url);
+        GNUNET_assert (0 ==
+                       json_array_append_new (urls,
+                                              json_string (url)));
+      }
+      g_free (url);
+    }
+    while (gtk_tree_model_iter_next (tm,
+                                     &iter));
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+  g_object_unref (G_OBJECT (builder));
+  if (0 == json_array_size (urls))
+  {
+    json_decref (urls);
+    fprintf (stderr,
+             "no new URLs\n");
+    return;
+  }
+  {
+    json_t *args;
+
+    args = json_pack ("{s:o}",
+                      "urls",
+                      urls);
+    GNUNET_assert (NULL ==
+                   ANASTASIS_redux_action (redux_state,
+                                           "back",
+                                           NULL,
+                                           &add_providers,
+                                           args));
+  }
+}
+
+
 /**
  * Callback invoked if the the "Edit"-provider list button is clicked.
  *
@@ -41,9 +226,42 @@ void
 anastasis_gtk_edit_provider_list_clicked_cb (GtkButton *object,
                                              gpointer user_data)
 {
-  GNUNET_break (0);
-#if 0
-  gtk_widget_show (GTK_WIDGET (GCG_get_main_window_object (
-                                 "anastasis_gtk_b_edit_provider_dialog")));
-#endif
+  GtkWidget *ad;
+  GtkBuilder *builder;
+  GtkListStore *ls;
+  json_t *providers;
+
+  builder = GNUNET_GTK_get_new_builder ("anastasis_gtk_edit_providers.glade",
+                                        NULL);
+  if (NULL == builder)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  ls = GTK_LIST_STORE (gtk_builder_get_object (builder,
+                                               "provider_liststore"));
+  providers = json_object_get (redux_state,
+                               "authentication_providers");
+  {
+    const char *url;
+    const json_t *provider;
+    json_object_foreach (providers, url, provider)
+    {
+      gtk_list_store_insert_with_values (ls,
+                                         NULL,
+                                         -1,
+                                         0, url,
+                                         -1);
+    }
+  }
+  ad = GTK_WIDGET (gtk_builder_get_object (builder,
+                                           "edit_provider_dialog"));
+  {
+    GtkWidget *toplevel;
+
+    toplevel = gtk_widget_get_toplevel (GTK_WIDGET (object));
+    gtk_window_set_transient_for (GTK_WINDOW (ad),
+                                  GTK_WINDOW (toplevel));
+    gtk_window_present (GTK_WINDOW (ad));
+  }
 }
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 02e0f7a..eff0590 100644
--- a/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
+++ b/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
@@ -78,8 +78,8 @@ AG_forward_country_selecting (void)
 }
 
 
-static void
-forward_user_attributes_collecting (void)
+void
+AG_forward_user_attributes_collecting (void)
 {
   json_t *args;
 
@@ -219,7 +219,7 @@ anastasis_gtk_main_window_forward_clicked (GObject *object,
     { .state = "COUNTRY_SELECTING",
       .action = &AG_forward_country_selecting },
     { .state = "USER_ATTRIBUTES_COLLECTING",
-      .action = &forward_user_attributes_collecting },
+      .action = &AG_forward_user_attributes_collecting },
     { .state = "AUTHENTICATIONS_EDITING",
       .action = &forward_authentications_editing },
     { .state = "POLICIES_REVIEWING",
diff --git a/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.h 
b/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.h
index 49513b6..27140fe 100644
--- a/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.h
+++ b/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.h
@@ -30,4 +30,9 @@
 void
 AG_forward_country_selecting (void);
 
+
+void
+AG_forward_user_attributes_collecting (void);
+
+
 #endif
diff --git a/src/anastasis/anastasis-gtk_helper.c 
b/src/anastasis/anastasis-gtk_helper.c
index 73d682f..4360e6b 100644
--- a/src/anastasis/anastasis-gtk_helper.c
+++ b/src/anastasis/anastasis-gtk_helper.c
@@ -194,3 +194,35 @@ GCG_get_main_window_object (const char *name)
   return GNUNET_GTK_main_loop_get_object (ml,
                                           name);
 }
+
+
+void
+AG_error (const char *format,
+          ...)
+{
+  va_list ap;
+  char *msg;
+  int ret;
+  GtkLabel *l;
+
+  va_start (ap, format);
+  ret = vasprintf (&msg,
+                   format,
+                   ap);
+  va_end (ap);
+  if (-1 == ret)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  l = GTK_LABEL (GCG_get_main_window_object ("anastasis_gtk_error_label"));
+  if (NULL == l)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  gtk_label_set_text (l,
+                      msg);
+  free (msg);
+  gtk_widget_show (GTK_WIDGET (l));
+}
diff --git a/src/anastasis/anastasis-gtk_helper.h 
b/src/anastasis/anastasis-gtk_helper.h
index c43633b..a340a52 100644
--- a/src/anastasis/anastasis-gtk_helper.h
+++ b/src/anastasis/anastasis-gtk_helper.h
@@ -140,4 +140,15 @@ void
 AG_hide_all_frames (void);
 
 
+/**
+ * Show error message.
+ *
+ * @param format format string
+ * @param ... arguments for format string
+ */
+void
+AG_error (const char *format,
+          ...)
+__attribute__ ((format (printf, 1, 2)));
+
 #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]