]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Migrazione a libzakform di struttura.
authorAndrea Zagli <azagli@libero.it>
Mon, 12 Dec 2016 12:33:42 +0000 (13:33 +0100)
committerAndrea Zagli <azagli@libero.it>
Mon, 12 Dec 2016 12:33:42 +0000 (13:33 +0100)
data/organigramma/form/struttura.form
src/struttura.c

index b043305c5b232b4f25ccd2560d98b62c832d0704..96622f8aa2b39185e43687a96f84c89fd27d6a0b 100644 (file)
@@ -1,31 +1,35 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>strutture</table>
-
-       <widget type="label" name="label31" label="label32">
-               <field type="integer" name="id">
-                       <is-key>t</is-key>
-                       <auto-increment>t</auto-increment>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry8" label="label27">
-               <field type="text" name="nome">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="textview" name="textview3" label="label28">
-               <field type="text" name="descrizione" />
-       </widget>
-
-       <widget type="entry" name="entry9" label="label30">
-               <field type="text" name="prefisso_centralino" />
-       </widget>
-
-       <widget type="entry" name="entry10" label="label33">
-               <field type="text" name="interno_centralino" />
-       </widget>
-
-</gtkform>
+<zakform>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id</name>
+    <type>integer</type>
+    <label>label32</label>
+    <is-key>TRUE</is-key>
+    <widget>label31</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>nome</name>
+    <type>string</type>
+    <label>label27</label>
+    <widget>entry8</widget>
+    <validator type="zak_form_element_validator_notempty"/>
+  </element>
+  <element type="zak_form_gtk_form_element_textview">
+    <name>descrizione</name>
+    <type>string</type>
+    <label>label28</label>
+    <widget>textview3</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>prefisso_centralino</name>
+    <type>string</type>
+    <label>label30</label>
+    <widget>entry9</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>interno_centralino</name>
+    <type>string</type>
+    <label>label33</label>
+    <widget>entry10</widget>
+  </element>
+</zakform>
index d892dd4903e93412656c5fc02e3526bbd2e759d7..e1f1e6ad0cf617cce8ccdc46534f8cdec38ff02a 100644 (file)
@@ -24,7 +24,9 @@
 #include <libpq-fe.h>
 
 #include <libzakautho/autoz.h>
-#include <libgtkform/form.h>
+#include <libzakform/libzakform.h>
+#include <libzakformgtk/libzakformgtk.h>
+#include <libzakformgdaex/libzakformgdaex.h>
 #include <libterritorio/via.h>
 #include <libsolipa/utils.h>
 
@@ -147,7 +149,8 @@ struct _OrganigrammaStrutturaPrivate
        {
                OrganigrammaCommons *commons;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *form_provider;
 
                GtkWidget *w;
 
@@ -229,13 +232,15 @@ OrganigrammaStruttura
                        return NULL;
                }
 
-       priv->form = gtk_form_new ();
-       g_object_set (G_OBJECT (priv->form), "gdaex", priv->commons->gdaex, NULL);
-       gtk_form_load_from_file (priv->form, g_build_filename (priv->commons->formdir, "struttura.form", NULL), priv->commons->gtkbuilder);
+       priv->form = zak_form_gtk_form_new ();
+       zak_form_gtk_form_set_gtkbuilder (priv->form, priv->commons->gtkbuilder);
+       zak_form_form_load_from_file (ZAK_FORM_FORM (priv->form), g_build_filename (priv->commons->formdir, "struttura.form", NULL));
+
+       priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "strutture");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_struttura"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
+       priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form,
                                                      "label31",
                                                      "lstore_struttura_indirizzi",
                                                      "lstore_struttura_collegamenti",
@@ -245,7 +250,7 @@ OrganigrammaStruttura
        priv->sallegato = solipa_allegato_new (commons->solipa);
        if (priv->sallegato != NULL)
                {
-                       solipa_allegato_add_to_gtkform (priv->sallegato, priv->form,
+                       solipa_allegato_add_to_zakformgtk (priv->sallegato, priv->form,
                                                        "immagine_percorso", "immagine_file_data", "immagine_file_dimensione");
                        solipa_allegato_con_salva_in_db (priv->sallegato, FALSE);
                        gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->commons->gtkbuilder, "alignment3")),
@@ -297,17 +302,18 @@ OrganigrammaStruttura
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button149"),
                          "clicked", G_CALLBACK (organigramma_struttura_on_btn_salvaechiudi_clicked), (gpointer)a);
 
