gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis-gtk] branch master updated: revise dialogs to enter cor


From: gnunet
Subject: [taler-anastasis-gtk] branch master updated: revise dialogs to enter core secret
Date: Tue, 13 Jul 2021 19:09:14 +0200

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 63ad015  revise dialogs to enter core secret
63ad015 is described below

commit 63ad015f2d57d84d559c86e5208e82daaad08b68
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Jul 13 19:09:11 2021 +0200

    revise dialogs to enter core secret
---
 contrib/anastasis_gtk_main_window.glade            | 187 ++++++++++---
 src/anastasis/Makefile.am                          |   2 +
 src/anastasis/anastasis-gtk_action.c               | 292 +++++++++++++++------
 src/anastasis/anastasis-gtk_action.h               |  10 +
 ...=> anastasis-gtk_handle-clear-secret-clicked.c} |  47 ++--
 .../anastasis-gtk_handle-core-secret-changed.c     |  62 ++---
 ...anastasis-gtk_handle-core-secret-name-changed.c |  60 +++++
 .../anastasis-gtk_handle-secret-buttons.c          | 133 ++++++----
 8 files changed, 567 insertions(+), 226 deletions(-)

diff --git a/contrib/anastasis_gtk_main_window.glade 
b/contrib/anastasis_gtk_main_window.glade
index 92fb46d..9f7822b 100644
--- a/contrib/anastasis_gtk_main_window.glade
+++ b/contrib/anastasis_gtk_main_window.glade
@@ -1726,7 +1726,7 @@ Author: Christian Grothoff, Dennis Neufeld
                                                 <property 
name="visible">True</property>
                                                 <property 
name="can-focus">False</property>
                                                 <property 
name="margin-top">10</property>
-                                                <property name="label" 
translatable="yes">Anastasis is developed by &lt;a 
href="https://anastasis.lu/en/about.html#team"&gt;privacy advocates&lt;/a&gt; 
+                                                <property name="label" 
translatable="yes">Anastasis is developed by &lt;a 
href="https://anastasis.lu/en/about.html#team"&gt;privacy advocates&lt;/a&gt;
 with &lt;a href="https://www.ngi.eu/ngi-projects/ledger/"&gt;funding&lt;/a&gt; 
from the European Commission.</property>
                                                 <property 
name="use-markup">True</property>
                                                 <property 
name="justify">center</property>
@@ -2690,6 +2690,8 @@ with &lt;a 
href="https://www.ngi.eu/ngi-projects/ledger/"&gt;funding&lt;/a&gt; f
                                                   <object class="GtkEntry" 
id="anastasis_gtk_secret_name_entry">
                                                     <property 
name="visible">True</property>
                                                     <property 
name="can-focus">True</property>
+                                                    <property 
name="has-focus">True</property>
+                                                    <signal name="changed" 
handler="anastasis_gtk_enter_secret_name_entry_changed_cb" swapped="no"/>
                                                   </object>
                                                   <packing>
                                                     <property 
name="expand">True</property>
@@ -2727,38 +2729,77 @@ identify your secret later.</property>
                                                 <property 
name="can-focus">False</property>
                                                 <property 
name="orientation">vertical</property>
                                                 <child>
-                                                  <object class="GtkLabel" 
id="secret_text_label">
+                                                  <object class="GtkBox">
                                                     <property 
name="visible">True</property>
                                                     <property 
name="can-focus">False</property>
-                                                    <property 
name="halign">start</property>
-                                                    <property name="label" 
translatable="yes">Provide secret as text</property>
+                                                    <child>
+                                                      <object class="GtkLabel" 
id="secret_text_label">
+                                                        <property 
name="visible">True</property>
+                                                        <property 
name="can-focus">False</property>
+                                                        <property 
name="halign">start</property>
+                                                        <property name="label" 
translatable="yes">Provide secret as text</property>
+                                                      </object>
+                                                      <packing>
+                                                        <property 
name="expand">False</property>
+                                                        <property 
name="fill">False</property>
+                                                        <property 
name="padding">5</property>
+                                                        <property 
name="position">0</property>
+                                                      </packing>
+                                                    </child>
                                                   </object>
                                                   <packing>
-                                                    <property 
name="expand">False</property>
-                                                    <property 
name="fill">False</property>
-                                                    <property 
name="padding">5</property>
+                                                    <property 
name="expand">True</property>
+                                                    <property 
name="fill">True</property>
                                                     <property 
name="position">0</property>
                                                   </packing>
                                                 </child>
                                                 <child>
-                                                  <object class="GtkEntry" 
id="anastasis_gtk_enter_secret_entry">
+                                                  <object class="GtkBox">
                                                     <property 
