]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Migrazione a libzakform di persona ufficio.
authorAndrea Zagli <azagli@libero.it>
Tue, 13 Dec 2016 11:18:57 +0000 (12:18 +0100)
committerAndrea Zagli <azagli@libero.it>
Tue, 13 Dec 2016 11:18:57 +0000 (12:18 +0100)
data/organigramma/form/persona_ufficio.form
data/organigramma/gui/organigramma.gui
src/personaufficio.c

index b158e137f3fa0b775c4b442c9509b277259acc18..cdf001b8acd38ab6a3fef06086465b4c03075743 100644 (file)
@@ -1,67 +1,63 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>persona_uffici</table>
-
-       <widget type="label" name="label90">
-               <field type="integer" name="id">
-                       <is-key>t</is-key>
-                       <auto-increment>t</auto-increment>
-               </field>
-       </widget>
-
-       <widget type="label" name="label91">
-               <field type="integer" name="id_persone">
-               </field>
-       </widget>
-
-       <widget type="decoder" name="gtkformdecoder13" label="label88">
-               <decoder>
-                       <sql>
-                               SELECT nome FROM uffici WHERE id = ##key0::gint
-                       </sql>
-               </decoder>
-               <field type="integer" name="id_uffici">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="decoder" name="gtkformdecoder1" label="label177">
-               <decoder>
-                       <sql>
-                               SELECT nome FROM ruoli WHERE id = ##key0::gint
-                       </sql>
-               </decoder>
-               <field type="integer" name="id_ruoli">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry22" label="label92">
-               <field type="datetime" name="da_data">
-                       <datetime-type>date</datetime-type>
-                       <display-format>%d/%m/%Y</display-format>
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry23" label="label93">
-               <field type="datetime" name="a_data">
-                       <datetime-type>date</datetime-type>
-                       <display-format>%d/%m/%Y</display-format>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry46" label="label167">
-               <field type="text" name="piano"/>
-       </widget>
-
-       <widget type="entry" name="entry47" label="label168">
-               <field type="text" name="stanza"/>
-       </widget>
-
-       <widget type="textview" name="textview9" label="label87">
-               <field type="text" name="note" />
-       </widget>
-
-</gtkform>
+<zakform>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id</name>
+    <type>integer</type>
+    <is-key>TRUE</is-key>
+    <widget>label90</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id_persone</name>
+    <type>integer</type>
+    <widget>label91</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_decoder">
+    <name>id_uffici</name>
+    <type>integer</type>
+    <label>label88</label>
+    <widget>zakgtkdecoder7</widget>
+    <validator type="zak_form_element_validator_notempty">0</validator>
+  </element>
+  <element type="zak_form_gtk_form_element_decoder">
+    <name>id_ruoli</name>
+    <type>integer</type>
+    <label>label177</label>
+    <widget>zakgtkdecoder8</widget>
+    <validator type="zak_form_element_validator_notempty">0</validator>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>da_data</name>
+    <type>datetime</type>
+    <label>label92</label>
+    <widget>entry22</widget>
+    <format>%d/%m/%Y</format>
+    <validator type="zak_form_element_validator_notempty"/>
+    <validator type="zak_form_element_validator_date">%d/%m/%Y</validator>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>a_data</name>
+    <type>datetime</type>
+    <label>label93</label>
+    <widget>entry23</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>piano</name>
+    <type>string</type>
+    <label>label167</label>
+    <widget>entry46</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>stanza</name>
+    <type>string</type>
+    <label>label168</label>
+    <widget>entry47</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_textview">
+    <name>note</name>
+    <type>string</type>
+    <label>label87</label>
+    <widget>textview9</widget>
+  </element>
+</zakform>
index 2fe2871998fb60efdbdcfcb41c7cde3307cf313d..09dbf7c2cd6916b07b48542e2f7fecb3da7bac03 100644 (file)
                 <property name="top_attach">5</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkFormDecoder" id="gtkformdecoder1">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="hexpand">True</property>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="top_attach">1</property>
