--- trunk/src/map-tool.c 2009/10/26 10:40:06 142 +++ trunk/src/map-tool.c 2009/10/26 19:55:00 143 @@ -45,6 +45,8 @@ static const char *get_proxy_uri(appdata_t *appdata) { static char proxy_buffer[64] = ""; + printf("get_proxy_uri in\n"); + /* use environment settings if preset */ const char *proxy = g_getenv("http_proxy"); if(proxy) { @@ -75,11 +77,14 @@ return proxy_buffer; } + printf("get_proxy_uri out\n"); return NULL; } static void cb_map_gps(osd_button_t but, map_context_t *context) { + printf("cb_map_gps in\n"); + if(but == OSD_GPS) { pos_t *refpos = get_pos(context->appdata); if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { @@ -100,6 +105,7 @@ 0.0, 0.0, 1); } } + printf("cb_map_gps out\n"); } static int dist2pixel(map_context_t *context, float km, float lat) { @@ -109,6 +115,8 @@ static gboolean map_gps_update(gpointer data) { map_context_t *context = (map_context_t*)data; + printf("map_gps_update in\n"); + /* get reference position ... */ pos_t *refpos = get_pos(context->appdata); gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); @@ -136,14 +144,150 @@ } else osm_gps_map_clear_gps(OSM_GPS_MAP(context->widget)); + printf("map_gps_update out\n"); return TRUE; } +static void map_draw_cache(GtkWidget *map, cache_t *cache) { + printf("map_draw_cache in\n"); + + 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 { + 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); + } + printf("map_draw_cache out\n"); +} + +static void map_draw_gpx(appdata_t *appdata, GtkWidget *map, gpx_t *gpx) { + printf("map_draw_gpx in\n"); + + 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; + } + printf("map_draw_gpx out\n"); +} + +/* draw geocaches and set window title */ +static void map_setup(map_context_t *context) { + char *name = NULL; + + printf("map_setup in\n"); + + 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 ccahe images */ + osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); + + /* 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")); + 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)); + + map_draw_gpx(context->appdata, context->widget, + context->appdata->cur_gpx); + name = g_strdup(context->appdata->cur_gpx->name); + context->state = MAP_GPX; + } + } else { + cache_t *cache = context->appdata->cur_cache; + + printf("map_setp(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)); + + map_draw_cache(context->widget, cache); + 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"); + + printf("map_setup out\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 +297,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 +313,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, @@ -172,43 +325,14 @@ context->map_complete = TRUE; } + printf("map configure done\n"); 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) { + printf("map_cachelist_nearest in\n"); while(cache) { pos_t cpos = gpx_cache_pos(cache); @@ -223,12 +347,15 @@ cache = cache->next; } + printf("map_cachelist_nearest out\n"); } static cache_t *map_closest(map_context_t *context, pos_t *pos) { cache_t *result = NULL; float distance = NAN; + printf("map_closest in\n"); + if(!context->appdata->cur_gpx && !context->appdata->cur_cache) { /* search all geocaches */ gpx_t *gpx = context->appdata->gpx; @@ -242,6 +369,7 @@ } else result = context->appdata->cur_gpx->cache; + printf("map_closest out\n"); return result; } @@ -258,11 +386,15 @@ static gboolean on_map_button_press_event(GtkWidget *widget, GdkEventButton *event, map_context_t *context) { + printf("on_map_button_press_event in\n"); + 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) { + printf("on_map_button_press_event out 1\n"); return FALSE; + } /* got a press event without release event? eat it! */ if(context->press_on != NULL) { @@ -282,6 +414,7 @@ context->press_on = nearest; } + printf("on_map_button_press_event out\n"); return FALSE; } @@ -289,6 +422,8 @@ cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *buf, gint x, gint y) { /* convert the pixbuf into something cairo can handle */ + printf("cairo_draw_pixbuf in\n"); + // Create a new ImageSurface cairo_surface_t *image_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, @@ -306,6 +441,7 @@ cairo_set_source_surface(cr, image_surface, x, y); cairo_paint(cr); + printf("cairo_draw_pixbuf out\n"); } #ifndef BIG_BALLOONS @@ -316,11 +452,11 @@ static void balloon_cb(osm_gps_map_balloon_event_t *event, gpointer data) { + printf("balloon event:\n"); + map_context_t *context = (map_context_t*)data; cache_t *cache = context->balloon; - printf("balloon event: "); - if(event->type == OSM_GPS_MAP_BALLOON_EVENT_TYPE_DRAW) { printf("draw\n"); @@ -492,6 +628,7 @@ printf("removed\n"); context->balloon = NULL; } + printf("balloon out\n"); } static gboolean @@ -499,6 +636,8 @@ GdkEventButton *event, map_context_t *context) { OsmGpsMap *map = OSM_GPS_MAP(context->widget); + printf("on_map_button_release_event in\n"); + /* in "MAP_CACHE" state only one cache is visible */ /* and the map is in navigation mode. the balloon is */ /* pretty useless there */ @@ -531,6 +670,7 @@ context->appdata->map.pos.lon = lon; } + printf("on_map_button_release_event out\n"); return FALSE; } @@ -584,81 +724,10 @@ } #endif -/* draw geocaches and set window title */ -static void map_setup(map_context_t *context) { - char *name = NULL; - - if(!context->appdata->cur_gpx && !context->appdata->cur_cache) { - if(context->state != MAP_ALL) { - printf("map_setp(ALL)\n"); - - /* no navigation in this mode */ - osm_gps_map_osd_clear_nav (OSM_GPS_MAP(context->widget)); +/* 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)); - - /* 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")); - context->state = MAP_ALL; - } - } else if(!context->appdata->cur_cache) { - if(context->state != MAP_GPX) { - printf("map_setp(GPX)\n"); - - /* no navigation in this mode */ - osm_gps_map_osd_clear_nav (OSM_GPS_MAP(context->widget)); - - /* clear all existing ccahe images */ - osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); - - map_draw_gpx(context->appdata, context->widget, - context->appdata->cur_gpx); - name = g_strdup(context->appdata->cur_gpx->name); - context->state = MAP_GPX; - } - } else { - cache_t *cache = context->appdata->cur_cache; - - printf("map_setp(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)); - - map_draw_cache(context->widget, cache); - name = g_strdup(cache->name); - context->state = MAP_CACHE; - - /* navigation in this mode! */ - pos_t cpos = gpx_cache_pos(cache); - osm_gps_map_osd_draw_nav (OSM_GPS_MAP(context->widget), - context->appdata->imperial, - cpos.lat, cpos.lon, cache->name); - } - - if(name) { - char *title = g_strdup_printf("%s - %s", _("Map"), name); - g_free(name); - - gtk_window_set_title(GTK_WINDOW(context->window), title); - - g_free(title); - } else - printf("map_setup(keep)\n"); -} - -/* 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 */ static gboolean on_focus_in(GtkWidget *widget, GdkEventFocus *event, gpointer data) { printf("map got focus\n"); @@ -667,6 +736,7 @@ } void map_update(appdata_t *appdata) { + printf("map_update\n"); #ifndef USE_MAEMO if(appdata->map.context) map_setup(appdata->map.context); @@ -676,6 +746,8 @@ void map(appdata_t *appdata) { map_context_t *context = NULL; + printf("map 1\n"); + /* if the map window already exists, just raise it */ if(appdata->map.context) { printf("using existing map!\n"); @@ -684,6 +756,8 @@ return; } + printf("map 2\n"); + context = appdata->map.context = g_new0(map_context_t, 1); context->appdata = appdata; context->map_complete = FALSE; @@ -696,6 +770,8 @@ rmdir_recursive(old_path); } + printf("map 3\n"); + /* 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) */ @@ -718,6 +794,8 @@ gint source = context->appdata->map.source; if(!source) source = MAP_SOURCE; + printf("map 4\n"); + context->widget = g_object_new(OSM_TYPE_GPS_MAP, "map-source", source, "tile-cache", path, @@ -731,6 +809,8 @@ osm_gps_map_osd_classic_init(OSM_GPS_MAP(context->widget)); + printf("map 5\n"); + #ifdef USE_MAEMO /* we don't use a stackable window here on fremantle, since */ /* this leaves the main window independent from the map and */ @@ -745,8 +825,7 @@ context->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); #endif - /* setup cache state */ - map_setup(context); + printf("map 6\n"); #ifndef USE_MAEMO gtk_window_set_default_size(GTK_WINDOW(context->window), 640, 480); @@ -767,15 +846,23 @@ /* install handler for timed updates of the gps button */ context->handler_id = gtk_timeout_add(1000, map_gps_update, context); + printf("map 7\n"); + #if MAEMO_VERSION_MAJOR == 5 /* prevent some of the main screen things */ context->old_view = appdata->cur_view; appdata->cur_view = NULL; #endif + printf("map 8\n"); + g_signal_connect(G_OBJECT(context->window), "destroy", G_CALLBACK(on_window_destroy), context); + printf("map 9\n"); gtk_container_add(GTK_CONTAINER(context->window), context->widget); + printf("map 10\n"); gtk_widget_show_all(GTK_WIDGET(context->window)); + + printf("map 11\n"); }