Diff of /trunk/src/map-tool.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 205 by harbaum, Mon Nov 23 20:12:22 2009 UTC revision 297 by harbaum, Wed Aug 25 12:24:38 2010 UTC
# Line 41  Line 41 
41  #include <X11/Xatom.h>  #include <X11/Xatom.h>
42  #endif  #endif
43    
44    /* any defined key enables key support */
45    #if (defined(MAP_KEY_FULLSCREEN) || \
46         defined(MAP_KEY_ZOOMIN) || \
47         defined(MAP_KEY_ZOOMOUT) || \
48         defined(MAP_KEY_UP) || \
49         defined(MAP_KEY_DOWN) || \
50         defined(MAP_KEY_LEFT) || \
51         defined(MAP_KEY_RIGHT))
52    #include <gdk/gdkkeysyms.h>
53    #endif
54    
55  /* default values */  /* default values */
56  #define MAP_SOURCE  OSM_GPS_MAP_SOURCE_OPENCYCLEMAP  #define MAP_SOURCE  OSM_GPS_MAP_SOURCE_OPENCYCLEMAP
57  #define GPS_DEFAULT_ZOOM 13  #define GPS_DEFAULT_ZOOM 13
# Line 84  static const char *get_proxy_uri(appdata Line 95  static const char *get_proxy_uri(appdata
95    return NULL;    return NULL;
96  }  }
97    
98    
99    pos_t *map_gps_get_pos(map_context_t *context) {
100      static pos_t pos;
101    
102      if(context->gps.set & FIX_LATLON_SET) {
103        pos.lat = context->gps.fix.latitude;
104        pos.lon = context->gps.fix.longitude;
105        return &pos;
106      }
107    
108      return NULL;
109    }
110    
111    pos_t *map_get_pos(map_context_t *context) {
112      pos_t *pos = &context->appdata->home;
113    
114      if(context->appdata->active_location) {
115        int i = context->appdata->active_location-1;
116        location_t *loc = context->appdata->location;
117        while(i--) loc = loc->next;
118        pos = &loc->pos;
119      }
120    
121      if(context->appdata->use_gps)
122        pos = map_gps_get_pos(context);
123    
124      return pos;
125    }
126    
127    float map_gps_get_heading(map_context_t *context) {
128      if(context->gps.set & FIX_TRACK_SET)
129        return context->gps.fix.track;
130    
131      return NAN;
132    }
133    
134    float map_gps_get_eph(map_context_t *context) {
135      if(context->gps.set & FIX_HERR_SET)
136        return context->gps.fix.eph;
137    
138      return NAN;
139    }
140    
141    /* callback called by the gps layer whenever gps state changes */
142    static void
143    gps_callback(gps_mask_t set, struct gps_t *fix, void *data) {
144      map_context_t *context = (map_context_t*)data;
145    
146      printf("map: gps callback\n");
147    
148      context->gps.set = set;
149      memcpy(&context->gps.fix, fix, sizeof(struct gps_t));
150    }
151    
152  static void  static void
153  cb_map_gps(osd_button_t but, map_context_t *context) {  cb_map_gps(osd_button_t but, map_context_t *context) {
154    
# Line 115  static int dist2pixel(map_context_t *con Line 180  static int dist2pixel(map_context_t *con
180    
181  static gboolean map_gps_update(gpointer data) {  static gboolean map_gps_update(gpointer data) {
182    map_context_t *context = (map_context_t*)data;    map_context_t *context = (map_context_t*)data;
183    static gboolean goto_is_enabled = FALSE;  
184    #ifdef USE_MAEMO
185      if(context->appdata->goto_disable_screensaver)
186        if(osso_display_blanking_pause(context->appdata->osso_context) != OSSO_OK)
187          fprintf(stderr, "error with display blank\n");
188    #endif
189    
190    /* get reference position ... */    /* get reference position ... */
191    pos_t *refpos = get_pos(context->appdata);    pos_t *refpos = map_get_pos(context);
192    gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon);    gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon);
193    
194    /* ... and enable "goto" button if it's valid */    /* ... and enable "goto" button if it's valid */
195    if(ok != goto_is_enabled) {    if(ok != context->goto_is_enabled) {
196      osm_gps_map_osd_enable_gps (OSM_GPS_MAP(context->widget),      osm_gps_map_osd_enable_gps (OSM_GPS_MAP(context->widget),
197                  OSM_GPS_MAP_OSD_CALLBACK(ok?cb_map_gps:NULL), context);                  OSM_GPS_MAP_OSD_CALLBACK(ok?cb_map_gps:NULL), context);
198      goto_is_enabled = ok;      context->goto_is_enabled = ok;
199    }    }
200    
201    if(ok) {    if(ok) {
# Line 133  static gboolean map_gps_update(gpointer Line 203  static gboolean map_gps_update(gpointer
203      int radius = 0;      int radius = 0;
204    
205      if(context->appdata->use_gps) {      if(context->appdata->use_gps) {
206        heading = gps_get_heading(context->appdata);        heading = map_gps_get_heading(context);
207    
208        /* get error */        /* get error */
209        float eph = gps_get_eph(context->appdata);        float eph = map_gps_get_eph(context);
210        if(!isnan(eph))        if(!isnan(eph))
211          radius = dist2pixel(context, eph/1000, refpos->lat);          radius = dist2pixel(context, eph/1000, refpos->lat);
212      }      }
# Line 180  static void map_draw_cache(GtkWidget *ma Line 250  static void map_draw_cache(GtkWidget *ma
250    }    }
251  }  }
252    
253    static void map_draw_wpt(GtkWidget *map, cache_t *cache, wpt_t *wpt) {
254      /* only draw wpts that don't equal the main point */
255      if(pos_differ(&cache->pos, &wpt->pos)) {
256        if(!isnan(wpt->pos.lat) && !isnan(wpt->pos.lon))  {
257          GdkPixbuf *icon =
258            icon_get(ICON_WPT, (wpt->sym!=WPT_SYM_UNKNOWN)?
259                     wpt->sym:WPT_SYM_REFPOINT);
260    
261          osm_gps_map_add_image(OSM_GPS_MAP(map),
262                                wpt->pos.lat, wpt->pos.lon, icon);
263        }
264      }
265    }
266    
267  static void map_draw_gpx(appdata_t *appdata, cache_display_t *caches,  static void map_draw_gpx(appdata_t *appdata, cache_display_t *caches,
268                           GtkWidget *map, gpx_t *gpx,                           GtkWidget *map, gpx_t *gpx,
269                           cache_t *nav, gboolean semi) {                           cache_t *nav, gboolean semi) {
# Line 200  static void map_draw_gpx(appdata_t *appd Line 284  static void map_draw_gpx(appdata_t *appd
284        /* if nav is not given do what semi sais */        /* if nav is not given do what semi sais */
285        map_draw_cache(map, cache, nav?(cache != nav):semi);        map_draw_cache(map, cache, nav?(cache != nav):semi);
286        caches[i].id = cache->id;        caches[i].id = cache->id;
287    
288          /* also draw waypoints of nav cache */
289          if(nav && cache == nav) {
290            wpt_t *wpt = cache->wpt;
291            while(wpt) {
292              map_draw_wpt(map, cache, wpt);
293              wpt = wpt->next;
294            }
295          }
296      }      }
297    
298      cache = cache->next;      cache = cache->next;
299    }    }
300  }  }
301    
302    static cache_t *cache_search_first(gpx_t *gpx, cache_t *cache) {
303      while(gpx) {
304        cache_t *cur = gpx->cache;
305        while(cur) {
306          /* we do a string comparision to make sure that if copies */
307          /* exist, we get the original one */
308          if(!strcmp(cache->id, cur->id))
309             return cur;
310    
311          cur = cur->next;
312        }
313        gpx = gpx->next;
314      }
315      g_assert(FALSE);
316      return NULL;
317    }
318    
319  /* draw geocaches and set window title */  /* draw geocaches and set window title */
320  static void map_setup(map_context_t *context) {  static void map_setup(map_context_t *context) {
321    char *name = NULL;    char *name = NULL;
# Line 227  static void map_setup(map_context_t *con Line 337  static void map_setup(map_context_t *con
337      printf("allocated space to handle %d map icons\n", cache_num);      printf("allocated space to handle %d map icons\n", cache_num);
338    }    }
339    
340    if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {    if(context->appdata->search_results && !context->appdata->cur_cache) {
341      if(context->state != MAP_ALL) {      if(context->state != MAP_SEARCH) {
342        printf("map_setup(ALL)\n");        printf("map_setup(SEARCH)\n");
343    
344        /* clear any pending balloon */        /* clear any pending balloon */
345        context->balloon = NULL;        context->balloon = NULL;
# Line 242  static void map_setup(map_context_t *con Line 352  static void map_setup(map_context_t *con
352    
353        /* clear all existing cache images */        /* clear all existing cache images */
354        osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));        osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));
       memset(context->caches_displayed, 0,  
              (cache_num+1) * sizeof(cache_display_t));  
