[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis-gtk] branch master updated: improve challenge treeview
From: |
gnunet |
Subject: |
[taler-anastasis-gtk] branch master updated: improve challenge treeview dialog |
Date: |
Sun, 04 Apr 2021 13:43:15 +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 e71cd51 improve challenge treeview dialog
e71cd51 is described below
commit e71cd51466e2fbe5e2562466bb6008c10420fa9a
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Apr 4 13:43:07 2021 +0200
improve challenge treeview dialog
---
src/anastasis/anastasis-gtk_action.c | 48 ++++++++-
.../anastasis-gtk_handle-challenge-row-activated.c | 116 +++++++++++++++++++--
2 files changed, 152 insertions(+), 12 deletions(-)
diff --git a/src/anastasis/anastasis-gtk_action.c
b/src/anastasis/anastasis-gtk_action.c
index 5f7ef0f..de03da2 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -1379,6 +1379,52 @@ get_challenge_offset (const char *uuid,
}
+/**
+ * Translate the @a state into a localized, human-readable
+ * string.
+ *
+ * @param state a challenge state, as a string
+ */
+static const char *
+translate_state (const char *state)
+{
+ struct
+ {
+ const char *in;
+ const char *out;
+ } state_map [] = {
+ { .in = "solved",
+ .out = _ ("challenge solved") },
+ { .in = "payment",
+ .out = _ ("payment required") },
+ { .in = "instructions",
+ .out = _ ("solution required") },
+ { .in = "redirect",
+ .out = _ ("visit Web site") },
+ { .in = "server-failure",
+ .out = _ ("provider failure") },
+ { .in = "truth-unknown",
+ .out = _ ("challenge unknown") },
+ { .in = "rate-limit-exceeded",
+ .out = _ ("tries exceeded, wait") },
+ { .in = NULL,
+ .out = NULL }
+ };
+
+ for (unsigned int i = 0; NULL != state_map[i].in; i++)
+ {
+ if (0 != strcmp (state_map[i].in,
+ state))
+ continue;
+ return state_map[i].out;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Could not localize unexpected state `%s'\n",
+ state);
+ return state;
+}
+
+
/**
* Update the list store with the challenge feedback.
*/
@@ -1465,7 +1511,7 @@ show_challenge_feedback (void)
AG_CSM_CHALLENGE_OFFSET, off,
AG_CSM_CHALLENGE_UUID, uuid,
AG_CSM_SOLVED, 0 == strcmp (state, "solved"),
- AG_CSM_STATUS, state, // FIXME: translate 'state' to more human-readable
text!
+ AG_CSM_STATUS, translate_state (state),
AG_CSM_PAYMENT_QR_CODE, qr,
AG_CSM_ERROR_MESSAGE, emsg,
AG_CSM_PAYTO_URI, taler_pay_uri,
diff --git a/src/anastasis/anastasis-gtk_handle-challenge-row-activated.c
b/src/anastasis/anastasis-gtk_handle-challenge-row-activated.c
index f541a76..c68b2b3 100644
--- a/src/anastasis/anastasis-gtk_handle-challenge-row-activated.c
+++ b/src/anastasis/anastasis-gtk_handle-challenge-row-activated.c
@@ -26,27 +26,121 @@
#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 <jansson.h>
+/**
+ * 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)
+ GtkTreeView *tree_view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ gpointer user_data)
{
- // FIXME: if possible, start selected challenge (not if solved, paying, etc.)
- GNUNET_break (0); // FIXME
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkTreeSelection *selection;
+ json_t *args;
+
+ (void) path;
+ (void) column;
+ (void) user_data;
+ selection = gtk_tree_view_get_selection (tree_view);
+ if (gtk_tree_selection_get_selected (selection,
+ &model,
+ &iter))
+ {
+ char *uuid;
+ gboolean solved;
+
+ gtk_tree_model_get (model,
+ &iter,
+ AG_CSM_CHALLENGE_UUID, &uuid,
+ AG_CSM_SOLVED, &solved,
+ -1);
+ if (solved)
+ {
+ g_free (uuid);
+ return;
+ }
+ args = json_pack ("{s:s}",
+ "uuid",
+ uuid);
+ g_free (uuid);
+ }
+ GNUNET_assert (NULL != args);
+ AG_freeze ();
+ AG_ra = ANASTASIS_redux_action (AG_redux_state,
+ "select_challenge",
+ args,
+ &AG_action_cb,
+ NULL);
+ json_decref (args);
}
+/**
+ * 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
*treeselection,
- gpointer user_data)
+anastasis_gtk_challenge_status_treeselection_changed_cb (
+ GtkTreeSelection *selection,
+ gpointer user_data)
{
- GNUNET_break (0); // FIXME: update clipboard with payto URI and/or redirect
URI
- // (if applicable)
+ 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);
+ }
}
--
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: improve challenge treeview dialog,
gnunet <=