--- trunk/src/map-tool.c 2009/09/27 19:11:37 125 +++ trunk/src/map-tool.c 2009/11/09 07:50:37 167 @@ -22,6 +22,13 @@ * http://topo.geofabrik.de/trail/${z}/${x}/${y}.png 8-15 */ +/* + * TODO: + * - draw caches only once + * - prefer duplicates from selected files + * - make semi-transparent caches selectable + */ + #include "gpxview.h" #include "converter.h" #include // for isnan @@ -48,7 +55,7 @@ /* use environment settings if preset */ const char *proxy = g_getenv("http_proxy"); if(proxy) { - printf("http_proxy: %s\n", proxy); + printf("map http proxy from env: %s\n", proxy); return proxy; } @@ -69,6 +76,7 @@ snprintf(proxy_buffer, sizeof(proxy_buffer), "http://%s:%u", host, port); + printf("map http proxy from gconf: %s\n ", proxy_buffer); g_free(host); } @@ -80,6 +88,7 @@ static void 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)) { @@ -108,14 +117,18 @@ static gboolean map_gps_update(gpointer data) { map_context_t *context = (map_context_t*)data; + static gboolean goto_is_enabled = FALSE; /* get reference position ... */ pos_t *refpos = get_pos(context->appdata); gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); /* ... and enable "goto" button if it's valid */ - osm_gps_map_osd_enable_gps (OSM_GPS_MAP(context->widget), - OSM_GPS_MAP_OSD_CALLBACK(ok?cb_map_gps:NULL), context); + if(ok != goto_is_enabled) { + osm_gps_map_osd_enable_gps (OSM_GPS_MAP(context->widget), + OSM_GPS_MAP_OSD_CALLBACK(ok?cb_map_gps:NULL), context); + goto_is_enabled = ok; + } if(ok) { float heading = NAN; @@ -130,6 +143,8 @@ radius = dist2pixel(context, eph/1000, refpos->lat); } + /* TODO: in order to save energy: only draw if state actually changed */ + g_object_set(context->widget, "gps-track-highlight-radius", radius, NULL); osm_gps_map_draw_gps(OSM_GPS_MAP(context->widget), refpos->lat, refpos->lon, heading); @@ -139,11 +154,199 @@ return TRUE; } +static void map_draw_cache(GtkWidget *map, cache_t *cache, gboolean semi) { + GdkPixbuf *icon = icon_get(semi?ICON_CACHE_TYPE_SEMI:ICON_CACHE_TYPE, + cache->type); + + /* check if there's also an overwritten coordinate */ + if(cache->notes && cache->notes->override) { + GdkPixbuf *over = icon_get(ICON_MISC, 1); + + osm_gps_map_add_image(OSM_GPS_MAP(map), + cache->notes->pos.lat, cache->notes->pos.lon, icon); + + osm_gps_map_add_image(OSM_GPS_MAP(map), + cache->notes->pos.lat, cache->notes->pos.lon, over); + } else { + if(!isnan(cache->pos.lat) && !isnan(cache->pos.lon)) + osm_gps_map_add_image(OSM_GPS_MAP(map), + cache->pos.lat, cache->pos.lon, icon); + } +} + +static void map_draw_gpx(appdata_t *appdata, cache_display_t *caches, + GtkWidget *map, gpx_t *gpx, + cache_t *nav, gboolean semi) { + if(!gpx->notes_loaded) { + notes_load_all(appdata, gpx); + gpx->notes_loaded = TRUE; + } + + cache_t *cache = gpx->cache; + while(cache) { + /* search if we have that cache already in our list/displayed */ + int i=0; + while(caches[i].id && (strcmp(caches[i].id, cache->id) != 0)) + i++; + + if(!caches[i].id) { + /* if nav is given draw all other caches semitransparent. */ + /* if nav is not given do what semi sais */ + map_draw_cache(map, cache, nav?(cache != nav):semi); + caches[i].id = cache->id; + } + + cache = cache->next; + } +} + +/* draw geocaches and set window title */ +static void map_setup(map_context_t *context) { + char *name = NULL; + + int cache_num = gpx_total_caches_global(context->appdata->gpx); + + if(context->caches_displayed && (cache_num != context->cache_list_len)) { + // printf("re-alloc because %p %d/%d\n", context->caches_displayed, + // cache_num, context->cache_list_len); + g_free(context->caches_displayed); + context->caches_displayed = NULL; + context->cache_list_len = 0; + } + + /* allocate buffer */ + if(cache_num && !context->caches_displayed) { + context->cache_list_len = cache_num; + context->caches_displayed = g_new0(cache_display_t, cache_num+1); + printf("allocated space to handle %d map icons\n", cache_num); + } + + if(!context->appdata->cur_gpx && !context->appdata->cur_cache) { + if(context->state != MAP_ALL) { + printf("map_setup(ALL)\n"); + +#ifdef OSD_NAV + /* no navigation in this mode */ + osm_gps_map_osd_clear_nav (OSM_GPS_MAP(context->widget)); +#endif + + /* clear all existing cache images */ + osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); + memset(context->caches_displayed, 0, + (cache_num+1) * sizeof(cache_display_t)); + + /* draw all geocaches and none is semi-transparent */ + gpx_t *gpx = context->appdata->gpx; + while(gpx) { + map_draw_gpx(context->appdata, context->caches_displayed, + context->widget, gpx, NULL, FALSE); + gpx = gpx->next; + } + + { + int i=0; + while(context->caches_displayed[i].id) i++; + printf("number of caches actually displayed: %d\n", i); + } + + name = g_strdup(_("all")); + context->state = MAP_ALL; + } + } else if(!context->appdata->cur_cache) { + if(context->state != MAP_GPX) { + printf("map_setup(GPX)\n"); + +#ifdef OSD_NAV + /* no navigation in this mode */ + osm_gps_map_osd_clear_nav (OSM_GPS_MAP(context->widget)); +#endif + + /* clear all existing ccahe images */ + osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); + memset(context->caches_displayed, 0, + (cache_num+1) * sizeof(cache_display_t)); + + /* draw all geocaches and all other gpx files are semi-transparent */ + map_draw_gpx(context->appdata, context->caches_displayed, + context->widget, context->appdata->cur_gpx, NULL, FALSE); + + gpx_t *gpx = context->appdata->gpx; + while(gpx) { + if(gpx != context->appdata->cur_gpx) + map_draw_gpx(context->appdata, context->caches_displayed, + context->widget, gpx, NULL, TRUE); + + gpx = gpx->next; + } + + name = g_strdup(context->appdata->cur_gpx->name); + context->state = MAP_GPX; + } + } else { + cache_t *cache = context->appdata->cur_cache; + + printf("map_setup(CACHE)\n"); + + /* no balloons in this mode */ + context->balloon = NULL; + osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(context->widget)); + + /* clear all existing ccahe images */ + osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); + memset(context->caches_displayed, 0, + (cache_num+1) * sizeof(cache_display_t)); + + /* draw all geocaches and all but selected one are semi-transparent */ + gpx_t *gpx = context->appdata->gpx; + while(gpx) { + map_draw_gpx(context->appdata, context->caches_displayed, + context->widget, gpx, cache, FALSE); + gpx = gpx->next; + } + + name = g_strdup(cache->name); + context->state = MAP_CACHE; + + /* navigation in this mode! */ + pos_t cpos = gpx_cache_pos(cache); + +#ifdef OSD_NAV + osm_gps_map_osd_draw_nav (OSM_GPS_MAP(context->widget), + context->appdata->imperial, + cpos.lat, cpos.lon, cache->name); +#else +#warning OSD_NAV not defined! +#endif + } + + if(name) { + char *title = g_strdup_printf(_("Map - %s"), name); + g_free(name); + + gtk_window_set_title(GTK_WINDOW(context->window), title); + + g_free(title); + } else + printf("map_setup(keep)\n"); +} + static gboolean on_map_configure(GtkWidget *widget, GdkEventConfigure *event, map_context_t *context) { - if(!context->map_complete) { + /* for some reason there's a configure event with 1/1 */ + /* on diablo. We just ignore this! */ + + printf("on_map_configure %d %d\n", + widget->allocation.width, + widget->allocation.height); + + if(!context->map_complete && + (widget->allocation.width > 100) && + (widget->allocation.height > 100)) { + + /* setup cache state */ + map_setup(context); /* set default values if they are invalid */ if(!context->appdata->map.zoom || @@ -153,10 +356,14 @@ pos_t *refpos = get_pos(context->appdata); if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { + printf("use refpos\n"); + /* use gps position if present */ context->appdata->map.pos = *refpos; context->appdata->map.zoom = GPS_DEFAULT_ZOOM; } else { + printf("use zero pos\n"); + /* use world map otherwise */ context->appdata->map.pos.lat = 0.0; context->appdata->map.pos.lon = 0.0; @@ -165,6 +372,11 @@ } /* jump to initial position */ + printf("osm_gps_map_set_mapcenter(%f,%f,%d)\n", + context->appdata->map.pos.lat, + context->appdata->map.pos.lon, + context->appdata->map.zoom); + osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), context->appdata->map.pos.lat, context->appdata->map.pos.lon, @@ -175,40 +387,10 @@ return FALSE; } -static void map_draw_cache(GtkWidget *map, cache_t *cache) { - GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type); - - /* check if there's also an overwritten coordinate */ - if(cache->notes && cache->notes->override) { - GdkPixbuf *over = icon_get(ICON_MISC, 1); - - osm_gps_map_add_image(OSM_GPS_MAP(map), - cache->notes->pos.lat, cache->notes->pos.lon, icon); - - osm_gps_map_add_image(OSM_GPS_MAP(map), - cache->notes->pos.lat, cache->notes->pos.lon, over); - } else - osm_gps_map_add_image(OSM_GPS_MAP(map), - cache->pos.lat, cache->pos.lon, icon); - -} - -static void map_draw_gpx(appdata_t *appdata, GtkWidget *map, gpx_t *gpx) { - if(!gpx->notes_loaded) { - notes_load_all(appdata, gpx); - gpx->notes_loaded = TRUE; - } - - cache_t *cache = gpx->cache; - while(cache) { - map_draw_cache(map, cache); - cache = cache->next; - } -} - static void map_cachelist_nearest(cache_t *cache, pos_t *pos, cache_t **result, float *distance) { + while(cache) { pos_t cpos = gpx_cache_pos(cache); @@ -229,22 +411,18 @@ cache_t *result = NULL; float distance = NAN; -#ifdef USE_MAEMO if(!context->appdata->cur_gpx && !context->appdata->cur_cache) { -#endif /* search all geocaches */ gpx_t *gpx = context->appdata->gpx; while(gpx) { map_cachelist_nearest(gpx->cache, pos, &result, &distance); gpx = gpx->next; } -#ifdef USE_MAEMO } else if(context->appdata->cur_gpx) { map_cachelist_nearest(context->appdata->cur_gpx->cache, pos, &result, &distance); } else result = context->appdata->cur_gpx->cache; -#endif return result; } @@ -262,10 +440,11 @@ static gboolean on_map_button_press_event(GtkWidget *widget, GdkEventButton *event, map_context_t *context) { + OsmGpsMap *map = OSM_GPS_MAP(context->widget); /* check if we actually clicked parts of the OSD */ - if(osm_gps_map_osd_check(map, event->x, event->y) != OSD_NONE) + if(osm_gps_map_osd_check(map, event->x, event->y) != OSD_NONE) return FALSE; /* got a press event without release event? eat it! */ @@ -300,6 +479,7 @@ gdk_pixbuf_get_height(buf)); // Create the new Context for the ImageSurface + g_assert(image_surface); cairo_t *context = cairo_create(image_surface); // Draw the image on the new Context @@ -319,121 +499,182 @@ #endif static void -balloon_draw_cb(cairo_t *cr, OsmGpsMapRect_t *rect, gpointer data) { - cache_t *cache = (cache_t*)data; - -#if 0 - /* draw pink background to check clipping */ - cairo_rectangle (cr, rect->x-20, rect->y-20, rect->w+40, rect->h+40); - cairo_set_source_rgba (cr, 1, 0, 0, 0.3); - cairo_fill_preserve (cr); - cairo_set_line_width (cr, 0); - cairo_stroke (cr); -#endif - - /* leave a little border top and left */ - gint x = rect->x, y = rect->y; - - /* draw the cache type icon ... */ - GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type); - cairo_draw_pixbuf(cr, icon, x, y); +balloon_cb(osm_gps_map_balloon_event_t *event, gpointer data) { + printf("balloon event: "); - if(cache->notes && cache->notes->override) { - GdkPixbuf *over = icon_get(ICON_MISC, 1); - cairo_draw_pixbuf(cr, over, x, y); - } + map_context_t *context = (map_context_t*)data; + cache_t *cache = context->balloon; - /* ... and right of it the waypoint id */ - cairo_text_extents_t extents; + if(event->type == OSM_GPS_MAP_BALLOON_EVENT_TYPE_DRAW) { + printf("draw\n"); - if(cache->id) { - cairo_select_font_face (cr, "Sans", - CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_WEIGHT_BOLD); - +#if 0 + /* draw pink background to check clipping */ + cairo_rectangle (event->data.draw.cr, + event->data.draw.rect->x-20, event->data.draw.rect->y-20, + event->data.draw.rect->w+40, event->data.draw.rect->h+40); + cairo_set_source_rgba (event->data.draw.cr, 1, 0, 0, 0.3); + cairo_fill_preserve (event->data.draw.cr); + cairo_set_line_width (event->data.draw.cr, 0); + cairo_stroke (event->data.draw.cr); +#endif + + /* leave a little border top and left */ + gint x = event->data.draw.rect->x, y = event->data.draw.rect->y; + + /* draw the cache type icon ... */ + GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type); + cairo_draw_pixbuf(event->data.draw.cr, icon, x, y); + + if(cache->notes && cache->notes->override) { + GdkPixbuf *over = icon_get(ICON_MISC, 1); + cairo_draw_pixbuf(event->data.draw.cr, over, x, y); + } + + /* ... and right of it the waypoint id */ + cairo_text_extents_t extents; + + if(cache->id) { + cairo_select_font_face (event->data.draw.cr, "Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_BOLD); + #ifndef BIG_BALLOONS - cairo_set_font_size (cr, 20.0); + cairo_set_font_size (event->data.draw.cr, 20.0); #else - cairo_set_font_size (cr, 36.0); + cairo_set_font_size (event->data.draw.cr, 36.0); #endif - - cairo_text_extents (cr, cache->id, &extents); - - /* display id right of icon vertically centered */ - x += gdk_pixbuf_get_width(icon) + 5; - y += (gdk_pixbuf_get_height(icon) + extents.height)/2; - cairo_move_to (cr, x, y); - cairo_set_source_rgba (cr, 0, 0, 0, 1); - cairo_show_text (cr, cache->id); - cairo_stroke (cr); - - y += (gdk_pixbuf_get_height(icon) - extents.height)/2 + LINE_SKIP; - } else - y += gdk_pixbuf_get_height(icon); - - /* return to the left border and below icon/text */ - x = rect->x; - - /* everything from here uses the same font */ - cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_WEIGHT_NORMAL); + + cairo_text_extents (event->data.draw.cr, cache->id, &extents); + + /* display id right of icon vertically centered */ + x += gdk_pixbuf_get_width(icon) + 5; + y += (gdk_pixbuf_get_height(icon) + extents.height)/2; + cairo_move_to (event->data.draw.cr, x, y); + cairo_set_source_rgba (event->data.draw.cr, 0, 0, 0, 1); + cairo_show_text (event->data.draw.cr, cache->id); + cairo_stroke (event->data.draw.cr); + + y += (gdk_pixbuf_get_height(icon) - extents.height)/2 + LINE_SKIP; + } else + y += gdk_pixbuf_get_height(icon); + + /* return to the left border and below icon/text */ + x = event->data.draw.rect->x; + + /* everything from here uses the same font */ + cairo_select_font_face (event->data.draw.cr, "Sans", CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); #ifndef BIG_BALLOONS - cairo_set_font_size (cr, 14.0); + cairo_set_font_size (event->data.draw.cr, 14.0); #else - cairo_set_font_size (cr, 22.0); + cairo_set_font_size (event->data.draw.cr, 22.0); #endif - - if(cache->name) { - /* draw cache name */ - cairo_text_extents (cr, cache->name, &extents); - y += extents.height; - cairo_move_to (cr, x, y); - cairo_set_source_rgba (cr, 0, 0, 0, 1); - cairo_show_text (cr, cache->name); - cairo_stroke (cr); - - /* return to the left border and below text */ - y += LINE_SKIP; - x = rect->x; - } - - if(cache->terrain) { - /* draw cache rating */ - const char *terrain = "Terrain:"; - icon = icon_get(ICON_STARS, (int)(cache->terrain*2-2)); - cairo_text_extents (cr, _(terrain), &extents); - y += (gdk_pixbuf_get_height(icon) + extents.height)/2; - - /* draw "Terrain:" string */ - cairo_move_to (cr, x, y); - cairo_set_source_rgba (cr, 0, 0, 0, 1); - cairo_show_text (cr, _(terrain)); - cairo_stroke (cr); - x += extents.width + 2; - - /* draw terrain stars */ - cairo_draw_pixbuf(cr, icon, x, y - - (gdk_pixbuf_get_height(icon) + extents.height)/2); - - x += gdk_pixbuf_get_width(icon) + LINE_SKIP; + + if(cache->name) { + /* draw cache name */ + cairo_text_extents (event->data.draw.cr, cache->name, &extents); + y += extents.height; + cairo_move_to (event->data.draw.cr, x, y); + cairo_set_source_rgba (event->data.draw.cr, 0, 0, 0, 1); + cairo_show_text (event->data.draw.cr, cache->name); + cairo_stroke (event->data.draw.cr); + + /* return to the left border and below text */ + y += LINE_SKIP; + x = event->data.draw.rect->x; + } + + if(cache->terrain) { + /* draw cache rating */ + const char *terrain = "Terrain:"; + icon = icon_get(ICON_STARS, (int)(cache->terrain*2-2)); + cairo_text_extents (event->data.draw.cr, _(terrain), &extents); + y += (gdk_pixbuf_get_height(icon) + extents.height)/2; + + /* draw "Terrain:" string */ + cairo_move_to (event->data.draw.cr, x, y); + cairo_set_source_rgba (event->data.draw.cr, 0, 0, 0, 1); + cairo_show_text (event->data.draw.cr, _(terrain)); + cairo_stroke (event->data.draw.cr); + x += extents.width + 2; + + /* draw terrain stars */ + cairo_draw_pixbuf(event->data.draw.cr, icon, x, y - + (gdk_pixbuf_get_height(icon) + extents.height)/2); + + x += gdk_pixbuf_get_width(icon) + LINE_SKIP; y -= (gdk_pixbuf_get_height(icon) + extents.height)/2; - } - - if(cache->difficulty) { - const char *difficulty = "Difficulty:"; - cairo_text_extents (cr, _(difficulty), &extents); - y += (gdk_pixbuf_get_height(icon) + extents.height)/2; - - /* draw "Difficulty:" string */ - cairo_move_to (cr, x, y); - cairo_set_source_rgba (cr, 0, 0, 0, 1); - cairo_show_text (cr, _(difficulty)); - cairo_stroke (cr); - x += extents.width + 2; + } - icon = icon_get(ICON_STARS, (int)(cache->difficulty*2-2)); - cairo_draw_pixbuf(cr, icon, x, y - + if(cache->difficulty) { + const char *difficulty = "Difficulty:"; + cairo_text_extents (event->data.draw.cr, _(difficulty), &extents); + y += (gdk_pixbuf_get_height(icon) + extents.height)/2; + + /* draw "Difficulty:" string */ + cairo_move_to (event->data.draw.cr, x, y); + cairo_set_source_rgba (event->data.draw.cr, 0, 0, 0, 1); + cairo_show_text (event->data.draw.cr, _(difficulty)); + cairo_stroke (event->data.draw.cr); + x += extents.width + 2; + + icon = icon_get(ICON_STARS, (int)(cache->difficulty*2-2)); + cairo_draw_pixbuf(event->data.draw.cr, icon, x, y - (gdk_pixbuf_get_height(icon) + extents.height)/2); + } + } else if(event->type == OSM_GPS_MAP_BALLOON_EVENT_TYPE_CLICK) { + printf("click %s event at %d %d\n", + event->data.click.down?"down":"up", + event->data.click.x, event->data.click.y); + + /* make the main screen jump to that cache */ + if(!event->data.click.down) { + if(context->appdata->cur_cache) { + printf("ERROR: no current cache should be visible!\n"); + } else { + gpx_t *is_in = NULL; + + if(!context->appdata->cur_gpx) { + printf("click while in \"all\" view\n"); + + /* we first need to figure out which gpx file this cache */ + /* is in so we can open it first */ + gpx_t *gpx = context->appdata->gpx; + while(gpx && !is_in) { + cache_t *cur = gpx->cache; + while(cur && !is_in) { + if(cur == cache) + is_in = gpx; + cur = cur->next; + } + gpx = gpx->next; + } + + if(is_in) + gpxlist_goto_cachelist(context->appdata, is_in); + + } else + /* the simple case: there already is an open gpx file and */ + /* we just jump into the "cache" view */ + is_in = context->appdata->cur_gpx; + + if(is_in) { + printf("selecting %s in %s\n", + cache->id, + context->appdata->cur_gpx->name); + + cachelist_goto_cache(context->appdata, cache); + + /* give focus to main screen (important for maemo) */ + printf("raising main window\n"); + gtk_window_present(GTK_WINDOW(context->appdata->window)); + } + } + } + } else if(event->type == OSM_GPS_MAP_BALLOON_EVENT_TYPE_REMOVED) { + printf("removed\n"); + context->balloon = NULL; } } @@ -442,7 +683,11 @@ GdkEventButton *event, map_context_t *context) { OsmGpsMap *map = OSM_GPS_MAP(context->widget); - if(context->press_on) { + /* in "MAP_CACHE" state only one cache is visible */ + /* and the map is in navigation mode. the balloon is */ + /* pretty useless there */ + if(context->press_on && (context->state != MAP_CACHE)) { + coord_t coo; coo = osm_gps_map_get_co_ordinates(map, event->x, event->y); @@ -456,11 +701,9 @@ float dist = gpx_pos_get_distance(pos, cpos, FALSE); if(dist2pixel(context, dist, cpos.lat) < CLICK_FUZZ) { + context->balloon = nearest; osm_gps_map_osd_draw_balloon(map, cpos.lat, cpos.lon, - balloon_draw_cb, nearest); - - osm_gps_map_osd_draw_nav (map, cpos.lat, cpos.lon, nearest->name); - + balloon_cb, context); } } context->press_on = NULL; @@ -478,8 +721,6 @@ static void on_window_destroy(GtkWidget *widget, map_context_t *context) { appdata_t *appdata = context->appdata; - printf("destroy map window\n"); - /* save map parameters */ OsmGpsMap *map = OSM_GPS_MAP(context->widget); gint zoom; @@ -501,6 +742,12 @@ #endif gtk_timeout_remove(context->handler_id); + gps_unregister_callback(appdata, context->cb_id); + + if(context->caches_displayed) { + g_free(context->caches_displayed); + context->caches_displayed = NULL; + } g_free(context); appdata->map.context = NULL; @@ -525,39 +772,51 @@ } #endif -/* draw geocaches and set window title */ -static void map_setup(map_context_t *context) { - char *name = NULL; +/* on maemo a window is either on top or completely invisible. this */ +/* means that we only need to update the map window if its raised. */ +/* on ordinary desktops this is different and we always update */ - /* clear all existing ccahe images */ - osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); +static gboolean on_focus_in(GtkWidget *widget, GdkEventFocus *event, + gpointer data) { + map_context_t *context = (map_context_t*)data; + + printf("map got focus\n"); #ifdef USE_MAEMO - if(!context->appdata->cur_gpx && !context->appdata->cur_cache) { + /* re-enable refresh of map */ + if(!context->handler_id) + context->handler_id = gtk_timeout_add(1000, map_gps_update, context); #endif - /* draw all geocaches */ - gpx_t *gpx = context->appdata->gpx; - while(gpx) { - map_draw_gpx(context->appdata, context->widget, gpx); - gpx = gpx->next; - } - name = g_strdup(_("all")); + + map_setup(context); + return FALSE; +} + #ifdef USE_MAEMO - } else if(!context->appdata->cur_cache) { - map_draw_gpx(context->appdata, context->widget, context->appdata->cur_gpx); - name = g_strdup(context->appdata->cur_gpx->name); - } else { - map_draw_cache(context->widget, context->appdata->cur_cache); - name = g_strdup(context->appdata->cur_cache->name); - } -#endif +static gboolean on_focus_out(GtkWidget *widget, GdkEventFocus *event, + gpointer data) { + map_context_t *context = (map_context_t*)data; - char *title = g_strdup_printf(_("Map - %s"), name); - g_free(name); + printf("map lost focus\n"); + gtk_timeout_remove(context->handler_id); + context->handler_id = 0; - gtk_window_set_title(GTK_WINDOW(context->window), title); + return FALSE; +} +#endif - g_free(title); +void map_update(appdata_t *appdata) { + printf("map_update\n"); +#ifndef USE_MAEMO + if(appdata->map.context) + map_setup(appdata->map.context); +#endif +} + +/* callback called by the gps layer whenever gps state changes */ +static void +gps_callback(struct gps_state *state, gpointer data) { + printf("map: gps callback\n"); } void map(appdata_t *appdata) { @@ -574,6 +833,7 @@ context = appdata->map.context = g_new0(map_context_t, 1); context->appdata = appdata; context->map_complete = FALSE; + context->state = MAP_NONE; /* cleanup old (pre 0.8.7) path if it exists */ char *old_path = g_strdup_printf("%s/map/", appdata->image_path); @@ -631,13 +891,18 @@ context->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); #endif - /* setup cache state */ - map_setup(context); - #ifndef USE_MAEMO gtk_window_set_default_size(GTK_WINDOW(context->window), 640, 480); #endif + g_signal_connect(G_OBJECT(context->widget), "focus-in-event", + G_CALLBACK(on_focus_in), context); + +#ifdef USE_MAEMO + g_signal_connect(G_OBJECT(context->widget), "focus-out-event", + G_CALLBACK(on_focus_out), context); +#endif + g_signal_connect(G_OBJECT(context->widget), "configure-event", G_CALLBACK(on_map_configure), context); @@ -649,6 +914,7 @@ /* install handler for timed updates of the gps button */ context->handler_id = gtk_timeout_add(1000, map_gps_update, context); + context->cb_id = gps_register_callback(appdata, gps_callback, context); #if MAEMO_VERSION_MAJOR == 5 /* prevent some of the main screen things */