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.
36 #include <glib/gstdio.h>
42 #include "hildon-mapper.h"
52 #include "mapper-types.h"
53 #include "ui-common.h"
58 #include "gps-panels.h"
64 menu_cb_route_download(GtkAction * action)
69 store=route_generate_store(&_route);
71 gtk_tree_view_set_model(route_tree_view, store);
72 g_object_unref(G_OBJECT(store));
78 menu_cb_route_open(GtkAction * action)
83 store=route_generate_store(&_route);
85 gtk_tree_view_set_model(route_tree_view, store);
86 g_object_unref(G_OBJECT(store));
92 menu_cb_route_distnext(GtkAction * action)
94 route_show_distance_to_next();
99 menu_cb_route_distlast(GtkAction * action)
101 route_show_distance_to_last();
106 menu_cb_route_reset(GtkAction * action)
108 route_find_nearest_point();
110 MACRO_QUEUE_DRAW_AREA();
115 menu_cb_route_clear(GtkAction * action)
118 gtk_tree_view_set_model(route_tree_view, NULL);
123 menu_cb_track_open(GtkAction * action)
130 menu_cb_track_save(GtkAction * action)
137 menu_cb_track_insert_break(GtkAction * action)
139 track_insert_break();
144 menu_cb_track_insert_mark(GtkAction * action)
151 menu_cb_track_distlast(GtkAction * action)
153 track_show_distance_from_last();
158 menu_cb_track_distfirst(GtkAction * action)
160 track_show_distance_from_first();
165 menu_cb_route_save(GtkAction * action)
172 menu_cb_track_clear(GtkAction * action)
179 menu_cb_track_filter(GtkAction * action)
186 menu_cb_show_tracks(GtkAction *action)
188 _show_tracks ^= TRACKS_MASK;
189 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
190 _show_tracks |= TRACKS_MASK;
192 MACRO_QUEUE_DRAW_AREA();
193 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now shown"));
195 _show_tracks &= ~TRACKS_MASK;
197 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now hidden"));
203 menu_cb_show_scale(GtkAction * action)
205 _show_scale = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
206 MACRO_QUEUE_DRAW_AREA();
211 menu_cb_show_routes(GtkAction * action)
213 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
214 _show_tracks |= ROUTES_MASK;
216 MACRO_QUEUE_DRAW_AREA();
217 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now shown"));
219 _show_tracks &= ~ROUTES_MASK;
221 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now hidden"));
227 menu_cb_show_velvec(GtkAction * action)
229 _show_velvec = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
235 menu_cb_show_poi(GtkAction * action)
237 _show_poi = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
243 menu_cb_gps_show_info(GtkAction * action)
245 _gps_info = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
251 menu_cb_autocenter(GtkAction *action, GtkRadioAction *current)
253 guint new_center_unitx, new_center_unity;
254 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
258 _center_mode = CENTER_LEAD;
259 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lead"));
262 _center_mode = CENTER_LATLON;
263 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lat/Lon"));
267 _center_mode = -_center_mode;
268 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Off"));
273 MACRO_RECALC_CENTER(_gps->data, new_center_unitx, new_center_unity);
274 map_center_unit(new_center_unitx, new_center_unity);
279 menu_cb_goto_latlon(GtkAction * action)
281 map_dialog_goto_latlon();
286 menu_cb_goto_home(GtkAction *action)
288 if (map_goto_position(&_home)==FALSE) {
289 MACRO_BANNER_SHOW_INFO(_window, _("Home not set."));
292 MACRO_BANNER_SHOW_INFO(_window, _("At home location"));
298 menu_cb_goto_destination(GtkAction *action)
300 if (map_goto_position(&_dest)==FALSE) {
301 MACRO_BANNER_SHOW_INFO(_window, _("Destination not set."));
304 MACRO_BANNER_SHOW_INFO(_window, _("At destination"));
310 menu_cb_goto_gps(GtkAction *action)
312 _center_mode = CENTER_LATLON;
313 map_center_unit(_gps->data.unitx, _gps->data.unity);
314 map_update_location_from_center();
315 MACRO_BANNER_SHOW_INFO(_window, _("At GPS coordinates."));
320 menu_cb_goto_nextway(GtkAction * action)
322 if (_next_way && _next_way->point->unity) {
323 if (_center_mode > 0)
324 set_action_activate("autocenter_none", TRUE);
326 map_center_unit(_next_way->point->unitx, _next_way->point->unity);
328 MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
335 menu_cb_goto_nearpoi(GtkAction * action)
340 if (_center_mode > 0) {
341 /* Auto-Center is enabled - use the GPS position. */
345 /* Auto-Center is disabled - use the view center. */
346 unit2latlon(_center.unitx, _center.unity, lat, lon);
349 p=poi_find_nearest(lat, lon);
355 latlon2unit(p->lat, p->lon, unitx, unity);
356 banner = g_strdup_printf("%s (%s)", p->label, p->cat_label);
357 g_printf("%s\n", banner);
358 MACRO_BANNER_SHOW_INFO(_window, banner);
362 if (_center_mode > 0)
363 set_action_activate("autocenter_none", TRUE);
365 map_center_unit(unitx, unity);
366 map_update_location_from_center();
368 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
375 menu_cb_maps_repoman(GtkAction * action)
382 menu_cb_maps_select(GtkAction * action, gpointer new_repo)
384 repo_set_curr(new_repo);
390 cb_zoom_auto(GtkAction * action)
392 map_set_autozoom(TRUE, _gps->data.speed);
397 cb_zoom_base(GtkAction * action)
399 map_set_autozoom(FALSE, 0);
405 cb_zoomin(GtkAction * action)
407 map_set_autozoom(FALSE, 0);
408 g_idle_add((GSourceFunc)map_zoom_in, NULL);
413 cb_zoomout(GtkAction * action)
415 map_set_autozoom(FALSE, 0);
416 g_idle_add((GSourceFunc)map_zoom_out, NULL);
421 cb_fullscreen(GtkAction * action)
423 if ((_fullscreen = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
424 gtk_window_fullscreen(GTK_WINDOW(_window));
426 gtk_window_unfullscreen(GTK_WINDOW(_window));
428 gtk_idle_add((GSourceFunc) window_present, NULL);
433 menu_cb_enable_gps(GtkAction * action)
435 if ((_enable_gps = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
436 if (_gps->io.address) {
437 gps_conn_set_state(_gps, RCVR_DOWN);
438 gps_connect_now(_gps);
440 popup_error(_window, _("Cannot enable GPS until a GPS Receiver has been configured in the GPS Settings dialog."));
441 set_action_activate("gps_enabled", FALSE);
444 if (_gps->io.conn > RCVR_OFF)
445 gps_conn_set_state(_gps, RCVR_OFF);
446 gps_disconnect(_gps);
447 track_add(NULL, FALSE);
450 if (_enable_gps==FALSE)
451 set_action_activate("autocenter_none", TRUE);
452 set_action_sensitive("goto_gps", _enable_gps);
453 set_action_sensitive("autocenter_latlon", _enable_gps);
454 set_action_sensitive("autocenter_lead", _enable_gps);
457 gps_show_info(&_gps->data);
463 menu_cb_auto_download(GtkAction * action)
465 if ((_auto_download = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) )) {
466 if (_curr_repo->url == REPOTYPE_NONE)
467 popup_error(_window, _("NOTE: You must set a Map URI in the current repository in order to download maps."));
475 menu_cb_settings(GtkAction * action)
478 MACRO_RECALC_FOCUS_BASE();
479 MACRO_RECALC_FOCUS_SIZE();
485 menu_cb_settings_gps(GtkAction * action)
487 if (settings_dialog_gps()) {
488 /* Settings have changed - reconnect to receiver. */
490 gps_conn_set_state(_gps, RCVR_DOWN);
491 gps_disconnect(_gps);
492 gps_connect_now(_gps);
495 MACRO_RECALC_FOCUS_BASE();
496 MACRO_RECALC_FOCUS_SIZE();
502 menu_cb_settings_osm(GtkAction * action)
504 settings_dialog_osm();
509 menu_cb_help(GtkAction * action)
511 help_topic_display(HELP_ID_INTRO, 0);
516 menu_cb_about(GtkAction * action)
521 "Cezary Jackiewicz", NULL
524 gtk_show_about_dialog(GTK_WINDOW(_window),
527 "copyright", "Kaj-Michael Lang",
535 window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
537 CustomKey custom_key;
539 switch (event->keyval) {
540 case HILDON_HARDKEY_UP:
541 custom_key = CUSTOM_KEY_UP;
543 case HILDON_HARDKEY_DOWN:
544 custom_key = CUSTOM_KEY_DOWN;
546 case HILDON_HARDKEY_LEFT:
547 custom_key = CUSTOM_KEY_LEFT;
549 case HILDON_HARDKEY_RIGHT:
550 custom_key = CUSTOM_KEY_RIGHT;
552 case HILDON_HARDKEY_SELECT:
553 custom_key = CUSTOM_KEY_SELECT;
555 case HILDON_HARDKEY_INCREASE:
556 custom_key = CUSTOM_KEY_INCREASE;
558 case HILDON_HARDKEY_DECREASE:
559 custom_key = CUSTOM_KEY_DECREASE;
561 case HILDON_HARDKEY_FULLSCREEN:
562 custom_key = CUSTOM_KEY_FULLSCREEN;
564 case HILDON_HARDKEY_ESC:
565 custom_key = CUSTOM_KEY_ESC;
571 switch (_action[custom_key]) {
572 case CUSTOM_ACTION_PAN_NORTH:
573 map_pan(0, -PAN_UNITS);
575 case CUSTOM_ACTION_PAN_WEST:
576 map_pan(-PAN_UNITS, 0);
578 case CUSTOM_ACTION_PAN_SOUTH:
579 map_pan(0, PAN_UNITS);
581 case CUSTOM_ACTION_PAN_EAST:
582 map_pan(PAN_UNITS, 0);
584 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
585 switch (_center_mode) {
587 case CENTER_WAS_LEAD:
588 set_action_activate("autocenter_lead", TRUE);
591 case CENTER_WAS_LATLON:
592 set_action_activate("autocenter_latlon", TRUE);
595 set_action_activate("autocenter_latlon", TRUE);
599 case CUSTOM_ACTION_ZOOM_IN:
600 case CUSTOM_ACTION_ZOOM_OUT:
601 if (!_key_zoom_timeout_sid) {
602 _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps);
603 /* Remember, _key_zoom_new is unsigned. */
604 if (_key_zoom_new < MAX_ZOOM) {
605 _key_zoom_timeout_sid = g_timeout_add(400, map_key_zoom_timeout, NULL);
609 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
610 set_action_activate("view_fullscreen", !_fullscreen);
612 case CUSTOM_ACTION_TOGGLE_TRACKS:
613 switch (_show_tracks) {
615 /* Nothing shown, nothing saved; just set both. */
616 _show_tracks = TRACKS_MASK | ROUTES_MASK;
618 case TRACKS_MASK << 16:
619 case ROUTES_MASK << 16:
620 case (ROUTES_MASK | TRACKS_MASK) << 16:
621 /* Something was saved and nothing changed since.
623 _show_tracks = _show_tracks >> 16;
626 /* There is no history, or they changed something
627 * since the last historical change. Save and
629 _show_tracks = _show_tracks << 16;
631 set_action_activate("view_route", _show_tracks & ROUTES_MASK);
632 set_action_activate("view_track", _show_tracks & TRACKS_MASK);
634 case CUSTOM_ACTION_TOGGLE_SCALE:
635 set_action_activate("view_scale", _show_scale);
637 case CUSTOM_ACTION_TOGGLE_POI:
638 set_action_activate("view_poi", _show_poi);
640 case CUSTOM_ACTION_CHANGE_REPO: {
641 GList *curr = g_list_find(_repo_list, _curr_repo);
645 /* Loop until we reach a next-able repo, or until we get
646 * back to the current repo. */
647 while ((curr = (curr->next ? curr->next : _repo_list)) && !((RepoData *) curr->data)->nextable && curr->data != _curr_repo) {
650 if (curr->data != _curr_repo) {
651 repo_set_curr(curr->data);
652 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_curr_repo->menu_item), TRUE);
654 popup_error(_window, _("There are no other next-able repositories."));
659 case CUSTOM_ACTION_ROUTE_DISTNEXT:
660 route_show_distance_to_next();
662 case CUSTOM_ACTION_ROUTE_DISTLAST:
663 route_show_distance_to_last();
665 case CUSTOM_ACTION_TRACK_BREAK:
666 track_insert_break();
668 case CUSTOM_ACTION_TRACK_DISTLAST:
669 track_show_distance_from_last();
671 case CUSTOM_ACTION_TRACK_DISTFIRST:
672 track_show_distance_from_first();
674 case CUSTOM_ACTION_TOGGLE_GPS:
675 set_action_activate("gps_enable", !_enable_gps);
677 case CUSTOM_ACTION_TOGGLE_GPSINFO:
678 set_action_activate("gps_info", !_gps_info);
680 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
690 window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
692 switch (event->keyval) {
693 case HILDON_HARDKEY_INCREASE:
694 case HILDON_HARDKEY_DECREASE:
695 if (_key_zoom_timeout_sid) {
696 g_source_remove(_key_zoom_timeout_sid);
697 _key_zoom_timeout_sid = 0;
698 map_set_zoom(_key_zoom_new);
708 cmenu_show_latlon(guint unitx, guint unity)
711 gchar buffer[80], tmp1[16], tmp2[16];
713 unit2latlon(unitx, unity, lat, lon);
714 lat_format(_degformat, lat, tmp1);
715 lon_format(_degformat, lon, tmp2);
717 g_snprintf(buffer, sizeof(buffer),
719 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
721 MACRO_BANNER_SHOW_INFO(_window, buffer);
725 cmenu_clip_latlon(guint unitx, guint unity)
730 unit2latlon(unitx, unity, lat, lon);
731 g_snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
733 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buffer, -1);
737 cmenu_route_to(guint unitx, guint unity)
744 unit2latlon(unitx, unity, lat, lon);
746 g_ascii_formatd(strlat, 32, "%.06f", lat);
747 g_ascii_formatd(strlon, 32, "%.06f", lon);
748 g_snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
750 route_download(buffer);
754 cmenu_distance_to(guint unitx, guint unity)
759 unit2latlon(unitx, unity, lat, lon);
761 g_snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"),
762 calculate_distance(_gps->data.lat, _gps->data.lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
763 MACRO_BANNER_SHOW_INFO(_window, buffer);
767 cmenu_add_route(guint unitx, guint unity)
769 MACRO_PATH_INCREMENT_TAIL(_route);
770 _route.tail->unitx = x2unit(_cmenu_position_x);
771 _route.tail->unity = y2unit(_cmenu_position_y);
772 route_find_nearest_point();
776 void cmenu_route_add_way(guint unitx, guint unity)
779 gchar tmp1[16], tmp2[16], *p_latlon;
783 GtkWidget *txt_scroll;
786 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
788 GTK_DIALOG_MODAL, GTK_STOCK_OK,
791 GTK_RESPONSE_REJECT, NULL);
793 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
794 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
796 gtk_table_attach(GTK_TABLE(table),
797 label = gtk_label_new(_("Lat, Lon")),
798 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
799 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
801 unit2latlon(unitx, unity, lat, lon);
802 lat_format(_degformat, lat, tmp1);
803 lon_format(_degformat, lon, tmp2);
804 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
805 gtk_table_attach(GTK_TABLE(table),
806 label = gtk_label_new(p_latlon),
807 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
808 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
811 gtk_table_attach(GTK_TABLE(table),
812 label = gtk_label_new(_("Description")),
813 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
814 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
816 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
817 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
819 gtk_table_attach(GTK_TABLE(table),
821 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
823 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
824 GTK_POLICY_AUTOMATIC,
825 GTK_POLICY_AUTOMATIC);
827 txt_desc = gtk_text_view_new();
828 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
830 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
831 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
833 gtk_widget_show_all(dialog);
835 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
837 GtkTextIter ti1, ti2;
840 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
841 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
842 gtk_text_buffer_get_end_iter(tbuf, &ti2);
843 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
846 /* There's a description. Add a waypoint. */
847 MACRO_PATH_INCREMENT_TAIL(_route);
848 _route.tail->unitx = unitx;
849 _route.tail->unity = unity;
850 _route.tail->time = 0;
851 _route.tail->altitude = NAN;
853 MACRO_PATH_INCREMENT_WTAIL(_route);
854 _route.wtail->point = _route.tail;
856 = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
862 confirm = hildon_note_new_confirmation(GTK_WINDOW(dialog),
863 _("Creating a \"waypoint\" with no description actually "
864 "adds a break point. Is that what you want?"));
866 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
867 /* There's no description. Add a break by adding a (0, 0)
868 * point (if necessary), and then the ordinary route point. */
869 if (_route.tail->unity) {
870 MACRO_PATH_INCREMENT_TAIL(_route);
871 *_route.tail = _point_null;
874 MACRO_PATH_INCREMENT_TAIL(_route);
875 _route.tail->unitx = unitx;
876 _route.tail->unity = unity;
877 _route.tail->time = 0;
878 _route.tail->altitude = NAN;
880 gtk_widget_destroy(confirm);
882 gtk_widget_destroy(confirm);
887 route_find_nearest_point();
889 MACRO_QUEUE_DRAW_AREA();
892 gtk_widget_destroy(dialog);
896 cmenu_cb_loc_show_latlon(GtkAction * action)
898 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
903 cmenu_cb_loc_clip_latlon(GtkAction * action)
905 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
910 cmenu_cb_loc_route_to(GtkAction * action)
912 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
917 cmenu_cb_loc_distance_to(GtkAction * action)
919 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
924 cmenu_cb_loc_add_route(GtkAction * action)
926 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
931 cmenu_cb_loc_add_way(GtkAction * action)
933 cmenu_route_add_way(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
938 cmenu_cb_loc_add_poi(GtkAction * action)
944 ux=x2unit(_cmenu_position_x);
945 uy=y2unit(_cmenu_position_y);
946 unit2latlon(ux, uy, poi->lat, poi->lon);
947 poi_edit_dialog(ACTION_ADD_POI, poi);
953 cb_poi_search(GtkAction *action)
958 if (_center_mode>0) {
962 unit2latlon(_center.unitx, _center.unity, lat, lon);
965 mapper_search_dialog(SEARCH_TYPE_POI, lat, lon);
970 cb_poi_add(GtkAction *action)
973 const gchar *name = gtk_action_get_name(action);
976 if (_center_mode>0) {
980 unit2latlon(_center.unitx, _center.unity, lat, lon);
983 if (strcmp(name, "poi_add")==0) {
987 poi_edit_dialog(ACTION_ADD_POI, p);
988 map_poi_cache_clear();
989 } else if (strcmp(name, "poi_quick_add")==0) {
990 poi_quick_dialog(lat, lon);
991 map_poi_cache_clear();
993 g_assert_not_reached();
999 menu_cb_search_address(GtkAction *action)
1003 if (_center_mode>0) {
1007 unit2latlon(_center.unitx, _center.unity, lat, lon);
1009 mapper_search_dialog(SEARCH_TYPE_WAY, lat, lon);
1014 cmenu_cb_loc_set_home(GtkAction * action)
1018 unitx = x2unit(_cmenu_position_x);
1019 unity = y2unit(_cmenu_position_y);
1020 unit2latlon(unitx, unity, _home.lat, _home.lon);
1029 cmenu_cb_loc_set_destination(GtkAction *action)
1033 unitx = x2unit(_cmenu_position_x);
1034 unity = y2unit(_cmenu_position_y);
1035 unit2latlon(unitx, unity, _dest.lat, _dest.lon);
1038 map_update_location_from_center();
1044 cmenu_cb_loc_set_gps(GtkAction * action)
1046 _gps->data.unitx = x2unit(_cmenu_position_x);
1047 _gps->data.unity = y2unit(_cmenu_position_y);
1048 unit2latlon(_gps->data.unitx, _gps->data.unity, _gps->data.lat, _gps->data.lon);
1050 /* Move mark to new location. */
1052 _gps->data.time=time(NULL);
1053 track_add(&_gps->data, FALSE);
1059 cmenu_cb_way_show_latlon(GtkAction * action)
1063 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1064 cmenu_show_latlon(way->point->unitx, way->point->unity);
1070 cmenu_cb_way_show_desc(GtkAction * action)
1074 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1075 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1082 cmenu_cb_way_clip_latlon(GtkAction * action)
1086 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1087 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1092 cmenu_cb_way_clip_desc(GtkAction * action)
1096 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1097 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), way->desc, -1);
1103 cmenu_cb_way_route_to(GtkAction * action)
1107 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1108 cmenu_route_to(way->point->unitx, way->point->unity);
1114 cmenu_cb_way_distance_to(GtkAction * action)
1118 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1119 route_show_distance_to(way->point);
1125 cmenu_cb_way_delete(GtkAction * action)
1129 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1130 gchar buffer[BUFFER_SIZE];
1133 g_snprintf(buffer, sizeof(buffer), "%s:\n%s\n", _("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 (poi_category_list())
1201 cmenu_cb_way_add_poi(GtkAction * action)
1205 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1209 unit2latlon(way->point->unitx, way->point->unity, p->lat, p->lon);
1210 poi_edit_dialog(ACTION_ADD_POI, p);
1216 cmenu_cb_poi_route_to(GtkAction * action)
1220 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1222 latlon2unit(poi.lat, poi.lon, unitx, unity);
1223 cmenu_route_to(unitx, unity);
1230 cmenu_cb_poi_distance_to(GtkAction * action)
1234 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1236 latlon2unit(poi.lat, poi.lon, unitx, unity);
1237 cmenu_distance_to(unitx, unity);
1244 cmenu_cb_poi_add_route(GtkAction * action)
1248 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1250 latlon2unit(poi.lat, poi.lon, unitx, unity);
1251 cmenu_add_route(unitx, unity);
1258 cmenu_cb_poi_add_way(GtkAction * action)
1262 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
1264 latlon2unit(poi.lat, poi.lon, unitx, unity);
1265 cmenu_route_add_way(unitx, unity);
1272 cmenu_cb_poi_show_poi(GtkAction *action)
1274 /* XXX: Write this */
1279 cmenu_cb_poi_edit_poi(GtkAction * action)
1284 unit2latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), lat, lon);
1285 p=poi_find_nearest(lat, lon);
1287 popup_error(_window, _("No POI found at location."));
1290 poi_edit_dialog(ACTION_EDIT_POI, p);