-              </packing>
-            </child>
             <child>
               <object class="GtkLabel" id="label177">
                 <property name="visible">True</property>
               </packing>
             </child>
             <child>
-              <object class="GtkFormDecoder" id="gtkformdecoder13">
+              <object class="ZakGtkDecoder" id="zakgtkdecoder7">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="hexpand">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="top_attach">0</property>
               </packing>
             </child>
+            <child>
+              <object class="ZakGtkDecoder" id="zakgtkdecoder8">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">True</property>
index 2ca76165e6d2524aee84047d1990d670c1030aa4..d3d9e22a86dfef16b6c5a7f75e0ee03f5de2f270 100644 (file)
 #include <glib/gprintf.h>
 
 #include <libzakautho/autoz.h>
-#include <libgtkform/form.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 "personaufficio.h"
@@ -43,6 +46,8 @@ static gboolean organigramma_persona_ufficio_conferma_chiusura (OrganigrammaPers
 static void organigramma_persona_ufficio_on_ufficio_selezionato (gpointer instance,
                                           guint id, gpointer user_data);
 static void organigramma_persona_ufficio_on_ruolo_selezionato (gpointer instance, guint id, gpointer user_data);
+static gchar *organigramma_persona_ufficio_on_ufficio_decode (gpointer instance, gchar *key, gpointer user_data);
+static gchar *organigramma_persona_ufficio_on_ruolo_decode (gpointer instance, gchar *key, gpointer user_data);
 
 static void organigramma_persona_ufficio_set_property (GObject *object,
                                      guint property_id,
@@ -83,7 +88,8 @@ struct _OrganigrammaPersonaUfficioPrivate
        {
                OrganigrammaCommons *commons;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *form_provider;
 
                GtkWidget *w;
 
@@ -157,13 +163,15 @@ OrganigrammaPersonaUfficio
                        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, "persona_ufficio.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_ufficio.form", NULL));
+
+       priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "persona_uffici");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_persona_ufficio"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
+       priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form,
                                                      "label90",
                                                      "label91",
                                                      NULL);
@@ -171,11 +179,14 @@ OrganigrammaPersonaUfficio
        g_signal_connect (priv->w,
                          "delete-event", G_CALLBACK (organigramma_persona_ufficio_on_w_organigramma_persona_ufficio_delete_event), (gpointer)a);
 
-       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder13")),
+       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder7")),
                          "btn-browse-clicked", G_CALLBACK (organigramma_persona_ufficio_on_btn_ufficio_clicked), (gpointer)a);
-
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder1"),
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder8"),
                          "btn-browse-clicked", G_CALLBACK (organigramma_persona_ufficio_on_btn_ruolo_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder7"),
+                         "decode", G_CALLBACK (organigramma_persona_ufficio_on_ufficio_decode), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder8"),
+                         "decode", G_CALLBACK (organigramma_persona_ufficio_on_ruolo_decode), (gpointer)a);
 
        g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button83")),
                          "clicked", G_CALLBACK (organigramma_persona_ufficio_on_btn_annulla_clicked), (gpointer)a);
@@ -184,7 +195,7 @@ OrganigrammaPersonaUfficio
        g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button161")),
                          "clicked", G_CALLBACK (organigramma_persona_ufficio_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)
@@ -192,7 +203,7 @@ OrganigrammaPersonaUfficio
                        gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), "");
                        gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID_PERSONE]), g_strdup_printf ("%d", id_persone));
 
-                       gtk_form_set_as_origin (priv->form);
+                       zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form));
                }
        else
                {
@@ -228,12 +239,9 @@ GtkWidget
 static void
 organigramma_persona_ufficio_carica (OrganigrammaPersonaUfficio *organigramma_persona_ufficio)
 {
-       gchar *sql;
-       GdaDataModel *dm;
-
        OrganigrammaPersonaUfficioPrivate *priv = ORGANIGRAMMA_PERSONA_UFFICIO_GET_PRIVATE (organigramma_persona_ufficio);
 
-       if (gtk_form_fill_from_table (priv->form))
+       if (zak_form_form_load (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider)))
                {
                }
 }
