]> err.no Git - mapper/blobdiff - src/map-download.c
Path: misc adjustments
[mapper] / src / map-download.c
index 32cdd1a29a4bef6806897d265950b233dbbc466a..d1505403cd0e93684d2bd72a6eb7f8d120cda9be 100644 (file)
@@ -43,7 +43,6 @@
 #include "hildon-mapper.h"
 
 #include "utils.h"
-#include "map.h"
 #include "osm.h"
 #include "db.h"
 #include "osm-db.h"
 #include "ui-common.h"
 #include "settings.h"
 #include "latlon.h"
-#include "gpx.h"
 #include "map-download.h"
 #include "iap.h"
 #include "map-repo.h"
+#include "gtkmap.h"
 
 static guint _num_downloads=0;
 static guint _curr_download=0;
@@ -131,12 +130,11 @@ while (_curl_multi && (msg = curl_multi_info_read(_curl_multi, &num_msgs))) {
                if (msg->easy_handle == _autoroute_data.curl_easy) {
                        /* This is the autoroute download. */
                        /* Now, parse the autoroute and update the display. */
-                       if (_autoroute_data.enabled && parse_gpx(&_route, _autoroute_data.rdl_data.bytes, _autoroute_data.rdl_data.bytes_read, 0)) {
+                       if (_autoroute_data.enabled && path_gpx_parse(_route, _autoroute_data.rdl_data.bytes, _autoroute_data.rdl_data.bytes_read, 0)) {
                                /* Find the nearest route point, if we're connected. */
-                               route_find_nearest_point();
-                               map_force_redraw();
+                               path_find_nearest_point(_route, _gps->data.lat, _gps->data.lon);
                        }
-                       route_cancel_autoroute(TRUE);   /* We're done. Clean up. */
+                       route_cancel_autoroute(_route, TRUE);   /* We're done. Clean up. */
                } else {
                        ProgressUpdateInfo *pui = g_hash_table_lookup(pui_by_easy, msg->easy_handle);
                        g_queue_push_head(curl_easy_queue, msg->easy_handle);
@@ -201,11 +199,6 @@ while (num_transfers < (4*4) && g_tree_nnodes(pui_tree)) {
                        curl_easy_setopt(curl_easy, CURLOPT_URL, pui->src_str);
                        curl_easy_setopt(curl_easy, CURLOPT_WRITEDATA, f);
                        g_hash_table_insert(pui_by_easy, curl_easy, pui);
-                       if (!_curl_multi) {
-                               /* Initialize CURL. */
-                               _curl_multi = curl_multi_init();
-                               /*curl_multi_setopt(_curl_multi, CURLMOPT_PIPELINING, 1); */
-                       }
                        curl_multi_add_handle(_curl_multi, curl_easy);
                        num_transfers++;
                } else {
@@ -237,9 +230,6 @@ if (!(num_transfers || g_tree_nnodes(pui_tree))) {
                while ((curr = g_queue_pop_tail(curl_easy_queue)))
                        curl_easy_cleanup(curr);
 
-               curl_multi_cleanup(_curl_multi);
-               _curl_multi = NULL;
-
                _curl_sid = 0;
                return FALSE;
        }
@@ -249,11 +239,15 @@ if (!(num_transfers || g_tree_nnodes(pui_tree))) {
 return TRUE;
 }
 
+#ifdef MAP_DOWNLOAD_WMS
 /**
  * Given a wms uri pattern, compute the coordinate transformation and
  * trimming.
  * 'proj' is used for the conversion
  */
+
+#define WMS_TILE_SIZE_PIXELS (256)
+
 static gchar *
 map_convert_wms_to_wms(gint tilex, gint tiley, gint zoomlevel, gchar * uri)
 {
@@ -275,14 +269,14 @@ strncpy(srs + 4, srsstr + 8, 256);
 srs[srsstre - srsstr - 4] = 0;
 /* convert to lower, as WMC is EPSG and cs2cs is epsg */
 
-gint dwidth = widthstr ? atoi(widthstr + 6) - TILE_SIZE_PIXELS : 0;
-gint dheight = heightstr ? atoi(heightstr + 7) - TILE_SIZE_PIXELS : 0;
+gint dwidth = widthstr ? atoi(widthstr + 6) - WMS_TILE_SIZE_PIXELS : 0;
+gint dheight = heightstr ? atoi(heightstr + 7) - WMS_TILE_SIZE_PIXELS : 0;
 
 unit2latlon(tile2zunit(tilex, zoomlevel) - pixel2zunit(dwidth / 2, zoomlevel),
-           tile2zunit(tiley + 1, zoomlevel) + pixel2zunit((dheight + 1) / 2, zoomlevel), lat1, lon1);
+           tile2zunit(tiley + 1, zoomlevel) + pixel2zunit((dheight + 1) / 2, zoomlevel), &lat1, &lon1);
 
 unit2latlon(tile2zunit(tilex + 1, zoomlevel) + pixel2zunit((dwidth + 1) / 2, zoomlevel), 
-               tile2zunit(tiley, zoomlevel) - pixel2zunit(dheight / 2, zoomlevel), lat2, lon2);
+               tile2zunit(tiley, zoomlevel) - pixel2zunit(dheight / 2, zoomlevel), &lat2, &lon2);
 
 setlocale(LC_NUMERIC, "C");
 
@@ -309,7 +303,7 @@ setlocale(LC_NUMERIC, "");
 
 return ret;
 }
-
+#endif
 
 /**
  * Given the xyz coordinates of our map coordinate system, write the qrst
@@ -346,28 +340,23 @@ map_construct_url(guint tilex, guint tiley, guint zoom)
 switch (_curr_repo->type) {
 case REPOTYPE_XYZ:
        return g_strdup_printf(_curr_repo->url, tilex, tiley, zoom);
-
 case REPOTYPE_XYZ_INV:
        return g_strdup_printf(_curr_repo->url, 17 - zoom, tilex, tiley);
-
-case REPOTYPE_QUAD_QRST:
-       {
-               gchar location[MAX_ZOOM + 2];
+case REPOTYPE_QUAD_QRST: {
+               gchar location[32];
                map_convert_coords_to_quadtree_string(tilex, tiley, zoom, location, 't', "qrts");
                return g_strdup_printf(_curr_repo->url, location);
        }
-
-case REPOTYPE_QUAD_ZERO:
-       {
+case REPOTYPE_QUAD_ZERO: {
                /* This is a zero-based quadtree URI. */
-               gchar location[MAX_ZOOM + 2];
+               gchar location[32];
                map_convert_coords_to_quadtree_string(tilex, tiley, zoom, location, '\0', "0123");
                return g_strdup_printf(_curr_repo->url, location);
        }
-
+#ifdef MAP_DOWNLOAD_WMD
 case REPOTYPE_WMS:
        return map_convert_wms_to_wms(tilex, tiley, zoom, _curr_repo->url);
-
+#endif
 default:
        return NULL;
 }
