From: Andrea Zagli Date: Wed, 13 Oct 2010 10:30:07 +0000 (+0200) Subject: Gestione recapiti generici della persona. X-Git-Tag: 0.0.3~45 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=efc7796f03c71fc50ac22885779e7b78af894197;p=solipa%2Forganigramma Gestione recapiti generici della persona. --- diff --git a/data/organigramma/form/Makefile.am b/data/organigramma/form/Makefile.am index b9dfa83..096dc1a 100644 --- a/data/organigramma/form/Makefile.am +++ b/data/organigramma/form/Makefile.am @@ -3,6 +3,7 @@ formdir = $(datadir)/$(PACKAGE)/form form_DATA = \ nodo.form \ persona.form \ + persona_recapito.form \ persona_ufficio.form \ struttura.form \ struttura_indirizzo.form \ diff --git a/data/organigramma/form/persona_recapito.form b/data/organigramma/form/persona_recapito.form new file mode 100644 index 0000000..b6d70b4 --- /dev/null +++ b/data/organigramma/form/persona_recapito.form @@ -0,0 +1,41 @@ + + + + persona_recapiti
+ + + + t + t + + + + + + + + + + 0 + + SELECT id, nome FROM tipi_recapito WHERE status <> 'E' ORDER BY nome + + + + + + + + + + + + + + + + + + + +
diff --git a/data/organigramma/gui/organigramma.gui b/data/organigramma/gui/organigramma.gui index 0b43cf5..1c0d892 100644 --- a/data/organigramma/gui/organigramma.gui +++ b/data/organigramma/gui/organigramma.gui @@ -648,16 +648,6 @@ - - - - - - - - - - @@ -722,6 +712,18 @@ + + + + + + + + + + + + True center-on-parent @@ -3954,6 +3956,17 @@ + + + Descrizione + + + + 3 + + + + @@ -4089,6 +4102,28 @@ + + + Da data + + + + 3 + + + + + + + A data + + + + 4 + + + + @@ -5574,7 +5609,7 @@ - lbl_id_persona + lbl_id_persone 1 @@ -6102,7 +6137,7 @@ True - 9 + 10 2 5 5 @@ -6138,8 +6173,8 @@ Note - 7 - 8 + 8 + 9 GTK_FILL GTK_FILL @@ -6161,8 +6196,8 @@ 1 2 - 7 - 8 + 8 + 9 @@ -6171,8 +6206,8 @@ lbl_id - 8 - 9 + 9 + 10 GTK_FILL GTK_FILL @@ -6240,8 +6275,8 @@ 1 2 - 8 - 9 + 9 + 10 GTK_FILL GTK_FILL @@ -6374,6 +6409,41 @@ GTK_FILL + + + True + 0 + 0 + Descrizione + + + 7 + 8 + GTK_FILL + GTK_FILL + + + + + True + True + automatic + automatic + etched-in + + + True + True + + + + + 1 + 2 + 7 + 8 + + 0 diff --git a/docs/organigramma.sql b/docs/organigramma.sql index 53446c4..8c7efee 100644 --- a/docs/organigramma.sql +++ b/docs/organigramma.sql @@ -4,7 +4,7 @@ -- Dumped from database version 8.4.4 -- Dumped by pg_dump version 9.0.0 --- Started on 2010-10-13 10:20:10 +-- Started on 2010-10-13 12:04:21 SET statement_timeout = 0; SET client_encoding = 'UTF8'; @@ -14,7 +14,7 @@ SET client_min_messages = warning; SET escape_string_warning = off; -- --- TOC entry 338 (class 2612 OID 16386) +-- TOC entry 341 (class 2612 OID 16386) -- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: - -- @@ -26,8 +26,8 @@ SET search_path = public, pg_catalog; SET default_with_oids = false; -- --- TOC entry 1525 (class 1259 OID 59279) --- Dependencies: 1816 1817 1818 3 +-- TOC entry 1528 (class 1259 OID 59279) +-- Dependencies: 1820 1821 1822 3 -- Name: nodi; Type: TABLE; Schema: public; Owner: - -- @@ -42,8 +42,25 @@ CREATE TABLE nodi ( -- --- TOC entry 1538 (class 1259 OID 61243) --- Dependencies: 1851 1852 3 +-- TOC entry 1542 (class 1259 OID 61266) +-- Dependencies: 1857 1858 1859 1860 1861 1862 3 +-- Name: persona_recapiti; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE persona_recapiti ( + id integer NOT NULL, + id_persone integer DEFAULT 0, + id_tipi_recapito integer DEFAULT 0, + recapito character varying(100) DEFAULT ''::character varying, + note text DEFAULT ''::text, + privato boolean DEFAULT false, + status character varying(1) DEFAULT ''::character varying +); + + +-- +-- TOC entry 1541 (class 1259 OID 61243) +-- Dependencies: 1855 1856 3 -- Name: persona_uffici; Type: TABLE; Schema: public; Owner: - -- @@ -59,8 +76,8 @@ CREATE TABLE persona_uffici ( -- --- TOC entry 1536 (class 1259 OID 61227) --- Dependencies: 1845 1846 1847 1848 3 +-- TOC entry 1539 (class 1259 OID 61227) +-- Dependencies: 1849 1850 1851 1852 3 -- Name: persone; Type: TABLE; Schema: public; Owner: - -- @@ -75,8 +92,8 @@ CREATE TABLE persone ( -- --- TOC entry 1531 (class 1259 OID 59346) --- Dependencies: 1832 1833 1834 3 +-- TOC entry 1534 (class 1259 OID 59346) +-- Dependencies: 1836 1837 1838 3 -- Name: struttura_indirizzi; Type: TABLE; Schema: public; Owner: - -- @@ -91,8 +108,8 @@ CREATE TABLE struttura_indirizzi ( -- --- TOC entry 1529 (class 1259 OID 59327) --- Dependencies: 1826 1827 1828 1829 1830 3 +-- TOC entry 1532 (class 1259 OID 59327) +-- Dependencies: 1830 1831 1832 1833 1834 3 -- Name: strutture; Type: TABLE; Schema: public; Owner: - -- @@ -107,8 +124,8 @@ CREATE TABLE strutture ( -- --- TOC entry 1526 (class 1259 OID 59290) --- Dependencies: 1819 1820 3 +-- TOC entry 1529 (class 1259 OID 59290) +-- Dependencies: 1823 1824 3 -- Name: tipi_nodo; Type: TABLE; Schema: public; Owner: - -- @@ -120,8 +137,8 @@ CREATE TABLE tipi_nodo ( -- --- TOC entry 1537 (class 1259 OID 61236) --- Dependencies: 1849 1850 3 +-- TOC entry 1540 (class 1259 OID 61236) +-- Dependencies: 1853 1854 3 -- Name: tipi_rapporto_lavoro; Type: TABLE; Schema: public; Owner: - -- @@ -133,8 +150,8 @@ CREATE TABLE tipi_rapporto_lavoro ( -- --- TOC entry 1527 (class 1259 OID 59297) --- Dependencies: 1821 1822 3 +-- TOC entry 1530 (class 1259 OID 59297) +-- Dependencies: 1825 1826 3 -- Name: tipi_recapito; Type: TABLE; Schema: public; Owner: - -- @@ -146,8 +163,8 @@ CREATE TABLE tipi_recapito ( -- --- TOC entry 1535 (class 1259 OID 61219) --- Dependencies: 1842 1843 1844 3 +-- TOC entry 1538 (class 1259 OID 61219) +-- Dependencies: 1846 1847 1848 3 -- Name: titoli; Type: TABLE; Schema: public; Owner: - -- @@ -160,8 +177,8 @@ CREATE TABLE titoli ( -- --- TOC entry 1528 (class 1259 OID 59311) --- Dependencies: 1823 1824 1825 3 +-- TOC entry 1531 (class 1259 OID 59311) +-- Dependencies: 1827 1828 1829 3 -- Name: uffici; Type: TABLE; Schema: public; Owner: - -- @@ -175,8 +192,8 @@ CREATE TABLE uffici ( -- --- TOC entry 1532 (class 1259 OID 59357) --- Dependencies: 1835 1836 3 +-- TOC entry 1535 (class 1259 OID 59357) +-- Dependencies: 1839 1840 3 -- Name: ufficio_nodi; Type: TABLE; Schema: public; Owner: - -- @@ -190,8 +207,8 @@ CREATE TABLE ufficio_nodi ( -- --- TOC entry 1533 (class 1259 OID 59399) --- Dependencies: 1837 1838 3 +-- TOC entry 1536 (class 1259 OID 59399) +-- Dependencies: 1841 1842 3 -- Name: ufficio_orari; Type: TABLE; Schema: public; Owner: - -- @@ -218,8 +235,8 @@ CREATE TABLE ufficio_orari ( -- --- TOC entry 1534 (class 1259 OID 59409) --- Dependencies: 1839 1840 1841 3 +-- TOC entry 1537 (class 1259 OID 59409) +-- Dependencies: 1843 1844 1845 3 -- Name: ufficio_recapiti; Type: TABLE; Schema: public; Owner: - -- @@ -235,8 +252,8 @@ CREATE TABLE ufficio_recapiti ( -- --- TOC entry 1530 (class 1259 OID 59340) --- Dependencies: 1831 3 +-- TOC entry 1533 (class 1259 OID 59340) +-- Dependencies: 1835 3 -- Name: vie; Type: TABLE; Schema: public; Owner: - -- @@ -247,8 +264,8 @@ CREATE TABLE vie ( -- --- TOC entry 1854 (class 2606 OID 59289) --- Dependencies: 1525 1525 +-- TOC entry 1864 (class 2606 OID 59289) +-- Dependencies: 1528 1528 -- Name: nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -257,8 +274,18 @@ ALTER TABLE ONLY nodi -- --- TOC entry 1880 (class 2606 OID 61252) --- Dependencies: 1538 1538 +-- TOC entry 1892 (class 2606 OID 61279) +-- Dependencies: 1542 1542 +-- Name: persona_recapiti_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY persona_recapiti + ADD CONSTRAINT persona_recapiti_pkey PRIMARY KEY (id); + + +-- +-- TOC entry 1890 (class 2606 OID 61252) +-- Dependencies: 1541 1541 -- Name: persona_uffici_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -267,8 +294,8 @@ ALTER TABLE ONLY persona_uffici -- --- TOC entry 1876 (class 2606 OID 61235) --- Dependencies: 1536 1536 +-- TOC entry 1886 (class 2606 OID 61235) +-- Dependencies: 1539 1539 -- Name: persone_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -277,8 +304,8 @@ ALTER TABLE ONLY persone -- --- TOC entry 1866 (class 2606 OID 59356) --- Dependencies: 1531 1531 +-- TOC entry 1876 (class 2606 OID 59356) +-- Dependencies: 1534 1534 -- Name: struttura_indirizzi_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -287,8 +314,8 @@ ALTER TABLE ONLY struttura_indirizzi -- --- TOC entry 1862 (class 2606 OID 59339) --- Dependencies: 1529 1529 +-- TOC entry 1872 (class 2606 OID 59339) +-- Dependencies: 1532 1532 -- Name: strutture_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -297,8 +324,8 @@ ALTER TABLE ONLY strutture -- --- TOC entry 1856 (class 2606 OID 59296) --- Dependencies: 1526 1526 +-- TOC entry 1866 (class 2606 OID 59296) +-- Dependencies: 1529 1529 -- Name: tipi_nodo_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -307,8 +334,8 @@ ALTER TABLE ONLY tipi_nodo -- --- TOC entry 1878 (class 2606 OID 61242) --- Dependencies: 1537 1537 +-- TOC entry 1888 (class 2606 OID 61242) +-- Dependencies: 1540 1540 -- Name: tipi_rapporto_lavoro_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -317,8 +344,8 @@ ALTER TABLE ONLY tipi_rapporto_lavoro -- --- TOC entry 1858 (class 2606 OID 59303) --- Dependencies: 1527 1527 +-- TOC entry 1868 (class 2606 OID 59303) +-- Dependencies: 1530 1530 -- Name: tipi_recapito_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -327,8 +354,8 @@ ALTER TABLE ONLY tipi_recapito -- --- TOC entry 1874 (class 2606 OID 61226) --- Dependencies: 1535 1535 +-- TOC entry 1884 (class 2606 OID 61226) +-- Dependencies: 1538 1538 -- Name: titoli_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -337,8 +364,8 @@ ALTER TABLE ONLY titoli -- --- TOC entry 1860 (class 2606 OID 59321) --- Dependencies: 1528 1528 +-- TOC entry 1870 (class 2606 OID 59321) +-- Dependencies: 1531 1531 -- Name: uffici_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -347,8 +374,8 @@ ALTER TABLE ONLY uffici -- --- TOC entry 1868 (class 2606 OID 59366) --- Dependencies: 1532 1532 +-- TOC entry 1878 (class 2606 OID 59366) +-- Dependencies: 1535 1535 -- Name: ufficio_nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -357,8 +384,8 @@ ALTER TABLE ONLY ufficio_nodi -- --- TOC entry 1870 (class 2606 OID 59408) --- Dependencies: 1533 1533 +-- TOC entry 1880 (class 2606 OID 59408) +-- Dependencies: 1536 1536 -- Name: ufficio_orari_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -367,8 +394,8 @@ ALTER TABLE ONLY ufficio_orari -- --- TOC entry 1872 (class 2606 OID 59419) --- Dependencies: 1534 1534 +-- TOC entry 1882 (class 2606 OID 59419) +-- Dependencies: 1537 1537 -- Name: ufficio_recapiti_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -377,8 +404,8 @@ ALTER TABLE ONLY ufficio_recapiti -- --- TOC entry 1864 (class 2606 OID 59345) --- Dependencies: 1530 1530 +-- TOC entry 1874 (class 2606 OID 59345) +-- Dependencies: 1533 1533 -- Name: vie_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -386,7 +413,7 @@ ALTER TABLE ONLY vie ADD CONSTRAINT vie_pkey PRIMARY KEY (id); --- Completed on 2010-10-13 10:20:10 +-- Completed on 2010-10-13 12:04:21 -- -- PostgreSQL database dump complete diff --git a/src/Makefile.am b/src/Makefile.am index 505967b..5309ffa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,8 @@ organigramma_SOURCES = \ persona.h \ persone.c \ persone.h \ + personarecapito.c \ + personarecapito.h \ personaufficio.c \ personaufficio.h \ struttura.c \ diff --git a/src/persona.c b/src/persona.c index 499f611..2cd0925 100644 --- a/src/persona.c +++ b/src/persona.c @@ -21,6 +21,7 @@ #include "persona.h" #include "personaufficio.h" +#include "personarecapito.h" static void persona_class_init (PersonaClass *klass); static void persona_init (Persona *persona); @@ -29,8 +30,10 @@ static void persona_carica (Persona *persona); static void persona_salva (Persona *persona); static void persona_carica_uffici (Persona *persona); +static void persona_carica_recapiti (Persona *persona); static void persona_ufficio_modifica (Persona *persona); +static void persona_recapito_modifica (Persona *persona); static gboolean persona_conferma_chiusura (Persona *persona); @@ -44,6 +47,7 @@ static void persona_get_property (GObject *object, GParamSpec *pspec); static void persona_on_ufficio_aggiornato (gpointer instance, gpointer user_data); +static void persona_on_recapito_aggiornato (gpointer instance, gpointer user_data); static gboolean persona_on_w_persona_delete_event (GtkWidget *widget, GdkEvent *event, @@ -60,6 +64,17 @@ static void persona_on_trv_uffici_row_activated (GtkTreeView *tree_view, GtkTreeViewColumn *column, gpointer user_data); +static void persona_on_btn_recapito_nuovo_clicked (GtkButton *button, + gpointer user_data); +static void persona_on_btn_recapito_modifica_clicked (GtkButton *button, + gpointer user_data); +static void persona_on_btn_recapito_elimina_clicked (GtkButton *button, + gpointer user_data); +static void persona_on_trv_recapiti_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data); + static void persona_on_btn_annulla_clicked (GtkButton *button, gpointer user_data); static void persona_on_btn_salva_clicked (GtkButton *button, @@ -70,7 +85,8 @@ static void persona_on_btn_salva_clicked (GtkButton *button, enum { LBL_ID, - LSTORE_UFFICI + LSTORE_UFFICI, + LSTORE_RECAPITI }; enum @@ -79,6 +95,13 @@ enum UFFICI_COL_UFFICIO }; +enum +{ + RECAPITI_COL_ID, + RECAPITI_COL_TIPO, + RECAPITI_COL_RECAPITO +}; + typedef struct _PersonaPrivate PersonaPrivate; struct _PersonaPrivate { @@ -91,6 +114,7 @@ struct _PersonaPrivate GObject **objects; GtkTreeSelection *sel_uffici; + GtkTreeSelection *sel_recapiti; gint id; }; @@ -152,6 +176,7 @@ Persona g_strsplit (g_strconcat ( "lstore_titoli" "|lstore_persona_uffici" + "|lstore_persona_recapiti" "|w_persona", NULL), "|", -1), &error); if (error != NULL) @@ -169,12 +194,14 @@ Persona priv->objects = gtk_form_get_objects_by_name (priv->form, "label67", "lstore_persona_uffici", + "lstore_persona_recapiti", NULL); g_signal_connect (priv->w, "delete-event", G_CALLBACK (persona_on_w_persona_delete_event), (gpointer *)a); priv->sel_uffici = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview11"))); + priv->sel_recapiti = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview15"))); g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button62")), "clicked", G_CALLBACK (persona_on_btn_ufficio_nuovo_clicked), (gpointer *)a); @@ -185,6 +212,15 @@ Persona g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview11")), "row-activated", G_CALLBACK (persona_on_trv_uffici_row_activated), (gpointer *)a); + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button76")), + "clicked", G_CALLBACK (persona_on_btn_recapito_nuovo_clicked), (gpointer *)a); + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button77")), + "clicked", G_CALLBACK (persona_on_btn_recapito_modifica_clicked), (gpointer *)a); + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button78")), + "clicked", G_CALLBACK (persona_on_btn_recapito_elimina_clicked), (gpointer *)a); + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview15")), + "row-activated", G_CALLBACK (persona_on_trv_recapiti_row_activated), (gpointer *)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button65"), "clicked", G_CALLBACK (persona_on_btn_annulla_clicked), (gpointer *)a); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button66"), @@ -229,6 +265,7 @@ persona_carica (Persona *persona) if (gtk_form_fill_from_table (priv->form)) { persona_carica_uffici (persona); + persona_carica_recapiti (persona); } } @@ -334,6 +371,46 @@ persona_carica_uffici (Persona *persona) g_free (sql); } +static void +persona_carica_recapiti (Persona *persona) +{ + gchar *sql; + GdaDataModel *dm; + guint row; + guint rows; + + PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona); + + gtk_list_store_clear (GTK_LIST_STORE (priv->objects[LSTORE_RECAPITI])); + + sql = g_strdup_printf ("SELECT pr.id, tr.nome, pr.recapito" + " FROM persona_recapiti AS pr INNER JOIN tipi_recapito AS tr ON" + " pr.id_tipi_recapito = tr.id" + " WHERE pr.id_persone = %d" + " AND pr.status <> 'E'" + " ORDER BY tr.nome, pr.recapito", + 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_RECAPITI]), &iter); + gtk_list_store_set (GTK_LIST_STORE (priv->objects[LSTORE_RECAPITI]), &iter, + RECAPITI_COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"), + RECAPITI_COL_TIPO, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"), + RECAPITI_COL_RECAPITO, gdaex_data_model_get_field_value_stringify_at (dm, row, "recapito"), + -1); + } + + g_object_unref (dm); + } + g_free (sql); +} + static void persona_ufficio_modifica (Persona *persona) { @@ -366,7 +443,45 @@ persona_ufficio_modifica (Persona *persona) GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, - "Occorre prima selezionare un ufficio"); + "Occorre prima selezionare un ufficio."); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +persona_recapito_modifica (Persona *persona) +{ + GtkTreeIter iter; + GtkWidget *dialog; + + PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona); + + if (gtk_tree_selection_get_selected (priv->sel_recapiti, NULL, &iter)) + { + guint id; + GtkWidget *w; + + gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_RECAPITI]), &iter, + RECAPITI_COL_ID, &id, + -1); + + PersonaRecapito *a = persona_recapito_new (priv->commons, id, 0); + + g_signal_connect (G_OBJECT (a), "aggiornato", + G_CALLBACK (persona_on_recapito_aggiornato), (gpointer)persona); + + w = persona_recapito_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 recapito."); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } @@ -439,6 +554,15 @@ persona_on_ufficio_aggiornato (gpointer instance, gpointer user_data) persona_carica_uffici (persona); } +static void +persona_on_recapito_aggiornato (gpointer instance, gpointer user_data) +{ + Persona *persona = (Persona *)user_data; + PersonaClass *klass = PERSONA_GET_CLASS (persona); + + persona_carica_recapiti (persona); +} + static gboolean persona_on_w_persona_delete_event (GtkWidget *widget, GdkEvent *event, @@ -534,6 +658,93 @@ persona_on_trv_uffici_row_activated (GtkTreeView *tree_view, persona_ufficio_modifica ((Persona *)user_data); } +static void +persona_on_btn_recapito_nuovo_clicked (GtkButton *button, + gpointer user_data) +{ + GtkWidget *w; + + Persona *persona = (Persona *)user_data; + + PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona); + + PersonaRecapito *a = persona_recapito_new (priv->commons, 0, priv->id); + + g_signal_connect (G_OBJECT (a), "aggiornato", + G_CALLBACK (persona_on_recapito_aggiornato), (gpointer)persona); + + w = persona_recapito_get_widget (a); + gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w)); + gtk_widget_show (w); +} + +static void +persona_on_btn_recapito_modifica_clicked (GtkButton *button, + gpointer user_data) +{ + persona_recapito_modifica ((Persona *)user_data); +} + +static void +persona_on_btn_recapito_elimina_clicked (GtkButton *button, + gpointer user_data) +{ + GtkTreeIter iter; + GtkWidget *dialog; + guint risp; + + Persona *persona = (Persona *)user_data; + + PersonaClass *klass = PERSONA_GET_CLASS (persona); + PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona); + + if (gtk_tree_selection_get_selected (priv->sel_recapiti, 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 il recapito 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_RECAPITI]), &iter, + RECAPITI_COL_ID, &id, + -1); + + gdaex_execute (priv->commons->gdaex, + g_strdup_printf ("UPDATE persona_recapiti" + " SET status = 'E'" + " WHERE id = %d", + id)); + + persona_carica_recapiti (persona); + } + 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 recapito."); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +persona_on_trv_recapiti_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data) +{ + persona_recapito_modifica ((Persona *)user_data); +} + static void persona_on_btn_annulla_clicked (GtkButton *button, gpointer user_data) diff --git a/src/personarecapito.c b/src/personarecapito.c new file mode 100644 index 0000000..f913cfa --- /dev/null +++ b/src/personarecapito.c @@ -0,0 +1,343 @@ +/* + * Copyright (C) 2009 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 + * + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include + +#include "personarecapito.h" + +static void persona_recapito_class_init (PersonaRecapitoClass *klass); +static void persona_recapito_init (PersonaRecapito *persona_recapito); + +static void persona_recapito_carica (PersonaRecapito *persona_recapito); +static void persona_recapito_salva (PersonaRecapito *persona_recapito); + +static gboolean persona_recapito_conferma_chiusura (PersonaRecapito *persona_recapito); + +static void persona_recapito_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void persona_recapito_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean persona_recapito_on_w_persona_recapito_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data); + +static void persona_recapito_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data); +static void persona_recapito_on_btn_salva_clicked (GtkButton *button, + gpointer user_data); + + +#define PERSONA_RECAPITO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_PERSONA_RECAPITO, PersonaRecapitoPrivate)) + +enum +{ + LBL_ID, + LBL_ID_PERSONE +}; + +typedef struct _PersonaRecapitoPrivate PersonaRecapitoPrivate; +struct _PersonaRecapitoPrivate + { + Commons *commons; + + GtkForm *form; + + GtkWidget *w; + + GObject **objects; + + guint id; + }; + +G_DEFINE_TYPE (PersonaRecapito, persona_recapito, G_TYPE_OBJECT) + +static void +persona_recapito_class_init (PersonaRecapitoClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (PersonaRecapitoPrivate)); + + object_class->set_property = persona_recapito_set_property; + object_class->get_property = persona_recapito_get_property; + + /** + * PersonaRecapito::aggiornato: + * @persona_recapito: + * + */ + 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 +persona_recapito_init (PersonaRecapito *persona_recapito) +{ + PersonaRecapitoPrivate *priv = PERSONA_RECAPITO_GET_PRIVATE (persona_recapito); +} + +/** + * persona_recapito_new: + * @commons: + * @id: + * @id_persone: + * + * Returns: the newly created #PersonaRecapito object. + */ +PersonaRecapito +*persona_recapito_new (Commons *commons, guint id, guint id_persone) +{ + GError *error; + + PersonaRecapito *a = PERSONA_RECAPITO (g_object_new (persona_recapito_get_type (), NULL)); + + PersonaRecapitoPrivate *priv = PERSONA_RECAPITO_GET_PRIVATE (a); + + priv->commons = commons; + + error = NULL; + + gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile, + g_strsplit ("lstore_tipi_recapito|w_persona_recapito", "|", -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, "persona_recapito.form", NULL), priv->commons->gtkbuilder); + + priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_persona_recapito")); + + priv->objects = gtk_form_get_objects_by_name (priv->form, + "label103", + "label107", + NULL); + + g_signal_connect (priv->w, + "delete-event", G_CALLBACK (persona_recapito_on_w_persona_recapito_delete_event), (gpointer *)a); + + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button87")), + "clicked", G_CALLBACK (persona_recapito_on_btn_annulla_clicked), (gpointer *)a); + g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button88")), + "clicked", G_CALLBACK (persona_recapito_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_PERSONE]), g_strdup_printf ("%d", id_persone)); + + gtk_form_set_as_origin (priv->form); + } + else + { + gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), g_strdup_printf ("%d", priv->id)); + + persona_recapito_carica (a); + } + + return a; +} + +/** + * persona_recapito_get_widget: + * @persona_recapito: + * + */ +GtkWidget +*persona_recapito_get_widget (PersonaRecapito *persona_recapito) +{ + PersonaRecapitoPrivate *priv = PERSONA_RECAPITO_GET_PRIVATE (persona_recapito); + + return priv->w; +} + +/* PRIVATE */ +static void +persona_recapito_carica (PersonaRecapito *persona_recapito) +{ + gchar *sql; + GdaDataModel *dm; + + PersonaRecapitoPrivate *priv = PERSONA_RECAPITO_GET_PRIVATE (persona_recapito); + + if (gtk_form_fill_from_table (priv->form)) + { + } +} + +static void +persona_recapito_salva (PersonaRecapito *persona_recapito) +{ + gchar *sql; + GtkWidget *dialog; + + PersonaRecapitoClass *klass = PERSONA_RECAPITO_GET_CLASS (persona_recapito); + + PersonaRecapitoPrivate *priv = PERSONA_RECAPITO_GET_PRIVATE (persona_recapito); + + 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 (persona_recapito, 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 +persona_recapito_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + PersonaRecapito *persona_recapito = PERSONA_RECAPITO (object); + + PersonaRecapitoPrivate *priv = PERSONA_RECAPITO_GET_PRIVATE (persona_recapito); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +persona_recapito_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + PersonaRecapito *persona_recapito = PERSONA_RECAPITO (object); + + PersonaRecapitoPrivate *priv = PERSONA_RECAPITO_GET_PRIVATE (persona_recapito); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +persona_recapito_conferma_chiusura (PersonaRecapito *persona_recapito) +{ + GtkWidget *dialog; + + gboolean ret; + + PersonaRecapitoPrivate *priv = PERSONA_RECAPITO_GET_PRIVATE (persona_recapito); + + 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 +persona_recapito_on_w_persona_recapito_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + return !persona_recapito_conferma_chiusura ((PersonaRecapito *)user_data); +} + +static void +persona_recapito_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data) +{ + PersonaRecapito *persona_recapito = (PersonaRecapito *)user_data; + + PersonaRecapitoPrivate *priv = PERSONA_RECAPITO_GET_PRIVATE (persona_recapito); + + if (persona_recapito_conferma_chiusura (persona_recapito)) gtk_widget_destroy (priv->w); +} + +static void +persona_recapito_on_btn_salva_clicked (GtkButton *button, + gpointer user_data) +{ + persona_recapito_salva ((PersonaRecapito *)user_data); +} diff --git a/src/personarecapito.h b/src/personarecapito.h new file mode 100644 index 0000000..5039794 --- /dev/null +++ b/src/personarecapito.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2009 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 __PERSONA_RECAPITO_H__ +#define __PERSONA_RECAPITO_H__ + +#include +#include + +#include + +#include "commons.h" + +G_BEGIN_DECLS + + +#define TYPE_PERSONA_RECAPITO (persona_recapito_get_type ()) +#define PERSONA_RECAPITO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PERSONA_RECAPITO, PersonaRecapito)) +#define PERSONA_RECAPITO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PERSONA_RECAPITO, PersonaRecapitoClass)) +#define IS_PERSONA_RECAPITO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PERSONA_RECAPITO)) +#define IS_PERSONA_RECAPITO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PERSONA_RECAPITO)) +#define PERSONA_RECAPITO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PERSONA_RECAPITO, PersonaRecapitoClass)) + + +typedef struct _PersonaRecapito PersonaRecapito; +typedef struct _PersonaRecapitoClass PersonaRecapitoClass; + +struct _PersonaRecapito + { + GObject parent; + }; + +struct _PersonaRecapitoClass + { + GObjectClass parent_class; + + guint aggiornato_signal_id; + }; + +GType persona_recapito_get_type (void) G_GNUC_CONST; + +PersonaRecapito *persona_recapito_new (Commons *commons, guint id, guint id_persone); + +GtkWidget *persona_recapito_get_widget (PersonaRecapito *persona_recapito); + + +G_END_DECLS + +#endif /* __PERSONA_RECAPITO_H__ */