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(&_route);
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(&_route);
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)
284 map_dialog_goto_latlon();
289 menu_cb_goto_home(GtkAction *action)
291 if (map_goto_position(&_home)==FALSE) {
292 MACRO_BANNER_SHOW_INFO(_window, _("Home not set."));
295 MACRO_BANNER_SHOW_INFO(_window, _("At home location"));
301 menu_cb_goto_destination(GtkAction *action)
303 if (map_goto_position(&_dest)==FALSE) {
304 MACRO_BANNER_SHOW_INFO(_window, _("Destination not set."));
307 MACRO_BANNER_SHOW_INFO(_window, _("At destination"));
313 menu_cb_goto_gps(GtkAction *action)
315 _center_mode = CENTER_LATLON;
316 map_center_unit(_pos.unitx, _pos.unity);
317 map_update_location_from_center();
323 menu_cb_goto_nextway(GtkAction * action)
325 if (_next_way && _next_way->point->unity) {
326 if (_center_mode > 0)
327 set_action_activate("autocenter_none", TRUE);
329 map_center_unit(_next_way->point->unitx, _next_way->point->unity);
331 MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
338 menu_cb_goto_nearpoi(GtkAction * action)
343 if (_center_mode > 0) {
344 /* Auto-Center is enabled - use the GPS position. */
345 unit2latlon(_pos.unitx, _pos.unity, lat, lon);
347 /* Auto-Center is disabled - use the view center. */
348 unit2latlon(_center.unitx, _center.unity, lat, lon);
351 p=poi_find_nearest(lat, lon);
357 latlon2unit(p->lat, p->lon, unitx, unity);
358 banner = g_strdup_printf("%s (%s)", p->label, p->cat_label);
359 g_printf("%s\n", banner);
360 MACRO_BANNER_SHOW_INFO(_window, banner);
364 if (_center_mode > 0)
365 set_action_activate("autocenter_none", TRUE);
367 map_center_unit(unitx, unity);
368 map_update_location_from_center();
370 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
377 menu_cb_maps_repoman(GtkAction * action)
384 menu_cb_maps_select(GtkAction * action, gpointer new_repo)
386 repo_set_curr(new_repo);
392 cb_zoom_auto(GtkAction * action)
394 map_set_autozoom(TRUE);
399 cb_zoom_base(GtkAction * action)
401 map_set_autozoom(FALSE);
407 cb_zoomin(GtkAction * action)
409 map_set_autozoom(FALSE);
410 g_idle_add((GSourceFunc)map_zoom_in, NULL);
415 cb_zoomout(GtkAction * action)
417 map_set_autozoom(FALSE);
418 g_idle_add((GSourceFunc)map_zoom_out, NULL);
423 cb_fullscreen(GtkAction * action)
425 if ((_fullscreen = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
426 gtk_window_fullscreen(GTK_WINDOW(_window));
428 gtk_window_unfullscreen(GTK_WINDOW(_window));
430 gtk_idle_add((GSourceFunc) window_present, NULL);
435 menu_cb_enable_gps(GtkAction * action)
437 if ((_enable_gps = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
439 gps_conn_set_state(RCVR_DOWN);
442 popup_error(_window, _("Cannot enable GPS until a GPS Receiver MAC is set in the Settings dialog box."));
443 set_action_activate("gps_enable", FALSE);
446 if (_conn_state > RCVR_OFF)
447 gps_conn_set_state(RCVR_OFF);
452 if (_enable_gps==FALSE)
453 set_action_activate("autocenter_none", TRUE);
454 set_action_sensitive("gps_details", _enable_gps);
455 set_action_sensitive("goto_gps", _enable_gps);
456 set_action_sensitive("autocenter_latlon", _enable_gps);
457 set_action_sensitive("autocenter_lead", _enable_gps);
466 menu_cb_auto_download(GtkAction * action)
468 if ((_auto_download = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) )) {
469 if (_curr_repo->url == REPOTYPE_NONE)
470 popup_error(_window, _("NOTE: You must set a Map URI in the current repository in order to download maps."));
478 menu_cb_gps_details(GtkAction * action)
485 menu_cb_settings(GtkAction * action)
487 if (settings_dialog()) {
488 /* Settings have changed - reconnect to receiver. */
490 gps_conn_set_state(RCVR_DOWN);
495 MACRO_RECALC_FOCUS_BASE();
496 MACRO_RECALC_FOCUS_SIZE();
502 menu_cb_help(GtkAction * action)
504 help_topic_display(HELP_ID_INTRO, 0);
509 menu_cb_about(GtkAction * action)
514 "Cezary Jackiewicz", NULL
517 gtk_show_about_dialog(GTK_WINDOW(_window),
520 "copyright", "Kaj-Michael Lang",
528 window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
530 CustomKey custom_key;
532 switch (event->keyval) {
533 case HILDON_HARDKEY_UP:
534 custom_key = CUSTOM_KEY_UP;
536 case HILDON_HARDKEY_DOWN:
537 custom_key = CUSTOM_KEY_DOWN;
539 case HILDON_HARDKEY_LEFT:
540 custom_key = CUSTOM_KEY_LEFT;
542 case HILDON_HARDKEY_RIGHT:
543 custom_key = CUSTOM_KEY_RIGHT;
545 case HILDON_HARDKEY_SELECT:
546 custom_key = CUSTOM_KEY_SELECT;
548 case HILDON_HARDKEY_INCREASE:
549 custom_key = CUSTOM_KEY_INCREASE;
551 case HILDON_HARDKEY_DECREASE:
552 custom_key = CUSTOM_KEY_DECREASE;
554 case HILDON_HARDKEY_FULLSCREEN:
555 custom_key = CUSTOM_KEY_FULLSCREEN;
557 case HILDON_HARDKEY_ESC:
558 custom_key = CUSTOM_KEY_ESC;
564 switch (_action[custom_key]) {
565 case CUSTOM_ACTION_PAN_NORTH:
566 map_pan(0, -PAN_UNITS);
568 case CUSTOM_ACTION_PAN_WEST:
569 map_pan(-PAN_UNITS, 0);
571 case CUSTOM_ACTION_PAN_SOUTH:
572 map_pan(0, PAN_UNITS);
574 case CUSTOM_ACTION_PAN_EAST:
575 map_pan(PAN_UNITS, 0);
577 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
578 switch (_center_mode) {
580 case CENTER_WAS_LEAD:
581 set_action_activate("autocenter_lead", TRUE);
584 case CENTER_WAS_LATLON:
585 set_action_activate("autocenter_latlon", TRUE);
588 set_action_activate("autocenter_latlon", TRUE);
592 case CUSTOM_ACTION_ZOOM_IN:
593 case CUSTOM_ACTION_ZOOM_OUT:
594 if (!_key_zoom_timeout_sid) {
595 _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps);
596 /* Remember, _key_zoom_new is unsigned. */
597 if (_key_zoom_new < MAX_ZOOM) {
598 _key_zoom_timeout_sid = g_timeout_add(400, map_key_zoom_timeout, NULL);
602 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
603 set_action_activate("view_fullscreen", !_fullscreen);
605 case CUSTOM_ACTION_TOGGLE_TRACKS:
606 switch (_show_tracks) {
608 /* Nothing shown, nothing saved; just set both. */
609 _show_tracks = TRACKS_MASK | ROUTES_MASK;
611 case TRACKS_MASK << 16:
612 case ROUTES_MASK << 16:
613 case (ROUTES_MASK | TRACKS_MASK) << 16:
614 /* Something was saved and nothing changed since.
616 _show_tracks = _show_tracks >> 16;
619 /* There is no history, or they changed something
620 * since the last historical change. Save and
622 _show_tracks = _show_tracks << 16;
624 set_action_activate("view_route", _show_tracks & ROUTES_MASK);
625 set_action_activate("view_track", _show_tracks & TRACKS_MASK);
627 case CUSTOM_ACTION_TOGGLE_SCALE:
628 set_action_activate("view_scale", _show_scale);
630 case CUSTOM_ACTION_TOGGLE_POI:
631 set_action_activate("view_poi", _show_poi);
633 case CUSTOM_ACTION_CHANGE_REPO: {
634 GList *curr = g_list_find(_repo_list, _curr_repo);
638 /* Loop until we reach a next-able repo, or until we get
639 * back to the current repo. */
640 while ((curr = (curr->next ? curr->next : _repo_list)) && !((RepoData *) curr->data)->nextable && curr->data != _curr_repo) {
643 if (curr->data != _curr_repo) {
644 repo_set_curr(curr->data);
645 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_curr_repo->menu_item), TRUE);
647 popup_error(_window, _("There are no other next-able repositories."));
652 case CUSTOM_ACTION_ROUTE_DISTNEXT:
653 route_show_distance_to_next();
655 case CUSTOM_ACTION_ROUTE_DISTLAST:
656 route_show_distance_to_last();
658 case CUSTOM_ACTION_TRACK_BREAK:
659 track_insert_break();
661 case CUSTOM_ACTION_TRACK_DISTLAST:
662 track_show_distance_from_last();
664 case CUSTOM_ACTION_TRACK_DISTFIRST:
665 track_show_distance_from_first();
667 case CUSTOM_ACTION_TOGGLE_GPS:
668 set_action_activate("gps_enable", !_enable_gps);
670 case CUSTOM_ACTION_TOGGLE_GPSINFO:
671 set_action_activate("gps_info", !_gps_info);
673 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
683 window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
685 switch (event->keyval) {
686 case HILDON_HARDKEY_INCREASE:
687 case HILDON_HARDKEY_DECREASE:
688 if (_key_zoom_timeout_sid) {
689 g_source_remove(_key_zoom_timeout_sid);
690 _key_zoom_timeout_sid = 0;
691 map_set_zoom(_key_zoom_new);
701 cmenu_show_latlon(guint unitx, guint unity)
704 gchar buffer[80], tmp1[16], tmp2[16];
706 unit2latlon(unitx, unity, lat, lon);
707 lat_format(_degformat, lat, tmp1);
708 lon_format(_degformat, lon, tmp2);
710 g_snprintf(buffer, sizeof(buffer),
712 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
714 MACRO_BANNER_SHOW_INFO(_window, buffer);
718 cmenu_clip_latlon(guint unitx, guint unity)
723 unit2latlon(unitx, unity, lat, lon);
724 g_snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
726 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buffer, -1);
730 cmenu_route_to(guint unitx, guint unity)
737 unit2latlon(unitx, unity, lat, lon);
739 g_ascii_formatd(strlat, 32, "%.06f", lat);
740 g_ascii_formatd(strlon, 32, "%.06f", lon);
741 g_snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
743 route_download(buffer);
747 cmenu_distance_to(guint unitx, guint unity)
752 unit2latlon(unitx, unity, lat, lon);
754 g_snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"),
755 calculate_distance(_gps.lat, _gps.lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
756 MACRO_BANNER_SHOW_INFO(_window, buffer);
760 cmenu_add_route(guint unitx, guint unity)
762 MACRO_PATH_INCREMENT_TAIL(_route);
763 _route.tail->unitx = x2unit(_cmenu_position_x);
764 _route.tail->unity = y2unit(_cmenu_position_y);
765 route_find_nearest_point();
769 void cmenu_route_add_way(guint unitx, guint unity)
772 gchar tmp1[16], tmp2[16], *p_latlon;
776 GtkWidget *txt_scroll;
779 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
781 GTK_DIALOG_MODAL, GTK_STOCK_OK,
784 GTK_RESPONSE_REJECT, NULL);
786 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
787 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
789 gtk_table_attach(GTK_TABLE(table),
790 label = gtk_label_new(_("Lat, Lon")),
791 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
792 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
794 unit2latlon(unitx, unity, lat, lon);
795 lat_format(_degformat, lat, tmp1);
796 lon_format(_degformat, lon, tmp2);
797 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
798 gtk_table_attach(GTK_TABLE(table),
799 label = gtk_label_new(p_latlon),
800 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
801 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
804 gtk_table_attach(GTK_TABLE(table),
805 label = gtk_label_new(_("Description")),
806 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
807 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
809 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
810 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
812 gtk_table_attach(GTK_TABLE(table),
814 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
816 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
817 GTK_POLICY_AUTOMATIC,
818 GTK_POLICY_AUTOMATIC);
820 txt_desc = gtk_text_view_new();
821 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
823 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
824 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
826 gtk_widget_show_all(dialog);
828 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
830 GtkTextIter ti1, ti2;
833 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
834 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
835 gtk_text_buffer_get_end_iter(tbuf, &ti2);
836 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
839 /* There's a description. Add a waypoint. */
840 MACRO_PATH_INCREMENT_TAIL(_route);
841 _route.tail->unitx = unitx;
842 _route.tail->unity = unity;
843 _route.tail->time = 0;
844 _route.tail->altitude = NAN;
846 MACRO_PATH_INCREMENT_WTAIL(_route);
847 _route.wtail->point = _route.tail;
849 = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
855 confirm = hildon_note_new_confirmation(GTK_WINDOW(dialog),
856 _("Creating a \"waypoint\" with no description actually "
857 "adds a break point. Is that what you want?"));
859 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
860 /* There's no description. Add a break by adding a (0, 0)
861 * point (if necessary), and then the ordinary route point. */
862 if (_route.tail->unity) {
863 MACRO_PATH_INCREMENT_TAIL(_route);
864 *_route.tail = _point_null;
867 MACRO_PATH_INCREMENT_TAIL(_route);
868 _route.tail->unitx = unitx;
869 _route.tail->unity = unity;
870 _route.tail->time = 0;
871 _route.tail->altitude = NAN;
873 gtk_widget_destroy(confirm);
875 gtk_widget_destroy(confirm);
880 route_find_nearest_point();
882 MACRO_QUEUE_DRAW_AREA();
885 gtk_widget_destroy(dialog);
889 cmenu_cb_loc_show_latlon(GtkAction * action)
891 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
896 cmenu_cb_loc_clip_latlon(GtkAction * action)
898 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
903 cmenu_cb_loc_route_to(GtkAction * action)
905 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
910 cmenu_cb_loc_distance_to(GtkAction * action)
912 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
917 cmenu_cb_loc_add_route(GtkAction * action)
919 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
924 cmenu_cb_loc_add_way(GtkAction * action)
926 cmenu_route_add_way(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
931 cmenu_cb_loc_add_poi(GtkAction * action)
937 ux=x2unit(_cmenu_position_x);
938 uy=y2unit(_cmenu_position_y);
939 unit2latlon(ux, uy, poi->lat, poi->lon);
940 poi_edit_dialog(ACTION_ADD_POI, poi);
946 cb_poi_search(GtkAction *action)
951 if (_center_mode>0) {
955 unit2latlon(_center.unitx, _center.unity, lat, lon);
958 mapper_search_dialog(SEARCH_TYPE_POI, lat, lon);
963 cb_poi_add(GtkAction *action)
966 const gchar *name = gtk_action_get_name(action);
969 if (_center_mode>0) {
973 unit2latlon(_center.unitx, _center.unity, lat, lon);
976 if (strcmp(name, "poi_add")==0) {
980 poi_edit_dialog(ACTION_ADD_POI, p);
981 map_poi_cache_clear();
982 } else if (strcmp(name, "poi_quick_add")==0) {
983 poi_quick_dialog(lat, lon);
984 map_poi_cache_clear();
986 g_assert_not_reached();
992 menu_cb_search_address(GtkAction *action)
996 if (_center_mode>0) {
1000 unit2latlon(_center.unitx, _center.unity, lat, lon);
1002 mapper_search_dialog(SEARCH_TYPE_WAY, lat, lon);
1007 cmenu_cb_loc_set_home(GtkAction * action)
1011 unitx = x2unit(_cmenu_position_x);
1012 unity = y2unit(_cmenu_position_y);
1013 unit2latlon(unitx, unity, _home.lat, _home.lon);
1022 cmenu_cb_loc_set_destination(GtkAction *action)
1026 unitx = x2unit(_cmenu_position_x);
1027 unity = y2unit(_cmenu_position_y);
1028 unit2latlon(unitx, unity, _dest.lat, _dest.lon);
1031 map_update_location_from_center();
1037 cmenu_cb_loc_set_gps(GtkAction * action)
1039 _pos.unitx = x2unit(_cmenu_position_x);
1040 _pos.unity = y2unit(_cmenu_position_y);
1041 unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
1043 /* Move mark to new location. */
1045 track_add(time(NULL), FALSE);
1051 cmenu_cb_way_show_latlon(GtkAction * action)
1055 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1056 cmenu_show_latlon(way->point->unitx, way->point->unity);
1062 cmenu_cb_way_show_desc(GtkAction * action)
1066 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1067 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1074 cmenu_cb_way_clip_latlon(GtkAction * action)
1078 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1079 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1084 cmenu_cb_way_clip_desc(GtkAction * action)
1088 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1089 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), way->desc, -1);
1095 cmenu_cb_way_route_to(GtkAction * action)
1099 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1100 cmenu_route_to(way->point->unitx, way->point->unity);
1106 cmenu_cb_way_distance_to(GtkAction * action)
1110 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1111 route_show_distance_to(way->point);
1117 cmenu_cb_way_delete(GtkAction * action)
1121 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1122 gchar buffer[BUFFER_SIZE];
1125 g_snprintf(buffer, sizeof(buffer), "%s:\n%s\n", _("Confirm delete of waypoint"), way->desc);
1126 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
1128 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1129 Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
1132 /* Delete surrounding route data, too. */
1133 if (way == _route.whead)
1134 pdel_min = _route.head;
1136 pdel_min = way[-1].point;
1138 if (way == _route.wtail)
1139 pdel_max = _route.tail;
1141 pdel_max = way[1].point;
1143 /* Find largest continuous segment around the waypoint, EXCLUDING
1144 * pdel_min and pdel_max. */
1145 for (pdel_start = way->point - 1; pdel_start->unity
1146 && pdel_start > pdel_min; pdel_start--) {
1148 for (pdel_end = way->point + 1; pdel_end->unity
1149 && pdel_end < pdel_max; pdel_end++) {
1152 /* If pdel_end is set to _route.tail, and if _route.tail is a
1153 * non-zero point, then delete _route.tail. */
1154 if (pdel_end == _route.tail && pdel_end->unity)
1155 pdel_end++; /* delete _route.tail too */
1156 /* else, if *both* endpoints are zero points, delete one. */
1157 else if (!pdel_start->unity && !pdel_end->unity)
1160 /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
1161 num_del = pdel_end - pdel_start - 1;
1163 memmove(pdel_start + 1, pdel_end,(_route.tail - pdel_end + 1) * sizeof(Point));
1164 _route.tail -= num_del;
1166 /* Remove waypoint and move/adjust subsequent waypoints. */
1168 while (way++ != _route.wtail) {
1170 way[-1].point -= num_del;
1174 route_find_nearest_point();
1177 gtk_widget_destroy(confirm);
1184 menu_cb_category(GtkAction * action)
1186 if (poi_category_list())
1193 cmenu_cb_way_add_poi(GtkAction * action)
1197 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1201 unit2latlon(way->point->unitx, way->point->unity, p->lat, p->lon);
1202 poi_edit_dialog(ACTION_ADD_POI, p);
1208 cmenu_cb_poi_route_to(GtkAction * action)
1212 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1214 latlon2unit(poi.lat, poi.lon, unitx, unity);
1215 cmenu_route_to(unitx, unity);
1222 cmenu_cb_poi_distance_to(GtkAction * action)
1226 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1228 latlon2unit(poi.lat, poi.lon, unitx, unity);
1229 cmenu_distance_to(unitx, unity);
1236 cmenu_cb_poi_add_route(GtkAction * action)
1240 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1242 latlon2unit(poi.lat, poi.lon, unitx, unity);
1243 cmenu_add_route(unitx, unity);
1250 cmenu_cb_poi_add_way(GtkAction * action)
1254 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1256 latlon2unit(poi.lat, poi.lon, unitx, unity);
1257 cmenu_route_add_way(unitx, unity);
1264 cmenu_cb_poi_show_poi(GtkAction *action)
1266 /* XXX: Write this */
1271 cmenu_cb_poi_edit_poi(GtkAction * action)
1276 unit2latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), lat, lon);
1277 p=poi_find_nearest(lat, lon);
1279 popup_error(_window, _("No POI found at location."));
1282 poi_edit_dialog(ACTION_EDIT_POI, p);