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

index ecec565532d5406ebf9a7aad3bb71e06bb21e758..3b0d2808d366105677ecf707f969b4b5ed061534 100644 (file)
@@ -1,47 +1,36 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>nodi</table>
-
-       <widget type="label" name="label6" label="label10">
-               <field type="integer" name="id">
-                       <is-key>t</is-key>
-                       <auto-increment>t</auto-increment>
-               </field>
-       </widget>
-
-       <widget type="decoder" name="gtkformdecoder11" label="label4">
-               <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="decoder" name="gtkformdecoder6" label="label1">
-               <decoder>
-                       <sql>
-                               SELECT a.nome
-                               FROM tipi_nodo AS a
-                               WHERE a.id = ##key0::gint
-                       </sql>
-               </decoder>
-               <field type="integer" name="id_tipi_nodo">
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry1" label="label2">
-               <field type="text" name="nome">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="textview" name="textview1" label="label3">
-               <field type="text" name="descrizione" />
-       </widget>
-
-</gtkform>
+<zakform>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id</name>
+    <type>integer</type>
+    <label>label10</label>
+    <is-key>TRUE</is-key>
+    <widget>label6</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_decoder">
+    <name>id_nodi</name>
+    <type>integer</type>
+    <label>label4</label>
+    <widget>zakgtkdecoder5</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_decoder">
+    <name>id_tipi_nodo</name>
+    <type>integer</type>
+    <label>label1</label>
+    <widget>zakgtkdecoder6</widget>
+    <validator type="zak_form_element_validator_notempty">0</validator>
+  </element>
+  <element type="zak_form_gtk_form_element_entry">
+    <name>nome</name>
+    <type>string</type>
+    <label>label2</label>
+    <widget>entry1</widget>
+    <validator type="zak_form_element_validator_notempty"/>
+  </element>
+  <element type="zak_form_gtk_form_element_textview">
+    <name>descrizione</name>
+    <type>string</type>
+    <label>label3</label>
+    <widget>textview1</widget>
+  </element>
+</zakform>
index 64b16950fe46bc9ee342203c2462b56fecfb57f4..2fe2871998fb60efdbdcfcb41c7cde3307cf313d 100644 (file)
               </packing>
             </child>
             <child>
-              <object class="GtkFormDecoder" id="gtkformdecoder6">
+              <object class="ZakGtkDecoder" id="zakgtkdecoder5">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="show_btn_clean">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="top_attach">2</property>
+                <property name="top_attach">1</property>
               </packing>
             </child>
             <child>
-              <object class="GtkFormDecoder" id="gtkformdecoder11">
+              <object class="ZakGtkDecoder" id="zakgtkdecoder6">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="show_btn_clean">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="top_attach">1</property>
+                <property name="top_attach">2</property>
               </packing>
             </child>
           </object>
index 14cb14e935e3c345becf85beda0eca666437bb4f..d5230348e1ddf55cb26e4c8298e101c844db3c0f 100644 (file)
 #endif
 
 #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 "nodo.h"
@@ -49,6 +52,8 @@ static void organigramma_nodo_get_property (GObject *object,
 
 static void organigramma_nodo_on_organigramma_nodo_selezionato (gpointer instance, guint id, gpointer user_data);
 static void organigramma_nodo_on_tipo_nodo_selezionato (gpointer instance, guint id, gpointer user_data);
+static gchar *organigramma_nodo_on_nodo_decode (gpointer instance, gchar *key, gpointer user_data);
+static gchar *organigramma_nodo_on_tipo_nodo_decode (gpointer instance, gchar *key, gpointer user_data);
 
 static void organigramma_nodo_on_btn_organigramma_nodo_clicked (GtkButton *button,
                       gpointer user_data);
@@ -78,7 +83,8 @@ struct _OrganigrammaNodoPrivate
        {
                OrganigrammaCommons *commons;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *form_provider;
 
                GtkWidget *w;
 
@@ -150,25 +156,29 @@ OrganigrammaNodo
                        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, "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, "nodo.form", NULL));
 
-       g_object_set (priv->form, "gdaex", priv->commons->gdaex, NULL);
+       priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "nodi");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_nodo"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
+       priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form,
                                                      "label6",
                                                      NULL);
 
        g_signal_connect (priv->w,
                          "delete-event", G_CALLBACK (organigramma_nodo_on_w_organigramma_nodo_delete_event), (gpointer)a);
 
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder11"),
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder5"),
                          "btn-browse-clicked", G_CALLBACK (organigramma_nodo_on_btn_organigramma_nodo_clicked), (gpointer)a);
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder6"),
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder6"),
                          "btn-browse-clicked", G_CALLBACK (organigramma_nodo_on_btn_tipo_nodo_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder5"),
+                         "decode", G_CALLBACK (organigramma_nodo_on_nodo_decode), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder6"),
+                         "decode", G_CALLBACK (organigramma_nodo_on_tipo_nodo_decode), (gpointer)a);
 
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button4"),
                          "clicked", G_CALLBACK (organigramma_nodo_on_btn_annulla_clicked), (gpointer)a);
