]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Inizio gestione persone.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 13 Oct 2010 06:44:31 +0000 (08:44 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 13 Oct 2010 06:44:31 +0000 (08:44 +0200)
12 files changed:
data/organigramma/form/Makefile.am
data/organigramma/form/persona.form [new file with mode: 0644]
data/organigramma/form/persona_ufficio.form [new file with mode: 0644]
data/organigramma/gui/organigramma.gui
src/Makefile.am
src/main.c
src/persona.c [new file with mode: 0644]
src/persona.h [new file with mode: 0644]
src/personaufficio.c [new file with mode: 0644]
src/personaufficio.h [new file with mode: 0644]
src/persone.c [new file with mode: 0644]
src/persone.h [new file with mode: 0644]

index de635a70487e7dd9014d6df6a939af37c53dea02..c4df04a9bc8e19fd56b0bfc61812d931f7d9cb90 100644 (file)
@@ -2,6 +2,8 @@ formdir = $(datadir)/$(PACKAGE)/form
 
 form_DATA = \
             nodo.form \
+            persona.form \
+            persona_ufficio.form \
             struttura.form \
             struttura_indirizzo.form \
             tipo_nodo.form \
diff --git a/data/organigramma/form/persona.form b/data/organigramma/form/persona.form
new file mode 100644 (file)
index 0000000..b63a8db
--- /dev/null
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<gtkform>
+
+       <table>persone</table>
+
+       <widget type="label" name="label67" label="label68">
+               <field type="integer" name="id">
+                       <is-key>t</is-key>
+                       <auto-increment>t</auto-increment>
+               </field>
+       </widget>
+
+       <widget type="entry" name="entry14" label="label65">
+               <field type="text" name="nome" />
+       </widget>
+
+       <widget type="entry" name="entry17" label="label72">
+               <field type="text" name="cognome">
+                       <obligatory>t</obligatory>
+               </field>
+       </widget>
+
+       <widget type="combobox" name="combobox4" label="label73">
+               <column-field>0</column-field>
+               <sql with-empty-entry="t">
+                       SELECT id, descrizione FROM titoli WHERE status &lt;&gt; 'E' ORDER BY descrizione
+               </sql>
+               <field type="integer" name="id_titoli">
+               </field>
+       </widget>
+
+       <widget type="entry" name="entry20" label="label84">
+               <field type="datetime" name="data_nascita">
+                       <datetime-type>date</datetime-type>
+                       <display-format>%d/%m/%Y</display-format>
+               </field>
+       </widget>
+
+</gtkform>
diff --git a/data/organigramma/form/persona_ufficio.form b/data/organigramma/form/persona_ufficio.form
new file mode 100644 (file)
index 0000000..0177a9c
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0"?>
+<gtkform>
+
+       <table>persona_uffici</table>
+
+       <widget type="label" name="label90">
+               <field type="integer" name="id">
+                       <is-key>t</is-key>
+                       <auto-increment>t</auto-increment>
+               </field>
+       </widget>
+
+       <widget type="label" name="label91">
+               <field type="integer" name="id_persone">
+               </field>
+       </widget>
+
+       <widget type="entry" name="entry21">
+               <field type="text" name="ufficio">
+                       <to-load>f</to-load>
+                       <to-save>f</to-save>
+               </field>
+       </widget>
+
+       <widget type="label" name="label89" label="label88">
+               <on-change what="update" when="after">
+                       <widget-name>entry21</widget-name>
+                       <sql>
+                               SELECT nome FROM ufficio WHERE id = ##label89::gint
+                       </sql>
+               </on-change>
+               <field type="integer" name="id_uffici">
+               </field>
+       </widget>
+
+       <widget type="entry" name="entry22" label="label92">
+               <field type="datetime" name="da_data">
+                       <datetime-type>date</datetime-type>
+                       <display-format>%d/%m/%Y</display-format>
+               </field>
+       </widget>
+
+       <widget type="entry" name="entry23" label="label93">
+               <field type="datetime" name="a_data">
+                       <datetime-type>date</datetime-type>
+                       <display-format>%d/%m/%Y</display-format>
+               </field>
+       </widget>
+
+       <widget type="textview" name="textview9" label="label87">
+               <field type="text" name="descrizione" />
+       </widget>
+
+</gtkform>
index 5e427485304b987b294d2d51699a3b18cf4430fd..cdd206e4f8534a5de4893c1ffaaad740914e2967 100644 (file)
                         <signal name="activate" handler="on_mnu_view_uffici_activate"/>
                       </object>
                     </child>
+                    <child>
+                      <object class="GtkMenuItem" id="menuitem11">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">_Persone</property>
+                        <property name="use_underline">True</property>
+                        <signal name="activate" handler="on_mnu_view_persone_activate"/>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>
       <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkListStore" id="lstore_persone">
+    <columns>
+      <!-- column-name id -->
+      <column type="guint"/>
+      <!-- column-name cognome_nome -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkWindow" id="w_nodi">
     <property name="modal">True</property>
     <property name="window_position">center-on-parent</property>
     <property name="title" translatable="yes">Persona - Gestione organigramma</property>
     <property name="modal">True</property>
     <property name="window_position">center-on-parent</property>
+    <property name="default_width">500</property>
     <property name="destroy_with_parent">True</property>
     <child>
       <object class="GtkVBox" id="vbox11">
               <object class="GtkEntry" id="entry14">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="max_length">100</property>
+                <property name="max_length">50</property>
                 <property name="invisible_char">&#x25CF;</property>
               </object>
               <packing>
               <object class="GtkEntry" id="entry17">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="max_length">50</property>
                 <property name="invisible_char">&#x25CF;</property>
               </object>
               <packing>
                 <child>
                   <object class="GtkCellRendererText" id="cellrenderertext38"/>
                   <attributes>
-                    <attribute name="text">2</attribute>
+                    <attribute name="text">1</attribute>
                   </attributes>
                 </child>
               </object>
             </child>
             <child>
               <object class="GtkLabel" id="label91">
-                <property name="label" translatable="yes">lbl_id_personale</property>
+                <property name="label" translatable="yes">lbl_id_persone</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
       </object>
     </child>
   </object>
+  <object class="GtkWindow" id="w_persone">
+    <property name="title" translatable="yes">Persone - Gestione organigramma</property>
+    <child>
+      <object class="GtkVBox" id="vbx_persone">
+        <property name="visible">True</property>
+        <property name="border_width">5</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">5</property>
+        <child>
+          <object class="GtkLabel" id="label139">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">&lt;b&gt;Persone&lt;/b&gt;</property>
+            <property name="use_markup">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow32">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hscrollbar_policy">automatic</property>
+            <property name="vscrollbar_policy">automatic</property>
+            <property name="shadow_type">etched-in</property>
+            <child>
+              <object class="GtkTreeView" id="treeview18">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="model">lstore_persone</property>
+                <property name="headers_clickable">False</property>
+                <property name="search_column">0</property>
+                <child>
+                  <object class="GtkTreeViewColumn" id="treeviewcolumn28">
+                    <property name="title">Cognome/Nome</property>
+                    <child>
+                      <object class="GtkCellRendererText" id="cellrenderertext39"/>
+                      <attributes>
+                        <attribute name="text">1</attribute>
+                      </attributes>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHButtonBox" id="hbuttonbox25">
+            <property name="visible">True</property>
+            <property name="spacing">5</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button102">
+                <property name="label">gtk-new</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button103">
+                <property name="label">gtk-edit</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button104">
+                <property name="label">gtk-delete</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button107">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button108">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">4</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
index 78d8f005c218a713547b1d44db0b3add702d7034..78a25207c98791fc724e45ca074911a7e22c857d 100644 (file)
@@ -17,6 +17,12 @@ organigramma_SOURCES = \
                 nodi.h \
                 nodo.c \
                 nodo.h \
+                persona.c \
+                persona.h \
+                persone.c \
+                persone.h \
+                personaufficio.c \
+                personaufficio.h \
                 struttura.c \
                 struttura.h \
                 strutturaindirizzo.c \
index dad4e99a309aad9dc48e48f2735a287f997eb0e6..31e396a7fe254ec7aa8f8dea504eb43694fbf548 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "commons.h"
 #include "nodi.h"
+#include "persone.h"
 #include "strutture.h"
 #include "tipinodo.h"
 #include "tipirecapito.h"
@@ -95,6 +96,19 @@ on_mnu_view_uffici_activate (GtkMenuItem *menuitem,
        main_set_vbx_body_child (vbx);
 }
 
+G_MODULE_EXPORT void
+on_mnu_view_persone_activate (GtkMenuItem *menuitem,
+                            gpointer user_data)
+{
+       GtkWidget *vbx;
+
+       Persone *m = persone_new (commons, FALSE);
+
+       vbx = persone_get_widget (m);
+
+       main_set_vbx_body_child (vbx);
+}
+
 G_MODULE_EXPORT void
 on_mnu_tabelle_tipi_nodo_activate (GtkMenuItem *menuitem,
                             gpointer user_data)
diff --git a/src/persona.c b/src/persona.c
new file mode 100644 (file)
index 0000000..499f611
--- /dev/null
@@ -0,0 +1,553 @@
+/* 
+ * Copyright (C) 2010 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
+ *
+ */
+
+#include <libgtkform/form.h>
+
+#include "persona.h"
+#include "personaufficio.h"
+
+static void persona_class_init (PersonaClass *klass);
+static void persona_init (Persona *persona);
+
+static void persona_carica (Persona *persona);
+static void persona_salva (Persona *persona);
+
+static void persona_carica_uffici (Persona *persona);
+
+static void persona_ufficio_modifica (Persona *persona);
+
+static gboolean persona_conferma_chiusura (Persona *persona);
+
+static void persona_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void persona_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+static void persona_on_ufficio_aggiornato (gpointer instance, gpointer user_data);
+
+static gboolean persona_on_w_persona_delete_event (GtkWidget *widget,
+                               GdkEvent *event,
+                               gpointer user_data);
+
+static void persona_on_btn_ufficio_nuovo_clicked (GtkButton *button,
+                                    gpointer user_data);
+static void persona_on_btn_ufficio_modifica_clicked (GtkButton *button,
+                                    gpointer user_data);
+static void persona_on_btn_ufficio_elimina_clicked (GtkButton *button,
+                                    gpointer user_data);
+static void persona_on_trv_uffici_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,
+                                  gpointer user_data);
+
+#define PERSONA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_PERSONA, PersonaPrivate))
+
+enum
+{
+       LBL_ID,
+       LSTORE_UFFICI
+};
+
+enum
+{
+       UFFICI_COL_ID,
+       UFFICI_COL_UFFICIO
+};
+
+typedef struct _PersonaPrivate PersonaPrivate;
+struct _PersonaPrivate
+       {
+               Commons *commons;
+
+               GtkForm *form;
+
+               GtkWidget *w;
+
+               GObject **objects;
+
+               GtkTreeSelection *sel_uffici;
+
+               gint id;
+       };
+
+G_DEFINE_TYPE (Persona, persona, G_TYPE_OBJECT)
+
+static void
+persona_class_init (PersonaClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (PersonaPrivate));
+
+       object_class->set_property = persona_set_property;
+       object_class->get_property = persona_get_property;
+
+       /**
+        * Persona::aggiornato:
+        * @persona:
+        *
+        */
+       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_init (Persona *persona)
+{
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+}
+
+/**
+ * persona_new:
+ * @commons:
+ * @id:
+ *
+ * Returns: the newly created #Persona object.
+ */
+Persona
+*persona_new (Commons *commons, gint id)
+{
+       GError *error;
+
+       Persona *a = PERSONA (g_object_new (persona_get_type (), NULL));
+
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (a);
+
+       priv->commons = commons;
+
+       error = NULL;
+       gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
+                                          g_strsplit (g_strconcat (
+                                          "lstore_titoli"
+                                          "|lstore_persona_uffici"
+                                          "|w_persona", NULL), "|", -1),
+                                          &error);
+       if (error != NULL)
+               {
+                       g_warning ("Errore: %s.", error->message);
+                       return NULL;
+               }
+
+       priv->form = gtk_form_new ();
+       g_object_set (G_OBJECT (priv->form), "gdaex", priv->commons->gdaex, NULL);
+       gtk_form_load_from_file (priv->form, g_build_filename (priv->commons->formdir, "persona.form", NULL), priv->commons->gtkbuilder);
+
+       priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_persona"));
+
+       priv->objects = gtk_form_get_objects_by_name (priv->form,
+                                                     "label67",
+                                                     "lstore_persona_uffici",
+                                                     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")));
+
+       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button62")),
+                         "clicked", G_CALLBACK (persona_on_btn_ufficio_nuovo_clicked), (gpointer *)a);
+       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button63")),
+                         "clicked", G_CALLBACK (persona_on_btn_ufficio_modifica_clicked), (gpointer *)a);
+       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button64")),
+                         "clicked", G_CALLBACK (persona_on_btn_ufficio_elimina_clicked), (gpointer *)a);
+       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 (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"),
+                         "clicked", G_CALLBACK (persona_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));
+                       persona_carica (a);
+               }
+
+       return a;
+}
+
+/**
+ * persona_get_widget:
+ * @persona:
+ *
+ */
+GtkWidget
+*persona_get_widget (Persona *persona)
+{
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+       return priv->w;
+}
+
+/* PRIVATE */
+static void
+persona_carica (Persona *persona)
+{
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+       if (gtk_form_fill_from_table (priv->form))
+               {
+                       persona_carica_uffici (persona);
+               }
+}
+
+static void
+persona_salva (Persona *persona)
+{
+       GError *error = NULL;
+       gchar *sql;
+       GtkWidget *dialog;
+
+       GDate *da;
+       GDate *a;
+
+       PersonaClass *klass = PERSONA_GET_CLASS (persona);
+
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+       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 (persona, 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
+persona_carica_uffici (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_UFFICI]));
+
+       sql = g_strdup_printf ("SELECT pu.id, u.nome"
+                              " FROM persona_uffici AS pu INNER JOIN uffici AS u ON"
+                              " pu.id_uffici = u.id"
+                              " WHERE pu.id_persone = %d"
+                              " AND pu.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_UFFICI]), &iter);
+                                       gtk_list_store_set (GTK_LIST_STORE (priv->objects[LSTORE_UFFICI]), &iter,
+                                                           UFFICI_COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"),
+                                                           UFFICI_COL_UFFICIO, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"),
+                                                           -1);
+                               }
+
+                       g_object_unref (dm);
+               }
+       g_free (sql);
+}
+
+static void
+persona_ufficio_modifica (Persona *persona)
+{
+       GtkTreeIter iter;
+       GtkWidget *dialog;
+
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+       if (gtk_tree_selection_get_selected (priv->sel_uffici, NULL, &iter))
+               {
+                       guint id;
+                       GtkWidget *w;
+
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->objects[LSTORE_UFFICI]), &iter,
+                                           UFFICI_COL_ID, &id,
+                                           -1);
+
+                       PersonaUfficio *a = persona_ufficio_new (priv->commons, id, 0);
+
+                       g_signal_connect (G_OBJECT (a), "aggiornato",
+                                         G_CALLBACK (persona_on_ufficio_aggiornato), (gpointer)persona);
+
+                       w = persona_ufficio_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 ufficio");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+}
+
+static void
+persona_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       Persona *persona = PERSONA (object);
+
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+persona_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       Persona *persona = PERSONA (object);
+
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static gboolean
+persona_conferma_chiusura (Persona *persona)
+{
+       GtkWidget *dialog;
+
+       gboolean ret;
+
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+       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 void
+persona_on_ufficio_aggiornato (gpointer instance, gpointer user_data)
+{
+       Persona *persona = (Persona *)user_data;
+       PersonaClass *klass = PERSONA_GET_CLASS (persona);
+
+       persona_carica_uffici (persona);
+}
+
+static gboolean
+persona_on_w_persona_delete_event (GtkWidget *widget,
+                               GdkEvent *event,
+                               gpointer user_data)
+{
+       return !persona_conferma_chiusura ((Persona *)user_data);
+}
+
+static void
+persona_on_btn_ufficio_nuovo_clicked (GtkButton *button,
+                                    gpointer user_data)
+{
+       GtkWidget *w;
+
+       Persona *persona = (Persona *)user_data;
+
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+       PersonaUfficio *a = persona_ufficio_new (priv->commons, 0, priv->id);
+
+       g_signal_connect (G_OBJECT (a), "aggiornato",
+                         G_CALLBACK (persona_on_ufficio_aggiornato), (gpointer)persona);
+
+       w = persona_ufficio_get_widget (a);
+       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w));
+       gtk_widget_show (w);
+}
+
+static void
+persona_on_btn_ufficio_modifica_clicked (GtkButton *button,
+                                    gpointer user_data)
+{
+       persona_ufficio_modifica ((Persona *)user_data);
+}
+
+static void
+persona_on_btn_ufficio_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_uffici, 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'ufficio 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_UFFICI]), &iter,
+                                                           UFFICI_COL_ID, &id,
+                                                           -1);
+
+                                       gdaex_execute (priv->commons->gdaex,
+                                                      g_strdup_printf ("UPDATE persona_uffici"
+                                                                       " SET status = 'E'"
+                                                                       " WHERE id = %d",
+                                                                       id));
+
+                                       persona_carica_uffici (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 ufficio");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+}
+
+static void
+persona_on_trv_uffici_row_activated (GtkTreeView *tree_view,
+                                     GtkTreePath *tree_path,
+                                     GtkTreeViewColumn *column,
+                                     gpointer user_data)
+{
+       persona_ufficio_modifica ((Persona *)user_data);
+}
+
+static void
+persona_on_btn_annulla_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       Persona *persona = (Persona *)user_data;
+
+       PersonaPrivate *priv = PERSONA_GET_PRIVATE (persona);
+
+       if (persona_conferma_chiusura (persona)) gtk_widget_destroy (priv->w);
+}
+
+static void
+persona_on_btn_salva_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       persona_salva ((Persona *)user_data);
+}
diff --git a/src/persona.h b/src/persona.h
new file mode 100644 (file)
index 0000000..2ec0461
--- /dev/null
@@ -0,0 +1,66 @@
+/* 
+ * Copyright (C) 2010 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 __PERSONA_H__
+#define __PERSONA_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+#include <libgdaex.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_PERSONA                 (persona_get_type ())
+#define PERSONA(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PERSONA, Persona))
+#define PERSONA_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PERSONA, PersonaClass))
+#define IS_PERSONA(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PERSONA))
+#define IS_PERSONA_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PERSONA))
+#define PERSONA_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PERSONA, PersonaClass))
+
+
+typedef struct _Persona Persona;
+typedef struct _PersonaClass PersonaClass;
+
+struct _Persona
+       {
+               GObject parent;
+       };
+
+struct _PersonaClass
+       {
+               GObjectClass parent_class;
+
+               guint aggiornato_signal_id;
+       };
+
+GType persona_get_type (void) G_GNUC_CONST;
+
+Persona *persona_new (Commons *commons, gint id);
+
+GtkWidget *persona_get_widget (Persona *persona);
+
+
+G_END_DECLS
+
+#endif /* __PERSONA_H__ */
diff --git a/src/personaufficio.c b/src/personaufficio.c
new file mode 100644 (file)
index 0000000..74d1a07
--- /dev/null
@@ -0,0 +1,383 @@
+/* 
+ * 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 "personaufficio.h"
+#include "uffici.h"
+
+static void persona_ufficio_class_init (PersonaUfficioClass *klass);
+static void persona_ufficio_init (PersonaUfficio *persona_ufficio);
+
+static void persona_ufficio_carica (PersonaUfficio *persona_ufficio);
+static void persona_ufficio_salva (PersonaUfficio *persona_ufficio);
+
+static void persona_ufficio_carica_ufficio (PersonaUfficio *indirizzo);
+
+static gboolean persona_ufficio_conferma_chiusura (PersonaUfficio *persona_ufficio);
+
+static void persona_ufficio_on_ufficio_selezionato (gpointer instance,
+                                          guint id, gpointer user_data);
+
+static void persona_ufficio_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void persona_ufficio_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+static gboolean persona_ufficio_on_w_persona_ufficio_delete_event (GtkWidget *widget,
+                               GdkEvent *event,
+                               gpointer user_data);
+
+static void persona_ufficio_on_btn_ricerca_via_clicked (GtkButton *button,
+                                    gpointer user_data);
+static void persona_ufficio_on_btn_annulla_clicked (GtkButton *button,
+                                    gpointer user_data);
+static void persona_ufficio_on_btn_salva_clicked (GtkButton *button,
+                                  gpointer user_data);
+
+
+#define PERSONA_UFFICIO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_PERSONA_UFFICIO, PersonaUfficioPrivate))
+
+enum
+{
+       LBL_ID,
+       LBL_ID_PERSONE
+};
+
+typedef struct _PersonaUfficioPrivate PersonaUfficioPrivate;
+struct _PersonaUfficioPrivate
+       {
+               Commons *commons;
+
+               GtkForm *form;
+
+               GtkWidget *w;
+
+               GObject **objects;
+
+               guint id;
+       };
+
+G_DEFINE_TYPE (PersonaUfficio, persona_ufficio, G_TYPE_OBJECT)
+
+static void
+persona_ufficio_class_init (PersonaUfficioClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (PersonaUfficioPrivate));
+
+       object_class->set_property = persona_ufficio_set_property;
+       object_class->get_property = persona_ufficio_get_property;
+
+       /**
+        * PersonaUfficio::aggiornato:
+        * @persona_ufficio:
+        *
+        */
+       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_ufficio_init (PersonaUfficio *persona_ufficio)
+{
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (persona_ufficio);
+}
+
+/**
+ * persona_ufficio_new:
+ * @commons:
+ * @id:
+ * @id_persone:
+ *
+ * Returns: the newly created #PersonaUfficio object.
+ */
+PersonaUfficio
+*persona_ufficio_new (Commons *commons, guint id, guint id_persone)
+{
+       GError *error;
+
+       PersonaUfficio *a = PERSONA_UFFICIO (g_object_new (persona_ufficio_get_type (), NULL));
+
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (a);
+
+       priv->commons = commons;
+
+       error = NULL;
+
+       gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
+                                          g_strsplit ("w_persona_ufficio", "|", -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_ufficio.form", NULL), priv->commons->gtkbuilder);
+
+       priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_persona_ufficio"));
+
+       priv->objects = gtk_form_get_objects_by_name (priv->form,
+                                                     "label90",
+                                                     "label91",
+                                                     NULL);
+
+       g_signal_connect (priv->w,
+                         "delete-event", G_CALLBACK (persona_ufficio_on_w_persona_ufficio_delete_event), (gpointer *)a);
+
+       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button82")),
+                         "clicked", G_CALLBACK (persona_ufficio_on_btn_ricerca_via_clicked), (gpointer *)a);
+
+       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button83")),
+                         "clicked", G_CALLBACK (persona_ufficio_on_btn_annulla_clicked), (gpointer *)a);
+       g_signal_connect (G_OBJECT (gtk_builder_get_object (priv->commons->gtkbuilder, "button84")),
+                         "clicked", G_CALLBACK (persona_ufficio_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_ufficio_carica (a);
+               }
+
+       return a;
+}
+
+/**
+ * persona_ufficio_get_widget:
+ * @persona_ufficio:
+ *
+ */
+GtkWidget
+*persona_ufficio_get_widget (PersonaUfficio *persona_ufficio)
+{
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (persona_ufficio);
+
+       return priv->w;
+}
+
+/* PRIVATE */
+static void
+persona_ufficio_carica (PersonaUfficio *persona_ufficio)
+{
+       gchar *sql;
+       GdaDataModel *dm;
+
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (persona_ufficio);
+
+       if (gtk_form_fill_from_table (priv->form))
+               {
+               }
+}
+
+static void
+persona_ufficio_salva (PersonaUfficio *persona_ufficio)
+{
+       gchar *sql;
+       GtkWidget *dialog;
+
+       PersonaUfficioClass *klass = PERSONA_UFFICIO_GET_CLASS (persona_ufficio);
+
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (persona_ufficio);
+
+       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_ufficio, 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_ufficio_on_ufficio_selezionato (gpointer instance, guint id, gpointer user_data)
+{
+       PersonaUfficio *ia = (PersonaUfficio *)user_data;
+
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (ia);
+
+       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "label89"), g_strdup_printf ("%d", id));
+}
+
+static void
+persona_ufficio_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       PersonaUfficio *persona_ufficio = PERSONA_UFFICIO (object);
+
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (persona_ufficio);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+persona_ufficio_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       PersonaUfficio *persona_ufficio = PERSONA_UFFICIO (object);
+
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (persona_ufficio);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static gboolean
+persona_ufficio_conferma_chiusura (PersonaUfficio *persona_ufficio)
+{
+       GtkWidget *dialog;
+
+       gboolean ret;
+
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (persona_ufficio);
+
+       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_ufficio_on_w_persona_ufficio_delete_event (GtkWidget *widget,
+                               GdkEvent *event,
+                               gpointer user_data)
+{
+       return !persona_ufficio_conferma_chiusura ((PersonaUfficio *)user_data);
+}
+
+static void
+persona_ufficio_on_btn_ricerca_via_clicked (GtkButton *button,
+                                    gpointer user_data)
+{
+       GtkWidget *w;
+
+       PersonaUfficio *ia = (PersonaUfficio *)user_data;
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (ia);
+
+       Uffici *v = uffici_new (priv->commons, TRUE);
+
+       g_signal_connect (G_OBJECT (v), "selezionato",
+                         G_CALLBACK (persona_ufficio_on_ufficio_selezionato), (gpointer)ia);
+
+       w = uffici_get_widget (v);
+       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w));
+       gtk_widget_show (w);
+}
+
+static void
+persona_ufficio_on_btn_annulla_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       PersonaUfficio *persona_ufficio = (PersonaUfficio *)user_data;
+
+       PersonaUfficioPrivate *priv = PERSONA_UFFICIO_GET_PRIVATE (persona_ufficio);
+
+       if (persona_ufficio_conferma_chiusura (persona_ufficio)) gtk_widget_destroy (priv->w);
+}
+
+static void
+persona_ufficio_on_btn_salva_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       persona_ufficio_salva ((PersonaUfficio *)user_data);
+}
diff --git a/src/personaufficio.h b/src/personaufficio.h
new file mode 100644 (file)
index 0000000..437c626
--- /dev/null
@@ -0,0 +1,65 @@
+/* 
+ * 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 __PERSONA_UFFICIO_H__
+#define __PERSONA_UFFICIO_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_PERSONA_UFFICIO                 (persona_ufficio_get_type ())
+#define PERSONA_UFFICIO(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PERSONA_UFFICIO, PersonaUfficio))
+#define PERSONA_UFFICIO_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PERSONA_UFFICIO, PersonaUfficioClass))
+#define IS_PERSONA_UFFICIO(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PERSONA_UFFICIO))
+#define IS_PERSONA_UFFICIO_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PERSONA_UFFICIO))
+#define PERSONA_UFFICIO_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PERSONA_UFFICIO, PersonaUfficioClass))
+
+
+typedef struct _PersonaUfficio PersonaUfficio;
+typedef struct _PersonaUfficioClass PersonaUfficioClass;
+
+struct _PersonaUfficio
+       {
+               GObject parent;
+       };
+
+struct _PersonaUfficioClass
+       {
+               GObjectClass parent_class;
+
+               guint aggiornato_signal_id;
+       };
+
+GType persona_ufficio_get_type (void) G_GNUC_CONST;
+
+PersonaUfficio *persona_ufficio_new (Commons *commons, guint id, guint id_persone);
+
+GtkWidget *persona_ufficio_get_widget (PersonaUfficio *persona_ufficio);
+
+
+G_END_DECLS
+
+#endif /* __PERSONA_UFFICIO_H__ */
diff --git a/src/persone.c b/src/persone.c
new file mode 100644 (file)
index 0000000..36f4d61
--- /dev/null
@@ -0,0 +1,445 @@
+/* 
+ * Copyright (C) 2010 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
+ *
+ */
+
+#include "persone.h"
+#include "persona.h"
+
+static void persone_class_init (PersoneClass *klass);
+static void persone_init (Persone *persone);
+
+static void persone_carica (Persone *persone);
+static void persone_modifica (Persone *persone);
+
+static void persone_selezionato (Persone *persone);
+static void persone_on_persona_aggiornato (gpointer instance, gpointer user_data);
+
+static void persone_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void persone_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+static void persone_on_btn_nuovo_clicked (GtkButton *button,
+                      gpointer user_data);
+static void persone_on_btn_modifica_clicked (GtkButton *button,
+                      gpointer user_data);
+static void persone_on_btn_elimina_clicked (GtkButton *button,
+                        gpointer user_data);
+static void persone_on_trv_persone_row_activated (GtkTreeView *tree_view,
+                                             GtkTreePath *tree_path,
+                                             GtkTreeViewColumn *column,
+                                             gpointer user_data);
+
+static void persone_on_btn_annulla_clicked (GtkButton *button,
+                                    gpointer user_data);
+static void persone_on_btn_seleziona_clicked (GtkButton *button,
+                                  gpointer user_data);
+
+#define PERSONE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_PERSONE, PersonePrivate))
+
+enum
+{
+       COL_ID,
+       COL_NOME
+};
+
+typedef struct _PersonePrivate PersonePrivate;
+struct _PersonePrivate
+       {
+               Commons *commons;
+
+               GtkWidget *widget;
+               GtkTreeSelection *selection;
+               GtkListStore *lstore_persone;
+
+               gboolean selezione;
+               GtkWindow *wtransient;
+       };
+
+G_DEFINE_TYPE (Persone, persone, G_TYPE_OBJECT)
+
+static void
+persone_class_init (PersoneClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (PersonePrivate));
+
+       object_class->set_property = persone_set_property;
+       object_class->get_property = persone_get_property;
+
+       /**
+        * Persone::selezionato:
+        * @persone:
+        *
+        */
+       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
+persone_init (Persone *persone)
+{
+       PersonePrivate *priv = PERSONE_GET_PRIVATE (persone);
+}
+
+/**
+ * persone_new:
+ * @commons:
+ * @selezione:
+ *
+ * Returns: the newly created #Persone object.
+ */
+Persone
+*persone_new (Commons *commons, gboolean selezione)
+{
+       GError *error;
+
+       Persone *a = PERSONE (g_object_new (persone_get_type (), NULL));
+
+       PersonePrivate *priv = PERSONE_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_persone|",
+                                          (selezione ? "w_persone" : "vbx_persone"),
+                                          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_persone" : "vbx_persone")));
+       priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview18")));
+       priv->lstore_persone = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_persone"));
+
+       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, "button102"),
+                         "clicked", G_CALLBACK (persone_on_btn_nuovo_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button103"),
+                         "clicked", G_CALLBACK (persone_on_btn_modifica_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button104"),
+                         "clicked", G_CALLBACK (persone_on_btn_elimina_clicked), (gpointer)a);
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview18"),
+                         "row-activated", G_CALLBACK (persone_on_trv_persone_row_activated), (gpointer)a);
+
+       if (priv->selezione)
+               {
+                       gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "label139")));
+                       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button107"),
+                                         "clicked", G_CALLBACK (persone_on_btn_annulla_clicked), (gpointer)a);
+                       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button108"),
+                                         "clicked", G_CALLBACK (persone_on_btn_seleziona_clicked), (gpointer)a);
+               }
+       else
+               {
+                       gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button107")));
+                       gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button108")));
+               }
+
+       persone_carica (a);
+
+       return a;
+}
+
+/**
+ * persone_get_widget:
+ * @persone:
+ *
+ */
+GtkWidget
+*persone_get_widget (Persone *persone)
+{
+       PersonePrivate *priv = PERSONE_GET_PRIVATE (persone);
+
+       return priv->widget;
+}
+
+/* PRIVATE */
+static void
+persone_carica (Persone *persone)
+{
+       GtkTreeIter iter;
+       GdaDataModel *dm;
+
+       gint rows;
+       gint row;
+
+       PersonePrivate *priv = PERSONE_GET_PRIVATE (persone);
+
+       gtk_list_store_clear (priv->lstore_persone);
+
+       dm = gdaex_query (priv->commons->gdaex,
+                         "SELECT c.id, c.cognome || ' ' || c.nome AS cognome_nome"
+                         " FROM persone AS c"
+                         " WHERE c.status <> 'E'"
+                         " ORDER BY c.cognome, 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_persone, &iter);
+
+                                       gtk_list_store_set (priv->lstore_persone, &iter,
+                                                           COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"),
+                                                           COL_NOME, gdaex_data_model_get_field_value_stringify_at (dm, row, "cognome_nome"),
+                                                           -1);
+                               }
+
+                       g_object_unref (dm);
+               }
+}
+
+static void
+persone_modifica (Persone *persone)
+{
+       GtkTreeIter iter;
+       guint id;
+
+       PersonePrivate *priv = PERSONE_GET_PRIVATE (persone);
+
+       if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
+               {
+                       GtkWidget *w;
+
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_persone), &iter,
+                                           COL_ID, &id,
+                                           -1);
+
+                       Persona *c = persona_new (priv->commons, id);
+
+                       g_signal_connect (G_OBJECT (c), "aggiornato",
+                                         G_CALLBACK (persone_on_persona_aggiornato), (gpointer)persone);
+
+                       w = persona_get_widget (c);
+                       gtk_window_set_transient_for (GTK_WINDOW (w), priv->wtransient);
+                       gtk_widget_show (w);
+               }
+       else
+               {
+                       GtkWidget *dialog = gtk_message_dialog_new (priv->wtransient,
+                                                                   GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                   GTK_MESSAGE_WARNING,
+                                                                   GTK_BUTTONS_OK,
+                                                                   "Occorre prima selezionare una persona");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+}
+
+static void
+persone_selezionato (Persone *persone)
+{
+       GtkTreeIter iter;
+       guint *id;
+
+       PersoneClass *klass = PERSONE_GET_CLASS (persone);
+       PersonePrivate *priv = PERSONE_GET_PRIVATE (persone);
+
+       if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
+               {
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_persone), &iter,
+                                           COL_ID, &id,
+                                           -1);
+
+                       g_signal_emit (G_OBJECT (persone), klass->selezionato_signal_id, 0, id);
+
+                       gtk_widget_destroy (priv->widget);
+                       g_object_unref (G_OBJECT (persone));
+               }
+       else
+               {
+                       GtkWidget *dialog = gtk_message_dialog_new (priv->wtransient,
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "Occorre prima selezionare una persona");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+}
+
+static void
+persone_on_persona_aggiornato (gpointer instance, gpointer user_data)
+{
+       persone_carica ((Persone *)user_data);
+}
+
+static void
+persone_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       Persone *persone = PERSONE (object);
+
+       PersonePrivate *priv = PERSONE_GET_PRIVATE (persone);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+persone_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       Persone *persone = PERSONE (object);
+
+       PersonePrivate *priv = PERSONE_GET_PRIVATE (persone);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+/* CALLBACK */
+static void
+persone_on_btn_nuovo_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       GtkWidget *w;
+
+       Persone *persone = (Persone *)user_data;
+       PersonePrivate *priv = PERSONE_GET_PRIVATE (persone);
+
+       Persona *c = persona_new (priv->commons, 0);
+
+       g_signal_connect (G_OBJECT (c), "aggiornato",
+                         G_CALLBACK (persone_on_persona_aggiornato), (gpointer)persone);
+
+       w = persona_get_widget (c);
+       gtk_window_set_transient_for (GTK_WINDOW (w), priv->wtransient);
+       gtk_widget_show (w);
+}
+
+static void
+persone_on_btn_modifica_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       persone_modifica ((Persone *)user_data);
+}
+
+static void
+persone_on_btn_elimina_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       GtkWidget *dialog;
+       gboolean risp;
+
+       GtkTreeIter iter;
+       guint id;
+
+       Persone *persone = (Persone *)user_data;
+       PersonePrivate *priv = PERSONE_GET_PRIVATE (persone);
+
+       if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
+               {
+                       dialog = gtk_message_dialog_new (priv->wtransient,
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_QUESTION,
+                                                        GTK_BUTTONS_YES_NO,
+                                                        "Sicuro di voler eliminare la persona selezionata?");
+                       risp = gtk_dialog_run (GTK_DIALOG (dialog));
+                       if (risp == GTK_RESPONSE_YES)
+                               {
+                                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_persone), &iter,
+                                                           COL_ID, &id,
+                                                           -1);
+
+                                       gdaex_execute (priv->commons->gdaex,
+                                                      g_strdup_printf ("UPDATE persone SET status = 'E' WHERE id = %d", id));
+
+                                       persone_carica (persone);
+                               }
+                       gtk_widget_destroy (dialog);
+               }
+       else
+               {
+                       dialog = gtk_message_dialog_new (priv->wtransient,
+                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_MESSAGE_WARNING,
+                                                        GTK_BUTTONS_OK,
+                                                        "Occorre prima selezionare una persona");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+}
+
+static void
+persone_on_trv_persone_row_activated (GtkTreeView *tree_view,
+                                             GtkTreePath *tree_path,
+                                             GtkTreeViewColumn *column,
+                                             gpointer user_data)
+{
+       PersonePrivate *priv = PERSONE_GET_PRIVATE ((Persone *)user_data);
+
+       if (priv->selezione)
+               {
+                       persone_selezionato ((Persone *)user_data);
+               }
+       else
+               {
+                       persone_modifica ((Persone *)user_data);
+               }
+}
+
+
+static void
+persone_on_btn_annulla_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       PersonePrivate *priv = PERSONE_GET_PRIVATE ((Persone *)user_data);
+
+       gtk_widget_destroy (priv->widget);
+       g_object_unref (G_OBJECT (user_data));
+}
+
+static void
+persone_on_btn_seleziona_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       persone_selezionato ((Persone *)user_data);
+}
diff --git a/src/persone.h b/src/persone.h
new file mode 100644 (file)
index 0000000..4188ee0
--- /dev/null
@@ -0,0 +1,66 @@
+/* 
+ * Copyright (C) 2010 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 __PERSONE_H__
+#define __PERSONE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+#include <libgdaex.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_PERSONE                 (persone_get_type ())
+#define PERSONE(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PERSONE, Persone))
+#define PERSONE_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PERSONE, PersoneClass))
+#define IS_PERSONE(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PERSONE))
+#define IS_PERSONE_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PERSONE))
+#define PERSONE_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PERSONE, PersoneClass))
+
+
+typedef struct _Persone Persone;
+typedef struct _PersoneClass PersoneClass;
+
+struct _Persone
+       {
+               GObject parent;
+       };
+
+struct _PersoneClass
+       {
+               GObjectClass parent_class;
+
+               guint selezionato_signal_id;
+       };
+
+GType persone_get_type (void) G_GNUC_CONST;
+
+Persone *persone_new (Commons *commons, gboolean selezione);
+
+GtkWidget *persone_get_widget (Persone *persone);
+
+
+G_END_DECLS
+
+#endif /* __PERSONE_H__ */