struttura_indirizzo.form \
tipo_nodo.form \
tipo_recapito.form \
- ufficio.form
+ ufficio.form \
+ ufficio_nodo.form
EXTRA_DIST = $(form_DATA)
<sql with-empty-entry="t">
SELECT id, nome FROM tipi_nodo WHERE status <> 'E' ORDER BY nome
</sql>
- <field type="integer" name="id_tipi_nodo"/>
+ <field type="integer" name="id_tipi_nodo">
+ <obligatory>t</obligatory>
+ </field>
</widget>
<widget type="entry" name="entry1" label="label2">
--- /dev/null
+<?xml version="1.0"?>
+<gtkform>
+
+ <table>ufficio_nodi</table>
+
+ <widget type="label" name="label38">
+ <field type="integer" name="id">
+ <is-key>t</is-key>
+ <auto-increment>t</auto-increment>
+ </field>
+ </widget>
+
+ <widget type="label" name="label22">
+ <field type="integer" name="id_uffici">
+ </field>
+ </widget>
+
+ <widget type="entry" name="entry11">
+ <field type="text" name="nodo">
+ <to-load>f</to-load>
+ <to-save>f</to-save>
+ </field>
+ </widget>
+
+ <widget type="label" name="label37" label="label36">
+ <on-change what="update" when="after">
+ <widget-name>entry11</widget-name>
+ <sql>
+ SELECT nome FROM nodi WHERE id = ##label37::gint
+ </sql>
+ </on-change>
+ <field type="integer" name="id_nodi">
+ </field>
+ </widget>
+
+ <widget type="textview" name="textview4" label="label35">
+ <field type="text" name="note" />
+ </widget>
+
+</gtkform>
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
- <property name="label" translatable="yes">Descrizione</property>
+ <property name="label" translatable="yes">Note</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
<property name="invisible_char">●</property>
- <property name="secondary_icon_stock">gtk-clear</property>
- <property name="secondary_icon_activatable">True</property>
- <property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="position">0</property>
-- PostgreSQL database dump
--
--- Started on 2010-08-16 10:29:29
+-- Started on 2010-08-16 11:28:39
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET escape_string_warning = off;
--
--- TOC entry 1826 (class 1262 OID 59278)
+-- TOC entry 1834 (class 1262 OID 59278)
-- Name: organigramma; Type: DATABASE; Schema: -; Owner: -
--
SET escape_string_warning = off;
--
--- TOC entry 320 (class 2612 OID 16386)
+-- TOC entry 323 (class 2612 OID 16386)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: -
--
SET default_with_oids = false;
--
--- TOC entry 1507 (class 1259 OID 59279)
--- Dependencies: 1791 1792 1793 3
+-- TOC entry 1510 (class 1259 OID 59279)
+-- Dependencies: 1795 1796 1797 3
-- Name: nodi; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1513 (class 1259 OID 59346)
--- Dependencies: 1807 1808 1809 3
+-- TOC entry 1516 (class 1259 OID 59346)
+-- Dependencies: 1811 1812 1813 3
-- Name: struttura_indirizzi; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1511 (class 1259 OID 59327)
--- Dependencies: 1801 1802 1803 1804 1805 3
+-- TOC entry 1514 (class 1259 OID 59327)
+-- Dependencies: 1805 1806 1807 1808 1809 3
-- Name: strutture; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1508 (class 1259 OID 59290)
--- Dependencies: 1794 1795 3
+-- TOC entry 1511 (class 1259 OID 59290)
+-- Dependencies: 1798 1799 3
-- Name: tipi_nodo; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1509 (class 1259 OID 59297)
--- Dependencies: 1796 1797 3
+-- TOC entry 1512 (class 1259 OID 59297)
+-- Dependencies: 1800 1801 3
-- Name: tipi_recapito; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1510 (class 1259 OID 59311)
--- Dependencies: 1798 1799 1800 3
+-- TOC entry 1513 (class 1259 OID 59311)
+-- Dependencies: 1802 1803 1804 3
-- Name: uffici; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1512 (class 1259 OID 59340)
--- Dependencies: 1806 3
+-- TOC entry 1517 (class 1259 OID 59357)
+-- Dependencies: 1814 1815 3
+-- Name: ufficio_nodi; Type: TABLE; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE TABLE ufficio_nodi (
+ id integer NOT NULL,
+ id_uffici integer,
+ id_nodi integer,
+ note text DEFAULT ''::text,
+ status character varying(1) DEFAULT ''::character varying
+);
+
+
+--
+-- TOC entry 1515 (class 1259 OID 59340)
+-- Dependencies: 1810 3
-- Name: vie; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1811 (class 2606 OID 59289)
--- Dependencies: 1507 1507
+-- TOC entry 1817 (class 2606 OID 59289)
+-- Dependencies: 1510 1510
-- Name: nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1823 (class 2606 OID 59356)
--- Dependencies: 1513 1513
+-- TOC entry 1829 (class 2606 OID 59356)
+-- Dependencies: 1516 1516
-- Name: struttura_indirizzi_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1819 (class 2606 OID 59339)
--- Dependencies: 1511 1511
+-- TOC entry 1825 (class 2606 OID 59339)
+-- Dependencies: 1514 1514
-- Name: strutture_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1813 (class 2606 OID 59296)
--- Dependencies: 1508 1508
+-- TOC entry 1819 (class 2606 OID 59296)
+-- Dependencies: 1511 1511
-- Name: tipi_nodo_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1815 (class 2606 OID 59303)
--- Dependencies: 1509 1509
+-- TOC entry 1821 (class 2606 OID 59303)
+-- Dependencies: 1512 1512
-- Name: tipi_recapito_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1817 (class 2606 OID 59321)
--- Dependencies: 1510 1510
+-- TOC entry 1823 (class 2606 OID 59321)
+-- Dependencies: 1513 1513
-- Name: uffici_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1821 (class 2606 OID 59345)
--- Dependencies: 1512 1512
+-- TOC entry 1831 (class 2606 OID 59366)
+-- Dependencies: 1517 1517
+-- Name: ufficio_nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
+--
+
+ALTER TABLE ONLY ufficio_nodi
+ ADD CONSTRAINT ufficio_nodi_pkey PRIMARY KEY (id);
+
+
+--
+-- TOC entry 1827 (class 2606 OID 59345)
+-- Dependencies: 1515 1515
-- Name: vie_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
--
--- TOC entry 1828 (class 0 OID 0)
+-- TOC entry 1836 (class 0 OID 0)
-- Dependencies: 3
-- Name: public; Type: ACL; Schema: -; Owner: -
--
GRANT ALL ON SCHEMA public TO PUBLIC;
--- Completed on 2010-08-16 10:29:30
+-- Completed on 2010-08-16 11:28:40
--
-- PostgreSQL database dump complete
uffici.h \
ufficio.c \
ufficio.h \
+ ufficionodo.c \
+ ufficionodo.h \
vie.c \
vie.h
\ No newline at end of file
#include "ufficio.h"
#include "strutture.h"
+#include "ufficionodo.h"
static void ufficio_class_init (UfficioClass *klass);
static void ufficio_init (Ufficio *ufficio);
static void ufficio_carica (Ufficio *ufficio);
static void ufficio_salva (Ufficio *ufficio);
+static void ufficio_carica_nodi (Ufficio *ufficio);
+
+static void ufficio_nodo_modifica (Ufficio *ufficio);
+
static gboolean ufficio_conferma_chiusura (Ufficio *ufficio);
static void ufficio_set_property (GObject *object,
GValue *value,
GParamSpec *pspec);
-static void ufficio_on_struttura_selezionato (gpointer instance, guint id, gpointer user_data);
+static void ufficio_on_nodo_aggiornato (gpointer instance, gpointer user_data);
-static void ufficio_on_btn_struttura_clicked (GtkButton *button,
- gpointer user_data);
+static void ufficio_on_ufficio_selezionato (gpointer instance, guint id, gpointer user_data);
static gboolean ufficio_on_w_ufficio_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data);
+static void ufficio_on_btn_ufficio_clicked (GtkButton *button,
+ gpointer user_data);
+
+static void ufficio_on_btn_nodo_nuovo_clicked (GtkButton *button,
+ gpointer user_data);
+static void ufficio_on_btn_nodo_modifica_clicked (GtkButton *button,
+ gpointer user_data);
+static void ufficio_on_btn_nodo_elimina_clicked (GtkButton *button,
+ gpointer user_data);
+static void ufficio_on_trv_nodi_row_activated (GtkTreeView *tree_view,
+ GtkTreePath *tree_path,
+ GtkTreeViewColumn *column,
+ gpointer user_data);
+
static void ufficio_on_btn_annulla_clicked (GtkButton *button,
gpointer user_data);
static void ufficio_on_btn_salva_clicked (GtkButton *button,
enum
{
- LBL_ID
+ LBL_ID,
+ LSTORE_NODI
+};
+
+enum
+{
+ NODI_COL_TIPO,
+ NODI_COL_ID,
+ NODI_COL_NOME
};
typedef struct _UfficioPrivate UfficioPrivate;
GObject **objects;
+ GtkTreeSelection *sel_nodi;
+
gint id;
};
error = NULL;
gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
- g_strsplit ("w_ufficio", "|", -1),
+ g_strsplit (g_strconcat ("lstore_ufficio_nodi",
+ "|lstore_ufficio_recapiti",
+ "|w_ufficio", NULL), "|", -1),
&error);
if (error != NULL)
{
priv->objects = gtk_form_get_objects_by_name (priv->form,
"label23",
+ "lstore_ufficio_nodi",
NULL);
+ priv->sel_nodi = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview7")));
+
g_signal_connect (priv->w,
"delete-event", G_CALLBACK (ufficio_on_w_ufficio_delete_event), (gpointer *)a);
g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button31"),
- "clicked", G_CALLBACK (ufficio_on_btn_struttura_clicked), (gpointer *)a);
+ "clicked", G_CALLBACK (ufficio_on_btn_ufficio_clicked), (gpointer *)a);
+
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button28")),
+ "clicked", G_CALLBACK (ufficio_on_btn_nodo_nuovo_clicked), (gpointer *)a);
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button42")),
+ "clicked", G_CALLBACK (ufficio_on_btn_nodo_modifica_clicked), (gpointer *)a);
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button43")),
+ "clicked", G_CALLBACK (ufficio_on_btn_nodo_elimina_clicked), (gpointer *)a);
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview7")),
+ "row-activated", G_CALLBACK (ufficio_on_trv_nodi_row_activated), (gpointer *)a);
g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button29"),
"clicked", G_CALLBACK (ufficio_on_btn_annulla_clicked), (gpointer *)a);
{
UfficioPrivate *priv = UFFICIO_GET_PRIVATE (ufficio);
- gtk_form_fill_from_table (priv->form);
+ if (gtk_form_fill_from_table (priv->form))
+ {
+ ufficio_carica_nodi (ufficio);
+ }
}
static void
}
}
+static void
+ufficio_carica_nodi (Ufficio *ufficio)
+{
+ gchar *sql;
+ GdaDataModel *dm;
+ guint row;
+ guint rows;
+
+ UfficioPrivate *priv = UFFICIO_GET_PRIVATE (ufficio);
+
+ gtk_list_store_clear (GTK_LIST_STORE (priv->objects[LSTORE_NODI]));
+
+ sql = g_strdup_printf ("SELECT tn.nome AS tipo, si.id, v.nome AS nome"
+ " FROM ufficio_nodi si INNER JOIN nodi v ON si.id_nodi = v.id"
+ " INNER JOIN tipi_nodo tn ON v.id_tipi_nodo = tn.id"
+ " WHERE si.id_uffici = %d"
+ " AND si.status <> 'E'",
+ priv->id);
+ dm = gdaex_query (priv->commons->gdaex, sql);
+ if (dm != NULL)
+ {
+ GtkTreeIter iter;
+
+ rows = gda_data_model_get_n_rows (dm);
+ for (row = 0; row < rows; row++)
+ {
+ gtk_list_store_append (GTK_LIST_STORE (priv->objects[LSTORE_NODI]), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (priv->objects[LSTORE_NODI]), &iter,
+ NODI_COL_TIPO, gdaex_data_model_get_field_value_stringify_at (dm, row, "tipo"),
+ NODI_COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"),
+ NODI_COL_NOME, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"),
+ -1);
+ }
+
+ g_object_unref (dm);
+ }
+ g_free (sql);
+}
+
+static void
+ufficio_nodo_modifica (Ufficio *ufficio)
+{
+ GtkTreeIter iter;
+ GtkWidget *dialog;
+
+ UfficioPrivate *priv = UFFICIO_GET_PRIVATE (ufficio);
+
+ if (gtk_tree_selection_get_selected (priv->sel_nodi, NULL, &iter))
+ {
+ guint id;
+ GtkWidget *w;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_NODI]), &iter,
+ NODI_COL_ID, &id,
+ -1);
+
+ UfficioNodo *a = ufficio_nodo_new (priv->commons, id, 0);
+
+ g_signal_connect (G_OBJECT (a), "aggiornato",
+ G_CALLBACK (ufficio_on_nodo_aggiornato), (gpointer)ufficio);
+
+ w = ufficio_nodo_get_widget (a);
+ gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w));
+ gtk_widget_show (w);
+ }
+ else
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Occorre prima selezionare un nodo");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+}
+
static void
ufficio_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
/* CALLBACK */
static void
-ufficio_on_struttura_selezionato (gpointer instance, guint id, gpointer user_data)
+ufficio_on_ufficio_selezionato (gpointer instance, guint id, gpointer user_data)
{
Ufficio *f = (Ufficio *)user_data;
UfficioPrivate *priv = UFFICIO_GET_PRIVATE (f);
}
static void
-ufficio_on_btn_struttura_clicked (GtkButton *button,
+ufficio_on_nodo_aggiornato (gpointer instance, gpointer user_data)
+{
+ Ufficio *ufficio = (Ufficio *)user_data;
+ UfficioClass *klass = UFFICIO_GET_CLASS (ufficio);
+
+ ufficio_carica_nodi (ufficio);
+}
+
+static gboolean
+ufficio_on_w_ufficio_delete_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ return !ufficio_conferma_chiusura ((Ufficio *)user_data);
+}
+
+static void
+ufficio_on_btn_ufficio_clicked (GtkButton *button,
gpointer user_data)
{
GtkWidget *w;
Strutture *c = strutture_new (priv->commons, TRUE);
g_signal_connect (G_OBJECT (c), "selezionato",
- G_CALLBACK (ufficio_on_struttura_selezionato), user_data);
+ G_CALLBACK (ufficio_on_ufficio_selezionato), user_data);
w = strutture_get_widget (c);
gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w));
gtk_widget_show (w);
}
-static gboolean
-ufficio_on_w_ufficio_delete_event (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data)
+static void
+ufficio_on_btn_nodo_nuovo_clicked (GtkButton *button,
+ gpointer user_data)
{
- return !ufficio_conferma_chiusura ((Ufficio *)user_data);
+ GtkWidget *w;
+
+ Ufficio *ufficio = (Ufficio *)user_data;
+
+ UfficioPrivate *priv = UFFICIO_GET_PRIVATE (ufficio);
+
+ UfficioNodo *a = ufficio_nodo_new (priv->commons, 0, priv->id);
+
+ g_signal_connect (G_OBJECT (a), "aggiornato",
+ G_CALLBACK (ufficio_on_nodo_aggiornato), (gpointer)ufficio);
+
+ w = ufficio_nodo_get_widget (a);
+ gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w));
+ gtk_widget_show (w);
+}
+
+static void
+ufficio_on_btn_nodo_modifica_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ ufficio_nodo_modifica ((Ufficio *)user_data);
+}
+
+static void
+ufficio_on_btn_nodo_elimina_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkTreeIter iter;
+ GtkWidget *dialog;
+ guint risp;
+
+ Ufficio *ufficio = (Ufficio *)user_data;
+
+ UfficioClass *klass = UFFICIO_GET_CLASS (ufficio);
+ UfficioPrivate *priv = UFFICIO_GET_PRIVATE (ufficio);
+
+ if (gtk_tree_selection_get_selected (priv->sel_nodi, NULL, &iter))
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ "Sicuro di voler eliminare l'nodo selezionato?");
+ risp = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (risp == GTK_RESPONSE_YES)
+ {
+ guint id;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_NODI]), &iter,
+ NODI_COL_ID, &id,
+ -1);
+
+ gdaex_execute (priv->commons->gdaex,
+ g_strdup_printf ("UPDATE ufficio_nodi"
+ " SET status = 'E'"
+ " WHERE id = %d",
+ id));
+
+ ufficio_carica_nodi (ufficio);
+ }
+ gtk_widget_destroy (dialog);
+ }
+ else
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Occorre prima selezionare un nodo");
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+}
+
+static void
+ufficio_on_trv_nodi_row_activated (GtkTreeView *tree_view,
+ GtkTreePath *tree_path,
+ GtkTreeViewColumn *column,
+ gpointer user_data)
+{
+ ufficio_nodo_modifica ((Ufficio *)user_data);
}
static void
--- /dev/null
+/*
+ * Copyright (C) 2009 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
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+#include <libgtkform/form.h>
+
+#include "ufficionodo.h"
+#include "nodi.h"
+
+static void ufficio_nodo_class_init (UfficioNodoClass *klass);
+static void ufficio_nodo_init (UfficioNodo *ufficio_nodo);
+
+static void ufficio_nodo_carica (UfficioNodo *ufficio_nodo);
+static void ufficio_nodo_salva (UfficioNodo *ufficio_nodo);
+
+static void ufficio_nodo_carica_indirizzo (UfficioNodo *indirizzo);
+
+static gboolean ufficio_nodo_conferma_chiusura (UfficioNodo *ufficio_nodo);
+
+static void indirizzo_on_nodo_selezionato (gpointer instance,
+ guint id, gpointer user_data);
+
+static void ufficio_nodo_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void ufficio_nodo_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static gboolean ufficio_nodo_on_w_ufficio_nodo_delete_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data);
+
+static void ufficio_nodo_on_btn_nodo_clicked (GtkButton *button,
+ gpointer user_data);
+static void ufficio_nodo_on_btn_annulla_clicked (GtkButton *button,
+ gpointer user_data);
+static void ufficio_nodo_on_btn_salva_clicked (GtkButton *button,
+ gpointer user_data);
+
+
+#define UFFICIO_NODO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_UFFICIO_NODO, UfficioNodoPrivate))
+
+enum
+{
+ LBL_ID,
+ LBL_ID_UFFICI,
+ LBL_ID_NODI
+};
+
+typedef struct _UfficioNodoPrivate UfficioNodoPrivate;
+struct _UfficioNodoPrivate
+ {
+ Commons *commons;
+
+ GtkForm *form;
+
+ GtkWidget *w;
+
+ GObject **objects;
+
+ guint id;
+ };
+
+G_DEFINE_TYPE (UfficioNodo, ufficio_nodo, G_TYPE_OBJECT)
+
+static void
+ufficio_nodo_class_init (UfficioNodoClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (UfficioNodoPrivate));
+
+ object_class->set_property = ufficio_nodo_set_property;
+ object_class->get_property = ufficio_nodo_get_property;
+
+ /**
+ * UfficioNodo::aggiornato:
+ * @ufficio_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
+ufficio_nodo_init (UfficioNodo *ufficio_nodo)
+{
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (ufficio_nodo);
+}
+
+/**
+ * ufficio_nodo_new:
+ * @commons:
+ * @id:
+ * @id_uffici:
+ *
+ * Returns: the newly created #UfficioNodo object.
+ */
+UfficioNodo
+*ufficio_nodo_new (Commons *commons, guint id, guint id_uffici)
+{
+ GError *error;
+
+ UfficioNodo *a = UFFICIO_NODO (g_object_new (ufficio_nodo_get_type (), NULL));
+
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (a);
+
+ priv->commons = commons;
+
+ error = NULL;
+
+ gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
+ g_strsplit ("w_ufficio_nodo", "|", -1),
+ &error);
+ if (error != NULL)
+ {
+ g_fprintf (stderr, "Errore: %s\n", 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, "ufficio_nodo.form", NULL), priv->commons->gtkbuilder);
+
+ priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_ufficio_nodo"));
+
+ priv->objects = gtk_form_get_objects_by_name (priv->form,
+ "label38",
+ "label22",
+ "label37",
+ NULL);
+
+ g_signal_connect (priv->w,
+ "delete-event", G_CALLBACK (ufficio_nodo_on_w_ufficio_nodo_delete_event), (gpointer *)a);
+
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button44")),
+ "clicked", G_CALLBACK (ufficio_nodo_on_btn_nodo_clicked), (gpointer *)a);
+
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button45")),
+ "clicked", G_CALLBACK (ufficio_nodo_on_btn_annulla_clicked), (gpointer *)a);
+ g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button46")),
+ "clicked", G_CALLBACK (ufficio_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_label_set_text (GTK_LABEL (priv->objects[LBL_ID_UFFICI]), g_strdup_printf ("%d", id_uffici));
+
+ gtk_form_set_as_origin (priv->form);
+ }
+ else
+ {
+ gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), g_strdup_printf ("%d", priv->id));
+
+ ufficio_nodo_carica (a);
+ }
+
+ return a;
+}
+
+/**
+ * ufficio_nodo_get_widget:
+ * @ufficio_nodo:
+ *
+ */
+GtkWidget
+*ufficio_nodo_get_widget (UfficioNodo *ufficio_nodo)
+{
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (ufficio_nodo);
+
+ return priv->w;
+}
+
+/* PRIVATE */
+static void
+ufficio_nodo_carica (UfficioNodo *ufficio_nodo)
+{
+ gchar *sql;
+ GdaDataModel *dm;
+
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (ufficio_nodo);
+
+ if (gtk_form_fill_from_table (priv->form))
+ {
+ }
+}
+
+static void
+ufficio_nodo_salva (UfficioNodo *ufficio_nodo)
+{
+ gchar *sql;
+ GtkWidget *dialog;
+
+ UfficioNodoClass *klass = UFFICIO_NODO_GET_CLASS (ufficio_nodo);
+
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (ufficio_nodo);
+
+ if (!gtk_form_check (priv->form, FALSE, 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 (ufficio_nodo, klass->aggiornato_signal_id, 0);
+
+ if (priv->id == 0)
+ {
+ priv->id = strtol (gtk_label_get_text (GTK_LABEL (priv->objects[LBL_ID])), NULL, 10);
+ }
+
+ gtk_form_set_as_origin (priv->form);
+
+ 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
+ {
+ 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
+ufficio_nodo_on_nodo_selezionato (gpointer instance, guint id, gpointer user_data)
+{
+ UfficioNodo *ia = (UfficioNodo *)user_data;
+
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (ia);
+
+ gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "label37"), g_strdup_printf ("%d", id));
+}
+
+static void
+ufficio_nodo_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ UfficioNodo *ufficio_nodo = UFFICIO_NODO (object);
+
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (ufficio_nodo);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+ufficio_nodo_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ UfficioNodo *ufficio_nodo = UFFICIO_NODO (object);
+
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (ufficio_nodo);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static gboolean
+ufficio_nodo_conferma_chiusura (UfficioNodo *ufficio_nodo)
+{
+ GtkWidget *dialog;
+
+ gboolean ret;
+
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (ufficio_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
+ufficio_nodo_on_w_ufficio_nodo_delete_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ return !ufficio_nodo_conferma_chiusura ((UfficioNodo *)user_data);
+}
+
+static void
+ufficio_nodo_on_btn_nodo_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkWidget *w;
+
+ UfficioNodo *ia = (UfficioNodo *)user_data;
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (ia);
+
+ Nodi *n = nodi_new (priv->commons, TRUE);
+
+ g_signal_connect (G_OBJECT (n), "selezionato",
+ G_CALLBACK (ufficio_nodo_on_nodo_selezionato), (gpointer)ia);
+
+ w = nodi_get_widget (n);
+ gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w));
+ gtk_widget_show (w);
+}
+
+static void
+ufficio_nodo_on_btn_annulla_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ UfficioNodo *ufficio_nodo = (UfficioNodo *)user_data;
+
+ UfficioNodoPrivate *priv = UFFICIO_NODO_GET_PRIVATE (ufficio_nodo);
+
+ if (ufficio_nodo_conferma_chiusura (ufficio_nodo)) gtk_widget_destroy (priv->w);
+}
+
+static void
+ufficio_nodo_on_btn_salva_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ ufficio_nodo_salva ((UfficioNodo *)user_data);
+}
--- /dev/null
+/*
+ * Copyright (C) 2009 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 __UFFICIO_NODO_H__
+#define __UFFICIO_NODO_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_UFFICIO_NODO (ufficio_nodo_get_type ())
+#define UFFICIO_NODO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UFFICIO_NODO, UfficioNodo))
+#define UFFICIO_NODO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UFFICIO_NODO, UfficioNodoClass))
+#define IS_UFFICIO_NODO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UFFICIO_NODO))
+#define IS_UFFICIO_NODO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UFFICIO_NODO))
+#define UFFICIO_NODO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UFFICIO_NODO, UfficioNodoClass))
+
+
+typedef struct _UfficioNodo UfficioNodo;
+typedef struct _UfficioNodoClass UfficioNodoClass;
+
+struct _UfficioNodo
+ {
+ GObject parent;
+ };
+
+struct _UfficioNodoClass
+ {
+ GObjectClass parent_class;
+
+ guint aggiornato_signal_id;
+ };
+
+GType ufficio_nodo_get_type (void) G_GNUC_CONST;
+
+UfficioNodo *ufficio_nodo_new (Commons *commons, guint id, guint id_uffici);
+
+GtkWidget *ufficio_nodo_get_widget (UfficioNodo *ufficio_nodo);
+
+
+G_END_DECLS
+
+#endif /* __UFFICIO_NODO_H__ */