]> git.street.me.uk Git - andy/viking.git/commitdiff
Fix URL display of Map tiles
authorRob Norris <rw_norris@hotmail.com>
Fri, 17 Feb 2017 22:27:24 +0000 (22:27 +0000)
committerRob Norris <rw_norris@hotmail.com>
Mon, 27 Feb 2017 23:25:41 +0000 (23:25 +0000)
Use function to create map tile URL since hostname field may or may not
include either http or https.

src/vikmapslayer.c
src/vikmapsourcedefault.c
src/vikmapsourcedefault.h

index 0d0bba25a0ad75d851afa47ab7c64ff56ea3b484..f3900fadeb00a02a9285d6c3fbc3d08d821d1dc8 100644 (file)
@@ -1984,9 +1984,9 @@ static void maps_layer_tile_info ( VikMapsLayer *vml )
                    vik_map_source_get_name(map),
                    ulm.scale, ulm.z, ulm.x, ulm.y, filename, max_path_len,
                    vik_map_source_get_file_extension(map) );
-    source = g_markup_printf_escaped ( "Source: 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 ) );
+    gchar *url = vik_map_source_default_get_url_display ( VIK_MAP_SOURCE_DEFAULT(map), &ulm );
+    source = g_markup_printf_escaped ( _("Source: %s"), url );
+    g_free ( url );
   }
 
   GArray *array = g_array_new (FALSE, TRUE, sizeof(gchar*));
index e5e4611fed27f721bcce1ea553fb91889ff8db71..178a1338d16533d663500677347e486857d82427 100644 (file)
@@ -29,6 +29,7 @@
 #include "vikmapsourcedefault.h"
 #include "vikenumtypes.h"
 #include "download.h"
+#include "string.h"
 
 static void map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data);
 static const gchar *map_source_get_license (VikMapSource *self);
@@ -533,3 +534,40 @@ vik_map_source_default_get_download_options( VikMapSourceDefault *self )
 
        return (*klass->get_download_options)(self);
 }
+
+gchar *
+vik_map_source_default_get_url_display( VikMapSourceDefault *self, MapCoord *src )
+{
+       VikMapSourceDefaultClass *klass;
+       g_return_val_if_fail (self != NULL, 0);
+       g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT (self), 0);
+       klass = VIK_MAP_SOURCE_DEFAULT_GET_CLASS(self);
+
+       g_return_val_if_fail (klass->get_uri != NULL, 0);
+       g_return_val_if_fail (klass->get_hostname != NULL, 0);
+
+       gchar *newstr = NULL;
+       gchar *hostname = (*klass->get_hostname)(self);
+       gchar *url = (*klass->get_uri)(self, src);
+       if ( hostname && strlen(hostname)>1 ) {
+               if ( strstr (hostname, "://") == NULL ) {
+                       //prepend http
+                       newstr = g_strdup_printf ( "http://%s", hostname );
+               }
+               else {
+                       newstr = g_strdup ( hostname );
+               }
+       }
+       if ( url && strlen(url)>1 ) {
+               if ( newstr ) {
+                       gchar *tmp = g_strdup ( newstr );
+                       newstr = g_strdup_printf ( "%s%s", newstr, url );
+                       g_free ( tmp );
+               }
+               else {
+                       newstr = g_strdup ( url );
+               }
+       }
+
+       return newstr;
+}
index f1eafcb8915c84ba4acb86790e04ac977297ef67..bcab546435e25212712b84aa9de98eb98a6917ce 100644 (file)
@@ -55,6 +55,7 @@ GType vik_map_source_default_get_type (void) G_GNUC_CONST;
 gchar * vik_map_source_default_get_uri( VikMapSourceDefault *self, MapCoord *src );
 gchar * vik_map_source_default_get_hostname( VikMapSourceDefault *self );
 DownloadFileOptions * vik_map_source_default_get_download_options( VikMapSourceDefault *self );
+gchar * vik_map_source_default_get_url_display( VikMapSourceDefault *self, MapCoord *src );
 
 G_END_DECLS