From 2eb18edcf50fe75d495725c0142ba2e0665d97a9 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Wed, 6 Aug 2014 00:04:56 +0100 Subject: [PATCH] Add map name property which is used in the directory path of the cache storage. If map name is not specified then fallback to the label name. --- data/maps.xml | 5 +++ doc/examples/maps.xml | 2 ++ help/C/viking.xml | 6 +++- help/viking.xml | 4 +++ src/bingmapsource.c | 1 + src/bluemarble.c | 1 + src/osm.c | 5 +++ src/vikmapslayer.c | 76 ++++++++++++++++++++++++++++++--------- src/vikmapslayer.h | 2 +- src/vikmapsource.c | 14 ++++++++ src/vikmapsource.h | 2 ++ src/vikmapsourcedefault.c | 36 ++++++++++++++++++- src/vikmaptype.c | 13 +++++++ 13 files changed, 147 insertions(+), 20 deletions(-) diff --git a/data/maps.xml b/data/maps.xml index c00e324c..760ae255 100644 --- a/data/maps.xml +++ b/data/maps.xml @@ -5,6 +5,7 @@ tile.openstreetmap.org /%d/%d/%d.png 13 + OSM-Mapnik © OpenStreetMap contributors CC-BY-SA http://www.openstreetmap.org/copyright @@ -17,6 +18,7 @@ b.tile.opencyclemap.org /cycle/%d/%d/%d.png 17 + OSM-Cycle © OpenStreetMap contributors CC-BY-SA http://www.openstreetmap.org/copyright @@ -25,6 +27,7 @@ --> 29 + CalTopo CalTopo USGS 7.5" Topos s3-us-west-1.amazonaws.com /caltopo/topo/%d/%d/%d.png?v=1 @@ -37,6 +40,7 @@ tile.xn--pnvkarte-m4a.de /tilegen/%0d/%d/%d.png 101 + pnvkarte © OpenStreetMap contributors CC-BY-SA http://www.openstreetmap.org/copyright @@ -46,6 +50,7 @@ tiles.openseamap.org /seamark/%d/%d/%d.png 600 + OpenSeaMap © OpenStreetMap contributors CC-BY-SA http://www.openstreetmap.org/copyright diff --git a/doc/examples/maps.xml b/doc/examples/maps.xml index 49f77ace..5cb5449a 100644 --- a/doc/examples/maps.xml +++ b/doc/examples/maps.xml @@ -6,6 +6,7 @@ tile.openstreetmap.org /%d/%d/%d.png 13 + OSM-Mapnik © OpenStreetMap contributors CC-BY-SA http://www.openstreetmap.org/copyright @@ -35,6 +36,7 @@ 60 + ArcGIS ArcGIS World Street Map services.arcgisonline.com /ArcGIS/rest/services/World_Street_Map/MapServer/tile/%d/%d/%d diff --git a/help/C/viking.xml b/help/C/viking.xml index 088a2256..c5fb45f8 100644 --- a/help/C/viking.xml +++ b/help/C/viking.xml @@ -2790,7 +2790,7 @@ Accept: */* You can find more examples in the documentation part of the distribution.
Map Source - It is possible to add new map's sources. The file is ~/.viking/maps.xml for UNIX like systems and C:\Documents and Settings\username\.viking\maps.xml on Windows XP. + It is possible to add new map's sources. The file is ~/.viking/maps.xml for UNIX like systems, C:\Documents and Settings\username\.viking\maps.xml on Windows XP or C:\Users\username\.viking\maps.xml on Windows 7 onwards. An example of the file is in the distribution doc/examples/maps.xml. Further examples and values are online in the Maps Wiki The VikSlippyMapSource allows to declare any map's source working like OpenStreetMap. It supports the following properties: @@ -2799,6 +2799,10 @@ Accept: */* id this is an integer and should be unique as it used to identify the map source + + name + a string (should be unique) that is used for the OSM style cache directory name when the Map Cache directory is the default (~/.viking-maps) + label the text displayed in the map's source selection dialog diff --git a/help/viking.xml b/help/viking.xml index 45682ed7..075fdd9c 100644 --- a/help/viking.xml +++ b/help/viking.xml @@ -195,6 +195,10 @@ and docbook-xsl in your Build-Depends control field. id this is an integer and should be unique as it used to identify the map source + + name + a string (should be unique) that is used for the OSM style cache directory name when the Map Cache directory is the default (~/.viking-maps) + label the text displayed in the map's source selection dialog diff --git a/src/bingmapsource.c b/src/bingmapsource.c index c1cb9335..add04fc2 100644 --- a/src/bingmapsource.c +++ b/src/bingmapsource.c @@ -522,6 +522,7 @@ bing_map_source_new_with_id (guint16 id, const gchar *label, const gchar *key) return g_object_new(BING_TYPE_MAP_SOURCE, "id", id, "label", label, + "name", "Bing-Aerial", "hostname", "ecn.t2.tiles.virtualearth.net", "url", "/tiles/a%s.jpeg?g=587", "api-key", key, diff --git a/src/bluemarble.c b/src/bluemarble.c index 0812e7f2..228622de 100644 --- a/src/bluemarble.c +++ b/src/bluemarble.c @@ -29,6 +29,7 @@ void bluemarble_init () { VikMapSource *bluemarble_type = VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE, "id", 15, + "name", "BlueMarble", "label", "BlueMarble", "hostname", "s3.amazonaws.com", "url", "/com.modestmaps.bluemarble/%d-r%3$d-c%2$d.jpg", diff --git a/src/osm.c b/src/osm.c index 7bc4954b..f957b7ee 100644 --- a/src/osm.c +++ b/src/osm.c @@ -47,6 +47,7 @@ void osm_init () { VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE, "id", 13, "label", "OpenStreetMap (Mapnik)", + "name", "OSM-Mapnik", "hostname", "tile.openstreetmap.org", "url", "/%d/%d/%d.png", "check-file-server-time", FALSE, @@ -59,6 +60,7 @@ void osm_init () { VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE, "id", 17, "label", "OpenStreetMap (Cycle)", + "name", "OSM-Cycle", "hostname", "tile.opencyclemap.org", "url", "/cycle/%d/%d/%d.png", "check-file-server-time", TRUE, @@ -71,6 +73,7 @@ void osm_init () { VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE, "id", 20, "label", "OpenStreetMap (Transport)", + "name", "OSM-Transport", "hostname", "tile2.opencyclemap.org", "url", "/transport/%d/%d/%d.png", "check-file-server-time", TRUE, @@ -82,6 +85,7 @@ void osm_init () { VikMapSource *mapquest_type = VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE, "id", 19, + "name", "OSM-MapQuest", "label", "OpenStreetMap (MapQuest)", "hostname", "otile1.mqcdn.com", "url", "/tiles/1.0.0/osm/%d/%d/%d.png", @@ -94,6 +98,7 @@ void osm_init () { VikMapSource *hot_type = VIK_MAP_SOURCE(g_object_new(VIK_TYPE_SLIPPY_MAP_SOURCE, "id", 22, + "name", "OSM-Humanitarian", "label", "OpenStreetMap (Humanitarian)", "hostname", "c.tile.openstreetmap.fr", "url", "/hot/%d/%d/%d.png", diff --git a/src/vikmapslayer.c b/src/vikmapslayer.c index 2ad4e216..10f53e8d 100644 --- a/src/vikmapslayer.c +++ b/src/vikmapslayer.c @@ -404,6 +404,7 @@ gchar *vik_maps_layer_get_map_label(VikMapsLayer *vml) /****************************************/ #define DIRECTDIRACCESS "%s%d" G_DIR_SEPARATOR_S "%d" G_DIR_SEPARATOR_S "%d%s" +#define DIRECTDIRACCESS_WITH_NAME "%s%s" G_DIR_SEPARATOR_S "%d" G_DIR_SEPARATOR_S "%d" G_DIR_SEPARATOR_S "%d%s" #define DIRSTRUCTURE "%st%ds%dz%d" G_DIR_SEPARATOR_S "%d" G_DIR_SEPARATOR_S "%d" #define MAPS_CACHE_DIR maps_layer_default_dir() @@ -979,11 +980,29 @@ static GdkPixbuf *pixbuf_apply_settings ( GdkPixbuf *pixbuf, VikMapsLayer *vml, return pixbuf; } -static void get_filename ( const gchar *cache_dir, VikMapsCacheLayout cl, gint mode, gint scale, gint z, gint x, gint y, gchar *filename_buf, gint buf_len ) +static void get_filename ( const gchar *cache_dir, + VikMapsCacheLayout cl, + gint mode, + const gchar *name, + gint scale, + gint z, + gint x, + gint y, + gchar *filename_buf, + gint buf_len ) { switch ( cl ) { case VIK_MAPS_CACHE_LAYOUT_OSM: - g_snprintf ( filename_buf, buf_len, DIRECTDIRACCESS, cache_dir, (17 - scale), x, y, ".png" ); + if ( name ) { + if ( g_strcmp0 ( cache_dir, MAPS_CACHE_DIR ) ) + // Cache dir not the default - assume it's been directed somewhere specific + g_snprintf ( filename_buf, buf_len, DIRECTDIRACCESS, cache_dir, (17 - scale), x, y, ".png" ); + else + // Using default cache - so use the map name in the directory path + g_snprintf ( filename_buf, buf_len, DIRECTDIRACCESS_WITH_NAME, cache_dir, name, (17 - scale), x, y, ".png" ); + } + else + g_snprintf ( filename_buf, buf_len, DIRECTDIRACCESS, cache_dir, (17 - scale), x, y, ".png" ); break; default: g_snprintf ( filename_buf, buf_len, DIRSTRUCTURE, cache_dir, mode, scale, z, x, y ); @@ -991,7 +1010,7 @@ static void get_filename ( const gchar *cache_dir, VikMapsCacheLayout cl, gint m } } -static GdkPixbuf *get_pixbuf( VikMapsLayer *vml, gint mode, MapCoord *mapcoord, gchar *filename_buf, gint buf_len, gdouble xshrinkfactor, gdouble yshrinkfactor ) +static GdkPixbuf *get_pixbuf( VikMapsLayer *vml, gint mode, const gchar* mapname, MapCoord *mapcoord, gchar *filename_buf, gint buf_len, gdouble xshrinkfactor, gdouble yshrinkfactor ) { GdkPixbuf *pixbuf; @@ -1009,10 +1028,12 @@ static GdkPixbuf *get_pixbuf( VikMapsLayer *vml, gint mode, MapCoord *mapcoord, return pixbuf; } else - get_filename ( vml->cache_dir, VIK_MAPS_CACHE_LAYOUT_OSM, mode, mapcoord->scale, mapcoord->z, mapcoord->x, mapcoord->y, filename_buf, buf_len ); + get_filename ( vml->cache_dir, VIK_MAPS_CACHE_LAYOUT_OSM, mode, NULL, + mapcoord->scale, mapcoord->z, mapcoord->x, mapcoord->y, filename_buf, buf_len ); } else - get_filename ( vml->cache_dir, vml->cache_layout, mode, mapcoord->scale, mapcoord->z, mapcoord->x, mapcoord->y, filename_buf, buf_len ); + get_filename ( vml->cache_dir, vml->cache_layout, mode, mapname, + mapcoord->scale, mapcoord->z, mapcoord->x, mapcoord->y, filename_buf, buf_len ); if ( g_file_test ( filename_buf, G_FILE_TEST_EXISTS ) == TRUE) { @@ -1121,6 +1142,7 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo gint xmin = MIN(ulm.x, brm.x), xmax = MAX(ulm.x, brm.x); gint ymin = MIN(ulm.y, brm.y), ymax = MAX(ulm.y, brm.y); gint mode = vik_map_source_get_uniq_id(map); + const gchar *mapname = vik_map_source_get_name(map); VikCoord coord; gint xx, yy, width, height; @@ -1153,7 +1175,7 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo for ( y = ymin; y <= ymax; y++ ) { ulm.x = x; ulm.y = y; - pixbuf = get_pixbuf ( vml, mode, &ulm, path_buf, max_path_len, xshrinkfactor, yshrinkfactor ); + pixbuf = get_pixbuf ( vml, mode, mapname, &ulm, path_buf, max_path_len, xshrinkfactor, yshrinkfactor ); if ( pixbuf ) { width = gdk_pixbuf_get_width ( pixbuf ); height = gdk_pixbuf_get_height ( pixbuf ); @@ -1197,9 +1219,11 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo if ( existence_only ) { if ( vik_map_source_is_direct_file_access (MAPS_LAYER_NTH_TYPE(vml->maptype)) ) - get_filename ( vml->cache_dir, VIK_MAPS_CACHE_LAYOUT_OSM, mode, ulm.scale, ulm.z, ulm.x, ulm.y, path_buf, max_path_len ); + get_filename ( vml->cache_dir, VIK_MAPS_CACHE_LAYOUT_OSM, mode, vik_map_source_get_name(map), + ulm.scale, ulm.z, ulm.x, ulm.y, path_buf, max_path_len ); else - get_filename ( vml->cache_dir, vml->cache_layout, mode, ulm.scale, ulm.z, ulm.x, ulm.y, path_buf, max_path_len ); + get_filename ( vml->cache_dir, vml->cache_layout, mode, vik_map_source_get_name(map), + ulm.scale, ulm.z, ulm.x, ulm.y, path_buf, max_path_len ); if ( g_file_test ( path_buf, G_FILE_TEST_EXISTS ) == TRUE ) { GdkGC *black_gc = gtk_widget_get_style(GTK_WIDGET(vvp))->black_gc; @@ -1214,7 +1238,7 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo ulm2.x = ulm.x / scale_factor; ulm2.y = ulm.y / scale_factor; ulm2.scale = ulm.scale + scale_inc; - pixbuf = get_pixbuf ( vml, mode, &ulm2, path_buf, max_path_len, xshrinkfactor * scale_factor, yshrinkfactor * scale_factor ); + pixbuf = get_pixbuf ( vml, mode, mapname, &ulm2, path_buf, max_path_len, xshrinkfactor * scale_factor, yshrinkfactor * scale_factor ); if ( pixbuf ) { gint src_x = (ulm.x % scale_factor) * tilesize_x_ceil; gint src_y = (ulm.y % scale_factor) * tilesize_y_ceil; @@ -1240,7 +1264,7 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo MapCoord ulm3 = ulm2; ulm3.x += pict_x; ulm3.y += pict_y; - pixbuf = get_pixbuf ( vml, mode, &ulm3, path_buf, max_path_len, xshrinkfactor / scale_factor, yshrinkfactor / scale_factor ); + pixbuf = get_pixbuf ( vml, mode, mapname, &ulm3, path_buf, max_path_len, xshrinkfactor / scale_factor, yshrinkfactor / scale_factor ); if ( pixbuf ) { gint src_x = 0; gint src_y = 0; @@ -1352,7 +1376,9 @@ static int map_download_thread ( MapDownloadInfo *mdi, gpointer threaddata ) gboolean remove_mem_cache = FALSE; gboolean need_download = FALSE; - get_filename ( mdi->cache_dir, mdi->cache_layout, vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(mdi->maptype)), + get_filename ( mdi->cache_dir, mdi->cache_layout, + vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(mdi->maptype)), + vik_map_source_get_name(MAPS_LAYER_NTH_TYPE(mdi->maptype)), mdi->mapcoord.scale, mdi->mapcoord.z, x, y, mdi->filename_buf, mdi->maxlen ); donemaps++; @@ -1459,7 +1485,9 @@ static void mdi_cancel_cleanup ( MapDownloadInfo *mdi ) { if ( mdi->mapcoord.x || mdi->mapcoord.y ) { - get_filename ( mdi->cache_dir, mdi->cache_layout, vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(mdi->maptype)), + get_filename ( mdi->cache_dir, mdi->cache_layout, + vik_map_source_get_uniq_id(MAPS_LAYER_NTH_TYPE(mdi->maptype)), + vik_map_source_get_name(MAPS_LAYER_NTH_TYPE(mdi->maptype)), mdi->mapcoord.scale, mdi->mapcoord.z, mdi->mapcoord.x, mdi->mapcoord.y, mdi->filename_buf, mdi->maxlen ); if ( g_file_test ( mdi->filename_buf, G_FILE_TEST_EXISTS ) == TRUE) { @@ -1516,7 +1544,9 @@ static void start_download_thread ( VikMapsLayer *vml, VikViewport *vvp, const V { for ( b = mdi->y0; b <= mdi->yf; b++ ) { - get_filename ( mdi->cache_dir, mdi->cache_layout, vik_map_source_get_uniq_id(map), + get_filename ( mdi->cache_dir, mdi->cache_layout, + vik_map_source_get_uniq_id(map), + vik_map_source_get_name(map), ulm.scale, ulm.z, a, b, mdi->filename_buf, mdi->maxlen ); if ( g_file_test ( mdi->filename_buf, G_FILE_TEST_EXISTS ) == FALSE ) mdi->mapstoget++; @@ -1602,7 +1632,9 @@ static void maps_layer_download_section ( VikMapsLayer *vml, VikViewport *vvp, V for (i = mdi->x0; i <= mdi->xf; i++) { for (j = mdi->y0; j <= mdi->yf; j++) { - get_filename ( mdi->cache_dir, mdi->cache_layout, vik_map_source_get_uniq_id(map), + get_filename ( mdi->cache_dir, mdi->cache_layout, + vik_map_source_get_uniq_id(map), + vik_map_source_get_name(map), ulm.scale, ulm.z, i, j, mdi->filename_buf, mdi->maxlen ); if ( g_file_test ( mdi->filename_buf, G_FILE_TEST_EXISTS ) == FALSE ) mdi->mapstoget++; @@ -1710,14 +1742,22 @@ static void maps_layer_tile_info ( VikMapsLayer *vml ) #endif } else { - filename = g_strdup_printf ( DIRECTDIRACCESS, vml->cache_dir, ulm.scale, ulm.x, ulm.y, ".png" ); + guint max_path_len = strlen(vml->cache_dir) + 40; + filename = g_malloc ( max_path_len * sizeof(char) ); + get_filename ( vml->cache_dir, VIK_MAPS_CACHE_LAYOUT_OSM, + vik_map_source_get_uniq_id(map), + NULL, + ulm.scale, ulm.z, ulm.x, ulm.y, filename, max_path_len ); source = g_strconcat ( "file://", filename, NULL ); } } else { guint max_path_len = strlen(vml->cache_dir) + 40; filename = g_malloc ( max_path_len * sizeof(char) ); - get_filename ( vml->cache_dir, vml->cache_layout, vik_map_source_get_uniq_id(map), ulm.scale, ulm.z, ulm.x, ulm.y, filename, max_path_len ); + get_filename ( vml->cache_dir, vml->cache_layout, + vik_map_source_get_uniq_id(map), + vik_map_source_get_name(map), + ulm.scale, ulm.z, ulm.x, ulm.y, filename, max_path_len ); source = g_strdup_printf ( "http://%s%s", vik_map_source_default_get_hostname ( VIK_MAP_SOURCE_DEFAULT(map) ), vik_map_source_default_get_uri ( VIK_MAP_SOURCE_DEFAULT(map), &ulm ) ); @@ -1937,7 +1977,9 @@ static gint maps_layer_how_many_maps ( VikMapsLayer *vml, VikViewport *vvp, VikC /* calculate how many we need */ for (i = mdi->x0; i <= mdi->xf; i++) { for (j = mdi->y0; j <= mdi->yf; j++) { - get_filename ( mdi->cache_dir, mdi->cache_layout, vik_map_source_get_uniq_id(map), + get_filename ( mdi->cache_dir, mdi->cache_layout, + vik_map_source_get_uniq_id(map), + vik_map_source_get_name(map), ulm.scale, ulm.z, i, j, mdi->filename_buf, mdi->maxlen ); if ( mdi->redownload == REDOWNLOAD_NEW ) { // Assume the worst - always a new file diff --git a/src/vikmapslayer.h b/src/vikmapslayer.h index 0bba94b3..15a569fa 100644 --- a/src/vikmapslayer.h +++ b/src/vikmapslayer.h @@ -49,7 +49,7 @@ typedef struct _VikMapsLayer VikMapsLayer; typedef enum { VIK_MAPS_CACHE_LAYOUT_VIKING=0, // CacheDir/tsz0/X/Y (NB no file extension) - Legacy default layout - VIK_MAPS_CACHE_LAYOUT_OSM, // CacheDir/OSMZoomLevel/X/Y.ext (Default ext=png) + VIK_MAPS_CACHE_LAYOUT_OSM, // CacheDir//OSMZoomLevel/X/Y.ext (Default ext=png) VIK_MAPS_CACHE_LAYOUT_NUM // Last enum } VikMapsCacheLayout; diff --git a/src/vikmapsource.c b/src/vikmapsource.c index 7d4cc97c..4add3a6a 100644 --- a/src/vikmapsource.c +++ b/src/vikmapsource.c @@ -65,6 +65,7 @@ vik_map_source_class_init (VikMapSourceClass *klass) klass->get_license = NULL; klass->get_license_url = NULL; klass->get_logo = NULL; + klass->get_name = NULL; klass->get_uniq_id = NULL; klass->get_label = NULL; klass->get_tilesize_x = NULL; @@ -151,6 +152,19 @@ vik_map_source_get_logo (VikMapSource *self) return (*klass->get_logo)(self); } +const gchar * +vik_map_source_get_name (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_name != NULL, NULL); + + return (*klass->get_name)(self); +} + guint16 vik_map_source_get_uniq_id (VikMapSource *self) { diff --git a/src/vikmapsource.h b/src/vikmapsource.h index a0342919..fdab3009 100644 --- a/src/vikmapsource.h +++ b/src/vikmapsource.h @@ -49,6 +49,7 @@ struct _VikMapSourceClass const gchar *(* get_license_url) (VikMapSource * self); const GdkPixbuf *(* get_logo) (VikMapSource * self); + const gchar *(* get_name) (VikMapSource * self); guint16 (* get_uniq_id) (VikMapSource * self); const gchar * (* get_label) (VikMapSource * self); guint16 (* get_tilesize_x) (VikMapSource * self); @@ -76,6 +77,7 @@ const gchar *vik_map_source_get_license (VikMapSource * self); const gchar *vik_map_source_get_license_url (VikMapSource * self); const GdkPixbuf *vik_map_source_get_logo (VikMapSource * self); +const gchar *vik_map_source_get_name (VikMapSource * self); guint16 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); diff --git a/src/vikmapsourcedefault.c b/src/vikmapsourcedefault.c index a4ac7b9e..d08f82a3 100644 --- a/src/vikmapsourcedefault.c +++ b/src/vikmapsourcedefault.c @@ -35,6 +35,7 @@ static const gchar *map_source_get_license (VikMapSource *self); static const gchar *map_source_get_license_url (VikMapSource *self); static const GdkPixbuf *map_source_get_logo (VikMapSource *self); +static const gchar *map_source_get_name (VikMapSource *self); static guint16 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); @@ -54,6 +55,7 @@ struct _VikMapSourceDefaultPrivate gchar *license_url; GdkPixbuf *logo; + gchar *name; guint16 uniq_id; gchar *label; guint16 tilesize_x; @@ -68,6 +70,7 @@ enum { PROP_0, + PROP_NAME, PROP_ID, PROP_LABEL, PROP_TILESIZE_X, @@ -91,6 +94,7 @@ vik_map_source_default_init (VikMapSourceDefault *object) priv->license = NULL; priv->license_url = NULL; priv->logo = NULL; + priv->name = NULL; } static void @@ -109,7 +113,9 @@ vik_map_source_default_finalize (GObject *object) priv->license_url = NULL; g_free (priv->logo); priv->license_url = NULL; - + g_free (priv->name); + priv->name = NULL; + G_OBJECT_CLASS (vik_map_source_default_parent_class)->finalize (object); } @@ -124,6 +130,14 @@ vik_map_source_default_set_property (GObject *object, switch (property_id) { + case PROP_NAME: + // Sanitize the name here for file usage + // A simple check just to prevent containing slashes ATM + g_free (priv->name); + priv->name = g_strdup(g_value_get_string (value)); + g_strdelimit (priv->name, "\\/", 'x' ); + break; + case PROP_ID: priv->uniq_id = g_value_get_uint (value); break; @@ -178,6 +192,10 @@ vik_map_source_default_get_property (GObject *object, switch (property_id) { + case PROP_NAME: + g_value_set_string (value, priv->name); + break; + case PROP_ID: g_value_set_uint (value, priv->uniq_id); break; @@ -232,6 +250,7 @@ vik_map_source_default_class_init (VikMapSourceDefaultClass *klass) parent_class->get_license = map_source_get_license; parent_class->get_license_url = map_source_get_license_url; parent_class->get_logo = map_source_get_logo; + parent_class->get_name = map_source_get_name; 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; @@ -246,6 +265,13 @@ vik_map_source_default_class_init (VikMapSourceDefaultClass *klass) klass->get_hostname = NULL; klass->get_download_options = NULL; + pspec = g_param_spec_string ("name", + "Name", + "The name of the map that may be used as the file cache directory", + "Unknown" /* default value */, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + g_object_class_install_property (object_class, PROP_NAME, pspec); + pspec = g_param_spec_uint ("id", "Id of the tool", "Set the id", @@ -359,6 +385,14 @@ map_source_get_logo (VikMapSource *self) return priv->logo; } +static const gchar * +map_source_get_name (VikMapSource *self) +{ + g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), NULL); + VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); + return priv->name; +} + static guint16 map_source_get_uniq_id (VikMapSource *self) { diff --git a/src/vikmaptype.c b/src/vikmaptype.c index fecd9d2c..ae3b8894 100644 --- a/src/vikmaptype.c +++ b/src/vikmaptype.c @@ -33,6 +33,7 @@ #include "vikmapslayer_compat.h" #include "download.h" +static const gchar *map_type_get_name (VikMapSource *self); static guint16 map_type_get_uniq_id (VikMapSource *self); static const gchar *map_type_get_label (VikMapSource *self); static guint16 map_type_get_tilesize_x (VikMapSource *self); @@ -48,6 +49,7 @@ typedef struct _VikMapTypePrivate VikMapTypePrivate; struct _VikMapTypePrivate { gchar *label; + gchar *name; VikMapsLayer_MapType map_type; }; @@ -61,6 +63,7 @@ vik_map_type_init (VikMapType *object) { VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(object); priv->label = NULL; + priv->name = NULL; } VikMapType * @@ -90,6 +93,7 @@ vik_map_type_class_init (VikMapTypeClass *klass) VikMapSourceClass* parent_class = VIK_MAP_SOURCE_CLASS (klass); /* Overiding methods */ + parent_class->get_name = map_type_get_name; parent_class->get_uniq_id = map_type_get_uniq_id; parent_class->get_label = map_type_get_label; parent_class->get_tilesize_x = map_type_get_tilesize_x; @@ -106,6 +110,15 @@ vik_map_type_class_init (VikMapTypeClass *klass) object_class->finalize = vik_map_type_finalize; } +static const gchar * +map_type_get_name (VikMapSource *self) +{ + VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); + g_return_val_if_fail (priv != NULL, NULL); + + return priv->name; +} + static guint16 map_type_get_uniq_id (VikMapSource *self) { -- 2.39.5