@@ -241,27 +249,38 @@ organigramma_persona_ufficio_carica (OrganigrammaPersonaUfficio *organigramma_pe
 static void
 organigramma_persona_ufficio_salva (OrganigrammaPersonaUfficio *organigramma_persona_ufficio, gboolean chiudi)
 {
-       gchar *sql;
+       gboolean success;
 
        OrganigrammaPersonaUfficioClass *klass = ORGANIGRAMMA_PERSONA_UFFICIO_GET_CLASS (organigramma_persona_ufficio);
 
        OrganigrammaPersonaUfficioPrivate *priv = ORGANIGRAMMA_PERSONA_UFFICIO_GET_PRIVATE (organigramma_persona_ufficio);
 
-       if (!gtk_form_check (priv->form, FALSE, 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,
+                                                                          "persona_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 (organigramma_persona_ufficio, klass->aggiornato_signal_id, 0);
 
@@ -270,7 +289,7 @@ organigramma_persona_ufficio_salva (OrganigrammaPersonaUfficio *organigramma_per
                                        priv->id = strtol (gtk_label_get_text (GTK_LABEL (priv->objects[LBL_ID])), NULL, 10);
                                }
 
-                       gtk_form_set_as_origin (priv->form);
+                       zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form));
 
                        solipa_message_dialog (priv->w,
                                               GTK_MESSAGE_INFO,
@@ -329,7 +348,7 @@ organigramma_persona_ufficio_conferma_chiusura (OrganigrammaPersonaUfficio *orga
 
        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,
@@ -359,7 +378,7 @@ organigramma_persona_ufficio_on_ufficio_selezionato (gpointer instance, guint id
 
        OrganigrammaPersonaUfficioPrivate *priv = ORGANIGRAMMA_PERSONA_UFFICIO_GET_PRIVATE (ia);
 
-       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "gtkformdecoder13"),
+       zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder7")),
                                             g_strdup_printf ("%d", id));
 }
 
@@ -369,10 +388,62 @@ organigramma_persona_ufficio_on_ruolo_selezionato (gpointer instance, guint id,
        OrganigrammaPersonaUfficio *a = (OrganigrammaPersonaUfficio *)user_data;
        OrganigrammaPersonaUfficioPrivate *priv = ORGANIGRAMMA_PERSONA_UFFICIO_GET_PRIVATE (a);
 
-       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "gtkformdecoder1"),
+       zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder8")),
                                             g_strdup_printf ("%d", id));
 }
 
+static gchar
+*organigramma_persona_ufficio_on_ufficio_decode (gpointer instance, gchar *key, gpointer user_data)
+{
+       GString *ret;
+       gchar *sql;
+       GdaDataModel *dm;
+
+       OrganigrammaPersonaUfficio *f = (OrganigrammaPersonaUfficio *)user_data;
+       OrganigrammaPersonaUfficioPrivate *priv = ORGANIGRAMMA_PERSONA_UFFICIO_GET_PRIVATE (f);
+
+       ret = g_string_new ("");
+
+       sql = g_strdup_printf ("SELECT nome"
+                                                  " FROM uffici"
+                                                  " 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 gchar
+*organigramma_persona_ufficio_on_ruolo_decode (gpointer instance, gchar *key, gpointer user_data)
+{
+       GString *ret;
+       gchar *sql;
+       GdaDataModel *dm;
+
+       OrganigrammaPersonaUfficio *f = (OrganigrammaPersonaUfficio *)user_data;
+       OrganigrammaPersonaUfficioPrivate *priv = ORGANIGRAMMA_PERSONA_UFFICIO_GET_PRIVATE (f);
+
+       ret = g_string_new ("");
+
+       sql = g_strdup_printf ("SELECT nome"
+                                                  " FROM ruoli"
+                                                  " 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_ufficio_on_btn_ufficio_clicked (GtkButton *button,
                                     gpointer user_data)