diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/anastasis/anastasis-gtk_action.c | 50 | ||||
-rw-r--r-- | src/anastasis/anastasis-gtk_attributes.c | 2 | ||||
-rw-r--r-- | src/anastasis/anastasis-gtk_handle-identity-changed.c | 138 | ||||
-rw-r--r-- | src/anastasis/anastasis-gtk_handle-identity-changed.h | 10 | ||||
-rw-r--r-- | src/anastasis/anastasis-gtk_helper.c | 33 | ||||
-rw-r--r-- | src/anastasis/anastasis-gtk_helper.h | 13 |
6 files changed, 202 insertions, 44 deletions
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 */ @@ -460,47 +465,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. * * @param name Glade-name of widget to update @@ -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 @@ -33,6 +33,108 @@ /** + * 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. * * @param cls closure @@ -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 |