From: Andrea Zagli <a.zagli@comune.scandicci.fi.it>
Date: Thu, 16 Jun 2011 15:41:41 +0000 (+0200)
Subject: Finito import vie da civilia.
X-Git-Tag: gtk3~24
X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=4057637c935185204d75021cb85e537e3dfc7125;p=solipa%2Fterritorio

Finito import vie da civilia.
---

diff --git a/configure.ac b/configure.ac
index 19b7670..8afdd77 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,7 +30,8 @@ PKG_CHECK_MODULES(TERRITORIO, [gio-2.0 >= 2.20
                           libgdaex >= 0.3.0
                           libgtkform >= 0.1.3
                           libaute >= 0.0.2
-                          libautoz >= 0.0.1])
+                          libautoz >= 0.0.1
+                          libsolipa >= 0.3.1])
 
 AC_SUBST(TERRITORIO_CFLAGS)
 AC_SUBST(TERRITORIO_LIBS)
diff --git a/data/territorio/gui/territorio.gui b/data/territorio/gui/territorio.gui
index ade36d4..d4fa37a 100644
--- a/data/territorio/gui/territorio.gui
+++ b/data/territorio/gui/territorio.gui
@@ -363,6 +363,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="model">lstore_stati</property>
+                <property name="rules_hint">True</property>
                 <property name="search_column">1</property>
                 <child>
                   <object class="GtkTreeViewColumn" id="treeviewcolumn2">
@@ -539,6 +540,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">255</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -554,6 +556,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">255</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -582,6 +585,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">5</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -623,6 +627,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">5</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -730,6 +735,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="model">lstore_regioni</property>
+                <property name="rules_hint">True</property>
                 <property name="search_column">1</property>
                 <child>
                   <object class="GtkTreeViewColumn" id="treeviewcolumn1">
@@ -893,6 +899,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">255</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -921,6 +928,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">5</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -1013,6 +1021,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="model">lstore_province</property>
+                <property name="rules_hint">True</property>
                 <property name="search_column">1</property>
                 <child>
                   <object class="GtkTreeViewColumn" id="treeviewcolumn3">
@@ -1212,6 +1221,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">255</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -1240,6 +1250,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">5</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -1268,6 +1279,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">5</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -1418,6 +1430,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="model">lstore_comuni</property>
+                <property name="rules_hint">True</property>
                 <property name="search_column">1</property>
                 <child>
                   <object class="GtkTreeViewColumn" id="treeviewcolumn4">
@@ -1617,6 +1630,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">255</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -1645,6 +1659,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">5</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -1673,6 +1688,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">5</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -1852,6 +1868,7 @@
                 <property name="can_focus">True</property>
                 <property name="model">lstore_tipi_aggregazione_territoriale</property>
                 <property name="headers_clickable">False</property>
+                <property name="rules_hint">True</property>
                 <property name="search_column">0</property>
                 <child>
                   <object class="GtkTreeViewColumn" id="treeviewcolumn5">
@@ -2015,6 +2032,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">150</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -2108,6 +2126,7 @@
                 <property name="can_focus">True</property>
                 <property name="model">lstore_aggregazioni_territoriali</property>
                 <property name="headers_clickable">False</property>
+                <property name="rules_hint">True</property>
                 <property name="search_column">0</property>
                 <child>
                   <object class="GtkTreeViewColumn" id="treeviewcolumn6">
@@ -2271,6 +2290,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">150</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
                 <property name="text" translatable="yes">uu</property>
               </object>
               <packing>
@@ -2397,6 +2417,7 @@
                 <property name="can_focus">True</property>
                 <property name="model">lstore_vie</property>
                 <property name="headers_clickable">False</property>
+                <property name="rules_hint">True</property>
                 <property name="search_column">1</property>
                 <child>
                   <object class="GtkTreeViewColumn" id="treeviewcolumn7">
