13 #include <glib/gstdio.h>
19 #include "hildon-mapper.h"
29 #include "mapper-types.h"
31 #include "ui-common.h"
35 #include "gps-panels.h"
38 menu_cb_route_download(GtkAction * action)
43 store=route_generate_store();
45 gtk_tree_view_set_model(route_tree_view, store);
46 g_object_unref(G_OBJECT(store));
52 menu_cb_route_open(GtkAction * action)
57 store=route_generate_store();
59 gtk_tree_view_set_model(route_tree_view, store);
60 g_object_unref(G_OBJECT(store));
66 menu_cb_route_distnext(GtkAction * action)
68 route_show_distance_to_next();
73 menu_cb_route_distlast(GtkAction * action)
75 route_show_distance_to_last();
80 menu_cb_route_reset(GtkAction * action)
82 route_find_nearest_point();
84 MACRO_QUEUE_DRAW_AREA();
89 menu_cb_route_clear(GtkAction * action)
92 gtk_tree_view_set_model(route_tree_view, NULL);
97 menu_cb_track_open(GtkAction * action)
104 menu_cb_track_save(GtkAction * action)
111 menu_cb_track_insert_break(GtkAction * action)
113 track_insert_break();
118 menu_cb_track_insert_mark(GtkAction * action)
125 menu_cb_track_distlast(GtkAction * action)
127 track_show_distance_from_last();
132 menu_cb_track_distfirst(GtkAction * action)
134 track_show_distance_from_first();
139 menu_cb_route_save(GtkAction * action)
146 menu_cb_track_clear(GtkAction * action)
153 menu_cb_track_filter(GtkAction * action)
160 menu_cb_show_tracks(GtkAction *action)
162 _show_tracks ^= TRACKS_MASK;
163 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
164 _show_tracks |= TRACKS_MASK;
166 MACRO_QUEUE_DRAW_AREA();
167 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now shown"));
169 _show_tracks &= ~TRACKS_MASK;
171 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now hidden"));
177 menu_cb_show_scale(GtkAction * action)
179 _show_scale = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
180 MACRO_QUEUE_DRAW_AREA();
185 menu_cb_show_routes(GtkAction * action)
187 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
188 _show_tracks |= ROUTES_MASK;
190 MACRO_QUEUE_DRAW_AREA();
191 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now shown"));
193 _show_tracks &= ~ROUTES_MASK;
195 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now hidden"));
201 menu_cb_show_velvec(GtkAction * action)
203 _show_velvec = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
209 menu_cb_show_poi(GtkAction * action)
211 _show_poi = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
217 menu_cb_gps_show_info(GtkAction * action)
219 _gps_info = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
225 menu_cb_autocenter(GtkAction *action, GtkRadioAction *current)
227 guint new_center_unitx, new_center_unity;
228 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
232 _center_mode = CENTER_LEAD;
233 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lead"));
236 _center_mode = CENTER_LATLON;
237 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lat/Lon"));
241 _center_mode = -_center_mode;
242 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Off"));
247 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
248 map_center_unit(new_center_unitx, new_center_unity);
253 menu_cb_goto_latlon(GtkAction * action)
261 dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"),
263 GTK_DIALOG_MODAL, GTK_STOCK_OK,
266 GTK_RESPONSE_REJECT, NULL);
268 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0);
270 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Latitude")),0, 1, 0, 1, GTK_FILL, 0, 2, 4);
271 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
273 gtk_table_attach(GTK_TABLE(table), txt_lat = gtk_entry_new(), 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
274 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
276 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Longitude")), 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
277 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
279 gtk_table_attach(GTK_TABLE(table), txt_lon = gtk_entry_new(), 1, 2, 1, 2, GTK_FILL, 0, 2, 4);
280 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
282 #ifdef WITH_DEVICE_770
283 g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
284 g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
287 /* Initialize with the current center position. */
291 unit2latlon(_center.unitx, _center.unity, lat, lon);
292 snprintf(buffer, sizeof(buffer), "%.06f", lat);
293 gtk_label_set_text(GTK_LABEL(txt_lat), buffer);
294 snprintf(buffer, sizeof(buffer), "%.06f", lon);
295 gtk_label_set_text(GTK_LABEL(txt_lon), buffer);
298 gtk_widget_show_all(dialog);
300 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
306 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
307 lat = strtof(text, &error_check);
308 if (text == error_check || lat < -90.f || lat > 90.f) {
309 popup_error(dialog, _("Invalid Latitude"));
313 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
314 lon = strtof(text, &error_check);
315 if (text == error_check || lon < -180.f || lon > 180.f) {
316 popup_error(dialog, _("Invalid Longitude"));
320 latlon2unit(lat, lon, unitx, unity);
321 if (_center_mode > 0)
322 set_action_activate("autocenter_none", TRUE);
324 map_center_unit(unitx, unity);
327 gtk_widget_destroy(dialog);
332 menu_cb_goto_home(GtkAction *action)
334 if (map_goto_position(&_home)==FALSE) {
335 MACRO_BANNER_SHOW_INFO(_window, _("Home not set."));
337 MACRO_BANNER_SHOW_INFO(_window, _("At home location"));
343 menu_cb_goto_destination(GtkAction *action)
345 if (map_goto_position(&_dest)==FALSE) {
346 MACRO_BANNER_SHOW_INFO(_window, _("Destination not set."));
348 MACRO_BANNER_SHOW_INFO(_window, _("At destination"));
354 menu_cb_goto_gps(GtkAction *action)
356 _center_mode = CENTER_LATLON;
357 map_center_unit(_pos.unitx, _pos.unity);
358 map_update_location_from_center();
364 menu_cb_goto_nextway(GtkAction * action)
366 if (_next_way && _next_way->point->unity) {
367 if (_center_mode > 0)
368 set_action_activate("autocenter_none", TRUE);
370 map_center_unit(_next_way->point->unitx, _next_way->point->unity);
372 MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
379 menu_cb_goto_nearpoi(GtkAction * action)
384 if (_center_mode > 0) {
385 /* Auto-Center is enabled - use the GPS position. */
386 unit2latlon(_pos.unitx, _pos.unity, lat, lon);
388 /* Auto-Center is disabled - use the view center. */
389 unit2latlon(_center.unitx, _center.unity, lat, lon);
392 p=poi_find_nearest(lat, lon);
398 latlon2unit(p->lat, p->lon, unitx, unity);
399 banner = g_strdup_printf("%s (%s)", p->label, p->cat_label);
400 g_printf("%s\n", banner);
401 MACRO_BANNER_SHOW_INFO(_window, banner);
405 if (_center_mode > 0)
406 set_action_activate("autocenter_none", TRUE);
408 map_center_unit(unitx, unity);
409 map_update_location_from_center();
411 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
418 menu_cb_maps_repoman(GtkAction * action)
425 menu_cb_maps_select(GtkAction * action, gpointer new_repo)
427 repo_set_curr(new_repo);
433 cb_zoom_auto(GtkAction * action)
435 map_set_autozoom(TRUE);
440 cb_zoom_base(GtkAction * action)
442 map_set_autozoom(FALSE);
448 cb_zoomin(GtkAction * action)
450 map_set_autozoom(FALSE);
456 cb_zoomout(GtkAction * action)
458 map_set_autozoom(FALSE);
464 cb_fullscreen(GtkAction * action)
466 if ((_fullscreen = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
467 gtk_window_fullscreen(GTK_WINDOW(_window));
469 gtk_window_unfullscreen(GTK_WINDOW(_window));
471 gtk_idle_add((GSourceFunc) window_present, NULL);
476 menu_cb_enable_gps(GtkAction * action)
478 if ((_enable_gps = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
480 set_conn_state(RCVR_DOWN);
483 popup_error(_window, _("Cannot enable GPS until a GPS Receiver MAC is set in the Settings dialog box."));
484 set_action_activate("gps_enable", FALSE);
487 if (_conn_state > RCVR_OFF)
488 set_conn_state(RCVR_OFF);
493 set_action_sensitive("gps_details", _enable_gps);
494 set_action_sensitive("goto_gps", _enable_gps);
495 set_action_sensitive("autocenter_latlon", _enable_gps);
496 set_action_sensitive("autocenter_lead", _enable_gps);
505 menu_cb_auto_download(GtkAction * action)
507 if ((_auto_download = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) )) {
508 if (_curr_repo->url == REPOTYPE_NONE)
509 popup_error(_window, _("NOTE: You must set a Map URI in the current repository in order to download maps."));
517 menu_cb_gps_details(GtkAction * action)
524 menu_cb_settings(GtkAction * action)
526 if (settings_dialog()) {
527 /* Settings have changed - reconnect to receiver. */
529 set_conn_state(RCVR_DOWN);
534 MACRO_RECALC_FOCUS_BASE();
535 MACRO_RECALC_FOCUS_SIZE();
541 menu_cb_help(GtkAction * action)
543 #ifdef WITH_OSSO_HELP
544 ossohelp_show(_osso, HELP_ID_INTRO, 0);
550 menu_cb_about(GtkAction * action)
555 "Cezary Jackiewicz", NULL
558 gtk_show_about_dialog(GTK_WINDOW(_window),
561 "copyright", "Kaj-Michael Lang",
569 window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
571 CustomKey custom_key;
573 switch (event->keyval) {
574 case HILDON_HARDKEY_UP:
575 custom_key = CUSTOM_KEY_UP;
577 case HILDON_HARDKEY_DOWN:
578 custom_key = CUSTOM_KEY_DOWN;
580 case HILDON_HARDKEY_LEFT:
581 custom_key = CUSTOM_KEY_LEFT;
583 case HILDON_HARDKEY_RIGHT:
584 custom_key = CUSTOM_KEY_RIGHT;
586 case HILDON_HARDKEY_SELECT:
587 custom_key = CUSTOM_KEY_SELECT;
589 case HILDON_HARDKEY_INCREASE:
590 custom_key = CUSTOM_KEY_INCREASE;
592 case HILDON_HARDKEY_DECREASE:
593 custom_key = CUSTOM_KEY_DECREASE;
595 case HILDON_HARDKEY_FULLSCREEN:
596 custom_key = CUSTOM_KEY_FULLSCREEN;
598 case HILDON_HARDKEY_ESC:
599 custom_key = CUSTOM_KEY_ESC;
605 switch (_action[custom_key]) {
606 case CUSTOM_ACTION_PAN_NORTH:
607 map_pan(0, -PAN_UNITS);
609 case CUSTOM_ACTION_PAN_WEST:
610 map_pan(-PAN_UNITS, 0);
612 case CUSTOM_ACTION_PAN_SOUTH:
613 map_pan(0, PAN_UNITS);
615 case CUSTOM_ACTION_PAN_EAST:
616 map_pan(PAN_UNITS, 0);
618 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
619 switch (_center_mode) {
621 case CENTER_WAS_LEAD:
622 set_action_activate("autocenter_lead", TRUE);
625 case CENTER_WAS_LATLON:
626 set_action_activate("autocenter_latlon", TRUE);
629 set_action_activate("autocenter_latlon", TRUE);
633 case CUSTOM_ACTION_ZOOM_IN:
634 case CUSTOM_ACTION_ZOOM_OUT:
635 if (!_key_zoom_timeout_sid) {
636 g_printf("Z: %d %d\n", _key_zoom_new, _zoom);
637 _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN
638 ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps);
639 /* Remember, _key_zoom_new is unsigned. */
640 if (_key_zoom_new < MAX_ZOOM) {
642 snprintf(buffer, sizeof(buffer), "%s %d", _("Zoom to Level"), _key_zoom_new);
643 MACRO_BANNER_SHOW_INFO(_window, buffer);
644 _key_zoom_timeout_sid = g_timeout_add(400, map_key_zoom_timeout, NULL);
648 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
649 set_action_activate("view_fullscreen", !_fullscreen);
651 case CUSTOM_ACTION_TOGGLE_TRACKS:
652 switch (_show_tracks) {
654 /* Nothing shown, nothing saved; just set both. */
655 _show_tracks = TRACKS_MASK | ROUTES_MASK;
657 case TRACKS_MASK << 16:
658 case ROUTES_MASK << 16:
659 case (ROUTES_MASK | TRACKS_MASK) << 16:
660 /* Something was saved and nothing changed since.
662 _show_tracks = _show_tracks >> 16;
665 /* There is no history, or they changed something
666 * since the last historical change. Save and
668 _show_tracks = _show_tracks << 16;
670 set_action_activate("view_route", _show_tracks & ROUTES_MASK);
671 set_action_activate("view_track", _show_tracks & TRACKS_MASK);
673 case CUSTOM_ACTION_TOGGLE_SCALE:
674 set_action_activate("view_scale", _show_scale);
676 case CUSTOM_ACTION_TOGGLE_POI:
677 set_action_activate("view_poi", _show_poi);
679 case CUSTOM_ACTION_CHANGE_REPO: {
680 GList *curr = g_list_find(_repo_list, _curr_repo);
684 /* Loop until we reach a next-able repo, or until we get
685 * back to the current repo. */
686 while ((curr = (curr->next ? curr->next : _repo_list)) && !((RepoData *) curr->data)->nextable && curr->data != _curr_repo) {
689 if (curr->data != _curr_repo) {
690 repo_set_curr(curr->data);
691 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_curr_repo->menu_item), TRUE);
693 popup_error(_window, _("There are no other next-able repositories."));
698 case CUSTOM_ACTION_ROUTE_DISTNEXT:
699 route_show_distance_to_next();
701 case CUSTOM_ACTION_ROUTE_DISTLAST:
702 route_show_distance_to_last();
704 case CUSTOM_ACTION_TRACK_BREAK:
705 track_insert_break();
707 case CUSTOM_ACTION_TRACK_DISTLAST:
708 track_show_distance_from_last();
710 case CUSTOM_ACTION_TRACK_DISTFIRST:
711 track_show_distance_from_first();
713 case CUSTOM_ACTION_TOGGLE_GPS:
714 set_action_activate("gps_enable", !_enable_gps);
716 case CUSTOM_ACTION_TOGGLE_GPSINFO:
717 set_action_activate("gps_info", !_gps_info);
719 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
720 _speed_limit_on ^= 1;
729 window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
731 switch (event->keyval) {
732 case HILDON_HARDKEY_INCREASE:
733 case HILDON_HARDKEY_DECREASE:
734 if (_key_zoom_timeout_sid) {
735 g_source_remove(_key_zoom_timeout_sid);
736 _key_zoom_timeout_sid = 0;
737 map_set_zoom(_key_zoom_new);
747 cmenu_show_latlon(guint unitx, guint unity)
750 gchar buffer[80], tmp1[16], tmp2[16];
752 unit2latlon(unitx, unity, lat, lon);
753 lat_format(lat, tmp1);
754 lon_format(lon, tmp2);
756 snprintf(buffer, sizeof(buffer),
758 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
760 MACRO_BANNER_SHOW_INFO(_window, buffer);
764 cmenu_clip_latlon(guint unitx, guint unity)
769 unit2latlon(unitx, unity, lat, lon);
770 snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
772 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buffer, -1);
776 cmenu_route_to(guint unitx, guint unity)
783 unit2latlon(unitx, unity, lat, lon);
785 g_ascii_formatd(strlat, 32, "%.06f", lat);
786 g_ascii_formatd(strlon, 32, "%.06f", lon);
787 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
789 route_download(buffer);
793 cmenu_distance_to(guint unitx, guint unity)
798 unit2latlon(unitx, unity, lat, lon);
800 snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"),
801 calculate_distance(_gps.lat, _gps.lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
802 MACRO_BANNER_SHOW_INFO(_window, buffer);
806 cmenu_add_route(guint unitx, guint unity)
808 MACRO_PATH_INCREMENT_TAIL(_route);
809 _route.tail->unitx = x2unit(_cmenu_position_x);
810 _route.tail->unity = y2unit(_cmenu_position_y);
811 route_find_nearest_point();
815 void cmenu_route_add_way(guint unitx, guint unity)
818 gchar tmp1[16], tmp2[16], *p_latlon;
822 GtkWidget *txt_scroll;
825 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
827 GTK_DIALOG_MODAL, GTK_STOCK_OK,
830 GTK_RESPONSE_REJECT, NULL);
832 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
833 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
835 gtk_table_attach(GTK_TABLE(table),
836 label = gtk_label_new(_("Lat, Lon")),
837 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
838 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
840 unit2latlon(unitx, unity, lat, lon);
841 lat_format(lat, tmp1);
842 lon_format(lon, tmp2);
843 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
844 gtk_table_attach(GTK_TABLE(table),
845 label = gtk_label_new(p_latlon),
846 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
847 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
850 gtk_table_attach(GTK_TABLE(table),
851 label = gtk_label_new(_("Description")),
852 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
853 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
855 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
856 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
858 gtk_table_attach(GTK_TABLE(table),
860 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
862 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
863 GTK_POLICY_AUTOMATIC,
864 GTK_POLICY_AUTOMATIC);
866 txt_desc = gtk_text_view_new();
867 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
869 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
870 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
872 gtk_widget_show_all(dialog);
874 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
876 GtkTextIter ti1, ti2;
879 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
880 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
881 gtk_text_buffer_get_end_iter(tbuf, &ti2);
882 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
885 /* There's a description. Add a waypoint. */
886 MACRO_PATH_INCREMENT_TAIL(_route);
887 _route.tail->unitx = unitx;
888 _route.tail->unity = unity;
889 _route.tail->time = 0;
890 _route.tail->altitude = NAN;
892 MACRO_PATH_INCREMENT_WTAIL(_route);
893 _route.wtail->point = _route.tail;
895 = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
901 confirm = hildon_note_new_confirmation(GTK_WINDOW(dialog),
902 _("Creating a \"waypoint\" with no description actually "
903 "adds a break point. Is that what you want?"));
905 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
906 /* There's no description. Add a break by adding a (0, 0)
907 * point (if necessary), and then the ordinary route point. */
908 if (_route.tail->unity) {
909 MACRO_PATH_INCREMENT_TAIL(_route);
910 *_route.tail = _point_null;
913 MACRO_PATH_INCREMENT_TAIL(_route);
914 _route.tail->unitx = unitx;
915 _route.tail->unity = unity;
916 _route.tail->time = 0;
917 _route.tail->altitude = NAN;
919 gtk_widget_destroy(confirm);
921 gtk_widget_destroy(confirm);
926 route_find_nearest_point();
928 MACRO_QUEUE_DRAW_AREA();
931 gtk_widget_destroy(dialog);
935 cmenu_cb_loc_show_latlon(GtkAction * action)
937 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
942 cmenu_cb_loc_clip_latlon(GtkAction * action)
944 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
949 cmenu_cb_loc_route_to(GtkAction * action)
951 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
956 cmenu_cb_loc_distance_to(GtkAction * action)
958 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
963 cmenu_cb_loc_add_route(GtkAction * action)
965 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
970 cmenu_cb_loc_add_way(GtkAction * action)
972 cmenu_route_add_way(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
977 cmenu_cb_loc_add_poi(GtkAction * action)
979 poi_dialog(ACTION_ADD_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
984 cb_poi_search(GtkAction *action)
988 poi_search_dialog(NULL, &poi);
993 cb_poi_add(GtkAction *action)
996 const gchar *name = gtk_action_get_name(action);
998 if (_center_mode > 0) {
999 latlon2unit(_gps.lat, _gps.lon, unitx, unity);
1001 unitx=_center.unitx;
1002 unity=_center.unity;
1005 if (strcmp(name, "poi_add")==0)
1006 poi_dialog(ACTION_ADD_POI, unitx, unity);
1007 else if (strcmp(name, "poi_quick_add")==0)
1008 poi_quick_dialog(unitx, unity);
1010 g_assert_not_reached();
1016 cmenu_cb_loc_set_home(GtkAction * action)
1020 unitx = x2unit(_cmenu_position_x);
1021 unity = y2unit(_cmenu_position_y);
1022 unit2latlon(unitx, unity, _home.lat, _home.lon);
1031 cmenu_cb_loc_set_destination(GtkAction *action)
1035 unitx = x2unit(_cmenu_position_x);
1036 unity = y2unit(_cmenu_position_y);
1037 unit2latlon(unitx, unity, _dest.lat, _dest.lon);
1039 map_update_location_from_center();
1044 cmenu_cb_loc_set_gps(GtkAction * action)
1046 _pos.unitx = x2unit(_cmenu_position_x);
1047 _pos.unity = y2unit(_cmenu_position_y);
1048 unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
1050 /* Move mark to new location. */
1052 track_add(time(NULL), FALSE);
1058 cmenu_cb_way_show_latlon(GtkAction * action)
1062 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1063 cmenu_show_latlon(way->point->unitx, way->point->unity);
1069 cmenu_cb_way_show_desc(GtkAction * action)
1073 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1074 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1081 cmenu_cb_way_clip_latlon(GtkAction * action)
1085 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1086 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1091 cmenu_cb_way_clip_desc(GtkAction * action)
1095 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1096 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), way->desc, -1);
1102 cmenu_cb_way_route_to(GtkAction * action)
1106 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1107 cmenu_route_to(way->point->unitx, way->point->unity);
1113 cmenu_cb_way_distance_to(GtkAction * action)
1117 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1118 route_show_distance_to(way->point);
1124 cmenu_cb_way_delete(GtkAction * action)
1128 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1129 gchar buffer[BUFFER_SIZE];
1132 snprintf(buffer, sizeof(buffer), "%s:\n%s\n",
1133 _("Confirm delete of waypoint"), way->desc);
1134 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
1136 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1137 Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
1140 /* Delete surrounding route data, too. */
1141 if (way == _route.whead)
1142 pdel_min = _route.head;
1144 pdel_min = way[-1].point;
1146 if (way == _route.wtail)
1147 pdel_max = _route.tail;
1149 pdel_max = way[1].point;
1151 /* Find largest continuous segment around the waypoint, EXCLUDING
1152 * pdel_min and pdel_max. */
1153 for (pdel_start = way->point - 1; pdel_start->unity
1154 && pdel_start > pdel_min; pdel_start--) {
1156 for (pdel_end = way->point + 1; pdel_end->unity
1157 && pdel_end < pdel_max; pdel_end++) {
1160 /* If pdel_end is set to _route.tail, and if _route.tail is a
1161 * non-zero point, then delete _route.tail. */
1162 if (pdel_end == _route.tail && pdel_end->unity)
1163 pdel_end++; /* delete _route.tail too */
1164 /* else, if *both* endpoints are zero points, delete one. */
1165 else if (!pdel_start->unity && !pdel_end->unity)
1168 /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
1169 num_del = pdel_end - pdel_start - 1;
1171 memmove(pdel_start + 1, pdel_end,(_route.tail - pdel_end + 1) * sizeof(Point));
1172 _route.tail -= num_del;
1174 /* Remove waypoint and move/adjust subsequent waypoints. */
1176 while (way++ != _route.wtail) {
1178 way[-1].point -= num_del;
1182 route_find_nearest_point();
1185 gtk_widget_destroy(confirm);
1192 menu_cb_category(GtkAction * action)
1194 if (category_list())
1201 cmenu_cb_way_add_poi(GtkAction * action)
1205 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1206 poi_dialog(ACTION_ADD_POI, way->point->unitx, way->point->unity);
1212 cmenu_cb_poi_route_to(GtkAction * action)
1216 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1218 latlon2unit(poi.lat, poi.lon, unitx, unity);
1219 cmenu_route_to(unitx, unity);
1226 cmenu_cb_poi_distance_to(GtkAction * action)
1230 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1232 latlon2unit(poi.lat, poi.lon, unitx, unity);
1233 cmenu_distance_to(unitx, unity);
1240 cmenu_cb_poi_add_route(GtkAction * action)
1244 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1246 latlon2unit(poi.lat, poi.lon, unitx, unity);
1247 cmenu_add_route(unitx, unity);
1254 cmenu_cb_poi_add_way(GtkAction * action)
1258 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1260 latlon2unit(poi.lat, poi.lon, unitx, unity);
1261 cmenu_route_add_way(unitx, unity);
1268 cmenu_cb_poi_edit_poi(GtkAction * action)
1270 poi_dialog(ACTION_EDIT_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));