From: Andrea Zagli Date: Tue, 24 Aug 2010 11:21:17 +0000 (+0200) Subject: Gestione regioni. X-Git-Tag: 0.0.1~6 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=da6c94f78dd698d5cdd65ba982cb15a2de232f7c;p=solipa%2Fterritorio Gestione regioni. --- diff --git a/data/territorio/form/Makefile.am b/data/territorio/form/Makefile.am index 68358ca..5fffa4b 100644 --- a/data/territorio/form/Makefile.am +++ b/data/territorio/form/Makefile.am @@ -1,6 +1,7 @@ formdir = $(datadir)/$(PACKAGE)/form form_DATA = \ + regione.form \ stato.form EXTRA_DIST = $(form_DATA) diff --git a/data/territorio/form/regione.form b/data/territorio/form/regione.form new file mode 100644 index 0000000..934f803 --- /dev/null +++ b/data/territorio/form/regione.form @@ -0,0 +1,21 @@ + + + + regioni
+ + + + t + t + + + + + + + + + + + +
diff --git a/data/territorio/gui/territorio.gui b/data/territorio/gui/territorio.gui index 2bd1907..0f60ffe 100644 --- a/data/territorio/gui/territorio.gui +++ b/data/territorio/gui/territorio.gui @@ -57,6 +57,7 @@ True _Regioni True + @@ -308,6 +309,14 @@ + + + + + + + + Stato - Territorio True @@ -571,6 +580,18 @@ True True + lstore_regioni + + + Nome + + + + 1 + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 5e62358..32aa8a1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,10 @@ bin_PROGRAMS = territorio territorio_SOURCES = \ commons.h \ main.c \ + regione.c \ + regione.h \ + regioni.c \ + regioni.h \ stati.c \ stati.h \ stato.c \ diff --git a/src/main.c b/src/main.c index fc489dc..ea1499b 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ #include #include "commons.h" +#include "regioni.h" #include "stati.h" static Commons *commons; @@ -64,6 +65,19 @@ on_mnu_view_stati_activate (GtkMenuItem *menuitem, main_set_vbx_body_child (vbx); } +G_MODULE_EXPORT void +on_mnu_view_regioni_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkWidget *vbx; + + Regioni *m = regioni_new (commons, FALSE); + + vbx = regioni_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/regione.c b/src/regione.c new file mode 100644 index 0000000..315a4ad --- /dev/null +++ b/src/regione.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 "regione.h" + +static void regione_class_init (RegioneClass *klass); +static void regione_init (Regione *regione); + +static void regione_carica (Regione *regione); +static void regione_salva (Regione *regione); + +static gboolean regione_conferma_chiusura (Regione *regione); + +static void regione_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void regione_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean regione_on_w_regione_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data); + +static void regione_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data); +static void regione_on_btn_salva_clicked (GtkButton *button, + gpointer user_data); + +#define REGIONE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_REGIONE, RegionePrivate)) + +enum +{ + LBL_ID +}; + +typedef struct _RegionePrivate RegionePrivate; +struct _RegionePrivate + { + Commons *commons; + + GtkForm *form; + + GtkWidget *w; + + GObject **objects; + + gint id; + }; + +G_DEFINE_TYPE (Regione, regione, G_TYPE_OBJECT) + +static void +regione_class_init (RegioneClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (RegionePrivate)); + + object_class->set_property = regione_set_property; + object_class->get_property = regione_get_property; + + /** + * Regione::aggiornato: + * @regione: + * + */ + 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 +regione_init (Regione *regione) +{ + RegionePrivate *priv = REGIONE_GET_PRIVATE (regione); +} + +/** + * regione_new: + * @commons: + * @id: + * + * Returns: the newly created #Regione object. + */ +Regione +*regione_new (Commons *commons, gint id) +{ + GError *error; + + Regione *a = REGIONE (g_object_new (regione_get_type (), NULL)); + + RegionePrivate *priv = REGIONE_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_regione", 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, "regione.form", NULL), priv->commons->gtkbuilder); + + priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_regione")); + + priv->objects = gtk_form_get_objects_by_name (priv->form, + "label11", + NULL); + + g_signal_connect (priv->w, + "delete-event", G_CALLBACK (regione_on_w_regione_delete_event), (gpointer *)a); + + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button13"), + "clicked", G_CALLBACK (regione_on_btn_annulla_clicked), (gpointer *)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button14"), + "clicked", G_CALLBACK (regione_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)); + regione_carica (a); + } + + return a; +} + +/** + * regione_get_widget: + * @regione: + * + */ +GtkWidget +*regione_get_widget (Regione *regione) +{ + RegionePrivate *priv = REGIONE_GET_PRIVATE (regione); + + return priv->w; +} + +/* PRIVATE */ +static void +regione_carica (Regione *regione) +{ + RegionePrivate *priv = REGIONE_GET_PRIVATE (regione); + + if (gtk_form_fill_from_table (priv->form)) + { + } +} + +static void +regione_salva (Regione *regione) +{ + GError *error = NULL; + gchar *sql; + GtkWidget *dialog; + + GDate *da; + GDate *a; + + RegioneClass *klass = REGIONE_GET_CLASS (regione); + + RegionePrivate *priv = REGIONE_GET_PRIVATE (regione); + + 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 (regione, 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 +regione_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + Regione *regione = REGIONE (object); + + RegionePrivate *priv = REGIONE_GET_PRIVATE (regione); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +regione_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + Regione *regione = REGIONE (object); + + RegionePrivate *priv = REGIONE_GET_PRIVATE (regione); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +regione_conferma_chiusura (Regione *regione) +{ + GtkWidget *dialog; + + gboolean ret; + + RegionePrivate *priv = REGIONE_GET_PRIVATE (regione); + + 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 +regione_on_w_regione_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + return !regione_conferma_chiusura ((Regione *)user_data); +} + +static void +regione_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data) +{ + Regione *regione = (Regione *)user_data; + + RegionePrivate *priv = REGIONE_GET_PRIVATE (regione); + + if (regione_conferma_chiusura (regione)) gtk_widget_destroy (priv->w); +} + +static void +regione_on_btn_salva_clicked (GtkButton *button, + gpointer user_data) +{ + regione_salva ((Regione *)user_data); +} diff --git a/src/regione.h b/src/regione.h new file mode 100644 index 0000000..4c2e8a7 --- /dev/null +++ b/src/regione.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 __REGIONE_H__ +#define __REGIONE_H__ + +#include +#include + +#include +#include + +#include "commons.h" + +G_BEGIN_DECLS + + +#define TYPE_REGIONE (regione_get_type ()) +#define REGIONE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_REGIONE, Regione)) +#define REGIONE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_REGIONE, RegioneClass)) +#define IS_REGIONE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_REGIONE)) +#define IS_REGIONE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_REGIONE)) +#define REGIONE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_REGIONE, RegioneClass)) + + +typedef struct _Regione Regione; +typedef struct _RegioneClass RegioneClass; + +struct _Regione + { + GObject parent; + }; + +struct _RegioneClass + { + GObjectClass parent_class; + + guint aggiornato_signal_id; + }; + +GType regione_get_type (void) G_GNUC_CONST; + +Regione *regione_new (Commons *commons, gint id); + +GtkWidget *regione_get_widget (Regione *regione); + + +G_END_DECLS + +#endif /* __REGIONE_H__ */ diff --git a/src/regioni.c b/src/regioni.c new file mode 100644 index 0000000..7a5746b --- /dev/null +++ b/src/regioni.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 "regioni.h" +#include "regione.h" + +static void regioni_class_init (RegioniClass *klass); +static void regioni_init (Regioni *regioni); + +static void regioni_carica (Regioni *regioni); +static void regioni_modifica (Regioni *regioni); + +static void regioni_selezionato (Regioni *regioni); +static void regioni_on_regione_aggiornato (gpointer instance, gpointer user_data); + +static void regioni_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void regioni_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void regioni_on_btn_nuovo_clicked (GtkButton *button, + gpointer user_data); +static void regioni_on_btn_modifica_clicked (GtkButton *button, + gpointer user_data); +static void regioni_on_btn_elimina_clicked (GtkButton *button, + gpointer user_data); +static void regioni_on_trv_regioni_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data); + +static void regioni_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data); +static void regioni_on_btn_seleziona_clicked (GtkButton *button, + gpointer user_data); + +#define REGIONI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_REGIONI, RegioniPrivate)) + +enum +{ + COL_ID, + COL_NOME +}; + +typedef struct _RegioniPrivate RegioniPrivate; +struct _RegioniPrivate + { + Commons *commons; + + GtkWidget *widget; + GtkTreeSelection *selection; + GtkListStore *lstore_regioni; + + gboolean selezione; + GtkWindow *wtransient; + }; + +G_DEFINE_TYPE (Regioni, regioni, G_TYPE_OBJECT) + +static void +regioni_class_init (RegioniClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (RegioniPrivate)); + + object_class->set_property = regioni_set_property; + object_class->get_property = regioni_get_property; + + /** + * Regioni::selezionato: + * @regioni: + * + */ + 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 +regioni_init (Regioni *regioni) +{ + RegioniPrivate *priv = REGIONI_GET_PRIVATE (regioni); +} + +/** + * regioni_new: + * @commons: + * @selezione: + * + * Returns: the newly created #Regioni object. + */ +Regioni +*regioni_new (Commons *commons, gboolean selezione) +{ + GError *error; + + Regioni *a = REGIONI (g_object_new (regioni_get_type (), NULL)); + + RegioniPrivate *priv = REGIONI_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_regioni|", + (selezione ? "w_regioni" : "vbox4"), + 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_regioni" : "vbox4"))); + priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview2"))); + priv->lstore_regioni = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_regioni")); + + 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, "button8"), + "clicked", G_CALLBACK (regioni_on_btn_nuovo_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button9"), + "clicked", G_CALLBACK (regioni_on_btn_modifica_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button10"), + "clicked", G_CALLBACK (regioni_on_btn_elimina_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview2"), + "row-activated", G_CALLBACK (regioni_on_trv_regioni_row_activated), (gpointer)a); + + if (priv->selezione) + { + gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "label9"))); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button11"), + "clicked", G_CALLBACK (regioni_on_btn_annulla_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button12"), + "clicked", G_CALLBACK (regioni_on_btn_seleziona_clicked), (gpointer)a); + } + else + { + gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button11"))); + gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button12"))); + } + + regioni_carica (a); + + return a; +} + +/** + * regioni_get_widget: + * @regioni: + * + */ +GtkWidget +*regioni_get_widget (Regioni *regioni) +{ + RegioniPrivate *priv = REGIONI_GET_PRIVATE (regioni); + + return priv->widget; +} + +/* PRIVATE */ +static void +regioni_carica (Regioni *regioni) +{ + GtkTreeIter iter; + GdaDataModel *dm; + + gint rows; + gint row; + + RegioniPrivate *priv = REGIONI_GET_PRIVATE (regioni); + + gtk_list_store_clear (priv->lstore_regioni); + + dm = gdaex_query (priv->commons->gdaex, + "SELECT c.id, c.nome" + " FROM regioni 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_regioni, &iter); + + gtk_list_store_set (priv->lstore_regioni, &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 +regioni_modifica (Regioni *regioni) +{ + GtkTreeIter iter; + guint id; + + RegioniPrivate *priv = REGIONI_GET_PRIVATE (regioni); + + if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter)) + { + GtkWidget *w; + + gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_regioni), &iter, + COL_ID, &id, + -1); + + Regione *c = regione_new (priv->commons, id); + + g_signal_connect (G_OBJECT (c), "aggiornato", + G_CALLBACK (regioni_on_regione_aggiornato), (gpointer)regioni); + + w = regione_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 regione"); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +regioni_selezionato (Regioni *regioni) +{ + GtkTreeIter iter; + guint *id; + + RegioniClass *klass = REGIONI_GET_CLASS (regioni); + RegioniPrivate *priv = REGIONI_GET_PRIVATE (regioni); + + if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter)) + { + gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_regioni), &iter, + COL_ID, &id, + -1); + + g_signal_emit (G_OBJECT (regioni), klass->selezionato_signal_id, 0, id); + + gtk_widget_destroy (priv->widget); + g_object_unref (G_OBJECT (regioni)); + } + else + { + GtkWidget *dialog = gtk_message_dialog_new (priv->wtransient, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + "Occorre prima selezionare una regione"); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +regioni_on_regione_aggiornato (gpointer instance, gpointer user_data) +{ + regioni_carica ((Regioni *)user_data); +} + +static void +regioni_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + Regioni *regioni = REGIONI (object); + + RegioniPrivate *priv = REGIONI_GET_PRIVATE (regioni); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +regioni_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + Regioni *regioni = REGIONI (object); + + RegioniPrivate *priv = REGIONI_GET_PRIVATE (regioni); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +/* CALLBACK */ +static void +regioni_on_btn_nuovo_clicked (GtkButton *button, + gpointer user_data) +{ + GtkWidget *w; + + Regioni *regioni = (Regioni *)user_data; + RegioniPrivate *priv = REGIONI_GET_PRIVATE (regioni); + + Regione *c = regione_new (priv->commons, 0); + + g_signal_connect (G_OBJECT (c), "aggiornato", + G_CALLBACK (regioni_on_regione_aggiornato), (gpointer)regioni); + + w = regione_get_widget (c); + gtk_window_set_transient_for (GTK_WINDOW (w), priv->wtransient); + gtk_widget_show (w); +} + +static void +regioni_on_btn_modifica_clicked (GtkButton *button, + gpointer user_data) +{ + regioni_modifica ((Regioni *)user_data); +} + +static void +regioni_on_btn_elimina_clicked (GtkButton *button, + gpointer user_data) +{ + GtkWidget *dialog; + gboolean risp; + + GtkTreeIter iter; + guint id; + + Regioni *regioni = (Regioni *)user_data; + RegioniPrivate *priv = REGIONI_GET_PRIVATE (regioni); + + 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 regione selezionata?"); + risp = gtk_dialog_run (GTK_DIALOG (dialog)); + if (risp == GTK_RESPONSE_YES) + { + gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_regioni), &iter, + COL_ID, &id, + -1); + + gdaex_execute (priv->commons->gdaex, + g_strdup_printf ("UPDATE regioni SET status = 'E' WHERE id = %d", id)); + + regioni_carica (regioni); + } + 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 regione"); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +regioni_on_trv_regioni_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data) +{ + RegioniPrivate *priv = REGIONI_GET_PRIVATE ((Regioni *)user_data); + + if (priv->selezione) + { + regioni_selezionato ((Regioni *)user_data); + } + else + { + regioni_modifica ((Regioni *)user_data); + } +} + + +static void +regioni_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data) +{ + RegioniPrivate *priv = REGIONI_GET_PRIVATE ((Regioni *)user_data); + + gtk_widget_destroy (priv->widget); + g_object_unref (G_OBJECT (user_data)); +} + +static void +regioni_on_btn_seleziona_clicked (GtkButton *button, + gpointer user_data) +{ + regioni_selezionato ((Regioni *)user_data); +} diff --git a/src/regioni.h b/src/regioni.h new file mode 100644 index 0000000..5f4f3cc --- /dev/null +++ b/src/regioni.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 __REGIONI_H__ +#define __REGIONI_H__ + +#include +#include + +#include +#include + +#include "commons.h" + +G_BEGIN_DECLS + + +#define TYPE_REGIONI (regioni_get_type ()) +#define REGIONI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_REGIONI, Regioni)) +#define REGIONI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_REGIONI, RegioniClass)) +#define IS_REGIONI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_REGIONI)) +#define IS_REGIONI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_REGIONI)) +#define REGIONI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_REGIONI, RegioniClass)) + + +typedef struct _Regioni Regioni; +typedef struct _RegioniClass RegioniClass; + +struct _Regioni + { + GObject parent; + }; + +struct _RegioniClass + { + GObjectClass parent_class; + + guint selezionato_signal_id; + }; + +GType regioni_get_type (void) G_GNUC_CONST; + +Regioni *regioni_new (Commons *commons, gboolean selezione); + +GtkWidget *regioni_get_widget (Regioni *regioni); + + +G_END_DECLS + +#endif /* __REGIONI_H__ */