name="visible">True</property>
-                                                    <property 
name="can-focus">True</property>
-                                                    <property 
name="valign">start</property>
-                                                    <property 
name="margin-left">5</property>
-                                                    <property 
name="margin-right">5</property>
-                                                    <property 
name="margin-start">5</property>
-                                                    <property 
name="margin-end">5</property>
-                                                    <property 
name="hexpand">True</property>
-                                                    <property 
name="primary-icon-stock">gtk-dialog-authentication</property>
-                                                    <property 
name="placeholder-text" translatable="yes">Type or paste your secret 
here</property>
-                                                    <property 
name="input-purpose">password</property>
-                                                    <signal name="changed" 
handler="anastasis_gtk_enter_secret_entry_changed_cb" swapped="no"/>
+                                                    <property 
name="can-focus">False</property>
+                                                    <child>
+                                                      <object class="GtkEntry" 
id="anastasis_gtk_enter_secret_entry">
+                                                        <property 
name="visible">True</property>
+                                                        <property 
name="can-focus">True</property>
+                                                        <property 
name="valign">start</property>
+                                                        <property 
name="margin-left">5</property>
+                                                        <property 
name="margin-right">5</property>
+                                                        <property 
name="margin-start">5</property>
+                                                        <property 
name="margin-end">5</property>
+                                                        <property 
name="hexpand">True</property>
+                                                        <property 
name="primary-icon-stock">gtk-dialog-authentication</property>
+                                                        <property 
name="placeholder-text" translatable="yes">Type or paste your secret 
here</property>
+                                                        <property 
name="input-purpose">password</property>
+                                                        <signal name="changed" 
handler="anastasis_gtk_enter_secret_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">0</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <object 
class="GtkButton" id="anastasis_gtk_secret_clear_text_button">
+                                                        <property 
name="label">gtk-clear</property>
+                                                        <property 
name="can-focus">True</property>
+                                                        <property 
name="receives-default">True</property>
+                                                        <property 
name="use-stock">True</property>
+                                                        <property 
name="always-show-image">True</property>
+                                                        <signal name="clicked" 
handler="anastasis_gtk_secret_clear_button_clicked_cb" swapped="no"/>
+                                                      </object>
+                                                      <packing>
+                                                        <property 
name="expand">False</property>
+                                                        <property 
name="fill">True</property>
+                                                        <property 
name="padding">5</property>
+                                                        <property 
name="pack-type">end</property>
+                                                        <property 
name="position">1</property>
+                                                      </packing>
+                                                    </child>
                                                   </object>
                                                   <packing>
-                                                    <property 
name="expand">True</property>
+                                                    <property 
name="expand">False</property>
                                                     <property 
name="fill">True</property>
-                                                    <property 
name="padding">5</property>
                                                     <property 
name="position">1</property>
                                                   </packing>
                                                 </child>
@@ -2769,11 +2810,43 @@ identify your secret later.</property>
                                                     <property 
name="can-focus">False</property>
                                                     <property 
name="margin-top">5</property>
                                                     <property 
name="margin-bottom">5</property>
+                                                    <property 
name="spacing">10</property>
                                                     <child>
-                                                      <object class="GtkLabel" 
id="secret_by_file_label">
+                                                      <object class="GtkBox" 
id="anastasis_gtk_secret_file_chooser_hbox">
                                                         <property 
name="visible">True</property>
                                                         <property 
name="can-focus">False</property>
-                                                        <property name="label" 
translatable="yes">Or provide secret as a file:</property>
+                                                        <property 
name="spacing">5</property>
+                                                        <child>
+                                                          <object 
class="GtkLabel" id="secret_by_file_label">
+                                                            <property 
name="visible">True</property>
+                                                            <property 
name="can-focus">False</property>
+                                                            <property 
name="label" translatable="yes">Or provide secret as a file:</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="GtkButton" id="anastasis_gtk_enter_secret_open_button">
+                                                            <property 
name="label">Choose file</property>
+                                                            <property 
name="visible">True</property>
+                                                            <property 
name="can-focus">True</property>
+                                                            <property 
name="can-default">True</property>
+                                                            <property 
name="receives-default">True</property>
+                                                            <property 
name="image">open_file_image</property>
+                                                            <property 
name="always-show-image">True</property>
+                                                            <signal 
name="clicked" handler="anastasis_gtk_enter_secret_open_button_clicked_cb" 
swapped="no"/>
+                                                          </object>
+                                                          <packing>
+                                                            <property 
name="expand">False</property>
+                                                            <property 
name="fill">True</property>
+                                                            <property 
name="padding">5</property>
+                                                            <property 
name="position">1</property>
+                                                          </packing>
+                                                        </child>
                                                       </object>
                                                       <packing>
                                                         <property 
name="expand">False</property>
@@ -2783,21 +2856,59 @@ identify your secret later.</property>
                                                       </packing>
                                                     </child>
                                                     <child>