@@ -2607,6 +2628,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">255</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -2635,6 +2657,7 @@
                 <property name="can_focus">True</property>
                 <property name="max_length">5</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -2783,6 +2806,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -2943,6 +2967,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -3103,6 +3128,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="invisible_char">&#x25CF;</property>
+                <property name="activates_default">True</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
diff --git a/src/commons.h b/src/commons.h
index 18b0031..91b71af 100644
--- a/src/commons.h
+++ b/src/commons.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Andrea Zagli <a.zagli@comune.scandicci.fi.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <a.zagli@comune.scandicci.fi.it>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@
 #include <libgdaex/libgdaex.h>
 #include <libautoz/autoz.h>
 #include <libautoz/role_interface.h>
+#include <libsolipa/libsolipa.h>
 
 typedef struct
 	{
@@ -43,6 +44,8 @@ typedef struct
 		gchar *utente;
 		Autoz *autoz;
 		AutozIRole *role_utente;
+
+		Solipa *solipa;
 	} TerritorioCommons;
 
 #endif /* __TERRITORIO_COMMONS_H__ */
diff --git a/src/importaviecivilia.c b/src/importaviecivilia.c
index d5d5bd4..90cd7c1 100644
--- a/src/importaviecivilia.c
+++ b/src/importaviecivilia.c
@@ -18,6 +18,7 @@
  */
 
 #include <libgda-ui/libgda-ui.h>
+#include <libsolipa/libsolipa.h>
 
 #include "importaviecivilia.h"
 
