From 022421745fd4b9b467880cf2667bf8caee15729e Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 29 Jan 2017 10:11:31 +0100 Subject: [PATCH] Added test for validator's and filter's property 'enabled'. --- data/zakformtests/gui/main.ui | 41 +++++++++++++++++- src/gtk_ini.c | 78 ++++++++++++++++++++++++++++++++--- 2 files changed, 113 insertions(+), 6 deletions(-) diff --git a/data/zakformtests/gui/main.ui b/data/zakformtests/gui/main.ui index 4b63601..b41bd8c 100644 --- a/data/zakformtests/gui/main.ui +++ b/data/zakformtests/gui/main.ui @@ -468,6 +468,45 @@ 2 + + + True + False + 5 + center + + + Disable validators + True + True + True + + + True + True + 0 + + + + + Disable filters + True + True + True + + + True + True + 1 + + + + + False + True + 3 + + True @@ -483,7 +522,7 @@ True True - 3 + 4 diff --git a/src/gtk_ini.c b/src/gtk_ini.c index b052dbf..950a797 100644 --- a/src/gtk_ini.c +++ b/src/gtk_ini.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Andrea Zagli + * Copyright (C) 2016-2017 Andrea Zagli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +24,8 @@ #include #include +GtkBuilder *builder; + GtkWidget *w; ZakFormGtkForm *form; @@ -40,14 +42,20 @@ void insert_clicked (GtkButton *button, gpointer user_data) { - zak_form_form_insert (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); + if (zak_form_gtk_form_is_valid (form, w)) + { + zak_form_form_insert (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); + } } void update_clicked (GtkButton *button, gpointer user_data) { - zak_form_form_update (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); + if (zak_form_gtk_form_is_valid (form, w)) + { + zak_form_form_update (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); + } } void @@ -75,11 +83,67 @@ is_changed_clicked (GtkButton *button, } } +void +validators_toggled (GtkToggleButton *button, + gpointer user_data) +{ + GPtrArray *ar; + guint i; + + GPtrArray *ar_el; + guint j; + + ar = zak_form_form_get_validators (ZAK_FORM_FORM (form)); + for (i = 0; i < ar->len; i++) + { + zak_form_validator_set_enabled ((ZakFormValidator *)g_ptr_array_index (ar, i), + !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "togglebutton1")))); + } + + ar_el = zak_form_form_get_elements (ZAK_FORM_FORM (form)); + for (i = 0; i < ar_el->len; i++) + { + ar = zak_form_element_get_validators (ZAK_FORM_ELEMENT ((ZakFormElement *)g_ptr_array_index (ar_el, i))); + for (j = 0; j < ar->len; j++) + { + zak_form_element_validator_set_enabled ((ZakFormElementValidator *)g_ptr_array_index (ar, j), + !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "togglebutton1")))); + } + + ar = zak_form_element_get_filters (ZAK_FORM_ELEMENT ((ZakFormElement *)g_ptr_array_index (ar_el, i))); + for (j = 0; j < ar->len; j++) + { + zak_form_element_filter_set_enabled ((ZakFormElementFilter *)g_ptr_array_index (ar, j), + !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "togglebutton2")))); + } + } +} + +void +filters_toggled (GtkToggleButton *button, + gpointer user_data) +{ + GPtrArray *ar; + guint i; + + GPtrArray *ar_el; + guint j; + + ar_el = zak_form_form_get_elements (ZAK_FORM_FORM (form)); + for (i = 0; i < ar_el->len; i++) + { + ar = zak_form_element_get_filters (ZAK_FORM_ELEMENT ((ZakFormElement *)g_ptr_array_index (ar_el, i))); + for (j = 0; j < ar->len; j++) + { + zak_form_element_filter_set_enabled ((ZakFormElementFilter *)g_ptr_array_index (ar, j), + !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "togglebutton2")))); + } + } +} + int main (int argc, char *argv[]) { - GtkBuilder *builder; - gtk_init (&argc, &argv); builder = gtk_builder_new (); @@ -102,6 +166,10 @@ main (int argc, char *argv[]) G_CALLBACK (is_valid_clicked), NULL); g_signal_connect (gtk_builder_get_object (builder, "button5"), "clicked", G_CALLBACK (is_changed_clicked), NULL); + g_signal_connect (gtk_builder_get_object (builder, "togglebutton1"), "toggled", + G_CALLBACK (validators_toggled), NULL); + g_signal_connect (gtk_builder_get_object (builder, "togglebutton2"), "toggled", + G_CALLBACK (filters_toggled), NULL); form = zak_form_gtk_form_new (); zak_form_gtk_form_set_gtkbuilder (form, builder); -- 2.49.0