[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis-gtk] branch master updated: add logic to serialize user
From: |
gnunet |
Subject: |
[taler-anastasis-gtk] branch master updated: add logic to serialize user attributes and core secret on save |
Date: |
Fri, 19 Mar 2021 12:31:02 +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 ce5cd91 add logic to serialize user attributes and core secret on save
ce5cd91 is described below
commit ce5cd91f79ea9ca332c3b4f4e5c47fd253e750ec
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Fri Mar 19 12:30:56 2021 +0100
add logic to serialize user attributes and core secret on save
---
src/anastasis/anastasis-gtk_action.c | 90 +++++++++++-----------
src/anastasis/anastasis-gtk_attributes.c | 59 ++++++++------
src/anastasis/anastasis-gtk_attributes.h | 10 ++-
.../anastasis-gtk_handle-identity-changed.c | 2 +-
...stasis-gtk_handle-main-window-forward-clicked.c | 2 +-
.../anastasis-gtk_handle-payqr-selection-changed.c | 18 ++---
src/anastasis/anastasis-gtk_io.c | 58 +++++++++++++-
7 files changed, 150 insertions(+), 89 deletions(-)
diff --git a/src/anastasis/anastasis-gtk_action.c
b/src/anastasis/anastasis-gtk_action.c
index 4d579bd..fc66b8f 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -449,25 +449,25 @@ action_user_attributes_collecting (void)
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
}
if (NULL == w)
- w = create_attribute_widget (&uh,
- attr_type,
- attr_label,
- attr_tooltip,
- id_attr);
+ w = create_attribute_widget (&uh,
+ attr_type,
+ attr_label,
+ attr_tooltip,
+ id_attr);
if (NULL != w)
{
- json_t *ia;
- json_t *val;
-
- ia = json_object_get (redux_state,
- "identity_attributes");
- val = json_object_get (ia,
- attr_name);
- if ( (NULL != val) &&
- (! json_is_null (val)) )
- AG_import_attribute_data (w,
- attr_type,
- val);
+ json_t *ia;
+ json_t *val;
+
+ ia = json_object_get (redux_state,
+ "identity_attributes");
+ val = json_object_get (ia,
+ attr_name);
+ if ( (NULL != val) &&
+ (! json_is_null (val)) )
+ AG_import_attribute_data (w,
+ attr_type,
+ val);
}
}
}
@@ -970,8 +970,8 @@ create_qrcode (unsigned int scale,
}
pixels = gdk_pixbuf_get_pixels (pb);
n_channels = gdk_pixbuf_get_n_channels (pb);
- for (unsigned int x = 4 * scale; x < size - 4*scale; x++)
- for (unsigned int y = 4 * scale; y < size- 4*scale; y++)
+ for (unsigned int x = 4 * scale; x < size - 4 * scale; x++)
+ for (unsigned int y = 4 * scale; y < size - 4 * scale; y++)
{
unsigned int xx = x - 4 * scale;
unsigned int yy = y - 4 * scale;
@@ -1042,7 +1042,7 @@ action_truths_paying (void)
AG_hide_all_frames ();
ls = GTK_LIST_STORE (GCG_get_main_window_object (
- "unpaid_qrcodes_liststore"));
+ "unpaid_qrcodes_liststore"));
gtk_list_store_clear (ls);
pprs = json_object_get (redux_state,
"payments");
@@ -1392,8 +1392,8 @@ action_challenge_selecting (void)
char *tmp;
if (0 > TALER_amount_add (&total,
- &total,
- &recovery_cost))
+ &total,
+ &recovery_cost))
{
GNUNET_break_op (0);
AG_error ("ERROR: Could not add up costs");
@@ -1525,14 +1525,14 @@ action_challenge_paying (void)
GNUNET_JSON_spec_string ("state",
&state),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("taler_pay_uri",
- &payto)),
+ GNUNET_JSON_spec_string ("taler_pay_uri",
+ &payto)),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("provider",
- &provider)),
+ GNUNET_JSON_spec_string ("provider",
+ &provider)),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("payment_secret",
- &ps)),
+ GNUNET_JSON_spec_string ("payment_secret",
+ &ps)),
GNUNET_JSON_spec_end ()
};
GdkPixbuf *pb;
@@ -1544,14 +1544,14 @@ action_challenge_paying (void)
{
GNUNET_break (0);
json_dumpf (ppr,
- stderr,
- JSON_INDENT (2));
+ stderr,
+ JSON_INDENT (2));
continue;
}
if (NULL == payto)
continue;
if (0 != strcmp (state,
- "payment"))
+ "payment"))
continue;
found = true;
pb = setup_qrcode ("unpaid_qr_treeview",
@@ -1581,9 +1581,9 @@ action_challenge_paying (void)
GNUNET_assert (NULL == ra);
args = json_pack ("{s:o, s:s}",
"timeout",
- GNUNET_JSON_from_time_rel (timeout),
- "payment_secret",
- ps);
+ GNUNET_JSON_from_time_rel (timeout),
+ "payment_secret",
+ ps);
ra = ANASTASIS_redux_action (redux_state,
"pay",
args,
@@ -1836,19 +1836,19 @@ AG_action_cb (void *cls,
AG_thaw ();
#if DEBUG
fprintf (stderr,
- "Action result %d\n",
- error_code);
+ "Action result %d\n",
+ error_code);
json_dumpf (response,
- stderr,
- JSON_INDENT (2));
+ stderr,
+ JSON_INDENT (2));
fprintf (stderr,
- "END action result %d\n",
- error_code);
+ "END action result %d\n",
+ error_code);
#endif
if (TALER_EC_NONE != error_code)
{
AG_error ("Error: %s (%d)\n",
- TALER_ErrorCode_get_hint (error_code),
+ TALER_ErrorCode_get_hint (error_code),
error_code);
if (in_action)
{
@@ -1870,10 +1870,10 @@ AG_action_cb (void *cls,
}
in_action = false;
AG_error ("Unhandled state `%s/%s'",
- json_string_value (json_object_get (redux_state,
- "backup_state")),
- json_string_value (json_object_get (redux_state,
- "recovery_state")));
+ json_string_value (json_object_get (redux_state,
+ "backup_state")),
+ json_string_value (json_object_get (redux_state,
+ "recovery_state")));
json_dumpf (redux_state,
stderr,
JSON_INDENT (2));
diff --git a/src/anastasis/anastasis-gtk_attributes.c
b/src/anastasis/anastasis-gtk_attributes.c
index f57e3bb..ad8b113 100644
--- a/src/anastasis/anastasis-gtk_attributes.c
+++ b/src/anastasis/anastasis-gtk_attributes.c
@@ -68,7 +68,7 @@ extract_cal (GtkWidget *cal)
json_t *
-AG_collect_attributes ()
+AG_collect_attributes (bool partial)
{
static struct
{
@@ -119,6 +119,13 @@ AG_collect_attributes ()
&uh);
w = GNUNET_CONTAINER_multihashmap_get (AG_entry_attributes,
&uh);
+ if (NULL == w)
+ {
+ if (partial)
+ continue;
+ json_decref (result);
+ return NULL;
+ }
for (unsigned int i = 0; NULL != e_map[i].type; i++)
{
if (0 != strcmp (e_map[i].type,
@@ -129,6 +136,8 @@ AG_collect_attributes ()
}
if (NULL == val)
{
+ if (partial)
+ continue;
json_decref (result);
return NULL;
}
@@ -151,11 +160,11 @@ AG_collect_attributes ()
*/
static void
import_entry (GtkWidget *w,
- const json_t *value)
+ const json_t *value)
{
GNUNET_break (json_is_string (value));
gtk_entry_set_text (GTK_ENTRY (w),
- json_string_value (value));
+ json_string_value (value));
}
@@ -167,7 +176,7 @@ import_entry (GtkWidget *w,
*/
static void
import_cal (GtkWidget *w,
- const json_t *value)
+ const json_t *value)
{
const char *s;
guint day;
@@ -177,39 +186,39 @@ import_cal (GtkWidget *w,
s = json_string_value (value);
if (NULL == s)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
if (3 !=
sscanf (s,
- "%04u-%02u-%02u%c",
- &year,
- &month,
- &day,
- &dummy))
- {
- GNUNET_break (0);
- return;
- }
+ "%04u-%02u-%02u%c",
+ &year,
+ &month,
+ &day,
+ &dummy))
+ {
+ GNUNET_break (0);
+ return;
+ }
gtk_calendar_select_day (GTK_CALENDAR (w),
- day);
+ day);
gtk_calendar_select_month (GTK_CALENDAR (w),
- month,
- year);
+ month,
+ year);
}
void
AG_import_attribute_data (GtkWidget *w,
- const char *type,
- const json_t *value)
+ const char *type,
+ const json_t *value)
{
static struct
{
const char *type;
void (*import)(GtkWidget *w,
- const json_t *value);
+ const json_t *value);
} i_map [] = {
{ .type = "string",
.import = &import_entry },
@@ -222,10 +231,10 @@ AG_import_attribute_data (GtkWidget *w,
for (unsigned int i = 0; NULL != i_map[i].type; i++)
{
if (0 != strcmp (i_map[i].type,
- type))
+ type))
continue;
i_map[i].import (w,
- value);
+ value);
return;
}
diff --git a/src/anastasis/anastasis-gtk_attributes.h
b/src/anastasis/anastasis-gtk_attributes.h
index 5171e27..13546cb 100644
--- a/src/anastasis/anastasis-gtk_attributes.h
+++ b/src/anastasis/anastasis-gtk_attributes.h
@@ -27,18 +27,20 @@
#define ANASTASIS_GTK_ATTRIBUTES_H
#include <jansson.h>
+#include <gtk/gtk.h>
/**
* Tries to compile the user's attributes into a JSON object.
*
+ * @param partial is partial collection OK?
* @return NULL on failure
*/
json_t *
-AG_collect_attributes (void);
+AG_collect_attributes (bool partial);
/**
- * Set widget @a w value from a the @a value.
+ * Set widget @a w value from a the @a value.
*
* @param w a widget to initialize
* @param type the attribute type of the widget and the value
@@ -46,8 +48,8 @@ AG_collect_attributes (void);
*/
void
AG_import_attribute_data (GtkWidget *w,
- const char *type,
- const json_t *value);
+ const char *type,
+ const json_t *value);
#endif
diff --git a/src/anastasis/anastasis-gtk_handle-identity-changed.c
b/src/anastasis/anastasis-gtk_handle-identity-changed.c
index e0a1735..cd00fe0 100644
--- a/src/anastasis/anastasis-gtk_handle-identity-changed.c
+++ b/src/anastasis/anastasis-gtk_handle-identity-changed.c
@@ -63,7 +63,7 @@ check_attributes_fullfilled (void)
json_t *args;
bool result;
- args = AG_collect_attributes ();
+ args = AG_collect_attributes (false);
if (NULL == args)
return false;
result = false;
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 9eb33fc..c6e36f3 100644
--- a/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
+++ b/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
@@ -84,7 +84,7 @@ AG_forward_user_attributes_collecting (void)
json_t *args;
AG_freeze ();
- args = AG_collect_attributes ();
+ args = AG_collect_attributes (false);
GNUNET_assert (NULL != args);
ra = ANASTASIS_redux_action (redux_state,
"enter_user_attributes",
diff --git a/src/anastasis/anastasis-gtk_handle-payqr-selection-changed.c
b/src/anastasis/anastasis-gtk_handle-payqr-selection-changed.c
index 1a9cd17..8ecea63 100644
--- a/src/anastasis/anastasis-gtk_handle-payqr-selection-changed.c
+++ b/src/anastasis/anastasis-gtk_handle-payqr-selection-changed.c
@@ -37,7 +37,7 @@
*/
void
unpaid_qr_tree_selection_changed_cb (GtkTreeSelection *selection,
- gpointer user_data)
+ gpointer user_data)
{
GtkTreeModel *model;
GtkTreeIter iter;
@@ -52,18 +52,18 @@ unpaid_qr_tree_selection_changed_cb (GtkTreeSelection
*selection,
char *uri;
gtk_tree_model_get (model,
- &iter,
- AG_UQRMC_URL, &uri,
- -1);
+ &iter,
+ AG_UQRMC_URL, &uri,
+ -1);
gtk_clipboard_set_text (cb,
- uri,
- strlen (uri));
- g_free (uri);
+ uri,
+ strlen (uri));
+ g_free (uri);
}
else
{
gtk_clipboard_set_text (cb,
- "",
- 0);
+ "",
+ 0);
}
}
diff --git a/src/anastasis/anastasis-gtk_io.c b/src/anastasis/anastasis-gtk_io.c
index ac9d06f..6558918 100644
--- a/src/anastasis/anastasis-gtk_io.c
+++ b/src/anastasis/anastasis-gtk_io.c
@@ -24,6 +24,8 @@
*/
#include <gnunet/platform.h>
#include <gnunet/gnunet_util_lib.h>
+#include "anastasis-gtk_attributes.h"
+#include "anastasis-gtk_dispatch.h"
#include "anastasis-gtk_helper.h"
#include <jansson.h>
@@ -91,6 +93,49 @@ anastasis_gtk_open_state_clicked_cb (GtkButton *button,
}
+/**
+ * Serialize state of currently shown use attribute editing frame to JSON.
+ */
+static void
+save_user_attributes_collecting (void)
+{
+ json_t *ia;
+
+ ia = AG_collect_attributes (true);
+ if (NULL == ia)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_break (0 ==
+ json_object_set (redux_state,
+ "identity_attributes",
+ json_object_get (ia,
+ "identity_attributes")));
+ json_decref (ia);
+}
+
+
+/**
+ * Serialize state of currently shown secret editing frame to JSON.
+ */
+static void
+save_secret_editing (void)
+{
+ GtkEntry *entry;
+ const char *str;
+
+ entry = GTK_ENTRY (GCG_get_main_window_object (
+ "anastasis_gtk_enter_secret_entry"));
+ str = gtk_entry_get_text (entry);
+ GNUNET_assert (0 ==
+ json_object_set_new (redux_state,
+ "core_secret",
+ GNUNET_JSON_from_data (str,
+ strlen (str))));
+}
+
+
/**
* Function called from the open-directory dialog upon completion.
*
@@ -103,6 +148,14 @@ save_directory_dialog_response_cb (GtkDialog *dialog,
gint response_id,
gpointer user_data)
{
+ static const struct DispatchItem save_state[] = {
+ { .state = "USER_ATTRIBUTES_COLLECTING",
+ .action = &save_user_attributes_collecting },
+ { .state = "SECRET_EDITING",
+ .action = &save_secret_editing },
+ { .state = NULL,
+ .action = NULL }
+ };
GtkBuilder *builder = GTK_BUILDER (user_data);
char *filename;
@@ -112,10 +165,7 @@ save_directory_dialog_response_cb (GtkDialog *dialog,
g_object_unref (G_OBJECT (builder));
return;
}
- // FIXME: serialize state of currently shown frame!?
- // Right now, user attributes entered on the current
- // screen as well as the core secret are LOST if
- // the user changed them and then clicks 'save as'
+ (void) AG_dispatch (save_state);
filename =
GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (dialog));
gtk_widget_destroy (GTK_WIDGET (dialog));
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis-gtk] branch master updated: add logic to serialize user attributes and core secret on save,
gnunet <=