From 95a69e2b42110cf4f53b16d9bbf66bdaffa0f2d0 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Tue, 24 Aug 2010 13:31:38 +0200 Subject: [PATCH] Gestione province. --- data/territorio/form/Makefile.am | 1 + data/territorio/form/provincia.form | 25 ++ data/territorio/gui/territorio.gui | 29 ++ src/Makefile.am | 4 + src/main.c | 14 + src/province.c | 445 ++++++++++++++++++++++++++++ src/province.h | 66 +++++ src/provincia.c | 338 +++++++++++++++++++++ src/provincia.h | 66 +++++ 9 files changed, 988 insertions(+) create mode 100644 data/territorio/form/provincia.form create mode 100644 src/province.c create mode 100644 src/province.h create mode 100644 src/provincia.c create mode 100644 src/provincia.h diff --git a/data/territorio/form/Makefile.am b/data/territorio/form/Makefile.am index 5fffa4b..8ffaa85 100644 --- a/data/territorio/form/Makefile.am +++ b/data/territorio/form/Makefile.am @@ -1,6 +1,7 @@ formdir = $(datadir)/$(PACKAGE)/form form_DATA = \ + provincia.form \ regione.form \ stato.form diff --git a/data/territorio/form/provincia.form b/data/territorio/form/provincia.form new file mode 100644 index 0000000..fd38096 --- /dev/null +++ b/data/territorio/form/provincia.form @@ -0,0 +1,25 @@ + + + + province
+ + + + t + t + + + + + + + + + + + + + + + +
diff --git a/data/territorio/gui/territorio.gui b/data/territorio/gui/territorio.gui index 0f60ffe..09af86f 100644 --- a/data/territorio/gui/territorio.gui +++ b/data/territorio/gui/territorio.gui @@ -60,6 +60,14 @@ + + + True + _Province + True + + + True @@ -92,6 +100,7 @@ True True True + @@ -317,6 +326,14 @@ + + + + + + + + Stato - Territorio True @@ -862,6 +879,18 @@ True True + lstore_province + + + Nome + + + + 1 + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 32aa8a1..e62efbd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,10 @@ bin_PROGRAMS = territorio territorio_SOURCES = \ commons.h \ main.c \ + province.c \ + province.h \ + provincia.c \ + provincia.h \ regione.c \ regione.h \ regioni.c \ diff --git a/src/main.c b/src/main.c index ea1499b..b38bc2f 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ #include #include "commons.h" +#include "province.h" #include "regioni.h" #include "stati.h" @@ -78,6 +79,19 @@ on_mnu_view_regioni_activate (GtkMenuItem *menuitem, 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) diff --git a/src/province.c b/src/province.c new file mode 100644 index 0000000..99bfb2d --- /dev/null +++ b/src/province.c @@ -0,0 +1,445 @@ +/* + * Copyright (C) 2010 Andrea Zagli + * + * 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); +} diff --git a/src/province.h b/src/province.h new file mode 100644 index 0000000..5c3da36 --- /dev/null +++ b/src/province.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2010 Andrea Zagli + * + * 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 +#include + +#include +#include + +#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__ */ diff --git a/src/provincia.c b/src/provincia.c new file mode 100644 index 0000000..fb7fcc1 --- /dev/null +++ b/src/provincia.c @@ -0,0 +1,338 @@ +/* + * Copyright (C) 2010 Andrea Zagli + * + * 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 + +#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); +} diff --git a/src/provincia.h b/src/provincia.h new file mode 100644 index 0000000..bd8db4d --- /dev/null +++ b/src/provincia.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2010 Andrea Zagli + * + * 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 +#include + +#include +#include + +#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__ */ -- 2.49.0