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

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

revision 143 by harbaum, Mon Oct 26 19:55:00 2009 UTC revision 149 by harbaum, Thu Oct 29 13:59:16 2009 UTC
# Line 45  Line 45 
45  static const char *get_proxy_uri(appdata_t *appdata) {  static const char *get_proxy_uri(appdata_t *appdata) {
46    static char proxy_buffer[64] = "";    static char proxy_buffer[64] = "";
47    
   printf("get_proxy_uri in\n");  
   
48    /* use environment settings if preset */    /* use environment settings if preset */
49    const char *proxy = g_getenv("http_proxy");    const char *proxy = g_getenv("http_proxy");
50    if(proxy) {    if(proxy) {
# Line 77  static const char *get_proxy_uri(appdata Line 75  static const char *get_proxy_uri(appdata
75      return proxy_buffer;      return proxy_buffer;
76    }    }
77    
   printf("get_proxy_uri out\n");  
78    return NULL;    return NULL;
79  }  }
80    
81  static void  static void
82  cb_map_gps(osd_button_t but, map_context_t *context) {  cb_map_gps(osd_button_t but, map_context_t *context) {
   printf("cb_map_gps in\n");  
83    
84    if(but == OSD_GPS) {    if(but == OSD_GPS) {
85      pos_t *refpos = get_pos(context->appdata);      pos_t *refpos = get_pos(context->appdata);
# Line 105  cb_map_gps(osd_button_t but, map_context Line 101  cb_map_gps(osd_button_t but, map_context
101                                  0.0, 0.0, 1);                                  0.0, 0.0, 1);
102      }      }
103    }    }
   printf("cb_map_gps out\n");  
104  }  }
105    
106  static int dist2pixel(map_context_t *context, float km, float lat) {  static int dist2pixel(map_context_t *context, float km, float lat) {
# Line 114  static int dist2pixel(map_context_t *con Line 109  static int dist2pixel(map_context_t *con
109    
110  static gboolean map_gps_update(gpointer data) {  static gboolean map_gps_update(gpointer data) {
111    map_context_t *context = (map_context_t*)data;    map_context_t *context = (map_context_t*)data;
112      static gboolean goto_is_enabled = FALSE;
   printf("map_gps_update in\n");  
113    
114    /* get reference position ... */    /* get reference position ... */
115    pos_t *refpos = get_pos(context->appdata);    pos_t *refpos = get_pos(context->appdata);
116    gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon);    gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon);
117    
118    /* ... and enable "goto" button if it's valid */    /* ... and enable "goto" button if it's valid */
119    osm_gps_map_osd_enable_gps (OSM_GPS_MAP(context->widget),    if(ok != goto_is_enabled) {
120                   OSM_GPS_MAP_OSD_CALLBACK(ok?cb_map_gps:NULL), context);      osm_gps_map_osd_enable_gps (OSM_GPS_MAP(context->widget),
121                    OSM_GPS_MAP_OSD_CALLBACK(ok?cb_map_gps:NULL), context);
122        goto_is_enabled = ok;
123      }
124    
125    if(ok) {    if(ok) {
126      float heading = NAN;      float heading = NAN;
# Line 138  static gboolean map_gps_update(gpointer Line 135  static gboolean map_gps_update(gpointer
135          radius = dist2pixel(context, eph/1000, refpos->lat);          radius = dist2pixel(context, eph/1000, refpos->lat);
136      }      }
137    
138        /* TODO: in order to save energy: only draw if state actually changed */
139    
140      g_object_set(context->widget, "gps-track-highlight-radius", radius, NULL);      g_object_set(context->widget, "gps-track-highlight-radius", radius, NULL);
141      osm_gps_map_draw_gps(OSM_GPS_MAP(context->widget),      osm_gps_map_draw_gps(OSM_GPS_MAP(context->widget),
142                           refpos->lat, refpos->lon, heading);                           refpos->lat, refpos->lon, heading);
143    } else    } else
144      osm_gps_map_clear_gps(OSM_GPS_MAP(context->widget));      osm_gps_map_clear_gps(OSM_GPS_MAP(context->widget));
145    
   printf("map_gps_update out\n");  
146    return TRUE;    return TRUE;
147  }  }
148    
149  static void map_draw_cache(GtkWidget *map, cache_t *cache) {  static void map_draw_cache(GtkWidget *map, cache_t *cache) {
   printf("map_draw_cache in\n");  
   
150    GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type);    GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type);
151    
152    /* check if there's also an overwritten coordinate */    /* check if there's also an overwritten coordinate */
# Line 167  static void map_draw_cache(GtkWidget *ma Line 163  static void map_draw_cache(GtkWidget *ma
163        osm_gps_map_add_image(OSM_GPS_MAP(map),        osm_gps_map_add_image(OSM_GPS_MAP(map),
164                              cache->pos.lat, cache->pos.lon, icon);                              cache->pos.lat, cache->pos.lon, icon);
165    }    }
   printf("map_draw_cache out\n");  
