2 * This file is part of mapper
4 * Copyright (C) 2007 Kaj-Michael Lang
5 * Copyright (C) 2006-2007 John Costigan.
7 * POI and GPS-Info code originally written by Cezary Jackiewicz.
9 * Default map data provided by http://www.openstreetmap.org/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38 #include <glib/gstdio.h>
44 #include "hildon-mapper.h"
54 #include "mapper-types.h"
56 #include "ui-common.h"
61 #include "gps-panels.h"
67 menu_cb_route_download(GtkAction * action)
72 store=route_generate_store();
74 gtk_tree_view_set_model(route_tree_view, store);
75 g_object_unref(G_OBJECT(store));
81 menu_cb_route_open(GtkAction * action)
86 store=route_generate_store();
88 gtk_tree_view_set_model(route_tree_view, store);
89 g_object_unref(G_OBJECT(store));
95 menu_cb_route_distnext(GtkAction * action)
97 route_show_distance_to_next();
102 menu_cb_route_distlast(GtkAction * action)
104 route_show_distance_to_last();
109 menu_cb_route_reset(GtkAction * action)
111 route_find_nearest_point();
113 MACRO_QUEUE_DRAW_AREA();
118 menu_cb_route_clear(GtkAction * action)
121 gtk_tree_view_set_model(route_tree_view, NULL);
126 menu_cb_track_open(GtkAction * action)
133 menu_cb_track_save(GtkAction * action)
140 menu_cb_track_insert_break(GtkAction * action)
142 track_insert_break();
147 menu_cb_track_insert_mark(GtkAction * action)
154 menu_cb_track_distlast(GtkAction * action)
156 track_show_distance_from_last();
161 menu_cb_track_distfirst(GtkAction * action)
163 track_show_distance_from_first();
168 menu_cb_route_save(GtkAction * action)
175 menu_cb_track_clear(GtkAction * action)
182 menu_cb_track_filter(GtkAction * action)
189 menu_cb_show_tracks(GtkAction *action)
191 _show_tracks ^= TRACKS_MASK;
192 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
193 _show_tracks |= TRACKS_MASK;
195 MACRO_QUEUE_DRAW_AREA();
196 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now shown"));
198 _show_tracks &= ~TRACKS_MASK;
200 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now hidden"));
206 menu_cb_show_scale(GtkAction * action)
208 _show_scale = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
209 MACRO_QUEUE_DRAW_AREA();
214 menu_cb_show_routes(GtkAction * action)
216 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
217 _show_tracks |= ROUTES_MASK;
219 MACRO_QUEUE_DRAW_AREA();
220 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now shown"));
222 _show_tracks &= ~ROUTES_MASK;
224 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now hidden"));
230 menu_cb_show_velvec(GtkAction * action)
232 _show_velvec = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
238 menu_cb_show_poi(GtkAction * action)
240 _show_poi = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
246 menu_cb_gps_show_info(GtkAction * action)
248 _gps_info = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
254 menu_cb_autocenter(GtkAction *action, GtkRadioAction *current)
256 guint new_center_unitx, new_center_unity;
257 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
261 _center_mode = CENTER_LEAD;
262 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lead"));
265 _center_mode = CENTER_LATLON;
266 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lat/Lon"));
270 _center_mode = -_center_mode;
271 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Off"));
276 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
277 map_center_unit(new_center_unitx, new_center_unity);
282 menu_cb_goto_latlon(GtkAction * action)
290 dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"),
292 GTK_DIALOG_MODAL, GTK_STOCK_OK,
295 GTK_RESPONSE_REJECT, NULL);
297 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0);
299 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Latitude")),0, 1, 0, 1, GTK_FILL, 0, 2, 4);
300 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
302 gtk_table_attach(GTK_TABLE(table), txt_lat = gtk_entry_new(), 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
303 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
305 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Longitude")), 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
306 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
308 gtk_table_attach(GTK_TABLE(table), txt_lon = gtk_entry_new(), 1, 2, 1, 2, GTK_FILL, 0, 2, 4);
309 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
311 #if defined (WITH_DEVICE_770) && !defined(WITH_HILDON_NEW)
312 g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
313 g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
316 /* Initialize with the current center position. */
320 unit2latlon(_center.unitx, _center.unity, lat, lon);
321 snprintf(buffer, sizeof(buffer), "%.06f", lat);
322 gtk_label_set_text(GTK_LABEL(txt_lat), buffer);
323 snprintf(buffer, sizeof(buffer), "%.06f", lon);
324 gtk_label_set_text(GTK_LABEL(txt_lon), buffer);
327 gtk_widget_show_all(dialog);
329 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
335 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
336 lat = strtof(text, &error_check);
337 if (text == error_check || lat < -90.f || lat > 90.f) {
338 popup_error(dialog, _("Invalid Latitude"));
342 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
343 lon = strtof(text, &error_check);
344 if (text == error_check || lon < -180.f || lon > 180.f) {
345 popup_error(dialog, _("Invalid Longitude"));
349 latlon2unit(lat, lon, unitx, unity);
350 if (_center_mode > 0)
351 set_action_activate("autocenter_none", TRUE);
353 map_center_unit(unitx, unity);
356 gtk_widget_destroy(dialog);
361 menu_cb_goto_home(GtkAction *action)
363 if (map_goto_position(&_home)==FALSE) {
364 MACRO_BANNER_SHOW_INFO(_window, _("Home not set."));
366 MACRO_BANNER_SHOW_INFO(_window, _("At home location"));
372 menu_cb_goto_destination(GtkAction *action)
374 if (map_goto_position(&_dest)==FALSE) {
375 MACRO_BANNER_SHOW_INFO(_window, _("Destination not set."));
377 MACRO_BANNER_SHOW_INFO(_window, _("At destination"));
383 menu_cb_goto_gps(GtkAction *action)
385 _center_mode = CENTER_LATLON;
386 map_center_unit(_pos.unitx, _pos.unity);
387 map_update_location_from_center();
393 menu_cb_goto_nextway(GtkAction * action)
395 if (_next_way && _next_way->point->unity) {
396 if (_center_mode > 0)
397 set_action_activate("autocenter_none", TRUE);
399 map_center_unit(_next_way->point->unitx, _next_way->point->unity);
401 MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
408 menu_cb_goto_nearpoi(GtkAction * action)
413 if (_center_mode > 0) {
414 /* Auto-Center is enabled - use the GPS position. */
415 unit2latlon(_pos.unitx, _pos.unity, lat, lon);
417 /* Auto-Center is disabled - use the view center. */
418 unit2latlon(_center.unitx, _center.unity, lat, lon);
421 p=poi_find_nearest(lat, lon);
427 latlon2unit(p->lat, p->lon, unitx, unity);
428 banner = g_strdup_printf("%s (%s)", p->label, p->cat_label);
429 g_printf("%s\n", banner);
430 MACRO_BANNER_SHOW_INFO(_window, banner);
434 if (_center_mode > 0)
435 set_action_activate("autocenter_none", TRUE);
437 map_center_unit(unitx, unity);
438 map_update_location_from_center();
440 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
447 menu_cb_maps_repoman(GtkAction * action)
454 menu_cb_maps_select(GtkAction * action, gpointer new_repo)
456 repo_set_curr(new_repo);
462 cb_zoom_auto(GtkAction * action)
464 map_set_autozoom(TRUE);
469 cb_zoom_base(GtkAction * action)
471 map_set_autozoom(FALSE);
477 cb_zoomin(GtkAction * action)
479 map_set_autozoom(FALSE);
485 cb_zoomout(GtkAction * action)
487 map_set_autozoom(FALSE);
493 cb_fullscreen(GtkAction * action)
495 if ((_fullscreen = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
496 gtk_window_fullscreen(GTK_WINDOW(_window));
498 gtk_window_unfullscreen(GTK_WINDOW(_window));
500 gtk_idle_add((GSourceFunc) window_present, NULL);
505 menu_cb_enable_gps(GtkAction * action)
507 if ((_enable_gps = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
509 gps_conn_set_state(RCVR_DOWN);
512 popup_error(_window, _("Cannot enable GPS until a GPS Receiver MAC is set in the Settings dialog box."));
513 set_action_activate("gps_enable", FALSE);
516 if (_conn_state > RCVR_OFF)
517 gps_conn_set_state(RCVR_OFF);
522 set_action_sensitive("gps_details", _enable_gps);
523 set_action_sensitive("goto_gps", _enable_gps);
524 set_action_sensitive("autocenter_latlon", _enable_gps);
525 set_action_sensitive("autocenter_lead", _enable_gps);
534 menu_cb_auto_download(GtkAction * action)
536 if ((_auto_download = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) )) {
537 if (_curr_repo->url == REPOTYPE_NONE)
538 popup_error(_window, _("NOTE: You must set a Map URI in the current repository in order to download maps."));
546 menu_cb_gps_details(GtkAction * action)
553 menu_cb_settings(GtkAction * action)
555 if (settings_dialog()) {
556 /* Settings have changed - reconnect to receiver. */
558 gps_conn_set_state(RCVR_DOWN);
563 MACRO_RECALC_FOCUS_BASE();
564 MACRO_RECALC_FOCUS_SIZE();
570 menu_cb_help(GtkAction * action)
572 help_topic_display(HELP_ID_INTRO, 0);
577 menu_cb_about(GtkAction * action)
582 "Cezary Jackiewicz", NULL
585 gtk_show_about_dialog(GTK_WINDOW(_window),
588 "copyright", "Kaj-Michael Lang",
596 window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
598 CustomKey custom_key;
600 switch (event->keyval) {
601 case HILDON_HARDKEY_UP:
602 custom_key = CUSTOM_KEY_UP;
604 case HILDON_HARDKEY_DOWN:
605 custom_key = CUSTOM_KEY_DOWN;
607 case HILDON_HARDKEY_LEFT:
608 custom_key = CUSTOM_KEY_LEFT;
610 case HILDON_HARDKEY_RIGHT:
611 custom_key = CUSTOM_KEY_RIGHT;
613 case HILDON_HARDKEY_SELECT:
614 custom_key = CUSTOM_KEY_SELECT;
616 case HILDON_HARDKEY_INCREASE:
617 custom_key = CUSTOM_KEY_INCREASE;
619 case HILDON_HARDKEY_DECREASE:
620 custom_key = CUSTOM_KEY_DECREASE;
622 case HILDON_HARDKEY_FULLSCREEN:
623 custom_key = CUSTOM_KEY_FULLSCREEN;
625 case HILDON_HARDKEY_ESC:
626 custom_key = CUSTOM_KEY_ESC;
632 switch (_action[custom_key]) {
633 case CUSTOM_ACTION_PAN_NORTH:
634 map_pan(0, -PAN_UNITS);
636 case CUSTOM_ACTION_PAN_WEST:
637 map_pan(-PAN_UNITS, 0);
639 case CUSTOM_ACTION_PAN_SOUTH:
640 map_pan(0, PAN_UNITS);
642 case CUSTOM_ACTION_PAN_EAST:
643 map_pan(PAN_UNITS, 0);
645 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
646 switch (_center_mode) {
648 case CENTER_WAS_LEAD:
649 set_action_activate("autocenter_lead", TRUE);
652 case CENTER_WAS_LATLON:
653 set_action_activate("autocenter_latlon", TRUE);
656 set_action_activate("autocenter_latlon", TRUE);
660 case CUSTOM_ACTION_ZOOM_IN:
661 case CUSTOM_ACTION_ZOOM_OUT:
662 if (!_key_zoom_timeout_sid) {
663 g_printf("Z: %d %d\n", _key_zoom_new, _zoom);
664 _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN
665 ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps);
666 /* Remember, _key_zoom_new is unsigned. */
667 if (_key_zoom_new < MAX_ZOOM) {
669 snprintf(buffer, sizeof(buffer), "%s %d", _("Zoom to Level"), _key_zoom_new);
670 MACRO_BANNER_SHOW_INFO(_window, buffer);
671 _key_zoom_timeout_sid = g_timeout_add(400, map_key_zoom_timeout, NULL);
675 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
676 set_action_activate("view_fullscreen", !_fullscreen);
678 case CUSTOM_ACTION_TOGGLE_TRACKS:
679 switch (_show_tracks) {
681 /* Nothing shown, nothing saved; just set both. */
682 _show_tracks = TRACKS_MASK | ROUTES_MASK;
684 case TRACKS_MASK << 16:
685 case ROUTES_MASK << 16:
686 case (ROUTES_MASK | TRACKS_MASK) << 16:
687 /* Something was saved and nothing changed since.
689 _show_tracks = _show_tracks >> 16;
692 /* There is no history, or they changed something
693 * since the last historical change. Save and
695 _show_tracks = _show_tracks << 16;
697 set_action_activate("view_route", _show_tracks & ROUTES_MASK);
698 set_action_activate("view_track", _show_tracks & TRACKS_MASK);
700 case CUSTOM_ACTION_TOGGLE_SCALE:
701 set_action_activate("view_scale", _show_scale);
703 case CUSTOM_ACTION_TOGGLE_POI:
704 set_action_activate("view_poi", _show_poi);
706 case CUSTOM_ACTION_CHANGE_REPO: {
707 GList *curr = g_list_find(_repo_list, _curr_repo);
711 /* Loop until we reach a next-able repo, or until we get
712 * back to the current repo. */
713 while ((curr = (curr->next ? curr->next : _repo_list)) && !((RepoData *) curr->data)->nextable && curr->data != _curr_repo) {
716 if (curr->data != _curr_repo) {
717 repo_set_curr(curr->data);
718 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_curr_repo->menu_item), TRUE);
720 popup_error(_window, _("There are no other next-able repositories."));
725 case CUSTOM_ACTION_ROUTE_DISTNEXT:
726 route_show_distance_to_next();
728 case CUSTOM_ACTION_ROUTE_DISTLAST:
729 route_show_distance_to_last();
731 case CUSTOM_ACTION_TRACK_BREAK:
732 track_insert_break();
734 case CUSTOM_ACTION_TRACK_DISTLAST:
735 track_show_distance_from_last();
737 case CUSTOM_ACTION_TRACK_DISTFIRST:
738 track_show_distance_from_first();
740 case CUSTOM_ACTION_TOGGLE_GPS:
741 set_action_activate("gps_enable", !_enable_gps);
743 case CUSTOM_ACTION_TOGGLE_GPSINFO:
744 set_action_activate("gps_info", !_gps_info);
746 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
747 _speed_limit_on ^= 1;
756 window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
758 switch (event->keyval) {
759 case HILDON_HARDKEY_INCREASE:
760 case HILDON_HARDKEY_DECREASE:
761 if (_key_zoom_timeout_sid) {
762 g_source_remove(_key_zoom_timeout_sid);
763 _key_zoom_timeout_sid = 0;
764 map_set_zoom(_key_zoom_new);
774 cmenu_show_latlon(guint unitx, guint unity)
777 gchar buffer[80], tmp1[16], tmp2[16];
779 unit2latlon(unitx, unity, lat, lon);
780 lat_format(lat, tmp1);
781 lon_format(lon, tmp2);
783 snprintf(buffer, sizeof(buffer),
785 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
787 MACRO_BANNER_SHOW_INFO(_window, buffer);
791 cmenu_clip_latlon(guint unitx, guint unity)
796 unit2latlon(unitx, unity, lat, lon);
797 snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
799 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buffer, -1);
803 cmenu_route_to(guint unitx, guint unity)
810 unit2latlon(unitx, unity, lat, lon);
812 g_ascii_formatd(strlat, 32, "%.06f", lat);
813 g_ascii_formatd(strlon, 32, "%.06f", lon);
814 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
816 route_download(buffer);
820 cmenu_distance_to(guint unitx, guint unity)
825 unit2latlon(unitx, unity, lat, lon);
827 snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"),
828 calculate_distance(_gps.lat, _gps.lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
829 MACRO_BANNER_SHOW_INFO(_window, buffer);
833 cmenu_add_route(guint unitx, guint unity)
835 MACRO_PATH_INCREMENT_TAIL(_route);
836 _route.tail->unitx = x2unit(_cmenu_position_x);
837 _route.tail->unity = y2unit(_cmenu_position_y);
838 route_find_nearest_point();
842 void cmenu_route_add_way(guint unitx, guint unity)
845 gchar tmp1[16], tmp2[16], *p_latlon;
849 GtkWidget *txt_scroll;
852 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
854 GTK_DIALOG_MODAL, GTK_STOCK_OK,
857 GTK_RESPONSE_REJECT, NULL);
859 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
860 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
862 gtk_table_attach(GTK_TABLE(table),
863 label = gtk_label_new(_("Lat, Lon")),
864 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
865 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
867 unit2latlon(unitx, unity, lat, lon);
868 lat_format(lat, tmp1);
869 lon_format(lon, tmp2);
870 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
871 gtk_table_attach(GTK_TABLE(table),
872 label = gtk_label_new(p_latlon),
873 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
874 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
877 gtk_table_attach(GTK_TABLE(table),
878 label = gtk_label_new(_("Description")),
879 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
880 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
882 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
883 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
885 gtk_table_attach(GTK_TABLE(table),
887 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
889 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
890 GTK_POLICY_AUTOMATIC,
891 GTK_POLICY_AUTOMATIC);
893 txt_desc = gtk_text_view_new();
894 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
896 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
897 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
899 gtk_widget_show_all(dialog);
901 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
903 GtkTextIter ti1, ti2;
906 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
907 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
908 gtk_text_buffer_get_end_iter(tbuf, &ti2);
909 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
912 /* There's a description. Add a waypoint. */
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 MACRO_PATH_INCREMENT_WTAIL(_route);
920 _route.wtail->point = _route.tail;
922 = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
928 confirm = hildon_note_new_confirmation(GTK_WINDOW(dialog),
929 _("Creating a \"waypoint\" with no description actually "
930 "adds a break point. Is that what you want?"));
932 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
933 /* There's no description. Add a break by adding a (0, 0)
934 * point (if necessary), and then the ordinary route point. */
935 if (_route.tail->unity) {
936 MACRO_PATH_INCREMENT_TAIL(_route);
937 *_route.tail = _point_null;
940 MACRO_PATH_INCREMENT_TAIL(_route);
941 _route.tail->unitx = unitx;
942 _route.tail->unity = unity;
943 _route.tail->time = 0;
944 _route.tail->altitude = NAN;
946 gtk_widget_destroy(confirm);
948 gtk_widget_destroy(confirm);
953 route_find_nearest_point();
955 MACRO_QUEUE_DRAW_AREA();
958 gtk_widget_destroy(dialog);
962 cmenu_cb_loc_show_latlon(GtkAction * action)
964 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
969 cmenu_cb_loc_clip_latlon(GtkAction * action)
971 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
976 cmenu_cb_loc_route_to(GtkAction * action)
978 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
983 cmenu_cb_loc_distance_to(GtkAction * action)
985 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
990 cmenu_cb_loc_add_route(GtkAction * action)
992 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
997 cmenu_cb_loc_add_way(GtkAction * action)
999 cmenu_route_add_way(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1004 cmenu_cb_loc_add_poi(GtkAction * action)
1010 ux=x2unit(_cmenu_position_x);
1011 uy=y2unit(_cmenu_position_y);
1012 unit2latlon(ux, uy, poi->lat, poi->lon);
1013 poi_edit_dialog(ACTION_ADD_POI, poi);
1019 cb_poi_search(GtkAction *action)
1024 if (_center_mode>0) {
1028 unit2latlon(_center.unitx, _center.unity, lat, lon);
1031 mapper_search_dialog(SEARCH_TYPE_POI, lat, lon);
1036 cb_poi_add(GtkAction *action)
1039 const gchar *name = gtk_action_get_name(action);
1042 if (_center_mode>0) {
1046 unit2latlon(_center.unitx, _center.unity, lat, lon);
1049 if (strcmp(name, "poi_add")==0) {
1053 poi_edit_dialog(ACTION_ADD_POI, p);
1054 map_poi_cache_clear();
1055 } else if (strcmp(name, "poi_quick_add")==0) {
1056 poi_quick_dialog(lat, lon);
1057 map_poi_cache_clear();
1059 g_assert_not_reached();
1065 menu_cb_search_address(GtkAction *action)
1069 if (_center_mode>0) {
1073 unit2latlon(_center.unitx, _center.unity, lat, lon);
1075 mapper_search_dialog(SEARCH_TYPE_WAY, lat, lon);
1080 cmenu_cb_loc_set_home(GtkAction * action)
1084 unitx = x2unit(_cmenu_position_x);
1085 unity = y2unit(_cmenu_position_y);
1086 unit2latlon(unitx, unity, _home.lat, _home.lon);
1095 cmenu_cb_loc_set_destination(GtkAction *action)
1099 unitx = x2unit(_cmenu_position_x);
1100 unity = y2unit(_cmenu_position_y);
1101 unit2latlon(unitx, unity, _dest.lat, _dest.lon);
1104 map_update_location_from_center();
1110 cmenu_cb_loc_set_gps(GtkAction * action)
1112 _pos.unitx = x2unit(_cmenu_position_x);
1113 _pos.unity = y2unit(_cmenu_position_y);
1114 unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
1116 /* Move mark to new location. */
1118 track_add(time(NULL), FALSE);
1124 cmenu_cb_way_show_latlon(GtkAction * action)
1128 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1129 cmenu_show_latlon(way->point->unitx, way->point->unity);
1135 cmenu_cb_way_show_desc(GtkAction * action)
1139 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1140 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1147 cmenu_cb_way_clip_latlon(GtkAction * action)
1151 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1152 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1157 cmenu_cb_way_clip_desc(GtkAction * action)
1161 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1162 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), way->desc, -1);
1168 cmenu_cb_way_route_to(GtkAction * action)
1172 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1173 cmenu_route_to(way->point->unitx, way->point->unity);
1179 cmenu_cb_way_distance_to(GtkAction * action)
1183 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1184 route_show_distance_to(way->point);
1190 cmenu_cb_way_delete(GtkAction * action)
1194 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1195 gchar buffer[BUFFER_SIZE];
1198 snprintf(buffer, sizeof(buffer), "%s:\n%s\n", _("Confirm delete of waypoint"), way->desc);
1199 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
1201 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1202 Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
1205 /* Delete surrounding route data, too. */
1206 if (way == _route.whead)
1207 pdel_min = _route.head;
1209 pdel_min = way[-1].point;
1211 if (way == _route.wtail)
1212 pdel_max = _route.tail;
1214 pdel_max = way[1].point;
1216 /* Find largest continuous segment around the waypoint, EXCLUDING
1217 * pdel_min and pdel_max. */
1218 for (pdel_start = way->point - 1; pdel_start->unity
1219 && pdel_start > pdel_min; pdel_start--) {
1221 for (pdel_end = way->point + 1; pdel_end->unity
1222 && pdel_end < pdel_max; pdel_end++) {
1225 /* If pdel_end is set to _route.tail, and if _route.tail is a
1226 * non-zero point, then delete _route.tail. */
1227 if (pdel_end == _route.tail && pdel_end->unity)
1228 pdel_end++; /* delete _route.tail too */
1229 /* else, if *both* endpoints are zero points, delete one. */
1230 else if (!pdel_start->unity && !pdel_end->unity)
1233 /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
1234 num_del = pdel_end - pdel_start - 1;
1236 memmove(pdel_start + 1, pdel_end,(_route.tail - pdel_end + 1) * sizeof(Point));
1237 _route.tail -= num_del;
1239 /* Remove waypoint and move/adjust subsequent waypoints. */
1241 while (way++ != _route.wtail) {
1243 way[-1].point -= num_del;
1247 route_find_nearest_point();
1250 gtk_widget_destroy(confirm);
1257 menu_cb_category(GtkAction * action)
1259 if (poi_category_list())
1266 cmenu_cb_way_add_poi(GtkAction * action)
1270 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1274 unit2latlon(way->point->unitx, way->point->unity, p->lat, p->lon);
1275 poi_edit_dialog(ACTION_ADD_POI, p);
1281 cmenu_cb_poi_route_to(GtkAction * action)
1285 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1287 latlon2unit(poi.lat, poi.lon, unitx, unity);
1288 cmenu_route_to(unitx, unity);
1295 cmenu_cb_poi_distance_to(GtkAction * action)
1299 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1301 latlon2unit(poi.lat, poi.lon, unitx, unity);
1302 cmenu_distance_to(unitx, unity);
1309 cmenu_cb_poi_add_route(GtkAction * action)
1313 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1315 latlon2unit(poi.lat, poi.lon, unitx, unity);
1316 cmenu_add_route(unitx, unity);
1323 cmenu_cb_poi_add_way(GtkAction * action)
1327 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1329 latlon2unit(poi.lat, poi.lon, unitx, unity);
1330 cmenu_route_add_way(unitx, unity);
1337 cmenu_cb_poi_show_poi(GtkAction *action)
1339 /* XXX: Write this */
1344 cmenu_cb_poi_edit_poi(GtkAction * action)
1349 unit2latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), lat, lon);
1350 p=poi_find_nearest(lat, lon);
1352 popup_error(_window, _("No POI found at location."));
1355 poi_edit_dialog(ACTION_EDIT_POI, p);