--- trunk/src/osm-gps-map.c 2009/08/31 14:22:28 88 +++ trunk/src/osm-gps-map.c 2009/09/01 11:16:30 89 @@ -66,6 +66,8 @@ #include #endif +#define USER_AGENT "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11" + struct _OsmGpsMapPrivate { GHashTable *tile_queue; @@ -95,6 +97,7 @@ char *proxy_uri; //where downloaded tiles are cached + char *tile_dir; char *cache_dir; //contains flags indicating the various special characters @@ -348,6 +351,8 @@ inspect_map_uri(OsmGpsMap *map) { OsmGpsMapPrivate *priv = map->priv; + priv->uri_format = 0; + priv->the_google = FALSE; if (g_strrstr(priv->repo_uri, URI_MARKER_X)) priv->uri_format |= URI_HAS_X; @@ -1094,6 +1099,11 @@ } } +#ifdef LIBSOUP22 + soup_message_headers_append(msg->request_headers, + "User-Agent", USER_AGENT); +#endif + g_hash_table_insert (priv->tile_queue, dl->uri, msg); soup_session_queue_message (priv->soup_session, msg, osm_gps_map_tile_download_complete, dl); } else { @@ -1502,8 +1512,6 @@ gboolean handled = FALSE; int step = GTK_WIDGET(widget)->allocation.width/OSM_GPS_MAP_SCROLL_STEP; - // printf("key event with keyval %x\n", event->keyval); - // the map handles some keys on its own ... switch(event->keyval) { #ifdef OSM_GPS_MAP_KEY_FULLSCREEN @@ -1570,7 +1578,6 @@ #endif default: - // printf("unhandled key event with keyval %x\n", event->keyval); break; } @@ -1622,12 +1629,12 @@ #ifndef LIBSOUP22 //Change naumber of concurrent connections option? - priv->soup_session = soup_session_async_new_with_options( - SOUP_SESSION_USER_AGENT, - "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11", - NULL); + priv->soup_session = + soup_session_async_new_with_options(SOUP_SESSION_USER_AGENT, + USER_AGENT, NULL); #else - /* libsoup-2.2 seems not to be able to set the user agent */ + /* libsoup-2.2 has no special way to set the user agent, so we */ + /* set it seperately as an extra header field for each reuest */ priv->soup_session = soup_session_async_new(); #endif @@ -1652,7 +1659,6 @@ g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, my_log_handler, NULL); #ifdef OSM_GPS_MAP_KEYS - // GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(object)); g_signal_connect(G_OBJECT(object), "key_press_event", G_CALLBACK(on_window_key_press), priv); #endif @@ -1698,12 +1704,10 @@ const char *fname = osm_gps_map_source_get_friendly_name(priv->map_source); if(!fname) fname = "_unknown_"; - if (priv->cache_dir) { - char *old = priv->cache_dir; - //the new cachedir is the given cache dir + the md5 of the repo_uri - priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, fname); - g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); - g_free(old); + if (priv->tile_dir) { + //the new cachedir is the given cache dir + the friendly name of the repo_uri + priv->cache_dir = g_strdup_printf("%s%c%s", priv->tile_dir, G_DIR_SEPARATOR, fname); + g_debug("Adjusting cache dir %s -> %s", priv->tile_dir, priv->cache_dir); } inspect_map_uri(map); @@ -1768,7 +1772,12 @@ OsmGpsMap *map = OSM_GPS_MAP(object); OsmGpsMapPrivate *priv = map->priv; - g_free(priv->cache_dir); + if(priv->tile_dir) + g_free(priv->tile_dir); + + if(priv->cache_dir) + g_free(priv->cache_dir); + g_free(priv->repo_uri); g_free(priv->image_format); @@ -1825,7 +1834,7 @@ break; case PROP_TILE_CACHE_DIR: if ( g_value_get_string(value) ) - priv->cache_dir = g_value_dup_string (value); + priv->tile_dir = g_value_dup_string (value); break; case PROP_ZOOM: priv->map_zoom = g_value_get_int (value); @@ -1853,9 +1862,53 @@ case PROP_GPS_POINT_R2: priv->ui_gps_point_outer_radius = g_value_get_int (value); break; - case PROP_MAP_SOURCE: + case PROP_MAP_SOURCE: { + gint old = priv->map_source; priv->map_source = g_value_get_int (value); - break; + if(old >= OSM_GPS_MAP_SOURCE_NULL && + priv->map_source != old && + priv->map_source >= OSM_GPS_MAP_SOURCE_NULL && + priv->map_source <= OSM_GPS_MAP_SOURCE_LAST) { + + /* we now have to switch the entire map */ + + /* flush the ram cache */ + g_hash_table_remove_all(priv->tile_cache); + + //check if the source given is valid + const char *uri = osm_gps_map_source_get_repo_uri(priv->map_source); + if (uri) { + g_debug("Setting map source from ID"); + g_free(priv->repo_uri); + + priv->repo_uri = g_strdup(uri); + priv->image_format = g_strdup( + osm_gps_map_source_get_image_format(priv->map_source)); + priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source); + priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source); + } + + /* create a new disk cache path */ + const char *fname = osm_gps_map_source_get_friendly_name(priv->map_source); + if(!fname) fname = "_unknown_"; + + if (priv->tile_dir) { + //the new cachedir is the given cache dir + the friendly name of the repo_uri + priv->cache_dir = + g_strdup_printf("%s%c%s", priv->tile_dir, G_DIR_SEPARATOR, fname); + g_debug("Adjusting cache dir %s -> %s", priv->tile_dir, priv->cache_dir); + } + + /* adjust zoom if necessary */ + if(priv->map_zoom > priv->max_zoom) + osm_gps_map_set_zoom(map, priv->max_zoom); + + if(priv->map_zoom < priv->min_zoom) + osm_gps_map_set_zoom(map, priv->min_zoom); + + inspect_map_uri(map); + + } } break; case PROP_IMAGE_FORMAT: priv->image_format = g_value_dup_string (value); break; @@ -2459,7 +2512,7 @@ -1, /* minimum property value */ G_MAXINT, /* maximum property value */ -1, - G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); g_object_class_install_property (object_class, PROP_IMAGE_FORMAT, @@ -2480,7 +2533,7 @@ case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: return "OpenStreetMap"; case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: - return "OpenStreetMap Renderer"; + return "OpenStreetMap Tiles@Home"; case OSM_GPS_MAP_SOURCE_OPENCYCLEMAP: return "OpenCycleMap"; case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: @@ -2565,7 +2618,9 @@ case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: case OSM_GPS_MAP_SOURCE_OPENCYCLEMAP: return "png"; + case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: + case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: @@ -2573,8 +2628,6 @@ case OSM_GPS_MAP_SOURCE_YAHOO_STREET: case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: - case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: - case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: return "jpg"; default: return "bin";