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)
45 menu_cb_route_open(GtkAction * action)
52 menu_cb_route_distnext(GtkAction * action)
54 route_show_distance_to_next();
59 menu_cb_route_distlast(GtkAction * action)
61 route_show_distance_to_last();
66 menu_cb_route_reset(GtkAction * action)
68 route_find_nearest_point();
70 MACRO_QUEUE_DRAW_AREA();
75 menu_cb_route_clear(GtkAction * action)
82 menu_cb_track_open(GtkAction * action)
89 menu_cb_track_save(GtkAction * action)
96 menu_cb_track_insert_break(GtkAction * action)
103 menu_cb_track_insert_mark(GtkAction * action)
110 menu_cb_track_distlast(GtkAction * action)
112 track_show_distance_from_last();
117 menu_cb_track_distfirst(GtkAction * action)
119 track_show_distance_from_first();
124 menu_cb_route_save(GtkAction * action)
131 menu_cb_track_clear(GtkAction * action)
138 menu_cb_track_filter(GtkAction * action)
145 menu_cb_show_tracks(GtkAction *action)
147 _show_tracks ^= TRACKS_MASK;
148 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
149 _show_tracks |= TRACKS_MASK;
151 MACRO_QUEUE_DRAW_AREA();
152 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now shown"));
154 _show_tracks &= ~TRACKS_MASK;
156 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now hidden"));
162 menu_cb_show_scale(GtkAction * action)
164 _show_scale = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
165 MACRO_QUEUE_DRAW_AREA();
170 menu_cb_show_routes(GtkAction * action)
172 if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
173 _show_tracks |= ROUTES_MASK;
175 MACRO_QUEUE_DRAW_AREA();
176 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now shown"));
178 _show_tracks &= ~ROUTES_MASK;
180 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now hidden"));
186 menu_cb_show_velvec(GtkAction * action)
188 _show_velvec = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
194 menu_cb_show_poi(GtkAction * action)
196 _show_poi = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
202 menu_cb_gps_show_info(GtkAction * action)
204 _gps_info = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
210 menu_cb_autocenter(GtkAction *action, GtkRadioAction *current)
212 guint new_center_unitx, new_center_unity;
213 gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
217 _center_mode = CENTER_LEAD;
218 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lead"));
221 _center_mode = CENTER_LATLON;
222 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lat/Lon"));
226 _center_mode = -_center_mode;
227 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Off"));
232 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
233 map_center_unit(new_center_unitx, new_center_unity);
238 menu_cb_goto_latlon(GtkAction * action)
246 dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"),
248 GTK_DIALOG_MODAL, GTK_STOCK_OK,
251 GTK_RESPONSE_REJECT, NULL);
253 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0);
255 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Latitude")),0, 1, 0, 1, GTK_FILL, 0, 2, 4);
256 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
258 gtk_table_attach(GTK_TABLE(table), txt_lat = gtk_entry_new(), 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
259 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
261 gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Longitude")), 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
262 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
264 gtk_table_attach(GTK_TABLE(table), txt_lon = gtk_entry_new(), 1, 2, 1, 2, GTK_FILL, 0, 2, 4);
265 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
267 #ifdef WITH_DEVICE_770
268 g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
269 g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
272 /* Initialize with the current center position. */
276 unit2latlon(_center.unitx, _center.unity, lat, lon);
277 snprintf(buffer, sizeof(buffer), "%.06f", lat);
278 gtk_label_set_text(GTK_LABEL(txt_lat), buffer);
279 snprintf(buffer, sizeof(buffer), "%.06f", lon);
280 gtk_label_set_text(GTK_LABEL(txt_lon), buffer);
283 gtk_widget_show_all(dialog);
285 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
291 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
292 lat = strtof(text, &error_check);
293 if (text == error_check || lat < -90.f || lat > 90.f) {
294 popup_error(dialog, _("Invalid Latitude"));
298 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
299 lon = strtof(text, &error_check);
300 if (text == error_check || lon < -180.f || lon > 180.f) {
301 popup_error(dialog, _("Invalid Longitude"));
305 latlon2unit(lat, lon, unitx, unity);
306 if (_center_mode > 0)
307 set_action_activate("autocenter_none", TRUE);
309 map_center_unit(unitx, unity);
312 gtk_widget_destroy(dialog);
317 menu_cb_goto_home(GtkAction *action)
319 if (map_goto_position(&_home)==FALSE) {
320 MACRO_BANNER_SHOW_INFO(_window, _("Home not set."));
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."));
333 MACRO_BANNER_SHOW_INFO(_window, _("At destination"));
339 menu_cb_goto_gps(GtkAction *action)
341 _center_mode = CENTER_LATLON;
342 map_center_unit(_pos.unitx, _pos.unity);
343 map_update_location_from_center();
349 menu_cb_goto_nextway(GtkAction * action)
351 if (_next_way && _next_way->point->unity) {
352 if (_center_mode > 0)
353 set_action_activate("autocenter_none", TRUE);
355 map_center_unit(_next_way->point->unitx, _next_way->point->unity);
357 MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
364 menu_cb_goto_nearpoi(GtkAction * action)
369 if (_center_mode > 0) {
370 /* Auto-Center is enabled - use the GPS position. */
371 unit2latlon(_pos.unitx, _pos.unity, lat, lon);
373 /* Auto-Center is disabled - use the view center. */
374 unit2latlon(_center.unitx, _center.unity, lat, lon);
377 p=poi_find_nearest(lat, lon);
383 latlon2unit(p->lat, p->lon, unitx, unity);
384 banner = g_strdup_printf("%s (%s)", p->label, p->cat_label);
385 g_printf("%s\n", banner);
386 MACRO_BANNER_SHOW_INFO(_window, banner);
390 if (_center_mode > 0)
391 set_action_activate("autocenter_none", TRUE);
393 map_center_unit(unitx, unity);
394 map_update_location_from_center();
396 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
403 menu_cb_maps_repoman(GtkAction * action)
410 menu_cb_maps_select(GtkAction * action, gpointer new_repo)
412 repo_set_curr(new_repo);
418 cb_zoom_auto(GtkAction * action)
420 map_set_autozoom(TRUE);
425 cb_zoom_base(GtkAction * action)
427 map_set_autozoom(FALSE);
433 cb_zoomin(GtkAction * action)
435 map_set_autozoom(FALSE);
441 cb_zoomout(GtkAction * action)
443 map_set_autozoom(FALSE);
449 cb_fullscreen(GtkAction * action)
451 if ((_fullscreen = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
452 gtk_window_fullscreen(GTK_WINDOW(_window));
454 gtk_window_unfullscreen(GTK_WINDOW(_window));
456 gtk_idle_add((GSourceFunc) window_present, NULL);
461 menu_cb_enable_gps(GtkAction * action)
463 if ((_enable_gps = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
465 set_conn_state(RCVR_DOWN);
468 popup_error(_window, _("Cannot enable GPS until a GPS Receiver MAC is set in the Settings dialog box."));
469 set_action_activate("gps_enable", FALSE);
472 if (_conn_state > RCVR_OFF)
473 set_conn_state(RCVR_OFF);
478 set_action_sensitive("gps_details", _enable_gps);
479 set_action_sensitive("goto_gps", _enable_gps);
480 set_action_sensitive("autocenter_latlon", _enable_gps);
481 set_action_sensitive("autocenter_lead", _enable_gps);
490 menu_cb_auto_download(GtkAction * action)
492 if ((_auto_download = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) )) {
493 if (_curr_repo->url == REPOTYPE_NONE)
494 popup_error(_window, _("NOTE: You must set a Map URI in the current repository in order to download maps."));
502 menu_cb_gps_details(GtkAction * action)
509 menu_cb_settings(GtkAction * action)
511 if (settings_dialog()) {
512 /* Settings have changed - reconnect to receiver. */
514 set_conn_state(RCVR_DOWN);
519 MACRO_RECALC_FOCUS_BASE();
520 MACRO_RECALC_FOCUS_SIZE();
526 menu_cb_help(GtkAction * action)
529 ossohelp_show(_osso, HELP_ID_INTRO, 0);
535 menu_cb_about(GtkAction * action)
540 "Cezary Jackiewicz", NULL
543 gtk_show_about_dialog(GTK_WINDOW(_window),
546 "copyright", "Kaj-Michael Lang",
554 window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
556 CustomKey custom_key;
558 switch (event->keyval) {
559 case HILDON_HARDKEY_UP:
560 custom_key = CUSTOM_KEY_UP;
562 case HILDON_HARDKEY_DOWN:
563 custom_key = CUSTOM_KEY_DOWN;
565 case HILDON_HARDKEY_LEFT:
566 custom_key = CUSTOM_KEY_LEFT;
568 case HILDON_HARDKEY_RIGHT:
569 custom_key = CUSTOM_KEY_RIGHT;
571 case HILDON_HARDKEY_SELECT:
572 custom_key = CUSTOM_KEY_SELECT;
574 case HILDON_HARDKEY_INCREASE:
575 custom_key = CUSTOM_KEY_INCREASE;
577 case HILDON_HARDKEY_DECREASE:
578 custom_key = CUSTOM_KEY_DECREASE;
580 case HILDON_HARDKEY_FULLSCREEN:
581 custom_key = CUSTOM_KEY_FULLSCREEN;
583 case HILDON_HARDKEY_ESC:
584 custom_key = CUSTOM_KEY_ESC;
590 switch (_action[custom_key]) {
591 case CUSTOM_ACTION_PAN_NORTH:
592 map_pan(0, -PAN_UNITS);
594 case CUSTOM_ACTION_PAN_WEST:
595 map_pan(-PAN_UNITS, 0);
597 case CUSTOM_ACTION_PAN_SOUTH:
598 map_pan(0, PAN_UNITS);
600 case CUSTOM_ACTION_PAN_EAST:
601 map_pan(PAN_UNITS, 0);
603 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
604 switch (_center_mode) {
606 case CENTER_WAS_LEAD:
607 set_action_activate("autocenter_lead", TRUE);
610 case CENTER_WAS_LATLON:
611 set_action_activate("autocenter_latlon", TRUE);
614 set_action_activate("autocenter_latlon", TRUE);
618 case CUSTOM_ACTION_ZOOM_IN:
619 case CUSTOM_ACTION_ZOOM_OUT:
620 if (!_key_zoom_timeout_sid) {
621 g_printf("Z: %d %d\n", _key_zoom_new, _zoom);
622 _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN
623 ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps);
624 /* Remember, _key_zoom_new is unsigned. */
625 if (_key_zoom_new < MAX_ZOOM) {
627 snprintf(buffer, sizeof(buffer), "%s %d", _("Zoom to Level"), _key_zoom_new);
628 MACRO_BANNER_SHOW_INFO(_window, buffer);
629 _key_zoom_timeout_sid = g_timeout_add(400, map_key_zoom_timeout, NULL);
633 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
634 set_action_activate("view_fullscreen", !_fullscreen);
636 case CUSTOM_ACTION_TOGGLE_TRACKS:
637 switch (_show_tracks) {
639 /* Nothing shown, nothing saved; just set both. */
640 _show_tracks = TRACKS_MASK | ROUTES_MASK;
642 case TRACKS_MASK << 16:
643 case ROUTES_MASK << 16:
644 case (ROUTES_MASK | TRACKS_MASK) << 16:
645 /* Something was saved and nothing changed since.
647 _show_tracks = _show_tracks >> 16;
650 /* There is no history, or they changed something
651 * since the last historical change. Save and
653 _show_tracks = _show_tracks << 16;
655 set_action_activate("view_route", _show_tracks & ROUTES_MASK);
656 set_action_activate("view_track", _show_tracks & TRACKS_MASK);
658 case CUSTOM_ACTION_TOGGLE_SCALE:
659 set_action_activate("view_scale", _show_scale);
661 case CUSTOM_ACTION_TOGGLE_POI:
662 set_action_activate("view_poi", _show_poi);
664 case CUSTOM_ACTION_CHANGE_REPO: {
665 GList *curr = g_list_find(_repo_list, _curr_repo);
669 /* Loop until we reach a next-able repo, or until we get
670 * back to the current repo. */
671 while ((curr = (curr->next ? curr->next : _repo_list)) && !((RepoData *) curr->data)->nextable && curr->data != _curr_repo) {
674 if (curr->data != _curr_repo) {
675 repo_set_curr(curr->data);
676 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_curr_repo->menu_item), TRUE);
678 popup_error(_window, _("There are no other next-able repositories."));
683 case CUSTOM_ACTION_ROUTE_DISTNEXT:
684 route_show_distance_to_next();
686 case CUSTOM_ACTION_ROUTE_DISTLAST:
687 route_show_distance_to_last();
689 case CUSTOM_ACTION_TRACK_BREAK:
690 track_insert_break();
692 case CUSTOM_ACTION_TRACK_DISTLAST:
693 track_show_distance_from_last();
695 case CUSTOM_ACTION_TRACK_DISTFIRST:
696 track_show_distance_from_first();
698 case CUSTOM_ACTION_TOGGLE_GPS:
699 set_action_activate("gps_enable", !_enable_gps);
701 case CUSTOM_ACTION_TOGGLE_GPSINFO:
702 set_action_activate("gps_info", !_gps_info);
704 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
705 _speed_limit_on ^= 1;
714 window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
716 switch (event->keyval) {
717 case HILDON_HARDKEY_INCREASE:
718 case HILDON_HARDKEY_DECREASE:
719 if (_key_zoom_timeout_sid) {
720 g_source_remove(_key_zoom_timeout_sid);
721 _key_zoom_timeout_sid = 0;
722 map_set_zoom(_key_zoom_new);
732 cmenu_show_latlon(guint unitx, guint unity)
735 gchar buffer[80], tmp1[16], tmp2[16];
737 unit2latlon(unitx, unity, lat, lon);
738 lat_format(lat, tmp1);
739 lon_format(lon, tmp2);
741 snprintf(buffer, sizeof(buffer),
743 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
745 MACRO_BANNER_SHOW_INFO(_window, buffer);
749 cmenu_clip_latlon(guint unitx, guint unity)
754 unit2latlon(unitx, unity, lat, lon);
755 snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
757 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buffer, -1);
761 cmenu_route_to(guint unitx, guint unity)
768 unit2latlon(unitx, unity, lat, lon);
770 g_ascii_formatd(strlat, 32, "%.06f", lat);
771 g_ascii_formatd(strlon, 32, "%.06f", lon);
772 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
774 route_download(buffer);
778 cmenu_distance_to(guint unitx, guint unity)
783 unit2latlon(unitx, unity, lat, lon);
785 snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"),
786 calculate_distance(_gps.lat, _gps.lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
787 MACRO_BANNER_SHOW_INFO(_window, buffer);
791 cmenu_add_route(guint unitx, guint unity)
793 MACRO_PATH_INCREMENT_TAIL(_route);
794 _route.tail->unitx = x2unit(_cmenu_position_x);
795 _route.tail->unity = y2unit(_cmenu_position_y);
796 route_find_nearest_point();
800 void cmenu_route_add_way(guint unitx, guint unity)
803 gchar tmp1[16], tmp2[16], *p_latlon;
807 GtkWidget *txt_scroll;
810 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
812 GTK_DIALOG_MODAL, GTK_STOCK_OK,
815 GTK_RESPONSE_REJECT, NULL);
817 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
818 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
820 gtk_table_attach(GTK_TABLE(table),
821 label = gtk_label_new(_("Lat, Lon")),
822 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
823 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
825 unit2latlon(unitx, unity, lat, lon);
826 lat_format(lat, tmp1);
827 lon_format(lon, tmp2);
828 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
829 gtk_table_attach(GTK_TABLE(table),
830 label = gtk_label_new(p_latlon),
831 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
832 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
835 gtk_table_attach(GTK_TABLE(table),
836 label = gtk_label_new(_("Description")),
837 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
838 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
840 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
841 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
843 gtk_table_attach(GTK_TABLE(table),
845 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
847 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
848 GTK_POLICY_AUTOMATIC,
849 GTK_POLICY_AUTOMATIC);
851 txt_desc = gtk_text_view_new();
852 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
854 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
855 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
857 gtk_widget_show_all(dialog);
859 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
861 GtkTextIter ti1, ti2;
864 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
865 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
866 gtk_text_buffer_get_end_iter(tbuf, &ti2);
867 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
870 /* There's a description. Add a waypoint. */
871 MACRO_PATH_INCREMENT_TAIL(_route);
872 _route.tail->unitx = unitx;
873 _route.tail->unity = unity;
874 _route.tail->time = 0;
875 _route.tail->altitude = NAN;
877 MACRO_PATH_INCREMENT_WTAIL(_route);
878 _route.wtail->point = _route.tail;
880 = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
886 confirm = hildon_note_new_confirmation(GTK_WINDOW(dialog),
887 _("Creating a \"waypoint\" with no description actually "
888 "adds a break point. Is that what you want?"));
890 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
891 /* There's no description. Add a break by adding a (0, 0)
892 * point (if necessary), and then the ordinary route point. */
893 if (_route.tail->unity) {
894 MACRO_PATH_INCREMENT_TAIL(_route);
895 *_route.tail = _point_null;
898 MACRO_PATH_INCREMENT_TAIL(_route);
899 _route.tail->unitx = unitx;
900 _route.tail->unity = unity;
901 _route.tail->time = 0;
902 _route.tail->altitude = NAN;
904 gtk_widget_destroy(confirm);
906 gtk_widget_destroy(confirm);
911 route_find_nearest_point();
913 MACRO_QUEUE_DRAW_AREA();
916 gtk_widget_destroy(dialog);
920 cmenu_cb_loc_show_latlon(GtkAction * action)
922 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
927 cmenu_cb_loc_clip_latlon(GtkAction * action)
929 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
934 cmenu_cb_loc_route_to(GtkAction * action)
936 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
941 cmenu_cb_loc_distance_to(GtkAction * action)
943 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
948 cmenu_cb_loc_add_route(GtkAction * action)
950 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
955 cmenu_cb_loc_add_way(GtkAction * action)
957 cmenu_route_add_way(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
962 cmenu_cb_loc_add_poi(GtkAction * action)
964 poi_dialog(ACTION_ADD_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
969 cb_add_poi(GtkAction *action)
972 const gchar *name = gtk_action_get_name(action);
974 if (_center_mode > 0) {
975 latlon2unit(_gps.lat, _gps.lon, unitx, unity);
981 if (strcmp(name, "poi_add")==0)
982 poi_dialog(ACTION_ADD_POI, unitx, unity);
983 else if (strcmp(name, "poi_quick_add")==0)
984 poi_quick_dialog(unitx, unity);
986 g_assert_not_reached();
992 cmenu_cb_loc_set_home(GtkAction * action)
996 unitx = x2unit(_cmenu_position_x);
997 unity = y2unit(_cmenu_position_y);
998 unit2latlon(unitx, unity, _home.lat, _home.lon);
1007 cmenu_cb_loc_set_destination(GtkAction *action)
1011 unitx = x2unit(_cmenu_position_x);
1012 unity = y2unit(_cmenu_position_y);
1013 unit2latlon(unitx, unity, _dest.lat, _dest.lon);
1015 map_update_location_from_center();
1020 cmenu_cb_loc_set_gps(GtkAction * action)
1022 _pos.unitx = x2unit(_cmenu_position_x);
1023 _pos.unity = y2unit(_cmenu_position_y);
1024 unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
1026 /* Move mark to new location. */
1028 track_add(time(NULL), FALSE);
1034 cmenu_cb_way_show_latlon(GtkAction * action)
1038 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1039 cmenu_show_latlon(way->point->unitx, way->point->unity);
1045 cmenu_cb_way_show_desc(GtkAction * action)
1049 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1050 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1057 cmenu_cb_way_clip_latlon(GtkAction * action)
1061 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1062 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1067 cmenu_cb_way_clip_desc(GtkAction * action)
1071 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1072 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), way->desc, -1);
1078 cmenu_cb_way_route_to(GtkAction * action)
1082 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1083 cmenu_route_to(way->point->unitx, way->point->unity);
1089 cmenu_cb_way_distance_to(GtkAction * action)
1093 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1094 route_show_distance_to(way->point);
1100 cmenu_cb_way_delete(GtkAction * action)
1104 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
1105 gchar buffer[BUFFER_SIZE];
1108 snprintf(buffer, sizeof(buffer), "%s:\n%s\n",
1109 _("Confirm delete of waypoint"), way->desc);
1110 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
1112 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1113 Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
1116 /* Delete surrounding route data, too. */
1117 if (way == _route.whead)
1118 pdel_min = _route.head;
1120 pdel_min = way[-1].point;
1122 if (way == _route.wtail)
1123 pdel_max = _route.tail;
1125 pdel_max = way[1].point;
1127 /* Find largest continuous segment around the waypoint, EXCLUDING
1128 * pdel_min and pdel_max. */
1129 for (pdel_start = way->point - 1; pdel_start->unity
1130 && pdel_start > pdel_min; pdel_start--) {
1132 for (pdel_end = way->point + 1; pdel_end->unity
1133 && pdel_end < pdel_max; pdel_end++) {
1136 /* If pdel_end is set to _route.tail, and if _route.tail is a
1137 * non-zero point, then delete _route.tail. */
1138 if (pdel_end == _route.tail && pdel_end->unity)
1139 pdel_end++; /* delete _route.tail too */
1140 /* else, if *both* endpoints are zero points, delete one. */
1141 else if (!pdel_start->unity && !pdel_end->unity)
1144 /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
1145 num_del = pdel_end - pdel_start - 1;
1147 memmove(pdel_start + 1, pdel_end,(_route.tail - pdel_end + 1) * sizeof(Point));
1148 _route.tail -= num_del;
1150 /* Remove waypoint and move/adjust subsequent waypoints. */
1152 while (way++ != _route.wtail) {
1154 way[-1].point -= num_del;
1158 route_find_nearest_point();
1161 gtk_widget_destroy(confirm);
1168 menu_cb_category(GtkAction * action)
1170 if (category_list())
1177 cmenu_cb_way_add_poi(GtkAction * action)
1181 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1182 poi_dialog(ACTION_ADD_POI, way->point->unitx, way->point->unity);
1188 cmenu_cb_poi_route_to(GtkAction * action)
1192 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1194 latlon2unit(poi.lat, poi.lon, unitx, unity);
1195 cmenu_route_to(unitx, unity);
1202 cmenu_cb_poi_distance_to(GtkAction * action)
1206 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1208 latlon2unit(poi.lat, poi.lon, unitx, unity);
1209 cmenu_distance_to(unitx, unity);
1216 cmenu_cb_poi_add_route(GtkAction * action)
1220 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1222 latlon2unit(poi.lat, poi.lon, unitx, unity);
1223 cmenu_add_route(unitx, unity);
1230 cmenu_cb_poi_add_way(GtkAction * action)
1234 if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1236 latlon2unit(poi.lat, poi.lon, unitx, unity);
1237 cmenu_route_add_way(unitx, unity);
1244 cmenu_cb_poi_edit_poi(GtkAction * action)
1246 poi_dialog(ACTION_EDIT_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));