]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Migrazione a libzakform di persona ufficio recapito.
authorAndrea Zagli <azagli@libero.it>
Tue, 13 Dec 2016 09:53:42 +0000 (10:53 +0100)
committerAndrea Zagli <azagli@libero.it>
Tue, 13 Dec 2016 09:53:46 +0000 (10:53 +0100)
data/organigramma/form/persona_ufficio_recapito.form
data/organigramma/gui/organigramma.gui
src/personaufficiorecapito.c

index add324626792c61ce5df8ffcdcb64a5332601a5a..0ff5444a0012ccca1571f3f1d0329f1b2670cab4 100644 (file)
@@ -1,51 +1,45 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>persona_ufficio_recapiti</table>
-
-       <widget type="label" name="label96">
-               <field type="integer" name="id">
-                       <is-key>t</is-key>
-                       <auto-increment>t</auto-increment>
-               </field>
-       </widget>
-
-       <widget type="label" name="label100">
-               <field type="integer" name="id_persone">
-               </field>
-       </widget>
-
-       <widget type="label" name="label97">
-               <field type="integer" name="id_uffici">
-               </field>
-       </widget>
-
-       <widget type="decoder" name="gtkformdecoder8" label="label95">
-               <decoder>
-                       <sql>
-                               SELECT a.nome
-                               FROM tipi_recapito AS a
-                               WHERE a.id = ##key0::gint
-                       </sql>
-               </decoder>
-               <field type="integer" name="id_tipi_recapito">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry24" label="label98">
-               <field type="text" name="recapito">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="textview" name="textview10" label="label94">
-               <field type="text" name="note" />
-       </widget>
-
-       <widget type="checkbox" name="checkbutton9" label="label99">
-               <field type="boolean" name="privato">
-               </field>
-       </widget>
-
-</gtkform>
+<zakform>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id</name>
+    <type>integer</type>
+    <is-key>TRUE</is-key>
+    <widget>label96</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id_persone</name>
+    <type>integer</type>
+    <widget>label100</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id_uffici</name>
+    <type>integer</type>
+    <widget>label97</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_decoder">
+    <name>id_tipi_recapito</name>
+    <type>integer</type>
+    <label>label95</label>
+    <widget>zakgtkdecoder2</widget>
+    <validator type="zak_form_element_validator_notempty">0</validator>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>recapito</name>
+    <type>string</type>
+    <label>label98</label>
+    <widget>entry24</widget>
+    <validator type="zak_form_element_validator_notempty"/>
+  </element>
+  <element type="zak_form_gtk_form_element_textview">
+    <name>note</name>
+    <type>string</type>
+    <label>label94</label>
+    <widget>textview10</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_check">
+    <name>privato</name>
+    <type>boolean</type>
+    <label>label99</label>
+    <widget>checkbutton9</widget>
+  </element>
+</zakform>
index 165cc601e04235812711257e3882ced064298c8c..3965eeaccd1ec63bbb89c616589b66a7d1094136 100644 (file)
               </packing>
             </child>
             <child>
-              <object class="GtkFormDecoder" id="gtkformdecoder8">
+              <object class="ZakGtkDecoder" id="zakgtkdecoder2">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
               </object>
index 63bbc11822c1d66a091f3390f5240db5d9eb98d0..20281595240b9287404a63ed05f0faad530c0834 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 "personaufficiorecapito.h"
@@ -38,6 +41,7 @@ static void organigramma_persona_ufficio_recapito_carica (OrganigrammaPersonaUff
 static void organigramma_persona_ufficio_recapito_salva (OrganigrammaPersonaUfficioRecapito *organigramma_persona_ufficio_recapito, gboolean chiudi);
 
 static gboolean organigramma_persona_ufficio_recapito_conferma_chiusura (OrganigrammaPersonaUfficioRecapito *organigramma_persona_ufficio_recapito);
+static gchar *organigramma_persona_ufficio_recapito_on_tipo_recapito_decode (gpointer instance, gchar *key, gpointer user_data);
 
 static void organigramma_persona_ufficio_recapito_on_tipo_recapito_selezionato (gpointer instance, guint id, gpointer user_data);
 
@@ -79,7 +83,8 @@ struct _OrganigrammaPersonaUfficioRecapitoPrivate
        {
                OrganigrammaCommons *commons;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *form_provider;
 
                GtkWidget *w;
 
@@ -154,13 +159,15 @@ OrganigrammaPersonaUfficioRecapito
                        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_recapito.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_recapito.form", NULL));
+
+       priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "persona_ufficio_recapiti");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_persona_ufficio_recapito"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
+       priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form,
                                                      "label96",
                                                      "label100",
                                                      "label97",
@@ -169,8 +176,10 @@ OrganigrammaPersonaUfficioRecapito
        g_signal_connect (priv->w,
                          "delete-event", G_CALLBACK (organigramma_persona_ufficio_recapito_on_w_organigramma_persona_ufficio_recapito_delete_event), (gpointer)a);
 
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder8"),
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder2"),
                          "btn-browse-clicked", G_CALLBACK (organigramma_persona_ufficio_recapito_on_btn_tipo_recapito_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder2"),
+                         "decode", G_CALLBACK (organigramma_persona_ufficio_recapito_on_tipo_recapito_decode), (gpointer)a);
 
        g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button85")),
                          "clicked", G_CALLBACK (organigramma_persona_ufficio_recapito_on_btn_annulla_clicked), (gpointer)a);
