]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Test gestione tipi nodo.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 12 Aug 2010 10:36:48 +0000 (12:36 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 12 Aug 2010 10:36:48 +0000 (12:36 +0200)
Cambiata la gestione di GUIDIR e FORM in windows per facilitare il
momento dello sviluppo (manca da modificare libautedb).

13 files changed:
data/organigramma/gui/organigramma.gui
docs/organigramma/examples/Makefile.am
docs/organigramma/examples/organigramma.conf [new file with mode: 0644]
src/Makefile.am
src/main.c
src/tipi_nodo.c [deleted file]
src/tipi_nodo.h [deleted file]
src/tipinodo.c [new file with mode: 0644]
src/tipinodo.h [new file with mode: 0644]
src/tipo_nodo.c [deleted file]
src/tipo_nodo.h [deleted file]
src/tiponodo.c [new file with mode: 0644]
src/tiponodo.h [new file with mode: 0644]

index b8ba3a1fdb758dc50c50b14f576c6283623d649b..e2578b647c4f75ef46cbbf09c762aa8831cf08fb 100644 (file)
@@ -7,6 +7,7 @@
     <property name="window_position">center</property>
     <property name="default_width">600</property>
     <property name="default_height">400</property>
+    <signal name="destroy" handler="gtk_main_quit"/>
     <child>
       <object class="GtkVBox" id="vbox1">
         <property name="visible">True</property>
@@ -67,6 +68,7 @@
                         <property name="visible">True</property>
                         <property name="label" translatable="yes">Tipi _nodo</property>
                         <property name="use_underline">True</property>
+                        <signal name="activate" handler="on_mnu_tabelle_tipi_nodo_activate"/>
                       </object>
                     </child>
                   </object>
           </packing>
         </child>
         <child>
-          <object class="GtkVBox" id="vbx_child">
+          <object class="GtkVBox" id="vbx_body">
             <property name="visible">True</property>
             <property name="orientation">vertical</property>
             <child>
index bb51949263beac628b5ba46ce5dc9510f52b5329..1f7a0969a6b5b73833c4edcd636aa94f545d6f1e 100644 (file)
@@ -1,5 +1,6 @@
 examplesdir = $(docdir)/$(PACKAGE)/examples
 
-examples_DATA = 
+examples_DATA = \
+                organigramma.conf
 
 EXTRA_DIST = $(examples_DATA)
diff --git a/docs/organigramma/examples/organigramma.conf b/docs/organigramma/examples/organigramma.conf
new file mode 100644 (file)
index 0000000..91d9111
--- /dev/null
@@ -0,0 +1,6 @@
+[AUTE]
+plugin=/usr/local/lib/libaute/plugins/libaute-db
+cnc_string=PostgreSQL://postgres:postgres@HOST=localhost;PORT=5432;DB_NAME=autedb
+
+[DB]
+cnc_string=PostgreSQL://postgres:postgres@HOST=localhost;PORT=5432;DB_NAME=organigramma
index 539e82a5ed4f25917c936c9464c277282600edcd..051617b3770163032f0b81f378e454a8d31af44b 100644 (file)
@@ -13,7 +13,7 @@ bin_PROGRAMS = organigramma
 organigramma_SOURCES = \
                 commons.h \
                 main.c \
-                tipi_nodo.c \
-                tipi_nodo.h \
-                tipo_nodo.c \
-                tipo_nodo.h
\ No newline at end of file
+                tipinodo.c \
+                tipinodo.h \
+                tiponodo.c \
+                tiponodo.h
\ No newline at end of file
index 8e8c7a755e53cbff6cfc5ab1ceb63419224ed6d6..4a8b7bde1670912c4d9cdba5f172047e63d2fc98 100644 (file)
        #include <config.h>
 #endif
 
+#include <string.h>
+
 #include <gtk/gtk.h>
 
 #include <libaute.h>
 #include <libgdaex.h>
 
 #include "commons.h"
+#include "tipinodo.h"
 
 static Commons *commons;
 
@@ -61,6 +64,19 @@ on_mnu_view_prenotazioni_activate (GtkMenuItem *menuitem,
        main_set_vbx_body_child (vbx);
 }*/
 
+G_MODULE_EXPORT void
+on_mnu_tabelle_tipi_nodo_activate (GtkMenuItem *menuitem,
+                            gpointer user_data)
+{
+       GtkWidget *vbx;
+
+       TipiNodo *m = tipi_nodo_new (commons, FALSE);
+
+       vbx = tipi_nodo_get_widget (m);
+
+       main_set_vbx_body_child (vbx);
+}
+
 G_MODULE_EXPORT void
 on_mnu_help_about_activate (GtkMenuItem *menuitem,
                             gpointer user_data)
@@ -78,7 +94,7 @@ on_mnu_help_about_activate (GtkMenuItem *menuitem,
                }
 
        diag = GTK_WIDGET (gtk_builder_get_object (commons->gtkbuilder, "dlg_about"));
-
+       gtk_window_set_transient_for (GTK_WINDOW (diag), GTK_WINDOW (w));
        gtk_dialog_run (GTK_DIALOG (diag));
        gtk_widget_destroy (diag);
 }
@@ -134,7 +150,7 @@ main (int argc, char *argv[])
        g_strfreev (aute_params);
 
        /* autenticazione */
-       aute = aute_new ();
+       /*aute = aute_new ();
        aute_set_config (aute, sl_aute_params);
 
        while (TRUE)
@@ -147,24 +163,40 @@ main (int argc, char *argv[])
                                }
                        else if (g_strcmp0 (utente, "") == 0)
                                {
-                                       return 0;                               
+                                       return 0;
                                }
                        else
                                {
                                        break;
                                }
-               }
+               }*/
 
        /* inizializzazione commons */
        commons = g_malloc (sizeof (Commons));
 
 #ifdef G_OS_WIN32
 
-#undef GUIDIR
-       commons->guidir = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", PACKAGE, "gui", NULL);
+       gchar *moddir;
+       gchar *p;
+
+       moddir = g_win32_get_package_installation_directory_of_module (NULL);
 
-#undef FORMDIR
-       commons->formdir = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", PACKAGE, "form", NULL);
+       p = strrchr (moddir, G_DIR_SEPARATOR);
+       if (p != NULL
+           && g_ascii_strcasecmp (p + 1, "src") == 0)
+               {
+                       /*
+                       *p = '\0';
+                       commons->guidir = g_build_filename (moddir, "data", PACKAGE, "gui", NULL);
+                       commons->formdir = g_build_filename (moddir, "data", PACKAGE, "form", NULL);*/
+                       commons->guidir = g_strdup (GUIDIR);
+                       commons->formdir = g_strdup (FORMDIR);
+               }
+       else
+               {
+                       commons->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL);
+                       commons->formdir = g_build_filename (moddir, "share", PACKAGE, "form", NULL);
+               }
 
 #else
 
@@ -173,7 +205,7 @@ main (int argc, char *argv[])
 
 #endif
 
-       commons->guifile = g_build_filename (commons->guidir, "mezzi.gui", NULL);
+       commons->guifile = g_build_filename (commons->guidir, "organigramma.gui", NULL);
 
        /* leggo la stringa di connessione al db */
        error = NULL;
