From: Andrea Zagli Date: Wed, 13 Oct 2010 07:20:22 +0000 (+0200) Subject: Gestione tabella tipi rapporto di lavoro. X-Git-Tag: 0.0.3~47 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=e60e813ac69b565b6a728a462bfad48fc5aaa4bd;p=solipa%2Forganigramma Gestione tabella tipi rapporto di lavoro. --- diff --git a/data/organigramma/form/Makefile.am b/data/organigramma/form/Makefile.am index c4df04a..b9dfa83 100644 --- a/data/organigramma/form/Makefile.am +++ b/data/organigramma/form/Makefile.am @@ -7,6 +7,7 @@ form_DATA = \ struttura.form \ struttura_indirizzo.form \ tipo_nodo.form \ + tipo_rapporto_lavoro.form \ tipo_recapito.form \ titolo.form \ ufficio.form \ diff --git a/data/organigramma/form/tipo_rapporto_lavoro.form b/data/organigramma/form/tipo_rapporto_lavoro.form new file mode 100644 index 0000000..0f14e97 --- /dev/null +++ b/data/organigramma/form/tipo_rapporto_lavoro.form @@ -0,0 +1,17 @@ + + + + tipi_rapporto_lavoro
+ + + + t + t + + + + + + + +
diff --git a/data/organigramma/gui/organigramma.gui b/data/organigramma/gui/organigramma.gui index cdd206e..32d3d3b 100644 --- a/data/organigramma/gui/organigramma.gui +++ b/data/organigramma/gui/organigramma.gui @@ -112,6 +112,14 @@ + + + True + Tipi _rapporto di lavoro + True + + + @@ -630,16 +638,6 @@ - - - - - - - - - - @@ -710,6 +708,20 @@ + + + + + + + + + + + + + + True center-on-parent @@ -5337,7 +5349,7 @@ - lbl_id_personale + lbl_id_persona 5 @@ -5547,7 +5559,7 @@ - lbl_id_personale + lbl_id_persona 1 @@ -5726,7 +5738,7 @@ - lbl_id_personale + lbl_id_persona 1 @@ -6002,7 +6014,7 @@ - lbl_id_personale + lbl_id_persona 5 @@ -6208,7 +6220,7 @@ - lbl_id_personale + lbl_id_persona 1 @@ -6824,4 +6836,260 @@ + + Tipi rapporto di lavoro - Gestione organigramma + True + center-on-parent + 500 + 400 + True + + + True + 5 + vertical + 5 + + + True + <b>Tipi rapporto di lavoro</b> + True + + + False + 0 + + + + + True + True + automatic + automatic + etched-in + + + True + True + lstore_tipi_rapporto_lavoro + False + 0 + + + Nome + + + + 1 + + + + + + + + + 1 + + + + + True + 5 + end + + + gtk-new + True + True + True + True + + + False + False + 0 + + + + + gtk-edit + True + True + True + True + + + False + False + 1 + + + + + gtk-delete + True + True + True + True + + + False + False + 2 + + + + + gtk-cancel + True + True + True + True + + + False + False + 3 + + + + + gtk-ok + True + True + True + True + + + False + False + 4 + + + + + False + 2 + + + + + + + Tipo rapporto lavoro - Gestione organigramma + True + center-on-parent + True + + + True + 5 + vertical + 5 + + + True + 2 + 2 + 5 + 5 + + + True + 0 + lbl_id + + + 1 + 2 + GTK_FILL + + + + + True + 0 + ID + + + GTK_FILL + GTK_FILL + + + + + True + 0 + Nome + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + True + 50 + + + + 1 + 2 + 1 + 2 + GTK_FILL + + + + + 0 + + + + + True + 5 + end + + + gtk-cancel + True + True + True + True + + + False + False + 0 + + + + + gtk-save + True + True + True + True + + + False + False + 1 + + + + + False + 1 + + + + + diff --git a/docs/organigramma.sql b/docs/organigramma.sql index f62267c..9048efb 100644 --- a/docs/organigramma.sql +++ b/docs/organigramma.sql @@ -2,7 +2,9 @@ -- PostgreSQL database dump -- --- Started on 2010-08-17 15:07:46 +-- Dumped from database version 8.4.4 +-- Dumped by pg_dump version 9.0.0 +-- Started on 2010-10-13 08:52:29 SET statement_timeout = 0; SET client_encoding = 'UTF8'; @@ -12,40 +14,21 @@ SET client_min_messages = warning; SET escape_string_warning = off; -- --- TOC entry 1851 (class 1262 OID 59278) --- Name: organigramma; Type: DATABASE; Schema: -; Owner: - --- - -CREATE DATABASE organigramma WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'Italian, Italy' LC_CTYPE = 'Italian, Italy'; - - -\connect organigramma - -SET statement_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = off; -SET check_function_bodies = false; -SET client_min_messages = warning; -SET escape_string_warning = off; - --- --- TOC entry 329 (class 2612 OID 16386) +-- TOC entry 337 (class 2612 OID 16386) -- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: - -- -CREATE PROCEDURAL LANGUAGE plpgsql; +CREATE OR REPLACE PROCEDURAL LANGUAGE plpgsql; SET search_path = public, pg_catalog; -SET default_tablespace = ''; - SET default_with_oids = false; -- --- TOC entry 1516 (class 1259 OID 59279) --- Dependencies: 1803 1804 1805 3 --- Name: nodi; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- TOC entry 1524 (class 1259 OID 59279) +-- Dependencies: 1815 1816 1817 3 +-- Name: nodi; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE nodi ( @@ -59,9 +42,41 @@ CREATE TABLE nodi ( -- --- TOC entry 1522 (class 1259 OID 59346) --- Dependencies: 1819 1820 1821 3 --- Name: struttura_indirizzi; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- TOC entry 1534 (class 1259 OID 61206) +-- Dependencies: 1841 3 +-- Name: persona_uffici; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE persona_uffici ( + id integer NOT NULL, + id_persone integer, + id_uffici integer, + da_data date, + a_data date, + status character varying(1) DEFAULT ''::character varying +); + + +-- +-- TOC entry 1536 (class 1259 OID 61227) +-- Dependencies: 1845 1846 1847 1848 3 +-- Name: persone; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE persone ( + id integer NOT NULL, + cognome character varying(50) DEFAULT ''::character varying, + nome character varying(50) DEFAULT ''::character varying, + id_titoli integer DEFAULT 0, + data_nascita date, + status character varying(1) DEFAULT ''::character varying +); + + +-- +-- TOC entry 1530 (class 1259 OID 59346) +-- Dependencies: 1831 1832 1833 3 +-- Name: struttura_indirizzi; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE struttura_indirizzi ( @@ -75,9 +90,9 @@ CREATE TABLE struttura_indirizzi ( -- --- TOC entry 1520 (class 1259 OID 59327) --- Dependencies: 1813 1814 1815 1816 1817 3 --- Name: strutture; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- TOC entry 1528 (class 1259 OID 59327) +-- Dependencies: 1825 1826 1827 1828 1829 3 +-- Name: strutture; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE strutture ( @@ -91,9 +106,9 @@ CREATE TABLE strutture ( -- --- TOC entry 1517 (class 1259 OID 59290) --- Dependencies: 1806 1807 3 --- Name: tipi_nodo; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- TOC entry 1525 (class 1259 OID 59290) +-- Dependencies: 1818 1819 3 +-- Name: tipi_nodo; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE tipi_nodo ( @@ -104,9 +119,22 @@ CREATE TABLE tipi_nodo ( -- --- TOC entry 1518 (class 1259 OID 59297) --- Dependencies: 1808 1809 3 --- Name: tipi_recapito; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- TOC entry 1537 (class 1259 OID 61236) +-- Dependencies: 1849 1850 3 +-- Name: tipi_rapporto_lavoro; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE tipi_rapporto_lavoro ( + id integer NOT NULL, + nome character varying(255) DEFAULT ''::character varying, + status character varying(1) DEFAULT ''::character varying +); + + +-- +-- TOC entry 1526 (class 1259 OID 59297) +-- Dependencies: 1820 1821 3 +-- Name: tipi_recapito; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE tipi_recapito ( @@ -117,9 +145,23 @@ CREATE TABLE tipi_recapito ( -- --- TOC entry 1519 (class 1259 OID 59311) --- Dependencies: 1810 1811 1812 3 --- Name: uffici; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- TOC entry 1535 (class 1259 OID 61219) +-- Dependencies: 1842 1843 1844 3 +-- Name: titoli; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE titoli ( + id integer NOT NULL, + sigla character varying(10) DEFAULT ''::character varying, + descrizione character varying(50) DEFAULT ''::character varying, + status character varying(1) DEFAULT ''::character varying +); + + +-- +-- TOC entry 1527 (class 1259 OID 59311) +-- Dependencies: 1822 1823 1824 3 +-- Name: uffici; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE uffici ( @@ -132,9 +174,9 @@ CREATE TABLE uffici ( -- --- TOC entry 1523 (class 1259 OID 59357) --- Dependencies: 1822 1823 3 --- Name: ufficio_nodi; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- TOC entry 1531 (class 1259 OID 59357) +-- Dependencies: 1834 1835 3 +-- Name: ufficio_nodi; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE ufficio_nodi ( @@ -147,9 +189,9 @@ CREATE TABLE ufficio_nodi ( -- --- TOC entry 1524 (class 1259 OID 59399) --- Dependencies: 1824 1825 3 --- Name: ufficio_orari; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- TOC entry 1532 (class 1259 OID 59399) +-- Dependencies: 1836 1837 3 +-- Name: ufficio_orari; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE ufficio_orari ( @@ -175,9 +217,9 @@ CREATE TABLE ufficio_orari ( -- --- TOC entry 1525 (class 1259 OID 59409) --- Dependencies: 1826 1827 1828 3 --- Name: ufficio_recapiti; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- TOC entry 1533 (class 1259 OID 59409) +-- Dependencies: 1838 1839 1840 3 +-- Name: ufficio_recapiti; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE ufficio_recapiti ( @@ -192,9 +234,9 @@ CREATE TABLE ufficio_recapiti ( -- --- TOC entry 1521 (class 1259 OID 59340) --- Dependencies: 1818 3 --- Name: vie; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- TOC entry 1529 (class 1259 OID 59340) +-- Dependencies: 1830 3 +-- Name: vie; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE vie ( @@ -204,9 +246,9 @@ CREATE TABLE vie ( -- --- TOC entry 1830 (class 2606 OID 59289) --- Dependencies: 1516 1516 --- Name: nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- TOC entry 1852 (class 2606 OID 59289) +-- Dependencies: 1524 1524 +-- Name: nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY nodi @@ -214,9 +256,29 @@ ALTER TABLE ONLY nodi -- --- TOC entry 1842 (class 2606 OID 59356) --- Dependencies: 1522 1522 --- Name: struttura_indirizzi_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- TOC entry 1872 (class 2606 OID 61211) +-- Dependencies: 1534 1534 +-- Name: persona_uffici_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY persona_uffici + ADD CONSTRAINT persona_uffici_pkey PRIMARY KEY (id); + + +-- +-- TOC entry 1876 (class 2606 OID 61235) +-- Dependencies: 1536 1536 +-- Name: persone_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY persone + ADD CONSTRAINT persone_pkey PRIMARY KEY (id); + + +-- +-- TOC entry 1864 (class 2606 OID 59356) +-- Dependencies: 1530 1530 +-- Name: struttura_indirizzi_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY struttura_indirizzi @@ -224,9 +286,9 @@ ALTER TABLE ONLY struttura_indirizzi -- --- TOC entry 1838 (class 2606 OID 59339) --- Dependencies: 1520 1520 --- Name: strutture_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- TOC entry 1860 (class 2606 OID 59339) +-- Dependencies: 1528 1528 +-- Name: strutture_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY strutture @@ -234,9 +296,9 @@ ALTER TABLE ONLY strutture -- --- TOC entry 1832 (class 2606 OID 59296) --- Dependencies: 1517 1517 --- Name: tipi_nodo_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- TOC entry 1854 (class 2606 OID 59296) +-- Dependencies: 1525 1525 +-- Name: tipi_nodo_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY tipi_nodo @@ -244,9 +306,19 @@ ALTER TABLE ONLY tipi_nodo -- --- TOC entry 1834 (class 2606 OID 59303) --- Dependencies: 1518 1518 --- Name: tipi_recapito_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- TOC entry 1878 (class 2606 OID 61242) +-- Dependencies: 1537 1537 +-- Name: tipi_rapporto_lavoro_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY tipi_rapporto_lavoro + ADD CONSTRAINT tipi_rapporto_lavoro_pkey PRIMARY KEY (id); + + +-- +-- TOC entry 1856 (class 2606 OID 59303) +-- Dependencies: 1526 1526 +-- Name: tipi_recapito_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY tipi_recapito @@ -254,9 +326,19 @@ ALTER TABLE ONLY tipi_recapito -- --- TOC entry 1836 (class 2606 OID 59321) --- Dependencies: 1519 1519 --- Name: uffici_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- TOC entry 1874 (class 2606 OID 61226) +-- Dependencies: 1535 1535 +-- Name: titoli_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY titoli + ADD CONSTRAINT titoli_pkey PRIMARY KEY (id); + + +-- +-- TOC entry 1858 (class 2606 OID 59321) +-- Dependencies: 1527 1527 +-- Name: uffici_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY uffici @@ -264,9 +346,9 @@ ALTER TABLE ONLY uffici -- --- TOC entry 1844 (class 2606 OID 59366) --- Dependencies: 1523 1523 --- Name: ufficio_nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- TOC entry 1866 (class 2606 OID 59366) +-- Dependencies: 1531 1531 +-- Name: ufficio_nodi_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY ufficio_nodi @@ -274,9 +356,9 @@ ALTER TABLE ONLY ufficio_nodi -- --- TOC entry 1846 (class 2606 OID 59408) --- Dependencies: 1524 1524 --- Name: ufficio_orari_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- TOC entry 1868 (class 2606 OID 59408) +-- Dependencies: 1532 1532 +-- Name: ufficio_orari_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY ufficio_orari @@ -284,9 +366,9 @@ ALTER TABLE ONLY ufficio_orari -- --- TOC entry 1848 (class 2606 OID 59419) --- Dependencies: 1525 1525 --- Name: ufficio_recapiti_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- TOC entry 1870 (class 2606 OID 59419) +-- Dependencies: 1533 1533 +-- Name: ufficio_recapiti_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY ufficio_recapiti @@ -294,28 +376,16 @@ ALTER TABLE ONLY ufficio_recapiti -- --- TOC entry 1840 (class 2606 OID 59345) --- Dependencies: 1521 1521 --- Name: vie_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- TOC entry 1862 (class 2606 OID 59345) +-- Dependencies: 1529 1529 +-- Name: vie_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY vie ADD CONSTRAINT vie_pkey PRIMARY KEY (id); --- --- TOC entry 1853 (class 0 OID 0) --- Dependencies: 3 --- Name: public; Type: ACL; Schema: -; Owner: - --- - -REVOKE ALL ON SCHEMA public FROM PUBLIC; -REVOKE ALL ON SCHEMA public FROM postgres; -GRANT ALL ON SCHEMA public TO postgres; -GRANT ALL ON SCHEMA public TO PUBLIC; - - --- Completed on 2010-08-17 15:07:46 +-- Completed on 2010-10-13 08:52:29 -- -- PostgreSQL database dump complete diff --git a/src/Makefile.am b/src/Makefile.am index 78a2520..505967b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,10 +31,14 @@ organigramma_SOURCES = \ strutture.h \ tipinodo.c \ tipinodo.h \ + tipirapportolavoro.c \ + tipirapportolavoro.h \ tipirecapito.c \ tipirecapito.h \ tiponodo.c \ tiponodo.h \ + tiporapportolavoro.c \ + tiporapportolavoro.h \ tiporecapito.c \ tiporecapito.h \ titoli.c \ diff --git a/src/main.c b/src/main.c index 31e396a..7c85aaa 100644 --- a/src/main.c +++ b/src/main.c @@ -32,6 +32,7 @@ #include "persone.h" #include "strutture.h" #include "tipinodo.h" +#include "tipirapportolavoro.h" #include "tipirecapito.h" #include "titoli.h" #include "uffici.h" @@ -148,6 +149,19 @@ on_mnu_tabelle_titoli_activate (GtkMenuItem *menuitem, main_set_vbx_body_child (vbx); } +G_MODULE_EXPORT void +on_mnu_tabelle_tipi_rapporto_lavoro_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkWidget *vbx; + + TipiRapportoLavoro *m = tipi_rapporto_lavoro_new (commons, FALSE); + + vbx = tipi_rapporto_lavoro_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/tipirapportolavoro.c b/src/tipirapportolavoro.c new file mode 100644 index 0000000..8544853 --- /dev/null +++ b/src/tipirapportolavoro.c @@ -0,0 +1,452 @@ +/* + * 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 "tipirapportolavoro.h" +#include "tiporapportolavoro.h" + +static void tipi_rapporto_lavoro_class_init (TipiRapportoLavoroClass *klass); +static void tipi_rapporto_lavoro_init (TipiRapportoLavoro *tipi_rapporto_lavoro); + +static void tipi_rapporto_lavoro_carica (TipiRapportoLavoro *tipi_rapporto_lavoro); +static void tipi_rapporto_lavoro_modifica (TipiRapportoLavoro *tipi_rapporto_lavoro); + +static void tipi_rapporto_lavoro_selezionato (TipiRapportoLavoro *tipi_rapporto_lavoro); +static void tipi_rapporto_lavoro_on_costo_aggiornato (gpointer instance, gpointer user_data); + +static void tipi_rapporto_lavoro_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void tipi_rapporto_lavoro_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void tipi_rapporto_lavoro_on_btn_nuovo_clicked (GtkButton *button, + gpointer user_data); +static void tipi_rapporto_lavoro_on_btn_modifica_clicked (GtkButton *button, + gpointer user_data); +static void tipi_rapporto_lavoro_on_btn_elimina_clicked (GtkButton *button, + gpointer user_data); +static void tipi_rapporto_lavoro_on_trv_tipi_rapporto_lavoro_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data); + +static void tipi_rapporto_lavoro_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data); +static void tipi_rapporto_lavoro_on_btn_seleziona_clicked (GtkButton *button, + gpointer user_data); + +#define TIPI_RAPPORTO_LAVORO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TIPI_RAPPORTO_LAVORO, TipiRapportoLavoroPrivate)) + +enum +{ + COL_ID, + COL_NOME +}; + +typedef struct _TipiRapportoLavoroPrivate TipiRapportoLavoroPrivate; +struct _TipiRapportoLavoroPrivate + { + Commons *commons; + + GtkWidget *widget; + GtkTreeSelection *selection; + GtkListStore *lstore_tipi_rapporto_lavoro; + + gboolean selezione; + GtkWindow *wtransient; + }; + +G_DEFINE_TYPE (TipiRapportoLavoro, tipi_rapporto_lavoro, G_TYPE_OBJECT) + +static void +tipi_rapporto_lavoro_class_init (TipiRapportoLavoroClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (TipiRapportoLavoroPrivate)); + + object_class->set_property = tipi_rapporto_lavoro_set_property; + object_class->get_property = tipi_rapporto_lavoro_get_property; + + /** + * TipiRapportoLavoro::selezionato: + * @tipi_rapporto_lavoro: + * + */ + 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 +tipi_rapporto_lavoro_init (TipiRapportoLavoro *tipi_rapporto_lavoro) +{ + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE (tipi_rapporto_lavoro); +} + +/** + * tipi_rapporto_lavoro_new: + * @commons: + * @selezione: + * + * Returns: the newly created #TipiRapportoLavoro object. + */ +TipiRapportoLavoro +*tipi_rapporto_lavoro_new (Commons *commons, gboolean selezione) +{ + GError *error; + + TipiRapportoLavoro *a = TIPI_RAPPORTO_LAVORO (g_object_new (tipi_rapporto_lavoro_get_type (), NULL)); + + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_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_tipi_rapporto_lavoro|", + (selezione ? "w_tipi_rapporto_lavoro" : "vbx_tipi_rapporto_lavoro"), + 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_tipi_rapporto_lavoro" : "vbx_tipi_rapporto_lavoro"))); + priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview19"))); + priv->lstore_tipi_rapporto_lavoro = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_tipi_rapporto_lavoro")); + + 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, "button109"), + "clicked", G_CALLBACK (tipi_rapporto_lavoro_on_btn_nuovo_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button110"), + "clicked", G_CALLBACK (tipi_rapporto_lavoro_on_btn_modifica_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button111"), + "clicked", G_CALLBACK (tipi_rapporto_lavoro_on_btn_elimina_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview19"), + "row-activated", G_CALLBACK (tipi_rapporto_lavoro_on_trv_tipi_rapporto_lavoro_row_activated), (gpointer)a); + + if (priv->selezione) + { + gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "label143"))); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button112"), + "clicked", G_CALLBACK (tipi_rapporto_lavoro_on_btn_annulla_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button113"), + "clicked", G_CALLBACK (tipi_rapporto_lavoro_on_btn_seleziona_clicked), (gpointer)a); + } + else + { + gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button112"))); + gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button113"))); + } + + tipi_rapporto_lavoro_carica (a); + + return a; +} + +/** + * tipi_rapporto_lavoro_get_widget: + * @tipi_rapporto_lavoro: + * + */ +GtkWidget +*tipi_rapporto_lavoro_get_widget (TipiRapportoLavoro *tipi_rapporto_lavoro) +{ + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE (tipi_rapporto_lavoro); + + return priv->widget; +} + +/* PRIVATE */ +static void +tipi_rapporto_lavoro_carica (TipiRapportoLavoro *tipi_rapporto_lavoro) +{ + GtkTreeIter iter; + GdaDataModel *dm; + + gint rows; + gint row; + + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE (tipi_rapporto_lavoro); + + gtk_list_store_clear (priv->lstore_tipi_rapporto_lavoro); + + dm = gdaex_query (priv->commons->gdaex, + "SELECT c.id, c.nome" + " FROM tipi_rapporto_lavoro 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_tipi_rapporto_lavoro, &iter); + + gtk_list_store_set (priv->lstore_tipi_rapporto_lavoro, &iter, + COL_ID, gdaex_data_model_get_field_value_stringify_at (dm, row, "id"), + COL_NOME, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"), + -1); + } + + g_object_unref (dm); + } +} + +static void +tipi_rapporto_lavoro_modifica (TipiRapportoLavoro *tipi_rapporto_lavoro) +{ + GtkTreeIter iter; + gchar *id; + + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE (tipi_rapporto_lavoro); + + if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter)) + { + GtkWidget *w; + + gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_tipi_rapporto_lavoro), &iter, + COL_ID, &id, + -1); + + TipoRapportoLavoro *c = tipo_rapporto_lavoro_new (priv->commons, strtol (id, NULL, 10)); + + g_signal_connect (G_OBJECT (c), "aggiornato", + G_CALLBACK (tipi_rapporto_lavoro_on_costo_aggiornato), (gpointer)tipi_rapporto_lavoro); + + w = tipo_rapporto_lavoro_get_widget (c); + if (priv->selezione) + { + gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->widget)); + } + else + { + gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main"))); + } + 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 un tipo rapporto lavoro."); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +tipi_rapporto_lavoro_selezionato (TipiRapportoLavoro *tipi_rapporto_lavoro) +{ + GtkTreeIter iter; + gchar *id; + + TipiRapportoLavoroClass *klass = TIPI_RAPPORTO_LAVORO_GET_CLASS (tipi_rapporto_lavoro); + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE (tipi_rapporto_lavoro); + + if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter)) + { + gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_tipi_rapporto_lavoro), &iter, + COL_ID, &id, + -1); + + g_signal_emit (G_OBJECT (tipi_rapporto_lavoro), klass->selezionato_signal_id, 0, strtol (id, NULL, 10)); + + gtk_widget_destroy (priv->widget); + g_object_unref (G_OBJECT (tipi_rapporto_lavoro)); + } + else + { + GtkWidget *dialog = gtk_message_dialog_new (priv->wtransient, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + "Occorre prima selezionare un tipo rapporto lavoro."); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +tipi_rapporto_lavoro_on_costo_aggiornato (gpointer instance, gpointer user_data) +{ + tipi_rapporto_lavoro_carica ((TipiRapportoLavoro *)user_data); +} + +static void +tipi_rapporto_lavoro_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + TipiRapportoLavoro *tipi_rapporto_lavoro = TIPI_RAPPORTO_LAVORO (object); + + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE (tipi_rapporto_lavoro); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +tipi_rapporto_lavoro_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + TipiRapportoLavoro *tipi_rapporto_lavoro = TIPI_RAPPORTO_LAVORO (object); + + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE (tipi_rapporto_lavoro); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +/* CALLBACK */ +static void +tipi_rapporto_lavoro_on_btn_nuovo_clicked (GtkButton *button, + gpointer user_data) +{ + GtkWidget *w; + + TipiRapportoLavoro *tipi_rapporto_lavoro = (TipiRapportoLavoro *)user_data; + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE (tipi_rapporto_lavoro); + + TipoRapportoLavoro *c = tipo_rapporto_lavoro_new (priv->commons, 0); + + g_signal_connect (G_OBJECT (c), "aggiornato", + G_CALLBACK (tipi_rapporto_lavoro_on_costo_aggiornato), (gpointer)tipi_rapporto_lavoro); + + w = tipo_rapporto_lavoro_get_widget (c); + gtk_window_set_transient_for (GTK_WINDOW (w), priv->wtransient); + gtk_widget_show (w); +} + +static void +tipi_rapporto_lavoro_on_btn_modifica_clicked (GtkButton *button, + gpointer user_data) +{ + tipi_rapporto_lavoro_modifica ((TipiRapportoLavoro *)user_data); +} + +static void +tipi_rapporto_lavoro_on_btn_elimina_clicked (GtkButton *button, + gpointer user_data) +{ + GtkWidget *dialog; + gboolean risp; + + GtkTreeIter iter; + gchar *id; + + TipiRapportoLavoro *tipi_rapporto_lavoro = (TipiRapportoLavoro *)user_data; + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE (tipi_rapporto_lavoro); + + 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 il tipo rapporto lavoro selezionato?"); + risp = gtk_dialog_run (GTK_DIALOG (dialog)); + if (risp == GTK_RESPONSE_YES) + { + gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_tipi_rapporto_lavoro), &iter, + COL_ID, &id, + -1); + + gdaex_execute (priv->commons->gdaex, + g_strdup_printf ("UPDATE tipi_rapporto_lavoro SET status = 'E' WHERE id = %d", strtol (id, NULL, 10))); + + tipi_rapporto_lavoro_carica (tipi_rapporto_lavoro); + } + 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 un tipo rapporto di lavoro."); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +tipi_rapporto_lavoro_on_trv_tipi_rapporto_lavoro_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data) +{ + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE ((TipiRapportoLavoro *)user_data); + + if (priv->selezione) + { + tipi_rapporto_lavoro_selezionato ((TipiRapportoLavoro *)user_data); + } + else + { + tipi_rapporto_lavoro_modifica ((TipiRapportoLavoro *)user_data); + } +} + + +static void +tipi_rapporto_lavoro_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data) +{ + TipiRapportoLavoroPrivate *priv = TIPI_RAPPORTO_LAVORO_GET_PRIVATE ((TipiRapportoLavoro *)user_data); + + gtk_widget_destroy (priv->widget); + g_object_unref (G_OBJECT (user_data)); +} + +static void +tipi_rapporto_lavoro_on_btn_seleziona_clicked (GtkButton *button, + gpointer user_data) +{ + tipi_rapporto_lavoro_selezionato ((TipiRapportoLavoro *)user_data); +} diff --git a/src/tipirapportolavoro.h b/src/tipirapportolavoro.h new file mode 100644 index 0000000..dc0e9a0 --- /dev/null +++ b/src/tipirapportolavoro.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 __TIPI_RAPPORTO_LAVORO_H__ +#define __TIPI_RAPPORTO_LAVORO_H__ + +#include +#include + +#include +#include + +#include "commons.h" + +G_BEGIN_DECLS + + +#define TYPE_TIPI_RAPPORTO_LAVORO (tipi_rapporto_lavoro_get_type ()) +#define TIPI_RAPPORTO_LAVORO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TIPI_RAPPORTO_LAVORO, TipiRapportoLavoro)) +#define TIPI_RAPPORTO_LAVORO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TIPI_RAPPORTO_LAVORO, TipiRapportoLavoroClass)) +#define IS_TIPI_RAPPORTO_LAVORO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TIPI_RAPPORTO_LAVORO)) +#define IS_TIPI_RAPPORTO_LAVORO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TIPI_RAPPORTO_LAVORO)) +#define TIPI_RAPPORTO_LAVORO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TIPI_RAPPORTO_LAVORO, TipiRapportoLavoroClass)) + + +typedef struct _TipiRapportoLavoro TipiRapportoLavoro; +typedef struct _TipiRapportoLavoroClass TipiRapportoLavoroClass; + +struct _TipiRapportoLavoro + { + GObject parent; + }; + +struct _TipiRapportoLavoroClass + { + GObjectClass parent_class; + + guint selezionato_signal_id; + }; + +GType tipi_rapporto_lavoro_get_type (void) G_GNUC_CONST; + +TipiRapportoLavoro *tipi_rapporto_lavoro_new (Commons *commons, gboolean selezione); + +GtkWidget *tipi_rapporto_lavoro_get_widget (TipiRapportoLavoro *tipi_rapporto_lavoro); + + +G_END_DECLS + +#endif /* __TIPI_RAPPORTO_LAVORO_H__ */ diff --git a/src/tiporapportolavoro.c b/src/tiporapportolavoro.c new file mode 100644 index 0000000..3905c58 --- /dev/null +++ b/src/tiporapportolavoro.c @@ -0,0 +1,336 @@ +/* + * 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 "tiporapportolavoro.h" + +static void tipo_rapporto_lavoro_class_init (TipoRapportoLavoroClass *klass); +static void tipo_rapporto_lavoro_init (TipoRapportoLavoro *tipo_rapporto_lavoro); + +static void tipo_rapporto_lavoro_carica (TipoRapportoLavoro *tipo_rapporto_lavoro); +static void tipo_rapporto_lavoro_salva (TipoRapportoLavoro *tipo_rapporto_lavoro); + +static gboolean tipo_rapporto_lavoro_conferma_chiusura (TipoRapportoLavoro *tipo_rapporto_lavoro); + +static void tipo_rapporto_lavoro_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void tipo_rapporto_lavoro_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean tipo_rapporto_lavoro_on_w_tipo_rapporto_lavoro_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data); + +static void tipo_rapporto_lavoro_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data); +static void tipo_rapporto_lavoro_on_btn_salva_clicked (GtkButton *button, + gpointer user_data); + +#define TIPO_RAPPORTO_LAVORO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TIPO_RAPPORTO_LAVORO, TipoRapportoLavoroPrivate)) + +enum +{ + LBL_ID +}; + +typedef struct _TipoRapportoLavoroPrivate TipoRapportoLavoroPrivate; +struct _TipoRapportoLavoroPrivate + { + Commons *commons; + + GtkForm *form; + + GtkWidget *w; + + GObject **objects; + + gint id; + }; + +G_DEFINE_TYPE (TipoRapportoLavoro, tipo_rapporto_lavoro, G_TYPE_OBJECT) + +static void +tipo_rapporto_lavoro_class_init (TipoRapportoLavoroClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (TipoRapportoLavoroPrivate)); + + object_class->set_property = tipo_rapporto_lavoro_set_property; + object_class->get_property = tipo_rapporto_lavoro_get_property; + + /** + * TipoRapportoLavoro::aggiornato: + * @tipo_rapporto_lavoro: + * + */ + 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 +tipo_rapporto_lavoro_init (TipoRapportoLavoro *tipo_rapporto_lavoro) +{ + TipoRapportoLavoroPrivate *priv = TIPO_RAPPORTO_LAVORO_GET_PRIVATE (tipo_rapporto_lavoro); +} + +/** + * tipo_rapporto_lavoro_new: + * @commons: + * @id: + * + * Returns: the newly created #TipoRapportoLavoro object. + */ +TipoRapportoLavoro +*tipo_rapporto_lavoro_new (Commons *commons, gint id) +{ + GError *error; + + TipoRapportoLavoro *a = TIPO_RAPPORTO_LAVORO (g_object_new (tipo_rapporto_lavoro_get_type (), NULL)); + + TipoRapportoLavoroPrivate *priv = TIPO_RAPPORTO_LAVORO_GET_PRIVATE (a); + + priv->commons = commons; + + error = NULL; + gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile, + g_strsplit ("w_tipo_rapporto_lavoro", "|", -1), + &error); + if (error != NULL) + { + g_warning ("Errore: %s.", error->message); + return NULL; + } + + priv->form = gtk_form_new_from_file (g_build_filename (priv->commons->formdir, "tipo_rapporto_lavoro.form", NULL), priv->commons->gtkbuilder); + + g_object_set (priv->form, "gdaex", priv->commons->gdaex, NULL); + + priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_tipo_rapporto_lavoro")); + + priv->objects = gtk_form_get_objects_by_name (priv->form, + "label145", + NULL); + + g_signal_connect (priv->w, + "delete-event", G_CALLBACK (tipo_rapporto_lavoro_on_w_tipo_rapporto_lavoro_delete_event), (gpointer *)a); + + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button114"), + "clicked", G_CALLBACK (tipo_rapporto_lavoro_on_btn_annulla_clicked), (gpointer *)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button115"), + "clicked", G_CALLBACK (tipo_rapporto_lavoro_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)); + tipo_rapporto_lavoro_carica (a); + } + + return a; +} + +/** + * tipo_rapporto_lavoro_get_widget: + * @tipo_rapporto_lavoro: + * + */ +GtkWidget +*tipo_rapporto_lavoro_get_widget (TipoRapportoLavoro *tipo_rapporto_lavoro) +{ + TipoRapportoLavoroPrivate *priv = TIPO_RAPPORTO_LAVORO_GET_PRIVATE (tipo_rapporto_lavoro); + + return priv->w; +} + +/* PRIVATE */ +static void +tipo_rapporto_lavoro_carica (TipoRapportoLavoro *tipo_rapporto_lavoro) +{ + TipoRapportoLavoroPrivate *priv = TIPO_RAPPORTO_LAVORO_GET_PRIVATE (tipo_rapporto_lavoro); + + gtk_form_fill_from_table (priv->form); +} + +static void +tipo_rapporto_lavoro_salva (TipoRapportoLavoro *tipo_rapporto_lavoro) +{ + GError *error = NULL; + gchar *sql; + GtkWidget *dialog; + + GDate *da; + GDate *a; + + TipoRapportoLavoroClass *klass = TIPO_RAPPORTO_LAVORO_GET_CLASS (tipo_rapporto_lavoro); + + TipoRapportoLavoroPrivate *priv = TIPO_RAPPORTO_LAVORO_GET_PRIVATE (tipo_rapporto_lavoro); + + 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 (tipo_rapporto_lavoro, 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 +tipo_rapporto_lavoro_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + TipoRapportoLavoro *tipo_rapporto_lavoro = TIPO_RAPPORTO_LAVORO (object); + + TipoRapportoLavoroPrivate *priv = TIPO_RAPPORTO_LAVORO_GET_PRIVATE (tipo_rapporto_lavoro); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +tipo_rapporto_lavoro_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + TipoRapportoLavoro *tipo_rapporto_lavoro = TIPO_RAPPORTO_LAVORO (object); + + TipoRapportoLavoroPrivate *priv = TIPO_RAPPORTO_LAVORO_GET_PRIVATE (tipo_rapporto_lavoro); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +tipo_rapporto_lavoro_conferma_chiusura (TipoRapportoLavoro *tipo_rapporto_lavoro) +{ + GtkWidget *dialog; + + gboolean ret; + + TipoRapportoLavoroPrivate *priv = TIPO_RAPPORTO_LAVORO_GET_PRIVATE (tipo_rapporto_lavoro); + + 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 +tipo_rapporto_lavoro_on_w_tipo_rapporto_lavoro_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + return !tipo_rapporto_lavoro_conferma_chiusura ((TipoRapportoLavoro *)user_data); +} + +static void +tipo_rapporto_lavoro_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data) +{ + TipoRapportoLavoro *tipo_rapporto_lavoro = (TipoRapportoLavoro *)user_data; + + TipoRapportoLavoroPrivate *priv = TIPO_RAPPORTO_LAVORO_GET_PRIVATE (tipo_rapporto_lavoro); + + if (tipo_rapporto_lavoro_conferma_chiusura (tipo_rapporto_lavoro)) gtk_widget_destroy (priv->w); +} + +static void +tipo_rapporto_lavoro_on_btn_salva_clicked (GtkButton *button, + gpointer user_data) +{ + tipo_rapporto_lavoro_salva ((TipoRapportoLavoro *)user_data); +} diff --git a/src/tiporapportolavoro.h b/src/tiporapportolavoro.h new file mode 100644 index 0000000..fbfd887 --- /dev/null +++ b/src/tiporapportolavoro.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 __TIPO_RAPPORTO_LAVORO_H__ +#define __TIPO_RAPPORTO_LAVORO_H__ + +#include +#include + +#include +#include + +#include "commons.h" + +G_BEGIN_DECLS + + +#define TYPE_TIPO_RAPPORTO_LAVORO (tipo_rapporto_lavoro_get_type ()) +#define TIPO_RAPPORTO_LAVORO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TIPO_RAPPORTO_LAVORO, TipoRapportoLavoro)) +#define TIPO_RAPPORTO_LAVORO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TIPO_RAPPORTO_LAVORO, TipoRapportoLavoroClass)) +#define IS_TIPO_RAPPORTO_LAVORO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TIPO_RAPPORTO_LAVORO)) +#define IS_TIPO_RAPPORTO_LAVORO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TIPO_RAPPORTO_LAVORO)) +#define TIPO_RAPPORTO_LAVORO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TIPO_RAPPORTO_LAVORO, TipoRapportoLavoroClass)) + + +typedef struct _TipoRapportoLavoro TipoRapportoLavoro; +typedef struct _TipoRapportoLavoroClass TipoRapportoLavoroClass; + +struct _TipoRapportoLavoro + { + GObject parent; + }; + +struct _TipoRapportoLavoroClass + { + GObjectClass parent_class; + + guint aggiornato_signal_id; + }; + +GType tipo_rapporto_lavoro_get_type (void) G_GNUC_CONST; + +TipoRapportoLavoro *tipo_rapporto_lavoro_new (Commons *commons, gint id); + +GtkWidget *tipo_rapporto_lavoro_get_widget (TipoRapportoLavoro *tipo_rapporto_lavoro); + + +G_END_DECLS + +#endif /* __TIPO_RAPPORTO_LAVORO_H__ */