formdir = $(datadir)/$(PACKAGE)/form
form_DATA = \
+ provincia.form \
regione.form \
stato.form
--- /dev/null
+<?xml version="1.0"?>
+<gtkform>
+
+ <table>province</table>
+
+ <widget type="label" name="label16" label="label14">
+ <field type="integer" name="id">
+ <is-key>t</is-key>
+ <auto-increment>t</auto-increment>
+ </field>
+ </widget>
+
+ <widget type="entry" name="entry6" label="label17">
+ <field type="text" name="nome" />
+ </widget>
+
+ <widget type="entry" name="entry7" label="label18">
+ <field type="text" name="cod_istat" />
+ </widget>
+
+ <widget type="entry" name="entry9" label="label19">
+ <field type="text" name="sigla" />
+ </widget>
+
+</gtkform>
<signal name="activate" handler="on_mnu_view_regioni_activate"/>
</object>
</child>
+ <child>
+ <object class="GtkMenuItem" id="menuitem8">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Province</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_mnu_view_province_activate"/>
+ </object>
+ </child>
<child>
<object class="GtkMenuItem" id="menuitem6">
<property name="visible">True</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
+ <signal name="activate" handler="on_mnu_help_about_activate"/>
</object>
</child>
</object>
<column type="gchararray"/>
</columns>
</object>
+ <object class="GtkListStore" id="lstore_province">
+ <columns>
+ <!-- column-name id -->
+ <column type="guint"/>
+ <!-- column-name nome -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkWindow" id="w_stato">
<property name="title" translatable="yes">Stato - Territorio</property>
<property name="modal">True</property>
<object class="GtkTreeView" id="treeview3">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="model">lstore_province</property>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn3">
+ <property name="title">Nome</property>
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderertext3"/>
+ <attributes>
+ <attribute name="text">1</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
territorio_SOURCES = \
commons.h \
main.c \
+ province.c \
+ province.h \
+ provincia.c \
+ provincia.h \
regione.c \
regione.h \
regioni.c \
#include <libgdaex.h>
#include "commons.h"
+#include "province.h"
#include "regioni.h"
#include "stati.h"
main_set_vbx_body_child (vbx);
}
+G_MODULE_EXPORT void
+on_mnu_view_province_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ GtkWidget *vbx;
+
+ Province *m = province_new (commons, FALSE);
+
+ vbx = province_get_widget (m);
+
+ main_set_vbx_body_child (vbx);
+}
+
G_MODULE_EXPORT void
on_mnu_help_about_activate (GtkMenuItem *menuitem,
gpointer user_data)
--- /dev/null
+/*
+ * 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 "province.h"
+#include "provincia.h"
+
+static void province_class_init (ProvinceClass *klass);
+static void province_init (Province *province);
+
+static void province_carica (Province *province);
+static void province_modifica (Province *province);
+
+static void province_selezionato (Province *province);
+static void province_on_provincia_aggiornato (gpointer instance, gpointer user_data);
+
+static void province_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void province_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static void province_on_btn_nuovo_clicked (GtkButton *button,
+ gpointer user_data);
+static void province_on_btn_modifica_clicked (GtkButton *button,
+ gpointer user_data);
+static void province_on_btn_elimina_clicked (GtkButton *button,
+ gpointer user_data);
+static void province_on_trv_province_row_activated (GtkTreeView *tree_view,
+ GtkTreePath *tree_path,
+ GtkTreeViewColumn *column,
+ gpointer user_data);
+
+static void province_on_btn_annulla_clicked (GtkButton *button,
+ gpointer user_data);
+static void province_on_btn_seleziona_clicked (GtkButton *button,
+ gpointer user_data);
+
+#define PROVINCE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_PROVINCE, ProvincePrivate))
+
+enum
+{
+ COL_ID,
+ COL_NOME
+};
+
+typedef struct _ProvincePrivate ProvincePrivate;
+struct _ProvincePrivate
+ {
+ Commons *commons;
+
+ GtkWidget *widget;
+ GtkTreeSelection *selection;
+ GtkListStore *lstore_province;
+
+ gboolean selezione;
+ GtkWindow *wtransient;
+ };
+
+G_DEFINE_TYPE (Province, province, G_TYPE_OBJECT)
+
+static void
+province_class_init (ProvinceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (ProvincePrivate));
+
+ object_class->set_property = province_set_property;
+ object_class->get_property = province_get_property;
+
+ /**
+ * Province::selezionato:
+ * @province:
+ *
+ */
+ 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
+province_init (Province *province)
+{
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE (province);
+}
+
+/**
+ * province_new:
+ * @commons:
+ * @selezione:
+ *
+ * Returns: the newly created #Province object.
+ */
+Province
+*province_new (Commons *commons, gboolean selezione)
+{
+ GError *error;
+
+ Province *a = PROVINCE (g_object_new (province_get_type (), NULL));
+
+ ProvincePrivate *priv = PROVINCE_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_province|",
+ (selezione ? "w_province" : "vbox6"),
+ 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_province" : "vbox6")));
+ priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview3")));
+ priv->lstore_province = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_province"));
+
+ if (priv->selezione)
+ {
+ priv->wtransient = GTK_WINDOW (priv->widget);
+ }
+ else
+ {
+ priv->wtransient = GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main"));
+ }
+
+ g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button15"),
+ "clicked", G_CALLBACK (province_on_btn_nuovo_clicked), (gpointer)a);
+ g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button16"),
+ "clicked", G_CALLBACK (province_on_btn_modifica_clicked), (gpointer)a);
+ g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button17"),
+ "clicked", G_CALLBACK (province_on_btn_elimina_clicked), (gpointer)a);
+ g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview3"),
+ "row-activated", G_CALLBACK (province_on_trv_province_row_activated), (gpointer)a);
+
+ if (priv->selezione)
+ {
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "label13")));
+ g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button18"),
+ "clicked", G_CALLBACK (province_on_btn_annulla_clicked), (gpointer)a);
+ g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button19"),
+ "clicked", G_CALLBACK (province_on_btn_seleziona_clicked), (gpointer)a);
+ }
+ else
+ {
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button18")));
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button19")));
+ }
+
+ province_carica (a);
+
+ return a;
+}
+
+/**
+ * province_get_widget:
+ * @province:
+ *
+ */
+GtkWidget
+*province_get_widget (Province *province)
+{
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE (province);
+
+ return priv->widget;
+}
+
+/* PRIVATE */
+static void
+province_carica (Province *province)
+{
+ GtkTreeIter iter;
+ GdaDataModel *dm;
+
+ gint rows;
+ gint row;
+
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE (province);
+
+ gtk_list_store_clear (priv->lstore_province);
+
+ dm = gdaex_query (priv->commons->gdaex,
+ "SELECT c.id, c.nome"
+ " FROM province AS c"
+ " WHERE c.status <> 'E'"
+ " ORDER BY c.nome");
+ if (dm != NULL)
+ {
+ rows = gda_data_model_get_n_rows (dm);
+ for (row = 0; row < rows; row++)
+ {
+ gtk_list_store_append (priv->lstore_province, &iter);
+
+ gtk_list_store_set (priv->lstore_province, &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
+province_modifica (Province *province)
+{
+ GtkTreeIter iter;
+ guint id;
+
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE (province);
+
+ if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
+ {
+ GtkWidget *w;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_province), &iter,
+ COL_ID, &id,
+ -1);
+
+ Provincia *c = provincia_new (priv->commons, id);
+
+ g_signal_connect (G_OBJECT (c), "aggiornato",
+ G_CALLBACK (province_on_provincia_aggiornato), (gpointer)province);
+
+ w = provincia_get_widget (c);
+ gtk_window_set_transient_for (GTK_WINDOW (w), priv->wtransient);
+ gtk_widget_show (w);
+ }
+ else
+ {
+ GtkWidget *dialog = gtk_message_dialog_new (priv->wtransient,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Occorre prima selezionare una provincia");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+}
+
+static void
+province_selezionato (Province *province)
+{
+ GtkTreeIter iter;
+ guint *id;
+
+ ProvinceClass *klass = PROVINCE_GET_CLASS (province);
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE (province);
+
+ if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_province), &iter,
+ COL_ID, &id,
+ -1);
+
+ g_signal_emit (G_OBJECT (province), klass->selezionato_signal_id, 0, id);
+
+ gtk_widget_destroy (priv->widget);
+ g_object_unref (G_OBJECT (province));
+ }
+ else
+ {
+ GtkWidget *dialog = gtk_message_dialog_new (priv->wtransient,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Occorre prima selezionare una provincia");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+}
+
+static void
+province_on_provincia_aggiornato (gpointer instance, gpointer user_data)
+{
+ province_carica ((Province *)user_data);
+}
+
+static void
+province_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ Province *province = PROVINCE (object);
+
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE (province);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+province_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ Province *province = PROVINCE (object);
+
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE (province);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+/* CALLBACK */
+static void
+province_on_btn_nuovo_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkWidget *w;
+
+ Province *province = (Province *)user_data;
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE (province);
+
+ Provincia *c = provincia_new (priv->commons, 0);
+
+ g_signal_connect (G_OBJECT (c), "aggiornato",
+ G_CALLBACK (province_on_provincia_aggiornato), (gpointer)province);
+
+ w = provincia_get_widget (c);
+ gtk_window_set_transient_for (GTK_WINDOW (w), priv->wtransient);
+ gtk_widget_show (w);
+}
+
+static void
+province_on_btn_modifica_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ province_modifica ((Province *)user_data);
+}
+
+static void
+province_on_btn_elimina_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkWidget *dialog;
+ gboolean risp;
+
+ GtkTreeIter iter;
+ guint id;
+
+ Province *province = (Province *)user_data;
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE (province);
+
+ if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
+ {
+ dialog = gtk_message_dialog_new (priv->wtransient,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ "Sicuro di voler eliminare la provincia selezionata?");
+ risp = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (risp == GTK_RESPONSE_YES)
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_province), &iter,
+ COL_ID, &id,
+ -1);
+
+ gdaex_execute (priv->commons->gdaex,
+ g_strdup_printf ("UPDATE province SET status = 'E' WHERE id = %d", id));
+
+ province_carica (province);
+ }
+ gtk_widget_destroy (dialog);
+ }
+ else
+ {
+ dialog = gtk_message_dialog_new (priv->wtransient,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Occorre prima selezionare una provincia");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+}
+
+static void
+province_on_trv_province_row_activated (GtkTreeView *tree_view,
+ GtkTreePath *tree_path,
+ GtkTreeViewColumn *column,
+ gpointer user_data)
+{
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE ((Province *)user_data);
+
+ if (priv->selezione)
+ {
+ province_selezionato ((Province *)user_data);
+ }
+ else
+ {
+ province_modifica ((Province *)user_data);
+ }
+}
+
+
+static void
+province_on_btn_annulla_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ ProvincePrivate *priv = PROVINCE_GET_PRIVATE ((Province *)user_data);
+
+ gtk_widget_destroy (priv->widget);
+ g_object_unref (G_OBJECT (user_data));
+}
+
+static void
+province_on_btn_seleziona_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ province_selezionato ((Province *)user_data);
+}
--- /dev/null
+/*
+ * 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 __PROVINCE_H__
+#define __PROVINCE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+#include <libgdaex.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_PROVINCE (province_get_type ())
+#define PROVINCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PROVINCE, Province))
+#define PROVINCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PROVINCE, ProvinceClass))
+#define IS_PROVINCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PROVINCE))
+#define IS_PROVINCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PROVINCE))
+#define PROVINCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PROVINCE, ProvinceClass))
+
+
+typedef struct _Province Province;
+typedef struct _ProvinceClass ProvinceClass;
+
+struct _Province
+ {
+ GObject parent;
+ };
+
+struct _ProvinceClass
+ {
+ GObjectClass parent_class;
+
+ guint selezionato_signal_id;
+ };
+
+GType province_get_type (void) G_GNUC_CONST;
+
+Province *province_new (Commons *commons, gboolean selezione);
+
+GtkWidget *province_get_widget (Province *province);
+
+
+G_END_DECLS
+
+#endif /* __PROVINCE_H__ */
--- /dev/null
+/*
+ * 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 "provincia.h"
+
+static void provincia_class_init (ProvinciaClass *klass);
+static void provincia_init (Provincia *provincia);
+
+static void provincia_carica (Provincia *provincia);
+static void provincia_salva (Provincia *provincia);
+
+static gboolean provincia_conferma_chiusura (Provincia *provincia);
+
+static void provincia_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void provincia_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static gboolean provincia_on_w_provincia_delete_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data);
+
+static void provincia_on_btn_annulla_clicked (GtkButton *button,
+ gpointer user_data);
+static void provincia_on_btn_salva_clicked (GtkButton *button,
+ gpointer user_data);
+
+#define PROVINCIA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_PROVINCIA, ProvinciaPrivate))
+
+enum
+{
+ LBL_ID
+};
+
+typedef struct _ProvinciaPrivate ProvinciaPrivate;
+struct _ProvinciaPrivate
+ {
+ Commons *commons;
+
+ GtkForm *form;
+
+ GtkWidget *w;
+
+ GObject **objects;
+
+ gint id;
+ };
+
+G_DEFINE_TYPE (Provincia, provincia, G_TYPE_OBJECT)
+
+static void
+provincia_class_init (ProvinciaClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (ProvinciaPrivate));
+
+ object_class->set_property = provincia_set_property;
+ object_class->get_property = provincia_get_property;
+
+ /**
+ * Provincia::aggiornato:
+ * @provincia:
+ *
+ */
+ 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
+provincia_init (Provincia *provincia)
+{
+ ProvinciaPrivate *priv = PROVINCIA_GET_PRIVATE (provincia);
+}
+
+/**
+ * provincia_new:
+ * @commons:
+ * @id:
+ *
+ * Returns: the newly created #Provincia object.
+ */
+Provincia
+*provincia_new (Commons *commons, gint id)
+{
+ GError *error;
+
+ Provincia *a = PROVINCIA (g_object_new (provincia_get_type (), NULL));
+
+ ProvinciaPrivate *priv = PROVINCIA_GET_PRIVATE (a);
+
+ priv->commons = commons;
+
+ error = NULL;
+ gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
+ g_strsplit (g_strconcat ("w_provincia", NULL), "|", -1),
+ &error);
+ if (error != NULL)
+ {
+ g_warning ("Errore: %s.", error->message);
+ 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, "provincia.form", NULL), priv->commons->gtkbuilder);
+
+ priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_provincia"));
+
+ priv->objects = gtk_form_get_objects_by_name (priv->form,
+ "label16",
+ NULL);
+
+ g_signal_connect (priv->w,
+ "delete-event", G_CALLBACK (provincia_on_w_provincia_delete_event), (gpointer *)a);
+
+ g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button20"),
+ "clicked", G_CALLBACK (provincia_on_btn_annulla_clicked), (gpointer *)a);
+ g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button21"),
+ "clicked", G_CALLBACK (provincia_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));
+ provincia_carica (a);
+ }
+
+ return a;
+}
+
+/**
+ * provincia_get_widget:
+ * @provincia:
+ *
+ */
+GtkWidget
+*provincia_get_widget (Provincia *provincia)
+{
+ ProvinciaPrivate *priv = PROVINCIA_GET_PRIVATE (provincia);
+
+ return priv->w;
+}
+
+/* PRIVATE */
+static void
+provincia_carica (Provincia *provincia)
+{
+ ProvinciaPrivate *priv = PROVINCIA_GET_PRIVATE (provincia);
+
+ if (gtk_form_fill_from_table (priv->form))
+ {
+ }
+}
+
+static void
+provincia_salva (Provincia *provincia)
+{
+ GError *error = NULL;
+ gchar *sql;
+ GtkWidget *dialog;
+
+ GDate *da;
+ GDate *a;
+
+ ProvinciaClass *klass = PROVINCIA_GET_CLASS (provincia);
+
+ ProvinciaPrivate *priv = PROVINCIA_GET_PRIVATE (provincia);
+
+ 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 (provincia, 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
+provincia_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ Provincia *provincia = PROVINCIA (object);
+
+ ProvinciaPrivate *priv = PROVINCIA_GET_PRIVATE (provincia);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+provincia_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ Provincia *provincia = PROVINCIA (object);
+
+ ProvinciaPrivate *priv = PROVINCIA_GET_PRIVATE (provincia);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static gboolean
+provincia_conferma_chiusura (Provincia *provincia)
+{
+ GtkWidget *dialog;
+
+ gboolean ret;
+
+ ProvinciaPrivate *priv = PROVINCIA_GET_PRIVATE (provincia);
+
+ 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
+provincia_on_w_provincia_delete_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ return !provincia_conferma_chiusura ((Provincia *)user_data);
+}
+
+static void
+provincia_on_btn_annulla_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ Provincia *provincia = (Provincia *)user_data;
+
+ ProvinciaPrivate *priv = PROVINCIA_GET_PRIVATE (provincia);
+
+ if (provincia_conferma_chiusura (provincia)) gtk_widget_destroy (priv->w);
+}
+
+static void
+provincia_on_btn_salva_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ provincia_salva ((Provincia *)user_data);
+}
--- /dev/null
+/*
+ * 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 __PROVINCIA_H__
+#define __PROVINCIA_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+#include <libgdaex.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_PROVINCIA (provincia_get_type ())
+#define PROVINCIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PROVINCIA, Provincia))
+#define PROVINCIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PROVINCIA, ProvinciaClass))
+#define IS_PROVINCIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PROVINCIA))
+#define IS_PROVINCIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PROVINCIA))
+#define PROVINCIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PROVINCIA, ProvinciaClass))
+
+
+typedef struct _Provincia Provincia;
+typedef struct _ProvinciaClass ProvinciaClass;
+
+struct _Provincia
+ {
+ GObject parent;
+ };
+
+struct _ProvinciaClass
+ {
+ GObjectClass parent_class;
+
+ guint aggiornato_signal_id;
+ };
+
+GType provincia_get_type (void) G_GNUC_CONST;
+
+Provincia *provincia_new (Commons *commons, gint id);
+
+GtkWidget *provincia_get_widget (Provincia *provincia);
+
+
+G_END_DECLS
+
+#endif /* __PROVINCIA_H__ */