13 #include <glib/gstdio.h>
19 #include "hildon-mapper.h"
29 #include "mapper-types.h"
31 #include "ui-common.h"
35 #include "gps-panels.h"
38 menu_cb_route_download(GtkAction * action)
43 store=route_generate_store();
45 gtk_tree_view_set_model(route_tree_view, store);
46 g_object_unref(G_OBJECT(store));
52 menu_cb_route_open(GtkAction * action)
57 store=route_generate_store();
59 gtk_tree_view_set_model(route_tree_view, store);
60 g_object_unref(G_OBJECT(store));
66 menu_cb_route_distnext(GtkAction * action)
68 route_show_distance_to_next();
73 menu_cb_route_distlast(GtkAction * action)
75 route_show_distance_to_last();
80 menu_cb_route_reset(GtkAction * action)
82 route_find_nearest_point();
84 MACRO_QUEUE_DRAW_AREA();
89 menu_cb_route_clear(GtkAction * action)
92 gtk_tree_view_set_model(route_tree_view, NULL);
97 menu_cb_track_open(GtkAction * action)
104 menu_cb_track_save(GtkAction * action)
111 menu_cb_track_insert_break(GtkAction * action)
113 track_insert_break();
118 menu_cb_track_insert_mark(GtkAction * action)
125 menu_cb_track_distlast(GtkAction * action)
127 track_show_distance_from_last();
132 menu_cb_track_distfirst(GtkAction * action)
134 track_show_distance_from_first();
139 menu_cb_route_save(GtkAction * action)
146 menu_cb_track_clear(GtkAction * action)
153 menu_cb_track_filter(GtkAction * action)
160 menu_cb_show_tracks(GtkAction *action)
162 _show_tracks ^= TRACKS_MASK;
163 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
164 _show_tracks |= TRACKS_MASK;
166 MACRO_QUEUE_DRAW_AREA();
167 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now shown"));
169 _show_tracks &= ~TRACKS_MASK;
171 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now hidden"));
177 menu_cb_show_scale(GtkAction * action)
179 _show_scale = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
180 MACRO_QUEUE_DRAW_AREA();
185 menu_cb_show_routes(GtkAction * action)
187 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
188 _show_tracks |= ROUTES_MASK;
190 MACRO_QUEUE_DRAW_AREA();
191 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now shown"));
193 _show_tracks &= ~ROUTES_MASK;
195 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now hidden"));
201 menu_cb_show_velvec(GtkAction * action)
203 _show_velvec = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
209 menu_cb_show_poi(GtkAction * action)
211 _show_poi = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
217 menu_cb_gps_show_info(GtkAction * action)
219 _gps_info = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
225 menu_cb_autocenter(GtkAction *action, GtkRadioAction *current)
227 guint new_center_unitx, new_center_unity;
228 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
232 _center_mode = CENTER_LEAD;
233 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lead"));
236 _center_mode = CENTER_LATLON;
237 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lat/Lon"));
241 _center_mode = -_center_mode;
242 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Off"));
247 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
248 map_center_unit(new_center_unitx, new_center_unity);
253 menu_cb_goto_latlon(GtkAction * action)
261 dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"),
263 GTK_DIALOG_MODAL, GTK_STOCK_OK,
266 GTK_RESPONSE_REJECT, NULL);
268 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0);
270 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Latitude")),0, 1, 0, 1, GTK_FILL, 0, 2, 4);
271 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
273 gtk_table_attach(GTK_TABLE(table), txt_lat = gtk_entry_new(), 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
274 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
276 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Longitude")), 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
277 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
279 gtk_table_attach(GTK_TABLE(table), txt_lon = gtk_entry_new(), 1, 2, 1, 2, GTK_FILL, 0, 2, 4);
280 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
282 #if defined (WITH_DEVICE_770) && !defined(WITH_HILDON_NEW)
283 g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
284 g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
287 /* Initialize with the current center position. */
291 unit2latlon(_center.unitx, _center.unity, lat, lon);
292 snprintf(buffer, sizeof(buffer), "%.06f", lat);
293 gtk_label_set_text(GTK_LABEL(txt_lat), buffer);
294 snprintf(buffer, sizeof(buffer), "%.06f", lon);
295 gtk_label_set_text(GTK_LABEL(txt_lon), buffer);
298 gtk_widget_show_all(dialog);
300 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
306 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
307 lat = strtof(text, &error_check);
308 if (text == error_check || lat < -90.f || lat > 90.f) {
309 popup_error(dialog, _("Invalid Latitude"));
313 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
314 lon = strtof(text, &error_check);
315 if (text == error_check || lon < -180.f || lon > 180.f) {
316 popup_error(dialog, _("Invalid Longitude"));
320 latlon2unit(lat, lon, unitx, unity);
321 if (_center_mode > 0)
322 set_action_activate("autocenter_none", TRUE);
324 map_center_unit(unitx, unity);
327 gtk_widget_destroy(dialog);
332 menu_cb_goto_home(GtkAction *action)
334 if (map_goto_position(&_home)==FALSE) {
335 MACRO_BANNER_SHOW_INFO(_window, _("Home not set."));
337 MACRO_BANNER_SHOW_INFO(_window, _("At home location"));
343 menu_cb_goto_destination(GtkAction *action)
345 if (map_goto_position(&_dest)==FALSE) {
346 MACRO_BANNER_SHOW_INFO(_window, _("Destination not set."));
348 MACRO_BANNER_SHOW_INFO(_window, _("At destination"));
354 menu_cb_goto_gps(GtkAction *action)
356 _center_mode = CENTER_LATLON;
357 map_center_unit(_pos.unitx, _pos.unity);
358 map_update_location_from_center();
364 menu_cb_goto_nextway(GtkAction * action)
366 if (_next_way && _next_way->point->unity) {
367 if (_center_mode > 0)
368 set_action_activate("autocenter_none", TRUE);
370 map_center_unit(_next_way->point->unitx, _next_way->point->unity);
372 MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
379 menu_cb_goto_nearpoi(GtkAction * action)
384 if (_center_mode > 0) {
385 /* Auto-Center is enabled - use the GPS position. */
386 unit2latlon(_pos.unitx, _pos.unity, lat, lon);
388 /* Auto-Center is disabled - use the view center. */
389 unit2latlon(_center.unitx, _center.unity, lat, lon);
392 p=poi_find_nearest(lat, lon);
398 latlon2unit(p->lat, p->lon, unitx, unity);
399 banner = g_strdup_printf("%s (%s)", p->label, p->cat_label);
400 g_printf("%s\n", banner);
401 MACRO_BANNER_SHOW_INFO(_window, banner);
405 if (_center_mode > 0)
406 set_action_activate("autocenter_none", TRUE);
408 map_center_unit(unitx, unity);
409 map_update_location_from_center();
411 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
418 menu_cb_maps_repoman(GtkAction * action)
425 menu_cb_maps_select(GtkAction * action, gpointer new_repo)
427 repo_set_curr(new_repo);
433 cb_zoom_auto(GtkAction * action)
435 map_set_autozoom(TRUE);
440 cb_zoom_base(GtkAction * action)
442 map_set_autozoom(FALSE);
448 cb_zoomin(GtkAction * action)
450 map_set_autozoom(FALSE);
456 cb_zoomout(GtkAction * action)
458 map_set_autozoom(FALSE);
464 cb_fullscreen(GtkAction * action)
466 if ((_fullscreen = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
467 gtk_window_fullscreen(GTK_WINDOW(_window));
469 gtk_window_unfullscreen(GTK_WINDOW(_window));
471 gtk_idle_add((GSourceFunc) window_present, NULL);
476 menu_cb_enable_gps(GtkAction * action)
478 if ((_enable_gps = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
480 set_conn_state(RCVR_DOWN);
483 popup_error(_window, _("Cannot enable GPS until a GPS Receiver MAC is set in the Settings dialog box."));
484 set_action_activate("gps_enable", FALSE);
487 if (_conn_state > RCVR_OFF)
488 set_conn_state(RCVR_OFF);
493 set_action_sensitive("gps_details", _enable_gps);
494 set_action_sensitive("goto_gps", _enable_gps);
495 set_action_sensitive("autocenter_latlon", _enable_gps);
496 set_action_sensitive("autocenter_lead", _enable_gps);
505 menu_cb_auto_download(GtkAction * action)
507 if ((_auto_download = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) )) {
508 if (_curr_repo->url == REPOTYPE_NONE)
509 popup_error(_window, _("NOTE: You must set a Map URI in the current repository in order to download maps."));
517 menu_cb_gps_details(GtkAction * action)
524 menu_cb_settings(GtkAction * action)
526 if (settings_dialog()) {
527 /* Settings have changed - reconnect to receiver. */
529 set_conn_state(RCVR_DOWN);
534 MACRO_RECALC_FOCUS_BASE();
535 MACRO_RECALC_FOCUS_SIZE();
541 menu_cb_help(GtkAction * action)
543 #ifdef WITH_OSSO_HELP
544 ossohelp_show(_osso, HELP_ID_INTRO, 0);
546 #ifdef WITH_HILDON_HELP
547 hildon_help_show(_osso, HELP_ID_INTRO, 0);
553 menu_cb_about(GtkAction * action)
558 "Cezary Jackiewicz", NULL
561 gtk_show_about_dialog(GTK_WINDOW(_window),
564 "copyright", "Kaj-Michael Lang",
572 window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
574 CustomKey custom_key;
576 switch (event->keyval) {
577 case HILDON_HARDKEY_UP:
578 custom_key = CUSTOM_KEY_UP;
580 case HILDON_HARDKEY_DOWN:
581 custom_key = CUSTOM_KEY_DOWN;
583 case HILDON_HARDKEY_LEFT:
584 custom_key = CUSTOM_KEY_LEFT;
586 case HILDON_HARDKEY_RIGHT:
587 custom_key = CUSTOM_KEY_RIGHT;
589 case HILDON_HARDKEY_SELECT:
590 custom_key = CUSTOM_KEY_SELECT;
592 case HILDON_HARDKEY_INCREASE:
593 custom_key = CUSTOM_KEY_INCREASE;
595 case HILDON_HARDKEY_DECREASE:
596 custom_key = CUSTOM_KEY_DECREASE;
598 case HILDON_HARDKEY_FULLSCREEN:
599 custom_key = CUSTOM_KEY_FULLSCREEN;
601 case HILDON_HARDKEY_ESC:
602 custom_key = CUSTOM_KEY_ESC;
608 switch (_action[custom_key]) {
609 case CUSTOM_ACTION_PAN_NORTH:
610 map_pan(0, -PAN_UNITS);
612 case CUSTOM_ACTION_PAN_WEST:
613 map_pan(-PAN_UNITS, 0);
615 case CUSTOM_ACTION_PAN_SOUTH:
616 map_pan(0, PAN_UNITS);
618 case CUSTOM_ACTION_PAN_EAST:
619 map_pan(PAN_UNITS, 0);
621 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
622 switch (_center_mode) {
624 case CENTER_WAS_LEAD:
625 set_action_activate("autocenter_lead", TRUE);
628 case CENTER_WAS_LATLON:
629 set_action_activate("autocenter_latlon", TRUE);
632 set_action_activate("autocenter_latlon", TRUE);
636 case CUSTOM_ACTION_ZOOM_IN:
637 case CUSTOM_ACTION_ZOOM_OUT:
638 if (!_key_zoom_timeout_sid) {
639 g_printf("Z: %d %d\n", _key_zoom_new, _zoom);
640 _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN
641 ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps);
642 /* Remember, _key_zoom_new is unsigned. */
643 if (_key_zoom_new < MAX_ZOOM) {
645 snprintf(buffer, sizeof(buffer), "%s %d", _("Zoom to Level"), _key_zoom_new);
646 MACRO_BANNER_SHOW_INFO(_window, buffer);
647 _key_zoom_timeout_sid = g_timeout_add(400, map_key_zoom_timeout, NULL);
651 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
652 set_action_activate("view_fullscreen", !_fullscreen);
654 case CUSTOM_ACTION_TOGGLE_TRACKS:
655 switch (_show_tracks) {
657 /* Nothing shown, nothing saved; just set both. */
658 _show_tracks = TRACKS_MASK | ROUTES_MASK;
660 case TRACKS_MASK << 16:
661 case ROUTES_MASK << 16:
662 case (ROUTES_MASK | TRACKS_MASK) << 16:
663 /* Something was saved and nothing changed since.
665 _show_tracks = _show_tracks >> 16;
668 /* There is no history, or they changed something
669 * since the last historical change. Save and
671 _show_tracks = _show_tracks << 16;
673 set_action_activate("view_route", _show_tracks & ROUTES_MASK);
674 set_action_activate("view_track", _show_tracks & TRACKS_MASK);
676 case CUSTOM_ACTION_TOGGLE_SCALE:
677 set_action_activate("view_scale", _show_scale);
679 case CUSTOM_ACTION_TOGGLE_POI:
680 set_action_activate("view_poi", _show_poi);
682 case CUSTOM_ACTION_CHANGE_REPO: {
683 GList *curr = g_list_find(_repo_list, _curr_repo);
687 /* Loop until we reach a next-able repo, or until we get
688 * back to the current repo. */
689 while ((curr = (curr->next ? curr->next : _repo_list)) && !((RepoData *) curr->data)->nextable && curr->data != _curr_repo) {
692 if (curr->data != _curr_repo) {
693 repo_set_curr(curr->data);
694 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_curr_repo->menu_item), TRUE);
696 popup_error(_window, _("There are no other next-able repositories."));
701 case CUSTOM_ACTION_ROUTE_DISTNEXT:
702 route_show_distance_to_next();
704 case CUSTOM_ACTION_ROUTE_DISTLAST:
705 route_show_distance_to_last();
707 case CUSTOM_ACTION_TRACK_BREAK:
708 track_insert_break();
710 case CUSTOM_ACTION_TRACK_DISTLAST:
711 track_show_distance_from_last();
713 case CUSTOM_ACTION_TRACK_DISTFIRST:
714 track_show_distance_from_first();
716 case CUSTOM_ACTION_TOGGLE_GPS:
717 set_action_activate("gps_enable", !_enable_gps);
719 case CUSTOM_ACTION_TOGGLE_GPSINFO:
720 set_action_activate("gps_info", !_gps_info);
722 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
723 _speed_limit_on ^= 1;
732 window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
734 switch (event->keyval) {
735 case HILDON_HARDKEY_INCREASE:
736 case HILDON_HARDKEY_DECREASE:
737 if (_key_zoom_timeout_sid) {
738 g_source_remove(_key_zoom_timeout_sid);
739 _key_zoom_timeout_sid = 0;
740 map_set_zoom(_key_zoom_new);
750 cmenu_show_latlon(guint unitx, guint unity)
753 gchar buffer[80], tmp1[16], tmp2[16];
755 unit2latlon(unitx, unity, lat, lon);
756 lat_format(lat, tmp1);
757 lon_format(lon, tmp2);
759 snprintf(buffer, sizeof(buffer),
761 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
763 MACRO_BANNER_SHOW_INFO(_window, buffer);
767 cmenu_clip_latlon(guint unitx, guint unity)
772 unit2latlon(unitx, unity, lat, lon);
773 snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
775 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buffer, -1);
779 cmenu_route_to(guint unitx, guint unity)
786 unit2latlon(unitx, unity, lat, lon);
788 g_ascii_formatd(strlat, 32, "%.06f", lat);
789 g_ascii_formatd(strlon, 32, "%.06f", lon);
790 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
792 route_download(buffer);
796 cmenu_distance_to(guint unitx, guint unity)
801 unit2latlon(unitx, unity, lat, lon);
803 snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"),
804 calculate_distance(_gps.lat, _gps.lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
805 MACRO_BANNER_SHOW_INFO(_window, buffer);
809 cmenu_add_route(guint unitx, guint unity)
811 MACRO_PATH_INCREMENT_TAIL(_route);
812 _route.tail->unitx = x2unit(_cmenu_position_x);
813 _route.tail->unity = y2unit(_cmenu_position_y);
814 route_find_nearest_point();
818 void cmenu_route_add_way(guint unitx, guint unity)
821 gchar tmp1[16], tmp2[16], *p_latlon;
825 GtkWidget *txt_scroll;
828 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
830 GTK_DIALOG_MODAL, GTK_STOCK_OK,
833 GTK_RESPONSE_REJECT, NULL);
835 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
836 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
838 gtk_table_attach(GTK_TABLE(table),
839 label = gtk_label_new(_("Lat, Lon")),
840 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
841 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
843 unit2latlon(unitx, unity, lat, lon);
844 lat_format(lat, tmp1);
845 lon_format(lon, tmp2);
846 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
847 gtk_table_attach(GTK_TABLE(table),
848 label = gtk_label_new(p_latlon),
849 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
850 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
853 gtk_table_attach(GTK_TABLE(table),
854 label = gtk_label_new(_("Description")),
855 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
856 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
858 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
859 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
861 gtk_table_attach(GTK_TABLE(table),
863 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
865 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
866 GTK_POLICY_AUTOMATIC,
867 GTK_POLICY_AUTOMATIC);
869 txt_desc = gtk_text_view_new();
870 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
872 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
873 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
875 gtk_widget_show_all(dialog);
877 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
879 GtkTextIter ti1, ti2;
882 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
883 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
884 gtk_text_buffer_get_end_iter(tbuf, &ti2);
885 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
888 /* There's a description. Add a waypoint. */
889 MACRO_PATH_INCREMENT_TAIL(_route);
890 _route.tail->unitx = unitx;
891 _route.tail->unity = unity;
892 _route.tail->time = 0;
893 _route.tail->altitude = NAN;
895 MACRO_PATH_INCREMENT_WTAIL(_route);
896 _route.wtail->point = _route.tail;
898 = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
904 confirm = hildon_note_new_confirmation(GTK_WINDOW(dialog),
905 _("Creating a \"waypoint\" with no description actually "
906 "adds a break point. Is that what you want?"));
908 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
909 /* There's no description. Add a break by adding a (0, 0)
910 * point (if necessary), and then the ordinary route point. */
911 if (_route.tail->unity) {
912 MACRO_PATH_INCREMENT_TAIL(_route);
913 *_route.tail = _point_null;
916 MACRO_PATH_INCREMENT_TAIL(_route);
917 _route.tail->unitx = unitx;
918 _route.tail->unity = unity;
919 _route.tail->time = 0;
920 _route.tail->altitude = NAN;
922 gtk_widget_destroy(confirm);
924 gtk_widget_destroy(confirm);
929 route_find_nearest_point();
931 MACRO_QUEUE_DRAW_AREA();
934 gtk_widget_destroy(dialog);
938 cmenu_cb_loc_show_latlon(GtkAction * action)
940 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
945 cmenu_cb_loc_clip_latlon(GtkAction * action)
947 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
952 cmenu_cb_loc_route_to(GtkAction * action)
954 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
959 cmenu_cb_loc_distance_to(GtkAction * action)
961 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
966 cmenu_cb_loc_add_route(GtkAction * action)
968 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
973 cmenu_cb_loc_add_way(GtkAction * action)
975 cmenu_route_add_way(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
980 cmenu_cb_loc_add_poi(GtkAction * action)
982 poi_dialog(ACTION_ADD_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
987 cb_poi_search(GtkAction *action)
991 poi_search_dialog(NULL, &poi);
996 cb_poi_add(GtkAction *action)
999 const gchar *name = gtk_action_get_name(action);
1001 if (_center_mode > 0) {
1002 latlon2unit(_gps.lat, _gps.lon, unitx, unity);
1004 unitx=_center.unitx;
1005 unity=_center.unity;
1008 if (strcmp(name, "poi_add")==0)
1009 poi_dialog(ACTION_ADD_POI, unitx, unity);
1010 else if (strcmp(name, "poi_quick_add")==0)
1011 poi_quick_dialog(unitx, unity);
1013 g_assert_not_reached();
1019 cmenu_cb_loc_set_home(GtkAction * action)
1023 unitx = x2unit(_cmenu_position_x);
1024 unity = y2unit(_cmenu_position_y);
1025 unit2latlon(unitx, unity, _home.lat, _home.lon);
1034 cmenu_cb_loc_set_destination(GtkAction *action)
1038 unitx = x2unit(_cmenu_position_x);
1039 unity = y2unit(_cmenu_position_y);
1040 unit2latlon(unitx, unity, _dest.lat, _dest.lon);
1042 map_update_location_from_center();
1047 cmenu_cb_loc_set_gps(GtkAction * action)
1049 _pos.unitx = x2unit(_cmenu_position_x);
1050 _pos.unity = y2unit(_cmenu_position_y);
1051 unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
1053 /* Move mark to new location. */
1055 track_add(time(NULL), FALSE);
1061 cmenu_cb_way_show_latlon(GtkAction * action)
1065 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1066 cmenu_show_latlon(way->point->unitx, way->point->unity);
1072 cmenu_cb_way_show_desc(GtkAction * action)
1076 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1077 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1084 cmenu_cb_way_clip_latlon(GtkAction * action)
1088 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1089 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1094 cmenu_cb_way_clip_desc(GtkAction * action)
1098 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1099 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), way->desc, -1);
1105 cmenu_cb_way_route_to(GtkAction * action)
1109 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1110 cmenu_route_to(way->point->unitx, way->point->unity);
1116 cmenu_cb_way_distance_to(GtkAction * action)
1120 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1121 route_show_distance_to(way->point);
1127 cmenu_cb_way_delete(GtkAction * action)
1131 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1132 gchar buffer[BUFFER_SIZE];
1135 snprintf(buffer, sizeof(buffer), "%s:\n%s\n",
1136 _("Confirm delete of waypoint"), way->desc);
1137 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
1139 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1140 Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
1143 /* Delete surrounding route data, too. */
1144 if (way == _route.whead)
1145 pdel_min = _route.head;
1147 pdel_min = way[-1].point;
1149 if (way == _route.wtail)
1150 pdel_max = _route.tail;
1152 pdel_max = way[1].point;
1154 /* Find largest continuous segment around the waypoint, EXCLUDING
1155 * pdel_min and pdel_max. */
1156 for (pdel_start = way->point - 1; pdel_start->unity
1157 && pdel_start > pdel_min; pdel_start--) {
1159 for (pdel_end = way->point + 1; pdel_end->unity
1160 && pdel_end < pdel_max; pdel_end++) {
1163 /* If pdel_end is set to _route.tail, and if _route.tail is a
1164 * non-zero point, then delete _route.tail. */
1165 if (pdel_end == _route.tail && pdel_end->unity)
1166 pdel_end++; /* delete _route.tail too */
1167 /* else, if *both* endpoints are zero points, delete one. */
1168 else if (!pdel_start->unity && !pdel_end->unity)
1171 /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
1172 num_del = pdel_end - pdel_start - 1;
1174 memmove(pdel_start + 1, pdel_end,(_route.tail - pdel_end + 1) * sizeof(Point));
1175 _route.tail -= num_del;
1177 /* Remove waypoint and move/adjust subsequent waypoints. */
1179 while (way++ != _route.wtail) {
1181 way[-1].point -= num_del;
1185 route_find_nearest_point();
1188 gtk_widget_destroy(confirm);
1195 menu_cb_category(GtkAction * action)
1197 if (poi_category_list())
1204 cmenu_cb_way_add_poi(GtkAction * action)
1208 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1209 poi_dialog(ACTION_ADD_POI, way->point->unitx, way->point->unity);
1215 cmenu_cb_poi_route_to(GtkAction * action)
1219 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1221 latlon2unit(poi.lat, poi.lon, unitx, unity);
1222 cmenu_route_to(unitx, unity);
1229 cmenu_cb_poi_distance_to(GtkAction * action)
1233 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1235 latlon2unit(poi.lat, poi.lon, unitx, unity);
1236 cmenu_distance_to(unitx, unity);
1243 cmenu_cb_poi_add_route(GtkAction * action)
1247 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1249 latlon2unit(poi.lat, poi.lon, unitx, unity);
1250 cmenu_add_route(unitx, unity);
1257 cmenu_cb_poi_add_way(GtkAction * action)
1261 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1263 latlon2unit(poi.lat, poi.lon, unitx, unity);
1264 cmenu_route_add_way(unitx, unity);
1271 cmenu_cb_poi_edit_poi(GtkAction * action)
1273 poi_dialog(ACTION_EDIT_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));