diff --git a/src/tipi_nodo.c b/src/tipi_nodo.c
deleted file mode 100644 (file)
index ded3513..0000000
+++ /dev/null
@@ -1,495 +0,0 @@
-/* 
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#include "tipi_nodo.h"
-#include "tipo_nodo.h"
-
-static void tipi_nodo_class_init (TipiNodoClass *klass);
-static void tipi_nodo_init (TipiNodo *tipi_nodo);
-
-static void tipi_nodo_carica (TipiNodo *tipi_nodo);
-static void tipi_nodo_modifica (TipiNodo *tipi_nodo);
-
-static void tipi_nodo_selezionato (TipiNodo *tipi_nodo);
-static void tipi_nodo_on_tipo_nodo_aggiornato (gpointer instance, gpointer user_data);
-
-static void tipi_nodo_set_property (GObject *object,
-                                     guint property_id,
-                                     const GValue *value,
-                                     GParamSpec *pspec);
-static void tipi_nodo_get_property (GObject *object,
-                                     guint property_id,
-                                     GValue *value,
-                                     GParamSpec *pspec);
-
-static void tipi_nodo_on_btn_nuovo_clicked (GtkButton *button,
-                      gpointer user_data);
-static void tipi_nodo_on_btn_modifica_clicked (GtkButton *button,
-                      gpointer user_data);
-static void tipi_nodo_on_btn_elimina_clicked (GtkButton *button,
-                        gpointer user_data);
-static void tipi_nodo_on_trv_tipi_nodo_row_activated (GtkTreeView *tree_view,
-                                             GtkTreePath *tree_path,
-                                             GtkTreeViewColumn *column,
-                                             gpointer user_data);
-
-static void tipi_nodo_on_btn_ricerca_clicked (GtkButton *button,
-                                    gpointer user_data);
-
-static void tipi_nodo_on_btn_annulla_clicked (GtkButton *button,
-                                    gpointer user_data);
-static void tipi_nodo_on_btn_seleziona_clicked (GtkButton *button,
-                                  gpointer user_data);
-
-#define TIPI_NODO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TIPI_NODO, TipiNodoPrivate))
-
-enum
-{
-       COL_ID,
-       COL_NOME
-};
-
-typedef struct _TipiNodoPrivate TipiNodoPrivate;
-struct _TipiNodoPrivate
-       {
-               Commons *commons;
-
-               GtkWidget *widget;
-               GtkTreeSelection *selection;
-               GtkListStore *lstore_tipi_nodo;
-
-               gboolean selezione;
-       };
-
-G_DEFINE_TYPE (TipiNodo, tipi_nodo, G_TYPE_OBJECT)
-
-static void
-tipi_nodo_class_init (TipiNodoClass *klass)
-{
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-       g_type_class_add_private (object_class, sizeof (TipiNodoPrivate));
-
-       object_class->set_property = tipi_nodo_set_property;
-       object_class->get_property = tipi_nodo_get_property;
-
-       /**
-        * TipiNodo::selezionato:
-        * @tipi_nodo:
-        *
-        */
-       klass->selezionato_signal_id = g_signal_new ("selezionato",
-                                                      G_TYPE_FROM_CLASS (object_class),
-                                                      G_SIGNAL_RUN_LAST,
-                                                      0,
-                                                      NULL,
-                                                      NULL,
-                                                      g_cclosure_marshal_VOID__UINT,
-                                                      G_TYPE_NONE,
-                                                      1, G_TYPE_UINT);
-}
-
-static void
-tipi_nodo_init (TipiNodo *tipi_nodo)
-{
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
-}
-
-/**
- * tipi_nodo_new:
- * @commons:
- * @selezione:
- *
- * Returns: the newly created #TipiNodo object.
- */
-TipiNodo
-*tipi_nodo_new (Commons *commons, gboolean selezione)
-{
-       GError *error;
-
-       TipiNodo *a = TIPI_NODO (g_object_new (tipi_nodo_get_type (), NULL));
-
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (a);
-
-       priv->commons = commons;
-       priv->selezione = selezione;
-
-       error = NULL;
-       gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
-                                          g_strsplit (g_strconcat ("lstore_tipi_nodo|", 
-                                          (selezione ? "w_tipi_nodo" : "vbx_tipi_nodo"),
-                                          NULL), "|", -1),
-                                          &error);
-       if (error != NULL)
-               {
-                       g_warning ("Errore: %s.", error->message);
-                       return NULL;
-               }
-
-       priv->widget = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, (selezione ? "w_tipi_nodo" : "vbx_tipi_nodo")));
-       priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview2")));
-       priv->lstore_tipi_nodo = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_tipi_nodo"));
-
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button7"),
-                         "clicked", G_CALLBACK (tipi_nodo_on_btn_nuovo_clicked), (gpointer)a);
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button10"),
-                         "clicked", G_CALLBACK (tipi_nodo_on_btn_modifica_clicked), (gpointer)a);
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button11"),
-                         "clicked", G_CALLBACK (tipi_nodo_on_btn_elimina_clicked), (gpointer)a);
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview2"),
-                         "row-activated", G_CALLBACK (tipi_nodo_on_trv_tipi_nodo_row_activated), (gpointer)a);
-
-       if (priv->selezione)
-               {
-                       gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "label7")));
-                       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button12"),
-                                         "clicked", G_CALLBACK (tipi_nodo_on_btn_annulla_clicked), (gpointer)a);
-                       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button13"),
-                                         "clicked", G_CALLBACK (tipi_nodo_on_btn_seleziona_clicked), (gpointer)a);
-               }
-       else
-               {
-                       gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button12")));
-                       gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button13")));
-               }
-
-       tipi_nodo_carica (a);
-
-       return a;
-}
-
-/**
- * tipi_nodo_get_widget:
- * @tipi_nodo:
- *
- */
-GtkWidget
-*tipi_nodo_get_widget (TipiNodo *tipi_nodo)
-{
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
-
-       return priv->widget;
-}
-
-/* PRIVATE */
-static void
-tipi_nodo_carica (TipiNodo *tipi_nodo)
-{
-       GtkTreeIter iter;
-       GdaDataModel *dm;
-
-       gchar *sql_where;
-       gchar *sql;
-
-       gchar *gcval;
-       gint ival;
-
-       gint rows;
-       gint row;
-
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
-
-       gtk_list_store_clear (priv->lstore_tipi_nodo);
-
-       sql_where = g_strdup ("");
-
-       /*if (priv->parametri_ricerca != NULL)
-               {
-                       gcval = (gchar *)g_value_get_string ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "ragione_sociale"));
-                       if (gcval != NULL && g_strcmp0 (g_strstrip (gcval), "") != 0)
-                               {
-                                       sql_where = g_strconcat (sql_where, " AND ragione_sociale ILIKE '%%",
-                                                                gdaex_strescape (gcval, NULL),
-                                                                "%%'",
-                                                                NULL);
-                               }
-                       gcval = (gchar *)g_value_get_string ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "codice_fiscale"));
-                       if (gcval != NULL && g_strcmp0 (g_strstrip (gcval), "") != 0)
-                               {
-                                       sql_where = g_strconcat (sql_where, " AND codice_fiscale = '",
-                                                                gdaex_strescape (gcval, NULL),
-                                                                "'",
-                                                                NULL);
-                               }
-                       gcval = (gchar *)g_value_get_string ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "partita_iva"));
-                       if (gcval != NULL && g_strcmp0 (g_strstrip (gcval), "") != 0)
-                               {
-                                       sql_where = g_strconcat (sql_where, " AND partita_iva = '",
-                                                                gdaex_strescape (gcval, NULL),
-                                                                "'",
-                                                                NULL);
-                               }
-                       ival = g_value_get_int ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "id_citta"));
-                       if (ival != 0)
-                               {
-                                       sql_where = g_strconcat (sql_where, " AND id_citta = ",
-                                                                g_strdup_printf ("%d", ival),
-                                                                NULL);
-                               }
-               }*/
-
-       sql = g_strdup_printf ("SELECT c.id, c.nome"
-                         " FROM tipi_nodo c"
-                         " WHERE c.status <> 'E'"
-                         "%s"
-                         " ORDER BY c.nome", sql_where);
-       dm = gdaex_query (priv->commons->gdaex, sql);
-       if (dm != NULL)
-               {
-                       rows = gda_data_model_get_n_rows (dm);
-                       for (row = 0; row < rows; row++)
-                               {
-                                       gtk_list_store_append (priv->lstore_tipi_nodo, &iter);
-
-                                       gtk_list_store_set (priv->lstore_tipi_nodo, &iter,
-                                                           COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"),
-                                                                               COL_NOME, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"),
-                                                           -1);
-                               }
-
-                       g_object_unref (dm);
-               }
-}
-
-static void
-tipi_nodo_modifica (TipiNodo *tipi_nodo)
-{
-       GtkTreeIter iter;
-       gint id;
-
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
-
-       if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
-               {
-                       GtkWidget *w;
-
-                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_tipi_nodo), &iter,
-                                           COL_ID, &id,
-                                                               -1);
-
-                       TipoNodo *c = tipo_nodo_new (priv->commons, id);
-
-                       g_signal_connect (G_OBJECT (c), "aggiornato",
-                                         G_CALLBACK (tipi_nodo_on_tipo_nodo_aggiornato), (gpointer)tipi_nodo);
-
-                       w = tipo_nodo_get_widget (c);
-                       if (priv->selezione)
-                               {
-                                       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->widget));
-                               }
-                       else
-                               {
-                                       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
-                               }
-                       gtk_widget_show (w);
-               }
-       else
-               {
-                       GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_WARNING,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "Occorre prima selezionare un tipo nodo");
-                       gtk_dialog_run (GTK_DIALOG (dialog));
-                       gtk_widget_destroy (dialog);
-               }
-}
-
-static void
-tipi_nodo_selezionato (TipiNodo *tipi_nodo)
-{
-       GtkTreeIter iter;
-       guint id;
-
-       TipiNodoClass *klass = TIPI_NODO_GET_CLASS (tipi_nodo);
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
-
-       if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
-               {
-                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_tipi_nodo), &iter,
-                                           COL_ID, &id,
-                                                               -1);
-
-                       g_signal_emit (G_OBJECT (tipi_nodo), klass->selezionato_signal_id, 0, id);
-
-                       gtk_widget_destroy (priv->widget);
-                       g_object_unref (G_OBJECT (tipi_nodo));
-               }
-       else
-               {
-                       GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_WARNING,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "Occorre prima selezionare un tipo nodo");
-                       gtk_dialog_run (GTK_DIALOG (dialog));
-                       gtk_widget_destroy (dialog);
-               }
-}
-
-static void
-tipi_nodo_on_tipo_nodo_aggiornato (gpointer instance, gpointer user_data)
-{
-       tipi_nodo_carica ((TipiNodo *)user_data);
-}
-
-static void
-tipi_nodo_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
-       TipiNodo *tipi_nodo = TIPI_NODO (object);
-
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
-
-       switch (property_id)
-               {
-                       default:
-                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-                               break;
-               }
-}
-
-static void
-tipi_nodo_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
-       TipiNodo *tipi_nodo = TIPI_NODO (object);
-
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
-
-       switch (property_id)
-               {
-                       default:
-                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-                               break;
-               }
-}
-
-/* CALLBACK */
-static void
-tipi_nodo_on_btn_nuovo_clicked (GtkButton *button,
-                      gpointer user_data)
-{
-       GtkWidget *w;
-
-       TipiNodo *tipi_nodo = (TipiNodo *)user_data;
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
-
-       TipoNodo *c = tipo_nodo_new (priv->commons, 0);
-
-       g_signal_connect (G_OBJECT (c), "aggiornato",
-                         G_CALLBACK (tipi_nodo_on_tipo_nodo_aggiornato), (gpointer)tipi_nodo);
-
-       w = tipo_nodo_get_widget (c);
-       if (priv->selezione)
-               {
-                       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->widget));
-               }
-       else
-               {
-                       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
-               }
-       gtk_widget_show (w);
-}
-
-static void
-tipi_nodo_on_btn_modifica_clicked (GtkButton *button,
-                      gpointer user_data)
-{
-       tipi_nodo_modifica ((TipiNodo *)user_data);
-}
-
-static void
-tipi_nodo_on_btn_elimina_clicked (GtkButton *button,
-                        gpointer user_data)
-{
-       GtkWidget *dialog;
-       gboolean risp;
-
-       GtkTreeIter iter;
-       gint id;
-
-       TipiNodo *tipi_nodo = (TipiNodo *)user_data;
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
-
-       if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
-               {
-                       dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_QUESTION,
-                                                                                        GTK_BUTTONS_YES_NO,
-                                                                                        "Sicuro di voler eliminare il tipo nodo selezionato?");
-                       risp = gtk_dialog_run (GTK_DIALOG (dialog));
-                       if (risp == GTK_RESPONSE_YES)
-                               {
-                                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_tipi_nodo), &iter,
-                                                                                       COL_ID, &id,
-                                                                                       -1);
-
-                                       gdaex_execute (priv->commons->gdaex,
-                                                      g_strdup_printf ("UPDATE tipi_nodo SET status = 'E' WHERE id = %d", id));
-
-                                       tipi_nodo_carica (tipi_nodo);
-                               }
-                       gtk_widget_destroy (dialog);
-               }
-       else
-               {
-                       dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_WARNING,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "Occorre prima selezionare un tipo nodo");
-                       gtk_dialog_run (GTK_DIALOG (dialog));
-                       gtk_widget_destroy (dialog);
-               }
-}
-
-static void
-tipi_nodo_on_trv_tipi_nodo_row_activated (GtkTreeView *tree_view,
-                                             GtkTreePath *tree_path,
-                                                                                        GtkTreeViewColumn *column,
-                                                                                        gpointer user_data)
-{
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE ((TipiNodo *)user_data);
-
-       if (priv->selezione)
-               {
-                       tipi_nodo_selezionato ((TipiNodo *)user_data);          
-               }
-       else
-               {
-                       tipi_nodo_modifica ((TipiNodo *)user_data);
-               }
-}
-
-static void
-tipi_nodo_on_btn_annulla_clicked (GtkButton *button,
-                        gpointer user_data)
-{
-       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE ((TipiNodo *)user_data);
-
-       gtk_widget_destroy (priv->widget);
-       g_object_unref (G_OBJECT (user_data));
-}
-
-static void
-tipi_nodo_on_btn_seleziona_clicked (GtkButton *button,
-                        gpointer user_data)
-{
-       tipi_nodo_selezionato ((TipiNodo *)user_data);
-}
diff --git a/src/tipi_nodo.h b/src/tipi_nodo.h
deleted file mode 100644 (file)
index 8664023..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/* 
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifndef __TIPI_NODO_H__
-#define __TIPI_NODO_H__
-
-#include <glib.h>
-#include <glib-object.h>
-
-#include <gtk/gtk.h>
-#include <libgdaex.h>
-
-#include "commons.h"
-
-G_BEGIN_DECLS
-
-
-#define TYPE_TIPI_NODO                 (tipi_nodo_get_type ())
-#define TIPI_NODO(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TIPI_NODO, TipiNodo))
-#define TIPI_NODO_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TIPI_NODO, TipiNodoClass))
-#define IS_TIPI_NODO(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TIPI_NODO))
-#define IS_TIPI_NODO_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TIPI_NODO))
-#define TIPI_NODO_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TIPI_NODO, TipiNodoClass))
-
-
-typedef struct _TipiNodo TipiNodo;
-typedef struct _TipiNodoClass TipiNodoClass;
-
-struct _TipiNodo
-       {
-               GObject parent;
-       };
-
-struct _TipiNodoClass
-       {
-               GObjectClass parent_class;
-
-               guint selezionato_signal_id;
-       };
-
-GType tipi_nodo_get_type (void) G_GNUC_CONST;
-
-TipiNodo *tipi_nodo_new (Commons *commons, gboolean selezione);
-
-GtkWidget *tipi_nodo_get_widget (TipiNodo *tipi_nodo);
-
-
-G_END_DECLS
-
-#endif /* __TIPI_NODO_H__ */
diff --git a/src/tipinodo.c b/src/tipinodo.c
new file mode 100644 (file)
index 0000000..8692775
--- /dev/null
@@ -0,0 +1,495 @@
+/* 
+ * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "tipinodo.h"
+#include "tiponodo.h"
+
+static void tipi_nodo_class_init (TipiNodoClass *klass);
+static void tipi_nodo_init (TipiNodo *tipi_nodo);
+
+static void tipi_nodo_carica (TipiNodo *tipi_nodo);
+static void tipi_nodo_modifica (TipiNodo *tipi_nodo);
+
+static void tipi_nodo_selezionato (TipiNodo *tipi_nodo);
+static void tipi_nodo_on_tipo_nodo_aggiornato (gpointer instance, gpointer user_data);
+
+static void tipi_nodo_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void tipi_nodo_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+static void tipi_nodo_on_btn_nuovo_clicked (GtkButton *button,
+                      gpointer user_data);
+static void tipi_nodo_on_btn_modifica_clicked (GtkButton *button,
+                      gpointer user_data);
+static void tipi_nodo_on_btn_elimina_clicked (GtkButton *button,
+                        gpointer user_data);
+static void tipi_nodo_on_trv_tipi_nodo_row_activated (GtkTreeView *tree_view,
+                                             GtkTreePath *tree_path,
+                                             GtkTreeViewColumn *column,
+                                             gpointer user_data);
+
+static void tipi_nodo_on_btn_ricerca_clicked (GtkButton *button,
+                                    gpointer user_data);
+
+static void tipi_nodo_on_btn_annulla_clicked (GtkButton *button,
+                                    gpointer user_data);
+static void tipi_nodo_on_btn_seleziona_clicked (GtkButton *button,
+                                  gpointer user_data);
+
+#define TIPI_NODO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TIPI_NODO, TipiNodoPrivate))
+
+enum
+{
+       COL_ID,
+       COL_NOME
+};
+
+typedef struct _TipiNodoPrivate TipiNodoPrivate;
+struct _TipiNodoPrivate
+       {
+               Commons *commons;
+
+               GtkWidget *widget;
+               GtkTreeSelection *selection;
+               GtkListStore *lstore_tipi_nodo;
+
+               gboolean selezione;
+       };
+
+G_DEFINE_TYPE (TipiNodo, tipi_nodo, G_TYPE_OBJECT)
+
+static void
+tipi_nodo_class_init (TipiNodoClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (TipiNodoPrivate));
+
+       object_class->set_property = tipi_nodo_set_property;
+       object_class->get_property = tipi_nodo_get_property;
+
+       /**
+        * TipiNodo::selezionato:
+        * @tipi_nodo:
+        *
+        */
+       klass->selezionato_signal_id = g_signal_new ("selezionato",
+                                                      G_TYPE_FROM_CLASS (object_class),
+                                                      G_SIGNAL_RUN_LAST,
+                                                      0,
+                                                      NULL,
+                                                      NULL,
+                                                      g_cclosure_marshal_VOID__UINT,
+                                                      G_TYPE_NONE,
+                                                      1, G_TYPE_UINT);
+}
+
+static void
+tipi_nodo_init (TipiNodo *tipi_nodo)
+{
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
+}
+
+/**
+ * tipi_nodo_new:
+ * @commons:
+ * @selezione:
+ *
+ * Returns: the newly created #TipiNodo object.
+ */
+TipiNodo
+*tipi_nodo_new (Commons *commons, gboolean selezione)
+{
+       GError *error;
+
+       TipiNodo *a = TIPI_NODO (g_object_new (tipi_nodo_get_type (), NULL));
+
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (a);
+
+       priv->commons = commons;
+       priv->selezione = selezione;
+
+       error = NULL;
+       gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
+                                          g_strsplit (g_strconcat ("lstore_tipi_nodo|", 
+                                          (selezione ? "w_tipi_nodo" : "vbx_tipi_nodo"),
+                                          NULL), "|", -1),
+                                          &error);
+       if (error != NULL)
+               {
+                       g_warning ("Errore: %s.", error->message);
+                       return NULL;
+               }
+
+       priv->widget = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, (selezione ? "w_tipi_nodo" : "vbx_tipi_nodo")));
+       priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview2")));
+       priv->lstore_tipi_nodo = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_tipi_nodo"));
+
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button7"),
+                         "clicked", G_CALLBACK (tipi_nodo_on_btn_nuovo_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button10"),
+                         "clicked", G_CALLBACK (tipi_nodo_on_btn_modifica_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button11"),
+                         "clicked", G_CALLBACK (tipi_nodo_on_btn_elimina_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview2"),
+                         "row-activated", G_CALLBACK (tipi_nodo_on_trv_tipi_nodo_row_activated), (gpointer)a);
+
+       if (priv->selezione)
+               {
+                       gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "label7")));
+                       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button12"),
+                                         "clicked", G_CALLBACK (tipi_nodo_on_btn_annulla_clicked), (gpointer)a);
+                       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button13"),
+                                         "clicked", G_CALLBACK (tipi_nodo_on_btn_seleziona_clicked), (gpointer)a);
+               }
+       else
+               {
+                       gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button12")));
+                       gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button13")));
+               }
+
+       tipi_nodo_carica (a);
+
+       return a;
+}
+
+/**
+ * tipi_nodo_get_widget:
+ * @tipi_nodo:
+ *
+ */
+GtkWidget
+*tipi_nodo_get_widget (TipiNodo *tipi_nodo)
+{
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
+
+       return priv->widget;
+}
+
+/* PRIVATE */
+static void
+tipi_nodo_carica (TipiNodo *tipi_nodo)
+{
+       GtkTreeIter iter;
+       GdaDataModel *dm;
+
+       gchar *sql_where;
+       gchar *sql;
+
+       gchar *gcval;
+       gint ival;
+
+       gint rows;
+       gint row;
+
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
+
+       gtk_list_store_clear (priv->lstore_tipi_nodo);
+
+       sql_where = g_strdup ("");
+
+       /*if (priv->parametri_ricerca != NULL)
+               {
+                       gcval = (gchar *)g_value_get_string ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "ragione_sociale"));
+                       if (gcval != NULL && g_strcmp0 (g_strstrip (gcval), "") != 0)
+                               {
+                                       sql_where = g_strconcat (sql_where, " AND ragione_sociale ILIKE '%%",
+                                                                gdaex_strescape (gcval, NULL),
+                                                                "%%'",
+                                                                NULL);
+                               }
+                       gcval = (gchar *)g_value_get_string ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "codice_fiscale"));
+                       if (gcval != NULL && g_strcmp0 (g_strstrip (gcval), "") != 0)
+                               {
+                                       sql_where = g_strconcat (sql_where, " AND codice_fiscale = '",
+                                                                gdaex_strescape (gcval, NULL),
+                                                                "'",
+                                                                NULL);
+                               }
+                       gcval = (gchar *)g_value_get_string ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "partita_iva"));
+                       if (gcval != NULL && g_strcmp0 (g_strstrip (gcval), "") != 0)
+                               {
+                                       sql_where = g_strconcat (sql_where, " AND partita_iva = '",
+                                                                gdaex_strescape (gcval, NULL),
+                                                                "'",
+                                                                NULL);
+                               }
+                       ival = g_value_get_int ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "id_citta"));
+                       if (ival != 0)
+                               {
+                                       sql_where = g_strconcat (sql_where, " AND id_citta = ",
+                                                                g_strdup_printf ("%d", ival),
+                                                                NULL);
+                               }
+               }*/
+
+       sql = g_strdup_printf ("SELECT c.id, c.nome"
+                         " FROM tipi_nodo c"
+                         " WHERE c.status <> 'E'"
+                         "%s"
+                         " ORDER BY c.nome", sql_where);
+       dm = gdaex_query (priv->commons->gdaex, sql);
+       if (dm != NULL)
+               {
+                       rows = gda_data_model_get_n_rows (dm);
+                       for (row = 0; row < rows; row++)
+                               {
+                                       gtk_list_store_append (priv->lstore_tipi_nodo, &iter);
+
+                                       gtk_list_store_set (priv->lstore_tipi_nodo, &iter,
+                                                           COL_ID, gdaex_data_model_get_field_value_stringify_at (dm, row, "id"),
+                                                                               COL_NOME, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"),
+                                                           -1);
+                               }
+
+                       g_object_unref (dm);
+               }
+}
+
+static void
+tipi_nodo_modifica (TipiNodo *tipi_nodo)
+{
+       GtkTreeIter iter;
+       gchar *id;
+
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
+
+       if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
+               {
+                       GtkWidget *w;
+
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_tipi_nodo), &iter,
+                                           COL_ID, &id,
+                                                               -1);
+
+                       TipoNodo *c = tipo_nodo_new (priv->commons, strtol (id, NULL, 10));
+
+                       g_signal_connect (G_OBJECT (c), "aggiornato",
+                                         G_CALLBACK (tipi_nodo_on_tipo_nodo_aggiornato), (gpointer)tipi_nodo);
+
+                       w = tipo_nodo_get_widget (c);
+                       if (priv->selezione)
+                               {
+                                       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->widget));
+                               }
+                       else
+                               {
+                                       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
+                               }
+                       gtk_widget_show (w);
+               }
+       else
+               {
+                       GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
+                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                        GTK_MESSAGE_WARNING,
+                                                                                        GTK_BUTTONS_OK,
+                                                                                        "Occorre prima selezionare un tipo nodo");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+}
+
+static void
+tipi_nodo_selezionato (TipiNodo *tipi_nodo)
+{
+       GtkTreeIter iter;
+       guint id;
+
+       TipiNodoClass *klass = TIPI_NODO_GET_CLASS (tipi_nodo);
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
+
+       if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
+               {
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_tipi_nodo), &iter,
+                                           COL_ID, &id,
+                                                               -1);
+
+                       g_signal_emit (G_OBJECT (tipi_nodo), klass->selezionato_signal_id, 0, id);
+
+                       gtk_widget_destroy (priv->widget);
+                       g_object_unref (G_OBJECT (tipi_nodo));
+               }
+       else
+               {
+                       GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
+                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                        GTK_MESSAGE_WARNING,
+                                                                                        GTK_BUTTONS_OK,
+                                                                                        "Occorre prima selezionare un tipo nodo");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+}
+
+static void
+tipi_nodo_on_tipo_nodo_aggiornato (gpointer instance, gpointer user_data)
+{
+       tipi_nodo_carica ((TipiNodo *)user_data);
+}
+
+static void
+tipi_nodo_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       TipiNodo *tipi_nodo = TIPI_NODO (object);
+
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+tipi_nodo_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       TipiNodo *tipi_nodo = TIPI_NODO (object);
+
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+/* CALLBACK */
+static void
+tipi_nodo_on_btn_nuovo_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       GtkWidget *w;
+
+       TipiNodo *tipi_nodo = (TipiNodo *)user_data;
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
+
+       TipoNodo *c = tipo_nodo_new (priv->commons, 0);
+
+       g_signal_connect (G_OBJECT (c), "aggiornato",
+                         G_CALLBACK (tipi_nodo_on_tipo_nodo_aggiornato), (gpointer)tipi_nodo);
+
+       w = tipo_nodo_get_widget (c);
+       if (priv->selezione)
+               {
+                       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->widget));
+               }
+       else
+               {
+                       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
+               }
+       gtk_widget_show (w);
+}
+
+static void
+tipi_nodo_on_btn_modifica_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       tipi_nodo_modifica ((TipiNodo *)user_data);
+}
+
+static void
+tipi_nodo_on_btn_elimina_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       GtkWidget *dialog;
+       gboolean risp;
+
+       GtkTreeIter iter;
+       gchar *id;
+
+       TipiNodo *tipi_nodo = (TipiNodo *)user_data;
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE (tipi_nodo);
+
+       if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
+               {
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
+                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                        GTK_MESSAGE_QUESTION,
+                                                                                        GTK_BUTTONS_YES_NO,
+                                                                                        "Sicuro di voler eliminare il tipo nodo selezionato?");
+                       risp = gtk_dialog_run (GTK_DIALOG (dialog));
+                       if (risp == GTK_RESPONSE_YES)
+                               {
+                                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_tipi_nodo), &iter,
+                                                                                       COL_ID, &id,
+                                                                                       -1);
+
+                                       gdaex_execute (priv->commons->gdaex,
+                                                      g_strdup_printf ("UPDATE tipi_nodo SET status = 'E' WHERE id = %d", strtol (id, NULL, 10)));
+
+                                       tipi_nodo_carica (tipi_nodo);
+                               }
+                       gtk_widget_destroy (dialog);
+               }
+       else
+               {
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
+                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                        GTK_MESSAGE_WARNING,
+                                                                                        GTK_BUTTONS_OK,
+                                                                                        "Occorre prima selezionare un tipo nodo");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+}
+
+static void
+tipi_nodo_on_trv_tipi_nodo_row_activated (GtkTreeView *tree_view,
+                                             GtkTreePath *tree_path,
+                                                                                        GtkTreeViewColumn *column,
+                                                                                        gpointer user_data)
+{
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE ((TipiNodo *)user_data);
+
+       if (priv->selezione)
+               {
+                       tipi_nodo_selezionato ((TipiNodo *)user_data);          
+               }
+       else
+               {
+                       tipi_nodo_modifica ((TipiNodo *)user_data);
+               }
+}
+
+static void
+tipi_nodo_on_btn_annulla_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       TipiNodoPrivate *priv = TIPI_NODO_GET_PRIVATE ((TipiNodo *)user_data);
+
+       gtk_widget_destroy (priv->widget);
+       g_object_unref (G_OBJECT (user_data));
+}
+
+static void
+tipi_nodo_on_btn_seleziona_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       tipi_nodo_selezionato ((TipiNodo *)user_data);
+}
diff --git a/src/tipinodo.h b/src/tipinodo.h
new file mode 100644 (file)
index 0000000..8664023
--- /dev/null
@@ -0,0 +1,66 @@
+/* 
+ * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __TIPI_NODO_H__
+#define __TIPI_NODO_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+#include <libgdaex.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_TIPI_NODO                 (tipi_nodo_get_type ())
+#define TIPI_NODO(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TIPI_NODO, TipiNodo))
+#define TIPI_NODO_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TIPI_NODO, TipiNodoClass))
+#define IS_TIPI_NODO(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TIPI_NODO))
+#define IS_TIPI_NODO_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TIPI_NODO))
+#define TIPI_NODO_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TIPI_NODO, TipiNodoClass))
+
+
+typedef struct _TipiNodo TipiNodo;
+typedef struct _TipiNodoClass TipiNodoClass;
+
+struct _TipiNodo
+       {
+               GObject parent;
+       };
+
+struct _TipiNodoClass
+       {
+               GObjectClass parent_class;
+
+               guint selezionato_signal_id;
+       };
+
+GType tipi_nodo_get_type (void) G_GNUC_CONST;
+
+TipiNodo *tipi_nodo_new (Commons *commons, gboolean selezione);
+
+GtkWidget *tipi_nodo_get_widget (TipiNodo *tipi_nodo);
+
+
+G_END_DECLS
+
+#endif /* __TIPI_NODO_H__ */
diff --git a/src/tipo_nodo.c b/src/tipo_nodo.c
deleted file mode 100644 (file)
index fffd83f..0000000
+++ /dev/null
@@ -1,339 +0,0 @@
-/* 
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#include <libgtkform/form.h>
-#include <libgtkform/fielddatetime.h>
-
-#include "tipo_nodo.h"
-
-static void tipo_nodo_class_init (TipoNodoClass *klass);
-static void tipo_nodo_init (TipoNodo *tipo_nodo);
-
-static void tipo_nodo_carica (TipoNodo *tipo_nodo);
-static void tipo_nodo_salva (TipoNodo *tipo_nodo);
-
-static gboolean tipo_nodo_conferma_chiusura (TipoNodo *tipo_nodo);
-
-static void tipo_nodo_set_property (GObject *object,
-                                     guint property_id,
-                                     const GValue *value,
-                                     GParamSpec *pspec);
-static void tipo_nodo_get_property (GObject *object,
-                                     guint property_id,
-                                     GValue *value,
-                                     GParamSpec *pspec);
-
-static gboolean tipo_nodo_on_w_tipo_nodo_delete_event (GtkWidget *widget,
-                               GdkEvent *event,
-                               gpointer user_data);
-
-static void tipo_nodo_on_btn_annulla_clicked (GtkButton *button,
-                                    gpointer user_data);
-static void tipo_nodo_on_btn_salva_clicked (GtkButton *button,
-                                  gpointer user_data);
-
-#define TIPO_NODO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TIPO_NODO, TipoNodoPrivate))
-
-enum
-{
-       LBL_ID
-};
-
-typedef struct _TipoNodoPrivate TipoNodoPrivate;
-struct _TipoNodoPrivate
-       {
-               Commons *commons;
-
-               GtkForm *form;
-
-               GtkWidget *w;
-
-               GObject **objects;
-
-               gint id;
-       };
-
-G_DEFINE_TYPE (TipoNodo, tipo_nodo, G_TYPE_OBJECT)
-
-static void
-tipo_nodo_class_init (TipoNodoClass *klass)
-{
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-       g_type_class_add_private (object_class, sizeof (TipoNodoPrivate));
-
-       object_class->set_property = tipo_nodo_set_property;
-       object_class->get_property = tipo_nodo_get_property;
-
-       /**
-        * TipoNodo::aggiornato:
-        * @tipo_nodo:
-        *
-        */
-       klass->aggiornato_signal_id = g_signal_new ("aggiornato",
-                                                      G_TYPE_FROM_CLASS (object_class),
-                                                      G_SIGNAL_RUN_LAST,
-                                                      0,
-                                                      NULL,
-                                                      NULL,
-                                                      g_cclosure_marshal_VOID__VOID,
-                                                      G_TYPE_NONE,
-                                                      0);
-}
-
-static void
-tipo_nodo_init (TipoNodo *tipo_nodo)
-{
-       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
-}
-
-/**
- * tipo_nodo_new:
- * @commons:
- * @id:
- *
- * Returns: the newly created #TipoNodo object.
- */
-TipoNodo
-*tipo_nodo_new (Commons *commons, gint id)
-{
-       GError *error;
-
-       TipoNodo *a = TIPO_NODO (g_object_new (tipo_nodo_get_type (), NULL));
-
-       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (a);
-
-       priv->commons = commons;
-
-       error = NULL;
-       gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
-                                          g_strsplit ("w_tipo_nodo", "|", -1),
-                                          &error);
-       if (error != NULL)
-               {
-                       g_warning ("Errore: %s.", error->message);
-                       return NULL;
-               }
-
-       priv->form = gtk_form_new_from_file (g_build_filename (priv->commons->formdir, "tipo_nodo.form", NULL), priv->commons->gtkbuilder);
-
-       g_object_set (priv->form, "gdaex", priv->commons->gdaex, NULL);
-
-       priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_tipo_nodo"));
-
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
-                                                     "label12",
-                                                     NULL);
-
-       g_signal_connect (priv->w,
-                         "delete-event", G_CALLBACK (tipo_nodo_on_w_tipo_nodo_delete_event), (gpointer *)a);
-
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button27"),
-                         "clicked", G_CALLBACK (tipo_nodo_on_btn_annulla_clicked), (gpointer *)a);
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button28"),
-                         "clicked", G_CALLBACK (tipo_nodo_on_btn_salva_clicked), (gpointer *)a);
-
-       priv->id = id;
-
-       if (priv->id == 0)
-               {
-                       gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), "");
-
-                       gtk_form_set_as_origin (priv->form);
-               }
-       else
-               {
-                       gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), g_strdup_printf ("%d", priv->id));
-                       tipo_nodo_carica (a);
-               }
-
-       return a;
-}
-
-/**
- * tipo_nodo_get_widget:
- * @tipo_nodo:
- *
- */
-GtkWidget
-*tipo_nodo_get_widget (TipoNodo *tipo_nodo)
-{
-       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
-
-       return priv->w;
-}
-
-/* PRIVATE */
-static void
-tipo_nodo_carica (TipoNodo *tipo_nodo)
-{
-       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
-
-       if (gtk_form_fill_from_table (priv->form))
-               {
-               }
-}
-
-static void
-tipo_nodo_salva (TipoNodo *tipo_nodo)
-{
-       GError *error = NULL;
-       gchar *sql;
-       GtkWidget *dialog;
-
-       GDate *da;
-       GDate *a;
-
-       TipoNodoClass *klass = TIPO_NODO_GET_CLASS (tipo_nodo);
-
-       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
-
-       if (!gtk_form_check (priv->form, (priv->id != 0), NULL, TRUE, priv->w, TRUE))
-               {
-                       return;
-               }
-
-       if (priv->id == 0)
-               {
-                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_INSERT);
-               }
-       else
-               {
-                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_UPDATE);
-               }
-
-       if (gdaex_execute (priv->commons->gdaex, sql) == 1)
-               {
-                       g_signal_emit (tipo_nodo, klass->aggiornato_signal_id, 0);
-
-                       gtk_form_set_as_origin (priv->form);
-
-                       if (priv->id == 0)
-                               {
-                                       priv->id = strtol (gtk_label_get_text (GTK_LABEL (priv->objects[LBL_ID])), NULL, 10);
-                               }
-
-                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_INFO,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "Salvataggio eseguito con successo.");
-                       gtk_dialog_run (GTK_DIALOG (dialog));
-                       gtk_widget_destroy (dialog);
-               }
-       else
-               {
-                       if (priv->id == 0)
-                               {
-                                       gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), "");
-                               }
-
-                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                                                        GTK_MESSAGE_WARNING,
-                                                                                        GTK_BUTTONS_OK,
-                                                                                        "Errore durante il salvataggio.");
-                       gtk_dialog_run (GTK_DIALOG (dialog));
-                       gtk_widget_destroy (dialog);
-               }
-}
-
-static void
-tipo_nodo_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
-{
-       TipoNodo *tipo_nodo = TIPO_NODO (object);
-
-       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
-
-       switch (property_id)
-               {
-                       default:
-                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-                               break;
-               }
-}
-
-static void
-tipo_nodo_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
-       TipoNodo *tipo_nodo = TIPO_NODO (object);
-
-       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
-
-       switch (property_id)
-               {
-                       default:
-                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-                               break;
-               }
-}
-
-static gboolean
-tipo_nodo_conferma_chiusura (TipoNodo *tipo_nodo)
-{
-       GtkWidget *dialog;
-
-       gboolean ret;
-
-       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
-
-       ret = TRUE;
-       if (gtk_form_is_changed (priv->form))
-               {
-                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                GTK_MESSAGE_QUESTION,
-                                                GTK_BUTTONS_YES_NO,
-                                                "Sicuro di voler chiudere senza salvare?");
-                       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_NO)
-                               {
-                                       ret = FALSE;
-                               }
-                       gtk_widget_destroy (dialog);
-               }
-
-       return ret;
-}
-
-/* CALLBACK */
-static gboolean
-tipo_nodo_on_w_tipo_nodo_delete_event (GtkWidget *widget,
-                               GdkEvent *event,
-                               gpointer user_data)
-{
-       return !tipo_nodo_conferma_chiusura ((TipoNodo *)user_data);
-}
-
-static void
-tipo_nodo_on_btn_annulla_clicked (GtkButton *button,
-                        gpointer user_data)
-{
-       TipoNodo *tipo_nodo = (TipoNodo *)user_data;
-
-       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
-
-       if (tipo_nodo_conferma_chiusura (tipo_nodo)) gtk_widget_destroy (priv->w);
-}
-
-static void
-tipo_nodo_on_btn_salva_clicked (GtkButton *button,
-                      gpointer user_data)
-{
-       tipo_nodo_salva ((TipoNodo *)user_data);
-}
diff --git a/src/tipo_nodo.h b/src/tipo_nodo.h
deleted file mode 100644 (file)
index 7b29f7d..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/* 
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifndef __TIPO_NODO_H__
-#define __TIPO_NODO_H__
-
-#include <glib.h>
-#include <glib-object.h>
-
-#include <gtk/gtk.h>
-#include <libgdaex.h>
-
-#include "commons.h"
-
-G_BEGIN_DECLS
-
-
-#define TYPE_TIPO_NODO                 (tipo_nodo_get_type ())
-#define TIPO_NODO(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TIPO_NODO, TipoNodo))
-#define TIPO_NODO_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TIPO_NODO, TipoNodoClass))
-#define IS_TIPO_NODO(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TIPO_NODO))
-#define IS_TIPO_NODO_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TIPO_NODO))
-#define TIPO_NODO_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TIPO_NODO, TipoNodoClass))
-
-
-typedef struct _TipoNodo TipoNodo;
-typedef struct _TipoNodoClass TipoNodoClass;
-
-struct _TipoNodo
-       {
-               GObject parent;
-       };
-
-struct _TipoNodoClass
-       {
-               GObjectClass parent_class;
-
-               guint aggiornato_signal_id;
-       };
-
-GType tipo_nodo_get_type (void) G_GNUC_CONST;
-
-TipoNodo *tipo_nodo_new (Commons *commons, gint id);
-
-GtkWidget *tipo_nodo_get_widget (TipoNodo *tipo_nodo);
-
-
-G_END_DECLS
-
-#endif /* __TIPO_NODO_H__ */
diff --git a/src/tiponodo.c b/src/tiponodo.c
new file mode 100644 (file)
index 0000000..6b30c3a
--- /dev/null
@@ -0,0 +1,339 @@
+/* 
+ * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <libgtkform/form.h>
+#include <libgtkform/fielddatetime.h>
+
+#include "tiponodo.h"
+
+static void tipo_nodo_class_init (TipoNodoClass *klass);
+static void tipo_nodo_init (TipoNodo *tipo_nodo);
+
+static void tipo_nodo_carica (TipoNodo *tipo_nodo);
+static void tipo_nodo_salva (TipoNodo *tipo_nodo);
+
+static gboolean tipo_nodo_conferma_chiusura (TipoNodo *tipo_nodo);
+
+static void tipo_nodo_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void tipo_nodo_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+static gboolean tipo_nodo_on_w_tipo_nodo_delete_event (GtkWidget *widget,
+                               GdkEvent *event,
+                               gpointer user_data);
+
+static void tipo_nodo_on_btn_annulla_clicked (GtkButton *button,
+                                    gpointer user_data);
+static void tipo_nodo_on_btn_salva_clicked (GtkButton *button,
+                                  gpointer user_data);
+
+#define TIPO_NODO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TIPO_NODO, TipoNodoPrivate))
+
+enum
+{
+       LBL_ID
+};
+
+typedef struct _TipoNodoPrivate TipoNodoPrivate;
+struct _TipoNodoPrivate
+       {
+               Commons *commons;
+
+               GtkForm *form;
+
+               GtkWidget *w;
+
+               GObject **objects;
+
+               gint id;
+       };
+
+G_DEFINE_TYPE (TipoNodo, tipo_nodo, G_TYPE_OBJECT)
+
+static void
+tipo_nodo_class_init (TipoNodoClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (TipoNodoPrivate));
+
+       object_class->set_property = tipo_nodo_set_property;
+       object_class->get_property = tipo_nodo_get_property;
+
+       /**
+        * TipoNodo::aggiornato:
+        * @tipo_nodo:
+        *
+        */
+       klass->aggiornato_signal_id = g_signal_new ("aggiornato",
+                                                      G_TYPE_FROM_CLASS (object_class),
+                                                      G_SIGNAL_RUN_LAST,
+                                                      0,
+                                                      NULL,
+                                                      NULL,
+                                                      g_cclosure_marshal_VOID__VOID,
+                                                      G_TYPE_NONE,
+                                                      0);
+}
+
+static void
+tipo_nodo_init (TipoNodo *tipo_nodo)
+{
+       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
+}
+
+/**
+ * tipo_nodo_new:
+ * @commons:
+ * @id:
+ *
+ * Returns: the newly created #TipoNodo object.
+ */
+TipoNodo
+*tipo_nodo_new (Commons *commons, gint id)
+{
+       GError *error;
+
+       TipoNodo *a = TIPO_NODO (g_object_new (tipo_nodo_get_type (), NULL));
+
+       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (a);
+
+       priv->commons = commons;
+
+       error = NULL;
+       gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
+                                          g_strsplit ("w_tipo_nodo", "|", -1),
+                                          &error);
+       if (error != NULL)
+               {
+                       g_warning ("Errore: %s.", error->message);
+                       return NULL;
+               }
+
+       priv->form = gtk_form_new_from_file (g_build_filename (priv->commons->formdir, "tipo_nodo.form", NULL), priv->commons->gtkbuilder);
+
+       g_object_set (priv->form, "gdaex", priv->commons->gdaex, NULL);
+
+       priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_tipo_nodo"));
+
+       priv->objects = gtk_form_get_objects_by_name (priv->form,
+                                                     "label12",
+                                                     NULL);
+
+       g_signal_connect (priv->w,
+                         "delete-event", G_CALLBACK (tipo_nodo_on_w_tipo_nodo_delete_event), (gpointer *)a);
+
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button8"),
+                         "clicked", G_CALLBACK (tipo_nodo_on_btn_annulla_clicked), (gpointer *)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button9"),
+                         "clicked", G_CALLBACK (tipo_nodo_on_btn_salva_clicked), (gpointer *)a);
+
+       priv->id = id;
+
+       if (priv->id == 0)
+               {
+                       gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), "");
+
+                       gtk_form_set_as_origin (priv->form);
+               }
+       else
+               {
+                       gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), g_strdup_printf ("%d", priv->id));
+                       tipo_nodo_carica (a);
+               }
+
+       return a;
+}
+
+/**
+ * tipo_nodo_get_widget:
+ * @tipo_nodo:
+ *
+ */
+GtkWidget
+*tipo_nodo_get_widget (TipoNodo *tipo_nodo)
+{
+       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
+
+       return priv->w;
+}
+
+/* PRIVATE */
+static void
+tipo_nodo_carica (TipoNodo *tipo_nodo)
+{
+       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
+
+       if (gtk_form_fill_from_table (priv->form))
+               {
+               }
+}
+
+static void
+tipo_nodo_salva (TipoNodo *tipo_nodo)
+{
+       GError *error = NULL;
+       gchar *sql;
+       GtkWidget *dialog;
+
+       GDate *da;
+       GDate *a;
+
+       TipoNodoClass *klass = TIPO_NODO_GET_CLASS (tipo_nodo);
+
+       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
+
+       if (!gtk_form_check (priv->form, (priv->id != 0), NULL, TRUE, priv->w, TRUE))
+               {
+                       return;
+               }
+
+       if (priv->id == 0)
+               {
+                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_INSERT);
+               }
+       else
+               {
+                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_UPDATE);
+               }
+
+       if (gdaex_execute (priv->commons->gdaex, sql) == 1)
+               {
+                       g_signal_emit (tipo_nodo, klass->aggiornato_signal_id, 0);
+
+                       gtk_form_set_as_origin (priv->form);
+
+                       if (priv->id == 0)
+                               {
+                                       priv->id = strtol (gtk_label_get_text (GTK_LABEL (priv->objects[LBL_ID])), NULL, 10);
+                               }
+
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                        GTK_MESSAGE_INFO,
+                                                                                        GTK_BUTTONS_OK,
+                                                                                        "Salvataggio eseguito con successo.");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+       else
+               {
+                       if (priv->id == 0)
+                               {
+                                       gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), "");
+                               }
+
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                        GTK_MESSAGE_WARNING,
+                                                                                        GTK_BUTTONS_OK,
+                                                                                        "Errore durante il salvataggio.");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+}
+
+static void
+tipo_nodo_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       TipoNodo *tipo_nodo = TIPO_NODO (object);
+
+       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+tipo_nodo_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       TipoNodo *tipo_nodo = TIPO_NODO (object);
+
+       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static gboolean
+tipo_nodo_conferma_chiusura (TipoNodo *tipo_nodo)
+{
+       GtkWidget *dialog;
+
+       gboolean ret;
+
+       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
+
+       ret = TRUE;
+       if (gtk_form_is_changed (priv->form))
+               {
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+                                                GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                GTK_MESSAGE_QUESTION,
+                                                GTK_BUTTONS_YES_NO,
+                                                "Sicuro di voler chiudere senza salvare?");
+                       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_NO)
+                               {
+                                       ret = FALSE;
+                               }
+                       gtk_widget_destroy (dialog);
+               }
+
+       return ret;
+}
+
+/* CALLBACK */
+static gboolean
+tipo_nodo_on_w_tipo_nodo_delete_event (GtkWidget *widget,
+                               GdkEvent *event,
+                               gpointer user_data)
+{
+       return !tipo_nodo_conferma_chiusura ((TipoNodo *)user_data);
+}
+
+static void
+tipo_nodo_on_btn_annulla_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       TipoNodo *tipo_nodo = (TipoNodo *)user_data;
+
+       TipoNodoPrivate *priv = TIPO_NODO_GET_PRIVATE (tipo_nodo);
+
+       if (tipo_nodo_conferma_chiusura (tipo_nodo)) gtk_widget_destroy (priv->w);
+}
+
+static void
+tipo_nodo_on_btn_salva_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       tipo_nodo_salva ((TipoNodo *)user_data);
+}
diff --git a/src/tiponodo.h b/src/tiponodo.h
new file mode 100644 (file)
index 0000000..7b29f7d
--- /dev/null
@@ -0,0 +1,66 @@
+/* 
+ * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __TIPO_NODO_H__
+#define __TIPO_NODO_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+#include <libgdaex.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_TIPO_NODO                 (tipo_nodo_get_type ())
+#define TIPO_NODO(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TIPO_NODO, TipoNodo))
+#define TIPO_NODO_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TIPO_NODO, TipoNodoClass))
+#define IS_TIPO_NODO(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TIPO_NODO))
+#define IS_TIPO_NODO_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TIPO_NODO))
+#define TIPO_NODO_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TIPO_NODO, TipoNodoClass))
+
+
+typedef struct _TipoNodo TipoNodo;
+typedef struct _TipoNodoClass TipoNodoClass;
+
+struct _TipoNodo
+       {
+               GObject parent;
+       };
+
+struct _TipoNodoClass
+       {
+               GObjectClass parent_class;
+
+               guint aggiornato_signal_id;
+       };
+
+GType tipo_nodo_get_type (void) G_GNUC_CONST;
+
+TipoNodo *tipo_nodo_new (Commons *commons, gint id);
+
+GtkWidget *tipo_nodo_get_widget (TipoNodo *tipo_nodo);
+
+
+G_END_DECLS
+
+#endif /* __TIPO_NODO_H__ */