-                                                      <object 
class="GtkButton" id="anastasis_gtk_enter_secret_open_button">
-                                                        <property 
name="label">Choose file</property>
-                                                        <property 
name="visible">True</property>
-                                                        <property 
name="can-focus">True</property>
-                                                        <property 
name="can-default">True</property>
-                                                        <property 
name="receives-default">True</property>
-                                                        <property 
name="image">open_file_image</property>
-                                                        <property 
name="always-show-image">True</property>
-                                                        <signal name="clicked" 
handler="anastasis_gtk_enter_secret_open_button_clicked_cb" swapped="no"/>
+                                                      <object class="GtkBox" 
id="anastasis_gtk_secret_file_name_hbox">
+                                                        <property 
name="can-focus">False</property>
+                                                        <property 
name="spacing">5</property>
+                                                        <child>
+                                                          <object 
class="GtkLabel" id="secret_file_name_label">
+                                                            <property 
name="visible">True</property>
+                                                            <property 
name="can-focus">False</property>
+                                                            <property 
name="label" translatable="yes">Your secret file:</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="GtkLabel" id="anastasis_gtk_secret_file_name_label">
+                                                            <property 
name="visible">True</property>
+                                                            <property 
name="can-focus">False</property>
+                                                            <property 
name="label">DYNAMICALLY GENERATED</property>
+                                                            <attributes>
+                                                            <attribute 
name="weight" value="bold"/>
+                                                            </attributes>
+                                                          </object>
+                                                          <packing>
+                                                            <property 
name="expand">False</property>
+                                                            <property 
name="fill">True</property>
+                                                            <property 
name="position">1</property>
+                                                          </packing>
+                                                        </child>
+                                                        <child>
+                                                          <object 
class="GtkButton" id="anastasis_gtk_secret_clear_file_button">
+                                                            <property 
name="label">gtk-clear</property>
+                                                            <property 
name="can-focus">True</property>
+                                                            <property 
name="receives-default">True</property>
+                                                            <property 
name="use-stock">True</property>
+                                                            <property 
name="always-show-image">True</property>
+                                                            <signal 
name="clicked" handler="anastasis_gtk_secret_clear_button_clicked_cb" 
swapped="no"/>
+                                                          </object>
+                                                          <packing>
+                                                            <property 
name="expand">False</property>
+                                                            <property 
name="fill">True</property>
+                                                            <property 
name="padding">5</property>
+                                                            <property 
name="pack-type">end</property>
+                                                            <property 
name="position">2</property>
+                                                          </packing>
+                                                        </child>
                                                       </object>
                                                       <packing>
                                                         <property 
name="expand">False</property>
                                                         <property 
name="fill">True</property>
-                                                        <property 
name="padding">5</property>
-                                                        <property 
name="position">1</property>
+                                                        <property 
name="position">2</property>
                                                       </packing>
                                                     </child>
                                                   </object>
@@ -2944,8 +3055,8 @@ identify your secret later.</property>
                                                     <property 
name="visible">True</property>
                                                     <property 
name="can-focus">False</property>
                                                     <property 
name="halign">start</property>
-                                                    <property name="label" 
translatable="yes">You pay this fee to back up your secret. 
-The fee may increase with the expiration 
+                                                    <property name="label" 
translatable="yes">You pay this fee to back up your secret.
+The fee may increase with the expiration
 date for the recovery policy.</property>
                                                   </object>
                                                   <packing>
@@ -3570,7 +3681,7 @@ date for the recovery policy.</property>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="padding">5</property>
+                <property name="padding">10</property>
                 <property name="position">0</property>
               </packing>
             </child>
@@ -3664,7 +3775,7 @@ date for the recovery policy.</property>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="padding">5</property>
+                <property name="padding">10</property>
                 <property name="position">6</property>
               </packing>
             </child>
diff --git a/src/anastasis/Makefile.am b/src/anastasis/Makefile.am
index 4759923..af3ed4e 100644
--- a/src/anastasis/Makefile.am
+++ b/src/anastasis/Makefile.am
@@ -23,11 +23,13 @@ anastasis_gtk_SOURCES = \
   anastasis-gtk_handle-challenge-code.c \
   anastasis-gtk_handle-challenge-row-activated.c \
   anastasis-gtk_handle-challenge-question.c \
+  anastasis-gtk_handle-clear-secret-clicked.c \
   anastasis-gtk_handle-continent-selected.c \
   anastasis-gtk_handle-country-activated.c \
   anastasis-gtk_handle-country-unselected.c \
   anastasis-gtk_handle-currency-changed.c \
   anastasis-gtk_handle-core-secret-changed.c \
+  anastasis-gtk_handle-core-secret-name-changed.c \
   anastasis-gtk_handle-expiration-change.c \
     anastasis-gtk_handle-expiration-change.h \
   anastasis-gtk_handle-identity-changed.c \
diff --git a/src/anastasis/anastasis-gtk_action.c 
b/src/anastasis/anastasis-gtk_action.c
index e54ec5e..b30c0fa 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -41,6 +41,16 @@
  */
 bool AG_in_action;
 
+/**
+ * Are we currently editing the secret?
+ */
+bool AG_in_secret_editing;
+
+/**
+ * Are we currently editing the secret name?
+ */
+bool AG_in_secret_name_editing;
+
 
 #define DEBUG 0
 
@@ -435,6 +445,37 @@ expand_name (const char *name,
 }
 
 
+/**
+ * Update GtkLabel @a name, setting text to @a value.
+ *
+ * @param name Glade-name of widget to update
+ * @param value value to set
+ */
+static void
+update_label (const char *name,
+              const char *value)
+{
+  GtkLabel *label;
+
+  label = GTK_LABEL (GCG_get_main_window_object (name));
+  if (NULL == label)
+    return;
+  if (NULL == value)
+  {
+    gtk_widget_hide (GTK_WIDGET (label));
+  }
+  else
+  {
+    gtk_label_set_text (label,
+                        value);
+    gtk_widget_show (GTK_WIDGET (label));
+  }
+}
+
+
+/**
+ * FIXME.
+ */
 static void
 action_user_attributes_collecting (void)
 {
@@ -505,18 +546,12 @@ action_user_attributes_collecting (void)
            (NULL != attr_label) )
       {
         char *label_widget;
-        GObject *label;
 
         GNUNET_asprintf (&label_widget,
                          "%s_label",
                          widget_name);
-        label = GCG_get_main_window_object (label_widget);
-        if (NULL != label)
-        {
-          gtk_label_set_text (GTK_LABEL (label),
-                              attr_label);
-          AG_show (label_widget); /* should not be required */
-        }
+        update_label (label_widget,
+                      attr_label);
         GNUNET_free (label_widget);
       }
       if ( (NULL != widget_name) &&
@@ -1007,6 +1042,38 @@ action_policies_reviewing (void)
 }
 
 
