]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Migrazione a libzakform di ufficio nodo.
authorAndrea Zagli <azagli@libero.it>
Tue, 13 Dec 2016 10:45:25 +0000 (11:45 +0100)
committerAndrea Zagli <azagli@libero.it>
Tue, 13 Dec 2016 10:45:25 +0000 (11:45 +0100)
data/organigramma/form/ufficio_nodo.form
data/organigramma/gui/organigramma.gui
src/ufficionodo.c

index 44975541e9dd2f032f8457a739355650a72db0d7..28f9485b6382c67aa8513ef45fea82170e930f68 100644 (file)
@@ -1,34 +1,27 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>ufficio_nodi</table>
-
-       <widget type="label" name="label38">
-               <field type="integer" name="id">
-                       <is-key>t</is-key>
-                       <auto-increment>t</auto-increment>
-               </field>
-       </widget>
-
-       <widget type="label" name="label22">
-               <field type="integer" name="id_uffici">
-               </field>
-       </widget>
-
-       <widget type="decoder" name="gtkformdecoder14" label="label36">
-               <decoder>
-                       <sql>
-                               SELECT a.nome
-                               FROM nodi AS a
-                               WHERE a.id = ##key0::gint
-                       </sql>
-               </decoder>
-               <field type="integer" name="id_nodi">
-               </field>
-       </widget>
-
-       <widget type="textview" name="textview4" label="label35">
-               <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>label38</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id_uffici</name>
+    <type>integer</type>
+    <widget>label22</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_decoder">
+    <name>id_nodi</name>
+    <type>integer</type>
+    <label>label36</label>
+    <widget>zakgtkdecoder4</widget>
+    <validator type="zak_form_element_validator_notempty">0</validator>
+  </element>
+  <element type="zak_form_gtk_form_element_textview">
+    <name>note</name>
+    <type>string</type>
+    <label>label35</label>
+    <widget>textview4</widget>
+  </element>
+</zakform>
index f8d48eed1e40c0ef1da3926efbd275de009a346f..64b16950fe46bc9ee342203c2462b56fecfb57f4 100644 (file)
               </packing>
             </child>
             <child>
-              <object class="GtkFormDecoder" id="gtkformdecoder14">
+              <object class="ZakGtkDecoder" id="zakgtkdecoder4">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
               </object>
index 3e718631a526fcb6a33f368a22f2c42f5278ad7a..ccb2322f67e307be93aa2fb63254be95b63d1820 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 "ufficionodo.h"
@@ -38,6 +41,7 @@ static void organigramma_ufficio_nodo_carica (OrganigrammaUfficioNodo *organigra
 static void organigramma_ufficio_nodo_salva (OrganigrammaUfficioNodo *organigramma_ufficio_nodo, gboolean chiudi);
 
 static gboolean organigramma_ufficio_nodo_conferma_chiusura (OrganigrammaUfficioNodo *organigramma_ufficio_nodo);
+static gchar *organigramma_ufficio_nodo_on_nodo_decode (gpointer instance, gchar *key, gpointer user_data);
 
 static void organigramma_ufficio_nodo_set_property (GObject *object,
                                      guint property_id,
@@ -75,7 +79,8 @@ struct _OrganigrammaUfficioNodoPrivate
        {
                OrganigrammaCommons *commons;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *form_provider;
 
                GtkWidget *w;
 
@@ -149,13 +154,15 @@ OrganigrammaUfficioNodo
                        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, "ufficio_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, "ufficio_nodo.form", NULL));
+
+       priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "ufficio_nodi");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_ufficio_nodo"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
+       priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form,
                                                      "label38",
                                                      "label22",
                                                      NULL);
@@ -163,8 +170,10 @@ OrganigrammaUfficioNodo
        g_signal_connect (priv->w,
                          "delete-event", G_CALLBACK (organigramma_ufficio_nodo_on_w_organigramma_ufficio_nodo_delete_event), (gpointer)a);
 
-       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder14")),
+       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder4")),
                          "btn-browse-clicked", G_CALLBACK (organigramma_ufficio_nodo_on_btn_nodo_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder4"),
+                         "decode", G_CALLBACK (organigramma_ufficio_nodo_on_nodo_decode), (gpointer)a);
 
        g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button45")),
                          "clicked", G_CALLBACK (organigramma_ufficio_nodo_on_btn_annulla_clicked), (gpointer)a);
@@ -173,13 +182,15 @@ OrganigrammaUfficioNodo
        g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button154")),
                          "clicked", G_CALLBACK (organigramma_ufficio_nodo_on_btn_salvaechiudi_clicked), (gpointer)a);
 
+       zak_form_form_clear (ZAK_FORM_FORM (priv->form));
+
        priv->id = id;
        if (priv->id == 0)
                {
                        gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), "");
                        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
                {
@@ -215,12 +226,9 @@ GtkWidget
 static void
 organigramma_ufficio_nodo_carica (OrganigrammaUfficioNodo *organigramma_ufficio_nodo)
 {
-       gchar *sql;
-       GdaDataModel *dm;
-
        OrganigrammaUfficioNodoPrivate *priv = ORGANIGRAMMA_UFFICIO_NODO_GET_PRIVATE (organigramma_ufficio_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)))
                {
                }
 }
@@ -228,27 +236,38 @@ organigramma_ufficio_nodo_carica (OrganigrammaUfficioNodo *organigramma_ufficio_
 static void
 organigramma_ufficio_nodo_salva (OrganigrammaUfficioNodo *organigramma_ufficio_nodo, gboolean chiudi)
 {
-       gchar *sql;
+       gboolean success;
 
        OrganigrammaUfficioNodoClass *klass = ORGANIGRAMMA_UFFICIO_NODO_GET_CLASS (organigramma_ufficio_nodo);
 
        OrganigrammaUfficioNodoPrivate *priv = ORGANIGRAMMA_UFFICIO_NODO_GET_PRIVATE (organigramma_ufficio_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,
+                                                                          "ufficio_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_ufficio_nodo, klass->aggiornato_signal_id, 0);
 
@@ -257,7 +276,7 @@ organigramma_ufficio_nodo_salva (OrganigrammaUfficioNodo *organigramma_ufficio_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,
@@ -285,10 +304,36 @@ organigramma_ufficio_nodo_on_nodo_selezionato (gpointer instance, guint id, gpoi
        OrganigrammaUfficioNodo *ia = (OrganigrammaUfficioNodo *)user_data;
        OrganigrammaUfficioNodoPrivate *priv = ORGANIGRAMMA_UFFICIO_NODO_GET_PRIVATE (ia);
 
-       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "gtkformdecoder14"),
+       zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder4")),
                                             g_strdup_printf ("%d", id));
 }
 
+static gchar
+*organigramma_ufficio_nodo_on_nodo_decode (gpointer instance, gchar *key, gpointer user_data)
+{
+       GString *ret;
+       gchar *sql;
+       GdaDataModel *dm;
+
+       OrganigrammaUfficioNodo *f = (OrganigrammaUfficioNodo *)user_data;
+       OrganigrammaUfficioNodoPrivate *priv = ORGANIGRAMMA_UFFICIO_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_ufficio_nodo_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
@@ -326,7 +371,7 @@ organigramma_ufficio_nodo_conferma_chiusura (OrganigrammaUfficioNodo *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,