From db03733a614fc5f52ede5d5c83b8aeb5651599aa Mon Sep 17 00:00:00 2001 From: Guilhem Bonnefille Date: Fri, 24 Jul 2009 22:32:48 +0200 Subject: [PATCH] Move label It is now a property of VikMapSourceDefault. It is also a private filed of VikMapType (compat layer). --- src/bluemarble.c | 4 ++-- src/openaerial.c | 4 ++-- src/osm.c | 18 +++++++++--------- src/terraserver.c | 12 ++++++------ src/terraservermapsource.c | 4 ++-- src/terraservermapsource.h | 2 +- src/vikmapslayer.c | 5 +++-- src/vikmapslayer.h | 2 +- src/vikmapslayer_compat.c | 4 ++-- src/vikmapsource.c | 14 ++++++++++++++ src/vikmapsource.h | 2 ++ src/vikmapsourcedefault.c | 43 ++++++++++++++++++++++++++++++++++++++++--- src/vikmaptype.c | 11 ++++++++--- src/vikmaptype.h | 2 +- src/vikslippymapsource.c | 4 ++-- src/vikslippymapsource.h | 2 +- 16 files changed, 96 insertions(+), 37 deletions(-) diff --git a/src/bluemarble.c b/src/bluemarble.c index 80f365bd..2c03fba7 100644 --- a/src/bluemarble.c +++ b/src/bluemarble.c @@ -27,8 +27,8 @@ /* initialisation */ void bluemarble_init () { - VikMapSource *bluemarble_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 15, "s3.amazonaws.com", "/com.modestmaps.bluemarble/%d-r%3$d-c%2$d.jpg" )); + VikMapSource *bluemarble_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 15, "BlueMarble", "s3.amazonaws.com", "/com.modestmaps.bluemarble/%d-r%3$d-c%2$d.jpg" )); - maps_layer_register_map_source ("BlueMarble", bluemarble_type); + maps_layer_register_map_source (bluemarble_type); } diff --git a/src/openaerial.c b/src/openaerial.c index d85e7bc9..cd0655a7 100644 --- a/src/openaerial.c +++ b/src/openaerial.c @@ -27,8 +27,8 @@ /* initialisation */ void openaerial_init () { - VikMapSource *openaerialmap_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 20, "tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%d/%d/%d.jpg" )); + VikMapSource *openaerialmap_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 20, "OpenAerialMap", "tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%d/%d/%d.jpg" )); - maps_layer_register_map_source ("OpenAerialMap", openaerialmap_type); + maps_layer_register_map_source (openaerialmap_type); } diff --git a/src/osm.c b/src/osm.c index 9326f4ee..6294e39e 100644 --- a/src/osm.c +++ b/src/osm.c @@ -32,15 +32,15 @@ /* initialisation */ void osm_init () { - VikMapSource *osmarender_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id(12, "tah.openstreetmap.org", "/Tiles/tile/%d/%d/%d.png")); - VikMapSource *mapnik_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 13, "tile.openstreetmap.org", "/%d/%d/%d.png")); - VikMapSource *maplint_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 14, "tah.openstreetmap.org", "/Tiles/maplint.php/%d/%d/%d.png")); - VikMapSource *cycle_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 17, "thunderflames.org/tiles/cycle/", "%d/%d/%d.png" )); - - maps_layer_register_map_source ("OpenStreetMap (Osmarender)", osmarender_type); - maps_layer_register_map_source ("OpenStreetMap (Mapnik)", mapnik_type); - maps_layer_register_map_source ("OpenStreetMap (Maplint)", maplint_type); - maps_layer_register_map_source ("OpenStreetMap (Cycle)", cycle_type); + VikMapSource *osmarender_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id(12, "OpenStreetMap (Osmarender)", "tah.openstreetmap.org", "/Tiles/tile/%d/%d/%d.png")); + VikMapSource *mapnik_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 13, "OpenStreetMap (Mapnik)", "tile.openstreetmap.org", "/%d/%d/%d.png")); + VikMapSource *maplint_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 14, "OpenStreetMap (Maplint)", "tah.openstreetmap.org", "/Tiles/maplint.php/%d/%d/%d.png")); + VikMapSource *cycle_type = VIK_MAP_SOURCE(vik_slippy_map_source_new_with_id( 17, "OpenStreetMap (Cycle)", "thunderflames.org/tiles/cycle/", "%d/%d/%d.png" )); + + maps_layer_register_map_source (osmarender_type); + maps_layer_register_map_source (mapnik_type); + maps_layer_register_map_source (maplint_type); + maps_layer_register_map_source (cycle_type); // Webtools VikWebtoolCenter *webtool = NULL; diff --git a/src/terraserver.c b/src/terraserver.c index e9d78c83..9e1636c7 100644 --- a/src/terraserver.c +++ b/src/terraserver.c @@ -27,11 +27,11 @@ #include "vikmapslayer.h" void terraserver_init () { - VikMapSource *map_type_1 = VIK_MAP_SOURCE(terraserver_map_source_new_with_id( 2, 2 )); - VikMapSource *map_type_2 = VIK_MAP_SOURCE(terraserver_map_source_new_with_id( 1, 1 )); - VikMapSource *map_type_3 = VIK_MAP_SOURCE(terraserver_map_source_new_with_id( 4, 4 )); + VikMapSource *map_type_1 = VIK_MAP_SOURCE(terraserver_map_source_new_with_id( 2, "Terraserver Topos", 2 )); + VikMapSource *map_type_2 = VIK_MAP_SOURCE(terraserver_map_source_new_with_id( 1, "Terraserver Aerials", 1 )); + VikMapSource *map_type_3 = VIK_MAP_SOURCE(terraserver_map_source_new_with_id( 4, "Terraserver Urban Areas", 4 )); - maps_layer_register_map_source ("Terraserver Topos", map_type_1); - maps_layer_register_map_source ("Terraserver Aerials", map_type_2); - maps_layer_register_map_source ("Terraserver Urban Areas", map_type_3); + maps_layer_register_map_source (map_type_1); + maps_layer_register_map_source (map_type_2); + maps_layer_register_map_source (map_type_3); } diff --git a/src/terraservermapsource.c b/src/terraservermapsource.c index ff2016e9..f7d32c36 100644 --- a/src/terraservermapsource.c +++ b/src/terraservermapsource.c @@ -224,7 +224,7 @@ _download ( VikMapSource *self, MapCoord *src, const gchar *dest_fn ) } TerraserverMapSource * -terraserver_map_source_new_with_id (guint8 id, int type) +terraserver_map_source_new_with_id (guint8 id, const char *label, int type) { - return g_object_new(TERRASERVER_TYPE_MAP_SOURCE, "id", id, "type", type, NULL); + return g_object_new(TERRASERVER_TYPE_MAP_SOURCE, "id", id, "label", label, "type", type, NULL); } \ No newline at end of file diff --git a/src/terraservermapsource.h b/src/terraservermapsource.h index 2b00f6ad..4f28991b 100644 --- a/src/terraservermapsource.h +++ b/src/terraservermapsource.h @@ -49,7 +49,7 @@ struct _TerraserverMapSource GType terraserver_map_source_get_type (void) G_GNUC_CONST; -TerraserverMapSource * terraserver_map_source_new_with_id (guint8 id, int type); +TerraserverMapSource * terraserver_map_source_new_with_id (guint8 id, const char *label, int type); G_END_DECLS diff --git a/src/vikmapslayer.c b/src/vikmapslayer.c index 4f88a509..7b49fefe 100644 --- a/src/vikmapslayer.c +++ b/src/vikmapslayer.c @@ -206,12 +206,13 @@ enum { REDOWNLOAD_NONE = 0, REDOWNLOAD_BAD, REDOWNLOAD_ALL, DOWNLOAD_OR_REFRESH /******** MAPS LAYER TYPES **************/ /****************************************/ -void maps_layer_register_map_source ( const char *label, VikMapSource *map ) +void maps_layer_register_map_source ( VikMapSource *map ) { - g_assert(label != NULL); g_assert(map != NULL); guint id = vik_map_source_get_uniq_id(map); + const char *label = vik_map_source_get_label(map); + g_assert(label != NULL); /* Add the label */ params_maptypes = g_list_append(params_maptypes, g_strdup(label)); diff --git a/src/vikmapslayer.h b/src/vikmapslayer.h index 914fd0b3..a52c6039 100644 --- a/src/vikmapslayer.h +++ b/src/vikmapslayer.h @@ -45,7 +45,7 @@ GType vik_maps_layer_get_type (); typedef struct _VikMapsLayer VikMapsLayer; -void maps_layer_register_map_source ( const char *label, VikMapSource *map ); +void maps_layer_register_map_source ( VikMapSource *map ); void maps_layer_download_section_without_redraw ( VikMapsLayer *vml, VikViewport *vvp, VikCoord *ul, VikCoord *br, gdouble zoom); gint vik_maps_layer_get_map_type(VikMapsLayer *vml); gchar *vik_maps_layer_get_map_label(VikMapsLayer *vml); diff --git a/src/vikmapslayer_compat.c b/src/vikmapslayer_compat.c index a3ca7a8f..0fd04bcb 100644 --- a/src/vikmapslayer_compat.c +++ b/src/vikmapslayer_compat.c @@ -33,6 +33,6 @@ void maps_layer_register_type ( const char *label, guint id, VikMapsLayer_MapType *map_type ) { g_assert(id == map_type->uniq_id); - VikMapType *object = vik_map_type_new_with_id (*map_type); - maps_layer_register_map_source ( label, VIK_MAP_SOURCE (object) ); + VikMapType *object = vik_map_type_new_with_id (*map_type, label); + maps_layer_register_map_source ( VIK_MAP_SOURCE (object) ); } diff --git a/src/vikmapsource.c b/src/vikmapsource.c index 15d282c2..48a679f0 100644 --- a/src/vikmapsource.c +++ b/src/vikmapsource.c @@ -52,6 +52,7 @@ vik_map_source_class_init (VikMapSourceClass *klass) GObjectClass* object_class = G_OBJECT_CLASS (klass); klass->get_uniq_id = NULL; + klass->get_label = NULL; klass->get_tilesize_x = NULL; klass->get_tilesize_y = NULL; klass->get_drawmode = NULL; @@ -76,6 +77,19 @@ vik_map_source_get_uniq_id (VikMapSource *self) return (*klass->get_uniq_id)(self); } +const gchar * +vik_map_source_get_label (VikMapSource *self) +{ + VikMapSourceClass *klass; + g_return_val_if_fail (self != NULL, NULL); + g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); + klass = VIK_MAP_SOURCE_GET_CLASS(self); + + g_return_val_if_fail (klass->get_label != NULL, NULL); + + return (*klass->get_label)(self); +} + guint16 vik_map_source_get_tilesize_x (VikMapSource *self) { diff --git a/src/vikmapsource.h b/src/vikmapsource.h index a8e4f810..29080ffd 100644 --- a/src/vikmapsource.h +++ b/src/vikmapsource.h @@ -43,6 +43,7 @@ struct _VikMapSourceClass GObjectClass parent_class; guint8 (* get_uniq_id) (VikMapSource * self); + const gchar * (* get_label) (VikMapSource * self); guint16 (* get_tilesize_x) (VikMapSource * self); guint16 (* get_tilesize_y) (VikMapSource * self); VikViewportDrawMode (* get_drawmode) (VikMapSource * self); @@ -59,6 +60,7 @@ struct _VikMapSource GType vik_map_source_get_type (void) G_GNUC_CONST; guint8 vik_map_source_get_uniq_id (VikMapSource * self); +const gchar *vik_map_source_get_label (VikMapSource * self); guint16 vik_map_source_get_tilesize_x (VikMapSource * self); guint16 vik_map_source_get_tilesize_y (VikMapSource * self); VikViewportDrawMode vik_map_source_get_drawmode (VikMapSource * self); diff --git a/src/vikmapsourcedefault.c b/src/vikmapsourcedefault.c index 4bd0f1c7..5e0e5702 100644 --- a/src/vikmapsourcedefault.c +++ b/src/vikmapsourcedefault.c @@ -21,6 +21,7 @@ #include "vikenumtypes.h" static guint8 map_source_get_uniq_id (VikMapSource *self); +static const gchar *map_source_get_label (VikMapSource *self); static guint16 map_source_get_tilesize_x (VikMapSource *self); static guint16 map_source_get_tilesize_y (VikMapSource *self); static VikViewportDrawMode map_source_get_drawmode (VikMapSource *self); @@ -29,6 +30,7 @@ typedef struct _VikMapSourceDefaultPrivate VikMapSourceDefaultPrivate; struct _VikMapSourceDefaultPrivate { guint8 uniq_id; + gchar *label; guint16 tilesize_x; guint16 tilesize_y; VikViewportDrawMode drawmode; @@ -42,6 +44,7 @@ enum PROP_0, PROP_ID, + PROP_LABEL, PROP_TILESIZE_X, PROP_TILESIZE_Y, PROP_DRAWMODE, @@ -52,15 +55,22 @@ G_DEFINE_TYPE_EXTENDED (VikMapSourceDefault, vik_map_source_default, VIK_TYPE_MA static void vik_map_source_default_init (VikMapSourceDefault *object) { - /* TODO: Add initialization code here */ + VikMapSourceDefault *self = VIK_MAP_SOURCE_DEFAULT (object); + VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE (self); + + priv->label = NULL; } static void vik_map_source_default_finalize (GObject *object) { - /* TODO: Add deinitalization code here */ + VikMapSourceDefault *self = VIK_MAP_SOURCE_DEFAULT (object); + VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE (self); - G_OBJECT_CLASS (vik_map_source_default_parent_class)->finalize (object); + g_free (priv->label); + priv->label = NULL; + + G_OBJECT_CLASS (vik_map_source_default_parent_class)->finalize (object); } static void @@ -78,6 +88,11 @@ vik_map_source_default_set_property (GObject *object, priv->uniq_id = g_value_get_uint (value); break; + case PROP_LABEL: + g_free (priv->label); + priv->label = g_strdup(g_value_get_string (value)); + break; + case PROP_TILESIZE_X: priv->tilesize_x = g_value_get_uint (value); break; @@ -112,6 +127,10 @@ vik_map_source_default_get_property (GObject *object, g_value_set_uint (value, priv->uniq_id); break; + case PROP_LABEL: + g_value_set_string (value, priv->label); + break; + case PROP_TILESIZE_X: g_value_set_uint (value, priv->tilesize_x); break; @@ -143,6 +162,7 @@ vik_map_source_default_class_init (VikMapSourceDefaultClass *klass) /* Overiding methods */ parent_class->get_uniq_id = map_source_get_uniq_id; + parent_class->get_label = map_source_get_label; parent_class->get_tilesize_x = map_source_get_tilesize_x; parent_class->get_tilesize_y = map_source_get_tilesize_y; parent_class->get_drawmode = map_source_get_drawmode; @@ -156,6 +176,13 @@ vik_map_source_default_class_init (VikMapSourceDefaultClass *klass) G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); g_object_class_install_property (object_class, PROP_ID, pspec); + pspec = g_param_spec_string ("label", + "Label", + "The label of the map source", + "" /* default value */, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + g_object_class_install_property (object_class, PROP_LABEL, pspec); + pspec = g_param_spec_uint ("tilesize-x", "TileSizeX", "Set the size of the tile (x)", @@ -197,6 +224,16 @@ map_source_get_uniq_id (VikMapSource *self) return priv->uniq_id; } +static const gchar * +map_source_get_label (VikMapSource *self) +{ + g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), NULL); + + VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); + + return priv->label; +} + static guint16 map_source_get_tilesize_x (VikMapSource *self) { diff --git a/src/vikmaptype.c b/src/vikmaptype.c index cf7cb3ab..36b964db 100644 --- a/src/vikmaptype.c +++ b/src/vikmaptype.c @@ -30,6 +30,7 @@ static int map_type_download (VikMapSource * self, MapCoord * src, const gchar * typedef struct _VikMapTypePrivate VikMapTypePrivate; struct _VikMapTypePrivate { + gchar *label; VikMapsLayer_MapType map_type; }; @@ -41,22 +42,26 @@ G_DEFINE_TYPE (VikMapType, vik_map_type, VIK_TYPE_MAP_SOURCE); static void vik_map_type_init (VikMapType *object) { - /* TODO: Add initialization code here */ + VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(object); + priv->label = NULL; } VikMapType * -vik_map_type_new_with_id (VikMapsLayer_MapType map_type) +vik_map_type_new_with_id (VikMapsLayer_MapType map_type, const char *label) { VikMapType *ret = (VikMapType *)g_object_new(vik_map_type_get_type(), NULL); VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(ret); priv->map_type = map_type; + priv->label = g_strdup (label); return ret; } static void vik_map_type_finalize (GObject *object) { - /* TODO: Add deinitalization code here */ + VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(object); + g_free (priv->label); + priv->label = NULL; G_OBJECT_CLASS (vik_map_type_parent_class)->finalize (object); } diff --git a/src/vikmaptype.h b/src/vikmaptype.h index d2361087..34c23e24 100644 --- a/src/vikmaptype.h +++ b/src/vikmaptype.h @@ -48,7 +48,7 @@ struct _VikMapType }; GType vik_map_type_get_type (void) G_GNUC_CONST; -VikMapType *vik_map_type_new_with_id (VikMapsLayer_MapType map_type); +VikMapType *vik_map_type_new_with_id (VikMapsLayer_MapType map_type, const char *label); G_END_DECLS diff --git a/src/vikslippymapsource.c b/src/vikslippymapsource.c index f7e46bbe..402eb93e 100644 --- a/src/vikslippymapsource.c +++ b/src/vikslippymapsource.c @@ -296,8 +296,8 @@ _get_download_options( VikSlippyMapSource *self ) } VikSlippyMapSource * -vik_slippy_map_source_new_with_id (guint8 id, const gchar *hostname, const gchar *url) +vik_slippy_map_source_new_with_id (guint8 id, const gchar *label, const gchar *hostname, const gchar *url) { return g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE, - "id", id, "hostname", hostname, "url", url, NULL); + "id", id, "label", label, "hostname", hostname, "url", url, NULL); } \ No newline at end of file diff --git a/src/vikslippymapsource.h b/src/vikslippymapsource.h index 3561b764..a6d7ebf2 100644 --- a/src/vikslippymapsource.h +++ b/src/vikslippymapsource.h @@ -53,7 +53,7 @@ struct _VikSlippyMapSource GType vik_slippy_map_source_get_type (void) G_GNUC_CONST; -VikSlippyMapSource * vik_slippy_map_source_new_with_id (guint8 id, const gchar *hostname, const gchar *url); +VikSlippyMapSource * vik_slippy_map_source_new_with_id (guint8 id, const gchar *label, const gchar *hostname, const gchar *url); gchar * vik_slippy_map_source_get_uri( VikSlippyMapSource *self, MapCoord *src ); gchar * vik_slippy_map_source_get_hostname( VikSlippyMapSource *self ); -- 2.11.4.GIT