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

index 1dfa967fd8fa8ae8a32459599159bcbb5e35ef3e..8e3382b5a6c4d9106af861fa2f065b4a39b7b4c6 100644 (file)
@@ -1,47 +1,36 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>uffici</table>
-
-       <widget type="label" name="label23" label="label24">
-               <field type="integer" name="id">
-                       <is-key>t</is-key>
-                       <auto-increment>t</auto-increment>
-               </field>
-       </widget>
-
-       <widget type="decoder" name="gtkformdecoder16" label="label170">
-               <decoder>
-                       <sql>
-                               SELECT a.nome
-                               FROM uffici AS a
-                               WHERE a.id = ##key0::gint
-                       </sql>
-               </decoder>
-               <field type="integer" name="id_uffici">
-               </field>
-       </widget>
-
-       <widget type="decoder" name="gtkformdecoder15" label="label18">
-               <decoder>
-                       <sql>
-                               SELECT a.nome
-                               FROM strutture AS a
-                               WHERE a.id = ##key0::gint
-                       </sql>
-               </decoder>
-               <field type="integer" name="id_strutture">
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry5" label="label19">
-               <field type="text" name="nome">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="textview" name="textview2" label="label20">
-               <field type="text" name="descrizione" />
-       </widget>
-
-</gtkform>
+<zakform>
+  <element type="zak_form_gtk_form_element_label">
+    <name>id</name>
+    <type>integer</type>
+    <label>label24</label>
+    <is-key>TRUE</is-key>
+    <widget>label23</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_decoder">
+    <name>id_uffici</name>
+    <type>integer</type>
+    <label>label170</label>
+    <widget>zakgtkdecoder9</widget>
+  </element>
+  <element type="zak_form_gtk_form_element_decoder">
+    <name>id_strutture</name>
+    <type>integer</type>
+    <label>label18</label>
+    <widget>zakgtkdecoder10</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>label19</label>
+    <widget>entry5</widget>
+    <validator type="zak_form_element_validator_notempty"/>
+  </element>
+  <element type="zak_form_gtk_form_element_textview">
+    <name>descrizione</name>
+    <type>string</type>
+    <label>label20</label>
+    <widget>textview2</widget>
+  </element>
+</zakform>
index 09dbf7c2cd6916b07b48542e2f7fecb3da7bac03..d9e9d50671c82175667f65eff9853e7e0b955d0f 100644 (file)
               </packing>
             </child>
             <child>
-              <object class="GtkFormDecoder" id="gtkformdecoder15">
+              <object class="ZakGtkDecoder" id="zakgtkdecoder9">
                 <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">3</property>
+                <property name="top_attach">2</property>
               </packing>
             </child>
             <child>
-              <object class="GtkFormDecoder" id="gtkformdecoder16">
+              <object class="ZakGtkDecoder" id="zakgtkdecoder10">
                 <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">3</property>
               </packing>
             </child>
           </object>
index e31ca964bff04b19d95d1d44095c0a09b406639d..dcc84dcea613de799ac07fa04cae21ca74920eb6 100644 (file)
 #include <libpq-fe.h>
 
 #include <libzakautho/autoz.h>
-#include <libgtkform/form.h>
-#include <libgtkform/fielddatetime.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 <libzakutils/libzakutils.h>
 
 #include "ufficio.h"
 #include "uffici.h"
