]> err.no Git - mapper/commitdiff
Misc cleanups
authorKaj-Michael Lang <milang@onion.tal.org>
Wed, 17 Oct 2007 07:52:07 +0000 (10:52 +0300)
committerKaj-Michael Lang <milang@onion.tal.org>
Wed, 17 Oct 2007 07:52:07 +0000 (10:52 +0300)
src/map-download.c

index 9703861f8b27a9e83a5f47b845084d8763779bd8..14763497e61e2e78881bbd36def100226422bb15 100644 (file)
@@ -35,8 +35,8 @@
 #include "gpx.h"
 #include "map-download.h"
 
-guint _num_downloads=0;
-guint _curr_download=0;
+static guint _num_downloads=0;
+static guint _curr_download=0;
 
 static gchar *map_construct_url(guint tilex, guint tiley, guint zoom);
 
@@ -75,8 +75,7 @@ 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,
+                       if (_autoroute_data.enabled && parse_gpx(&_route,
                                         _autoroute_data.rdl_data.bytes,
                                         _autoroute_data.rdl_data.bytes_read, 0)) {
                                /* Find the nearest route point, if we're connected. */
@@ -92,8 +91,7 @@ while (_curl_multi && (msg = curl_multi_info_read(_curl_multi, &num_msgs))) {
                        if (msg->data.result != CURLE_OK)
                                g_unlink(pui->dest_str);        /* Delete so we try again. */
                        curl_multi_remove_handle(_curl_multi, msg->easy_handle);
-                       g_idle_add_full(G_PRIORITY_HIGH_IDLE,
-                                       (GSourceFunc)map_download_idle_refresh, pui, NULL);
+                       g_idle_add_full(G_PRIORITY_HIGH_IDLE, (GSourceFunc)map_download_idle_refresh, pui, NULL);
                }
        }
 }