@@ -179,6 +188,8 @@ OrganigrammaPersonaUfficioRecapito
        g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button162")),
                          "clicked", G_CALLBACK (organigramma_persona_ufficio_recapito_on_btn_salvaechiudi_clicked), (gpointer)a);
 
+       zak_form_form_clear (ZAK_FORM_FORM (priv->form));
+
        priv->id = id;
        if (priv->id == 0)
                {
@@ -186,7 +197,7 @@ OrganigrammaPersonaUfficioRecapito
                        gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID_PERSONE]), g_strdup_printf ("%d", id_persone));
                        gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID_UFFICI]), g_strdup_printf ("%d", id_uffici));
 
-                       gtk_form_set_as_origin (priv->form);
+                       zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form));
                }
        else
                {
@@ -222,12 +233,9 @@ GtkWidget
 static void
 organigramma_persona_ufficio_recapito_carica (OrganigrammaPersonaUfficioRecapito *organigramma_persona_ufficio_recapito)
 {
-       gchar *sql;
-       GdaDataModel *dm;
-
        OrganigrammaPersonaUfficioRecapitoPrivate *priv = ORGANIGRAMMA_PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (organigramma_persona_ufficio_recapito);
 
-       if (gtk_form_fill_from_table (priv->form))
+       if (zak_form_form_load (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider)))
                {
                }
 }
@@ -235,27 +243,38 @@ organigramma_persona_ufficio_recapito_carica (OrganigrammaPersonaUfficioRecapito
 static void
 organigramma_persona_ufficio_recapito_salva (OrganigrammaPersonaUfficioRecapito *organigramma_persona_ufficio_recapito, gboolean chiudi)
 {
-       gchar *sql;
+       gboolean success;
 
        OrganigrammaPersonaUfficioRecapitoClass *klass = ORGANIGRAMMA_PERSONA_UFFICIO_RECAPITO_GET_CLASS (organigramma_persona_ufficio_recapito);
 
        OrganigrammaPersonaUfficioRecapitoPrivate *priv = ORGANIGRAMMA_PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (organigramma_persona_ufficio_recapito);
 
-       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_ufficio_recapiti",
+                                                                          "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_recapito, klass->aggiornato_signal_id, 0);
 
@@ -264,7 +283,7 @@ organigramma_persona_ufficio_recapito_salva (OrganigrammaPersonaUfficioRecapito
                                        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,
@@ -323,7 +342,7 @@ organigramma_persona_ufficio_recapito_conferma_chiusura (OrganigrammaPersonaUffi
 
        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,
@@ -344,10 +363,36 @@ organigramma_persona_ufficio_recapito_on_tipo_recapito_selezionato (gpointer ins
        OrganigrammaPersonaUfficioRecapito *f = (OrganigrammaPersonaUfficioRecapito *)user_data;
        OrganigrammaPersonaUfficioRecapitoPrivate *priv = ORGANIGRAMMA_PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (f);
 
-       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "gtkformdecoder8"),
+       zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder2")),
                                             g_strdup_printf ("%d", id));
 }
 
+static gchar
+*organigramma_persona_ufficio_recapito_on_tipo_recapito_decode (gpointer instance, gchar *key, gpointer user_data)
+{
+       GString *ret;
+       gchar *sql;
+       GdaDataModel *dm;
+
+       OrganigrammaPersonaUfficioRecapito *f = (OrganigrammaPersonaUfficioRecapito *)user_data;
+       OrganigrammaPersonaUfficioRecapitoPrivate *priv = ORGANIGRAMMA_PERSONA_UFFICIO_RECAPITO_GET_PRIVATE (f);
+
+       ret = g_string_new ("");
+
+       sql = g_strdup_printf ("SELECT nome"
+                                                  " FROM tipi_recapito"
+                                                  " 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 gboolean
 organigramma_persona_ufficio_recapito_on_w_organigramma_persona_ufficio_recapito_delete_event (GtkWidget *widget,
                                GdkEvent *event,