]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Migrazione a libzakform di ufficio allegato.
authorAndrea Zagli <azagli@libero.it>
Tue, 13 Dec 2016 08:02:29 +0000 (09:02 +0100)
committerAndrea Zagli <azagli@libero.it>
Tue, 13 Dec 2016 08:02:29 +0000 (09:02 +0100)
data/organigramma/form/ufficio_allegato.form
src/ufficioallegato.c

index 63e8b7e6b66165c4e8a361d8b1edae7792534c50..0dfd5c638084f9d49894a1442aef97b964d0ef98 100644 (file)
@@ -1,38 +1,42 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>ufficio_allegati</table>
-
-       <widget type="label" name="label193" label="label192">
-               <field type="integer" name="id">
-                       <is-key>t</is-key>
-                       <auto-increment>t</auto-increment>
-               </field>
-       </widget>
-
-       <widget type="label" name="label199">
-               <field type="integer" name="id_uffici" />
-       </widget>
-
-       <widget type="entry" name="entry56" label="label197">
-               <field type="text" name="titolo">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry54" label="label194">
-               <field type="text" name="descrizione" />
-       </widget>
-
-       <widget type="entry" name="entry55" label="label196">
-               <field type="datetime" name="data_documento">
-                       <datetime-type>date</datetime-type>
-                       <display-format>%d/%m/%Y</display-format>
-               </field>
-       </widget>
-
-       <widget type="textview" name="textview21" label="label195">
-               <field type="text" name="note" />
-       </widget>
-
-</gtkform>
+<zakform>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id</name>
+    <type>integer</type>
+    <label>label192</label>
+    <is-key>TRUE</is-key>
+    <widget>label193</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id_uffici</name>
+    <type>integer</type>
+    <widget>label199</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>titolo</name>
+    <type>string</type>
+    <label>label197</label>
+    <widget>entry56</widget>
+    <validator type="zak_form_element_validator_notempty"/>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>descrizione</name>
+    <type>string</type>
+    <label>label194</label>
+    <widget>entry54</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>data_documento</name>
+    <type>datetime</type>
+    <label>label196</label>
+    <widget>entry55</widget>
+    <format>%d/%m/%Y</format>
+    <validator type="zak_form_element_validator_date">%d/%m/%Y</validator>
+  </element>
+  <element type="zak_form_gtk_form_element_textview">
+    <name>note</name>
+    <type>string</type>
+    <label>label195</label>
+    <widget>textview21</widget>
+  </element>
+</zakform>
index c4efa88d2afed1f01e548e6cda083a2a6eea4896..0343f4f01b6042da8bb1b52614bd40fb82e5383c 100644 (file)
@@ -21,7 +21,9 @@
 
 #include <libsolipa/libsolipa.h>
 #include <libzakautho/autoz.h>
-#include <libgtkform/form.h>
+#include <libzakform/libzakform.h>
+#include <libzakformgtk/libzakformgtk.h>
+#include <libzakformgdaex/libzakformgdaex.h>
 
 #include "ufficioallegato.h"
 
@@ -66,7 +68,8 @@ struct _OrganigrammaUfficioAllegatoPrivate
        {
                OrganigrammaCommons *commons;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *form_provider;
 
                GtkWidget *w;
                SolipaAllegato *sallegato;
@@ -140,15 +143,15 @@ OrganigrammaUfficioAllegato
                        return NULL;
                }
 
-       priv->form = gtk_form_new ();
-       g_object_set (priv->form, "gdaex", priv->commons->gdaex, NULL);
-       gtk_form_load_from_file (priv->form, g_build_filename (priv->commons->formdir, "ufficio_allegato.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, "ufficio_allegato.form", NULL));
 
-       g_object_set (priv->form, "gdaex", priv->commons->gdaex, NULL);
+       priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "ufficio_allegati");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_ufficio_allegato"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
+       priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form,
                                                      "label193",
                                                      "label199",
                                                      NULL);
@@ -156,7 +159,7 @@ OrganigrammaUfficioAllegato
        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,
                                                        "percorso", "data_file", "dimensione_file");
                        solipa_allegato_con_salva_in_db (priv->sallegato, FALSE);
                        gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->commons->gtkbuilder, "alignment2")),
@@ -173,7 +176,7 @@ OrganigrammaUfficioAllegato
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button197"),
                          "clicked", G_CALLBACK (organigramma_ufficio_allegato_on_btn_salvachiudi_clicked), (gpointer)a);
 
-       gtk_form_clear (priv->form);
+       zak_form_form_clear (ZAK_FORM_FORM (priv->form));
 
        priv->id = id;
        if (priv->id == 0)
@@ -186,7 +189,7 @@ OrganigrammaUfficioAllegato
                                        solipa_allegato_set_salva_in_db (priv->sallegato, TRUE);
                                }
 
-                       gtk_form_set_as_origin (priv->form);
+                       zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form));
                }
        else
                {
@@ -223,7 +226,7 @@ organigramma_ufficio_allegato_carica (OrganigrammaUfficioAllegato *organigramma_
 {
        OrganigrammaUfficioAllegatoPrivate *priv = ORGANIGRAMMA_UFFICIO_ALLEGATO_GET_PRIVATE (organigramma_ufficio_allegato);
 
-       if (gtk_form_fill_from_table (priv->form))
+       if (zak_form_form_load (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider)))
                {
                        solipa_allegato_set_salva_in_db (priv->sallegato, TRUE);
                }
@@ -232,34 +235,46 @@ organigramma_ufficio_allegato_carica (OrganigrammaUfficioAllegato *organigramma_
 static void
 organigramma_ufficio_allegato_salva (OrganigrammaUfficioAllegato *organigramma_ufficio_allegato, gboolean chiudi)
 {
+       gboolean success;
+
        gchar *sql;
-       GtkWidget *dialog;
 
        OrganigrammaUfficioAllegatoClass *klass = ORGANIGRAMMA_UFFICIO_ALLEGATO_GET_CLASS (organigramma_ufficio_allegato);
 
        OrganigrammaUfficioAllegatoPrivate *priv = ORGANIGRAMMA_UFFICIO_ALLEGATO_GET_PRIVATE (organigramma_ufficio_allegato);
 
-       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,
+                                                                          "ufficio_allegati",
+                                                                          "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_free (sql);
 
                        g_signal_emit (organigramma_ufficio_allegato, 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)
                                {
@@ -347,8 +362,6 @@ organigramma_ufficio_allegato_salva (OrganigrammaUfficioAllegato *organigramma_u
                }
        else
                {
-                       g_free (sql);
-
                        if (priv->id == 0)
                                {
                                        gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), "");
@@ -397,7 +410,7 @@ organigramma_ufficio_allegato_conferma_chiusura (OrganigrammaUfficioAllegato *or
        OrganigrammaUfficioAllegatoPrivate *priv = ORGANIGRAMMA_UFFICIO_ALLEGATO_GET_PRIVATE (organigramma_ufficio_allegato);
 
        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,