166  }  }
167    
168  static void map_draw_gpx(appdata_t *appdata, GtkWidget *map, gpx_t *gpx) {  static void map_draw_gpx(appdata_t *appdata, GtkWidget *map, gpx_t *gpx) {
   printf("map_draw_gpx in\n");  
   
169    if(!gpx->notes_loaded) {    if(!gpx->notes_loaded) {
170      notes_load_all(appdata, gpx);      notes_load_all(appdata, gpx);
171      gpx->notes_loaded = TRUE;      gpx->notes_loaded = TRUE;
# Line 183  static void map_draw_gpx(appdata_t *appd Line 176  static void map_draw_gpx(appdata_t *appd
176      map_draw_cache(map, cache);      map_draw_cache(map, cache);
177      cache = cache->next;      cache = cache->next;
178    }    }
   printf("map_draw_gpx out\n");  
179  }  }
180    
181  /* draw geocaches and set window title */  /* draw geocaches and set window title */
182  static void map_setup(map_context_t *context) {  static void map_setup(map_context_t *context) {
183    char *name = NULL;    char *name = NULL;
184    
   printf("map_setup in\n");  
   
185    if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {    if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {
186      if(context->state != MAP_ALL) {      if(context->state != MAP_ALL) {
187        printf("map_setup(ALL)\n");        printf("map_setup(ALL)\n");
# Line 267  static void map_setup(map_context_t *con Line 257  static void map_setup(map_context_t *con
257      g_free(title);      g_free(title);
258    } else    } else
259      printf("map_setup(keep)\n");      printf("map_setup(keep)\n");
   
   printf("map_setup out\n");  
260  }  }
261    
262  static gboolean on_map_configure(GtkWidget *widget,  static gboolean on_map_configure(GtkWidget *widget,
# Line 325  static gboolean on_map_configure(GtkWidg Line 313  static gboolean on_map_configure(GtkWidg
313      context->map_complete = TRUE;      context->map_complete = TRUE;
314    }    }
315    
   printf("map configure done\n");  
316    return FALSE;    return FALSE;
317  }  }
318    
319  static void  static void
320  map_cachelist_nearest(cache_t *cache, pos_t *pos,  map_cachelist_nearest(cache_t *cache, pos_t *pos,
321                        cache_t **result, float *distance) {                        cache_t **result, float *distance) {
322    printf("map_cachelist_nearest in\n");  
323    while(cache) {    while(cache) {
324      pos_t cpos = gpx_cache_pos(cache);      pos_t cpos = gpx_cache_pos(cache);
325    
# Line 347  map_cachelist_nearest(cache_t *cache, po Line 334  map_cachelist_nearest(cache_t *cache, po
334    
335      cache = cache->next;      cache = cache->next;
336    }    }
   printf("map_cachelist_nearest out\n");  
337  }  }
338    
339  static cache_t *map_closest(map_context_t *context, pos_t *pos) {  static cache_t *map_closest(map_context_t *context, pos_t *pos) {
340    cache_t *result = NULL;    cache_t *result = NULL;
341    float distance = NAN;    float distance = NAN;
342    
   printf("map_closest in\n");  
   
343    if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {    if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {
344      /* search all geocaches */      /* search all geocaches */
345      gpx_t *gpx = context->appdata->gpx;      gpx_t *gpx = context->appdata->gpx;
# Line 369  static cache_t *map_closest(map_context_ Line 353  static cache_t *map_closest(map_context_
353    } else    } else
354      result = context->appdata->cur_gpx->cache;      result = context->appdata->cur_gpx->cache;
355    
   printf("map_closest out\n");  
356    return result;    return result;
357  }  }
358    
# Line 386  pos_t coord2pos(coord_t coo) { Line 369  pos_t coord2pos(coord_t coo) {
369  static gboolean  static gboolean
370  on_map_button_press_event(GtkWidget *widget,  on_map_button_press_event(GtkWidget *widget,
371                              GdkEventButton *event, map_context_t *context) {                              GdkEventButton *event, map_context_t *context) {
   printf("on_map_button_press_event in\n");  
372    
373    OsmGpsMap *map = OSM_GPS_MAP(context->widget);    OsmGpsMap *map = OSM_GPS_MAP(context->widget);
374    
375    /* check if we actually clicked parts of the OSD */    /* check if we actually clicked parts of the OSD */
376    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");  
377      return FALSE;      return FALSE;
   }  
378    
379    /* got a press event without release event? eat it! */    /* got a press event without release event? eat it! */
380    if(context->press_on != NULL) {    if(context->press_on != NULL) {
# Line 414  on_map_button_press_event(GtkWidget *wid Line 394  on_map_button_press_event(GtkWidget *wid
394        context->press_on = nearest;        context->press_on = nearest;
395    }    }
396    
   printf("on_map_button_press_event out\n");  
397    return FALSE;    return FALSE;
398  }  }
399    
# Line 422  static void Line 401  static void
401  cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *buf, gint x, gint y) {  cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *buf, gint x, gint y) {
402    /* convert the pixbuf into something cairo can handle */    /* convert the pixbuf into something cairo can handle */
403    
   printf("cairo_draw_pixbuf in\n");  
   
404    // Create a new ImageSurface    // Create a new ImageSurface
405    cairo_surface_t *image_surface =    cairo_surface_t *image_surface =
406      cairo_image_surface_create(CAIRO_FORMAT_ARGB32,      cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
# Line 441  cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf Line 418  cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf
418    cairo_set_source_surface(cr, image_surface, x, y);    cairo_set_source_surface(cr, image_surface, x, y);
419    
420    cairo_paint(cr);    cairo_paint(cr);
   printf("cairo_draw_pixbuf out\n");  
421  }  }
422    
423  #ifndef BIG_BALLOONS  #ifndef BIG_BALLOONS
# Line 452  cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf Line 428  cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf
428    
429  static void  static void
430  balloon_cb(osm_gps_map_balloon_event_t *event, gpointer data) {  balloon_cb(osm_gps_map_balloon_event_t *event, gpointer data) {
431    printf("balloon event:\n");    printf("balloon event: ");
432    
433    map_context_t *context = (map_context_t*)data;    map_context_t *context = (map_context_t*)data;
434    cache_t *cache = context->balloon;    cache_t *cache = context->balloon;
# Line 628  balloon_cb(osm_gps_map_balloon_event_t * Line 604  balloon_cb(osm_gps_map_balloon_event_t *
604      printf("removed\n");      printf("removed\n");
605      context->balloon = NULL;      context->balloon = NULL;
606    }    }
   printf("balloon out\n");  
