]> saetta.ns0.it Git - solipa/territorio/commitdiff
Aggiunto l'import delel vie da Civilia (da finire).
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 8 Jun 2011 11:46:50 +0000 (13:46 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 8 Jun 2011 11:46:50 +0000 (13:46 +0200)
Correzioni ai form.

13 files changed:
configure.ac
data/territorio/form/aggregazione_territoriale.form
data/territorio/form/comune.form
data/territorio/form/provincia.form
data/territorio/form/regione.form
data/territorio/form/stato.form
data/territorio/form/tipo_aggregazione_territoriale.form
data/territorio/form/via.form
data/territorio/gui/territorio.gui
src/Makefile.am
src/importaviecivilia.c [new file with mode: 0644]
src/importaviecivilia.h [new file with mode: 0644]
src/main.c

index 73bf3311010bfce4ba117fce2bba5d0cca0659ba..19b7670270ea3fd7323bb2f992a8822dc953179f 100644 (file)
@@ -26,6 +26,7 @@ AC_PROG_RANLIB
 # Checks for libraries.
 PKG_CHECK_MODULES(TERRITORIO, [gio-2.0 >= 2.20
                           gtk+-2.0 >= 2.16
+                          libgda-ui-4.0 >= 4.2.0
                           libgdaex >= 0.3.0
                           libgtkform >= 0.1.3
                           libaute >= 0.0.2
index 95252857972faad3dc364760926c75c3d606907c..823d6a13100381ebbc6c713f2fbd662e2c5705d3 100644 (file)
@@ -21,7 +21,9 @@
        </widget>
 
        <widget type="entry" name="entry14" label="label33">
-               <field type="text" name="nome" />
+               <field type="text" name="nome">
+                       <obligatory>t</obligatory>
+               </field>
        </widget>
 
 </gtkform>
index 58012ce1c3b8e69d44395487369195b90c806574..ac6e0922184c16fc665b510910d2bccbc6dd4ef9 100644 (file)
        </widget>
 
        <widget type="entry" name="entry10" label="label23">
-               <field type="text" name="nome" />
+               <field type="text" name="nome">
+                       <obligatory>t</obligatory>
+               </field>
        </widget>
 
        <widget type="entry" name="entry11" label="label24">
-               <field type="text" name="cod_istat" />
+               <field type="text" name="cod_istat">
+                       <obligatory>t</obligatory>
+               </field>
        </widget>
 
        <widget type="entry" name="entry12" label="label25">
index 6d64aff0705f7c9980255317514232c78d8a64f9..d0a7e5cd9feef2e170844ec36cd23ab0fa216daf 100644 (file)
        </widget>
 
        <widget type="entry" name="entry6" label="label17">
-               <field type="text" name="nome" />
+               <field type="text" name="nome">
+                       <obligatory>t</obligatory>
+               </field>
        </widget>
 
        <widget type="entry" name="entry7" label="label18">
-               <field type="text" name="cod_istat" />
+               <field type="text" name="cod_istat">
+                       <obligatory>t</obligatory>
+               </field>
        </widget>
 
        <widget type="entry" name="entry9" label="label19">
index 934f8030ac54b430e95eec6ac0abf23d85570747..247ebc0683a247ea86cff00b0e53625602fcde09 100644 (file)
        </widget>
 
        <widget type="entry" name="entry5" label="label12">
-               <field type="text" name="nome" />
+               <field type="text" name="nome">
+                       <obligatory>t</obligatory>
+               </field>
        </widget>
 
        <widget type="entry" name="entry8" label="label15">
-               <field type="text" name="cod_istat" />
+               <field type="text" name="cod_istat">
+                       <obligatory>t</obligatory>
+               </field>
        </widget>
 
 </gtkform>
index ea866e8c0590fce378e83e82b69dd146ffcb835b..f9940bd985c028152b75c45602f460562c0ddc34 100644 (file)
@@ -11,7 +11,9 @@
        </widget>
 
        <widget type="entry" name="entry1" label="label4">
-               <field type="text" name="nome" />
+               <field type="text" name="nome">
+                       <obligatory>t</obligatory>
+               </field>
        </widget>
 
        <widget type="entry" name="entry2" label="label5">
index 86001de240d6b7090ac76daf36fcb8c66a36fff5..4d08478d30941f148634cda3f9e078c2e3dca798 100644 (file)
@@ -11,7 +11,9 @@
        </widget>
 
        <widget type="entry" name="entry13" label="label29">
-               <field type="text" name="nome" />
+               <field type="text" name="nome">
+                       <obligatory>t</obligatory>
+               </field>
        </widget>
 
 </gtkform>
index ca05d4e6ac4ad005a7127013ae1d090f848fd3ab..85920a6cd9e0dde8ec404e48c26612597cfbf315 100644 (file)
@@ -11,7 +11,9 @@
        </widget>
 
        <widget type="entry" name="entry17" label="label42">
-               <field type="text" name="nome" />
+               <field type="text" name="nome">
+                       <obligatory>t</obligatory>
+               </field>
        </widget>
 
        <widget type="entry" name="entry19" label="label44">
index 96f9a373f57c7f573946a35d61fd09a94d065c9b..ade36d470f7220f2b9bcf8bf0a55b671f1239c91 100644 (file)
                                 <signal name="activate" handler="on_mnu_utilita_importa_capcomuniitaliani_activate"/>
                               </object>
                             </child>
+                            <child>
+                              <object class="GtkMenuItem" id="menuitem17">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">Vie da Ci_vilia</property>
+                                <property name="use_underline">True</property>
+                                <signal name="activate" handler="on_mnu_utilita_importa_viecivilia_activate"/>
+                              </object>
+                            </child>
                           </object>
                         </child>
                       </object>
     <property name="window_position">center-on-parent</property>
     <property name="destroy_with_parent">True</property>
     <property name="type_hint">normal</property>
-    <property name="has_separator">False</property>
     <property name="program_name">Territorio</property>
     <property name="version">0.0.1</property>
     <property name="copyright" translatable="yes">Andrea Zagli</property>
index 8e850200d346c2d1081419169cb868178f2bd5ec..f01272cd6006e78ef063333cb8970b128ff1de0f 100644 (file)
@@ -26,6 +26,8 @@ territorio_SOURCES = \
                 importacomuniistat.h \
                 importaregioniprovinceistat.c \
                 importaregioniprovinceistat.h \
+                importaviecivilia.c \
+                importaviecivilia.h \
                 main.c \
                 province.c \
                 province.h \
diff --git a/src/importaviecivilia.c b/src/importaviecivilia.c
new file mode 100644 (file)
index 0000000..d5d5bd4
--- /dev/null
@@ -0,0 +1,243 @@
+/* 
+ * Copyright (C) 2011 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 <libgda-ui/libgda-ui.h>
+
+#include "importaviecivilia.h"
+
+static void territorio_importa_viecivilia_class_init (TerritorioImportaVieCiviliaClass *klass);
+static void territorio_importa_viecivilia_init (TerritorioImportaVieCivilia *territorio_importa_viecivilia);
+
+static void territorio_importa_viecivilia_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void territorio_importa_viecivilia_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+#define TERRITORIO_IMPORTA_VIECIVILIA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TERRITORIO_IMPORTA_VIECIVILIA, TerritorioImportaVieCiviliaPrivate))
+
+typedef struct _TerritorioImportaVieCiviliaPrivate TerritorioImportaVieCiviliaPrivate;
+struct _TerritorioImportaVieCiviliaPrivate
+       {
+               TerritorioCommons *commons;
+       };
+
+G_DEFINE_TYPE (TerritorioImportaVieCivilia, territorio_importa_viecivilia, G_TYPE_OBJECT)
+
+static void
+territorio_importa_viecivilia_class_init (TerritorioImportaVieCiviliaClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (TerritorioImportaVieCiviliaPrivate));
+
+       object_class->set_property = territorio_importa_viecivilia_set_property;
+       object_class->get_property = territorio_importa_viecivilia_get_property;
+}
+
+static void
+territorio_importa_viecivilia_init (TerritorioImportaVieCivilia *territorio_importa_viecivilia)
+{
+       TerritorioImportaVieCiviliaPrivate *priv = TERRITORIO_IMPORTA_VIECIVILIA_GET_PRIVATE (territorio_importa_viecivilia);
+}
+
+/**
+ * territorio_importa_viecivilia_new:
+ * @commons:
+ *
+ * Returns: the newly created #TerritorioImportaVieCivilia object.
+ */
+TerritorioImportaVieCivilia
+*territorio_importa_viecivilia_new (TerritorioCommons *commons)
+{
+       GtkWidget *dialog;
+       GtkWidget *carea;
+       GtkWidget *connection;
+
+       GdaEx *gdaex;
+
+       gchar *sql;
+
+       GdaDataModel *dm;
+       GdaDataModelIter *iter;
+
+       GdaDataModel *dm_territorio;
+
+       const GdaDsnInfo *dsn;
+
+       guint id_vie;
+
+       TerritorioImportaVieCivilia *a = TERRITORIO_IMPORTA_VIECIVILIA (g_object_new (territorio_importa_viecivilia_get_type (), NULL));
+
+       TerritorioImportaVieCiviliaPrivate *priv = TERRITORIO_IMPORTA_VIECIVILIA_GET_PRIVATE (a);
+
+       gdaui_init ();
+
+       priv->commons = commons;
+
+       GtkWindow *w_main = GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main"));
+
+       dialog  = gtk_dialog_new_with_buttons ("Immettere i parametri di connessione al database Civilia dal quale importare",
+                                               w_main,
+                                               GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                               GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+                                               NULL);
+       gtk_dialog_set_has_separator (GTK_DIALOG (dialog), TRUE);
+
+       carea = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+
+       connection = gdaui_login_new (NULL);
+       gdaui_login_set_mode (GDAUI_LOGIN (connection), GDA_UI_LOGIN_HIDE_DSN_SELECTION_MODE);
+       gtk_container_add (GTK_CONTAINER (carea), connection);
+       gtk_widget_show (connection);
+
+       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+               {
+                       dsn = gdaui_login_get_connection_information (GDAUI_LOGIN (connection));
+                       gdaex = gdaex_new_from_string (g_strdup_printf ("%s://%s;%s", dsn->provider, dsn->cnc_string, dsn->auth_string));
+                       if (gdaex == NULL)
+                               {
+                                       gtk_widget_destroy (dialog);
+                                       dialog = gtk_message_dialog_new (w_main,
+                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                        GTK_MESSAGE_WARNING,
+                                                                        GTK_BUTTONS_OK,
+                                                                        "Impossibile stabilire la connessione al database Civilia.");
+                                       gtk_dialog_run (GTK_DIALOG (dialog));
+                                       gtk_widget_destroy (dialog);
+                                       return NULL;
+                               }
+
+                       sql = g_strdup_printf ("SELECT * FROM m1_tab_vie");
+                       dm = gdaex_query (gdaex, sql);
+                       g_free (sql);
+
+                       if (dm != NULL)
+                               {
+                                       iter = gda_data_model_create_iter (dm);
+                                       while (gda_data_model_iter_move_next (iter))
+                                               {
+                                                       /* controllo se esiste */
+                                                       sql = g_strdup_printf ("SELECT v.id"
+                                                                              " FROM vie AS v INNER JOIN comuni AS c ON v.id_comuni = c.id"
+                                                                              " INNER JOIN province AS p ON c.id_province = p.id"
+                                                                              " WHERE p.cod_istat || c.cod_istat = '%s'"
+                                                                              " AND v.nome = '%s'",
+                                                                              g_strdup_printf ("%06d", gdaex_data_model_iter_get_field_value_integer_at (iter, "M1_COMU_COD")),
+                                                                              gdaex_strescape (gdaex_data_model_iter_get_field_value_stringify_at (iter, "M1_VIA_DESC"), NULL));
+                                                       dm_territorio = gdaex_query (priv->commons->gdaex, sql);
+                                                       if (dm_territorio == NULL || gda_data_model_get_n_rows (dm_territorio) < 1)
+                                                               {
+                                                                       /* trovo un nuovo id */
+                                                                       id_vie = 0;
+                                                                       sql = g_strdup_printf ("SELECT COALESCE (MAX (id), 0) FROM vie");
+                                                                       dm_territorio = gdaex_query (priv->commons->gdaex, sql);
+                                                                       if (dm_territorio != NULL && gda_data_model_get_n_rows (dm_territorio) > 0)
+                                                                               {
+                                                                                       id_vie = gdaex_data_model_get_value_integer_at (dm_territorio, 0, 0);
+                                                                               }
+                                                                       id_vie++;
+
+                                                                       sql = g_strdup_printf ("INSERT INTO vie (id, nome, id_comuni, cap)"
+                                                                                              " VALUES (%d, '%s',"
+                                                                                              " (SELECT c.id FROM comuni AS c INNER JOIN province AS p ON c.id_province = p.id WHERE p.cod_istat || c.cod_istat = '%s'),"
+                                                                                              " '%s')",
+                                                                                              id_vie,
+                                                                                              gdaex_strescape (gdaex_data_model_iter_get_field_value_stringify_at (iter, "M1_VIA_DESC"), NULL),
+                                                                                              g_strdup_printf ("%06d", gdaex_data_model_iter_get_field_value_integer_at (iter, "M1_COMU_COD")),
+                                                                                              gdaex_strescape (gdaex_data_model_iter_get_field_value_stringify_at (iter, "M1_VIA_CAP"), NULL));
+                                                                       if (gdaex_execute (priv->commons->gdaex, sql) == -1)
+                                                                               {
+                                                                                       gtk_widget_destroy (dialog);
+                                                                                       dialog = gtk_message_dialog_new (w_main,
+                                                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                                                        GTK_MESSAGE_WARNING,
+                                                                                                                        GTK_BUTTONS_OK,
+                                                                                                                        "Errore durante il salvataggio della via: %s.",
+                                                                                                                        gdaex_data_model_iter_get_field_value_stringify_at (iter, "M1_VIA_DESC"));
+                                                                                       gtk_dialog_run (GTK_DIALOG (dialog));
+                                                                                       gtk_widget_destroy (dialog);
+                                                                                       return NULL;
+                                                                               }
+                                                               }
+                                                       else
+                                                               {
+                                                                       /* aggiorno la via */
+                                                                       id_vie = gdaex_data_model_get_value_integer_at (dm_territorio, 0, 0);
+                                                               }
+                                               }
+                               }
+                       else
+                               {
+                                       gtk_widget_destroy (dialog);
+                                       dialog = gtk_message_dialog_new (w_main,
+                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                        GTK_MESSAGE_WARNING,
+                                                                        GTK_BUTTONS_OK,
+                                                                        "Impossibile leggere le vie dal database Civilia selezionato.");
+                                       gtk_dialog_run (GTK_DIALOG (dialog));
+                                       gtk_widget_destroy (dialog);
+                                       return NULL;
+                               }
+               }
+       else
+               {
+                       gtk_widget_destroy (dialog);
+               }
+       g_message ("Fine import.");
+
+       return a;
+}
+
+/* PRIVATE */
+static void
+territorio_importa_viecivilia_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       TerritorioImportaVieCivilia *territorio_importa_viecivilia = TERRITORIO_IMPORTA_VIECIVILIA (object);
+
+       TerritorioImportaVieCiviliaPrivate *priv = TERRITORIO_IMPORTA_VIECIVILIA_GET_PRIVATE (territorio_importa_viecivilia);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+territorio_importa_viecivilia_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       TerritorioImportaVieCivilia *territorio_importa_viecivilia = TERRITORIO_IMPORTA_VIECIVILIA (object);
+
+       TerritorioImportaVieCiviliaPrivate *priv = TERRITORIO_IMPORTA_VIECIVILIA_GET_PRIVATE (territorio_importa_viecivilia);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+/* CALLBACK */
diff --git a/src/importaviecivilia.h b/src/importaviecivilia.h
new file mode 100644 (file)
index 0000000..9accbfd
--- /dev/null
@@ -0,0 +1,61 @@
+/* 
+ * Copyright (C) 2011 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 __TERRITORIO_IMPORTA_VIECIVILIA_H__
+#define __TERRITORIO_IMPORTA_VIECIVILIA_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+
+#include "commons.h"
+
+G_BEGIN_DECLS
+
+
+#define TYPE_TERRITORIO_IMPORTA_VIECIVILIA                 (territorio_importa_viecivilia_get_type ())
+#define TERRITORIO_IMPORTA_VIECIVILIA(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TERRITORIO_IMPORTA_VIECIVILIA, TerritorioImportaVieCivilia))
+#define TERRITORIO_IMPORTA_VIECIVILIA_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TERRITORIO_IMPORTA_VIECIVILIA, TerritorioImportaVieCiviliaClass))
+#define IS_TERRITORIO_IMPORTA_VIECIVILIA(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TERRITORIO_IMPORTA_VIECIVILIA))
+#define IS_TERRITORIO_IMPORTA_VIECIVILIA_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TERRITORIO_IMPORTA_VIECIVILIA))
+#define TERRITORIO_IMPORTA_VIECIVILIA_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TERRITORIO_IMPORTA_VIECIVILIA, TerritorioImportaVieCiviliaClass))
+
+
+typedef struct _TerritorioImportaVieCivilia TerritorioImportaVieCivilia;
+typedef struct _TerritorioImportaVieCiviliaClass TerritorioImportaVieCiviliaClass;
+
+struct _TerritorioImportaVieCivilia
+       {
+               GObject parent;
+       };
+
+struct _TerritorioImportaVieCiviliaClass
+       {
+               GObjectClass parent_class;
+       };
+
+GType territorio_importa_viecivilia_get_type (void) G_GNUC_CONST;
+
+TerritorioImportaVieCivilia *territorio_importa_viecivilia_new (TerritorioCommons *commons);
+
+
+G_END_DECLS
+
+#endif /* __TERRITORIO_IMPORTA_VIECIVILIA_H__ */
index c26806a1464edad1b64c2d90c43a44bbc7a68118..02013594e5798db05aced23f31c1bf4f06251ee6 100644 (file)
@@ -34,6 +34,7 @@
 #include "importacapcomuniitaliani.h"
 #include "importacomuniistat.h"
 #include "importaregioniprovinceistat.h"
+#include "importaviecivilia.h"
 #include "province.h"
 #include "regioni.h"
 #include "stati.h"
@@ -179,6 +180,15 @@ on_mnu_utilita_importa_capcomuniitaliani_activate (GtkMenuItem *menuitem,
        g_object_unref (m);
 }
 
+G_MODULE_EXPORT void
+on_mnu_utilita_importa_viecivilia_activate (GtkMenuItem *menuitem,
+                            gpointer user_data)
+{
+       TerritorioImportaVieCivilia *m = territorio_importa_viecivilia_new (commons);
+
+       g_object_unref (m);
+}
+
 G_MODULE_EXPORT void
 on_mnu_help_about_activate (GtkMenuItem *menuitem,
                             gpointer user_data)