-       gtk_form_clear (priv->form);
+       zak_form_form_clear (ZAK_FORM_FORM (priv->form));
 
        priv->id = id;
-
        if (priv->id == 0)
                {
                        gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), "");
 
-                       gtk_form_set_as_origin (priv->form);
+                       zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form));
 
-                       gtk_form_set_sensitive_by_name (priv->form, FALSE, "hbox6", "hbox23", "hbox31", NULL);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox6")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox23")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox31")), FALSE);
                }
        else
                {
@@ -318,14 +324,14 @@ OrganigrammaStruttura
        ires1 = zak_autho_get_resource_from_id (priv->commons->autoz, "organigramma_rw");
        if (!zak_autho_is_allowed (priv->commons->autoz, priv->commons->role_utente, ires1, FALSE))
                {
-                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "button47")), FALSE);
-                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "button51")), FALSE);
-                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "button40")), FALSE);
-                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "button149")), FALSE);
-                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "button181")), FALSE);
-                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "button183")), FALSE);
-                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "button191")), FALSE);
-                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "button193")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button47")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button51")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button40")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button149")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button181")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button183")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button191")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button193")), FALSE);
                }
 
        return a;
@@ -350,7 +356,7 @@ organigramma_struttura_carica (OrganigrammaStruttura *struttura)
 {
        OrganigrammaStrutturaPrivate *priv = ORGANIGRAMMA_STRUTTURA_GET_PRIVATE (struttura);
 
-       if (gtk_form_fill_from_table (priv->form))
+       if (zak_form_form_load (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider)))
                {
                        organigramma_struttura_carica_indirizzi (struttura);
                        organigramma_struttura_carica_collegamenti (struttura);
@@ -361,36 +367,51 @@ organigramma_struttura_carica (OrganigrammaStruttura *struttura)
 static void
 organigramma_struttura_salva (OrganigrammaStruttura *struttura, gboolean chiudi)
 {
+       gboolean success;
+
        gchar *sql;
 
        OrganigrammaStrutturaClass *klass = ORGANIGRAMMA_STRUTTURA_GET_CLASS (struttura);
-
        OrganigrammaStrutturaPrivate *priv = ORGANIGRAMMA_STRUTTURA_GET_PRIVATE (struttura);
 
-       if (!gtk_form_check (priv->form, (priv->id != 0), NULL, TRUE, priv->w, TRUE))
+       if (!zak_form_gtk_form_is_valid (priv->form, priv->w))
                {
                        return;
                }
 
+       success = FALSE;
+
        if (priv->id == 0)
                {
-                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_INSERT);
+                       guint new_id;
+
+                       new_id = gdaex_get_new_id (priv->commons->gdaex,
+                                                                          "strutture",
+                                                                          "id",
+                                                                          NULL);
+
+                       gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), g_strdup_printf ("%d", new_id));
+
+                       success = zak_form_form_insert (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider));
                }
        else
                {
-                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_UPDATE);
+                       success = zak_form_form_update (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider));
                }
 
-       if (gdaex_execute (priv->commons->gdaex, sql) == 1)
+       if (success)
                {
                        g_signal_emit (struttura, klass->aggiornato_signal_id, 0);
 
-                       gtk_form_set_as_origin (priv->form);
+                       zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form));
 
                        if (priv->id == 0)
                                {
                                        priv->id = strtol (gtk_label_get_text (GTK_LABEL (priv->objects[LBL_ID])), NULL, 10);
-                                       gtk_form_set_sensitive_by_name (priv->form, TRUE, "hbox6", "hbox23", "hbox31", NULL);
+
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox6")), TRUE);
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox23")), TRUE);
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox31")), TRUE);
                                }
 
                        /* salvo l'atto_allegato nel db */
@@ -755,7 +776,7 @@ organigramma_struttura_conferma_chiusura (OrganigrammaStruttura *struttura)
        OrganigrammaStrutturaPrivate *priv = ORGANIGRAMMA_STRUTTURA_GET_PRIVATE (struttura);
 
        ret = TRUE;
-       if (gtk_form_is_changed (priv->form))
+       if (zak_form_form_is_changed (ZAK_FORM_FORM (priv->form)))
                {
                        if (solipa_message_dialog (priv->w,
                                                   GTK_MESSAGE_QUESTION,