607  }  }
608    
609  static gboolean  static gboolean
# Line 636  on_map_button_release_event(GtkWidget *w Line 611  on_map_button_release_event(GtkWidget *w
611                              GdkEventButton *event, map_context_t *context) {                              GdkEventButton *event, map_context_t *context) {
612    OsmGpsMap *map = OSM_GPS_MAP(context->widget);    OsmGpsMap *map = OSM_GPS_MAP(context->widget);
613    
   printf("on_map_button_release_event in\n");  
   
614    /* in "MAP_CACHE" state only one cache is visible */    /* in "MAP_CACHE" state only one cache is visible */
615    /* and the map is in navigation mode. the balloon is */    /* and the map is in navigation mode. the balloon is */
616    /* pretty useless there */    /* pretty useless there */
# Line 670  on_map_button_release_event(GtkWidget *w Line 643  on_map_button_release_event(GtkWidget *w
643      context->appdata->map.pos.lon = lon;      context->appdata->map.pos.lon = lon;
644    }    }
645    
   printf("on_map_button_release_event out\n");  
646    return FALSE;    return FALSE;
647  }  }
648    
649  static void on_window_destroy(GtkWidget *widget, map_context_t *context) {  static void on_window_destroy(GtkWidget *widget, map_context_t *context) {
650    appdata_t *appdata = context->appdata;    appdata_t *appdata = context->appdata;
651    
   printf("destroy map window\n");  
   
652    /* save map parameters */    /* save map parameters */
653    OsmGpsMap *map = OSM_GPS_MAP(context->widget);    OsmGpsMap *map = OSM_GPS_MAP(context->widget);
654    gint zoom;    gint zoom;
# Line 700  static void on_window_destroy(GtkWidget Line 670  static void on_window_destroy(GtkWidget
670  #endif  #endif
671    
672    gtk_timeout_remove(context->handler_id);    gtk_timeout_remove(context->handler_id);
673      gps_unregister_callback(appdata, context->cb_id);
674    
675    g_free(context);    g_free(context);
676    appdata->map.context = NULL;    appdata->map.context = NULL;
# Line 743  void map_update(appdata_t *appdata) { Line 714  void map_update(appdata_t *appdata) {
714  #endif  #endif
715  }  }
716    
717    /* callback called by the gps layer whenever gps state changes */
718    static void
719    gps_callback(struct gps_state *state, gpointer data) {
720      printf("map: gps callback\n");
721    }
722    
723  void map(appdata_t *appdata) {  void map(appdata_t *appdata) {
724    map_context_t *context = NULL;    map_context_t *context = NULL;
725    
   printf("map 1\n");  
   
726    /* if the map window already exists, just raise it */    /* if the map window already exists, just raise it */
727    if(appdata->map.context) {    if(appdata->map.context) {
728      printf("using existing map!\n");      printf("using existing map!\n");
# Line 756  void map(appdata_t *appdata) { Line 731  void map(appdata_t *appdata) {
731      return;      return;
732    }    }
733    
   printf("map 2\n");  
   
734    context = appdata->map.context = g_new0(map_context_t, 1);    context = appdata->map.context = g_new0(map_context_t, 1);
735    context->appdata = appdata;    context->appdata = appdata;
736    context->map_complete = FALSE;    context->map_complete = FALSE;
# Line 770  void map(appdata_t *appdata) { Line 743  void map(appdata_t *appdata) {
743      rmdir_recursive(old_path);      rmdir_recursive(old_path);
744    }    }
745    
   printf("map 3\n");  
   
