]> saetta.ns0.it Git - zakform/tests/commitdiff
Added test for validator's and filter's property 'enabled'.
authorAndrea Zagli <azagli@libero.it>
Sun, 29 Jan 2017 09:11:31 +0000 (10:11 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 29 Jan 2017 09:11:31 +0000 (10:11 +0100)
data/zakformtests/gui/main.ui
src/gtk_ini.c

index 4b63601c6c7a65281106ae7709de69027e9d5f4f..b41bd8c391c9af351a23b0e063d2842e39684d3f 100644 (file)
             <property name="position">2</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkButtonBox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">5</property>
+            <property name="layout_style">center</property>
+            <child>
+              <object class="GtkToggleButton" id="togglebutton1">
+                <property name="label" translatable="yes">Disable validators</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToggleButton" id="togglebutton2">
+                <property name="label" translatable="yes">Disable filters</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkScrolledWindow" id="scrolledwindow1">
             <property name="visible">True</property>
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">3</property>
+            <property name="position">4</property>
           </packing>
         </child>
       </object>
index b052dbf2a836f8fba9bb4ea7b1d5b329c64ad42a..950a797fc6a1e9684df545cb40b86675598c2b79 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2016-2017 Andrea Zagli <azagli@libero.it>
  *
  *  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 <libzakformgtk/libzakformgtk.h>
 #include <libzakformini/libzakformini.h>
 
+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);