355    
356        /* draw all geocaches and none is semi-transparent */        if(context->caches_displayed) {
357        gpx_t *gpx = context->appdata->gpx;          memset(context->caches_displayed, 0,
358        while(gpx) {                 (cache_num+1) * sizeof(cache_display_t));
359    
360            /* draw search results and all other gpx files are semi-transparent */
361          map_draw_gpx(context->appdata, context->caches_displayed,          map_draw_gpx(context->appdata, context->caches_displayed,
362                       context->widget, gpx, NULL, FALSE);                       context->widget, context->appdata->search_results,
363          gpx = gpx->next;                       NULL, FALSE);
364        }  
365            gpx_t *gpx = context->appdata->gpx;
366            while(gpx) {
367              map_draw_gpx(context->appdata, context->caches_displayed,
368                           context->widget, gpx, NULL, TRUE);
369    
370        {            gpx = gpx->next;
371          int i=0;          }
         while(context->caches_displayed[i].id) i++;  
         printf("number of caches actually displayed: %d\n", i);  
372        }        }
373          name = g_strdup(_("Search results"));
374          context->state = MAP_SEARCH;
375        }
376      } else if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {
377        if(context->state != MAP_ALL) {
378          printf("map_setup(ALL)\n");
379    
380          /* clear any pending balloon */
381          context->balloon = NULL;
382          osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(context->widget));
383    
384    #ifdef OSD_NAV
385          /* no navigation in this mode */
386          osm_gps_map_osd_clear_nav (OSM_GPS_MAP(context->widget));
387    #endif
388    
389          /* clear all existing cache images */
390          osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));
391          if(context->caches_displayed) {
392            memset(context->caches_displayed, 0,
393                   (cache_num+1) * sizeof(cache_display_t));
394    
395            /* draw all geocaches and none is semi-transparent */
396            gpx_t *gpx = context->appdata->gpx;
397            while(gpx) {
398              map_draw_gpx(context->appdata, context->caches_displayed,
399                           context->widget, gpx, NULL, FALSE);
400              gpx = gpx->next;
401            }
402    
403            {
404              int i=0;
405              while(context->caches_displayed[i].id) i++;
406              printf("number of caches actually displayed: %d\n", i);
407            }
408          }
409        name = g_strdup(_("all"));        name = g_strdup(_("all"));
410        context->state = MAP_ALL;        context->state = MAP_ALL;
411      }      }
# Line 277  static void map_setup(map_context_t *con Line 424  static void map_setup(map_context_t *con
424    
425        /* clear all existing cache images */        /* clear all existing cache images */
426        osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));        osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));
427        memset(context->caches_displayed, 0,        if(context->caches_displayed) {
428               (cache_num+1) * sizeof(cache_display_t));          memset(context->caches_displayed, 0,
429                   (cache_num+1) * sizeof(cache_display_t));
430        /* draw all geocaches and all other gpx files are semi-transparent */  
431        map_draw_gpx(context->appdata, context->caches_displayed,          /* draw all geocaches and all other gpx files are semi-transparent */
432                     context->widget, context->appdata->cur_gpx, NULL, FALSE);          map_draw_gpx(context->appdata, context->caches_displayed,
433                         context->widget, context->appdata->cur_gpx, NULL, FALSE);
434        gpx_t *gpx = context->appdata->gpx;  
435        while(gpx) {          gpx_t *gpx = context->appdata->gpx;
436          if(gpx != context->appdata->cur_gpx)          while(gpx) {
437            map_draw_gpx(context->appdata, context->caches_displayed,            if(gpx != context->appdata->cur_gpx)
438                         context->widget, gpx, NULL, TRUE);              map_draw_gpx(context->appdata, context->caches_displayed,
439                             context->widget, gpx, NULL, TRUE);
440          gpx = gpx->next;  
441              gpx = gpx->next;
442            }
443        }        }
444    
445        name = g_strdup(context->appdata->cur_gpx->name);        name = g_strdup(context->appdata->cur_gpx->name);
# Line 307  static void map_setup(map_context_t *con Line 456  static void map_setup(map_context_t *con
456    
457      /* clear all existing ccahe images */      /* clear all existing ccahe images */
458      osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));      osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));
459      memset(context->caches_displayed, 0,      if(context->caches_displayed) {
460             (cache_num+1) * sizeof(cache_display_t));        memset(context->caches_displayed, 0,
461                 (cache_num+1) * sizeof(cache_display_t));
462      /* draw all geocaches and all but selected one are semi-transparent */  
463      gpx_t *gpx = context->appdata->gpx;        /* Make sure we really work on the first copy in the list as */
464      while(gpx) {        /* only this is being used if duplicates exist */
465        map_draw_gpx(context->appdata, context->caches_displayed,        cache = cache_search_first(context->appdata->gpx, cache);
466                     context->widget, gpx, cache, FALSE);  
467        gpx = gpx->next;        /* draw all geocaches and all but selected one are semi-transparent */
468          gpx_t *gpx = context->appdata->gpx;
469          while(gpx) {
470            map_draw_gpx(context->appdata, context->caches_displayed,
471                         context->widget, gpx, cache, FALSE);
472            gpx = gpx->next;
473          }
474      }      }
475    
476      name = g_strdup(cache->name);      name = g_strdup(cache->name);
# Line 333  static void map_setup(map_context_t *con Line 488  static void map_setup(map_context_t *con
488  #endif  #endif
489    }    }
490    
491    if(name) {    /* also mark geomath position */
     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) {  
   
   /* 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 ||  
        isnan(context->appdata->map.pos.lat) ||  
        isnan(context->appdata->map.pos.lon)) {  
       printf("no valid map position found\n");  
   
       pos_t *refpos = get_pos(context->appdata);  
       if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {  
         printf("use refpos\n");  
492    
493          /* use gps position if present */    /* remove all existing appearances of this icon first */
494          context->appdata->map.pos = *refpos;    osm_gps_map_remove_image(OSM_GPS_MAP(context->widget),
495          context->appdata->map.zoom = GPS_DEFAULT_ZOOM;                             icon_get(ICON_MISC, 4));
496        } else {  
497          printf("use zero pos\n");    if(!isnan(context->appdata->geomath.lat) &&
498         !isnan(context->appdata->geomath.lon))  {
499    
500          /* use world map otherwise */      osm_gps_map_add_image(OSM_GPS_MAP(context->widget),
501          context->appdata->map.pos.lat = 0.0;                            context->appdata->geomath.lat,
502          context->appdata->map.pos.lon = 0.0;                            context->appdata->geomath.lon,
503          context->appdata->map.zoom = 1;                            icon_get(ICON_MISC, 4));
       }  
     }  
   
     /* 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,  
                               context->appdata->map.zoom);  
     context->map_complete = TRUE;  
504    }    }
505    
506    return FALSE;    if(name) {
507        gtk_window_set_title(GTK_WINDOW(context->window), name);
508        g_free(name);
509      } else
510        printf("map_setup(keep)\n");
511  }  }
512    
513  static void  static void
# Line 424  map_cachelist_nearest(cache_t *cache, po Line 533  map_cachelist_nearest(cache_t *cache, po
533  static cache_t *map_closest(map_context_t *context, pos_t *pos) {  static cache_t *map_closest(map_context_t *context, pos_t *pos) {
534    cache_t *result = NULL;    cache_t *result = NULL;
535    float distance = NAN;    float distance = NAN;
536    
537    if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {    if(context->appdata->search_results && !context->appdata->cur_cache) {
538        /* search search results */
539        map_cachelist_nearest(context->appdata->search_results->cache,
540                              pos, &result, &distance);
541      } else if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {
542      /* search all geocaches */      /* search all geocaches */
543      gpx_t *gpx = context->appdata->gpx;      gpx_t *gpx = context->appdata->gpx;
544      while(gpx) {      while(gpx) {
# Line 433  static cache_t *map_closest(map_context_ Line 546  static cache_t *map_closest(map_context_
546        gpx = gpx->next;        gpx = gpx->next;
547      }      }
548    } else if(context->appdata->cur_gpx) {    } else if(context->appdata->cur_gpx) {
549        /* search in current gpx file */
550      map_cachelist_nearest(context->appdata->cur_gpx->cache,      map_cachelist_nearest(context->appdata->cur_gpx->cache,
551                            pos, &result, &distance);                            pos, &result, &distance);
552    } else    } else
553      result = context->appdata->cur_gpx->cache;      result = context->appdata->cur_cache;
554    
555      /* make sure this is the first hit */
556      if(context->caches_displayed)
557        result = cache_search_first(context->appdata->gpx, result);
558    
559    return result;    return result;
560  }  }
# Line 660  balloon_cb(osm_gps_map_balloon_event_t * Line 778  balloon_cb(osm_gps_map_balloon_event_t *
778      printf("click %s event at %d %d\n",      printf("click %s event at %d %d\n",
779             event->data.click.down?"down":"up",             event->data.click.down?"down":"up",
780             event->data.click.x, event->data.click.y);             event->data.click.x, event->data.click.y);
781    
782      /* make the main screen jump to that cache */      /* make the main screen jump to that cache */
783      if(!event->data.click.down) {      if(!event->data.click.down) {
784        if(context->appdata->cur_cache) {        if(context->appdata->cur_cache) {
785          printf("ERROR: no current cache should be visible!\n");          printf("ERROR: no current cache should be visible!\n");
786        } else {        } else {
787          gpx_t *is_in = NULL;          gpx_t *is_in = NULL;
788    
789            if(context->appdata->search_results) {
790              printf("click while in \"search results\" view\n");
791    
792          if(!context->appdata->cur_gpx) {            is_in = context->appdata->search_results;
793            } else if(!context->appdata->cur_gpx) {
794            printf("click while in \"all\" view\n");            printf("click while in \"all\" view\n");
795    
796            /* we first need to figure out which gpx file this cache */            /* we first need to figure out which gpx file this cache */
797            /* is in so we can open it first */            /* is in so we can open it first */
798            gpx_t *gpx = context->appdata->gpx;            gpx_t *gpx = context->appdata->gpx;
# Line 686  balloon_cb(osm_gps_map_balloon_event_t * Line 808  balloon_cb(osm_gps_map_balloon_event_t *
808    
809            if(is_in)            if(is_in)
810              gpxlist_goto_cachelist(context->appdata, is_in);              gpxlist_goto_cachelist(context->appdata, is_in);
811    
812          } else          } else {
813              printf("click while in \"cachelist\" view\n");
814    
815            /* the simple case: there already is an open gpx file and */            /* the simple case: there already is an open gpx file and */
816            /* we just jump into the "cache" view */            /* we just jump into the "cache" view */
817            is_in = context->appdata->cur_gpx;            is_in = context->appdata->cur_gpx;
818            }
819    
820          if(is_in) {          if(is_in) {
821            printf("selecting %s in %s\n",            printf("selecting %s in %s\n",
822                   cache->id,                   cache->id,
823                     context->appdata->search_results?
824                     context->appdata->search_results->name:
825                   context->appdata->cur_gpx->name);                   context->appdata->cur_gpx->name);
826    
827            cachelist_goto_cache(context->appdata, cache);            cachelist_goto_cache(context->appdata, cache);
828    
829            /* give focus to main screen (important for maemo) */            /* give focus to main screen (important for maemo) */
830            printf("raising main window\n");            printf("raising main window\n");
831            gtk_window_present(GTK_WINDOW(context->appdata->window));            gtk_window_present(GTK_WINDOW(context->appdata->window));
# Line 760  static void on_window_destroy(GtkWidget Line 887  static void on_window_destroy(GtkWidget
887    g_object_get(map, "zoom", &zoom, NULL);    g_object_get(map, "zoom", &zoom, NULL);
888    context->appdata->map.zoom = zoom;    context->appdata->map.zoom = zoom;
889    
890      gboolean dpix;
891      g_object_get(map, "double-pixel", &dpix, NULL);
892      context->appdata->map.dpix = dpix;
893    
894    gfloat lat, lon;    gfloat lat, lon;
895    g_object_get(map, "latitude", &lat, "longitude", &lon, NULL);    g_object_get(map, "latitude", &lat, "longitude", &lon, NULL);
896    context->appdata->map.pos.lat = lat;    context->appdata->map.pos.lat = lat;
# Line 775  static void on_window_destroy(GtkWidget Line 906  static void on_window_destroy(GtkWidget
906  #endif  #endif
907    
908    gtk_timeout_remove(context->handler_id);    gtk_timeout_remove(context->handler_id);
   gps_unregister_callback(appdata, context->cb_id);  
909    
910    if(context->caches_displayed) {    if(context->caches_displayed) {
911      g_free(context->caches_displayed);      g_free(context->caches_displayed);
912      context->caches_displayed = NULL;      context->caches_displayed = NULL;
913    }    }
914    
915      printf("destroy map context\n");
916    g_free(context);    g_free(context);
917    appdata->map.context = NULL;    appdata->map.context = NULL;
918  }  }
# Line 821  static gboolean on_focus_in(GtkWidget *w Line 952  static gboolean on_focus_in(GtkWidget *w
952      context->handler_id = gtk_timeout_add(1000, map_gps_update, context);      context->handler_id = gtk_timeout_add(1000, map_gps_update, context);
953  #endif  #endif
954    
955      gps_register_callback(context->appdata->gps_state,
956                            LATLON_CHANGED | HERR_CHANGED | TRACK_CHANGED,
957                            gps_callback, context);
958    
959    map_setup(context);    map_setup(context);
960    return FALSE;    return FALSE;
961  }  }
962    
 #ifdef USE_MAEMO  
963  static gboolean on_focus_out(GtkWidget *widget, GdkEventFocus *event,  static gboolean on_focus_out(GtkWidget *widget, GdkEventFocus *event,
964                           gpointer data) {                           gpointer data) {
965    map_context_t *context = (map_context_t*)data;    map_context_t *context = (map_context_t*)data;
966    
967    printf("map lost focus\n");    printf("map lost focus\n");
968    
969      /* save new map position */
970      gfloat lat, lon;
971      g_object_get(widget, "latitude", &lat, "longitude", &lon, NULL);
972    
973      context->appdata->map.pos.lat = lat;
974      context->appdata->map.pos.lon = lon;
975    
976    #ifdef USE_MAEMO
977    gtk_timeout_remove(context->handler_id);    gtk_timeout_remove(context->handler_id);
978    context->handler_id = 0;    context->handler_id = 0;
979    #endif
980    
981      gps_unregister_callback(context->appdata->gps_state, gps_callback);
982    
983    return FALSE;    return FALSE;
984  }  }
 #endif  
985    
986  void map_update(appdata_t *appdata) {  void map_update(appdata_t *appdata) {
987    printf("map_update\n");    printf("map_update\n");
# Line 846  void map_update(appdata_t *appdata) { Line 991  void map_update(appdata_t *appdata) {
991  #endif  #endif
992  }  }
993    
994  /* callback called by the gps layer whenever gps state changes */  static gboolean
995  static void  on_map_window_key_press(GtkWidget *window, GdkEventKey *event, GtkWidget *map)  {
996  gps_callback(struct gps_state *state, gpointer data) {  #ifdef USE_MAEMO
997    printf("map: gps callback\n");    if((event->keyval == HILDON_HARDKEY_FULLSCREEN) ||
998         (event->keyval == HILDON_HARDKEY_INCREASE) ||
999         (event->keyval == HILDON_HARDKEY_DECREASE))
1000    #else
1001      if(event->keyval == GDK_F11)
1002    #endif
1003      {
1004        gboolean return_val;
1005        g_signal_emit_by_name(GTK_OBJECT(map), "key_press_event",
1006                              event, &return_val);
1007        return return_val;
1008      }
1009    
1010      return FALSE;
1011  }  }
1012    
1013  void map(appdata_t *appdata) {  void map(appdata_t *appdata) {
# Line 864  void map(appdata_t *appdata) { Line 1022  void map(appdata_t *appdata) {
1022    }    }
1023    
1024    context = appdata->map.context = g_new0(map_context_t, 1);    context = appdata->map.context = g_new0(map_context_t, 1);
1025      printf("allocated new context at %p\n", context);
1026    
1027    context->appdata = appdata;    context->appdata = appdata;
   context->map_complete = FALSE;  
1028    context->state = MAP_NONE;    context->state = MAP_NONE;
1029    
1030    /* cleanup old (pre 0.8.7) path if it exists */    /* cleanup old (pre 0.8.7) path if it exists */
# Line 899  void map(appdata_t *appdata) { Line 1058  void map(appdata_t *appdata) {
1058    
1059    context->widget = g_object_new(OSM_TYPE_GPS_MAP,    context->widget = g_object_new(OSM_TYPE_GPS_MAP,
1060                   "map-source",               source,                   "map-source",               source,
1061                   "tile-cache",               path,                   "tile-cache",               OSM_GPS_MAP_CACHE_FRIENDLY,
1062                     "tile-cache-base",          path,
1063                   "auto-center",              FALSE,                   "auto-center",              FALSE,
1064                   "record-trip-history",      FALSE,                   "record-trip-history",      FALSE,
1065                   "show-trip-history",        FALSE,                   "show-trip-history",        FALSE,
1066                     "double-pixel",             context->appdata->map.dpix,
1067                   proxy?"proxy-uri":NULL,     proxy,                   proxy?"proxy-uri":NULL,     proxy,
1068                   NULL);                   NULL);
1069    
# Line 910  void map(appdata_t *appdata) { Line 1071  void map(appdata_t *appdata) {
1071    
1072    osm_gps_map_osd_classic_init(OSM_GPS_MAP(context->widget));    osm_gps_map_osd_classic_init(OSM_GPS_MAP(context->widget));
1073    
1074      /* set default values if they are invalid */
1075      if(!context->appdata->map.zoom ||
1076         isnan(context->appdata->map.pos.lat) ||
1077         isnan(context->appdata->map.pos.lon)) {
1078        printf("no valid map position found\n");
1079    
1080        pos_t *refpos = get_pos(context->appdata);
1081        if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {
1082          printf("use refpos\n");
1083    
1084            /* use gps position if present */
1085          context->appdata->map.pos = *refpos;
1086          context->appdata->map.zoom = GPS_DEFAULT_ZOOM;
1087        } else {
1088          printf("use zero pos\n");
1089    
1090          /* use world map otherwise */
1091          context->appdata->map.pos.lat = 0.0;
1092          context->appdata->map.pos.lon = 0.0;
1093          context->appdata->map.zoom = 1;
1094        }
1095      }
1096    
1097      int key_maps[][2] = {
1098        { OSM_GPS_MAP_KEY_FULLSCREEN, MAP_KEY_FULLSCREEN },
1099        { OSM_GPS_MAP_KEY_ZOOMIN, MAP_KEY_ZOOMIN },
1100        { OSM_GPS_MAP_KEY_ZOOMOUT, MAP_KEY_ZOOMOUT },
1101        { OSM_GPS_MAP_KEY_UP, MAP_KEY_UP },
1102        { OSM_GPS_MAP_KEY_DOWN, MAP_KEY_DOWN },
1103        { OSM_GPS_MAP_KEY_LEFT, MAP_KEY_LEFT },
1104        { OSM_GPS_MAP_KEY_RIGHT, MAP_KEY_RIGHT },
1105        { OSM_GPS_MAP_KEY_MAX, 0 } };
1106    
1107      int i;
1108      for(i=0;key_maps[i][0] != OSM_GPS_MAP_KEY_MAX;i++)
1109        osm_gps_map_set_keyboard_shortcut(OSM_GPS_MAP(context->widget),
1110                                          key_maps[i][0], key_maps[i][1]);
1111    
1112      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),
1113                                context->appdata->map.pos.lat,
1114                                context->appdata->map.pos.lon,
1115                                context->appdata->map.zoom);
1116    
1117  #ifdef USE_MAEMO  #ifdef USE_MAEMO
1118    /* we don't use a stackable window here on fremantle, since */    /* we don't use a stackable window here on fremantle, since */
1119    /* this leaves the main window independent from the map and */    /* this leaves the main window independent from the map and */
# Line 931  void map(appdata_t *appdata) { Line 1135  void map(appdata_t *appdata) {
1135    g_signal_connect(G_OBJECT(context->widget), "focus-in-event",    g_signal_connect(G_OBJECT(context->widget), "focus-in-event",
1136                     G_CALLBACK(on_focus_in), context);                     G_CALLBACK(on_focus_in), context);
1137    
 #ifdef USE_MAEMO  
