53 |
} mmapper; |
} mmapper; |
54 |
#endif |
#endif |
55 |
|
|
56 |
|
#ifdef ENABLE_OSM_GPS_MAP |
57 |
struct { |
struct { |
58 |
GtkWidget *widget; |
GtkWidget *widget; |
59 |
GtkWidget *zoomin, *zoomout, *center, *modesel; |
GtkWidget *zoomin, *zoomout, *center, *modesel, *gps; |
60 |
gboolean needs_redraw, drag_mode; |
gboolean needs_redraw, drag_mode; |
61 |
|
gint handler_id; |
62 |
coord_t start; |
coord_t start; |
63 |
} map; |
} map; |
64 |
|
#endif |
65 |
} context_t; |
} context_t; |
66 |
|
|
67 |
static void parse_and_set_lat(GtkWidget *src, pos_float_t *store) { |
static void parse_and_set_lat(GtkWidget *src, pos_float_t *store) { |
76 |
*store = i; |
*store = i; |
77 |
} |
} |
78 |
|
|
|
#define LOG2(x) (log(x) / log(2)) |
|
|
|
|
79 |
static gboolean current_tab_is(context_t *context, gint page_num, char *str) { |
static gboolean current_tab_is(context_t *context, gint page_num, char *str) { |
80 |
if(page_num < 0) |
if(page_num < 0) |
81 |
page_num = |
page_num = |
134 |
} |
} |
135 |
|
|
136 |
#ifdef ENABLE_OSM_GPS_MAP |
#ifdef ENABLE_OSM_GPS_MAP |
137 |
|
#define LOG2(x) (log(x) / log(2)) |
138 |
|
|
139 |
static GSList *pos_append_rad(GSList *list, pos_float_t lat, pos_float_t lon) { |
static GSList *pos_append_rad(GSList *list, pos_float_t lat, pos_float_t lon) { |
140 |
coord_t *coo = g_new0(coord_t, 1); |
coord_t *coo = g_new0(coord_t, 1); |
141 |
coo->rlat = lat; |
coo->rlat = lat; |
313 |
static void callback_fetch_mm_clicked(GtkButton *button, gpointer data) { |
static void callback_fetch_mm_clicked(GtkButton *button, gpointer data) { |
314 |
context_t *context = (context_t*)data; |
context_t *context = (context_t*)data; |
315 |
|
|
316 |
if(!dbus_mm_set_position(context->area->osso_context, NULL)) { |
if(!dbus_mm_set_position(context->area->appdata->osso_context, NULL)) { |
317 |
errorf(context->dialog, |
errorf(context->dialog, |
318 |
_("Unable to communicate with Maemo Mapper. " |
_("Unable to communicate with Maemo Mapper. " |
319 |
"You need to have Maemo Mapper installed " |
"You need to have Maemo Mapper installed " |
321 |
return; |
return; |
322 |
} |
} |
323 |
|
|
324 |
if(!context->area->mmpos->valid) { |
if(!context->area->appdata->mmpos.valid) { |
325 |
errorf(context->dialog, |
errorf(context->dialog, |
326 |
_("No valid position received yet. You need " |
_("No valid position received yet. You need " |
327 |
"to scroll or zoom the Maemo Mapper view " |
"to scroll or zoom the Maemo Mapper view " |
335 |
return; |
return; |
336 |
|
|
337 |
/* maemo mapper pos data ... */ |
/* maemo mapper pos data ... */ |
338 |
pos_float_t center_lat = context->area->mmpos->pos.lat; |
pos_float_t center_lat = context->area->appdata->mmpos.pos.lat; |
339 |
pos_float_t center_lon = context->area->mmpos->pos.lon; |
pos_float_t center_lon = context->area->appdata->mmpos.pos.lon; |
340 |
int zoom = context->area->mmpos->zoom; |
int zoom = context->area->appdata->mmpos.zoom; |
341 |
|
|
342 |
if(!pos_lat_valid(center_lat) || !pos_lon_valid(center_lon)) |
if(!pos_lat_valid(center_lat) || !pos_lon_valid(center_lon)) |
343 |
return; |
return; |
499 |
return FALSE; |
return FALSE; |
500 |
} |
} |
501 |
|
|
502 |
|
static gboolean |
503 |
|
cb_map_gps(GtkButton *button, context_t *context) { |
504 |
|
pos_t pos; |
505 |
|
|
506 |
|
/* user clicked "gps" button -> jump to position */ |
507 |
|
gboolean gps_on = |
508 |
|
context->area->appdata->settings && |
509 |
|
context->area->appdata->settings->enable_gps; |
510 |
|
|
511 |
|
if(gps_on && gps_get_pos(context->area->appdata, &pos, NULL)) { |
512 |
|
osm_gps_map_set_center(OSM_GPS_MAP(context->map.widget), |
513 |
|
DEG2RAD(pos.lat), DEG2RAD(pos.lon)); |
514 |
|
} |
515 |
|
|
516 |
|
return FALSE; |
517 |
|
} |
518 |
|
|
519 |
static void on_page_switch(GtkNotebook *notebook, GtkNotebookPage *page, |
static void on_page_switch(GtkNotebook *notebook, GtkNotebookPage *page, |
520 |
guint page_num, context_t *context) { |
guint page_num, context_t *context) { |
521 |
|
|
526 |
context->map.needs_redraw) |
context->map.needs_redraw) |
527 |
map_update(context, TRUE); |
map_update(context, TRUE); |
528 |
} |
} |
529 |
|
|
530 |
|
static GtkWidget |
531 |
|
*map_add_button(const gchar *icon, GCallback cb, gpointer data, |
532 |
|
char *tooltip) { |
533 |
|
GtkWidget *button = gtk_button_new(); |
534 |
|
gtk_button_set_image(GTK_BUTTON(button), |
535 |
|
gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU)); |
536 |
|
g_signal_connect(button, "clicked", cb, data); |
537 |
|
#ifndef USE_HILDON |
538 |
|
gtk_widget_set_tooltip_text(button, tooltip); |
539 |
|
#endif |
540 |
|
return button; |
541 |
|
} |
542 |
|
|
543 |
|
static gboolean map_gps_update(gpointer data) { |
544 |
|
context_t *context = (context_t*)data; |
545 |
|
|
546 |
|
gboolean gps_on = |
547 |
|
context->area->appdata->settings && |
548 |
|
context->area->appdata->settings->enable_gps; |
549 |
|
|
550 |
|
gboolean gps_fix = gps_on && |
551 |
|
gps_get_pos(context->area->appdata, NULL, NULL); |
552 |
|
|
553 |
|
gtk_widget_set_sensitive(context->map.gps, gps_fix); |
554 |
|
|
555 |
|
return TRUE; |
556 |
|
} |
557 |
|
|
558 |
#endif |
#endif |
559 |
|
|
560 |
gboolean area_edit(area_edit_t *area) { |
gboolean area_edit(area_edit_t *area) { |
618 |
context.map.widget = g_object_new(OSM_TYPE_GPS_MAP, |
context.map.widget = g_object_new(OSM_TYPE_GPS_MAP, |
619 |
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
620 |
"proxy-uri", misc_get_proxy_uri(area->settings), |
"proxy-uri", misc_get_proxy_uri(area->settings), |
621 |
|
"tile-cache", NULL, |
622 |
NULL); |
NULL); |
623 |
|
|
624 |
g_signal_connect(G_OBJECT(context.map.widget), "configure-event", |
g_signal_connect(G_OBJECT(context.map.widget), "configure-event", |
635 |
/* zoom button box */ |
/* zoom button box */ |
636 |
vbox = gtk_vbox_new(FALSE,0); |
vbox = gtk_vbox_new(FALSE,0); |
637 |
|
|
638 |
context.map.zoomin = gtk_button_new(); |
context.map.zoomin = |
639 |
gtk_button_set_image(GTK_BUTTON(context.map.zoomin), |
map_add_button(GTK_STOCK_ZOOM_IN, G_CALLBACK(cb_map_zoomin), |
640 |
gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU)); |
&context, _("Zoom in")); |
|
g_signal_connect(context.map.zoomin, "clicked", |
|
|
G_CALLBACK(cb_map_zoomin), &context); |
|
641 |
gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomin, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomin, FALSE, FALSE, 0); |
642 |
|
|
643 |
context.map.zoomout = gtk_button_new(); |
context.map.zoomout = |
644 |
gtk_button_set_image(GTK_BUTTON(context.map.zoomout), |
map_add_button(GTK_STOCK_ZOOM_OUT, G_CALLBACK(cb_map_zoomout), |
645 |
gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU)); |
&context, _("Zoom out")); |
|
g_signal_connect(context.map.zoomout, "clicked", |
|
|
G_CALLBACK(cb_map_zoomout), &context); |
|
646 |
gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomout, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomout, FALSE, FALSE, 0); |
647 |
|
|
648 |
context.map.center = gtk_button_new(); |
context.map.center = |
649 |
gtk_button_set_image(GTK_BUTTON(context.map.center), |
map_add_button(GTK_STOCK_HOME, G_CALLBACK(cb_map_center), |
650 |
gtk_image_new_from_stock(GTK_STOCK_HOME, GTK_ICON_SIZE_MENU)); |
&context, _("Center selected area")); |
|
g_signal_connect(context.map.center, "clicked", |
|
|
G_CALLBACK(cb_map_center), &context); |
|
651 |
gtk_box_pack_start(GTK_BOX(vbox), context.map.center, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context.map.center, FALSE, FALSE, 0); |
652 |
|
|
653 |
|
context.map.gps = |
654 |
|
map_add_button(GTK_STOCK_ABOUT, G_CALLBACK(cb_map_gps), |
655 |
|
&context, _("Jump to GPS position")); |
656 |
|
gtk_widget_set_sensitive(context.map.gps, FALSE); |
657 |
|
/* install handler for timed updates of the gps button */ |
658 |
|
context.map.handler_id = gtk_timeout_add(1000, map_gps_update, &context); |
659 |
|
gtk_box_pack_start(GTK_BOX(vbox), context.map.gps, FALSE, FALSE, 0); |
660 |
|
|
661 |
context.map.drag_mode = TRUE; |
context.map.drag_mode = TRUE; |
662 |
context.map.start.rlon = context.map.start.rlat = NAN; |
context.map.start.rlon = context.map.start.rlat = NAN; |
663 |
context.map.modesel = gtk_button_new(); |
context.map.modesel = |
664 |
gtk_button_set_image(GTK_BUTTON(context.map.modesel), |
map_add_button(GTK_STOCK_FIND, G_CALLBACK(cb_map_modesel), |
665 |
gtk_image_new_from_stock(context.map.drag_mode? |
&context, _("Toggle scroll/select")); |
|
GTK_STOCK_FIND:GTK_STOCK_CUT, GTK_ICON_SIZE_MENU)); |
|
|
g_signal_connect(context.map.modesel, "clicked", |
|
|
G_CALLBACK(cb_map_modesel), &context); |
|
666 |
gtk_box_pack_start(GTK_BOX(vbox), context.map.modesel, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context.map.modesel, FALSE, FALSE, 0); |
667 |
|
|
|
|
|
668 |
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
669 |
|
|
670 |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
817 |
ok = TRUE; |
ok = TRUE; |
818 |
} |
} |
819 |
|
|
820 |
|
#ifdef ENABLE_OSM_GPS_MAP |
821 |
|
gtk_timeout_remove(context.map.handler_id); |
822 |
|
#endif |
823 |
|
|
824 |
gtk_widget_destroy(context.dialog); |
gtk_widget_destroy(context.dialog); |
825 |
|
|
826 |
return ok; |
return ok; |