14 #include <glib/gstdio.h>
17 #include <gconf/gconf-client.h>
23 #include <osso-helplib.h>
26 #include <hildon-widgets/hildon-program.h>
27 #include <hildon-widgets/hildon-controlbar.h>
28 #include <hildon-widgets/hildon-note.h>
29 #include <hildon-widgets/hildon-color-button.h>
30 #include <hildon-widgets/hildon-file-chooser-dialog.h>
31 #include <hildon-widgets/hildon-number-editor.h>
32 #include <hildon-widgets/hildon-banner.h>
33 #include <hildon-widgets/hildon-input-mode-hint.h>
34 #include <device_symbols.h>
43 #include "mapper-types.h"
45 #include "ui-common.h"
50 gboolean map_cb_configure(GtkWidget * widget, GdkEventConfigure * event)
52 printf("%s(%d, %d)\n", __PRETTY_FUNCTION__,
53 _map_widget->allocation.width, _map_widget->allocation.height);
55 _screen_width_pixels = _map_widget->allocation.width;
56 _screen_height_pixels = _map_widget->allocation.height;
57 _screen_grids_halfwidth = pixel2grid(_screen_width_pixels) / 2;
58 _screen_grids_halfheight = pixel2grid(_screen_height_pixels) / 2;
60 /* Set _scale_rect. */
61 _scale_rect.x = (_screen_width_pixels - SCALE_WIDTH) / 2;
62 _scale_rect.width = SCALE_WIDTH;
63 pango_layout_set_text(_scale_layout, "0", -1);
64 pango_layout_get_pixel_size(_scale_layout, NULL, &_scale_rect.height);
65 _scale_rect.y = _screen_height_pixels - _scale_rect.height - 1;
67 MACRO_RECALC_FOCUS_BASE();
68 MACRO_RECALC_FOCUS_SIZE();
70 _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth));
71 _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight));
72 _max_center.unitx = WORLD_SIZE_UNITS - grid2unit(_screen_grids_halfwidth) - 1;
73 _max_center.unity = WORLD_SIZE_UNITS - grid2unit(_screen_grids_halfheight) - 1;
75 map_center_unit(_center.unitx, _center.unity);
77 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
81 gboolean menu_cb_route_download(GtkAction * action)
83 printf("%s()\n", __PRETTY_FUNCTION__);
85 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
89 gboolean menu_cb_route_open(GtkAction * action)
91 printf("%s()\n", __PRETTY_FUNCTION__);
95 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
99 gboolean menu_cb_route_distnext(GtkAction * action)
101 printf("%s()\n", __PRETTY_FUNCTION__);
103 route_show_distance_to_next();
105 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
109 gboolean menu_cb_route_distlast(GtkAction * action)
111 printf("%s()\n", __PRETTY_FUNCTION__);
113 route_show_distance_to_last();
115 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
119 gboolean menu_cb_route_reset(GtkAction * action)
121 printf("%s()\n", __PRETTY_FUNCTION__);
123 route_find_nearest_point();
124 MACRO_MAP_RENDER_DATA();
125 MACRO_QUEUE_DRAW_AREA();
127 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
131 gboolean menu_cb_route_clear(GtkAction * action)
133 printf("%s()\n", __PRETTY_FUNCTION__);
135 cancel_autoroute(FALSE);
136 MACRO_PATH_FREE(_route);
137 MACRO_PATH_INIT(_route);
138 route_find_nearest_point();
141 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
145 gboolean menu_cb_track_open(GtkAction * action)
147 printf("%s()\n", __PRETTY_FUNCTION__);
151 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
155 gboolean menu_cb_track_save(GtkAction * action)
157 printf("%s()\n", __PRETTY_FUNCTION__);
161 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
165 gboolean menu_cb_track_insert_break(GtkAction * action)
167 printf("%s()\n", __PRETTY_FUNCTION__);
169 track_insert_break();
171 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
175 gboolean menu_cb_track_insert_mark(GtkAction * action)
177 printf("%s()\n", __PRETTY_FUNCTION__);
181 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
185 gboolean menu_cb_track_distlast(GtkAction * action)
187 printf("%s()\n", __PRETTY_FUNCTION__);
189 track_show_distance_from_last();
191 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
195 gboolean menu_cb_track_distfirst(GtkAction * action)
197 printf("%s()\n", __PRETTY_FUNCTION__);
199 track_show_distance_from_first();
201 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
205 gboolean menu_cb_route_save(GtkAction * action)
207 printf("%s()\n", __PRETTY_FUNCTION__);
211 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
215 gboolean menu_cb_track_clear(GtkAction * action)
217 printf("%s()\n", __PRETTY_FUNCTION__);
221 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
225 gboolean menu_cb_show_tracks(GtkAction * action)
227 printf("%s()\n", __PRETTY_FUNCTION__);
229 _show_tracks ^= TRACKS_MASK;
230 if (gtk_check_menu_item_get_active
231 (GTK_CHECK_MENU_ITEM(_menu_show_tracks_item))) {
232 _show_tracks |= TRACKS_MASK;
234 MACRO_QUEUE_DRAW_AREA();
235 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now shown"));
237 _show_tracks &= ~TRACKS_MASK;
239 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now hidden"));
242 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
246 gboolean menu_cb_show_scale(GtkAction * action)
248 printf("%s()\n", __PRETTY_FUNCTION__);
251 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
252 (_menu_show_scale_item));
253 MACRO_QUEUE_DRAW_AREA();
255 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
259 gboolean menu_cb_show_routes(GtkAction * action)
261 printf("%s()\n", __PRETTY_FUNCTION__);
263 if (gtk_check_menu_item_get_active
264 (GTK_CHECK_MENU_ITEM(_menu_show_routes_item))) {
265 _show_tracks |= ROUTES_MASK;
267 MACRO_QUEUE_DRAW_AREA();
268 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now shown"));
270 _show_tracks &= ~ROUTES_MASK;
272 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now hidden"));
275 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
279 gboolean menu_cb_show_velvec(GtkAction * action)
281 printf("%s()\n", __PRETTY_FUNCTION__);
283 _show_velvec = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_show_velvec_item));
286 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
290 gboolean menu_cb_show_poi(GtkAction * action)
292 printf("%s()\n", __PRETTY_FUNCTION__);
294 _show_poi = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_show_poi_item));
297 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
301 gboolean menu_cb_gps_show_info(GtkAction * action)
303 printf("%s()\n", __PRETTY_FUNCTION__);
305 _gps_info = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_gps_show_info_item));
309 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
313 gboolean menu_cb_ac_lead(GtkAction * action)
315 guint new_center_unitx, new_center_unity;
316 printf("%s()\n", __PRETTY_FUNCTION__);
318 _center_mode = CENTER_LEAD;
319 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lead"));
320 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
321 map_center_unit(new_center_unitx, new_center_unity);
323 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
327 gboolean menu_cb_ac_latlon(GtkAction * action)
329 guint new_center_unitx, new_center_unity;
330 printf("%s()\n", __PRETTY_FUNCTION__);
332 _center_mode = CENTER_LATLON;
333 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lat/Lon"));
334 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
335 map_center_unit(new_center_unitx, new_center_unity);
337 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
341 gboolean menu_cb_ac_none(GtkAction * action)
343 printf("%s()\n", __PRETTY_FUNCTION__);
345 _center_mode = -_center_mode;
346 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Off"));
348 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
352 gboolean menu_cb_goto_latlon(GtkAction * action)
359 printf("%s()\n", __PRETTY_FUNCTION__);
361 dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"),
363 GTK_DIALOG_MODAL, GTK_STOCK_OK,
366 GTK_RESPONSE_REJECT, NULL);
368 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
369 table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0);
371 gtk_table_attach(GTK_TABLE(table),
372 label = gtk_label_new(_("Latitude")),
373 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
374 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
376 gtk_table_attach(GTK_TABLE(table),
377 txt_lat = gtk_entry_new(),
378 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
379 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
381 gtk_table_attach(GTK_TABLE(table),
382 label = gtk_label_new(_("Longitude")),
383 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
384 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
386 gtk_table_attach(GTK_TABLE(table),
387 txt_lon = gtk_entry_new(),
388 1, 2, 1, 2, GTK_FILL, 0, 2, 4);
389 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
392 g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT,
393 HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
394 g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT,
395 HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
398 /* Initialize with the current center position. */
402 unit2latlon(_center.unitx, _center.unity, lat, lon);
403 snprintf(buffer, sizeof(buffer), "%.06f", lat);
404 gtk_label_set_text(GTK_LABEL(txt_lat), buffer);
405 snprintf(buffer, sizeof(buffer), "%.06f", lon);
406 gtk_label_set_text(GTK_LABEL(txt_lon), buffer);
409 gtk_widget_show_all(dialog);
411 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
417 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
418 lat = strtof(text, &error_check);
419 if (text == error_check || lat < -90.f || lat > 90.f) {
420 popup_error(dialog, _("Invalid Latitude"));
424 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
425 lon = strtof(text, &error_check);
426 if (text == error_check || lon < -180.f || lon > 180.f) {
427 popup_error(dialog, _("Invalid Longitude"));
431 latlon2unit(lat, lon, unitx, unity);
432 if (_center_mode > 0)
433 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
434 (_menu_ac_none_item), TRUE);
435 map_center_unit(unitx, unity);
438 gtk_widget_destroy(dialog);
439 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
443 gboolean menu_cb_goto_home(GtkAction * action)
447 printf("%s()\n", __PRETTY_FUNCTION__);
449 if (_center_mode > 0)
450 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
451 (_menu_ac_none_item), TRUE);
453 latlon2unit(_home.lat, _home.lon, unitx, unity);
454 map_center_unit(unitx, unity);
456 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
460 gboolean menu_cb_goto_gps(GtkAction * action)
462 printf("%s()\n", __PRETTY_FUNCTION__);
464 if (_center_mode > 0)
465 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
466 (_menu_ac_none_item), TRUE);
468 map_center_unit(_pos.unitx, _pos.unity);
470 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
474 gboolean menu_cb_goto_nextway(GtkAction * action)
476 printf("%s()\n", __PRETTY_FUNCTION__);
478 if (_next_way && _next_way->point->unity) {
479 if (_center_mode > 0)
480 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
481 (_menu_ac_none_item),
484 map_center_unit(_next_way->point->unitx,
485 _next_way->point->unity);
487 MACRO_BANNER_SHOW_INFO(_window,
488 _("There is no next waypoint."));
491 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
495 gboolean menu_cb_goto_nearpoi(GtkAction * action)
500 printf("%s()\n", __PRETTY_FUNCTION__);
502 if (_center_mode > 0) {
503 /* Auto-Center is enabled - use the GPS position. */
504 unit2latlon(_pos.unitx, _pos.unity, lat, lon);
506 /* Auto-Center is disabled - use the view center. */
507 unit2latlon(_center.unitx, _center.unity, lat, lon);
510 p=poi_find_nearest(lat, lon);
516 latlon2unit(p->lat, p->lon, unitx, unity);
517 banner = g_strdup_printf("%s (%s)", p->label, p->cat_label);
518 g_printf("%s\n", banner);
519 MACRO_BANNER_SHOW_INFO(_window, banner);
523 if (_center_mode > 0)
524 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_ac_none_item), TRUE);
526 map_center_unit(unitx, unity);
528 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
531 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
535 gboolean menu_cb_maps_repoman(GtkAction * action)
537 printf("%s()\n", __PRETTY_FUNCTION__);
539 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
543 gboolean menu_cb_maps_select(GtkAction * action, gpointer new_repo)
545 printf("%s()\n", __PRETTY_FUNCTION__);
546 repo_set_curr(new_repo);
548 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
552 gboolean cb_zoom_autozoom(GtkAction * action)
554 printf("%s()\n", __PRETTY_FUNCTION__);
556 map_set_autozoom(TRUE);
558 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
562 gboolean cb_zoom_base(GtkAction * action)
564 printf("%s()\n", __PRETTY_FUNCTION__);
566 map_set_autozoom(FALSE);
569 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
573 gboolean cb_zoomin(GtkAction * action)
575 printf("%s()\n", __PRETTY_FUNCTION__);
577 map_set_autozoom(FALSE);
580 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
584 gboolean cb_zoomout(GtkAction * action)
586 printf("%s()\n", __PRETTY_FUNCTION__);
588 map_set_autozoom(FALSE);
591 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
595 gboolean cb_fullscreen_click(GtkAction * action)
597 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_fullscreen_item), !_fullscreen);
601 gboolean cb_fullscreen(GtkAction * action)
603 printf("%s()\n", __PRETTY_FUNCTION__);
605 if ((_fullscreen = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_fullscreen_item)))) {
606 gtk_window_fullscreen(GTK_WINDOW(_window));
607 gtk_widget_set_state(_toolbar_fullscreen_item, GTK_STATE_ACTIVE);
609 gtk_window_unfullscreen(GTK_WINDOW(_window));
610 gtk_widget_set_state(_toolbar_fullscreen_item, GTK_STATE_NORMAL);
613 gtk_idle_add((GSourceFunc) window_present, NULL);
615 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
619 gboolean menu_cb_enable_gps(GtkAction * action)
621 printf("%s()\n", __PRETTY_FUNCTION__);
624 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
625 (_menu_enable_gps_item)))) {
627 set_conn_state(RCVR_DOWN);
631 _("Cannot enable GPS until a GPS Receiver MAC "
632 "is set in the Settings dialog box."));
633 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
634 (_menu_enable_gps_item),
638 if (_conn_state > RCVR_OFF)
639 set_conn_state(RCVR_OFF);
642 _speed_excess = FALSE;
646 gtk_widget_set_sensitive(GTK_WIDGET(_menu_gps_details_item), _enable_gps);
648 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
652 gboolean menu_cb_auto_download(GtkAction * action)
654 printf("%s()\n", __PRETTY_FUNCTION__);
656 if ((_auto_download =
657 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_auto_download_item)))) {
658 if (_curr_repo->url == REPOTYPE_NONE)
660 _("NOTE: You must set a Map URI in the current repository in "
661 "order to download maps."));
665 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
669 gboolean menu_cb_gps_details(GtkAction * action)
671 printf("%s()\n", __PRETTY_FUNCTION__);
675 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
679 gboolean menu_cb_settings(GtkAction * action)
681 printf("%s()\n", __PRETTY_FUNCTION__);
683 if (settings_dialog()) {
684 /* Settings have changed - reconnect to receiver. */
686 set_conn_state(RCVR_DOWN);
691 MACRO_RECALC_FOCUS_BASE();
692 MACRO_RECALC_FOCUS_SIZE();
695 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
699 gboolean menu_cb_help(GtkAction * action)
701 printf("%s()\n", __PRETTY_FUNCTION__);
704 ossohelp_show(_osso, HELP_ID_INTRO, 0);
707 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
711 gboolean menu_cb_about(GtkAction * action)
714 ossohelp_show(_osso, HELP_ID_ABOUT, OSSO_HELP_SHOW_DIALOG);
717 "Kaj-Michael Lang","John Costigan","Cezary Jackiewicz", NULL};
719 gtk_show_about_dialog(GTK_WINDOW(_window),
722 "copyright", "Kaj-Michael Lang",
730 gboolean window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
732 CustomKey custom_key;
733 printf("%s()\n", __PRETTY_FUNCTION__);
735 switch (event->keyval) {
736 case HILDON_HARDKEY_UP:
737 custom_key = CUSTOM_KEY_UP;
739 case HILDON_HARDKEY_DOWN:
740 custom_key = CUSTOM_KEY_DOWN;
742 case HILDON_HARDKEY_LEFT:
743 custom_key = CUSTOM_KEY_LEFT;
745 case HILDON_HARDKEY_RIGHT:
746 custom_key = CUSTOM_KEY_RIGHT;
748 case HILDON_HARDKEY_SELECT:
749 custom_key = CUSTOM_KEY_SELECT;
751 case HILDON_HARDKEY_INCREASE:
752 custom_key = CUSTOM_KEY_INCREASE;
754 case HILDON_HARDKEY_DECREASE:
755 custom_key = CUSTOM_KEY_DECREASE;
757 case HILDON_HARDKEY_FULLSCREEN:
758 custom_key = CUSTOM_KEY_FULLSCREEN;
760 case HILDON_HARDKEY_ESC:
761 custom_key = CUSTOM_KEY_ESC;
764 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
768 switch (_action[custom_key]) {
769 case CUSTOM_ACTION_PAN_NORTH:
770 map_pan(0, -PAN_UNITS);
773 case CUSTOM_ACTION_PAN_WEST:
774 map_pan(-PAN_UNITS, 0);
777 case CUSTOM_ACTION_PAN_SOUTH:
778 map_pan(0, PAN_UNITS);
781 case CUSTOM_ACTION_PAN_EAST:
782 map_pan(PAN_UNITS, 0);
785 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
786 switch (_center_mode) {
788 case CENTER_WAS_LEAD:
789 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
790 (_menu_ac_lead_item),
794 case CENTER_WAS_LATLON:
795 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
796 (_menu_ac_latlon_item),
803 case CUSTOM_ACTION_ZOOM_IN:
804 case CUSTOM_ACTION_ZOOM_OUT:
805 if (!_key_zoom_timeout_sid) {
806 g_printf("Z: %d %d\n", _key_zoom_new, _zoom);
807 _key_zoom_new = _zoom
808 + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN
809 ? -_curr_repo->view_zoom_steps
810 : _curr_repo->view_zoom_steps);
811 /* Remember, _key_zoom_new is unsigned. */
812 if (_key_zoom_new < MAX_ZOOM) {
814 snprintf(buffer, sizeof(buffer), "%s %d",
815 _("Zoom to Level"), _key_zoom_new);
816 MACRO_BANNER_SHOW_INFO(_window, buffer);
817 _key_zoom_timeout_sid =
818 g_timeout_add(500, map_key_zoom_timeout,
824 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
825 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_fullscreen_item), !_fullscreen);
828 case CUSTOM_ACTION_TOGGLE_TRACKS:
829 switch (_show_tracks) {
831 /* Nothing shown, nothing saved; just set both. */
832 _show_tracks = TRACKS_MASK | ROUTES_MASK;
834 case TRACKS_MASK << 16:
835 case ROUTES_MASK << 16:
836 case (ROUTES_MASK | TRACKS_MASK) << 16:
837 /* Something was saved and nothing changed since.
839 _show_tracks = _show_tracks >> 16;
842 /* There is no history, or they changed something
843 * since the last historical change. Save and
845 _show_tracks = _show_tracks << 16;
847 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
848 (_menu_show_routes_item),
849 _show_tracks & ROUTES_MASK);
851 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
852 (_menu_show_tracks_item),
853 _show_tracks & TRACKS_MASK);
855 case CUSTOM_ACTION_TOGGLE_SCALE:
856 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
857 (_menu_show_scale_item),
861 case CUSTOM_ACTION_TOGGLE_POI:
862 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
863 (_menu_show_poi_item),
866 case CUSTOM_ACTION_CHANGE_REPO:{
867 GList *curr = g_list_find(_repo_list, _curr_repo);
871 /* Loop until we reach a next-able repo, or until we get
872 * back to the current repo. */
873 while ((curr = (curr->next ? curr->next : _repo_list))
874 && !((RepoData *) curr->data)->nextable
875 && curr->data != _curr_repo) {
878 if (curr->data != _curr_repo) {
879 repo_set_curr(curr->data);
880 gtk_check_menu_item_set_active
881 (GTK_CHECK_MENU_ITEM(_curr_repo->menu_item),
886 ("There are no other next-able repositories."));
891 case CUSTOM_ACTION_ROUTE_DISTNEXT:
892 route_show_distance_to_next();
895 case CUSTOM_ACTION_ROUTE_DISTLAST:
896 route_show_distance_to_last();
899 case CUSTOM_ACTION_TRACK_BREAK:
900 track_insert_break();
903 case CUSTOM_ACTION_TRACK_DISTLAST:
904 track_show_distance_from_last();
907 case CUSTOM_ACTION_TRACK_DISTFIRST:
908 track_show_distance_from_first();
911 case CUSTOM_ACTION_TOGGLE_GPS:
912 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
913 (_menu_enable_gps_item),
917 case CUSTOM_ACTION_TOGGLE_GPSINFO:
918 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
919 (_menu_gps_show_info_item),
923 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
924 _speed_limit_on ^= 1;
928 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
933 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
936 gboolean window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
938 printf("%s()\n", __PRETTY_FUNCTION__);
940 switch (event->keyval) {
941 case HILDON_HARDKEY_INCREASE:
942 case HILDON_HARDKEY_DECREASE:
943 if (_key_zoom_timeout_sid) {
944 g_source_remove(_key_zoom_timeout_sid);
945 _key_zoom_timeout_sid = 0;
946 map_set_zoom(_key_zoom_new);
953 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
956 void cmenu_show_latlon(guint unitx, guint unity)
959 gchar buffer[80], tmp1[16], tmp2[16];
960 printf("%s()\n", __PRETTY_FUNCTION__);
962 g_printf("S: %d %d\n", unitx, unity);
964 unit2latlon(unitx, unity, lat, lon);
965 lat_format(lat, tmp1);
966 lon_format(lon, tmp2);
968 snprintf(buffer, sizeof(buffer),
970 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
972 MACRO_BANNER_SHOW_INFO(_window, buffer);
974 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
977 void cmenu_clip_latlon(guint unitx, guint unity)
981 printf("%s()\n", __PRETTY_FUNCTION__);
983 unit2latlon(unitx, unity, lat, lon);
985 snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
987 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
990 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
993 void cmenu_route_to(guint unitx, guint unity)
999 printf("%s()\n", __PRETTY_FUNCTION__);
1001 unit2latlon(unitx, unity, lat, lon);
1003 g_ascii_formatd(strlat, 32, "%.06f", lat);
1004 g_ascii_formatd(strlon, 32, "%.06f", lon);
1005 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
1007 route_download(buffer);
1009 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1012 void cmenu_distance_to(guint unitx, guint unity)
1016 printf("%s()\n", __PRETTY_FUNCTION__);
1018 unit2latlon(unitx, unity, lat, lon);
1020 snprintf(buffer, sizeof(buffer), "%s: %.02f %s", _("Distance"),
1021 calculate_distance(_gps.lat, _gps.lon, lat, lon)
1022 * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
1023 MACRO_BANNER_SHOW_INFO(_window, buffer);
1025 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1028 void cmenu_add_route(guint unitx, guint unity)
1030 printf("%s()\n", __PRETTY_FUNCTION__);
1031 MACRO_PATH_INCREMENT_TAIL(_route);
1032 _route.tail->unitx = x2unit(_cmenu_position_x);
1033 _route.tail->unity = y2unit(_cmenu_position_y);
1034 route_find_nearest_point();
1036 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1039 void cmenu_route_add_way(guint unitx, guint unity)
1042 gchar tmp1[16], tmp2[16], *p_latlon;
1046 GtkWidget *txt_scroll;
1047 GtkWidget *txt_desc;
1048 printf("%s()\n", __PRETTY_FUNCTION__);
1050 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
1051 GTK_WINDOW(_window),
1052 GTK_DIALOG_MODAL, GTK_STOCK_OK,
1053 GTK_RESPONSE_ACCEPT,
1055 GTK_RESPONSE_REJECT, NULL);
1057 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1058 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
1060 gtk_table_attach(GTK_TABLE(table),
1061 label = gtk_label_new(_("Lat, Lon")),
1062 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
1063 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1065 unit2latlon(unitx, unity, lat, lon);
1066 lat_format(lat, tmp1);
1067 lon_format(lon, tmp2);
1068 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
1069 gtk_table_attach(GTK_TABLE(table),
1070 label = gtk_label_new(p_latlon),
1071 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
1072 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
1075 gtk_table_attach(GTK_TABLE(table),
1076 label = gtk_label_new(_("Description")),
1077 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
1078 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1080 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
1081 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
1083 gtk_table_attach(GTK_TABLE(table),
1085 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
1087 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
1088 GTK_POLICY_AUTOMATIC,
1089 GTK_POLICY_AUTOMATIC);
1091 txt_desc = gtk_text_view_new();
1092 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
1094 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
1095 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
1097 gtk_widget_show_all(dialog);
1099 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
1100 GtkTextBuffer *tbuf;
1101 GtkTextIter ti1, ti2;
1104 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
1105 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
1106 gtk_text_buffer_get_end_iter(tbuf, &ti2);
1107 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
1110 /* There's a description. Add a waypoint. */
1111 MACRO_PATH_INCREMENT_TAIL(_route);
1112 _route.tail->unitx = unitx;
1113 _route.tail->unity = unity;
1114 _route.tail->time = 0;
1115 _route.tail->altitude = NAN;
1117 MACRO_PATH_INCREMENT_WTAIL(_route);
1118 _route.wtail->point = _route.tail;
1120 = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
1126 confirm = hildon_note_new_confirmation(GTK_WINDOW(dialog),
1127 _("Creating a \"waypoint\" with no description actually "
1128 "adds a break point. Is that what you want?"));
1130 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1131 /* There's no description. Add a break by adding a (0, 0)
1132 * point (if necessary), and then the ordinary route point. */
1133 if (_route.tail->unity) {
1134 MACRO_PATH_INCREMENT_TAIL(_route);
1135 *_route.tail = _point_null;
1138 MACRO_PATH_INCREMENT_TAIL(_route);
1139 _route.tail->unitx = unitx;
1140 _route.tail->unity = unity;
1141 _route.tail->time = 0;
1142 _route.tail->altitude = NAN;
1144 gtk_widget_destroy(confirm);
1146 gtk_widget_destroy(confirm);
1151 route_find_nearest_point();
1153 MACRO_QUEUE_DRAW_AREA();
1156 gtk_widget_destroy(dialog);
1157 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1160 gboolean cmenu_cb_loc_show_latlon(GtkAction * action)
1162 printf("%s()\n", __PRETTY_FUNCTION__);
1164 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1166 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1170 gboolean cmenu_cb_loc_clip_latlon(GtkAction * action)
1172 printf("%s()\n", __PRETTY_FUNCTION__);
1174 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1176 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1180 gboolean cmenu_cb_loc_route_to(GtkAction * action)
1182 printf("%s()\n", __PRETTY_FUNCTION__);
1184 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1186 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1190 gboolean cmenu_cb_loc_distance_to(GtkAction * action)
1192 printf("%s()\n", __PRETTY_FUNCTION__);
1194 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1196 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1200 gboolean cmenu_cb_loc_add_route(GtkAction * action)
1202 printf("%s()\n", __PRETTY_FUNCTION__);
1204 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1206 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1210 gboolean cmenu_cb_loc_add_way(GtkAction * action)
1212 printf("%s()\n", __PRETTY_FUNCTION__);
1214 cmenu_route_add_way(x2unit(_cmenu_position_x),
1215 y2unit(_cmenu_position_y));
1217 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1221 gboolean cmenu_cb_loc_add_poi(GtkAction * action)
1223 printf("%s()\n", __PRETTY_FUNCTION__);
1225 poi_dialog(ACTION_ADD_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1227 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1231 gboolean cb_add_poi(GtkAction * action)
1234 printf("%s()\n", __PRETTY_FUNCTION__);
1236 latlon2unit(_gps.lat, _gps.lon, unitx, unity);
1237 poi_dialog(ACTION_ADD_POI, unitx, unity);
1239 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1243 gboolean cmenu_cb_loc_set_home(GtkAction * action)
1245 _pos.unitx = x2unit(_cmenu_position_x);
1246 _pos.unity = y2unit(_cmenu_position_y);
1247 unit2latlon(_pos.unitx, _pos.unity, _home.lat, _home.lon);
1253 gboolean cmenu_cb_loc_set_gps(GtkAction * action)
1255 _pos.unitx = x2unit(_cmenu_position_x);
1256 _pos.unity = y2unit(_cmenu_position_y);
1257 unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
1259 /* Move mark to new location. */
1265 gboolean cmenu_cb_way_show_latlon(GtkAction * action)
1268 printf("%s()\n", __PRETTY_FUNCTION__);
1270 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1271 y2unit(_cmenu_position_y))))
1272 cmenu_show_latlon(way->point->unitx, way->point->unity);
1274 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1278 gboolean cmenu_cb_way_show_desc(GtkAction * action)
1281 printf("%s()\n", __PRETTY_FUNCTION__);
1283 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1284 y2unit(_cmenu_position_y)))) {
1285 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1288 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1292 gboolean cmenu_cb_way_clip_latlon(GtkAction * action)
1295 printf("%s()\n", __PRETTY_FUNCTION__);
1297 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1298 y2unit(_cmenu_position_y))))
1299 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1301 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1305 gboolean cmenu_cb_way_clip_desc(GtkAction * action)
1308 printf("%s()\n", __PRETTY_FUNCTION__);
1310 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1311 y2unit(_cmenu_position_y))))
1312 gtk_clipboard_set_text(gtk_clipboard_get
1313 (GDK_SELECTION_CLIPBOARD), way->desc,
1316 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1320 gboolean cmenu_cb_way_route_to(GtkAction * action)
1323 printf("%s()\n", __PRETTY_FUNCTION__);
1325 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1326 y2unit(_cmenu_position_y))))
1327 cmenu_route_to(way->point->unitx, way->point->unity);
1329 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1333 gboolean cmenu_cb_way_distance_to(GtkAction * action)
1336 printf("%s()\n", __PRETTY_FUNCTION__);
1338 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1339 y2unit(_cmenu_position_y))))
1340 route_show_distance_to(way->point);
1342 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1346 gboolean cmenu_cb_way_delete(GtkAction * action)
1349 printf("%s()\n", __PRETTY_FUNCTION__);
1351 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1352 y2unit(_cmenu_position_y)))) {
1353 gchar buffer[BUFFER_SIZE];
1356 snprintf(buffer, sizeof(buffer), "%s:\n%s\n",
1357 _("Confirm delete of waypoint"), way->desc);
1358 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
1360 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1361 Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
1364 /* Delete surrounding route data, too. */
1365 if (way == _route.whead)
1366 pdel_min = _route.head;
1368 pdel_min = way[-1].point;
1370 if (way == _route.wtail)
1371 pdel_max = _route.tail;
1373 pdel_max = way[1].point;
1375 /* Find largest continuous segment around the waypoint, EXCLUDING
1376 * pdel_min and pdel_max. */
1377 for (pdel_start = way->point - 1; pdel_start->unity
1378 && pdel_start > pdel_min; pdel_start--) {
1380 for (pdel_end = way->point + 1; pdel_end->unity
1381 && pdel_end < pdel_max; pdel_end++) {
1384 /* If pdel_end is set to _route.tail, and if _route.tail is a
1385 * non-zero point, then delete _route.tail. */
1386 if (pdel_end == _route.tail && pdel_end->unity)
1387 pdel_end++; /* delete _route.tail too */
1388 /* else, if *both* endpoints are zero points, delete one. */
1389 else if (!pdel_start->unity && !pdel_end->unity)
1392 /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
1393 num_del = pdel_end - pdel_start - 1;
1395 memmove(pdel_start + 1, pdel_end,
1396 (_route.tail - pdel_end + 1) * sizeof(Point));
1397 _route.tail -= num_del;
1399 /* Remove waypoint and move/adjust subsequent waypoints. */
1401 while (way++ != _route.wtail) {
1403 way[-1].point -= num_del;
1407 route_find_nearest_point();
1410 gtk_widget_destroy(confirm);
1413 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1417 gboolean cmenu_cb_way_add_poi(GtkAction * action)
1420 printf("%s()\n", __PRETTY_FUNCTION__);
1422 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1423 poi_dialog(ACTION_ADD_POI, way->point->unitx, way->point->unity);
1425 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1429 gboolean cmenu_cb_poi_route_to(GtkAction * action)
1432 printf("%s()\n", __PRETTY_FUNCTION__);
1434 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1436 latlon2unit(poi.lat, poi.lon, unitx, unity);
1437 cmenu_route_to(unitx, unity);
1440 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1444 gboolean cmenu_cb_poi_distance_to(GtkAction * action)
1447 printf("%s()\n", __PRETTY_FUNCTION__);
1449 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1451 latlon2unit(poi.lat, poi.lon, unitx, unity);
1452 cmenu_distance_to(unitx, unity);
1455 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1459 gboolean cmenu_cb_poi_add_route(GtkAction * action)
1462 printf("%s()\n", __PRETTY_FUNCTION__);
1464 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1466 latlon2unit(poi.lat, poi.lon, unitx, unity);
1467 cmenu_add_route(unitx, unity);
1470 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1474 gboolean cmenu_cb_poi_add_way(GtkAction * action)
1477 printf("%s()\n", __PRETTY_FUNCTION__);
1479 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1481 latlon2unit(poi.lat, poi.lon, unitx, unity);
1482 cmenu_route_add_way(unitx, unity);
1485 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1489 gboolean cmenu_cb_poi_edit_poi(GtkAction * action)
1491 printf("%s()\n", __PRETTY_FUNCTION__);
1493 poi_dialog(ACTION_EDIT_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1495 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);