@@ -177,15 +187,14 @@ OrganigrammaNodo
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button152"),
                          "clicked", G_CALLBACK (organigramma_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)
                {
                        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));
                }
        else
                {
@@ -222,7 +231,7 @@ organigramma_nodo_carica (OrganigrammaNodo *nodo)
 {
        OrganigrammaNodoPrivate *priv = ORGANIGRAMMA_NODO_GET_PRIVATE (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)))
                {
                }
 }
@@ -230,31 +239,42 @@ organigramma_nodo_carica (OrganigrammaNodo *nodo)
 static void
 organigramma_nodo_salva (OrganigrammaNodo *nodo, gboolean chiudi)
 {
-       gchar *sql;
+       gboolean success;
 
        OrganigrammaNodoClass *klass = ORGANIGRAMMA_NODO_GET_CLASS (nodo);
 
        OrganigrammaNodoPrivate *priv = ORGANIGRAMMA_NODO_GET_PRIVATE (nodo);
 
-       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;
                }
 
+       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,
+                                                                          "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 (nodo, 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)
                                {
@@ -322,7 +342,7 @@ organigramma_nodo_conferma_chiusura (OrganigrammaNodo *nodo)
        OrganigrammaNodoPrivate *priv = ORGANIGRAMMA_NODO_GET_PRIVATE (nodo);
 
        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,
@@ -343,7 +363,7 @@ organigramma_nodo_on_organigramma_nodo_selezionato (gpointer instance, guint id,
        OrganigrammaNodo *f = (OrganigrammaNodo *)user_data;
        OrganigrammaNodoPrivate *priv = ORGANIGRAMMA_NODO_GET_PRIVATE (f);
 
-       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "gtkformdecoder11"),
+       zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder5")),
                                             g_strdup_printf ("%d", id));
 }
 
@@ -353,10 +373,62 @@ organigramma_nodo_on_tipo_nodo_selezionato (gpointer instance, guint id, gpointe
        OrganigrammaNodo *f = (OrganigrammaNodo *)user_data;
        OrganigrammaNodoPrivate *priv = ORGANIGRAMMA_NODO_GET_PRIVATE (f);
 
-       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "gtkformdecoder6"),
+       zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder6")),
                                             g_strdup_printf ("%d", id));
 }
 
+static gchar
+*organigramma_nodo_on_nodo_decode (gpointer instance, gchar *key, gpointer user_data)
+{
+       GString *ret;
+       gchar *sql;
+       GdaDataModel *dm;
+
+       OrganigrammaNodo *f = (OrganigrammaNodo *)user_data;
+       OrganigrammaNodoPrivate *priv = ORGANIGRAMMA_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 gchar
+*organigramma_nodo_on_tipo_nodo_decode (gpointer instance, gchar *key, gpointer user_data)
+{
+       GString *ret;
+       gchar *sql;
+       GdaDataModel *dm;
+
+       OrganigrammaNodo *f = (OrganigrammaNodo *)user_data;
+       OrganigrammaNodoPrivate *priv = ORGANIGRAMMA_NODO_GET_PRIVATE (f);
+
+       ret = g_string_new ("");
+
+       sql = g_strdup_printf ("SELECT nome"
+                                                  " FROM tipi_nodo"
+                                                  " 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_nodo_on_btn_organigramma_nodo_clicked (GtkButton *button,
                       gpointer user_data)