@@ -124,15 +122,13 @@ while (num_transfers < (BUF_WIDTH_TILES * BUF_HEIGHT_TILES) && g_tree_nnodes(_pu
                if (pui->retries > 0) {
                        /* We're not updating - check if file already exists. */
                        if (g_file_test(pui->dest_str, G_FILE_TEST_EXISTS)) {
-                               g_idle_add_full(G_PRIORITY_HIGH_IDLE,
-                                               (GSourceFunc)map_download_idle_refresh, pui, NULL);
+                               g_idle_add_full(G_PRIORITY_HIGH_IDLE, (GSourceFunc)map_download_idle_refresh, pui, NULL);
                                continue;
                        }
                }
 
                /* Attempt to open the file for writing. */
-               if (!(f = g_fopen(pui->dest_str, "w"))
-                   && errno == ENOENT) {
+               if (!(f = g_fopen(pui->dest_str, "w")) && errno == ENOENT) {
                        /* Directory doesn't exist yet - create it, then we'll retry */
                        gchar buffer[BUFFER_SIZE];
                        snprintf(buffer, sizeof(buffer), "%s/%u/%u",
@@ -160,15 +156,13 @@ while (num_transfers < (BUF_WIDTH_TILES * BUF_HEIGHT_TILES) && g_tree_nnodes(_pu
                        curl_multi_add_handle(_curl_multi, curl_easy);
                        num_transfers++;
                } else {
-                       /* Unable to download file. */
+                       /* Unable to open tile file for writing. */
                        gchar buffer[BUFFER_SIZE];
                        snprintf(buffer, sizeof(buffer), "%s:\n%s",
                                 _("Failed to open file for writing"),
                                 pui->dest_str);
                        MACRO_BANNER_SHOW_INFO(_window, buffer);
-                       g_idle_add_full(G_PRIORITY_HIGH_IDLE,
-                                       (GSourceFunc)map_download_idle_refresh, pui,
-                                       NULL);
+                       g_idle_add_full(G_PRIORITY_HIGH_IDLE, (GSourceFunc)map_download_idle_refresh, pui, NULL);
                        continue;
                }
        } else if (--deletes_left) {
@@ -178,12 +172,10 @@ while (num_transfers < (BUF_WIDTH_TILES * BUF_HEIGHT_TILES) && g_tree_nnodes(_pu
                g_tree_insert(_downloading_tree, pui, pui);
 
                snprintf(buffer, sizeof(buffer), "%s/%u/%u/%u.jpg",
-                        pui->repo->cache_dir, pui->zoom, pui->tilex,
-                        pui->tiley);
+                       pui->repo->cache_dir, pui->zoom, 
+                       pui->tilex,     pui->tiley);
                g_unlink(buffer);
-               g_idle_add_full(G_PRIORITY_HIGH_IDLE,
-                               (GSourceFunc)map_download_idle_refresh,
-                               pui, NULL);
+               g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_download_idle_refresh, pui, NULL);
        } else
                break;
 }
@@ -257,12 +249,10 @@ vprintf("Running command: %s\n", cmd);
 system_retcode = system(cmd);
 
 if (system_retcode)
-       g_printerr("cs2cs returned error code %d\n",
-                  WEXITSTATUS(system_retcode));
+       g_printerr("cs2cs returned error code %d\n", WEXITSTATUS(system_retcode));
 else if (!(in = g_fopen("/tmp/tmpcs2cs", "r")))
        g_printerr("Cannot open results of conversion\n");
-else if (5 !=
-        fscanf(in, "%lf %lf %s %lf %lf", &lon1, &lat1, cmd, &lon2, &lat2)) {
+else if (5 != fscanf(in, "%lf %lf %s %lf %lf", &lon1, &lat1, cmd, &lon2, &lat2)) {
        g_printerr("Wrong conversion\n");
        fclose(in);
 } else {
@@ -351,12 +341,8 @@ if (!pui->retries || g_file_test(pui->dest_str, G_FILE_TEST_EXISTS)) {
                /* If zoom has changed since we first put in the request for
                 * this tile, then we may have to update more than one tile. */
                guint tilex, tiley, tilex_end, tiley_end;
-               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++) {
+               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++) {
                                if ((tilex - _base_tilex) < BUF_WIDTH_TILES && (tiley - _base_tiley) < BUF_HEIGHT_TILES) {
                                        map_render_tile(tilex, tiley,
                                                        ((tilex - _base_tilex) << TILE_SIZE_P2),
@@ -394,8 +380,7 @@ else {
                return FALSE;
        } else {
                /* No more retries left - something must be wrong. */
-               MACRO_BANNER_SHOW_INFO(_window, _("Error in download.  Check internet connection"
-                                       " and/or Map Repository URL Format."));
+               MACRO_BANNER_SHOW_INFO(_window, _("Error in download. Check internet connection and/or Map Repository URL Format."));
        }
 }
 
@@ -406,13 +391,11 @@ if (++_curr_download == _num_downloads) {
 #ifdef WITH_HILDON
        gtk_widget_destroy(_download_banner);
        _download_banner = NULL;
-#else
-       gtk_widget_hide(GTK_WIDGET(_progress_item));
 #endif
        _num_downloads = _curr_download = 0;
-} else
+} else {
        hildon_banner_set_fraction(HILDON_BANNER(_download_banner), _curr_download / (double)_num_downloads);
-
+}
 return FALSE;
 }
 
@@ -458,9 +441,7 @@ if (!_curl_sid)
        _curl_sid = g_timeout_add(100, (GSourceFunc) map_download_timeout, NULL);
 
 if (!_num_downloads++ && !_download_banner) {
-       gchar buffer[100];
-       g_snprintf(buffer, 100, _("Downloading maps (%d)"), g_tree_nnodes(_pui_tree));
-       _download_banner = hildon_banner_show_progress(_window, NULL, buffer);
+       _download_banner = hildon_banner_show_progress(_window, NULL, _("Downloading maps..."));
 }
 }