[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis-gtk] branch master updated: fix #7083: highlight next '
From: |
gnunet |
Subject: |
[taler-anastasis-gtk] branch master updated: fix #7083: highlight next 'bad' user attribute |
Date: |
Mon, 27 Dec 2021 22:57:51 +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 c7ece85 fix #7083: highlight next 'bad' user attribute
c7ece85 is described below
commit c7ece85320454c809b84798b6b5847f22fea5dcc
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Dec 27 22:57:49 2021 +0100
fix #7083: highlight next 'bad' user attribute
---
contrib/anastasis_gtk_main_window.glade | 17 ++-
src/anastasis/anastasis-gtk_action.c | 50 ++------
src/anastasis/anastasis-gtk_attributes.c | 2 +
.../anastasis-gtk_handle-identity-changed.c | 138 ++++++++++++++++++++-
.../anastasis-gtk_handle-identity-changed.h | 10 ++
src/anastasis/anastasis-gtk_helper.c | 33 +++++
src/anastasis/anastasis-gtk_helper.h | 13 ++
7 files changed, 215 insertions(+), 48 deletions(-)
diff --git a/contrib/anastasis_gtk_main_window.glade
b/contrib/anastasis_gtk_main_window.glade
index e9e165a..1b1ab4e 100644
--- a/contrib/anastasis_gtk_main_window.glade
+++ b/contrib/anastasis_gtk_main_window.glade
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2
+<!-- Generated with glade 3.38.2
Copyright (C) 2019-2021 Anastasis SARL
@@ -897,6 +897,7 @@ Author: Christian Grothoff, Dennis Neufeld
<property
name="hexpand">True</property>
<property
name="placeholder-text" translatable="yes">Max Mustermann</property>
<signal name="changed"
handler="AG_identity_changed" swapped="no"/>
+ <signal
name="style-updated" handler="gtk_widget_queue_draw" swapped="no"/>
</object>
<packing>
<property
name="expand">True</property>
@@ -1006,6 +1007,7 @@ Author: Christian Grothoff, Dennis Neufeld
<property
name="day">22</property>
<property
name="show-week-numbers">True</property>
<signal
name="day-selected" handler="AG_identity_changed" swapped="no"/>
+ <signal
name="style-updated" handler="gtk_widget_queue_draw" swapped="no"/>
</object>
<packing>
<property
name="expand">False</property>
@@ -1114,6 +1116,8 @@ Author: Christian Grothoff, Dennis Neufeld
<property
name="can-focus">True</property>
<property
name="hexpand">True</property>
<property
name="placeholder-text" translatable="yes">Earth</property>
+ <signal name="changed"
handler="AG_identity_changed" swapped="no"/>
+ <signal
name="style-updated" handler="gtk_widget_queue_draw" swapped="no"/>
</object>
<packing>
<property
name="expand">True</property>
@@ -1226,6 +1230,7 @@ Author: Christian Grothoff, Dennis Neufeld
<property
name="placeholder-text" translatable="yes">756.1222.3425.89</property>
<property
name="input-purpose">number</property>
<signal name="changed"
handler="AG_identity_changed" swapped="no"/>
+ <signal
name="style-updated" handler="gtk_widget_queue_draw" swapped="no"/>
</object>
<packing>
<property
name="expand">False</property>
@@ -1331,13 +1336,15 @@ Author: Christian Grothoff, Dennis Neufeld
<property
name="visible">True</property>
<property
name="can-focus">True</property>
<property
name="max-length">11</property>
- <property
name="width-chars">12</property>
+ <property
name="width-chars">11</property>
<property
name="max-width-chars">11</property>
<property
name="placeholder-text" translatable="yes">12345678912</property>
<property
name="input-purpose">number</property>
+ <signal name="changed"
handler="AG_identity_changed" swapped="no"/>
+ <signal
name="style-updated" handler="gtk_widget_queue_draw" swapped="no"/>
</object>
<packing>
- <property
name="expand">False</property>
+ <property
name="expand">True</property>
<property
name="fill">True</property>
<property
name="padding">5</property>
<property
name="position">1</property>
@@ -1447,9 +1454,10 @@ Author: Christian Grothoff, Dennis Neufeld
<property
name="placeholder-text" translatable="yes">14230460S534</property>
<property
name="input-purpose">alpha</property>
<signal name="changed"
handler="AG_identity_changed" swapped="no"/>
+ <signal
name="style-updated" handler="gtk_widget_queue_draw" swapped="no"/>
</object>
<packing>
- <property
name="expand">False</property>
+ <property
name="expand">True</property>
<property
name="fill">True</property>
<property
name="padding">5</property>
<property
name="position">1</property>
@@ -1557,6 +1565,7 @@ Author: Christian Grothoff, Dennis Neufeld
<property
name="max-width-chars">11</property>
<property
name="placeholder-text" translatable="yes">000-00-0000</property>
<signal name="changed"
handler="AG_identity_changed" swapped="no"/>
+ <signal
name="style-updated" handler="gtk_widget_queue_draw" swapped="no"/>
</object>
<packing>
<property
name="expand">False</property>
diff --git a/src/anastasis/anastasis-gtk_action.c
b/src/anastasis/anastasis-gtk_action.c
index 823f5f6..8ad386f 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -392,6 +392,11 @@ create_attribute_widget (const struct GNUNET_HashCode *uh,
"changed",
G_CALLBACK (&AG_identity_changed),
NULL));
+ GNUNET_assert (0 <
+ g_signal_connect (w,
+ "style-updated",
+ G_CALLBACK (>k_widget_queue_draw),
+ NULL));
gtk_widget_set_tooltip_text (w,
tooltip);
gtk_box_pack_start (box, /* parent */
@@ -459,47 +464,6 @@ create_attribute_widget (const struct GNUNET_HashCode *uh,
}
-/**
- * Expand base @a name of a widget based on the @a type to
- * create the name of the widget with the data.
- *
- * @param name base name of the widget
- * @param type type of the widget
- * @return NULL on error
- */
-static char *
-expand_name (const char *name,
- const char *type)
-{
- static struct
- {
- const char *type;
- const char *suffix;
- } type_map [] = {
- { .type = "string",
- .suffix = "entry" },
- { .type = "date",
- .suffix = "cal" },
- { .type = NULL,
- .suffix = NULL }
- };
- char *data_widget;
-
- for (unsigned int i = 0; NULL != type_map[i].type; i++)
- {
- if (0 != strcmp (type_map[i].type,
- type))
- continue;
- GNUNET_asprintf (&data_widget,
- "%s_%s",
- name,
- type_map[i].suffix);
- return data_widget;
- }
- return NULL;
-}
-
-
/**
* Update GtkLabel @a name, setting text to @a value.
*
@@ -585,8 +549,8 @@ action_user_attributes_collecting (void)
{
char *data_name;
- data_name = expand_name (widget_name,
- attr_type);
+ data_name = AG_expand_name (widget_name,
+ attr_type);
w = GTK_WIDGET (GCG_get_main_window_object (data_name));
if (NULL == w)
{
diff --git a/src/anastasis/anastasis-gtk_attributes.c
b/src/anastasis/anastasis-gtk_attributes.c
index 133dc24..1c1139f 100644
--- a/src/anastasis/anastasis-gtk_attributes.c
+++ b/src/anastasis/anastasis-gtk_attributes.c
@@ -28,6 +28,7 @@
#include "anastasis-gtk_helper.h"
#include "anastasis-gtk_action.h"
#include "anastasis-gtk_attributes.h"
+#include "anastasis-gtk_handle-identity-changed.h"
static json_t *
@@ -144,6 +145,7 @@ AG_collect_attributes (bool partial)
continue;
if (optional)
continue;
+ AG_mark_invalid_input (attr_name);
json_decref (result);
return NULL;
}
diff --git a/src/anastasis/anastasis-gtk_handle-identity-changed.c
b/src/anastasis/anastasis-gtk_handle-identity-changed.c
index 5edc95f..c84c031 100644
--- a/src/anastasis/anastasis-gtk_handle-identity-changed.c
+++ b/src/anastasis/anastasis-gtk_handle-identity-changed.c
@@ -32,6 +32,108 @@
#include <jansson.h>
+/**
+ * Enable or disable highlighting of widget @a w as problematic.
+ *
+ * @param on true to enable highlighting, false to disable
+ */
+static void
+highlight (GtkWidget *w,
+ bool on)
+{
+ static GtkCssProvider *gcp;
+ GtkStyleContext *gsc;
+
+ if (NULL == gcp)
+ {
+ GError *err = NULL;
+
+ gcp = gtk_css_provider_new ();
+ GNUNET_break (true ==
+ gtk_css_provider_load_from_data (gcp,
+ "* {background-color:
#FF4500;}",
+ -1,
+ &err));
+ if (NULL != err)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse CSS: %s\n",
+ err->message);
+ }
+ gsc = gtk_widget_get_style_context (w);
+ if (on)
+ {
+ gtk_style_context_add_provider (gsc,
+ GTK_STYLE_PROVIDER (gcp),
+ GTK_STYLE_PROVIDER_PRIORITY_USER);
+ }
+ else
+ {
+ gtk_style_context_remove_provider (gsc,
+ GTK_STYLE_PROVIDER (gcp));
+ }
+}
+
+
+void
+AG_mark_invalid_input (const char *name)
+{
+ const json_t *id_attributes;
+ size_t index;
+ json_t *id_attr;
+
+ id_attributes = json_object_get (AG_redux_state,
+ "required_attributes");
+ json_array_foreach (id_attributes, index, id_attr)
+ {
+ const char *widget_name = NULL;
+ const char *attr_type;
+ const char *attr_uuid;
+ const char *attr_name;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("widget",
+ &widget_name)),
+ GNUNET_JSON_spec_string ("type",
+ &attr_type),
+ GNUNET_JSON_spec_string ("uuid",
+ &attr_uuid),
+ GNUNET_JSON_spec_string ("name",
+ &attr_name),
+ GNUNET_JSON_spec_end ()
+ };
+ GtkWidget *w = NULL;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_JSON_parse (id_attr,
+ spec,
+ NULL, NULL));
+ if (NULL != widget_name)
+ {
+ char *data_name;
+
+ data_name = AG_expand_name (widget_name,
+ attr_type);
+ w = GTK_WIDGET (GCG_get_main_window_object (data_name));
+ GNUNET_free (data_name);
+ }
+ if (NULL == w)
+ {
+ struct GNUNET_HashCode uh;
+
+ GNUNET_CRYPTO_hash (attr_uuid,
+ strlen (attr_uuid),
+ &uh);
+ w = GNUNET_CONTAINER_multihashmap_get (AG_entry_attributes,
+ &uh);
+ }
+ highlight (w,
+ (0 == strcmp (name,
+ attr_name)));
+ GNUNET_JSON_parse_free (spec);
+ }
+}
+
+
/**
* Function called with the results of #ANASTASIS_redux_action.
*
@@ -45,9 +147,42 @@ test_ok_cb (void *cls,
json_t *response)
{
bool *result = cls;
+ const char *name;
- if (TALER_EC_NONE == error_code)
+ switch (error_code)
+ {
+ case TALER_EC_NONE:
*result = true;
+ AG_mark_invalid_input ("__none__");
+ break;
+ case TALER_EC_GENERIC_PARAMETER_MISSING:
+ /* should not be possible */
+ GNUNET_break (0);
+ break;
+ case TALER_EC_ANASTASIS_REDUCER_STATE_INVALID:
+ /* should not be possible */
+ GNUNET_break (0);
+ break;
+ case TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID:
+ /* should not be possible */
+ GNUNET_break (0);
+ break;
+ case TALER_EC_ANASTASIS_REDUCER_INPUT_REGEX_FAILED:
+ name = json_string_value (json_object_get (response,
+ "detail"));
+ AG_mark_invalid_input (name);
+ break;
+ case TALER_EC_ANASTASIS_REDUCER_INPUT_VALIDATION_FAILED:
+ name = json_string_value (json_object_get (response,
+ "detail"));
+ AG_mark_invalid_input (name);
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unexpected error code %d from reducer\n",
+ error_code);
+ break;
+ }
}
@@ -75,6 +210,7 @@ check_attributes_fullfilled (void)
if (NULL != ta)
{
result = true;
+ AG_mark_invalid_input ("__none__");
ANASTASIS_redux_action_cancel (ta);
}
json_decref (args);
diff --git a/src/anastasis/anastasis-gtk_handle-identity-changed.h
b/src/anastasis/anastasis-gtk_handle-identity-changed.h
index 826b69c..4724d79 100644
--- a/src/anastasis/anastasis-gtk_handle-identity-changed.h
+++ b/src/anastasis/anastasis-gtk_handle-identity-changed.h
@@ -26,6 +26,16 @@
#ifndef ANASTASIS_GTK_HANDLE_IDENTITY_CHANGED_H
#define ANASTASIS_GTK_HANDLE_IDENTITY_CHANGED_H
+
+/**
+ * Mark widget for attribute with name @a name as problematic.
+ *
+ * @param name name of the attribute to highlight
+ */
+void
+AG_mark_invalid_input (const char *name);
+
+
/**
* Function called when the user changed anything about its identity.
* Check whether the current input is valid and enables/disables the
diff --git a/src/anastasis/anastasis-gtk_helper.c
b/src/anastasis/anastasis-gtk_helper.c
index 6e036ca..dbb66ce 100644
--- a/src/anastasis/anastasis-gtk_helper.c
+++ b/src/anastasis/anastasis-gtk_helper.c
@@ -413,3 +413,36 @@ AG_setup_qrcode (GtkWidget *w,
text,
text_size);
}
+
+
+char *
+AG_expand_name (const char *name,
+ const char *type)
+{
+ static struct
+ {
+ const char *type;
+ const char *suffix;
+ } type_map [] = {
+ { .type = "string",
+ .suffix = "entry" },
+ { .type = "date",
+ .suffix = "cal" },
+ { .type = NULL,
+ .suffix = NULL }
+ };
+ char *data_widget;
+
+ for (unsigned int i = 0; NULL != type_map[i].type; i++)
+ {
+ if (0 != strcmp (type_map[i].type,
+ type))
+ continue;
+ GNUNET_asprintf (&data_widget,
+ "%s_%s",
+ name,
+ type_map[i].suffix);
+ return data_widget;
+ }
+ return NULL;
+}
diff --git a/src/anastasis/anastasis-gtk_helper.h
b/src/anastasis/anastasis-gtk_helper.h
index 35cd633..2cd3d7a 100644
--- a/src/anastasis/anastasis-gtk_helper.h
+++ b/src/anastasis/anastasis-gtk_helper.h
@@ -535,4 +535,17 @@ AG_setup_qrcode (GtkWidget *w,
size_t text_size);
+/**
+ * Expand base @a name of a widget based on the @a type to
+ * create the name of the widget with the data.
+ *
+ * @param name base name of the widget
+ * @param type type of the widget
+ * @return NULL on error
+ */
+char *
+AG_expand_name (const char *name,
+ const char *type);
+
+
#endif
--
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: fix #7083: highlight next 'bad' user attribute,
gnunet <=