+/**
+ * Update GtkEntry @a name, setting text to @a value.
+ *
+ * @param name Glade-name of widget to update
+ * @param value value to set
+ */
+static void
+update_entry (const char *name,
+              const char *value)
+{
+  GtkEntry *entry;
+  const char *old;
+
+  if (NULL == value)
+    value = "";
+  entry = GTK_ENTRY (GCG_get_main_window_object (name));
+  if (NULL == entry)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "`%s' is not a GtkEntry!\n",
+                name);
+  }
+  old = gtk_entry_get_text (entry);
+  if (NULL == old)
+    old = "";
+  if (0 != strcmp (old,
+                   value))
+    gtk_entry_set_text (entry,
+                        value);
+}
+
+
 /**
  * Function called when we begin editing the secret.
  */
@@ -1022,7 +1089,6 @@ action_secret_editing (void)
   struct tm tv;
 
   AG_hide_all_frames ();
-
   if (GNUNET_OK !=
       GNUNET_JSON_parse (AG_redux_state,
                          spec,
@@ -1043,18 +1109,15 @@ action_secret_editing (void)
   }
 
   {
-    GtkLabel *fee_label;
     json_t *fees;
 
-    fee_label = GTK_LABEL (GCG_get_main_window_object (
-                             "backup_fee_value_label"));
     fees = json_object_get (AG_redux_state,
                             "upload_fees");
     if (0 == json_array_size (fees))
     {
-      gtk_label_set_text (fee_label,
-                          _ (/* in the sense of gratis */
-                            "free"));
+      update_label ("backup_fee_value_label",
+                    _ (/* in the sense of gratis */
+                      "free"));
     }
     else
     {
@@ -1087,31 +1150,28 @@ action_secret_editing (void)
         GNUNET_asprintf (&tmp,
                          "%s%s%llu.%u %s",
                          val,
-                         strlen (val) > 0 ? ", " : "",
+                         strlen (val) > 0 ? "\n" : "",
                          (unsigned long long) a.value,
                          (unsigned int) a.fraction,
                          a.currency);
         GNUNET_free (val);
         val = tmp;
       }
-      gtk_label_set_text (fee_label,
-                          val);
+      update_label ("backup_fee_value_label",
+                    val);
       GNUNET_free (val);
     }
   }
   {
-    GtkLabel *expiration_label;
     char estr[128];
 
-    expiration_label = GTK_LABEL (GCG_get_main_window_object (
-                                    "expiration_date_without_year_label"));
     GNUNET_assert (sizeof (estr) >
                    strftime (estr,
                              sizeof (estr),
-                             "%A, %d %B",
+                             "%d %B",
                              &tv));
-    gtk_label_set_text (expiration_label,
-                        estr);
+    update_label ("expiration_date_without_year_label",
+                  estr);
   }
 
   {
@@ -1131,53 +1191,110 @@ action_secret_editing (void)
                                (double) exp_year);
   }
 
+  AG_insensitive ("anastasis_gtk_main_window_forward_button");
+  AG_sensitive ("anastasis_gtk_enter_secret_open_button");
+  AG_sensitive ("anastasis_gtk_enter_secret_entry");
+  AG_hide ("anastasis_gtk_secret_clear_file_button");
+  AG_hide ("anastasis_gtk_secret_clear_text_button");
+  AG_hide ("anastasis_gtk_secret_file_name_hbox");
+  AG_show ("anastasis_gtk_secret_file_chooser_hbox");
   {
-    GtkEntry *entry;
     const char *name = "";
-    void *secret;
-    size_t secret_size;
+    json_t *jsecret = NULL;
+    const char *filename = NULL;
     struct GNUNET_JSON_Specification spec[] = {
-      GNUNET_JSON_spec_varsize ("core_secret",
-                                &secret,
-                                &secret_size),
+      GNUNET_JSON_spec_mark_optional (
+        GNUNET_JSON_spec_json ("core_secret",
+                               &jsecret)),
       GNUNET_JSON_spec_mark_optional (
         GNUNET_JSON_spec_string ("secret_name",
                                  &name)),
       GNUNET_JSON_spec_end ()
     };
 
-    entry = GTK_ENTRY (GCG_get_main_window_object (
-                         "anastasis_gtk_enter_secret_entry"));
-    if ( (GNUNET_OK ==
-          GNUNET_JSON_parse (AG_redux_state,
-                             spec,
-                             NULL, NULL)) &&
-         (0 < strlen (secret)) )
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (AG_redux_state,
+                           spec,
+                           NULL, NULL))
+    {
+      GNUNET_break (0);
+      json_dumpf (AG_redux_state,
+                  stderr,
+                  JSON_INDENT (2));
+      AG_error ("State did not parse correctly: invalid secret data");
+      return;
+    }
+    if (! AG_in_secret_name_editing)
+      update_entry ("anastasis_gtk_secret_name_entry",
+                    name);
+    if (NULL != jsecret)
     {
-      const char *old = gtk_entry_get_text (entry);
+      const char *mime = NULL;
+      const char *text = NULL;
+      struct GNUNET_JSON_Specification sspec[] = {
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_string ("text",
+                                   &text)),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_string ("mime",
+                                   &mime)),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_string ("filename",
+                                   &filename)),
+        GNUNET_JSON_spec_end ()
+      };
 
