From: Andrea Zagli Date: Wed, 15 Jul 2009 17:26:30 +0000 (+0200) Subject: Added GtkGisLayerSourceShp::new_from_xml. X-Git-Tag: GTKGIS_0_0_2~5 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=0a465ea056d96794c45f5274fb330364468ce96f;p=libgtkgis Added GtkGisLayerSourceShp::new_from_xml. Added GtkGisLayerSourceRaster::new_from_xml. Added GtkGisLayerSourcePostgis::new_from_xml. --- diff --git a/src/gtkgis.c b/src/gtkgis.c index 3806401..5475307 100644 --- a/src/gtkgis.c +++ b/src/gtkgis.c @@ -233,44 +233,15 @@ GtkWidget if (xmlStrcmp (cur->name, "shape") == 0) { - gchar *filename; - - filename = xmlGetProp (cur, (const xmlChar *)"filename"); - if (filename != NULL) - { - if (!g_path_is_absolute (filename)) - { - filename = g_build_filename (g_get_current_dir (), - filename, - NULL); - } - - layer_source = gtk_gis_layer_source_shp_new ((const gchar *)filename); - } + layer_source = gtk_gis_layer_source_shp_new_from_xml (cur); } else if (xmlStrcmp (cur->name, "postgis") == 0) { - layer_source = gtk_gis_layer_source_postgis_new (xmlGetProp (cur, (const xmlChar *)"host"), - atol (xmlGetProp (cur, (const xmlChar *)"port")), - xmlGetProp (cur, (const xmlChar *)"username"), - xmlGetProp (cur, (const xmlChar *)"password")); + layer_source = gtk_gis_layer_source_postgis_new_from_xml (cur); } else if (xmlStrcmp (cur->name, "raster") == 0) { - gchar *filename; - - filename = xmlGetProp (cur, (const xmlChar *)"filename"); - if (filename != NULL) - { - if (!g_path_is_absolute (filename)) - { - filename = g_build_filename (g_get_current_dir (), - filename, - NULL); - } - - layer_source = gtk_gis_layer_source_raster_new ((const gchar *)filename); - } + layer_source = gtk_gis_layer_source_raster_new_from_xml (cur); } if (layer_source != NULL) diff --git a/src/layersourcepostgis.c b/src/layersourcepostgis.c index 8c97e23..bfa5188 100644 --- a/src/layersourcepostgis.c +++ b/src/layersourcepostgis.c @@ -20,8 +20,6 @@ #include #endif -#include - #include "layersourcepostgis.h" static void gtk_gis_layer_source_postgis_class_init (GtkGisLayerSourcePostgisClass *klass); @@ -104,6 +102,37 @@ GtkGisLayerSource return source; } +/** + * gtk_gis_layer_source_postgis_new_from_xml: + * @xnode: + * + * Creates a new #GtkGisLayerSourcePostgis object from an #xmlNode. + * + * Returns: the newly created #GtkGisLayerSourcePostgis object. + */ +GtkGisLayerSource +*gtk_gis_layer_source_postgis_new_from_xml (xmlNode *xnode) +{ + GtkGisLayerSource *source = NULL; + + gchar *host; + gint port; + gchar *username; + gchar *password; + + host = xmlGetProp (xnode, (const xmlChar *)"host"); + port = strtol (xmlGetProp (xnode, (const xmlChar *)"port"), NULL, 10); + username = xmlGetProp (xnode, (const xmlChar *)"username"); + password = xmlGetProp (xnode, (const xmlChar *)"password"); + + source = gtk_gis_layer_source_postgis_new (host, + port, + username, + password); + + return source; +} + static xmlNode *gtk_gis_layer_source_postgis_get_xml (GtkGisLayerSource *source) { diff --git a/src/layersourcepostgis.h b/src/layersourcepostgis.h index ccba260..2c03ea1 100644 --- a/src/layersourcepostgis.h +++ b/src/layersourcepostgis.h @@ -20,6 +20,8 @@ #ifndef __GTK_GIS_LAYER_SOURCE_POSTGIS_H__ #define __GTK_GIS_LAYER_SOURCE_POSTGIS_H__ +#include + #include "layersource.h" G_BEGIN_DECLS @@ -54,6 +56,8 @@ GtkGisLayerSource *gtk_gis_layer_source_postgis_new (gchar *host, gchar *username, gchar *password); +GtkGisLayerSource *gtk_gis_layer_source_postgis_new_from_xml (xmlNode *xnode); + G_END_DECLS diff --git a/src/layersourceraster.c b/src/layersourceraster.c index 4a3cc2e..467a95f 100644 --- a/src/layersourceraster.c +++ b/src/layersourceraster.c @@ -20,8 +20,6 @@ #include #endif -#include - #include #include "layersourceraster.h" @@ -105,6 +103,37 @@ GtkGisLayerSource return source; } +/** + * gtk_gis_layer_source_raster_new_from_xml: + * @xnode: + * + * Creates a new #GtkGisLayerSourceRaster object from an #xmlNode. + * + * Returns: the newly created #GtkGisLayerSourceRaster object. + */ +GtkGisLayerSource +*gtk_gis_layer_source_raster_new_from_xml (xmlNode *xnode) +{ + GtkGisLayerSource *source = NULL; + + gchar *filename; + + filename = xmlGetProp (xnode, (const xmlChar *)"filename"); + if (filename != NULL) + { + if (!g_path_is_absolute (filename)) + { + filename = g_build_filename (g_get_current_dir (), + filename, + NULL); + } + + source = gtk_gis_layer_source_raster_new ((const gchar *)filename); + } + + return source; +} + /** * gtk_gis_layer_source_raster_get_filename: * @source: diff --git a/src/layersourceraster.h b/src/layersourceraster.h index 51e14cd..d496572 100644 --- a/src/layersourceraster.h +++ b/src/layersourceraster.h @@ -20,6 +20,8 @@ #ifndef __GTK_GIS_LAYER_SOURCE_RASTER_H__ #define __GTK_GIS_LAYER_SOURCE_RASTER_H__ +#include + #include "layersource.h" G_BEGIN_DECLS @@ -51,6 +53,8 @@ GType gtk_gis_layer_source_raster_get_type (void) G_GNUC_CONST; GtkGisLayerSource *gtk_gis_layer_source_raster_new (const gchar *filename); +GtkGisLayerSource *gtk_gis_layer_source_raster_new_from_xml (xmlNode *xnode); + gchar *gtk_gis_layer_source_raster_get_filename (GtkGisLayerSourceRaster *source); diff --git a/src/layersourceshp.c b/src/layersourceshp.c index e557251..d4cf214 100644 --- a/src/layersourceshp.c +++ b/src/layersourceshp.c @@ -23,8 +23,6 @@ #include #include -#include - #include "layersourceshp.h" static void gtk_gis_layer_source_shp_class_init (GtkGisLayerSourceShpClass *klass); @@ -106,6 +104,37 @@ GtkGisLayerSource return source; } +/** + * gtk_gis_layer_source_shp_new_from_xml: + * @xnode: + * + * Creates a new #GtkGisLayerSourceShp object from an #xmlNode. + * + * Returns: the newly created #GtkGisLayerSourceShp object. + */ +GtkGisLayerSource +*gtk_gis_layer_source_shp_new_from_xml (xmlNode *xnode) +{ + GtkGisLayerSource *source = NULL; + + gchar *filename; + + filename = xmlGetProp (xnode, (const xmlChar *)"filename"); + if (filename != NULL) + { + if (!g_path_is_absolute (filename)) + { + filename = g_build_filename (g_get_current_dir (), + filename, + NULL); + } + + source = gtk_gis_layer_source_shp_new ((const gchar *)filename); + } + + return source; +} + /** * gtk_gis_layer_source_shp_get_filename: * @source: diff --git a/src/layersourceshp.h b/src/layersourceshp.h index afb638e..723e759 100644 --- a/src/layersourceshp.h +++ b/src/layersourceshp.h @@ -20,6 +20,8 @@ #ifndef __GTK_GIS_LAYER_SOURCE_SHP_H__ #define __GTK_GIS_LAYER_SOURCE_SHP_H__ +#include + #include "layersource.h" G_BEGIN_DECLS @@ -51,6 +53,8 @@ GType gtk_gis_layer_source_shp_get_type (void) G_GNUC_CONST; GtkGisLayerSource *gtk_gis_layer_source_shp_new (const gchar *filename); +GtkGisLayerSource *gtk_gis_layer_source_shp_new_from_xml (xmlNode *xnode); + gchar *gtk_gis_layer_source_shp_get_filename (GtkGisLayerSourceShp *source);