diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-11-21 23:11:37 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-11-21 23:11:37 +0100 |
commit | 9142443ac99346ad6fe996179a2c53e6a9b6eead (patch) | |
tree | f9ae5a0bb01efcec15703b230fdc5bdf12820a54 /src | |
parent | 64d6b245702fae93093c40d6bd1d62442638ff82 (diff) | |
download | anastasis-gtk-9142443ac99346ad6fe996179a2c53e6a9b6eead.tar.gz anastasis-gtk-9142443ac99346ad6fe996179a2c53e6a9b6eead.tar.bz2 anastasis-gtk-9142443ac99346ad6fe996179a2c53e6a9b6eead.zip |
work on #7082 (incomplete)
Diffstat (limited to 'src')
-rw-r--r-- | src/anastasis/Makefile.am | 1 | ||||
-rw-r--r-- | src/anastasis/anastasis-gtk_action.c | 257 | ||||
-rw-r--r-- | src/anastasis/anastasis-gtk_handle-challenge-row-activated.c | 188 |
3 files changed, 257 insertions, 189 deletions
diff --git a/src/anastasis/Makefile.am b/src/anastasis/Makefile.am index ade98dc..fe908df 100644 --- a/src/anastasis/Makefile.am +++ b/src/anastasis/Makefile.am @@ -21,7 +21,6 @@ anastasis_gtk_SOURCES = \ anastasis-gtk_handle-backup-button-clicked.c \ anastasis-gtk_handle-challenge-code.c \ anastasis-gtk_handle-challenge-iban.c \ - anastasis-gtk_handle-challenge-row-activated.c \ anastasis-gtk_handle-challenge-question.c \ anastasis-gtk_handle-challenge-totp.c \ anastasis-gtk_handle-clear-secret-clicked.c \ 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 (); diff --git a/src/anastasis/anastasis-gtk_handle-challenge-row-activated.c b/src/anastasis/anastasis-gtk_handle-challenge-row-activated.c deleted file mode 100644 index 4f2c9cb..0000000 --- a/src/anastasis/anastasis-gtk_handle-challenge-row-activated.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - This file is part of anastasis-gtk. - 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 - 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-challenge-row-activated.c - * @brief - * @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_handle-identity-changed.h" -#include <jansson.h> - - -static void -start_solve (GtkTreeModel *model, - GtkTreeIter *iter) -{ - char *uuid; - gboolean solved; - json_t *args; - - gtk_tree_model_get (model, - iter, - AG_CSM_CHALLENGE_UUID, &uuid, - AG_CSM_SOLVED, &solved, - -1); - if (solved) - { - g_free (uuid); - return; - } - args = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("uuid", - uuid)); - g_free (uuid); - AG_freeze (); - AG_ra = ANASTASIS_redux_action (AG_redux_state, - "select_challenge", - args, - &AG_action_cb, - NULL); - json_decref (args); -} - - -/** - * The user activated a row in the challenge list. - * If the row contains an unsolved challenge, start - * the process to solve the challenge. - * - * @param selection the selected data - * @param user_data unused - */ -void -anastasis_gtk_challenge_status_treeview_row_activated_cb ( - GtkTreeView *tree_view, - GtkTreePath *path, - GtkTreeViewColumn *column, - gpointer user_data) -{ - GtkTreeModel *model; - GtkTreeIter iter; - GtkTreeSelection *selection; - - (void) path; - (void) column; - (void) user_data; - selection = gtk_tree_view_get_selection (tree_view); - if (gtk_tree_selection_get_selected (selection, - &model, - &iter)) - { - start_solve (model, - &iter); - } - else - { - /* How can this be? */ - GNUNET_break (0); - } -} - - -/** - * The user clicked one of the challenge buttons, select the - * challenge. - * - * @param button the button that was clicked - * @param user_data a `json *` with the challenge - */ -void -anastasis_gtk_challenge_status_solved_toggled_cb ( - GtkCellRendererToggle *cell_renderer, - gchar *path, - gpointer user_data) -{ - GtkTreePath *p; - GtkTreeIter iter; - GtkTreeModel *model; - - model = GTK_TREE_MODEL (GCG_get_main_window_object ( - "challenge_status_liststore")); - p = gtk_tree_path_new_from_string (path); - gtk_tree_model_get_iter (model, - &iter, - p); - gtk_tree_path_free (p); - start_solve (model, - &iter); -} - - -/** - * The user selected another row in the challenge list. - * If the row has data that might be interesting for the - * clipboard, copy it there. - * - * @param selection the selected data - * @param user_data unused - */ -void -anastasis_gtk_challenge_status_treeselection_changed_cb ( - GtkTreeSelection *selection, - gpointer user_data) -{ - GtkTreeModel *model; - GtkTreeIter iter; - GtkClipboard *cb; - - (void) user_data; - cb = gtk_clipboard_get (GDK_SELECTION_PRIMARY); - GNUNET_assert (NULL != cb); - if (gtk_tree_selection_get_selected (selection, - &model, - &iter)) - { - char *uri; - char *url; - gboolean paying; - gboolean have_redir; - - gtk_tree_model_get (model, - &iter, - AG_CSM_PAYTO_URI, &uri, - AG_CSM_PAYING, &paying, - AG_CSM_REDIRECT_URL, &url, - AG_CSM_HAVE_REDIRECT, &have_redir, - -1); - if (paying && (NULL != uri)) - gtk_clipboard_set_text (cb, - uri, - strlen (uri)); - else if (have_redir && (NULL != url)) - gtk_clipboard_set_text (cb, - url, - strlen (url)); - else - gtk_clipboard_set_text (cb, - "", - 0); - g_free (url); - } - else - { - gtk_clipboard_set_text (cb, - "", - 0); - } -} |