-      if (0 != strcmp (old,
-                       secret))
+      if (GNUNET_OK !=
+          GNUNET_JSON_parse (jsecret,
+                             sspec,
+                             NULL, NULL))
       {
-        fprintf (stderr,
-                 "Changing secret from\n%s to\n%s\n",
-                 old,
-                 secret);
-        gtk_entry_set_text (entry,
-                            secret);
+        GNUNET_break (0);
+        json_dumpf (AG_redux_state,
+                    stderr,
+                    JSON_INDENT (2));
+        AG_error ("State did not parse correctly: invalid secret data");
+        return;
+      }
+      if ( (NULL != text) &&
+           (0 == strlen (text)) )
+        text = NULL;
+      if (! AG_in_secret_editing)
+        update_entry ("anastasis_gtk_enter_secret_entry",
+                      text);
+      update_label ("anastasis_gtk_secret_file_name_label",
+                    filename);
+      if ( (NULL != text) ||
+           (NULL != filename) )
+      {
+        AG_sensitive ("anastasis_gtk_main_window_forward_button");
+      }
+      if (NULL != text)
+      {
+        AG_insensitive ("anastasis_gtk_enter_secret_open_button");
+        AG_show ("anastasis_gtk_secret_clear_text_button");
       }
-      AG_sensitive ("anastasis_gtk_main_window_forward_button");
+      if (NULL != filename)
+      {
+        AG_insensitive ("anastasis_gtk_enter_secret_entry");
+        AG_show ("anastasis_gtk_secret_clear_file_button");
+        AG_show ("anastasis_gtk_secret_file_name_hbox");
+        AG_hide ("anastasis_gtk_secret_file_chooser_hbox");
+      }
+      GNUNET_JSON_parse_free (sspec);
     }
     else
     {
-      AG_insensitive ("anastasis_gtk_main_window_forward_button");
-    }
+      /* secret is NULL */
+      update_entry ("anastasis_gtk_enter_secret_entry",
+                    NULL);
 
-    entry = GTK_ENTRY (GCG_get_main_window_object (
-                         "anastasis_gtk_secret_name_entry"));
-    if (NULL != name)
-      gtk_entry_set_text (entry,
-                          name);
+    }
+    if ( (NULL == name) ||
+         (0 == strlen (name) ) )
+      AG_focus ("anastasis_gtk_secret_name_entry");
+    else if (NULL == filename)
+      AG_focus ("anastasis_gtk_enter_secret_entry");
     GNUNET_JSON_parse_free (spec);
   }
   AG_sensitive ("anastasis_gtk_main_window_prev_button");
@@ -1187,7 +1304,6 @@ action_secret_editing (void)
   AG_hide ("anastasis_gtk_recovery_progress_scrolled_window");
   AG_show ("anastasis_gtk_enter_secret_frame");
   AG_show ("anastasis_gtk_enter_secret_image");
-  AG_focus ("anastasis_gtk_enter_secret_entry");
   AG_show ("anastasis_gtk_main_control_vbox");
   AG_show ("anastasis_gtk_main_window_prev_button");
   AG_show ("anastasis_gtk_main_window_forward_button");
@@ -2680,28 +2796,34 @@ action_challenge_solving (void)
 }
 
 
+/**
+ * FIXME.
+ */
 static void
 action_recovery_finished (void)
 {
-  GtkLabel *l;
   const char *mime;
+  const char *text;
   void *data;
   size_t data_size;
   const json_t *cs;
   struct GNUNET_JSON_Specification spec[] = {
-    GNUNET_JSON_spec_string ("mime",
-                             &mime),
-    GNUNET_JSON_spec_varsize ("value",
-                              &data,
-                              &data_size),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("mime",
+                               &mime)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("text",
+                               &text)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_varsize ("value",
+                                &data,
+                                &data_size)),
     GNUNET_JSON_spec_end ()
   };
   GdkPixbuf *pb;
   GtkImage *img;
 
   AG_hide_all_frames ();
-  l = GTK_LABEL (GCG_get_main_window_object (
-                   "anastasis_gtk_secret_value_label"));
   cs = json_object_get (AG_redux_state,
                         "core_secret");
   GNUNET_assert (NULL != cs);
@@ -2710,34 +2832,30 @@ action_recovery_finished (void)
                                     spec,
                                     NULL, NULL));
   AG_hide ("anastasis_gtk_secret_copy_button");
