--- trunk/src/map-tool.c 2009/08/20 18:54:06 69 +++ trunk/src/map-tool.c 2009/08/28 07:52:01 84 @@ -23,9 +23,16 @@ #ifdef ENABLE_OSM_GPS_MAP #include "osm-gps-map.h" +#include "osm-gps-map-osd-classic.h" #endif -#define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENSTREETMAP +#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) +#include +#include +#endif + +// #define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENSTREETMAP +#define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENCYCLEMAP #define GPS_DEFAULT_ZOOM 13 #define PROXY_KEY "/system/http_proxy/" @@ -67,15 +74,26 @@ } static void -cb_map_gps(map_context_t *context) { - pos_t *refpos = get_pos(context->appdata); - if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { - osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), - refpos->lat, refpos->lon, GPS_DEFAULT_ZOOM); - } else { - /* no coordinates given: display the entire world */ - osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), - 0.0, 0.0, 1); +cb_map_gps(osd_button_t but, map_context_t *context) { + if(but == OSD_GPS) { + pos_t *refpos = get_pos(context->appdata); + if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { + gint zoom; + g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL); + if(zoom < 10) + osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), + refpos->lat, refpos->lon, GPS_DEFAULT_ZOOM); + else + osm_gps_map_set_center(OSM_GPS_MAP(context->widget), + refpos->lat, refpos->lon); + + /* re-enable centering */ + g_object_set(context->widget, "auto-center", TRUE, NULL); + } else { + /* no coordinates given: display the entire world */ + osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), + 0.0, 0.0, 1); + } } } @@ -92,7 +110,7 @@ /* ... and enable "goto" button if it's valid */ osm_gps_map_osd_enable_gps (OSM_GPS_MAP(context->widget), - OSM_GPS_MAP_OSD_GPS_CALLBACK(ok?cb_map_gps:NULL), context); + OSM_GPS_MAP_OSD_CALLBACK(ok?cb_map_gps:NULL), context); if(ok) { float heading = NAN; @@ -144,7 +162,7 @@ context->appdata->map.pos.lat, context->appdata->map.pos.lon, context->appdata->map.zoom); - + return FALSE; } @@ -266,8 +284,6 @@ balloon_draw_cb(cairo_t *cr, OsmGpsMapRect_t *rect, gpointer data) { cache_t *cache = (cache_t*)data; - // printf("draw cb for \"%s\"\n", cache->name); - #if 0 /* draw pink background to check clipping */ cairo_rectangle (cr, rect->x-20, rect->y-20, rect->w+40, rect->h+40); @@ -438,6 +454,25 @@ appdata->map.context = NULL; } +#if (MAEMO_VERSION_MAJOR == 5) && !defined(__i386__) +/* get access to zoom buttons */ +static void +on_window_realize(GtkWidget *widget, gpointer data) { + if (widget->window) { + unsigned char value = 1; + Atom hildon_zoom_key_atom = + gdk_x11_get_xatom_by_name("_HILDON_ZOOM_KEY_ATOM"), + integer_atom = gdk_x11_get_xatom_by_name("INTEGER"); + Display *dpy = + GDK_DISPLAY_XDISPLAY(gdk_drawable_get_display(widget->window)); + Window w = GDK_WINDOW_XID(widget->window); + + XChangeProperty(dpy, w, hildon_zoom_key_atom, + integer_atom, 8, PropModeReplace, &value, 1); + } +} +#endif + void map(appdata_t *appdata) { map_context_t *context = NULL; @@ -450,7 +485,30 @@ context = appdata->map.context = g_new0(map_context_t, 1); context->appdata = appdata; - char *path = g_strdup_printf("%s/map/", appdata->image_path); + /* cleanup old (pre 0.8.7) path if it exists */ + char *old_path = g_strdup_printf("%s/map/", appdata->image_path); + if(g_file_test(old_path, G_FILE_TEST_IS_DIR)) { + printf("old file path %s exists\n", old_path); + rmdir_recursive(old_path); + } + + /* It is recommanded that all applications share these same */ + /* map path, so data is only cached once. The path should be: */ + /* ~/.osm-gps-map on standard PC (users home) */ + /* /home/user/.osm-gps-map on Maemo5 (ext3 on internal card) */ + /* /media/mmc2/osm-gps-map on Maemo4 (vfat on internal card) */ +#if !defined(USE_MAEMO) + char *p = getenv("HOME"); + if(!p) p = "/tmp"; + char *path = g_strdup_printf("%s/.osm-gps-map", p); +#else +#if MAEMO_VERSION_MAJOR == 5 + char *path = g_strdup("/home/user/.osm-gps-map"); +#else + char *path = g_strdup("/media/mmc2/osm-gps-map"); +#endif +#endif + const char *proxy = get_proxy_uri(appdata); context->widget = g_object_new(OSM_TYPE_GPS_MAP, @@ -464,6 +522,8 @@ g_free(path); + osm_gps_map_osd_classic_init(OSM_GPS_MAP(context->widget)); + char *name = NULL; #ifdef USE_MAEMO if(!appdata->cur_gpx) { @@ -488,6 +548,12 @@ #ifdef USE_MAEMO #ifdef USE_STACKABLE_WINDOW context->window = hildon_stackable_window_new(); + /* try to enable the zoom buttons. don't do this on x86 as it breaks */ + /* at runtime with cygwin x */ +#ifndef __i386__ + g_signal_connect(G_OBJECT(context->window), "realize", + G_CALLBACK(on_window_realize), NULL); +#endif // MAEMO_VERSION #else context->window = hildon_window_new(); #endif