@@ -80,11 +83,9 @@ static void organigramma_ufficio_on_allegato_aggiornato (gpointer instance, gpoi
 
 static void organigramma_ufficio_on_ufficio_selezionato (gpointer instance, guint id, gpointer user_data);
 static void organigramma_ufficio_on_struttura_selezionato (gpointer instance, guint id, gpointer user_data);
+static gchar *organigramma_ufficio_on_ufficio_decode (gpointer instance, gchar *key, gpointer user_data);
+static gchar *organigramma_ufficio_on_struttura_decode (gpointer instance, gchar *key, gpointer user_data);
 
-static void organigramma_ufficio_on_ufficio_pulisci (GtkEntry *entry,
-                          GtkEntryIconPosition icon_pos,
-                          GdkEvent *event,
-                          gpointer user_data);
 static void organigramma_ufficio_on_btn_ufficio_clicked (GtkButton *button,
                       gpointer user_data);
 static void organigramma_ufficio_on_btn_struttura_clicked (GtkButton *button,
@@ -252,7 +253,8 @@ struct _OrganigrammaUfficioPrivate
        {
                OrganigrammaCommons *commons;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *form_provider;
 
                GtkWidget *w;
 
@@ -343,13 +345,15 @@ OrganigrammaUfficio
                        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.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.form", NULL));
+
+       priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "uffici");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_ufficio"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
+       priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form,
                                                      "label23",
                                                      "lstore_ufficio_nodi",
                                                      "lstore_ufficio_stanze",
@@ -363,7 +367,7 @@ OrganigrammaUfficio
        priv->sallegato = solipa_allegato_new (commons->solipa);
        if (priv->sallegato != NULL)
                {
-                       solipa_allegato_add_to_gtkform (priv->sallegato, priv->form,
+                       solipa_allegato_add_to_zakformgtk (priv->sallegato, priv->form,
                                                        "immagine_percorso", "immagine_file_data", "immagine_file_dimensione");
                        solipa_allegato_con_salva_in_db (priv->sallegato, FALSE);
                        gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->commons->gtkbuilder, "alignment4")),
@@ -381,10 +385,14 @@ OrganigrammaUfficio
        g_signal_connect (priv->w,
                          "delete-event", G_CALLBACK (organigramma_ufficio_on_w_ufficio_delete_event), (gpointer)a);
 
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder16"),
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder9"),
                          "btn-browse-clicked", G_CALLBACK (organigramma_ufficio_on_btn_ufficio_clicked), (gpointer)a);
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "gtkformdecoder15"),
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder10"),
                          "btn-browse-clicked", G_CALLBACK (organigramma_ufficio_on_btn_struttura_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder9"),
+                         "decode", G_CALLBACK (organigramma_ufficio_on_ufficio_decode), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder10"),
+                         "decode", G_CALLBACK (organigramma_ufficio_on_struttura_decode), (gpointer)a);
 
        g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button28")),
                          "clicked", G_CALLBACK (organigramma_ufficio_on_btn_nodo_nuovo_clicked), (gpointer)a);
@@ -451,17 +459,22 @@ OrganigrammaUfficio
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button151"),
                          "clicked", G_CALLBACK (organigramma_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)
                {
                        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));
 
-                       gtk_form_set_sensitive_by_name (priv->form, FALSE, "hbox2", "hbox19", "hbox4", "hbox9", "hbox21", "hbox22", "hbox24", NULL);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "hbox2")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "hbox19")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "hbox4")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "hbox9")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "hbox21")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "hbox22")), FALSE);
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "hbox24")), FALSE);
                }
        else
                {
@@ -530,7 +543,7 @@ organigramma_ufficio_carica (OrganigrammaUfficio *ufficio)
 {
        OrganigrammaUfficioPrivate *priv = ORGANIGRAMMA_UFFICIO_GET_PRIVATE (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)))
                {
                        organigramma_ufficio_carica_nodi (ufficio);
                        organigramma_ufficio_carica_stanze (ufficio);
@@ -545,36 +558,55 @@ organigramma_ufficio_carica (OrganigrammaUfficio *ufficio)
 static void
 organigramma_ufficio_salva (OrganigrammaUfficio *ufficio, gboolean chiudi)
 {
+       gboolean success;
+
        gchar *sql;
 
        OrganigrammaUfficioClass *klass = ORGANIGRAMMA_UFFICIO_GET_CLASS (ufficio);
 
        OrganigrammaUfficioPrivate *priv = ORGANIGRAMMA_UFFICIO_GET_PRIVATE (ufficio);
 
-       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,
+                                                                          "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 (ufficio, 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)
                                {
                                        priv->id = strtol (gtk_label_get_text (GTK_LABEL (priv->objects[LBL_ID])), NULL, 10);
-                                       gtk_form_set_sensitive_by_name (priv->form, TRUE, "hbox2", "hbox19", "hbox4", "hbox9", "hbox21", "hbox24", NULL);
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox2")), TRUE);
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox19")), TRUE);
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox4")), TRUE);
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox9")), TRUE);
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox21")), TRUE);
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox22")), TRUE);
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "hbox24")), TRUE);
                                }
 
                        /* salvo l'atto_allegato nel db */
