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>
38 #include <gdk/gdkkeysyms.h>
43 #include "hildon-mapper.h"
53 #include "mapper-types.h"
54 #include "ui-common.h"
59 #include "gps-panels.h"
63 #include "filter-gui.h"
66 #include "config-gconf.h"
69 path_tree_view_update_store(GtkWidget *tree_view, Path *path)
76 store=path_generate_store(path);
80 gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), store);
81 g_object_unref(G_OBJECT(store));
85 /***********************
87 ***********************/
89 menu_cb_route_download(GtkAction * action)
91 route_download(_route, NULL);
92 route_menu_set_sensitive(path_tree_view_update_store(route_tree_view, _route));
97 menu_cb_route_open(GtkAction *action)
99 route_open_file(_route);
100 route_menu_set_sensitive(path_tree_view_update_store(route_tree_view, _route));
105 menu_cb_route_save(GtkAction * action)
112 menu_cb_route_distnext(GtkAction * action)
114 route_show_distance_to_next(_route);
119 menu_cb_route_distlast(GtkAction * action)
121 route_show_distance_to_last(_route);
126 menu_cb_route_reset(GtkAction * action)
128 route_find_nearest_point(_route);
130 MACRO_QUEUE_DRAW_AREA();
135 menu_cb_route_clear(GtkAction * action)
137 if (route_clear(_route)) {
138 gtk_tree_view_set_model(route_tree_view, NULL);
139 route_menu_set_sensitive(FALSE);
144 /***********************
146 ***********************/
148 menu_cb_track_open(GtkAction * action)
151 path_tree_view_update_store(track_tree_view, _track);
156 menu_cb_track_save(GtkAction * action)
159 path_tree_view_update_store(track_tree_view, _track);
164 menu_cb_track_insert_break(GtkAction * action)
166 path_insert_break(_track);
167 path_tree_view_update_store(track_tree_view, _track);
172 menu_cb_track_insert_mark(GtkAction * action)
174 if (track_insert_mark(_track)) {
176 MACRO_QUEUE_DRAW_AREA();
177 path_tree_view_update_store(track_tree_view, _track);
183 menu_cb_track_distlast(GtkAction * action)
185 track_show_distance_from_last(_track);
190 menu_cb_track_distfirst(GtkAction * action)
192 track_show_distance_from_first(_track);
197 menu_cb_track_clear(GtkAction * action)
200 path_tree_view_update_store(track_tree_view, _track);
205 menu_cb_track_filter(GtkAction * action)
207 filter_dialog(_window);
211 /***********************
213 ***********************/
215 menu_cb_show_tracks(GtkAction *action)
217 _show_tracks ^= TRACKS_MASK;
218 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
219 _show_tracks |= TRACKS_MASK;
221 MACRO_QUEUE_DRAW_AREA();
222 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now shown"));
224 _show_tracks &= ~TRACKS_MASK;
226 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now hidden"));
232 menu_cb_show_scale(GtkAction * action)
234 _show_scale = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
235 MACRO_QUEUE_DRAW_AREA();
240 menu_cb_show_routes(GtkAction * action)
242 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
243 _show_tracks |= ROUTES_MASK;
245 MACRO_QUEUE_DRAW_AREA();
246 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now shown"));
248 _show_tracks &= ~ROUTES_MASK;
250 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now hidden"));
256 menu_cb_show_velvec(GtkAction * action)
258 _show_velvec = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
264 menu_cb_show_poi(GtkAction * action)
266 _show_poi = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
272 menu_cb_gps_show_info(GtkAction * action)
274 _gps_info = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
280 menu_cb_autocenter(GtkAction *action, GtkRadioAction *current)
282 guint new_center_unitx, new_center_unity;
283 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
287 _center_mode = CENTER_LEAD;
288 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lead"));
291 _center_mode = CENTER_LATLON;
292 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lat/Lon"));
296 _center_mode = -_center_mode;
297 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Off"));
302 MACRO_RECALC_CENTER(_gps->data, new_center_unitx, new_center_unity);
303 map_center_unit(new_center_unitx, new_center_unity);
308 menu_cb_goto_latlon(GtkAction * action)
310 map_dialog_goto_latlon();
315 menu_cb_goto_home(GtkAction *action)
317 if (map_goto_position(&_home)==FALSE) {
318 MACRO_BANNER_SHOW_INFO(_window, _("Home not set."));
320 if (map_get_zoom()>3)
322 MACRO_BANNER_SHOW_INFO(_window, _("At home location"));
328 menu_cb_goto_destination(GtkAction *action)
330 if (map_goto_position(&_dest)==FALSE) {
331 MACRO_BANNER_SHOW_INFO(_window, _("Destination not set."));
334 MACRO_BANNER_SHOW_INFO(_window, _("At destination"));
340 menu_cb_goto_gps(GtkAction *action)
342 _center_mode = CENTER_LATLON;
343 map_center_unit(_gps->data.unitx, _gps->data.unity);
344 map_update_location_from_center();
345 MACRO_BANNER_SHOW_INFO(_window, _("At GPS coordinates."));
350 menu_cb_goto_nextway(GtkAction * action)
352 if (_next_way && _next_way->point->unity) {
353 if (_center_mode > 0)
354 set_action_activate("autocenter_none", TRUE);
356 map_center_unit(_next_way->point->unitx, _next_way->point->unity);
358 MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
365 menu_cb_goto_nearpoi(GtkAction * action)
370 if (_center_mode > 0) {
371 /* Auto-Center is enabled - use the GPS position. */
375 /* Auto-Center is disabled - use the view center. */
376 unit2latlon(_center.unitx, _center.unity, lat, lon);
379 p=poi_find_nearest(lat, lon);
385 latlon2unit(p->lat, p->lon, unitx, unity);
386 banner = g_strdup_printf("%s (%s)", p->label, p->cat_label);
387 g_printf("%s\n", banner);
388 MACRO_BANNER_SHOW_INFO(_window, banner);
392 if (_center_mode > 0)
393 set_action_activate("autocenter_none", TRUE);
395 map_center_unit(unitx, unity);
396 map_update_location_from_center();
398 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
405 menu_cb_maps_repoman(GtkAction * action)
412 menu_cb_maps_select(GtkAction * action, gpointer new_repo)
414 repo_set_curr(new_repo);
420 cb_zoom_auto(GtkAction * action)
422 map_set_autozoom(TRUE, _gps->data.speed);
427 cb_zoom_base(GtkAction * action)
429 map_set_autozoom(FALSE, 0);
435 cb_zoomin(GtkAction * action)
437 map_set_autozoom(FALSE, 0);
438 g_idle_add((GSourceFunc)map_zoom_in, NULL);
443 cb_zoomout(GtkAction * action)
445 map_set_autozoom(FALSE, 0);
446 g_idle_add((GSourceFunc)map_zoom_out, NULL);
451 cb_fullscreen(GtkAction * action)
453 if ((_fullscreen = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
454 gtk_window_fullscreen(GTK_WINDOW(_window));
456 gtk_window_unfullscreen(GTK_WINDOW(_window));
458 gtk_idle_add((GSourceFunc) window_present, NULL);
463 menu_cb_view_toolbar(GtkAction *action)
465 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))
466 gtk_widget_show(_toolbar);
468 gtk_widget_hide(_toolbar);
474 menu_cb_enable_gps(GtkAction * action)
476 if ((_enable_gps = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
477 if (_gps->io.address) {
478 gps_conn_set_state(_gps, RCVR_DOWN);
479 gps_connect_now(_gps);
481 MACRO_BANNER_SHOW_INFO(_window, _("Cannot enable GPS until a GPS Receiver has been configured in the GPS Settings dialog."));
482 set_action_activate("gps_enabled", FALSE);
485 if (_gps->io.conn > RCVR_OFF)
486 gps_conn_set_state(_gps, RCVR_OFF);
487 gps_disconnect(_gps);
488 track_add(_track, NULL);
491 if (_enable_gps==FALSE)
492 set_action_activate("autocenter_none", TRUE);
493 set_action_sensitive("goto_gps", _enable_gps);
494 set_action_sensitive("autocenter_latlon", _enable_gps);
495 set_action_sensitive("autocenter_lead", _enable_gps);
498 gps_show_info(&_gps->data);
504 menu_cb_auto_download(GtkAction * action)
506 if ((_auto_download = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) )) {
507 if (_curr_repo->url == REPOTYPE_NONE) {
508 popup_error(_window, _("NOTE: You must set a Map URI in the current repository in order to download maps."));
509 /* set_action_activate("", FALSE); */
520 menu_cb_settings(GtkAction * action)
522 if (settings_dialog()) {
523 MACRO_RECALC_FOCUS_BASE(_center_ratio);
524 MACRO_RECALC_FOCUS_SIZE(_center_ratio);
531 menu_cb_settings_gps(GtkAction * action)
533 if (settings_dialog_gps(_gps)) {
534 /* Settings have changed - reconnect to receiver. */
536 gps_conn_set_state(_gps, RCVR_DOWN);
537 gps_disconnect(_gps);
538 gps_connect_now(_gps);
546 menu_cb_settings_colors(GtkAction * action)
548 settings_dialog_colors();
554 menu_cb_settings_osm(GtkAction * action)
556 settings_dialog_osm();
561 menu_cb_settings_keys(GtkAction * action)
563 settings_dialog_hardkeys();
568 menu_cb_import_osm(GtkAction * action)
570 osm_import_dialog(_window);
575 menu_cb_help(GtkAction * action)
577 help_topic_display(HELP_ID_INTRO, 0);
582 menu_cb_about(GtkAction * action)
587 "Cezary Jackiewicz", NULL
590 gtk_show_about_dialog(GTK_WINDOW(_window),
593 "copyright", "Kaj-Michael Lang",
601 custom_key_get_type(gint keyval)
604 case HILDON_HARDKEY_UP:
605 return CUSTOM_KEY_UP;
607 case HILDON_HARDKEY_DOWN:
608 return CUSTOM_KEY_DOWN;
610 case HILDON_HARDKEY_LEFT:
611 return CUSTOM_KEY_LEFT;
613 case HILDON_HARDKEY_RIGHT:
614 return CUSTOM_KEY_RIGHT;
616 case HILDON_HARDKEY_SELECT:
617 return CUSTOM_KEY_SELECT;
619 case HILDON_HARDKEY_INCREASE:
620 return CUSTOM_KEY_INCREASE;
622 case HILDON_HARDKEY_DECREASE:
623 return CUSTOM_KEY_DECREASE;
625 case HILDON_HARDKEY_FULLSCREEN:
626 return CUSTOM_KEY_FULLSCREEN;
628 case HILDON_HARDKEY_ESC:
629 return CUSTOM_KEY_ESC;
632 return CUSTOM_KEY_ENUM_COUNT;
638 window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
640 CustomKey custom_key;
642 custom_key=custom_key_get_type(event->keyval);
643 if (custom_key==CUSTOM_KEY_ENUM_COUNT)
646 switch (_action[custom_key]) {
647 case CUSTOM_ACTION_PAN_NORTH:
648 map_pan(0, -PAN_UNITS);
650 case CUSTOM_ACTION_PAN_WEST:
651 map_pan(-PAN_UNITS, 0);
653 case CUSTOM_ACTION_PAN_SOUTH:
654 map_pan(0, PAN_UNITS);
656 case CUSTOM_ACTION_PAN_EAST:
657 map_pan(PAN_UNITS, 0);
659 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
660 switch (_center_mode) {
662 case CENTER_WAS_LEAD:
663 set_action_activate("autocenter_lead", TRUE);
666 case CENTER_WAS_LATLON:
667 set_action_activate("autocenter_latlon", TRUE);
670 set_action_activate("autocenter_latlon", TRUE);
674 case CUSTOM_ACTION_ZOOM_IN:
675 case CUSTOM_ACTION_ZOOM_OUT:
676 if (!_key_zoom_timeout_sid) {
677 _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps);
678 /* Remember, _key_zoom_new is unsigned. */
679 if (_key_zoom_new < MAX_ZOOM) {
680 _key_zoom_timeout_sid = g_timeout_add(400, map_key_zoom_timeout, NULL);
684 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
685 set_action_activate("view_fullscreen", !_fullscreen);
687 case CUSTOM_ACTION_TOGGLE_TRACKS:
688 switch (_show_tracks) {
690 /* Nothing shown, nothing saved; just set both. */
691 _show_tracks = TRACKS_MASK | ROUTES_MASK;
693 case TRACKS_MASK << 16:
694 case ROUTES_MASK << 16:
695 case (ROUTES_MASK | TRACKS_MASK) << 16:
696 /* Something was saved and nothing changed since.
698 _show_tracks = _show_tracks >> 16;
701 /* There is no history, or they changed something
702 * since the last historical change. Save and
704 _show_tracks = _show_tracks << 16;
706 set_action_activate("view_route", _show_tracks & ROUTES_MASK);
707 set_action_activate("view_track", _show_tracks & TRACKS_MASK);
709 case CUSTOM_ACTION_TOGGLE_SCALE:
710 set_action_activate("view_scale", _show_scale);
712 case CUSTOM_ACTION_TOGGLE_POI:
713 set_action_activate("view_poi", _show_poi);
715 case CUSTOM_ACTION_CHANGE_REPO: {
716 GList *curr = g_list_find(_repo_list, _curr_repo);
720 /* Loop until we reach a next-able repo, or until we get
721 * back to the current repo. */
722 while ((curr = (curr->next ? curr->next : _repo_list)) && !((RepoData *) curr->data)->nextable && curr->data != _curr_repo) {
725 if (curr->data != _curr_repo) {
726 repo_set_curr(curr->data);
727 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_curr_repo->menu_item), TRUE);
729 popup_error(_window, _("There are no other next-able repositories."));
734 case CUSTOM_ACTION_ROUTE_DISTNEXT:
735 route_show_distance_to_next(_route);
737 case CUSTOM_ACTION_ROUTE_DISTLAST:
738 route_show_distance_to_last(_route);
740 case CUSTOM_ACTION_TRACK_BREAK:
741 path_insert_break(_track);
743 case CUSTOM_ACTION_TRACK_DISTLAST:
744 track_show_distance_from_last(_track);
746 case CUSTOM_ACTION_TRACK_DISTFIRST:
747 track_show_distance_from_first(_track);
749 case CUSTOM_ACTION_TOGGLE_GPS:
750 set_action_activate("gps_enable", !_enable_gps);
752 case CUSTOM_ACTION_TOGGLE_GPSINFO:
753 set_action_activate("gps_info", !_gps_info);
755 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
765 window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
767 switch (event->keyval) {
768 case HILDON_HARDKEY_INCREASE:
769 case HILDON_HARDKEY_DECREASE:
770 if (_key_zoom_timeout_sid) {
771 g_source_remove(_key_zoom_timeout_sid);
772 _key_zoom_timeout_sid = 0;
773 map_set_zoom(_key_zoom_new);
783 cmenu_show_latlon(guint unitx, guint unity)
786 gchar buffer[80], tmp1[16], tmp2[16];
788 unit2latlon(unitx, unity, lat, lon);
789 lat_format(_degformat, lat, tmp1);
790 lon_format(_degformat, lon, tmp2);
792 g_snprintf(buffer, sizeof(buffer),
794 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
796 MACRO_BANNER_SHOW_INFO(_window, buffer);
800 cmenu_clip_latlon(guint unitx, guint unity)
805 unit2latlon(unitx, unity, lat, lon);
806 g_snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
808 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buffer, -1);
812 cmenu_route_to(guint unitx, guint unity)
819 unit2latlon(unitx, unity, lat, lon);
821 g_ascii_formatd(strlat, 32, "%.06f", lat);
822 g_ascii_formatd(strlon, 32, "%.06f", lon);
823 g_snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
825 route_download(_route, buffer);
829 cmenu_distance_to(guint unitx, guint unity)
834 unit2latlon(unitx, unity, lat, lon);
836 g_snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"),
837 calculate_distance(_gps->data.lat, _gps->data.lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
838 MACRO_BANNER_SHOW_INFO(_window, buffer);
842 cmenu_add_route(guint unitx, guint unity)
844 MACRO_PATH_INCREMENT_TAIL(*_route);
845 _route->tail->unitx = x2unit(_cmenu_position_x);
846 _route->tail->unity = y2unit(_cmenu_position_y);
847 route_find_nearest_point(_route);
851 void cmenu_route_add_way(guint unitx, guint unity)
854 gchar tmp1[16], tmp2[16], *p_latlon;
858 GtkWidget *txt_scroll;
861 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
863 GTK_DIALOG_MODAL, GTK_STOCK_OK,
866 GTK_RESPONSE_REJECT, NULL);
868 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
870 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Lat, Lon")), 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
871 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
873 unit2latlon(unitx, unity, lat, lon);
874 lat_format(_degformat, lat, tmp1);
875 lon_format(_degformat, lon, tmp2);
876 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
877 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(p_latlon), 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
878 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
881 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Description")), 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
882 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
884 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
885 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll), GTK_SHADOW_IN);
886 gtk_table_attach(GTK_TABLE(table), txt_scroll, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
888 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
890 txt_desc = gtk_text_view_new();
891 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
893 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
894 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
896 gtk_widget_show_all(dialog);
898 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
900 GtkTextIter ti1, ti2;
903 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
904 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
905 gtk_text_buffer_get_end_iter(tbuf, &ti2);
906 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
909 /* There's a description. Add a waypoint. */
910 MACRO_PATH_INCREMENT_TAIL(*_route);
911 _route->tail->unitx = unitx;
912 _route->tail->unity = unity;
913 _route->tail->time = 0;
914 _route->tail->altitude = NAN;
916 MACRO_PATH_INCREMENT_WTAIL(*_route);
917 _route->wtail->point = _route->tail;
918 _route->wtail->desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
924 confirm = hildon_note_new_confirmation(GTK_WINDOW(dialog),
925 _("Creating a \"waypoint\" with no description actually "
926 "adds a break point. Is that what you want?"));
928 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
929 /* There's no description. Add a break by adding a (0, 0)
930 * point (if necessary), and then the ordinary route point. */
931 if (_route->tail->unity) {
932 MACRO_PATH_INCREMENT_TAIL(*_route);
933 *_route->tail = _point_null;
936 MACRO_PATH_INCREMENT_TAIL(*_route);
937 _route->tail->unitx = unitx;
938 _route->tail->unity = unity;
939 _route->tail->time = 0;
940 _route->tail->altitude = NAN;
942 gtk_widget_destroy(confirm);
944 gtk_widget_destroy(confirm);
949 route_find_nearest_point(_route);
951 MACRO_QUEUE_DRAW_AREA();
954 gtk_widget_destroy(dialog);
958 cmenu_cb_loc_show_latlon(GtkAction * action)
960 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
965 cmenu_cb_loc_clip_latlon(GtkAction * action)
967 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
972 cmenu_cb_loc_route_to(GtkAction * action)
974 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
979 cmenu_cb_loc_distance_to(GtkAction * action)
981 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
986 cmenu_cb_loc_add_route(GtkAction * action)
988 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
993 cmenu_cb_loc_add_way(GtkAction * action)
995 cmenu_route_add_way(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1000 cmenu_cb_loc_add_poi(GtkAction * action)
1006 ux=x2unit(_cmenu_position_x);
1007 uy=y2unit(_cmenu_position_y);
1008 unit2latlon(ux, uy, poi->lat, poi->lon);
1009 poi_edit_dialog(ACTION_ADD_POI, poi);
1015 cb_poi_search(GtkAction *action)
1020 if (_center_mode>0) {
1024 unit2latlon(_center.unitx, _center.unity, lat, lon);
1027 mapper_search_dialog(SEARCH_TYPE_POI, lat, lon);
1032 cb_poi_add(GtkAction *action)
1035 const gchar *name = gtk_action_get_name(action);
1038 if (_center_mode>0) {
1042 unit2latlon(_center.unitx, _center.unity, lat, lon);
1045 if (strcmp(name, "poi_add")==0) {
1049 poi_edit_dialog(ACTION_ADD_POI, p);
1050 map_poi_cache_clear();
1051 } else if (strcmp(name, "poi_quick_add")==0) {
1052 poi_quick_dialog(lat, lon);
1053 map_poi_cache_clear();
1055 g_assert_not_reached();
1061 menu_cb_search_address(GtkAction *action)
1065 if (_center_mode>0) {
1069 unit2latlon(_center.unitx, _center.unity, lat, lon);
1071 mapper_search_dialog(SEARCH_TYPE_WAY, lat, lon);
1076 cmenu_cb_loc_set_home(GtkAction * action)
1080 unitx = x2unit(_cmenu_position_x);
1081 unity = y2unit(_cmenu_position_y);
1082 unit2latlon(unitx, unity, _home.lat, _home.lon);
1085 if (!config_save_position(&_home, GCONF_KEY_POSITION_HOME))
1086 popup_error(_window, _("Failed to save home position."));
1093 cmenu_cb_loc_set_destination(GtkAction *action)
1097 unitx = x2unit(_cmenu_position_x);
1098 unity = y2unit(_cmenu_position_y);
1099 unit2latlon(unitx, unity, _dest.lat, _dest.lon);
1101 if (!config_save_position(&_dest, GCONF_KEY_POSITION_DEST))
1102 popup_error(_window, _("Failed to save destination."));
1108 cmenu_cb_loc_set_gps(GtkAction * action)
1110 _gps->data.unitx = x2unit(_cmenu_position_x);
1111 _gps->data.unity = y2unit(_cmenu_position_y);
1112 unit2latlon(_gps->data.unitx, _gps->data.unity, _gps->data.lat, _gps->data.lon);
1114 /* Move mark to new location. */
1115 _gps->data.time=time(NULL);
1116 track_add(_track, &_gps->data);
1123 cmenu_cb_way_show_latlon(GtkAction * action)
1127 if ((way = route_find_nearest_waypoint(_route, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1128 cmenu_show_latlon(way->point->unitx, way->point->unity);
1134 cmenu_cb_way_show_desc(GtkAction * action)
1138 if ((way = route_find_nearest_waypoint(_route, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1139 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1146 cmenu_cb_way_clip_latlon(GtkAction * action)
1150 if ((way = route_find_nearest_waypoint(_route, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1151 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1156 cmenu_cb_way_clip_desc(GtkAction * action)
1160 if ((way = route_find_nearest_waypoint(_route, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1161 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), way->desc, -1);
1167 cmenu_cb_way_route_to(GtkAction * action)
1171 if ((way = route_find_nearest_waypoint(_route, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1172 cmenu_route_to(way->point->unitx, way->point->unity);
1178 cmenu_cb_way_distance_to(GtkAction * action)
1182 if ((way = route_find_nearest_waypoint(_route, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1183 route_show_distance_to(_route, way->point);
1189 cmenu_cb_way_delete(GtkAction * action)
1193 if ((way = route_find_nearest_waypoint(_route, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1194 gchar buffer[BUFFER_SIZE];
1197 g_snprintf(buffer, sizeof(buffer), "%s:\n%s\n", _("Confirm delete of waypoint"), way->desc);
1198 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
1200 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1201 Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
1204 /* Delete surrounding route data, too. */
1205 if (way == _route->whead)
1206 pdel_min = _route->head;
1208 pdel_min = way[-1].point;
1210 if (way == _route->wtail)
1211 pdel_max = _route->tail;
1213 pdel_max = way[1].point;
1215 /* Find largest continuous segment around the waypoint, EXCLUDING
1216 * pdel_min and pdel_max. */
1217 for (pdel_start = way->point - 1; pdel_start->unity
1218 && pdel_start > pdel_min; pdel_start--) {
1220 for (pdel_end = way->point + 1; pdel_end->unity
1221 && pdel_end < pdel_max; pdel_end++) {
1224 /* If pdel_end is set to _route->tail, and if _route->tail is a
1225 * non-zero point, then delete _route->tail. */
1226 if (pdel_end == _route->tail && pdel_end->unity)
1227 pdel_end++; /* delete _route->tail too */
1228 /* else, if *both* endpoints are zero points, delete one. */
1229 else if (!pdel_start->unity && !pdel_end->unity)
1232 /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
1233 num_del = pdel_end - pdel_start - 1;
1235 memmove(pdel_start + 1, pdel_end,(_route->tail - pdel_end + 1) * sizeof(Point));
1236 _route->tail -= num_del;
1238 /* Remove waypoint and move/adjust subsequent waypoints. */
1240 while (way++ != _route->wtail) {
1242 way[-1].point -= num_del;
1246 route_find_nearest_point(_route);
1249 gtk_widget_destroy(confirm);
1256 menu_cb_category(GtkAction * action)
1258 if (poi_category_list())
1265 cmenu_cb_way_add_poi(GtkAction * action)
1269 if ((way = route_find_nearest_waypoint(_route, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1273 unit2latlon(way->point->unitx, way->point->unity, p->lat, p->lon);
1274 poi_edit_dialog(ACTION_ADD_POI, p);
1275 /* XXX: free it ? */
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);
1362 headphone_button_cb(gpointer data)
1365 switch (hb_action) {
1368 /* XXX: Add code to add generic POI */
1369 hildon_banner_show_information(_window, NULL, _("POI Added"));
1374 path_insert_mark_text(_track, g_strdup("Mark"));
1375 hildon_banner_show_information(_window, NULL, _("Mark added"));