From: Andrea Zagli <a.zagli@comune.scandicci.fi.it> Date: Tue, 12 Oct 2010 15:46:11 +0000 (+0200) Subject: Gestione tabella titoli. X-Git-Tag: 0.0.3~49 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=031e717e496aa1c1001a6f256c71d6e8bf70a35c;p=solipa%2Forganigramma Gestione tabella titoli. --- diff --git a/.cproject b/.cproject index 002cbd0..87b0512 100644 --- a/.cproject +++ b/.cproject @@ -25,9 +25,11 @@ <tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.2083640945" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/> <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.630803900" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base"/> <tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.base.1795142806" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.base"> - <option id="gnu.c.compiler.option.include.paths.665935208" superClass="gnu.c.compiler.option.include.paths" valueType="includePath"> + <option id="gnu.c.compiler.option.include.paths.665935208" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath"> <listOptionValue builtIn="false" value=""C:\mingw\include\glib-2.0""/> <listOptionValue builtIn="false" value=""C:\mingw\include\gtk-2.0""/> + <listOptionValue builtIn="false" value=""C:\mingw\include\libgda-4.0""/> + <listOptionValue builtIn="false" value=""C:\mingw\include\libgtkform""/> </option> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.669767949" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> </tool> @@ -210,6 +212,7 @@ </profile> </scannerConfigBuildInfo> </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.language.mapping"/> </cconfiguration> </storageModule> <storageModule moduleId="cdtBuildSystem" version="4.0.0"> diff --git a/data/organigramma/form/Makefile.am b/data/organigramma/form/Makefile.am index a97d614..de635a7 100644 --- a/data/organigramma/form/Makefile.am +++ b/data/organigramma/form/Makefile.am @@ -6,6 +6,7 @@ form_DATA = \ struttura_indirizzo.form \ tipo_nodo.form \ tipo_recapito.form \ + titolo.form \ ufficio.form \ ufficio_nodo.form \ ufficio_orario.form \ diff --git a/data/organigramma/form/titolo.form b/data/organigramma/form/titolo.form new file mode 100644 index 0000000..186747e --- /dev/null +++ b/data/organigramma/form/titolo.form @@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<gtkform> + + <table>titoli</table> + + <widget type="label" name="label140" label="label141"> + <field type="integer" name="id"> + <is-key>t</is-key> + <auto-increment>t</auto-increment> + </field> + </widget> + + <widget type="entry" name="entry37" label="label138"> + <field type="text" name="sigla" /> + </widget> + + <widget type="entry" name="entry38" label="label142"> + <field type="text" name="descrizione" /> + </widget> + +</gtkform> diff --git a/data/organigramma/gui/organigramma.gui b/data/organigramma/gui/organigramma.gui index 140e931..5e42748 100644 --- a/data/organigramma/gui/organigramma.gui +++ b/data/organigramma/gui/organigramma.gui @@ -96,6 +96,14 @@ <signal name="activate" handler="on_mnu_tabelle_tipi_recapito_activate"/> </object> </child> + <child> + <object class="GtkMenuItem" id="menuitem10"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Titoli</property> + <property name="use_underline">True</property> + <signal name="activate" handler="on_mnu_tabelle_titoli_activate"/> + </object> + </child> </object> </child> </object> @@ -676,6 +684,16 @@ <column type="gchararray"/> </columns> </object> + <object class="GtkListStore" id="lstore_titoli"> + <columns> + <!-- column-name id --> + <column type="gchararray"/> + <!-- column-name sigla --> + <column type="gchararray"/> + <!-- column-name descrizione --> + <column type="gchararray"/> + </columns> + </object> <object class="GtkWindow" id="w_nodi"> <property name="modal">True</property> <property name="window_position">center-on-parent</property> @@ -3823,6 +3841,13 @@ <child> <object class="GtkComboBox" id="combobox4"> <property name="visible">True</property> + <property name="model">lstore_titoli</property> + <child> + <object class="GtkCellRendererText" id="cellrenderertext38"/> + <attributes> + <attribute name="text">2</attribute> + </attributes> + </child> </object> <packing> <property name="left_attach">1</property> @@ -6351,4 +6376,299 @@ </object> </child> </object> + <object class="GtkWindow" id="w_titoli"> + <property name="title" translatable="yes">Titoli - Gestione organigramma</property> + <property name="modal">True</property> + <property name="window_position">center-on-parent</property> + <property name="default_width">500</property> + <property name="default_height">400</property> + <property name="destroy_with_parent">True</property> + <child> + <object class="GtkVBox" id="vbx_titoli"> + <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="label137"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Titoli</b></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="scrolledwindow31"> + <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="treeview17"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="model">lstore_titoli</property> + <property name="headers_clickable">False</property> + <property name="search_column">0</property> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn26"> + <property name="title">Sigla</property> + <child> + <object class="GtkCellRendererText" id="cellrenderertext36"/> + <attributes> + <attribute name="text">1</attribute> + </attributes> + </child> + </object> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn27"> + <property name="title">Descrizione</property> + <child> + <object class="GtkCellRendererText" id="cellrenderertext37"/> + <attributes> + <attribute name="text">2</attribute> + </attributes> + </child> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkHButtonBox" id="hbuttonbox23"> + <property name="visible">True</property> + <property name="spacing">5</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="button95"> + <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="button96"> + <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="button97"> + <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="button100"> + <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="button101"> + <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> + <object class="GtkWindow" id="w_titolo"> + <property name="title" translatable="yes">Titolo - Gestione organigramma</property> + <property name="modal">True</property> + <property name="window_position">center-on-parent</property> + <property name="destroy_with_parent">True</property> + <child> + <object class="GtkVBox" id="vbox20"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="orientation">vertical</property> + <property name="spacing">5</property> + <child> + <object class="GtkTable" id="table18"> + <property name="visible">True</property> + <property name="n_rows">3</property> + <property name="n_columns">2</property> + <property name="column_spacing">5</property> + <property name="row_spacing">5</property> + <child> + <object class="GtkLabel" id="label138"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Sigla</property> + </object> + <packing> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="entry37"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="max_length">10</property> + <property name="invisible_char">●</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label140"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">lbl_id</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label141"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">ID</property> + </object> + <packing> + <property name="x_options">GTK_FILL</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label142"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Descrizione</property> + </object> + <packing> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="entry38"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="max_length">50</property> + <property name="invisible_char">●</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkHButtonBox" id="hbuttonbox24"> + <property name="visible">True</property> + <property name="spacing">5</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="button105"> + <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">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button106"> + <property name="label">gtk-save</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> + </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> </interface> diff --git a/src/Makefile.am b/src/Makefile.am index d3e6d91..78d8f00 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,10 @@ organigramma_SOURCES = \ tiponodo.h \ tiporecapito.c \ tiporecapito.h \ + titoli.c \ + titoli.h \ + titolo.c \ + titolo.h \ uffici.c \ uffici.h \ ufficio.c \ diff --git a/src/main.c b/src/main.c index 4e92bf8..dad4e99 100644 --- a/src/main.c +++ b/src/main.c @@ -32,6 +32,7 @@ #include "strutture.h" #include "tipinodo.h" #include "tipirecapito.h" +#include "titoli.h" #include "uffici.h" static Commons *commons; @@ -120,6 +121,19 @@ on_mnu_tabelle_tipi_recapito_activate (GtkMenuItem *menuitem, main_set_vbx_body_child (vbx); } +G_MODULE_EXPORT void +on_mnu_tabelle_titoli_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + GtkWidget *vbx; + + Titoli *m = titoli_new (commons, FALSE); + + vbx = titoli_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/titoli.c b/src/titoli.c new file mode 100644 index 0000000..8cfeef9 --- /dev/null +++ b/src/titoli.c @@ -0,0 +1,447 @@ +/* + * 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 "titoli.h" +#include "titolo.h" + +static void titoli_class_init (TitoliClass *klass); +static void titoli_init (Titoli *titoli); + +static void titoli_carica (Titoli *titoli); +static void titoli_modifica (Titoli *titoli); + +static void titoli_selezionato (Titoli *titoli); +static void titoli_on_titolo_aggiornato (gpointer instance, gpointer user_data); + +static void titoli_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void titoli_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void titoli_on_btn_nuovo_clicked (GtkButton *button, + gpointer user_data); +static void titoli_on_btn_modifica_clicked (GtkButton *button, + gpointer user_data); +static void titoli_on_btn_elimina_clicked (GtkButton *button, + gpointer user_data); +static void titoli_on_trv_titoli_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data); + +static void titoli_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data); +static void titoli_on_btn_seleziona_clicked (GtkButton *button, + gpointer user_data); + +#define TITOLI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TITOLI, TitoliPrivate)) + +enum +{ + COL_ID, + COL_SIGLA, + COL_DESCRIZIONE +}; + +typedef struct _TitoliPrivate TitoliPrivate; +struct _TitoliPrivate + { + Commons *commons; + + GtkWidget *widget; + GtkTreeSelection *selection; + GtkListStore *lstore_titoli; + + gboolean selezione; + GtkWindow *wtransient; + }; + +G_DEFINE_TYPE (Titoli, titoli, G_TYPE_OBJECT) + +static void +titoli_class_init (TitoliClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (TitoliPrivate)); + + object_class->set_property = titoli_set_property; + object_class->get_property = titoli_get_property; + + /** + * Titoli::selezionato: + * @titoli: + * + */ + 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 +titoli_init (Titoli *titoli) +{ + TitoliPrivate *priv = TITOLI_GET_PRIVATE (titoli); +} + +/** + * titoli_new: + * @commons: + * @selezione: + * + * Returns: the newly created #Titoli object. + */ +Titoli +*titoli_new (Commons *commons, gboolean selezione) +{ + GError *error; + + Titoli *a = TITOLI (g_object_new (titoli_get_type (), NULL)); + + TitoliPrivate *priv = TITOLI_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_titoli|", + (selezione ? "w_titoli" : "vbx_titoli"), + 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_titoli" : "vbx_titoli"))); + priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview17"))); + priv->lstore_titoli = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_titoli")); + + 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, "button95"), + "clicked", G_CALLBACK (titoli_on_btn_nuovo_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button96"), + "clicked", G_CALLBACK (titoli_on_btn_modifica_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button97"), + "clicked", G_CALLBACK (titoli_on_btn_elimina_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview17"), + "row-activated", G_CALLBACK (titoli_on_trv_titoli_row_activated), (gpointer)a); + + if (priv->selezione) + { + gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "label137"))); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button100"), + "clicked", G_CALLBACK (titoli_on_btn_annulla_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button101"), + "clicked", G_CALLBACK (titoli_on_btn_seleziona_clicked), (gpointer)a); + } + else + { + gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button100"))); + gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button101"))); + } + + titoli_carica (a); + + return a; +} + +/** + * titoli_get_widget: + * @titoli: + * + */ +GtkWidget +*titoli_get_widget (Titoli *titoli) +{ + TitoliPrivate *priv = TITOLI_GET_PRIVATE (titoli); + + return priv->widget; +} + +/* PRIVATE */ +static void +titoli_carica (Titoli *titoli) +{ + GtkTreeIter iter; + GdaDataModel *dm; + + gint rows; + gint row; + + TitoliPrivate *priv = TITOLI_GET_PRIVATE (titoli); + + gtk_list_store_clear (priv->lstore_titoli); + + dm = gdaex_query (priv->commons->gdaex, + "SELECT c.id, c.sigla, c.descrizione" + " FROM titoli AS c" + " WHERE c.status <> 'E'" + " ORDER BY c.sigla"); + if (dm != NULL) + { + rows = gda_data_model_get_n_rows (dm); + for (row = 0; row < rows; row++) + { + gtk_list_store_append (priv->lstore_titoli, &iter); + + gtk_list_store_set (priv->lstore_titoli, &iter, + COL_ID, gdaex_data_model_get_field_value_stringify_at (dm, row, "id"), + COL_SIGLA, gdaex_data_model_get_field_value_stringify_at (dm, row, "sigla"), + COL_DESCRIZIONE, gdaex_data_model_get_field_value_stringify_at (dm, row, "descrizione"), + -1); + } + + g_object_unref (dm); + } +} + +static void +titoli_modifica (Titoli *titoli) +{ + GtkTreeIter iter; + gchar *id; + + TitoliPrivate *priv = TITOLI_GET_PRIVATE (titoli); + + if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter)) + { + GtkWidget *w; + + gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_titoli), &iter, + COL_ID, &id, + -1); + + Titolo *c = titolo_new (priv->commons, strtol (id, NULL, 10)); + + g_signal_connect (G_OBJECT (c), "aggiornato", + G_CALLBACK (titoli_on_titolo_aggiornato), (gpointer)titoli); + + w = titolo_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 un titolo"); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +titoli_selezionato (Titoli *titoli) +{ + GtkTreeIter iter; + gchar *id; + + TitoliClass *klass = TITOLI_GET_CLASS (titoli); + TitoliPrivate *priv = TITOLI_GET_PRIVATE (titoli); + + if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter)) + { + gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_titoli), &iter, + COL_ID, &id, + -1); + + g_signal_emit (G_OBJECT (titoli), klass->selezionato_signal_id, 0, strtol (id, NULL, 10)); + + gtk_widget_destroy (priv->widget); + g_object_unref (G_OBJECT (titoli)); + } + else + { + GtkWidget *dialog = gtk_message_dialog_new (priv->wtransient, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + "Occorre prima selezionare un titolo"); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +titoli_on_titolo_aggiornato (gpointer instance, gpointer user_data) +{ + titoli_carica ((Titoli *)user_data); +} + +static void +titoli_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + Titoli *titoli = TITOLI (object); + + TitoliPrivate *priv = TITOLI_GET_PRIVATE (titoli); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +titoli_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + Titoli *titoli = TITOLI (object); + + TitoliPrivate *priv = TITOLI_GET_PRIVATE (titoli); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +/* CALLBACK */ +static void +titoli_on_btn_nuovo_clicked (GtkButton *button, + gpointer user_data) +{ + GtkWidget *w; + + Titoli *titoli = (Titoli *)user_data; + TitoliPrivate *priv = TITOLI_GET_PRIVATE (titoli); + + Titolo *c = titolo_new (priv->commons, 0); + + g_signal_connect (G_OBJECT (c), "aggiornato", + G_CALLBACK (titoli_on_titolo_aggiornato), (gpointer)titoli); + + w = titolo_get_widget (c); + gtk_window_set_transient_for (GTK_WINDOW (w), priv->wtransient); + gtk_widget_show (w); +} + +static void +titoli_on_btn_modifica_clicked (GtkButton *button, + gpointer user_data) +{ + titoli_modifica ((Titoli *)user_data); +} + +static void +titoli_on_btn_elimina_clicked (GtkButton *button, + gpointer user_data) +{ + GtkWidget *dialog; + gboolean risp; + + GtkTreeIter iter; + gchar *id; + + Titoli *titoli = (Titoli *)user_data; + TitoliPrivate *priv = TITOLI_GET_PRIVATE (titoli); + + 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 titolo selezionato?"); + risp = gtk_dialog_run (GTK_DIALOG (dialog)); + if (risp == GTK_RESPONSE_YES) + { + gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_titoli), &iter, + COL_ID, &id, + -1); + + gdaex_execute (priv->commons->gdaex, + g_strdup_printf ("UPDATE titoli SET status = 'E' WHERE id = %d", strtol (id, NULL, 10))); + + titoli_carica (titoli); + } + 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 titolo."); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +static void +titoli_on_trv_titoli_row_activated (GtkTreeView *tree_view, + GtkTreePath *tree_path, + GtkTreeViewColumn *column, + gpointer user_data) +{ + TitoliPrivate *priv = TITOLI_GET_PRIVATE ((Titoli *)user_data); + + if (priv->selezione) + { + titoli_selezionato ((Titoli *)user_data); + } + else + { + titoli_modifica ((Titoli *)user_data); + } +} + + +static void +titoli_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data) +{ + TitoliPrivate *priv = TITOLI_GET_PRIVATE ((Titoli *)user_data); + + gtk_widget_destroy (priv->widget); + g_object_unref (G_OBJECT (user_data)); +} + +static void +titoli_on_btn_seleziona_clicked (GtkButton *button, + gpointer user_data) +{ + titoli_selezionato ((Titoli *)user_data); +} diff --git a/src/titoli.h b/src/titoli.h new file mode 100644 index 0000000..3ca3cd5 --- /dev/null +++ b/src/titoli.h @@ -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 __TITOLI_H__ +#define __TITOLI_H__ + +#include <glib.h> +#include <glib-object.h> + +#include <gtk/gtk.h> +#include <libgdaex.h> + +#include "commons.h" + +G_BEGIN_DECLS + + +#define TYPE_TITOLI (titoli_get_type ()) +#define TITOLI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TITOLI, Titoli)) +#define TITOLI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TITOLI, TitoliClass)) +#define IS_TITOLI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TITOLI)) +#define IS_TITOLI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TITOLI)) +#define TITOLI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TITOLI, TitoliClass)) + + +typedef struct _Titoli Titoli; +typedef struct _TitoliClass TitoliClass; + +struct _Titoli + { + GObject parent; + }; + +struct _TitoliClass + { + GObjectClass parent_class; + + guint selezionato_signal_id; + }; + +GType titoli_get_type (void) G_GNUC_CONST; + +Titoli *titoli_new (Commons *commons, gboolean selezione); + +GtkWidget *titoli_get_widget (Titoli *titoli); + + +G_END_DECLS + +#endif /* __TITOLI_H__ */ diff --git a/src/titolo.c b/src/titolo.c new file mode 100644 index 0000000..e4b4fe7 --- /dev/null +++ b/src/titolo.c @@ -0,0 +1,338 @@ +/* + * 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 "titolo.h" + +static void titolo_class_init (TitoloClass *klass); +static void titolo_init (Titolo *titolo); + +static void titolo_carica (Titolo *titolo); +static void titolo_salva (Titolo *titolo); + +static gboolean titolo_conferma_chiusura (Titolo *titolo); + +static void titolo_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void titolo_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean titolo_on_w_titolo_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data); + +static void titolo_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data); +static void titolo_on_btn_salva_clicked (GtkButton *button, + gpointer user_data); + +#define TITOLO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TITOLO, TitoloPrivate)) + +enum +{ + LBL_ID +}; + +typedef struct _TitoloPrivate TitoloPrivate; +struct _TitoloPrivate + { + Commons *commons; + + GtkForm *form; + + GtkWidget *w; + + GObject **objects; + + gint id; + }; + +G_DEFINE_TYPE (Titolo, titolo, G_TYPE_OBJECT) + +static void +titolo_class_init (TitoloClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (TitoloPrivate)); + + object_class->set_property = titolo_set_property; + object_class->get_property = titolo_get_property; + + /** + * Titolo::aggiornato: + * @titolo: + * + */ + 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 +titolo_init (Titolo *titolo) +{ + TitoloPrivate *priv = TITOLO_GET_PRIVATE (titolo); +} + +/** + * titolo_new: + * @commons: + * @id: + * + * Returns: the newly created #Titolo object. + */ +Titolo +*titolo_new (Commons *commons, gint id) +{ + GError *error; + + Titolo *a = TITOLO (g_object_new (titolo_get_type (), NULL)); + + TitoloPrivate *priv = TITOLO_GET_PRIVATE (a); + + priv->commons = commons; + + error = NULL; + gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile, + g_strsplit ("w_titolo", "|", -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, "titolo.form", NULL), priv->commons->gtkbuilder); + + priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_titolo")); + + priv->objects = gtk_form_get_objects_by_name (priv->form, + "label140", + NULL); + + g_signal_connect (priv->w, + "delete-event", G_CALLBACK (titolo_on_w_titolo_delete_event), (gpointer *)a); + + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button105"), + "clicked", G_CALLBACK (titolo_on_btn_annulla_clicked), (gpointer *)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button106"), + "clicked", G_CALLBACK (titolo_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)); + titolo_carica (a); + } + + return a; +} + +/** + * titolo_get_widget: + * @titolo: + * + */ +GtkWidget +*titolo_get_widget (Titolo *titolo) +{ + TitoloPrivate *priv = TITOLO_GET_PRIVATE (titolo); + + return priv->w; +} + +/* PRIVATE */ +static void +titolo_carica (Titolo *titolo) +{ + TitoloPrivate *priv = TITOLO_GET_PRIVATE (titolo); + + if (gtk_form_fill_from_table (priv->form)) + { + } +} + +static void +titolo_salva (Titolo *titolo) +{ + GError *error = NULL; + gchar *sql; + GtkWidget *dialog; + + GDate *da; + GDate *a; + + TitoloClass *klass = TITOLO_GET_CLASS (titolo); + + TitoloPrivate *priv = TITOLO_GET_PRIVATE (titolo); + + 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 (titolo, 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 +titolo_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + Titolo *titolo = TITOLO (object); + + TitoloPrivate *priv = TITOLO_GET_PRIVATE (titolo); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +titolo_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + Titolo *titolo = TITOLO (object); + + TitoloPrivate *priv = TITOLO_GET_PRIVATE (titolo); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +titolo_conferma_chiusura (Titolo *titolo) +{ + GtkWidget *dialog; + + gboolean ret; + + TitoloPrivate *priv = TITOLO_GET_PRIVATE (titolo); + + 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 +titolo_on_w_titolo_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + return !titolo_conferma_chiusura ((Titolo *)user_data); +} + +static void +titolo_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data) +{ + Titolo *titolo = (Titolo *)user_data; + + TitoloPrivate *priv = TITOLO_GET_PRIVATE (titolo); + + if (titolo_conferma_chiusura (titolo)) gtk_widget_destroy (priv->w); +} + +static void +titolo_on_btn_salva_clicked (GtkButton *button, + gpointer user_data) +{ + titolo_salva ((Titolo *)user_data); +} diff --git a/src/titolo.h b/src/titolo.h new file mode 100644 index 0000000..ae76ed0 --- /dev/null +++ b/src/titolo.h @@ -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 __TITOLO_H__ +#define __TITOLO_H__ + +#include <glib.h> +#include <glib-object.h> + +#include <gtk/gtk.h> +#include <libgdaex.h> + +#include "commons.h" + +G_BEGIN_DECLS + + +#define TYPE_TITOLO (titolo_get_type ()) +#define TITOLO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TITOLO, Titolo)) +#define TITOLO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TITOLO, TitoloClass)) +#define IS_TITOLO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TITOLO)) +#define IS_TITOLO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TITOLO)) +#define TITOLO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TITOLO, TitoloClass)) + + +typedef struct _Titolo Titolo; +typedef struct _TitoloClass TitoloClass; + +struct _Titolo + { + GObject parent; + }; + +struct _TitoloClass + { + GObjectClass parent_class; + + guint aggiornato_signal_id; + }; + +GType titolo_get_type (void) G_GNUC_CONST; + +Titolo *titolo_new (Commons *commons, gint id); + +GtkWidget *titolo_get_widget (Titolo *titolo); + + +G_END_DECLS + +#endif /* __TITOLO_H__ */