1138    g_signal_connect(G_OBJECT(context->widget), "focus-out-event",    g_signal_connect(G_OBJECT(context->widget), "focus-out-event",
1139                     G_CALLBACK(on_focus_out), context);                     G_CALLBACK(on_focus_out), context);
 #endif  
   
   g_signal_connect(G_OBJECT(context->widget), "configure-event",  
                    G_CALLBACK(on_map_configure), context);  
1140    
1141    g_signal_connect(G_OBJECT(context->widget), "button-press-event",    g_signal_connect(G_OBJECT(context->widget), "button-press-event",
1142                     G_CALLBACK(on_map_button_press_event), context);                     G_CALLBACK(on_map_button_press_event), context);
# Line 947  void map(appdata_t *appdata) { Line 1146  void map(appdata_t *appdata) {
1146    
1147    /* install handler for timed updates of the gps button */    /* install handler for timed updates of the gps button */
1148    context->handler_id = gtk_timeout_add(1000, map_gps_update, context);    context->handler_id = gtk_timeout_add(1000, map_gps_update, context);
   context->cb_id = gps_register_callback(appdata, gps_callback, context);  
1149    
1150  #if MAEMO_VERSION_MAJOR == 5  #if MAEMO_VERSION_MAJOR == 5
1151    /* prevent some of the main screen things */    /* prevent some of the main screen things */
# Line 958  void map(appdata_t *appdata) { Line 1156  void map(appdata_t *appdata) {
1156    g_signal_connect(G_OBJECT(context->window), "destroy",    g_signal_connect(G_OBJECT(context->window), "destroy",
1157                     G_CALLBACK(on_window_destroy), context);                     G_CALLBACK(on_window_destroy), context);
1158    
1159      /* connect a key handler to forward global shortcuts (function keys) */
1160      /* to the ap widget */
1161      g_signal_connect(G_OBJECT(context->window), "key_press_event",
1162                       G_CALLBACK(on_map_window_key_press), context->widget);
1163    
1164    gtk_container_add(GTK_CONTAINER(context->window), context->widget);    gtk_container_add(GTK_CONTAINER(context->window), context->widget);
1165    gtk_widget_show_all(GTK_WIDGET(context->window));    gtk_widget_show_all(GTK_WIDGET(context->window));
1166    
1167      /* setup cache state */
1168      map_setup(context);
1169  }  }

Legend:
Removed from v.205  
changed lines
  Added in v.297