@@ -862,8 +894,8 @@ organigramma_ufficio_carica_persone (OrganigrammaUfficio *ufficio)
                                                            PERSONE_COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"),
                                                            PERSONE_COL_RUOLO, gdaex_data_model_get_field_value_stringify_at (dm, row, "ruolo"),
                                                            PERSONE_COL_NOME, gdaex_data_model_get_field_value_stringify_at (dm, row, "cognome_nome"),
-                                                           PERSONE_COL_DA_DATA, gtk_form_field_datetime_get_str_from_tm (gdaex_data_model_get_field_value_tm_at (dm, row, "da_data"), "%d/%m/%Y"),
-                                                           PERSONE_COL_A_DATA, gtk_form_field_datetime_get_str_from_tm (gdaex_data_model_get_field_value_tm_at (dm, row, "a_data"), "%d/%m/%Y"),
+                                                           PERSONE_COL_DA_DATA, zak_utils_gdatetime_format (gdaex_data_model_get_field_value_gdatetime_at (dm, row, "da_data"), "%d/%m/%Y"),
+                                                           PERSONE_COL_A_DATA, zak_utils_gdatetime_format (gdaex_data_model_get_field_value_gdatetime_at (dm, row, "a_data"), "%d/%m/%Y"),
                                                            -1);
                                }
 
@@ -1197,7 +1229,7 @@ organigramma_ufficio_conferma_chiusura (OrganigrammaUfficio *ufficio)
        OrganigrammaUfficioPrivate *priv = ORGANIGRAMMA_UFFICIO_GET_PRIVATE (ufficio);
 
        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,
@@ -1218,7 +1250,7 @@ organigramma_ufficio_on_ufficio_selezionato (gpointer instance, guint id, gpoint
        OrganigrammaUfficio *f = (OrganigrammaUfficio *)user_data;
        OrganigrammaUfficioPrivate *priv = ORGANIGRAMMA_UFFICIO_GET_PRIVATE (f);
 
-       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "gtkformdecoder16"),
+       zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder9")),
                                             g_strdup_printf ("%d", id));
 }
 
@@ -1228,10 +1260,62 @@ organigramma_ufficio_on_struttura_selezionato (gpointer instance, guint id, gpoi
        OrganigrammaUfficio *f = (OrganigrammaUfficio *)user_data;
        OrganigrammaUfficioPrivate *priv = ORGANIGRAMMA_UFFICIO_GET_PRIVATE (f);
 
-       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "gtkformdecoder15"),
+       zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder10")),
                                             g_strdup_printf ("%d", id));
 }
 
+static gchar
+*organigramma_ufficio_on_ufficio_decode (gpointer instance, gchar *key, gpointer user_data)
+{
+       GString *ret;
+       gchar *sql;
+       GdaDataModel *dm;
+
+       OrganigrammaUfficio *f = (OrganigrammaUfficio *)user_data;
+       OrganigrammaUfficioPrivate *priv = ORGANIGRAMMA_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_ufficio_on_struttura_decode (gpointer instance, gchar *key, gpointer user_data)
+{
+       GString *ret;
+       gchar *sql;
+       GdaDataModel *dm;
+
+       OrganigrammaUfficio *f = (OrganigrammaUfficio *)user_data;
+       OrganigrammaUfficioPrivate *priv = ORGANIGRAMMA_UFFICIO_GET_PRIVATE (f);
+
+       ret = g_string_new ("");
+
+       sql = g_strdup_printf ("SELECT nome"
+                                                  " FROM strutture"
+                                                  " 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_on_nodo_aggiornato (gpointer instance, gpointer user_data)
 {
@@ -1813,7 +1897,6 @@ organigramma_ufficio_on_btn_allegato_apri_clicked (GtkButton *button,
                                         gpointer user_data)
 {
        GtkTreeIter iter;
-       const gchar *percorso;
        guint id;
 
        gchar *sql;