summaryrefslogtreecommitdiff
path: root/src/anastasis/anastasis-gtk_action.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-11-21 23:11:37 +0100
committerChristian Grothoff <christian@grothoff.org>2021-11-21 23:11:37 +0100
commit9142443ac99346ad6fe996179a2c53e6a9b6eead (patch)
treef9ae5a0bb01efcec15703b230fdc5bdf12820a54 /src/anastasis/anastasis-gtk_action.c
parent64d6b245702fae93093c40d6bd1d62442638ff82 (diff)
downloadanastasis-gtk-9142443ac99346ad6fe996179a2c53e6a9b6eead.tar.gz
anastasis-gtk-9142443ac99346ad6fe996179a2c53e6a9b6eead.tar.bz2
anastasis-gtk-9142443ac99346ad6fe996179a2c53e6a9b6eead.zip
work on #7082 (incomplete)
Diffstat (limited to 'src/anastasis/anastasis-gtk_action.c')
-rw-r--r--src/anastasis/anastasis-gtk_action.c257
1 files changed, 257 insertions, 0 deletions
diff --git a/src/anastasis/anastasis-gtk_action.c b/src/anastasis/anastasis-gtk_action.c
index 07b387e..d742a25 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -2194,6 +2194,227 @@ long_action_cb (void *cls,
/**
+ * Callback invoked if the a "challenge"-button is clicked.
+ *
+ * @param object
+ * @param user_data points to the UUID of the challenge
+ */
+static void
+challenge_button_clicked_cb (GObject *object,
+ gpointer user_data)
+{
+ const char *uuid = user_data;
+ json_t *args;
+
+ (void) object;
+ args = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("uuid",
+ uuid));
+ AG_freeze ();
+ AG_ra = ANASTASIS_redux_action (AG_redux_state,
+ "select_challenge",
+ args,
+ &AG_action_cb,
+ NULL);
+ json_decref (args);
+}
+
+
+/**
+ * Generate widget about a @a challenge and add it to the
+ * @a challenge_box.
+ *
+ * @param challenge_box box to expand
+ * @param rd our recovery document (to use)
+ * @param challenge the challenge to add
+ */
+static void
+add_challenge (GtkBox *challenge_box,
+ json_t *rd,
+ json_t *challenge)
+{
+ GtkBuilder *builder;
+ GtkWindow *window;
+ GtkWidget *hbox;
+ GtkLabel *label;
+ GtkButton *button;
+ const char *instructions;
+ const char *provider;
+ const char *type;
+ const char *uuid;
+ struct TALER_Amount cost;
+ bool async = false;
+ bool solved = false;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("instructions",
+ &instructions),
+ GNUNET_JSON_spec_string ("type",
+ &type),
+ GNUNET_JSON_spec_string ("url",
+ &provider),
+ GNUNET_JSON_spec_string ("uuid",
+ &uuid),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_bool ("async",
+ &async)),
+ GNUNET_JSON_spec_end ()
+ };
+
+ {
+ const json_t *ks;
+
+ ks = json_object_get (challenge,
+ "key_share");
+ if ( (NULL != ks) &&
+ (! json_is_null (ks)) )
+ solved = true;
+ }
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (challenge,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (GNUNET_OK !=
+ lookup_recovery_cost (provider,
+ type,
+ &cost))
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ builder = GNUNET_GTK_get_new_builder (
+ "anastasis_gtk_challenge_template.glade",
+ NULL);
+ window = GTK_WINDOW (gtk_builder_get_object (builder,
+ "challenge_template_window"));
+ hbox = GTK_WIDGET (gtk_builder_get_object (builder,
+ "challenge_hbox"));
+ label = GTK_LABEL (gtk_builder_get_object (builder,
+ "challenge_label"));
+ button = GTK_BUTTON (gtk_builder_get_object (builder,
+ "solve_challenge_button"));
+ if (solved)
+ {
+ GtkImage *solved_img;
+
+ solved_img = GTK_IMAGE (gtk_builder_get_object (builder,
+ "challenge_solved_image"));
+ gtk_widget_show (GTK_WIDGET (solved_img));
+ gtk_widget_hide (GTK_WIDGET (button));
+ }
+ else
+ {
+ g_signal_connect (button,
+ "clicked",
+ G_CALLBACK (challenge_button_clicked_cb),
+ (void *) uuid);
+ gtk_widget_set_tooltip_text (GTK_WIDGET (button),
+ TALER_amount2s (&cost));
+ }
+ {
+ GtkImage *icon;
+ char *lab;
+
+ GNUNET_asprintf (&lab,
+ "challenge_category_%s_image",
+ type);
+ icon = GTK_IMAGE (gtk_builder_get_object (builder,
+ lab));
+ GNUNET_free (lab);
+ if (NULL != icon)
+ gtk_widget_show (GTK_WIDGET (icon));
+ }
+ gtk_label_set_text (label,
+ instructions);
+ g_object_ref (hbox);
+ gtk_container_remove (GTK_CONTAINER (window),
+ hbox);
+ g_object_unref (window);
+ g_object_unref (builder);
+ gtk_box_pack_end (challenge_box,
+ hbox,
+ false,
+ false,
+ 15);
+}
+
+
+/**
+ * Generate widget about a @a policy and add it to the
+ * @a policy_box.
+ *
+ * @param policy_box box to expand
+ * @param rd our recovery document (to use)
+ * @param pindex policy index (for the label)
+ * @param policy policy to add
+ */
+static void
+add_policy (GtkBox *policy_box,
+ json_t *rd,
+ size_t pindex,
+ json_t *policy)
+{
+ GtkBuilder *builder;
+ GtkWindow *window;
+ GtkWidget *widget;
+ GtkLabel *label;
+ GtkBox *vbox;
+ char *txt;
+ json_t *challenges;
+
+ challenges = json_object_get (policy,
+ "challenges");
+ if (NULL == challenges)
+ {
+ GNUNET_break_op (0);
+ AG_error ("Policy did not parse correctly");
+ return;
+ }
+ builder = GNUNET_GTK_get_new_builder ("anastasis_gtk_policy_template.glade",
+ NULL);
+ window = GTK_WINDOW (gtk_builder_get_object (builder,
+ "policy_template_window"));
+ widget = GTK_WIDGET (gtk_builder_get_object (builder,
+ "policy_frame"));
+ label = GTK_LABEL (gtk_builder_get_object (builder,
+ "policy_label"));
+ vbox = GTK_BOX (gtk_builder_get_object (builder,
+ "policy_vbox"));
+ {
+ size_t index;
+ json_t *challenge;
+
+ json_array_foreach (challenges, index, challenge)
+ {
+ add_challenge (vbox,
+ rd,
+ challenge);
+ }
+ }
+ GNUNET_asprintf (&txt,
+ _ ("Policy #%u"),
+ (unsigned int) pindex);
+ gtk_label_set_text (label,
+ txt);
+ GNUNET_free (txt);
+ g_object_ref (widget);
+ gtk_container_remove (GTK_CONTAINER (window),
+ widget);
+ g_object_unref (window);
+ g_object_unref (builder);
+ gtk_box_pack_end (policy_box,
+ widget,
+ false,
+ false,
+ 15);
+}
+
+
+/**
* The user must select the next challenge to solve
* during the recovery process.
*/
@@ -2201,10 +2422,44 @@ static void
action_challenge_selecting (void)
{
json_t *rd;
+ json_t *policies;
+ GtkBox *policy_box;
AG_hide_all_frames ();
rd = json_object_get (AG_redux_state,
"recovery_document");
+ policies = json_object_get (rd,
+ "dps");
+ GNUNET_assert (NULL != policies);
+ policy_box = GTK_BOX (GCG_get_main_window_object (
+ "anastasis_gtk_policy_vbox"));
+ /* remove all existing entries from the box */
+ {
+ GtkContainer *pb;
+ GList *children;
+
+ pb = GTK_CONTAINER (policy_box);
+ children = gtk_container_get_children (pb);
+ for (GList *iter = children; iter != NULL; iter = g_list_next (iter))
+ gtk_container_remove (pb,
+ GTK_WIDGET (iter->data));
+ g_list_free (children);
+ }
+ {
+ size_t pindex;
+ json_t *policy;
+
+ json_array_foreach (policies, pindex, policy)
+ {
+ add_policy (policy_box,
+ rd,
+ pindex,
+ policy);
+ }
+ }
+
+#if OLD
+
{
json_t *challenges;
size_t index;
@@ -2431,6 +2686,8 @@ action_challenge_selecting (void)
"anastasis_gtk_choose_policy_treeview"));
gtk_tree_view_expand_all (tv);
}
+#endif
+
AG_sensitive ("anastasis_gtk_review_policy_treeview");
AG_show ("anastasis_gtk_progress_vbox");
AG_progress_update ();