746    /* It is recommanded that all applications share these same */    /* It is recommanded that all applications share these same */
747    /* map path, so data is only cached once. The path should be: */    /* map path, so data is only cached once. The path should be: */
748    /* ~/.osm-gps-map on standard PC     (users home) */    /* ~/.osm-gps-map on standard PC     (users home) */
# Line 794  void map(appdata_t *appdata) { Line 765  void map(appdata_t *appdata) {
765    gint source = context->appdata->map.source;    gint source = context->appdata->map.source;
766    if(!source) source = MAP_SOURCE;    if(!source) source = MAP_SOURCE;
767    
   printf("map 4\n");  
   
768    context->widget = g_object_new(OSM_TYPE_GPS_MAP,    context->widget = g_object_new(OSM_TYPE_GPS_MAP,
769                   "map-source",               source,                   "map-source",               source,
770                   "tile-cache",               path,                   "tile-cache",               path,
# Line 809  void map(appdata_t *appdata) { Line 778  void map(appdata_t *appdata) {
778    
779    osm_gps_map_osd_classic_init(OSM_GPS_MAP(context->widget));    osm_gps_map_osd_classic_init(OSM_GPS_MAP(context->widget));
780    
   printf("map 5\n");  
   
781  #ifdef USE_MAEMO  #ifdef USE_MAEMO
782    /* we don't use a stackable window here on fremantle, since */    /* we don't use a stackable window here on fremantle, since */
783    /* this leaves the main window independent from the map and */    /* this leaves the main window independent from the map and */
# Line 825  void map(appdata_t *appdata) { Line 792  void map(appdata_t *appdata) {
792    context->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);    context->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
793  #endif  #endif
794    
   printf("map 6\n");  
   
795  #ifndef USE_MAEMO  #ifndef USE_MAEMO
796    gtk_window_set_default_size(GTK_WINDOW(context->window), 640, 480);    gtk_window_set_default_size(GTK_WINDOW(context->window), 640, 480);
797  #endif  #endif
# Line 845  void map(appdata_t *appdata) { Line 810  void map(appdata_t *appdata) {
810    
811    /* install handler for timed updates of the gps button */    /* install handler for timed updates of the gps button */
812    context->handler_id = gtk_timeout_add(1000, map_gps_update, context);    context->handler_id = gtk_timeout_add(1000, map_gps_update, context);
813      context->cb_id = gps_register_callback(appdata, gps_callback, context);
   printf("map 7\n");  
814    
815  #if MAEMO_VERSION_MAJOR == 5  #if MAEMO_VERSION_MAJOR == 5
816    /* prevent some of the main screen things */    /* prevent some of the main screen things */
# Line 854  void map(appdata_t *appdata) { Line 818  void map(appdata_t *appdata) {
818    appdata->cur_view = NULL;    appdata->cur_view = NULL;
819  #endif  #endif
820    
   printf("map 8\n");  
   
821    g_signal_connect(G_OBJECT(context->window), "destroy",    g_signal_connect(G_OBJECT(context->window), "destroy",
822                     G_CALLBACK(on_window_destroy), context);                     G_CALLBACK(on_window_destroy), context);
823    
   printf("map 9\n");  
824    gtk_container_add(GTK_CONTAINER(context->window), context->widget);    gtk_container_add(GTK_CONTAINER(context->window), context->widget);
   printf("map 10\n");  
825    gtk_widget_show_all(GTK_WIDGET(context->window));    gtk_widget_show_all(GTK_WIDGET(context->window));
   
   printf("map 11\n");  
826  }  }

Legend:
Removed from v.143  
changed lines
  Added in v.149