@@ -69,10 +70,13 @@ territorio_importa_viecivilia_init (TerritorioImportaVieCivilia *territorio_impo
 TerritorioImportaVieCivilia
 *territorio_importa_viecivilia_new (TerritorioCommons *commons)
 {
+	GtkWindow *w_main;
 	GtkWidget *dialog;
 	GtkWidget *carea;
 	GtkWidget *connection;
 
+	SolipaProgressWindow *w_progress;
+
 	GdaEx *gdaex;
 
 	gchar *sql;
@@ -80,11 +84,18 @@ TerritorioImportaVieCivilia
 	GdaDataModel *dm;
 	GdaDataModelIter *iter;
 
+	guint rows;
+	gdouble fract;
+	gdouble fract_tot;
+
 	GdaDataModel *dm_territorio;
 
 	const GdaDsnInfo *dsn;
 
 	guint id_vie;
+	gchar *nome;
+	gchar *m1_comu_cod;
+	gchar *m1_via_cap;
 
 	TerritorioImportaVieCivilia *a = TERRITORIO_IMPORTA_VIECIVILIA (g_object_new (territorio_importa_viecivilia_get_type (), NULL));
 
@@ -94,7 +105,7 @@ TerritorioImportaVieCivilia
 
 	priv->commons = commons;
 
-	GtkWindow *w_main = GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main"));
+	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,
@@ -115,9 +126,9 @@ TerritorioImportaVieCivilia
 		{
 			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));
+			gtk_widget_destroy (dialog);
 			if (gdaex == NULL)
 				{
-					gtk_widget_destroy (dialog);
 					dialog = gtk_message_dialog_new (w_main,
 					                                 GTK_DIALOG_DESTROY_WITH_PARENT,
 					                                 GTK_MESSAGE_WARNING,
@@ -134,27 +145,64 @@ TerritorioImportaVieCivilia
 
 			if (dm != NULL)
 				{
+					rows = gda_data_model_get_n_rows (dm);
+					if (rows > 0)
+						{
+							w_progress = solipa_progress_window_new (priv->commons->solipa);
+							g_object_set (G_OBJECT (w_progress),
+							              "title", "Importazione vie da Civilia",
+							              "label", "",
+							              "with-label", FALSE,
+							              "with-cancel-button", FALSE,
+							              "with-percentage", TRUE,
+							              NULL);
+							solipa_progress_window_run (w_progress, w_main);
+
+							fract = 1.0 / (gdouble)rows;
+							fract_tot = 0.0 - fract;
+						}
+
 					iter = gda_data_model_create_iter (dm);
 					while (gda_data_model_iter_move_next (iter))
 						{
+							fract_tot += fract;
+							solipa_progress_window_set_fraction (w_progress, fract_tot);
+							while (gtk_events_pending ()) gtk_main_iteration ();
+
+							nome = gdaex_strescape (gdaex_data_model_iter_get_field_value_stringify_at (iter, "M1_VIA_DESC"), NULL);
+							if (g_strcmp0 (nome, "") == 0)
+								{
+									g_free (nome);
+									continue;
+								}
+
+							m1_comu_cod = g_strdup_printf ("%06d", gdaex_data_model_iter_get_field_value_integer_at (iter, "M1_COMU_COD"));
+							m1_via_cap = gdaex_strescape (gdaex_data_model_iter_get_field_value_stringify_at (iter, "M1_VIA_CAP"), NULL);
+
 							/* 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));
+							                       m1_comu_cod,
+							                       nome);
 							dm_territorio = gdaex_query (priv->commons->gdaex, sql);
+							g_free (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)
+									g_free (sql);
+									if (dm_territorio != NULL)
 										{
-											id_vie = gdaex_data_model_get_value_integer_at (dm_territorio, 0, 0);
+											if (gda_data_model_get_n_rows (dm_territorio) > 0)
+												{
+													id_vie = gdaex_data_model_get_value_integer_at (dm_territorio, 0, 0);
+												}
+											g_object_unref (dm_territorio);
 										}
 									id_vie++;
 
@@ -163,12 +211,13 @@ TerritorioImportaVieCivilia
 									                       " (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));
+									                       nome,
+									                       m1_comu_cod,
+									                       m1_via_cap);
 									if (gdaex_execute (priv->commons->gdaex, sql) == -1)
 										{
-											gtk_widget_destroy (dialog);
+											g_free (sql);
+											g_object_unref (w_progress);
 											dialog = gtk_message_dialog_new (w_main,
 											                                 GTK_DIALOG_DESTROY_WITH_PARENT,
 											                                 GTK_MESSAGE_WARNING,
@@ -179,12 +228,51 @@ TerritorioImportaVieCivilia
 											gtk_widget_destroy (dialog);
 											return NULL;
 										}
+									g_free (sql);
 								}
 							else
 								{
+									if (dm_territorio != NULL)
+										{
+											g_object_unref (dm_territorio);
+										}
+
 									/* aggiorno la via */
 									id_vie = gdaex_data_model_get_value_integer_at (dm_territorio, 0, 0);
+									sql = g_strdup_printf ("UPDATE vie"
+									                       " SET nome = '%s',"
+									                       " id_comuni = (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'),"
+									                       " cap = '%s'"
+									                       " WHERE id = %d",
+									                       nome,
+									                       m1_comu_cod,
+									                       m1_via_cap,
+									                       id_vie);
+									if (gdaex_execute (priv->commons->gdaex, sql) == -1)
+										{
+											g_free (sql);
+											g_object_unref (w_progress);
+											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;
+										}
+									g_free (sql);
 								}
+
+							g_free (nome);
+							g_free (m1_comu_cod);
+							g_free (m1_via_cap);
+						}
+
+					if (rows > 0)
+						{
+							g_object_unref (w_progress);
 						}
 				}
 			else
@@ -199,6 +287,8 @@ TerritorioImportaVieCivilia
 					gtk_widget_destroy (dialog);
 					return NULL;
 				}
+
+			gdaex_free (gdaex);
 		}
 	else
 		{
diff --git a/src/main.c b/src/main.c
index 0201359..47f6161 100644
--- a/src/main.c
+++ b/src/main.c
@@ -373,6 +373,9 @@ main (int argc, char *argv[])
 			g_error ("Errore nella connessione al database: %s", cnc_string);
 		}
 
+	/* inizializzo solipa */
+	commons->solipa = solipa_new ();
+
 	commons->gtkbuilder = gtk_builder_new ();
 
 	error = NULL;