-  if (0 == strncasecmp (mime,
-                        "text/",
-                        strlen ("text/")))
-  {
-    char *secret = GNUNET_strndup (data,
-                                   data_size);
-
-    gtk_label_set_text (l,
-                        secret);
-    GNUNET_free (secret);
-    /* offer copying secret text to clipboard */
+  update_label ("anastasis_gtk_secret_value_label",
+                text);
+  if ( (0 == strncasecmp (mime,
+                          "text/",
+                          strlen ("text/"))) ||
+       (0 == strncasecmp (mime,
+                          "image/",
+                          strlen ("image/"))) ||
+       (NULL != text) )
+  {
+    /* images and text can be copied */
     AG_show ("anastasis_gtk_secret_copy_button");
   }
-  if (0 == strncasecmp (mime,
-                        "image/",
-                        strlen ("image/")))
+  if (NULL != data)
   {
-    /* images we can copy, too */
-    AG_show ("anastasis_gtk_secret_copy_button");
+    pb = setup_qrcode ("anastasis_gtk_secret_qr_image",
+                       data,
+                       data_size);
+    img = GTK_IMAGE (GCG_get_main_window_object (
+                       "anastasis_gtk_secret_qr_image"));
+    gtk_image_set_from_pixbuf (img,
+                               pb);
+    g_object_unref (pb);
   }
-  pb = setup_qrcode ("anastasis_gtk_secret_qr_image",
-                     data,
-                     data_size);
-  img = GTK_IMAGE (GCG_get_main_window_object (
-                     "anastasis_gtk_secret_qr_image"));
-  gtk_image_set_from_pixbuf (img,
-                             pb);
-  g_object_unref (pb);
   GNUNET_JSON_parse_free (spec);
   AG_hide ("anastassis_gtk_progress_vbox");
   AG_hide ("anastasis_gtk_recovery_progress_scrolled_window");
diff --git a/src/anastasis/anastasis-gtk_action.h 
b/src/anastasis/anastasis-gtk_action.h
index 8db3c6d..cb74f33 100644
--- a/src/anastasis/anastasis-gtk_action.h
+++ b/src/anastasis/anastasis-gtk_action.h
@@ -37,6 +37,16 @@
  */
 extern bool AG_in_action;
 
+/**
+ * Are we currently editing the secret?
+ */
+extern bool AG_in_secret_editing;
+
+/**
+ * Are we currently editing the secret name?
+ */
+extern bool AG_in_secret_name_editing;
+
 /**
  * Function called with the results of #ANASTASIS_redux_action.
  *
diff --git a/src/anastasis/anastasis-gtk_action.h 
b/src/anastasis/anastasis-gtk_handle-clear-secret-clicked.c
similarity index 50%
copy from src/anastasis/anastasis-gtk_action.h
copy to src/anastasis/anastasis-gtk_handle-clear-secret-clicked.c
index 8db3c6d..5857d8a 100644
--- a/src/anastasis/anastasis-gtk_action.h
+++ b/src/anastasis/anastasis-gtk_handle-clear-secret-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
@@ -17,37 +17,32 @@
      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      Boston, MA 02110-1301, USA.
 */
-
 /**
- * @file src/include/anastasis-gtk_action.h
- * @brief Definition of redux action result handler
+ * @file src/anastasis/anastasis-gtk_handle-clear-secret-clicked.c
+ * @brief Handle user clicking a 'clear' button in the enter secret dialog
  * @author Christian Grothoff
- * @author Dennis Neufeld
  */
-#ifndef ANASTASIS_GTK_ACTION_H
-#define ANASTASIS_GTK_ACTION_H
-#include <gnunet-gtk/gnunet_gtk.h>
-#include <gtk/gtk.h>
-#include <anastasis/anastasis_service.h>
-#include <anastasis/anastasis_redux.h>
-
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "anastasis-gtk_action.h"
+#include "anastasis-gtk_helper.h"
+#include <jansson.h>
 
-/**
- * Are we currently processing an action?
- */
-extern bool AG_in_action;
 
 /**
- * Function called with the results of #ANASTASIS_redux_action.
+ * Callback invoked if the the "backup"-button is clicked.
  *
- * @param cls closure
- * @param error_code Error code
- * @param response new state as result or config information of provider
+ * @param object
+ * @param user_data unused
  */
 void
-AG_action_cb (void *cls,
-              enum TALER_ErrorCode error_code,
-              json_t *response);
-
-
-#endif
+anastasis_gtk_secret_clear_button_clicked_cb (GObject *object,
+                                              gpointer user_data)
+{
+  AG_freeze ();
+  AG_ra = ANASTASIS_redux_action (AG_redux_state,
+                                  "clear_secret",
+                                  NULL,
+                                  &AG_action_cb,
+                                  NULL);
+}
diff --git a/src/anastasis/anastasis-gtk_handle-core-secret-changed.c 
b/src/anastasis/anastasis-gtk_handle-core-secret-changed.c
index daf3e7b..cc4f787 100644
--- a/src/anastasis/anastasis-gtk_handle-core-secret-changed.c
+++ b/src/anastasis/anastasis-gtk_handle-core-secret-changed.c
@@ -38,41 +38,43 @@ anastasis_gtk_enter_secret_entry_changed_cb (GtkEditable 
*entry,
 {
   GtkEntry *e = GTK_ENTRY (entry);
   const char *text = gtk_entry_get_text (e);
-  GtkEntry *ne = GTK_ENTRY (GCG_get_main_window_object (
-                              "anastasis_gtk_secret_name_entry"));
-  const char *name = gtk_entry_get_text (ne);
+  json_t *arguments;
+  struct GNUNET_TIME_Absolute expiration;
 
-  if (! AG_in_action)
+  if (AG_in_action)
+    return;
+  AG_in_secret_editing = true;
+  expiration = AG_get_desired_expiration ();
+  if (0 == expiration.abs_value_us)
+    return;   /* failured */
+  if ( (NULL == text) ||
+       (0 == strlen (text)) )
   {
-    json_t *arguments;
-    struct GNUNET_TIME_Absolute expiration;
-
-    expiration = AG_get_desired_expiration ();
-    if (0 == expiration.abs_value_us)
-      return; /* failured */
-    arguments = json_pack ("{s:s?,s:{s:s,s:s?},s:o}",
-                           "name",
-                           name,
-                           "secret",
-                           "value",
-                           text,
-                           "mime",
-                           "text/plain",
-                           "expiration",
-                           GNUNET_JSON_from_time_abs (expiration));
-    GNUNET_assert (NULL != arguments);
     AG_freeze ();
     AG_ra = ANASTASIS_redux_action (AG_redux_state,
-                                    "enter_secret",
-                                    arguments,
+                                    "clear_secret",
+                                    NULL,
                                     &AG_action_cb,
                                     NULL);
-    json_decref (arguments);
+    AG_focus ("anastasis_gtk_enter_secret_entry");
+    return;
   }
-
-  if ( (NULL != text) &&
-       (strlen (text) > 0) )
-    AG_sensitive ("anastasis_gtk_main_window_forward_button");
-  else
-    AG_insensitive ("anastasis_gtk_main_window_forward_button");
+  arguments = json_pack ("{s:{s:s,s:s},s:o}",
+                         "secret",
+                         "text",
+                         text,
+                         "mime",
+                         "text/plain",
+                         "expiration",
+                         GNUNET_JSON_from_time_abs (expiration));
+  GNUNET_assert (NULL != arguments);
+  AG_freeze ();
+  AG_ra = ANASTASIS_redux_action (AG_redux_state,
+                                  "enter_secret",
+                                  arguments,
+                                  &AG_action_cb,
+                                  NULL);
+  json_decref (arguments);
+  AG_focus ("anastasis_gtk_enter_secret_entry");
+  AG_in_secret_editing = false;
 }
diff --git a/src/anastasis/anastasis-gtk_handle-core-secret-name-changed.c 
b/src/anastasis/anastasis-gtk_handle-core-secret-name-changed.c
new file mode 100644
index 0000000..285251f
--- /dev/null
+++ b/src/anastasis/anastasis-gtk_handle-core-secret-name-changed.c
@@ -0,0 +1,60 @@
+/*
+     This file is part of anastasis-gtk.
+     Copyright (C) 2020 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
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     Anastasis 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; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+/**
+ * @file src/anastasis/anastasis-gtk_handle-core-secret-name-changed.c
+ * @brief The user changed the name of the core secret. Update state.
+ * @author Christian Grothoff
+ */
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "anastasis-gtk_helper.h"
+#include "anastasis-gtk_action.h"
+#include "anastasis-gtk_attributes.h"
+#include "anastasis-gtk_handle-identity-changed.h"
+#include "anastasis-gtk_handle-expiration-change.h"
+#include <jansson.h>
+
+
+void
+anastasis_gtk_enter_secret_name_entry_changed_cb (GtkEditable *entry,
+                                                  gpointer user_data)
+{
+  GtkEntry *ne = GTK_ENTRY (entry);
+  const char *name = gtk_entry_get_text (ne);
+  json_t *arguments;
+
+  if (AG_in_action)
+    return;
+  arguments = json_pack ("{s:s}",
+                         "name",
+                         name);
+  GNUNET_assert (NULL != arguments);
+  AG_freeze ();
+  AG_in_secret_name_editing = true;
+  AG_ra = ANASTASIS_redux_action (AG_redux_state,
+                                  "enter_secret_name",
+                                  arguments,
+                                  &AG_action_cb,
+                                  NULL);
+  GNUNET_break (NULL == AG_ra);
+  AG_focus ("anastasis_gtk_secret_name_entry");
+  AG_in_secret_name_editing = false;
+  json_decref (arguments);
+}
diff --git a/src/anastasis/anastasis-gtk_handle-secret-buttons.c 
b/src/anastasis/anastasis-gtk_handle-secret-buttons.c
index fdc356c..ba82a5d 100644
--- a/src/anastasis/anastasis-gtk_handle-secret-buttons.c
+++ b/src/anastasis/anastasis-gtk_handle-secret-buttons.c
@@ -52,6 +52,7 @@ open_secret_dialog_response_cb (GtkDialog *dialog,
 {
   GtkBuilder *builder = GTK_BUILDER (user_data);
   char *filename;
+  const char *fn;
   size_t data_size;
   void *data;
   const char *mime;
@@ -68,7 +69,12 @@ open_secret_dialog_response_cb (GtkDialog *dialog,
     GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (dialog));
   gtk_widget_destroy (GTK_WIDGET (dialog));
   g_object_unref (G_OBJECT (builder));
-
+  fn = strrchr (filename,
+                '/');
+  if (NULL == fn)
+    fn = filename;
+  else
+    fn++; /* skip '/' itself */
   {
     struct GNUNET_DISK_FileHandle *fh;
     off_t size;
@@ -122,7 +128,6 @@ open_secret_dialog_response_cb (GtkDialog *dialog,
     }
     GNUNET_DISK_file_close (fh);
   }
-  GNUNET_free (filename);
   entry = GTK_ENTRY (GCG_get_main_window_object (
                        "anastasis_gtk_secret_name_entry"));
   name = gtk_entry_get_text (entry);
@@ -137,19 +142,23 @@ open_secret_dialog_response_cb (GtkDialog *dialog,
     if (0 == expiration.abs_value_us)
     {
       GNUNET_free (data);
+      GNUNET_free (filename);
       return; /* failured */
     }
-    arguments = json_pack ("{s:s?,s:{s:o,s:s?},s:o}",
+    arguments = json_pack ("{s:s?,s:{s:o,s:s,s:s?},s:o}",
                            "name",
                            name,
                            "secret",
                            "value",
                            GNUNET_JSON_from_data (data,
                                                   data_size),
+                           "filename",
+                           fn,
                            "mime",
                            mime,
                            "expiration",
                            GNUNET_JSON_from_time_abs (expiration));
+    GNUNET_free (filename);
     GNUNET_free (data);
     GNUNET_assert (NULL != arguments);
     AG_freeze ();
@@ -312,8 +321,12 @@ anastasis_gtk_secret_save_as_button_clicked_cb (GtkButton 
*button,
   const char *fn;
   json_t *cs;
   struct GNUNET_JSON_Specification spec[] = {
-    GNUNET_JSON_spec_string ("mime",
-                             &mime),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("filename",
+                               &fn)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("mime",
+                               &mime)),
     GNUNET_JSON_spec_end ()
   };
 
@@ -336,14 +349,18 @@ anastasis_gtk_secret_save_as_button_clicked_cb (GtkButton 
*button,
   }
   ad = GTK_WIDGET (gtk_builder_get_object (builder,
                                            "save_file_dialog"));
-  fn = "untitled.secret";
-  for (unsigned int i = 0; NULL != mime_map[i].mime; i++)
+  if ( (NULL == fn) &&
+       (NULL != mime) )
   {
-    if (0 != strcmp (mime_map[i].mime,
-                     mime))
-      continue;
-    fn = mime_map[i].fn;
-    break;
+    fn = "untitled.secret";
+    for (unsigned int i = 0; NULL != mime_map[i].mime; i++)
+    {
+      if (0 != strcmp (mime_map[i].mime,
+                       mime))
+        continue;
+      fn = mime_map[i].fn;
+      break;
+    }
   }
   gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (ad),
                                      fn);
@@ -371,13 +388,19 @@ anastasis_gtk_secret_copy_button_clicked_cb (GtkButton 
*button,
   size_t data_len;
   void *data;
   const char *mime;
+  const char *text;
   json_t *cs;
   struct GNUNET_JSON_Specification spec[] = {
-    GNUNET_JSON_spec_varsize ("value",
-                              &data,
-                              &data_len),
-    GNUNET_JSON_spec_string ("mime",
-                             &mime),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_varsize ("value",
+                                &data,
+                                &data_len)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("mime",
+                               &mime)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("text",
+                               &text)),
     GNUNET_JSON_spec_end ()
   };
   GtkClipboard *cb;
@@ -393,43 +416,63 @@ anastasis_gtk_secret_copy_button_clicked_cb (GtkButton 
*button,
                                     NULL, NULL));
   cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
   GNUNET_assert (NULL != cb);
-  if (0 == strncasecmp (mime,
-                        "text/",
-                        strlen ("text/")))
+  if (NULL != text)
   {
     gtk_clipboard_set_text (cb,
-                            data,
-                            data_len);
+                            text,
+                            strlen (text));
   }
-  else if (0 == strncasecmp (mime,
-                             "image/",
-                             strlen ("image/")))
+  else
   {
-    GdkPixbufLoader *loader;
-
-    loader = gdk_pixbuf_loader_new_with_mime_type (mime,
-                                                   NULL);
-    if (NULL != loader)
+    if (0 == strncasecmp (mime,
+                          "text/",
+                          strlen ("text/")))
+    {
+      gtk_clipboard_set_text (cb,
+                              data,
+                              data_len);
+    }
+    else if (0 == strncasecmp (mime,
+                               "image/",
+                               strlen ("image/")))
     {
-      GdkPixbuf *pb;
+      GdkPixbufLoader *loader;
 
-      gdk_pixbuf_loader_write (loader,
-                               data,
-                               data_len,
-                               NULL);
-      pb = gdk_pixbuf_loader_get_pixbuf (loader);
-      if (NULL != pb)
+      loader = gdk_pixbuf_loader_new_with_mime_type (mime,
+                                                     NULL);
+      if (NULL != loader)
+      {
+        GdkPixbuf *pb;
+
+        gdk_pixbuf_loader_write (loader,
+                                 data,
+                                 data_len,
+                                 NULL);
+        pb = gdk_pixbuf_loader_get_pixbuf (loader);
+        if (NULL != pb)
+        {
+          gtk_clipboard_set_image (cb,
+                                   pb);
+          g_object_unref (pb);
+        }
+        else
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                      "Failed to parse secret image data.\n");
+        }
+        g_object_unref (loader);
+      }
+      else
       {
-        gtk_clipboard_set_image (cb,
-                                 pb);
-        g_object_unref (pb);
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                    "Unsupported image mime type `%s'\n",
+                    mime);
       }
-      g_object_unref (loader);
     }
-  }
-  else
-  {
-    GNUNET_break (0);
+    else
+    {
+      GNUNET_break (0);
+    }
   }
   GNUNET_JSON_parse_free (spec);
 }

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