@@ -396,10 +385,12 @@ gtk_progress_bar_set_fraction(_progress_item, currd/(double)numd);
 gboolean 
 map_download_idle_refresh(ProgressUpdateInfo * pui)
 {
+guint tmp=0;
 /* Test if download succeeded (only if retries != 0). */
 if (!pui->retries || g_file_test(pui->dest_str, G_FILE_TEST_EXISTS)) {
-       gint zoom_diff = pui->zoom - _zoom;
+       gint zoom_diff = pui->zoom - gtk_map_get_zoom(_map);
 
+#if 0
        /* Only refresh at same or "lower" (more detailed) zoom level. */
        if (zoom_diff >= 0) {
                guint tilex, tiley, tilex_end, tiley_end;
@@ -408,7 +399,7 @@ if (!pui->retries || g_file_test(pui->dest_str, G_FILE_TEST_EXISTS)) {
                 * this tile, then we may have to update more than one tile. */
                for (tilex = pui->tilex << zoom_diff, tilex_end = tilex + (1 << zoom_diff); tilex < tilex_end; tilex++) {
                        for (tiley = pui->tiley << zoom_diff, tiley_end = tiley + (1 << zoom_diff); tiley < tiley_end; tiley++) {
-                               g_debug("MDIR: %d %d", tilex, tiley);
+                               tmp++;
                                if (map_render_tile(tilex, tiley, ((tilex - _base_tilex) << TILE_SIZE_P2), ((tiley - _base_tiley) << TILE_SIZE_P2), TRUE)==TRUE) {
                                        map_render_data();
                                        gtk_widget_queue_draw_area(_map_widget,
@@ -418,7 +409,11 @@ if (!pui->retries || g_file_test(pui->dest_str, G_FILE_TEST_EXISTS)) {
                                }
                        }
                }
+       g_debug("*** MDIR LOOP: %u", tmp);
        }
+#else
+       g_debug("XXX: Add cb or signal or something to inform map widget about fresh tile");
+#endif
 }
 /* Else the download failed. Update retries and maybe try again. */
 else {
@@ -469,7 +464,7 @@ pui = g_slice_new(ProgressUpdateInfo);
 pui->tilex = tilex;
 pui->tiley = tiley;
 pui->zoom = zoom;
-pui->priority = (abs((gint) tilex - unit2tile(_center.unitx)) + abs((gint) tiley - unit2tile(_center.unity)));
+pui->priority = 1;
 if (!retries)
        pui->priority = -pui->priority; /* "Negative" makes them lowest pri. */
 pui->retries = retries;
@@ -499,6 +494,8 @@ curl_easy_queue = g_queue_new();
 pui_tree = g_tree_new_full((GCompareDataFunc)download_comparefunc, NULL, (GDestroyNotify) progress_update_info_free, NULL);
 downloading_tree = g_tree_new_full((GCompareDataFunc)download_comparefunc, NULL, (GDestroyNotify) progress_update_info_free, NULL);
 pui_by_easy = g_hash_table_new(g_direct_hash, g_direct_equal);
+_curl_multi = curl_multi_init();
+/* curl_multi_setopt(_curl_multi, CURLMOPT_PIPELINING, 1); */
 }
 
 gboolean
@@ -522,7 +519,8 @@ if (_curl_multi) {
                        ProgressUpdateInfo *pui = g_hash_table_lookup(pui_by_easy, msg->easy_handle);
                        g_queue_push_head(curl_easy_queue, msg->easy_handle);
                        g_hash_table_remove(pui_by_easy, msg->easy_handle);
-                       fclose(pui->file);
+                       if (pui->file)
+                               fclose(pui->file);
                        curl_multi_remove_handle(_curl_multi, msg->easy_handle);
                }
        }
@@ -530,8 +528,6 @@ if (_curl_multi) {
        g_debug("Stopping downloads");
        while ((curr = g_queue_pop_tail(curl_easy_queue)))
                curl_easy_cleanup(curr);
-       curl_multi_cleanup(_curl_multi);
-       _curl_multi = NULL;
        return TRUE;
 }
 g_debug("No downloads to stop");
@@ -564,6 +560,8 @@ if (_curl_multi) {
                g_hash_table_destroy(pui_by_easy);
        if (curl_easy_queue)
                g_queue_free(curl_easy_queue);
+       curl_multi_cleanup(_curl_multi);
+       _curl_multi = NULL;
 }
 
 if (_curl_sid) {