]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Migrazione a libzakform di persona. zakform
authorAndrea Zagli <azagli@libero.it>
Sat, 2 Dec 2017 11:13:32 +0000 (12:13 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 2 Dec 2017 11:13:32 +0000 (12:13 +0100)
data/organigramma/form/persona.form
data/organigramma/gui/organigramma.gui
src/persona.c

index 50999e314991bd0a3645431231c95c0bd2c04476..170afd2b42194c4939f9833f70239d704dea7b85 100644 (file)
@@ -1,77 +1,75 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>persone</table>
-
-       <widget type="label" name="label67" label="label68">
-               <field type="integer" name="id">
-                       <is-key>t</is-key>
-                       <auto-increment>t</auto-increment>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry14" label="label65">
-               <field type="text" name="nome" />
-       </widget>
-
-       <widget type="entry" name="entry17" label="label72">
-               <field type="text" name="cognome">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="decoder" name="gtkformdecoder24" label="label73">
-               <decoder>
-                       <sql>
-                               SELECT a.descrizione
-                               FROM titoli AS a
-                               WHERE a.id = ##key0::gint
-                       </sql>
-               </decoder>
-               <field type="integer" name="id_titoli">
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry20" label="label84">
-               <field type="datetime" name="data_nascita">
-                       <datetime-type>date</datetime-type>
-                       <display-format>%d/%m/%Y</display-format>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry26" label="label108">
-               <field type="text" name="indirizzo"/>
-       </widget>
-
-
-       <widget type="entry" name="entry27">
-               <field type="text" name="citta">
-                       <to-load>f</to-load>
-                       <to-save>f</to-save>
-               </field>
-       </widget>
-
-       <widget type="label" name="label110" label="label109">
-               <on-change what="update" when="after">
-                       <widget-name>entry27</widget-name>
-                       <connection-name>territorio</connection-name>
-                       <sql>
-                               SELECT c.nome FROM comuni AS c WHERE c.id = ##label110::gint
-                       </sql>
-               </on-change>
-               <field type="integer" name="id_citta">
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry29" label="label112">
-               <field type="text" name="cap"/>
-       </widget>
-
-       <widget type="entry" name="entry28" label="label111">
-               <field type="text" name="codice_fiscale"/>
-       </widget>
-       <widget type="textview" name="textview8" label="label66">
-               <field type="text" name="descrizione" />
-       </widget>
-
-</gtkform>
+<zakform>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id</name>
+    <type>integer</type>
+    <label>label68</label>
+    <is-key>TRUE</is-key>
+    <widget>label67</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>nome</name>
+    <type>string</type>
+    <label>label65</label>
+    <widget>entry14</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>cognome</name>
+    <type>string</type>
+    <label>label72</label>
+    <widget>entry17</widget>
+    <validator type="zak_form_element_validator_notempty"/>
+  </element>
+  <element type="">
+    <name>id_titoli</name>
+    <type>integer</type>
+    <label>label73</label>
+    <widget>gtkformdecoder24</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>data_nascita</name>
+    <type>datetime</type>
+    <label>label84</label>
+    <widget>entry20</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_entry">
+    <name>indirizzo</name>
+    <type>string</type>
+    <label>label108</label>
+    <widget>entry26</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>citta</name>
+    <type>string</type>
+    <to-load>FALSE</to-load>
+    <to-save>FALSE</to-save>
+    <widget>entry27</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id_citta</name>
+    <type>integer</type>
+    <label>label109</label>
+    <widget>label110</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>cap</name>
+    <type>string</type>
+    <label>label112</label>
+    <widget>entry29</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>codice_fiscale</name>
+    <type>string</type>
+    <label>label111</label>
+    <widget>entry28</widget>
+    <validator type="solipa_zak_form_element_validator_codfisc"/>
+  </element>
+  <element type="zak_form_gtk_form_element_textview">
+    <name>descrizione</name>
+    <type>string</type>
+    <label>label66</label>
+    <widget>textview8</widget>
+  </element>
+</zakform>
index 1424c81d02a18c7f12df7bb2fa847251ba348533..aff230653922940d90c885527b0856f18a8140a0 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
+<!-- Generated with glade 3.20.2 -->
 <interface>
   <requires lib="gtk+" version="3.16"/>
   <requires lib="gtkformui" version="0.0"/>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
+                <property name="max_length">16</property>
                 <property name="invisible_char">●</property>
                 <property name="primary_icon_activatable">False</property>
                 <property name="secondary_icon_activatable">False</property>
               </packing>
             </child>
             <child>
-              <object class="GtkFormDecoder" id="gtkformdecoder24">
+              <object class="ZakGtkDecoder" id="zakgtkdecoder17">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
               </object>
index 7f8965a5e75b2352681d4f5e41a57002fc307c32..c0da1123fda19f8bd765c73b653feb9417ab188a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2016 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2017 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 #endif
 
 #include <libzakautho/autho.h>
-#include <libgtkform/form.h>
-#include <libgtkform/fielddatetime.h>
-#include <libgtkformui/gtkformdecoder.h>
+#include <libzakgtkdecoder/libzakgtkdecoder.h>
+#include <libzakform/libzakform.h>
+#include <libzakformgtk/libzakformgtk.h>
+#include <libzakformgdaex/libzakformgdaex.h>
+#include <libzakformgtkdecoder/libzakformgtkdecoder.h>
 #include <libsolipa/utils.h>
 
 #include <libterritorio/comuni.h>
@@ -77,6 +79,7 @@ static void organigramma_persona_on_ufficio_recapito_aggiornato (gpointer instan
 static void organigramma_persona_on_recapito_aggiornato (gpointer instance, gpointer user_data);
 
 static void organigramma_persona_on_titolo_selezionato (gpointer instance, guint id, gpointer user_data);
+static gchar *organigramma_persona_on_titolo_decode (gpointer instance, gchar *key, gpointer user_data);
 static void organigramma_persona_on_comune_selezionato (gpointer instance, guint id, gpointer user_data);
 
 static gboolean organigramma_persona_on_w_organigramma_persona_delete_event (GtkWidget *widget,
@@ -230,7 +233,8 @@ struct _OrganigrammaPersonaPrivate
        {
                OrganigrammaCommons *commons;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *form_provider;
 
                GtkWidget *w;
 
@@ -316,14 +320,15 @@ OrganigrammaPersona
                        return NULL;
                }
 
-       priv->form = gtk_form_new ();
-       g_object_set (G_OBJECT (priv->form), "gdaex", priv->commons->gdaex, NULL);
-       gtk_form_add_db_connection_gdaex (priv->form, "territorio", commons->territorio_commons->gdaex);
-       gtk_form_load_from_file (priv->form, g_build_filename (priv->commons->formdir, "persona.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, "persona.form", NULL));
+
+       priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "persone");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_persona"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
+       priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form,
                                                      "label67",
                                                      "lstore_persona_incarichi",
                                                      "lstore_persona_nodi",
@@ -348,8 +353,11 @@ OrganigrammaPersona
        g_signal_connect (priv->sel_uffici,
                          "changed", G_CALLBACK (organigramma_persona_on_uffici_sel_changed), (gpointer)a);
 
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder24"),
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder17"),
                          "btn-browse-clicked", G_CALLBACK (organigramma_persona_on_btn_ricerca_titolo_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder17"),
+                         "decode", G_CALLBACK (organigramma_persona_on_titolo_decode), (gpointer)a);
+
        g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button89")),
                          "clicked", G_CALLBACK (organigramma_persona_on_btn_ricerca_comune_clicked), (gpointer)a);
 
@@ -414,7 +422,7 @@ OrganigrammaPersona
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button153"),
                          "clicked", G_CALLBACK (organigramma_persona_on_btn_salvaechiudi_clicked), (gpointer)a);
 
-       gtk_form_clear (priv->form);
+       zak_form_form_clear (ZAK_FORM_FORM (priv->form));
 
        priv->id = id;
 
@@ -422,9 +430,9 @@ OrganigrammaPersona
                {
                        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, "notebook1", NULL);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "notebook1")), FALSE);
                }
        else
                {
@@ -493,7 +501,7 @@ organigramma_persona_carica (OrganigrammaPersona *persona)
 {
        OrganigrammaPersonaPrivate *priv = ORGANIGRAMMA_PERSONA_GET_PRIVATE (persona);
 
-       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_persona_carica_incarichi (persona);
                        organigramma_persona_carica_nodi (persona);
@@ -507,46 +515,47 @@ organigramma_persona_carica (OrganigrammaPersona *persona)
 static void
 organigramma_persona_salva (OrganigrammaPersona *persona, gboolean chiudi)
 {
-       gchar *sql;
+       gboolean success;
 
        OrganigrammaPersonaClass *klass = ORGANIGRAMMA_PERSONA_GET_CLASS (persona);
 
        OrganigrammaPersonaPrivate *priv = ORGANIGRAMMA_PERSONA_GET_PRIVATE (persona);
 
-       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;
                }
 
-       if (!solipa_chk_codice_fiscale (gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (priv->commons->gtkbuilder, "entry28"))), TRUE))
-               {
-                       solipa_message_dialog (priv->w,
-                                              GTK_MESSAGE_WARNING,
-                                              GTK_BUTTONS_OK,
-                                              "Codice fiscale errato.");
-                       gtk_widget_grab_focus (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "entry28")));
-                       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,
+                                                                          "uffici",
+                                                                          "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 (persona, 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, "notebook1", NULL);
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "notebook1")), TRUE);
                                }
 
                        solipa_message_dialog (priv->w,
@@ -1125,7 +1134,7 @@ organigramma_persona_conferma_chiusura (OrganigrammaPersona *persona)
        OrganigrammaPersonaPrivate *priv = ORGANIGRAMMA_PERSONA_GET_PRIVATE (persona);
 
        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,
@@ -1140,6 +1149,42 @@ organigramma_persona_conferma_chiusura (OrganigrammaPersona *persona)
 }
 
 /* CALLBACK */
