18 |
*/ |
*/ |
19 |
|
|
20 |
#include "appdata.h" |
#include "appdata.h" |
21 |
|
|
22 |
|
#ifdef ENABLE_OSM_GPS_MAP |
23 |
#include "osm-gps-map.h" |
#include "osm-gps-map.h" |
24 |
|
#endif |
25 |
|
|
26 |
|
#define TAB_LABEL_MAP "Map" |
27 |
|
#define TAB_LABEL_DIRECT "Direct" |
28 |
|
#define TAB_LABEL_EXTENT "Extent" |
29 |
|
#define TAB_LABEL_MM "Maemo Mapper" |
30 |
|
|
31 |
/* limit of square kilometers above the warning is enabled */ |
/* limit of square kilometers above the warning is enabled */ |
32 |
#define WARN_OVER 5.0 |
#define WARN_OVER 5.0 |
75 |
|
|
76 |
#define LOG2(x) (log(x) / log(2)) |
#define LOG2(x) (log(x) / log(2)) |
77 |
|
|
78 |
|
static gboolean current_tab_is(context_t *context, gint page_num, char *str) { |
79 |
|
if(page_num < 0) |
80 |
|
page_num = |
81 |
|
gtk_notebook_get_current_page(GTK_NOTEBOOK(context->notebook)); |
82 |
|
|
83 |
|
if(page_num < 0) return FALSE; |
84 |
|
|
85 |
|
GtkWidget *w = |
86 |
|
gtk_notebook_get_nth_page(GTK_NOTEBOOK(context->notebook), page_num); |
87 |
|
const char *name = |
88 |
|
gtk_notebook_get_tab_label_text(GTK_NOTEBOOK(context->notebook), w); |
89 |
|
|
90 |
|
return(strcasecmp(name, _(str)) == 0); |
91 |
|
} |
92 |
|
|
93 |
static void on_area_warning_clicked(GtkButton *button, gpointer data) { |
static void on_area_warning_clicked(GtkButton *button, gpointer data) { |
94 |
context_t *context = (context_t*)data; |
context_t *context = (context_t*)data; |
95 |
|
|
101 |
double area = vscale * (context->max.lat - context->min.lat) * |
double area = vscale * (context->max.lat - context->min.lat) * |
102 |
hscale * (context->max.lon - context->min.lon); |
hscale * (context->max.lon - context->min.lon); |
103 |
|
|
104 |
messagef(context->dialog, _("Area size warning"), |
warningf(context->dialog, |
105 |
_("The currently selected area is %.02f km² (%.02f mil²) in size. " |
_("The currently selected area is %.02f km² (%.02f mil²) in size. " |
106 |
"This is more than the recommended %.02f km² (%.02f mil²). " |
"This is more than the recommended %.02f km² (%.02f mil²).\n\n" |
107 |
"This may result in a big download and slow mapping performance " |
"Continuing may result in a big download and low mapping performance " |
108 |
"in a densly mapped area (e.g. cities)!"), |
"in a densly mapped area (e.g. cities)!"), |
109 |
area, area/(KMPMIL*KMPMIL), |
area, area/(KMPMIL*KMPMIL), |
110 |
WARN_OVER, WARN_OVER/(KMPMIL*KMPMIL) |
WARN_OVER, WARN_OVER/(KMPMIL*KMPMIL) |
132 |
gtk_widget_hide(context->warning); |
gtk_widget_hide(context->warning); |
133 |
} |
} |
134 |
|
|
135 |
|
#ifdef ENABLE_OSM_GPS_MAP |
136 |
/* the contents of the map tab have been changed */ |
/* the contents of the map tab have been changed */ |
137 |
static void map_update(context_t *context, gboolean forced) { |
static void map_update(context_t *context, gboolean forced) { |
138 |
|
|
139 |
/* map is first tab (page 0) */ |
/* map is first tab (page 0) */ |
140 |
if(!forced && |
if(!forced && !current_tab_is(context, -1, TAB_LABEL_MAP)) { |
|
gtk_notebook_get_current_page(GTK_NOTEBOOK(context->notebook)) != 0) { |
|
141 |
context->map.needs_redraw = TRUE; |
context->map.needs_redraw = TRUE; |
142 |
return; |
return; |
143 |
} |
} |
167 |
map_update(context, FALSE); |
map_update(context, FALSE); |
168 |
return FALSE; |
return FALSE; |
169 |
} |
} |
170 |
|
#endif |
171 |
|
|
172 |
/* the contents of the direct tab have been changed */ |
/* the contents of the direct tab have been changed */ |
173 |
static void direct_update(context_t *context) { |
static void direct_update(context_t *context) { |
199 |
context_t *context = (context_t*)data; |
context_t *context = (context_t*)data; |
200 |
|
|
201 |
/* direct is second tab (page 1) */ |
/* direct is second tab (page 1) */ |
202 |
if(gtk_notebook_get_current_page(GTK_NOTEBOOK(context->notebook)) != 1) |
if(!current_tab_is(context, -1, TAB_LABEL_DIRECT)) |
203 |
return; |
return; |
204 |
|
|
205 |
/* parse the fields from the direct entry pad */ |
/* parse the fields from the direct entry pad */ |
212 |
|
|
213 |
/* also adjust other views */ |
/* also adjust other views */ |
214 |
extent_update(context); |
extent_update(context); |
215 |
|
#ifdef ENABLE_OSM_GPS_MAP |
216 |
|
map_update(context, FALSE); |
217 |
|
#endif |
218 |
} |
} |
219 |
|
|
220 |
static void callback_modified_extent(GtkWidget *widget, gpointer data) { |
static void callback_modified_extent(GtkWidget *widget, gpointer data) { |
221 |
context_t *context = (context_t*)data; |
context_t *context = (context_t*)data; |
222 |
|
|
223 |
/* extent is third tab (page 2) */ |
/* extent is third tab (page 2) */ |
224 |
if(gtk_notebook_get_current_page(GTK_NOTEBOOK(context->notebook)) != 2) |
if(!current_tab_is(context, -1, TAB_LABEL_EXTENT)) |
225 |
return; |
return; |
226 |
|
|
227 |
pos_float_t center_lat = pos_lat_get(context->extent.lat); |
pos_float_t center_lat = pos_lat_get(context->extent.lat); |
248 |
|
|
249 |
/* also update other tabs */ |
/* also update other tabs */ |
250 |
direct_update(context); |
direct_update(context); |
251 |
|
#ifdef ENABLE_OSM_GPS_MAP |
252 |
map_update(context, FALSE); |
map_update(context, FALSE); |
253 |
|
#endif |
254 |
} |
} |
255 |
|
|
256 |
static void callback_modified_unit(GtkWidget *widget, gpointer data) { |
static void callback_modified_unit(GtkWidget *widget, gpointer data) { |
273 |
static void callback_fetch_mm_clicked(GtkButton *button, gpointer data) { |
static void callback_fetch_mm_clicked(GtkButton *button, gpointer data) { |
274 |
context_t *context = (context_t*)data; |
context_t *context = (context_t*)data; |
275 |
|
|
|
printf("clicked fetch mm!\n"); |
|
|
|
|
276 |
if(!dbus_mm_set_position(context->area->osso_context, NULL)) { |
if(!dbus_mm_set_position(context->area->osso_context, NULL)) { |
277 |
errorf(context->dialog, |
errorf(context->dialog, |
278 |
_("Unable to communicate with Maemo Mapper. " |
_("Unable to communicate with Maemo Mapper. " |
291 |
} |
} |
292 |
|
|
293 |
/* maemo mapper is fourth tab (page 3) */ |
/* maemo mapper is fourth tab (page 3) */ |
294 |
if(gtk_notebook_get_current_page(GTK_NOTEBOOK(context->notebook)) != 3) |
if(!current_tab_is(context, -1, TAB_LABEL_MM)) |
295 |
return; |
return; |
296 |
|
|
297 |
/* maemo mapper pos data ... */ |
/* maemo mapper pos data ... */ |
317 |
/* also update other tabs */ |
/* also update other tabs */ |
318 |
direct_update(context); |
direct_update(context); |
319 |
extent_update(context); |
extent_update(context); |
320 |
|
#ifdef ENABLE_OSM_GPS_MAP |
321 |
map_update(context, FALSE); |
map_update(context, FALSE); |
322 |
|
#endif |
323 |
} |
} |
324 |
#endif |
#endif |
325 |
|
|
326 |
|
#ifdef ENABLE_OSM_GPS_MAP |
327 |
/* the user has changed the map view, update other views accordingly */ |
/* the user has changed the map view, update other views accordingly */ |
328 |
static void map_has_changed(context_t *context) { |
static void map_has_changed(context_t *context) { |
329 |
coord_t pt1, pt2; |
coord_t pt1, pt2; |
380 |
/* updating the map while the user manually changes some coordinates */ |
/* updating the map while the user manually changes some coordinates */ |
381 |
/* may confuse the map. so we delay those updates until the map tab */ |
/* may confuse the map. so we delay those updates until the map tab */ |
382 |
/* is becoming visible */ |
/* is becoming visible */ |
383 |
if((page_num == 0) && context->map.needs_redraw) |
if(current_tab_is(context, page_num, TAB_LABEL_MAP) && |
384 |
|
context->map.needs_redraw) |
385 |
map_update(context, TRUE); |
map_update(context, TRUE); |
386 |
} |
} |
387 |
|
#endif |
388 |
|
|
389 |
gboolean area_edit(area_edit_t *area) { |
gboolean area_edit(area_edit_t *area) { |
390 |
|
GtkWidget *vbox; |
391 |
gboolean ok = FALSE; |
gboolean ok = FALSE; |
392 |
|
|
393 |
context_t context; |
context_t context; |
438 |
|
|
439 |
context.notebook = gtk_notebook_new(); |
context.notebook = gtk_notebook_new(); |
440 |
|
|
441 |
|
#ifdef ENABLE_OSM_GPS_MAP |
442 |
/* ------------- fetch from map ------------------------ */ |
/* ------------- fetch from map ------------------------ */ |
443 |
|
|
444 |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
457 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context.map.widget); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context.map.widget); |
458 |
|
|
459 |
/* zoom button box */ |
/* zoom button box */ |
460 |
GtkWidget *vbox = gtk_vbox_new(FALSE,0); |
vbox = gtk_vbox_new(FALSE,0); |
461 |
|
|
462 |
context.map.zoomin = gtk_button_new(); |
context.map.zoomin = gtk_button_new(); |
463 |
gtk_button_set_image(GTK_BUTTON(context.map.zoomin), |
gtk_button_set_image(GTK_BUTTON(context.map.zoomin), |
476 |
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
477 |
|
|
478 |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
479 |
hbox, gtk_label_new(_("Map"))); |
hbox, gtk_label_new(_(TAB_LABEL_MAP))); |
480 |
|
#endif |
481 |
|
|
482 |
/* ------------ direct min/max edit --------------- */ |
/* ------------ direct min/max edit --------------- */ |
483 |
|
|
519 |
|
|
520 |
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
521 |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
522 |
vbox, gtk_label_new(_("Direct"))); |
vbox, gtk_label_new(_(TAB_LABEL_DIRECT))); |
523 |
|
|
524 |
/* ------------- center/extent edit ------------------------ */ |
/* ------------- center/extent edit ------------------------ */ |
525 |
|
|
579 |
|
|
580 |
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
581 |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
582 |
vbox, gtk_label_new(_("Extent"))); |
vbox, gtk_label_new(_(TAB_LABEL_EXTENT))); |
583 |
|
|
584 |
#ifdef USE_HILDON |
#ifdef USE_HILDON |
585 |
/* ------------- fetch from maemo mapper ------------------------ */ |
/* ------------- fetch from maemo mapper ------------------------ */ |
598 |
|
|
599 |
|
|
600 |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
601 |
vbox, gtk_label_new(_("Maemo Mapper"))); |
vbox, gtk_label_new(_(TAB_LABEL_MM))); |
602 |
#endif |
#endif |
603 |
|
|
604 |
/* ------------------------------------------------------ */ |
/* ------------------------------------------------------ */ |
606 |
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context.dialog)->vbox), |
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context.dialog)->vbox), |
607 |
context.notebook); |
context.notebook); |
608 |
|
|
609 |
|
#ifdef ENABLE_OSM_GPS_MAP |
610 |
g_signal_connect(G_OBJECT(context.notebook), "switch-page", |
g_signal_connect(G_OBJECT(context.notebook), "switch-page", |
611 |
G_CALLBACK(on_page_switch), &context); |
G_CALLBACK(on_page_switch), &context); |
612 |
|
#endif |
613 |
|
|
614 |
gtk_widget_show_all(context.dialog); |
gtk_widget_show_all(context.dialog); |
615 |
|
|