]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Migrazione a libzakform di persona nodo.
authorAndrea Zagli <azagli@libero.it>
Wed, 14 Dec 2016 15:03:13 +0000 (16:03 +0100)
committerAndrea Zagli <azagli@libero.it>
Wed, 14 Dec 2016 15:03:13 +0000 (16:03 +0100)
data/organigramma/form/persona_nodo.form
data/organigramma/gui/organigramma.gui
src/personanodo.c

index 63f196e348ecbe363b482c171b52b72ca441f641..cfe574650b7d369695c5ad20741005c97044dd04 100644 (file)
@@ -1,50 +1,45 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>persona_nodi</table>
-
-       <widget type="label" name="label116">
-               <field type="integer" name="id">
-                       <is-key>t</is-key>
-                       <auto-increment>t</auto-increment>
-               </field>
-       </widget>
-
-       <widget type="label" name="label117">
-               <field type="integer" name="id_persone">
-               </field>
-       </widget>
-
-       <widget type="decoder" name="gtkformdecoder12" label="label114">
-               <decoder>
-                       <sql>
-                               SELECT a.nome
-                               FROM nodi AS a
-                               WHERE a.id = ##key0::gint
-                       </sql>
-               </decoder>
-               <field type="integer" name="id_nodi">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry31" label="label118">
-               <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="entry32" label="label119">
-               <field type="datetime" name="a_data">
-                       <datetime-type>date</datetime-type>
-                       <display-format>%d/%m/%Y</display-format>
-               </field>
-       </widget>
-
-       <widget type="textview" name="textview12" label="label113">
-               <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>label116</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id_persone</name>
+    <type>integer</type>
+    <widget>label117</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_decoder">
+    <name>id_nodi</name>
+    <type>integer</type>
+    <label>label114</label>
+    <widget>zakgtkdecoder15</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>label118</label>
+    <widget>entry31</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>label119</label>
+    <widget>entry32</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>label113</label>
+    <widget>textview12</widget>
+  </element>
+  <validator type="zak_form_validator_compare_date" type_comp="lt" element1="da_data" format1="%d/%m/%Y" element2="a_data" format2="%d/%m/%Y"></validator>
+</zakform>
index 1f30c99950b3c244145eeb181e95a4cb86f491ee..ca927dd3d28294adc7006a7620911a2d6388e82f 100644 (file)
               </packing>
             </child>
             <child>
-              <object class="GtkFormDecoder" id="gtkformdecoder12">
+              <object class="ZakGtkDecoder" id="zakgtkdecoder15">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
               </object>
index e340d4589faa9c3fa638ded7db2527b76175ba5b..4bd9b4d9aeef2219bed5cc2516aab64af2696ec2 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 "personanodo.h"
@@ -41,6 +44,7 @@ static gboolean organigramma_persona_nodo_conferma_chiusura (OrganigrammaPersona
 
 static void organigramma_persona_nodo_on_nodo_selezionato (gpointer instance,
                                           guint id, gpointer user_data);
+static gchar *organigramma_persona_nodo_on_nodo_decode (gpointer instance, gchar *key, gpointer user_data);
 
 static void organigramma_persona_nodo_set_property (GObject *object,
                                      guint property_id,
@@ -78,7 +82,8 @@ struct _OrganigrammaPersonaNodoPrivate
        {
                OrganigrammaCommons *commons;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *form_provider;
 
                GtkWidget *w;
 
@@ -152,13 +157,15 @@ OrganigrammaPersonaNodo
                        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_nodo.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_nodo.form", NULL));
+
+       priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "persona_nodi");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_persona_nodo"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
+       priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form,
                                                      "label116",
                                                      "label117",
                                                      NULL);
@@ -166,8 +173,10 @@ OrganigrammaPersonaNodo
        g_signal_connect (priv->w,
                          "delete-event", G_CALLBACK (organigramma_persona_nodo_on_w_organigramma_persona_nodo_delete_event), (gpointer)a);
 
-       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder12")),
+       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder15")),
                          "btn-browse-clicked", G_CALLBACK (organigramma_persona_nodo_on_btn_nodo_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder15"),
+                         "decode", G_CALLBACK (organigramma_persona_nodo_on_nodo_decode), (gpointer)a);
 
        g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button91")),
                          "clicked", G_CALLBACK (organigramma_persona_nodo_on_btn_annulla_clicked), (gpointer)a);
@@ -176,7 +185,7 @@ OrganigrammaPersonaNodo
        g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button159")),
                          "clicked", G_CALLBACK (organigramma_persona_nodo_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)
@@ -184,7 +193,7 @@ OrganigrammaPersonaNodo
                        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
                {
@@ -220,12 +229,9 @@ GtkWidget
 static void
 organigramma_persona_nodo_carica (OrganigrammaPersonaNodo *organigramma_persona_nodo)
 {
-       gchar *sql;
-       GdaDataModel *dm;
-
        OrganigrammaPersonaNodoPrivate *priv = ORGANIGRAMMA_PERSONA_NODO_GET_PRIVATE (organigramma_persona_nodo);
 
-       if (gtk_form_fill_from_table (priv->form))
+       if (zak_form_form_load (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider)))
                {
                }
 }
@@ -233,27 +239,38 @@ organigramma_persona_nodo_carica (OrganigrammaPersonaNodo *organigramma_persona_
 static void
 organigramma_persona_nodo_salva (OrganigrammaPersonaNodo *organigramma_persona_nodo, gboolean chiudi)
 {
-       gchar *sql;
+       gboolean success;
 
        OrganigrammaPersonaNodoClass *klass = ORGANIGRAMMA_PERSONA_NODO_GET_CLASS (organigramma_persona_nodo);
 
        OrganigrammaPersonaNodoPrivate *priv = ORGANIGRAMMA_PERSONA_NODO_GET_PRIVATE (organigramma_persona_nodo);
 
-       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_nodi",
+                                                                          "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_nodo, klass->aggiornato_signal_id, 0);
 
@@ -262,7 +279,7 @@ organigramma_persona_nodo_salva (OrganigrammaPersonaNodo *organigramma_persona_n
                                        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,
@@ -291,10 +308,36 @@ organigramma_persona_nodo_on_nodo_selezionato (gpointer instance, guint id, gpoi
 
        OrganigrammaPersonaNodoPrivate *priv = ORGANIGRAMMA_PERSONA_NODO_GET_PRIVATE (ia);
 
-       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "gtkformdecoder12"),
+       zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder15")),
                                             g_strdup_printf ("%d", id));
 }
 
+static gchar
+*organigramma_persona_nodo_on_nodo_decode (gpointer instance, gchar *key, gpointer user_data)
+{
+       GString *ret;
+       gchar *sql;
+       GdaDataModel *dm;
+
+       OrganigrammaPersonaNodo *f = (OrganigrammaPersonaNodo *)user_data;
+       OrganigrammaPersonaNodoPrivate *priv = ORGANIGRAMMA_PERSONA_NODO_GET_PRIVATE (f);
+
+       ret = g_string_new ("");
+
+       sql = g_strdup_printf ("SELECT nome"
+                                                  " FROM nodi"
+                                                  " 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_nodo_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
@@ -332,7 +375,7 @@ organigramma_persona_nodo_conferma_chiusura (OrganigrammaPersonaNodo *organigram
 
        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,