+static void
+organigramma_persona_on_titolo_selezionato (gpointer instance, guint id, gpointer user_data)
+{
+       OrganigrammaPersona *f = (OrganigrammaPersona *)user_data;
+       OrganigrammaPersonaPrivate *priv = ORGANIGRAMMA_PERSONA_GET_PRIVATE (f);
+
+       zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder17")),
+                                            g_strdup_printf ("%d", id));
+}
+
+static gchar
+*organigramma_persona_on_titolo_decode (gpointer instance, gchar *key, gpointer user_data)
+{
+       GString *ret;
+       gchar *sql;
+       GdaDataModel *dm;
+
+       OrganigrammaPersona *f = (OrganigrammaPersona *)user_data;
+       OrganigrammaPersonaPrivate *priv = ORGANIGRAMMA_PERSONA_GET_PRIVATE (f);
+
+       ret = g_string_new ("");
+
+       sql = g_strdup_printf ("SELECT descrizione"
+                                                  " FROM titoli"
+                                                  " WHERE id = %d",
+                                                  strtol (key, NULL, 10));
+       dm = gdaex_query (priv->commons->gdaex, sql);
+       g_free (sql);
+       if (!gdaex_data_model_is_empty (dm))
+               {
+                       g_string_append (ret, gdaex_data_model_get_value_stringify_at (dm, 0, 0));
+               }
+
+       return ret->str;
+}
+
 static void
 organigramma_persona_on_incarico_aggiornato (gpointer instance, gpointer user_data)
 {
@@ -1194,17 +1239,6 @@ organigramma_persona_on_recapito_aggiornato (gpointer instance, gpointer user_da
        organigramma_persona_carica_recapiti (persona);
 }
 
-static void
-organigramma_persona_on_titolo_selezionato (gpointer instance, guint id, gpointer user_data)
-{
-       OrganigrammaPersona *ia = (OrganigrammaPersona *)user_data;
-
-       OrganigrammaPersonaPrivate *priv = ORGANIGRAMMA_PERSONA_GET_PRIVATE (ia);
-
-       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "gtkformdecoder24"),
-                                            g_strdup_printf ("%d", id));
-}
-
 static void
 organigramma_persona_on_comune_selezionato (gpointer instance, guint id, gpointer user_data)
 {