]> git.street.me.uk Git - andy/viking.git/blobdiff - src/bingmapsource.c
Add settings to override bfilter simplify and compress default values.
[andy/viking.git] / src / bingmapsource.c
index 7a3887ad4e2a2458f1ef7a4910bed6471401d0ee..c999ac754aa6f6215246c1bcae432dc72a41bbf9 100644 (file)
@@ -79,6 +79,7 @@ struct _BingMapSourcePrivate
        GList *attributions;
        /* Current attribution, when parsing */
        gchar *attribution;
+       gboolean loading_attributions;
 };
 
 /* The pixbuf to store the logo */
@@ -109,6 +110,7 @@ bing_map_source_init (BingMapSource *self)
        priv->api_key = NULL;
        priv->attributions = NULL;
        priv->attribution = NULL;
+       priv->loading_attributions = FALSE;
 }
 
 static void
@@ -297,7 +299,11 @@ _get_copyright(VikMapSource * self, LatLonBBox bbox, gdouble zoom, void (*fct)(V
        /* Loop over all known attributions */
        GList *attribution = priv->attributions;
        if (attribution == NULL && g_strcmp0 ("<no-set>", priv->api_key)) {
-               _async_load_attributions (BING_MAP_SOURCE (self));
+               if ( ! priv->loading_attributions )
+                       _async_load_attributions (BING_MAP_SOURCE (self));
+               else
+                       // Wait until attributions loaded before processing them
+                       return;
        }
        while (attribution != NULL) {
                struct _Attribution *current = (struct _Attribution*)attribution->data;
@@ -351,25 +357,29 @@ btext (GMarkupParseContext *context,
        int len = g_slist_length ((GSList *)stack);
 
        const gchar *parent = len > 1 ? g_slist_nth_data ((GSList *)stack, 1) : NULL;
-       
        if (strcmp (element, "Attribution") == 0) {
                g_free (priv->attribution);
                priv->attribution = g_strdup (textl);
-       } else if (parent != NULL && strcmp (parent, "CoverageArea") == 0) {
-               if (strcmp (element, "ZoomMin") == 0) {
-                       attribution->minZoom = atoi (textl);
-               } else if (strcmp (element, "ZoomMax") == 0) {
-                       attribution->maxZoom = atoi (textl);
-               }
-       } else if (parent != NULL && strcmp (parent, "BoundingBox") == 0) {
-               if (strcmp (element, "SouthLatitude") == 0) {
-                       attribution->bounds.south = g_ascii_strtod (textl, NULL);
-               } else if (strcmp (element, "WestLongitude") == 0) {
-                       attribution->bounds.west = g_ascii_strtod (textl, NULL);
-               } else if (strcmp (element, "NorthLatitude") == 0) {
-                       attribution->bounds.north = g_ascii_strtod (textl, NULL);
-               } else if (strcmp (element, "EastLongitude") == 0) {
-                       attribution->bounds.east = g_ascii_strtod (textl, NULL);
+       }
+       else {
+               if ( attribution ) {
+                       if (parent != NULL && strcmp (parent, "CoverageArea") == 0) {
+                               if (strcmp (element, "ZoomMin") == 0) {
+                                       attribution->minZoom = atoi (textl);
+                               } else if (strcmp (element, "ZoomMax") == 0) {
+                                       attribution->maxZoom = atoi (textl);
+                               }
+                       } else if (parent != NULL && strcmp (parent, "BoundingBox") == 0) {
+                               if (strcmp (element, "SouthLatitude") == 0) {
+                                       attribution->bounds.south = g_ascii_strtod (textl, NULL);
+                               } else if (strcmp (element, "WestLongitude") == 0) {
+                                       attribution->bounds.west = g_ascii_strtod (textl, NULL);
+                               } else if (strcmp (element, "NorthLatitude") == 0) {
+                                       attribution->bounds.north = g_ascii_strtod (textl, NULL);
+                               } else if (strcmp (element, "EastLongitude") == 0) {
+                                       attribution->bounds.east = g_ascii_strtod (textl, NULL);
+                               }
+                       }
                }
        }
        g_free(textl);
@@ -454,17 +464,21 @@ _load_attributions ( BingMapSource *self )
        gchar *uri = g_strdup_printf(URL_ATTR_FMT, priv->api_key);
 
        gchar *tmpname = a_download_uri_to_tmp_file ( uri, vik_map_source_default_get_download_options(VIK_MAP_SOURCE_DEFAULT(self)) );
+       if ( !tmpname ) {
+               ret = -1;
+               goto done;
+       }
 
        g_debug("%s: %s", __FUNCTION__, tmpname);
        if (!_parse_file_for_attributions(self, tmpname)) {
                ret = -1;
-               goto done;
        }
 
+       (void)g_remove(tmpname);
+       g_free(tmpname);
 done:
+       priv->loading_attributions = FALSE;
        g_free(uri);
-       g_remove(tmpname);
-       g_free(tmpname);
        return ret;
 }