14 #include <glib/gstdio.h>
17 #include <gconf/gconf-client.h>
21 #include "hildon-mapper.h"
29 #include "mapper-types.h"
31 #include "ui-common.h"
36 gboolean map_cb_configure(GtkWidget * widget, GdkEventConfigure * event)
38 printf("%s(%d, %d)\n", __PRETTY_FUNCTION__,
39 _map_widget->allocation.width, _map_widget->allocation.height);
41 _screen_width_pixels = _map_widget->allocation.width;
42 _screen_height_pixels = _map_widget->allocation.height;
43 _screen_grids_halfwidth = pixel2grid(_screen_width_pixels) / 2;
44 _screen_grids_halfheight = pixel2grid(_screen_height_pixels) / 2;
46 /* Set _scale_rect. */
47 _scale_rect.x = (_screen_width_pixels - SCALE_WIDTH) / 2;
48 _scale_rect.width = SCALE_WIDTH;
49 pango_layout_set_text(_scale_layout, "0", -1);
50 pango_layout_get_pixel_size(_scale_layout, NULL, &_scale_rect.height);
51 _scale_rect.y = _screen_height_pixels - _scale_rect.height - 1;
53 MACRO_RECALC_FOCUS_BASE();
54 MACRO_RECALC_FOCUS_SIZE();
56 _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth));
57 _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight));
58 _max_center.unitx = WORLD_SIZE_UNITS - grid2unit(_screen_grids_halfwidth) - 1;
59 _max_center.unity = WORLD_SIZE_UNITS - grid2unit(_screen_grids_halfheight) - 1;
61 map_center_unit(_center.unitx, _center.unity);
63 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
67 gboolean menu_cb_route_download(GtkAction * action)
69 printf("%s()\n", __PRETTY_FUNCTION__);
71 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
75 gboolean menu_cb_route_open(GtkAction * action)
77 printf("%s()\n", __PRETTY_FUNCTION__);
81 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
85 gboolean menu_cb_route_distnext(GtkAction * action)
87 printf("%s()\n", __PRETTY_FUNCTION__);
89 route_show_distance_to_next();
91 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
95 gboolean menu_cb_route_distlast(GtkAction * action)
97 printf("%s()\n", __PRETTY_FUNCTION__);
99 route_show_distance_to_last();
101 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
105 gboolean menu_cb_route_reset(GtkAction * action)
107 printf("%s()\n", __PRETTY_FUNCTION__);
109 route_find_nearest_point();
110 MACRO_MAP_RENDER_DATA();
111 MACRO_QUEUE_DRAW_AREA();
113 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
117 gboolean menu_cb_route_clear(GtkAction * action)
119 printf("%s()\n", __PRETTY_FUNCTION__);
121 cancel_autoroute(FALSE);
122 MACRO_PATH_FREE(_route);
123 MACRO_PATH_INIT(_route);
124 route_find_nearest_point();
127 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
131 gboolean menu_cb_track_open(GtkAction * action)
133 printf("%s()\n", __PRETTY_FUNCTION__);
137 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
141 gboolean menu_cb_track_save(GtkAction * action)
143 printf("%s()\n", __PRETTY_FUNCTION__);
147 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
151 gboolean menu_cb_track_insert_break(GtkAction * action)
153 printf("%s()\n", __PRETTY_FUNCTION__);
155 track_insert_break();
157 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
161 gboolean menu_cb_track_insert_mark(GtkAction * action)
163 printf("%s()\n", __PRETTY_FUNCTION__);
167 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
171 gboolean menu_cb_track_distlast(GtkAction * action)
173 printf("%s()\n", __PRETTY_FUNCTION__);
175 track_show_distance_from_last();
177 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
181 gboolean menu_cb_track_distfirst(GtkAction * action)
183 printf("%s()\n", __PRETTY_FUNCTION__);
185 track_show_distance_from_first();
187 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
191 gboolean menu_cb_route_save(GtkAction * action)
193 printf("%s()\n", __PRETTY_FUNCTION__);
197 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
201 gboolean menu_cb_track_clear(GtkAction * action)
203 printf("%s()\n", __PRETTY_FUNCTION__);
207 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
211 gboolean menu_cb_track_filter(GtkAction * action)
217 gboolean menu_cb_show_tracks(GtkAction * action)
219 printf("%s()\n", __PRETTY_FUNCTION__);
221 _show_tracks ^= TRACKS_MASK;
222 if (gtk_check_menu_item_get_active
223 (GTK_CHECK_MENU_ITEM(_menu_show_tracks_item))) {
224 _show_tracks |= TRACKS_MASK;
226 MACRO_QUEUE_DRAW_AREA();
227 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now shown"));
229 _show_tracks &= ~TRACKS_MASK;
231 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now hidden"));
234 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
238 gboolean menu_cb_show_scale(GtkAction * action)
240 printf("%s()\n", __PRETTY_FUNCTION__);
243 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
244 (_menu_show_scale_item));
245 MACRO_QUEUE_DRAW_AREA();
247 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
251 gboolean menu_cb_show_routes(GtkAction * action)
253 printf("%s()\n", __PRETTY_FUNCTION__);
255 if (gtk_check_menu_item_get_active
256 (GTK_CHECK_MENU_ITEM(_menu_show_routes_item))) {
257 _show_tracks |= ROUTES_MASK;
259 MACRO_QUEUE_DRAW_AREA();
260 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now shown"));
262 _show_tracks &= ~ROUTES_MASK;
264 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now hidden"));
267 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
271 gboolean menu_cb_show_velvec(GtkAction * action)
273 printf("%s()\n", __PRETTY_FUNCTION__);
275 _show_velvec = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_show_velvec_item));
278 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
282 gboolean menu_cb_show_poi(GtkAction * action)
284 printf("%s()\n", __PRETTY_FUNCTION__);
286 _show_poi = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_show_poi_item));
289 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
293 gboolean menu_cb_gps_show_info(GtkAction * action)
295 printf("%s()\n", __PRETTY_FUNCTION__);
297 _gps_info = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_gps_show_info_item));
301 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
305 gboolean menu_cb_ac_lead(GtkAction * action)
307 guint new_center_unitx, new_center_unity;
308 printf("%s()\n", __PRETTY_FUNCTION__);
310 _center_mode = CENTER_LEAD;
311 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lead"));
312 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
313 map_center_unit(new_center_unitx, new_center_unity);
315 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
319 gboolean menu_cb_ac_latlon(GtkAction * action)
321 guint new_center_unitx, new_center_unity;
322 printf("%s()\n", __PRETTY_FUNCTION__);
324 _center_mode = CENTER_LATLON;
325 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lat/Lon"));
326 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
327 map_center_unit(new_center_unitx, new_center_unity);
329 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
333 gboolean menu_cb_ac_none(GtkAction * action)
335 printf("%s()\n", __PRETTY_FUNCTION__);
337 _center_mode = -_center_mode;
338 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Off"));
340 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
344 gboolean menu_cb_goto_latlon(GtkAction * action)
351 printf("%s()\n", __PRETTY_FUNCTION__);
353 dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"),
355 GTK_DIALOG_MODAL, GTK_STOCK_OK,
358 GTK_RESPONSE_REJECT, NULL);
360 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
361 table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0);
363 gtk_table_attach(GTK_TABLE(table),
364 label = gtk_label_new(_("Latitude")),
365 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
366 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
368 gtk_table_attach(GTK_TABLE(table),
369 txt_lat = gtk_entry_new(),
370 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
371 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
373 gtk_table_attach(GTK_TABLE(table),
374 label = gtk_label_new(_("Longitude")),
375 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
376 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
378 gtk_table_attach(GTK_TABLE(table),
379 txt_lon = gtk_entry_new(),
380 1, 2, 1, 2, GTK_FILL, 0, 2, 4);
381 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
383 #ifdef WITH_DEVICE_770
384 g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT,
385 HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
386 g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT,
387 HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
390 /* Initialize with the current center position. */
394 unit2latlon(_center.unitx, _center.unity, lat, lon);
395 snprintf(buffer, sizeof(buffer), "%.06f", lat);
396 gtk_label_set_text(GTK_LABEL(txt_lat), buffer);
397 snprintf(buffer, sizeof(buffer), "%.06f", lon);
398 gtk_label_set_text(GTK_LABEL(txt_lon), buffer);
401 gtk_widget_show_all(dialog);
403 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
409 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
410 lat = strtof(text, &error_check);
411 if (text == error_check || lat < -90.f || lat > 90.f) {
412 popup_error(dialog, _("Invalid Latitude"));
416 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
417 lon = strtof(text, &error_check);
418 if (text == error_check || lon < -180.f || lon > 180.f) {
419 popup_error(dialog, _("Invalid Longitude"));
423 latlon2unit(lat, lon, unitx, unity);
424 if (_center_mode > 0)
425 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
426 (_menu_ac_none_item), TRUE);
427 map_center_unit(unitx, unity);
430 gtk_widget_destroy(dialog);
431 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
435 gboolean menu_cb_goto_home(GtkAction * action)
439 printf("%s()\n", __PRETTY_FUNCTION__);
441 if (_center_mode > 0)
442 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
443 (_menu_ac_none_item), TRUE);
445 latlon2unit(_home.lat, _home.lon, unitx, unity);
446 map_center_unit(unitx, unity);
447 map_set_autozoom(FALSE);
448 map_update_location_from_center();
450 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
454 gboolean menu_cb_goto_destination(GtkAction *action)
458 if (_dest.valid==FALSE) {
459 MACRO_BANNER_SHOW_INFO(_window, _("Destination not set."));
462 latlon2unit(_dest.lat, _dest.lon, unitx, unity);
463 map_center_unit(unitx, unity);
464 map_set_autozoom(FALSE);
468 gboolean menu_cb_goto_gps(GtkAction * action)
470 printf("%s()\n", __PRETTY_FUNCTION__);
472 if (_center_mode > 0)
473 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
474 (_menu_ac_none_item), TRUE);
476 map_center_unit(_pos.unitx, _pos.unity);
477 map_update_location_from_center();
479 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
483 gboolean menu_cb_goto_nextway(GtkAction * action)
485 printf("%s()\n", __PRETTY_FUNCTION__);
487 if (_next_way && _next_way->point->unity) {
488 if (_center_mode > 0)
489 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
490 (_menu_ac_none_item),
493 map_center_unit(_next_way->point->unitx,
494 _next_way->point->unity);
496 MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
499 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
503 gboolean menu_cb_goto_nearpoi(GtkAction * action)
508 printf("%s()\n", __PRETTY_FUNCTION__);
510 if (_center_mode > 0) {
511 /* Auto-Center is enabled - use the GPS position. */
512 unit2latlon(_pos.unitx, _pos.unity, lat, lon);
514 /* Auto-Center is disabled - use the view center. */
515 unit2latlon(_center.unitx, _center.unity, lat, lon);
518 p=poi_find_nearest(lat, lon);
524 latlon2unit(p->lat, p->lon, unitx, unity);
525 banner = g_strdup_printf("%s (%s)", p->label, p->cat_label);
526 g_printf("%s\n", banner);
527 MACRO_BANNER_SHOW_INFO(_window, banner);
531 if (_center_mode > 0)
532 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_ac_none_item), TRUE);
534 map_center_unit(unitx, unity);
535 map_update_location_from_center();
537 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
540 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
544 gboolean menu_cb_maps_repoman(GtkAction * action)
546 printf("%s()\n", __PRETTY_FUNCTION__);
548 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
552 gboolean menu_cb_maps_select(GtkAction * action, gpointer new_repo)
554 printf("%s()\n", __PRETTY_FUNCTION__);
555 repo_set_curr(new_repo);
557 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
561 gboolean cb_zoom_autozoom(GtkAction * action)
563 printf("%s()\n", __PRETTY_FUNCTION__);
565 map_set_autozoom(TRUE);
567 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
571 gboolean cb_zoom_base(GtkAction * action)
573 printf("%s()\n", __PRETTY_FUNCTION__);
575 map_set_autozoom(FALSE);
578 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
582 gboolean cb_zoomin(GtkAction * action)
584 printf("%s()\n", __PRETTY_FUNCTION__);
586 map_set_autozoom(FALSE);
589 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
593 gboolean cb_zoomout(GtkAction * action)
595 printf("%s()\n", __PRETTY_FUNCTION__);
597 map_set_autozoom(FALSE);
600 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
604 gboolean cb_fullscreen_click(GtkAction * action)
606 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_fullscreen_item), !_fullscreen);
610 gboolean cb_fullscreen(GtkAction * action)
612 printf("%s()\n", __PRETTY_FUNCTION__);
614 if ((_fullscreen = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_fullscreen_item)))) {
615 gtk_window_fullscreen(GTK_WINDOW(_window));
616 gtk_widget_set_state(_toolbar_fullscreen_item, GTK_STATE_ACTIVE);
618 gtk_window_unfullscreen(GTK_WINDOW(_window));
619 gtk_widget_set_state(_toolbar_fullscreen_item, GTK_STATE_NORMAL);
622 gtk_idle_add((GSourceFunc) window_present, NULL);
624 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
628 gboolean menu_cb_enable_gps(GtkAction * action)
630 printf("%s()\n", __PRETTY_FUNCTION__);
633 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
634 (_menu_enable_gps_item)))) {
636 set_conn_state(RCVR_DOWN);
640 _("Cannot enable GPS until a GPS Receiver MAC "
641 "is set in the Settings dialog box."));
642 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
643 (_menu_enable_gps_item),
647 if (_conn_state > RCVR_OFF)
648 set_conn_state(RCVR_OFF);
651 _speed_excess = FALSE;
655 gtk_widget_set_sensitive(GTK_WIDGET(_menu_gps_details_item), _enable_gps);
657 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
661 gboolean menu_cb_auto_download(GtkAction * action)
663 printf("%s()\n", __PRETTY_FUNCTION__);
665 if ((_auto_download =
666 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_auto_download_item)))) {
667 if (_curr_repo->url == REPOTYPE_NONE)
669 _("NOTE: You must set a Map URI in the current repository in "
670 "order to download maps."));
674 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
678 gboolean menu_cb_gps_details(GtkAction * action)
680 printf("%s()\n", __PRETTY_FUNCTION__);
684 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
688 gboolean menu_cb_settings(GtkAction * action)
690 printf("%s()\n", __PRETTY_FUNCTION__);
692 if (settings_dialog()) {
693 /* Settings have changed - reconnect to receiver. */
695 set_conn_state(RCVR_DOWN);
700 MACRO_RECALC_FOCUS_BASE();
701 MACRO_RECALC_FOCUS_SIZE();
704 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
708 gboolean menu_cb_help(GtkAction * action)
710 printf("%s()\n", __PRETTY_FUNCTION__);
713 ossohelp_show(_osso, HELP_ID_INTRO, 0);
716 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
720 gboolean menu_cb_about(GtkAction * action)
723 ossohelp_show(_osso, HELP_ID_ABOUT, OSSO_HELP_SHOW_DIALOG);
726 "Kaj-Michael Lang","John Costigan","Cezary Jackiewicz", NULL};
728 gtk_show_about_dialog(GTK_WINDOW(_window),
731 "copyright", "Kaj-Michael Lang",
739 gboolean window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
741 CustomKey custom_key;
742 printf("%s()\n", __PRETTY_FUNCTION__);
744 switch (event->keyval) {
745 case HILDON_HARDKEY_UP:
746 custom_key = CUSTOM_KEY_UP;
748 case HILDON_HARDKEY_DOWN:
749 custom_key = CUSTOM_KEY_DOWN;
751 case HILDON_HARDKEY_LEFT:
752 custom_key = CUSTOM_KEY_LEFT;
754 case HILDON_HARDKEY_RIGHT:
755 custom_key = CUSTOM_KEY_RIGHT;
757 case HILDON_HARDKEY_SELECT:
758 custom_key = CUSTOM_KEY_SELECT;
760 case HILDON_HARDKEY_INCREASE:
761 custom_key = CUSTOM_KEY_INCREASE;
763 case HILDON_HARDKEY_DECREASE:
764 custom_key = CUSTOM_KEY_DECREASE;
766 case HILDON_HARDKEY_FULLSCREEN:
767 custom_key = CUSTOM_KEY_FULLSCREEN;
769 case HILDON_HARDKEY_ESC:
770 custom_key = CUSTOM_KEY_ESC;
773 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
777 switch (_action[custom_key]) {
778 case CUSTOM_ACTION_PAN_NORTH:
779 map_pan(0, -PAN_UNITS);
782 case CUSTOM_ACTION_PAN_WEST:
783 map_pan(-PAN_UNITS, 0);
786 case CUSTOM_ACTION_PAN_SOUTH:
787 map_pan(0, PAN_UNITS);
790 case CUSTOM_ACTION_PAN_EAST:
791 map_pan(PAN_UNITS, 0);
794 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
795 switch (_center_mode) {
797 case CENTER_WAS_LEAD:
798 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
799 (_menu_ac_lead_item),
803 case CENTER_WAS_LATLON:
804 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
805 (_menu_ac_latlon_item),
812 case CUSTOM_ACTION_ZOOM_IN:
813 case CUSTOM_ACTION_ZOOM_OUT:
814 if (!_key_zoom_timeout_sid) {
815 g_printf("Z: %d %d\n", _key_zoom_new, _zoom);
816 _key_zoom_new = _zoom
817 + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN
818 ? -_curr_repo->view_zoom_steps
819 : _curr_repo->view_zoom_steps);
820 /* Remember, _key_zoom_new is unsigned. */
821 if (_key_zoom_new < MAX_ZOOM) {
823 snprintf(buffer, sizeof(buffer), "%s %d",
824 _("Zoom to Level"), _key_zoom_new);
825 MACRO_BANNER_SHOW_INFO(_window, buffer);
826 _key_zoom_timeout_sid =
827 g_timeout_add(500, map_key_zoom_timeout,
833 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
834 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_fullscreen_item), !_fullscreen);
837 case CUSTOM_ACTION_TOGGLE_TRACKS:
838 switch (_show_tracks) {
840 /* Nothing shown, nothing saved; just set both. */
841 _show_tracks = TRACKS_MASK | ROUTES_MASK;
843 case TRACKS_MASK << 16:
844 case ROUTES_MASK << 16:
845 case (ROUTES_MASK | TRACKS_MASK) << 16:
846 /* Something was saved and nothing changed since.
848 _show_tracks = _show_tracks >> 16;
851 /* There is no history, or they changed something
852 * since the last historical change. Save and
854 _show_tracks = _show_tracks << 16;
856 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
857 (_menu_show_routes_item),
858 _show_tracks & ROUTES_MASK);
860 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
861 (_menu_show_tracks_item),
862 _show_tracks & TRACKS_MASK);
864 case CUSTOM_ACTION_TOGGLE_SCALE:
865 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
866 (_menu_show_scale_item),
870 case CUSTOM_ACTION_TOGGLE_POI:
871 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
872 (_menu_show_poi_item),
875 case CUSTOM_ACTION_CHANGE_REPO:{
876 GList *curr = g_list_find(_repo_list, _curr_repo);
880 /* Loop until we reach a next-able repo, or until we get
881 * back to the current repo. */
882 while ((curr = (curr->next ? curr->next : _repo_list))
883 && !((RepoData *) curr->data)->nextable
884 && curr->data != _curr_repo) {
887 if (curr->data != _curr_repo) {
888 repo_set_curr(curr->data);
889 gtk_check_menu_item_set_active
890 (GTK_CHECK_MENU_ITEM(_curr_repo->menu_item),
895 ("There are no other next-able repositories."));
900 case CUSTOM_ACTION_ROUTE_DISTNEXT:
901 route_show_distance_to_next();
904 case CUSTOM_ACTION_ROUTE_DISTLAST:
905 route_show_distance_to_last();
908 case CUSTOM_ACTION_TRACK_BREAK:
909 track_insert_break();
912 case CUSTOM_ACTION_TRACK_DISTLAST:
913 track_show_distance_from_last();
916 case CUSTOM_ACTION_TRACK_DISTFIRST:
917 track_show_distance_from_first();
920 case CUSTOM_ACTION_TOGGLE_GPS:
921 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
922 (_menu_enable_gps_item),
926 case CUSTOM_ACTION_TOGGLE_GPSINFO:
927 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
928 (_menu_gps_show_info_item),
932 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
933 _speed_limit_on ^= 1;
937 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
942 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
945 gboolean window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
947 printf("%s()\n", __PRETTY_FUNCTION__);
949 switch (event->keyval) {
950 case HILDON_HARDKEY_INCREASE:
951 case HILDON_HARDKEY_DECREASE:
952 if (_key_zoom_timeout_sid) {
953 g_source_remove(_key_zoom_timeout_sid);
954 _key_zoom_timeout_sid = 0;
955 map_set_zoom(_key_zoom_new);
962 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
965 void cmenu_show_latlon(guint unitx, guint unity)
968 gchar buffer[80], tmp1[16], tmp2[16];
969 printf("%s()\n", __PRETTY_FUNCTION__);
971 g_printf("S: %d %d\n", unitx, unity);
973 unit2latlon(unitx, unity, lat, lon);
974 lat_format(lat, tmp1);
975 lon_format(lon, tmp2);
977 snprintf(buffer, sizeof(buffer),
979 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
981 MACRO_BANNER_SHOW_INFO(_window, buffer);
983 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
986 void cmenu_clip_latlon(guint unitx, guint unity)
990 printf("%s()\n", __PRETTY_FUNCTION__);
992 unit2latlon(unitx, unity, lat, lon);
994 snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
996 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
999 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1002 void cmenu_route_to(guint unitx, guint unity)
1008 printf("%s()\n", __PRETTY_FUNCTION__);
1010 unit2latlon(unitx, unity, lat, lon);
1012 g_ascii_formatd(strlat, 32, "%.06f", lat);
1013 g_ascii_formatd(strlon, 32, "%.06f", lon);
1014 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
1016 route_download(buffer);
1018 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1021 void cmenu_distance_to(guint unitx, guint unity)
1025 printf("%s()\n", __PRETTY_FUNCTION__);
1027 unit2latlon(unitx, unity, lat, lon);
1029 snprintf(buffer, sizeof(buffer), "%s: %.02f %s", _("Distance"),
1030 calculate_distance(_gps.lat, _gps.lon, lat, lon)
1031 * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
1032 MACRO_BANNER_SHOW_INFO(_window, buffer);
1034 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1037 void cmenu_add_route(guint unitx, guint unity)
1039 printf("%s()\n", __PRETTY_FUNCTION__);
1040 MACRO_PATH_INCREMENT_TAIL(_route);
1041 _route.tail->unitx = x2unit(_cmenu_position_x);
1042 _route.tail->unity = y2unit(_cmenu_position_y);
1043 route_find_nearest_point();
1045 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1048 void cmenu_route_add_way(guint unitx, guint unity)
1051 gchar tmp1[16], tmp2[16], *p_latlon;
1055 GtkWidget *txt_scroll;
1056 GtkWidget *txt_desc;
1057 printf("%s()\n", __PRETTY_FUNCTION__);
1059 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
1060 GTK_WINDOW(_window),
1061 GTK_DIALOG_MODAL, GTK_STOCK_OK,
1062 GTK_RESPONSE_ACCEPT,
1064 GTK_RESPONSE_REJECT, NULL);
1066 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1067 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
1069 gtk_table_attach(GTK_TABLE(table),
1070 label = gtk_label_new(_("Lat, Lon")),
1071 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
1072 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1074 unit2latlon(unitx, unity, lat, lon);
1075 lat_format(lat, tmp1);
1076 lon_format(lon, tmp2);
1077 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
1078 gtk_table_attach(GTK_TABLE(table),
1079 label = gtk_label_new(p_latlon),
1080 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
1081 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
1084 gtk_table_attach(GTK_TABLE(table),
1085 label = gtk_label_new(_("Description")),
1086 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
1087 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1089 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
1090 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
1092 gtk_table_attach(GTK_TABLE(table),
1094 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
1096 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
1097 GTK_POLICY_AUTOMATIC,
1098 GTK_POLICY_AUTOMATIC);
1100 txt_desc = gtk_text_view_new();
1101 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
1103 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
1104 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
1106 gtk_widget_show_all(dialog);
1108 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
1109 GtkTextBuffer *tbuf;
1110 GtkTextIter ti1, ti2;
1113 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
1114 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
1115 gtk_text_buffer_get_end_iter(tbuf, &ti2);
1116 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
1119 /* There's a description. Add a waypoint. */
1120 MACRO_PATH_INCREMENT_TAIL(_route);
1121 _route.tail->unitx = unitx;
1122 _route.tail->unity = unity;
1123 _route.tail->time = 0;
1124 _route.tail->altitude = NAN;
1126 MACRO_PATH_INCREMENT_WTAIL(_route);
1127 _route.wtail->point = _route.tail;
1129 = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
1135 confirm = hildon_note_new_confirmation(GTK_WINDOW(dialog),
1136 _("Creating a \"waypoint\" with no description actually "
1137 "adds a break point. Is that what you want?"));
1139 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1140 /* There's no description. Add a break by adding a (0, 0)
1141 * point (if necessary), and then the ordinary route point. */
1142 if (_route.tail->unity) {
1143 MACRO_PATH_INCREMENT_TAIL(_route);
1144 *_route.tail = _point_null;
1147 MACRO_PATH_INCREMENT_TAIL(_route);
1148 _route.tail->unitx = unitx;
1149 _route.tail->unity = unity;
1150 _route.tail->time = 0;
1151 _route.tail->altitude = NAN;
1153 gtk_widget_destroy(confirm);
1155 gtk_widget_destroy(confirm);
1160 route_find_nearest_point();
1162 MACRO_QUEUE_DRAW_AREA();
1165 gtk_widget_destroy(dialog);
1166 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1169 gboolean cmenu_cb_loc_show_latlon(GtkAction * action)
1171 printf("%s()\n", __PRETTY_FUNCTION__);
1173 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1175 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1179 gboolean cmenu_cb_loc_clip_latlon(GtkAction * action)
1181 printf("%s()\n", __PRETTY_FUNCTION__);
1183 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1185 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1189 gboolean cmenu_cb_loc_route_to(GtkAction * action)
1191 printf("%s()\n", __PRETTY_FUNCTION__);
1193 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1195 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1199 gboolean cmenu_cb_loc_distance_to(GtkAction * action)
1201 printf("%s()\n", __PRETTY_FUNCTION__);
1203 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1205 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1209 gboolean cmenu_cb_loc_add_route(GtkAction * action)
1211 printf("%s()\n", __PRETTY_FUNCTION__);
1213 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1215 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1219 gboolean cmenu_cb_loc_add_way(GtkAction * action)
1221 printf("%s()\n", __PRETTY_FUNCTION__);
1223 cmenu_route_add_way(x2unit(_cmenu_position_x),
1224 y2unit(_cmenu_position_y));
1226 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1230 gboolean cmenu_cb_loc_add_poi(GtkAction * action)
1232 printf("%s()\n", __PRETTY_FUNCTION__);
1234 poi_dialog(ACTION_ADD_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1236 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1240 gboolean cb_add_poi(GtkAction * action)
1243 printf("%s()\n", __PRETTY_FUNCTION__);
1245 if (_center_mode > 0) {
1246 latlon2unit(_gps.lat, _gps.lon, unitx, unity);
1247 poi_dialog(ACTION_ADD_POI, unitx, unity);
1249 poi_dialog(ACTION_ADD_POI, _center.unitx, _center.unity);
1252 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1256 gboolean cmenu_cb_loc_set_home(GtkAction * action)
1258 _pos.unitx = x2unit(_cmenu_position_x);
1259 _pos.unity = y2unit(_cmenu_position_y);
1260 unit2latlon(_pos.unitx, _pos.unity, _home.lat, _home.lon);
1267 gboolean cmenu_cb_loc_set_destination(GtkAction *action)
1269 _pos.unitx = x2unit(_cmenu_position_x);
1270 _pos.unity = y2unit(_cmenu_position_y);
1271 unit2latlon(_pos.unitx, _pos.unity, _dest.lat, _dest.lon);
1276 gboolean cmenu_cb_loc_set_gps(GtkAction * action)
1278 _pos.unitx = x2unit(_cmenu_position_x);
1279 _pos.unity = y2unit(_cmenu_position_y);
1280 unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
1282 /* Move mark to new location. */
1288 gboolean cmenu_cb_way_show_latlon(GtkAction * action)
1291 printf("%s()\n", __PRETTY_FUNCTION__);
1293 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1294 y2unit(_cmenu_position_y))))
1295 cmenu_show_latlon(way->point->unitx, way->point->unity);
1297 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1301 gboolean cmenu_cb_way_show_desc(GtkAction * action)
1304 printf("%s()\n", __PRETTY_FUNCTION__);
1306 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1307 y2unit(_cmenu_position_y)))) {
1308 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1311 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1315 gboolean cmenu_cb_way_clip_latlon(GtkAction * action)
1318 printf("%s()\n", __PRETTY_FUNCTION__);
1320 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1321 y2unit(_cmenu_position_y))))
1322 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1324 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1328 gboolean cmenu_cb_way_clip_desc(GtkAction * action)
1331 printf("%s()\n", __PRETTY_FUNCTION__);
1333 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1334 y2unit(_cmenu_position_y))))
1335 gtk_clipboard_set_text(gtk_clipboard_get
1336 (GDK_SELECTION_CLIPBOARD), way->desc,
1339 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1343 gboolean cmenu_cb_way_route_to(GtkAction * action)
1346 printf("%s()\n", __PRETTY_FUNCTION__);
1348 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1349 y2unit(_cmenu_position_y))))
1350 cmenu_route_to(way->point->unitx, way->point->unity);
1352 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1356 gboolean cmenu_cb_way_distance_to(GtkAction * action)
1359 printf("%s()\n", __PRETTY_FUNCTION__);
1361 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1362 y2unit(_cmenu_position_y))))
1363 route_show_distance_to(way->point);
1365 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1369 gboolean cmenu_cb_way_delete(GtkAction * action)
1372 printf("%s()\n", __PRETTY_FUNCTION__);
1374 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1375 y2unit(_cmenu_position_y)))) {
1376 gchar buffer[BUFFER_SIZE];
1379 snprintf(buffer, sizeof(buffer), "%s:\n%s\n",
1380 _("Confirm delete of waypoint"), way->desc);
1381 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
1383 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1384 Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
1387 /* Delete surrounding route data, too. */
1388 if (way == _route.whead)
1389 pdel_min = _route.head;
1391 pdel_min = way[-1].point;
1393 if (way == _route.wtail)
1394 pdel_max = _route.tail;
1396 pdel_max = way[1].point;
1398 /* Find largest continuous segment around the waypoint, EXCLUDING
1399 * pdel_min and pdel_max. */
1400 for (pdel_start = way->point - 1; pdel_start->unity
1401 && pdel_start > pdel_min; pdel_start--) {
1403 for (pdel_end = way->point + 1; pdel_end->unity
1404 && pdel_end < pdel_max; pdel_end++) {
1407 /* If pdel_end is set to _route.tail, and if _route.tail is a
1408 * non-zero point, then delete _route.tail. */
1409 if (pdel_end == _route.tail && pdel_end->unity)
1410 pdel_end++; /* delete _route.tail too */
1411 /* else, if *both* endpoints are zero points, delete one. */
1412 else if (!pdel_start->unity && !pdel_end->unity)
1415 /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
1416 num_del = pdel_end - pdel_start - 1;
1418 memmove(pdel_start + 1, pdel_end,
1419 (_route.tail - pdel_end + 1) * sizeof(Point));
1420 _route.tail -= num_del;
1422 /* Remove waypoint and move/adjust subsequent waypoints. */
1424 while (way++ != _route.wtail) {
1426 way[-1].point -= num_del;
1430 route_find_nearest_point();
1433 gtk_widget_destroy(confirm);
1436 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1440 gboolean cmenu_cb_way_add_poi(GtkAction * action)
1443 printf("%s()\n", __PRETTY_FUNCTION__);
1445 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1446 poi_dialog(ACTION_ADD_POI, way->point->unitx, way->point->unity);
1448 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1452 gboolean cmenu_cb_poi_route_to(GtkAction * action)
1455 printf("%s()\n", __PRETTY_FUNCTION__);
1457 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1459 latlon2unit(poi.lat, poi.lon, unitx, unity);
1460 cmenu_route_to(unitx, unity);
1463 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1467 gboolean cmenu_cb_poi_distance_to(GtkAction * action)
1470 printf("%s()\n", __PRETTY_FUNCTION__);
1472 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1474 latlon2unit(poi.lat, poi.lon, unitx, unity);
1475 cmenu_distance_to(unitx, unity);
1478 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1482 gboolean cmenu_cb_poi_add_route(GtkAction * action)
1485 printf("%s()\n", __PRETTY_FUNCTION__);
1487 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1489 latlon2unit(poi.lat, poi.lon, unitx, unity);
1490 cmenu_add_route(unitx, unity);
1493 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1497 gboolean cmenu_cb_poi_add_way(GtkAction * action)
1500 printf("%s()\n", __PRETTY_FUNCTION__);
1502 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1504 latlon2unit(poi.lat, poi.lon, unitx, unity);
1505 cmenu_route_add_way(unitx, unity);
1508 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1512 gboolean cmenu_cb_poi_edit_poi(GtkAction * action)
1514 printf("%s()\n", __PRETTY_FUNCTION__);
1516 poi_dialog(ACTION_EDIT_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1518 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);