14 #include <glib/gstdio.h>
17 #include <libgnomevfs/gnome-vfs.h>
18 #include <curl/multi.h>
19 #include <gconf/gconf-client.h>
20 #include <libxml/parser.h>
27 #include <osso-helplib.h>
28 #include <hildon-widgets/hildon-program.h>
29 #include <hildon-widgets/hildon-controlbar.h>
30 #include <hildon-widgets/hildon-note.h>
31 #include <hildon-widgets/hildon-color-button.h>
32 #include <hildon-widgets/hildon-file-chooser-dialog.h>
33 #include <hildon-widgets/hildon-number-editor.h>
34 #include <hildon-widgets/hildon-banner.h>
35 #include <hildon-widgets/hildon-input-mode-hint.h>
36 #include <device_symbols.h>
45 #include "mapper-types.h"
47 #include "ui-common.h"
52 gboolean map_cb_configure(GtkWidget * widget, GdkEventConfigure * event)
54 printf("%s(%d, %d)\n", __PRETTY_FUNCTION__,
55 _map_widget->allocation.width, _map_widget->allocation.height);
57 _screen_width_pixels = _map_widget->allocation.width;
58 _screen_height_pixels = _map_widget->allocation.height;
59 _screen_grids_halfwidth = pixel2grid(_screen_width_pixels) / 2;
60 _screen_grids_halfheight = pixel2grid(_screen_height_pixels) / 2;
62 /* Set _scale_rect. */
63 _scale_rect.x = (_screen_width_pixels - SCALE_WIDTH) / 2;
64 _scale_rect.width = SCALE_WIDTH;
65 pango_layout_set_text(_scale_layout, "0", -1);
66 pango_layout_get_pixel_size(_scale_layout, NULL, &_scale_rect.height);
67 _scale_rect.y = _screen_height_pixels - _scale_rect.height - 1;
69 MACRO_RECALC_FOCUS_BASE();
70 MACRO_RECALC_FOCUS_SIZE();
72 _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth));
73 _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight));
74 _max_center.unitx = WORLD_SIZE_UNITS - grid2unit(_screen_grids_halfwidth) - 1;
75 _max_center.unity = WORLD_SIZE_UNITS - grid2unit(_screen_grids_halfheight) - 1;
77 map_center_unit(_center.unitx, _center.unity);
79 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
83 gboolean menu_cb_route_download(GtkAction * action)
85 printf("%s()\n", __PRETTY_FUNCTION__);
87 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
91 gboolean menu_cb_route_open(GtkAction * action)
93 printf("%s()\n", __PRETTY_FUNCTION__);
97 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
101 gboolean menu_cb_route_distnext(GtkAction * action)
103 printf("%s()\n", __PRETTY_FUNCTION__);
105 route_show_distance_to_next();
107 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
111 gboolean menu_cb_route_distlast(GtkAction * action)
113 printf("%s()\n", __PRETTY_FUNCTION__);
115 route_show_distance_to_last();
117 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
121 gboolean menu_cb_route_reset(GtkAction * action)
123 printf("%s()\n", __PRETTY_FUNCTION__);
125 route_find_nearest_point();
126 MACRO_MAP_RENDER_DATA();
127 MACRO_QUEUE_DRAW_AREA();
129 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
133 gboolean menu_cb_route_clear(GtkAction * action)
135 printf("%s()\n", __PRETTY_FUNCTION__);
137 cancel_autoroute(FALSE);
138 MACRO_PATH_FREE(_route);
139 MACRO_PATH_INIT(_route);
140 route_find_nearest_point();
143 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
147 gboolean menu_cb_track_open(GtkAction * action)
149 printf("%s()\n", __PRETTY_FUNCTION__);
153 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
157 gboolean menu_cb_track_save(GtkAction * action)
159 printf("%s()\n", __PRETTY_FUNCTION__);
163 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
167 gboolean menu_cb_track_insert_break(GtkAction * action)
169 printf("%s()\n", __PRETTY_FUNCTION__);
171 track_insert_break();
173 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
177 gboolean menu_cb_track_insert_mark(GtkAction * action)
179 printf("%s()\n", __PRETTY_FUNCTION__);
183 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
187 gboolean menu_cb_track_distlast(GtkAction * action)
189 printf("%s()\n", __PRETTY_FUNCTION__);
191 track_show_distance_from_last();
193 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
197 gboolean menu_cb_track_distfirst(GtkAction * action)
199 printf("%s()\n", __PRETTY_FUNCTION__);
201 track_show_distance_from_first();
203 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
207 gboolean menu_cb_route_save(GtkAction * action)
209 printf("%s()\n", __PRETTY_FUNCTION__);
213 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
217 gboolean menu_cb_track_clear(GtkAction * action)
219 printf("%s()\n", __PRETTY_FUNCTION__);
223 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
227 gboolean menu_cb_show_tracks(GtkAction * action)
229 printf("%s()\n", __PRETTY_FUNCTION__);
231 _show_tracks ^= TRACKS_MASK;
232 if (gtk_check_menu_item_get_active
233 (GTK_CHECK_MENU_ITEM(_menu_show_tracks_item))) {
234 _show_tracks |= TRACKS_MASK;
236 MACRO_QUEUE_DRAW_AREA();
237 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now shown"));
239 _show_tracks &= ~TRACKS_MASK;
241 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now hidden"));
244 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
248 gboolean menu_cb_show_scale(GtkAction * action)
250 printf("%s()\n", __PRETTY_FUNCTION__);
253 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
254 (_menu_show_scale_item));
255 MACRO_QUEUE_DRAW_AREA();
257 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
261 gboolean menu_cb_show_routes(GtkAction * action)
263 printf("%s()\n", __PRETTY_FUNCTION__);
265 if (gtk_check_menu_item_get_active
266 (GTK_CHECK_MENU_ITEM(_menu_show_routes_item))) {
267 _show_tracks |= ROUTES_MASK;
269 MACRO_QUEUE_DRAW_AREA();
270 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now shown"));
272 _show_tracks &= ~ROUTES_MASK;
274 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now hidden"));
277 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
281 gboolean menu_cb_show_velvec(GtkAction * action)
283 printf("%s()\n", __PRETTY_FUNCTION__);
285 _show_velvec = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_show_velvec_item));
288 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
292 gboolean menu_cb_show_poi(GtkAction * action)
294 printf("%s()\n", __PRETTY_FUNCTION__);
296 _show_poi = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_show_poi_item));
299 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
303 gboolean menu_cb_gps_show_info(GtkAction * action)
305 printf("%s()\n", __PRETTY_FUNCTION__);
307 _gps_info = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_gps_show_info_item));
311 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
315 gboolean menu_cb_ac_lead(GtkAction * action)
317 guint new_center_unitx, new_center_unity;
318 printf("%s()\n", __PRETTY_FUNCTION__);
320 _center_mode = CENTER_LEAD;
321 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lead"));
322 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
323 map_center_unit(new_center_unitx, new_center_unity);
325 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
329 gboolean menu_cb_ac_latlon(GtkAction * action)
331 guint new_center_unitx, new_center_unity;
332 printf("%s()\n", __PRETTY_FUNCTION__);
334 _center_mode = CENTER_LATLON;
335 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lat/Lon"));
336 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
337 map_center_unit(new_center_unitx, new_center_unity);
339 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
343 gboolean menu_cb_ac_none(GtkAction * action)
345 printf("%s()\n", __PRETTY_FUNCTION__);
347 _center_mode = -_center_mode;
348 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Off"));
350 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
354 gboolean menu_cb_goto_latlon(GtkAction * action)
361 printf("%s()\n", __PRETTY_FUNCTION__);
363 dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"),
365 GTK_DIALOG_MODAL, GTK_STOCK_OK,
368 GTK_RESPONSE_REJECT, NULL);
370 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
371 table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0);
373 gtk_table_attach(GTK_TABLE(table),
374 label = gtk_label_new(_("Latitude")),
375 0, 1, 0, 1, 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_lat = gtk_entry_new(),
380 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
381 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
383 gtk_table_attach(GTK_TABLE(table),
384 label = gtk_label_new(_("Longitude")),
385 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
386 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
388 gtk_table_attach(GTK_TABLE(table),
389 txt_lon = gtk_entry_new(),
390 1, 2, 1, 2, GTK_FILL, 0, 2, 4);
391 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
394 g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT,
395 HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
396 g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT,
397 HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
400 /* Initialize with the current center position. */
404 unit2latlon(_center.unitx, _center.unity, lat, lon);
405 snprintf(buffer, sizeof(buffer), "%.06f", lat);
406 gtk_label_set_text(GTK_LABEL(txt_lat), buffer);
407 snprintf(buffer, sizeof(buffer), "%.06f", lon);
408 gtk_label_set_text(GTK_LABEL(txt_lon), buffer);
411 gtk_widget_show_all(dialog);
413 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
419 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
420 lat = strtof(text, &error_check);
421 if (text == error_check || lat < -90.f || lat > 90.f) {
422 popup_error(dialog, _("Invalid Latitude"));
426 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
427 lon = strtof(text, &error_check);
428 if (text == error_check || lon < -180.f || lon > 180.f) {
429 popup_error(dialog, _("Invalid Longitude"));
433 latlon2unit(lat, lon, unitx, unity);
434 if (_center_mode > 0)
435 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
436 (_menu_ac_none_item), TRUE);
437 map_center_unit(unitx, unity);
440 gtk_widget_destroy(dialog);
441 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
445 gboolean menu_cb_goto_home(GtkAction * action)
449 printf("%s()\n", __PRETTY_FUNCTION__);
451 if (_center_mode > 0)
452 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
453 (_menu_ac_none_item), TRUE);
455 latlon2unit(_home.lat, _home.lon, unitx, unity);
456 map_center_unit(unitx, unity);
458 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
462 gboolean menu_cb_goto_gps(GtkAction * action)
464 printf("%s()\n", __PRETTY_FUNCTION__);
466 if (_center_mode > 0)
467 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
468 (_menu_ac_none_item), TRUE);
470 map_center_unit(_pos.unitx, _pos.unity);
472 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
476 gboolean menu_cb_goto_nextway(GtkAction * action)
478 printf("%s()\n", __PRETTY_FUNCTION__);
480 if (_next_way && _next_way->point->unity) {
481 if (_center_mode > 0)
482 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
483 (_menu_ac_none_item),
486 map_center_unit(_next_way->point->unitx,
487 _next_way->point->unity);
489 MACRO_BANNER_SHOW_INFO(_window,
490 _("There is no next waypoint."));
493 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
497 gboolean menu_cb_goto_nearpoi(GtkAction * action)
502 printf("%s()\n", __PRETTY_FUNCTION__);
504 if (_center_mode > 0) {
505 /* Auto-Center is enabled - use the GPS position. */
506 unit2latlon(_pos.unitx, _pos.unity, lat, lon);
508 /* Auto-Center is disabled - use the view center. */
509 unit2latlon(_center.unitx, _center.unity, lat, lon);
512 p=poi_find_nearest(lat, lon);
518 latlon2unit(p->lat, p->lon, unitx, unity);
519 banner = g_strdup_printf("%s (%s)", p->label, p->cat_label);
520 g_printf("%s\n", banner);
521 MACRO_BANNER_SHOW_INFO(_window, banner);
525 if (_center_mode > 0)
526 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_ac_none_item), TRUE);
528 map_center_unit(unitx, unity);
530 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
533 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
537 gboolean menu_cb_maps_repoman(GtkAction * action)
539 printf("%s()\n", __PRETTY_FUNCTION__);
541 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
545 gboolean menu_cb_maps_select(GtkAction * action, gpointer new_repo)
547 printf("%s()\n", __PRETTY_FUNCTION__);
548 repo_set_curr(new_repo);
550 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
554 gboolean cb_zoom_autozoom(GtkAction * action)
556 printf("%s()\n", __PRETTY_FUNCTION__);
558 map_set_autozoom(TRUE);
560 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
564 gboolean cb_zoom_base(GtkAction * action)
566 printf("%s()\n", __PRETTY_FUNCTION__);
568 map_set_autozoom(FALSE);
571 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
575 gboolean cb_zoomin(GtkAction * action)
577 printf("%s()\n", __PRETTY_FUNCTION__);
579 map_set_autozoom(FALSE);
582 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
586 gboolean cb_zoomout(GtkAction * action)
588 printf("%s()\n", __PRETTY_FUNCTION__);
590 map_set_autozoom(FALSE);
593 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
597 gboolean cb_fullscreen_click(GtkAction * action)
599 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_fullscreen_item), !_fullscreen);
603 gboolean cb_fullscreen(GtkAction * action)
605 printf("%s()\n", __PRETTY_FUNCTION__);
607 if ((_fullscreen = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_fullscreen_item)))) {
608 gtk_window_fullscreen(GTK_WINDOW(_window));
609 gtk_widget_set_state(_toolbar_fullscreen_item, GTK_STATE_ACTIVE);
611 gtk_window_unfullscreen(GTK_WINDOW(_window));
612 gtk_widget_set_state(_toolbar_fullscreen_item, GTK_STATE_NORMAL);
615 gtk_idle_add((GSourceFunc) window_present, NULL);
617 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
621 gboolean menu_cb_enable_gps(GtkAction * action)
623 printf("%s()\n", __PRETTY_FUNCTION__);
626 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
627 (_menu_enable_gps_item)))) {
629 set_conn_state(RCVR_DOWN);
633 _("Cannot enable GPS until a GPS Receiver MAC "
634 "is set in the Settings dialog box."));
635 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
636 (_menu_enable_gps_item),
640 if (_conn_state > RCVR_OFF)
641 set_conn_state(RCVR_OFF);
644 _speed_excess = FALSE;
648 gtk_widget_set_sensitive(GTK_WIDGET(_menu_gps_details_item), _enable_gps);
650 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
654 gboolean menu_cb_auto_download(GtkAction * action)
656 printf("%s()\n", __PRETTY_FUNCTION__);
658 if ((_auto_download =
659 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_auto_download_item)))) {
660 if (_curr_repo->url == REPOTYPE_NONE)
662 _("NOTE: You must set a Map URI in the current repository in "
663 "order to download maps."));
667 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
671 gboolean menu_cb_gps_details(GtkAction * action)
673 printf("%s()\n", __PRETTY_FUNCTION__);
677 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
681 gboolean menu_cb_settings(GtkAction * action)
683 printf("%s()\n", __PRETTY_FUNCTION__);
685 if (settings_dialog()) {
686 /* Settings have changed - reconnect to receiver. */
688 set_conn_state(RCVR_DOWN);
693 MACRO_RECALC_FOCUS_BASE();
694 MACRO_RECALC_FOCUS_SIZE();
697 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
701 gboolean menu_cb_help(GtkAction * action)
703 printf("%s()\n", __PRETTY_FUNCTION__);
706 ossohelp_show(_osso, HELP_ID_INTRO, 0);
709 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
713 gboolean menu_cb_about(GtkAction * action)
715 printf("%s()\n", __PRETTY_FUNCTION__);
718 ossohelp_show(_osso, HELP_ID_ABOUT, OSSO_HELP_SHOW_DIALOG);
720 gtk_show_about_dialog(GTK_WINDOW(_window), "name", "Mapper",
721 "version", VERSION, NULL);
724 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
728 gboolean window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
730 CustomKey custom_key;
731 printf("%s()\n", __PRETTY_FUNCTION__);
733 switch (event->keyval) {
734 case HILDON_HARDKEY_UP:
735 custom_key = CUSTOM_KEY_UP;
737 case HILDON_HARDKEY_DOWN:
738 custom_key = CUSTOM_KEY_DOWN;
740 case HILDON_HARDKEY_LEFT:
741 custom_key = CUSTOM_KEY_LEFT;
743 case HILDON_HARDKEY_RIGHT:
744 custom_key = CUSTOM_KEY_RIGHT;
746 case HILDON_HARDKEY_SELECT:
747 custom_key = CUSTOM_KEY_SELECT;
749 case HILDON_HARDKEY_INCREASE:
750 custom_key = CUSTOM_KEY_INCREASE;
752 case HILDON_HARDKEY_DECREASE:
753 custom_key = CUSTOM_KEY_DECREASE;
755 case HILDON_HARDKEY_FULLSCREEN:
756 custom_key = CUSTOM_KEY_FULLSCREEN;
758 case HILDON_HARDKEY_ESC:
759 custom_key = CUSTOM_KEY_ESC;
762 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
766 switch (_action[custom_key]) {
767 case CUSTOM_ACTION_PAN_NORTH:
768 map_pan(0, -PAN_UNITS);
771 case CUSTOM_ACTION_PAN_WEST:
772 map_pan(-PAN_UNITS, 0);
775 case CUSTOM_ACTION_PAN_SOUTH:
776 map_pan(0, PAN_UNITS);
779 case CUSTOM_ACTION_PAN_EAST:
780 map_pan(PAN_UNITS, 0);
783 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
784 switch (_center_mode) {
786 case CENTER_WAS_LEAD:
787 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
788 (_menu_ac_lead_item),
792 case CENTER_WAS_LATLON:
793 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
794 (_menu_ac_latlon_item),
801 case CUSTOM_ACTION_ZOOM_IN:
802 case CUSTOM_ACTION_ZOOM_OUT:
803 if (!_key_zoom_timeout_sid) {
804 g_printf("Z: %d %d\n", _key_zoom_new, _zoom);
805 _key_zoom_new = _zoom
806 + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN
807 ? -_curr_repo->view_zoom_steps
808 : _curr_repo->view_zoom_steps);
809 /* Remember, _key_zoom_new is unsigned. */
810 if (_key_zoom_new < MAX_ZOOM) {
812 snprintf(buffer, sizeof(buffer), "%s %d",
813 _("Zoom to Level"), _key_zoom_new);
814 MACRO_BANNER_SHOW_INFO(_window, buffer);
815 _key_zoom_timeout_sid =
816 g_timeout_add(500, map_key_zoom_timeout,
822 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
823 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_fullscreen_item), !_fullscreen);
826 case CUSTOM_ACTION_TOGGLE_TRACKS:
827 switch (_show_tracks) {
829 /* Nothing shown, nothing saved; just set both. */
830 _show_tracks = TRACKS_MASK | ROUTES_MASK;
832 case TRACKS_MASK << 16:
833 case ROUTES_MASK << 16:
834 case (ROUTES_MASK | TRACKS_MASK) << 16:
835 /* Something was saved and nothing changed since.
837 _show_tracks = _show_tracks >> 16;
840 /* There is no history, or they changed something
841 * since the last historical change. Save and
843 _show_tracks = _show_tracks << 16;
845 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
846 (_menu_show_routes_item),
847 _show_tracks & ROUTES_MASK);
849 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
850 (_menu_show_tracks_item),
851 _show_tracks & TRACKS_MASK);
853 case CUSTOM_ACTION_TOGGLE_SCALE:
854 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
855 (_menu_show_scale_item),
859 case CUSTOM_ACTION_TOGGLE_POI:
860 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
861 (_menu_show_poi_item),
864 case CUSTOM_ACTION_CHANGE_REPO:{
865 GList *curr = g_list_find(_repo_list, _curr_repo);
869 /* Loop until we reach a next-able repo, or until we get
870 * back to the current repo. */
871 while ((curr = (curr->next ? curr->next : _repo_list))
872 && !((RepoData *) curr->data)->nextable
873 && curr->data != _curr_repo) {
876 if (curr->data != _curr_repo) {
877 repo_set_curr(curr->data);
878 gtk_check_menu_item_set_active
879 (GTK_CHECK_MENU_ITEM(_curr_repo->menu_item),
884 ("There are no other next-able repositories."));
889 case CUSTOM_ACTION_ROUTE_DISTNEXT:
890 route_show_distance_to_next();
893 case CUSTOM_ACTION_ROUTE_DISTLAST:
894 route_show_distance_to_last();
897 case CUSTOM_ACTION_TRACK_BREAK:
898 track_insert_break();
901 case CUSTOM_ACTION_TRACK_DISTLAST:
902 track_show_distance_from_last();
905 case CUSTOM_ACTION_TRACK_DISTFIRST:
906 track_show_distance_from_first();
909 case CUSTOM_ACTION_TOGGLE_GPS:
910 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
911 (_menu_enable_gps_item),
915 case CUSTOM_ACTION_TOGGLE_GPSINFO:
916 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
917 (_menu_gps_show_info_item),
921 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
922 _speed_limit_on ^= 1;
926 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
931 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
934 gboolean window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
936 printf("%s()\n", __PRETTY_FUNCTION__);
938 switch (event->keyval) {
939 case HILDON_HARDKEY_INCREASE:
940 case HILDON_HARDKEY_DECREASE:
941 if (_key_zoom_timeout_sid) {
942 g_source_remove(_key_zoom_timeout_sid);
943 _key_zoom_timeout_sid = 0;
944 map_set_zoom(_key_zoom_new);
951 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
954 void cmenu_show_latlon(guint unitx, guint unity)
957 gchar buffer[80], tmp1[16], tmp2[16];
958 printf("%s()\n", __PRETTY_FUNCTION__);
960 g_printf("S: %d %d\n", unitx, unity);
962 unit2latlon(unitx, unity, lat, lon);
963 lat_format(lat, tmp1);
964 lon_format(lon, tmp2);
966 snprintf(buffer, sizeof(buffer),
968 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
970 MACRO_BANNER_SHOW_INFO(_window, buffer);
972 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
975 void cmenu_clip_latlon(guint unitx, guint unity)
979 printf("%s()\n", __PRETTY_FUNCTION__);
981 unit2latlon(unitx, unity, lat, lon);
983 snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
985 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
988 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
991 void cmenu_route_to(guint unitx, guint unity)
997 printf("%s()\n", __PRETTY_FUNCTION__);
999 unit2latlon(unitx, unity, lat, lon);
1001 g_ascii_formatd(strlat, 32, "%.06f", lat);
1002 g_ascii_formatd(strlon, 32, "%.06f", lon);
1003 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
1005 route_download(buffer);
1007 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1010 void cmenu_distance_to(guint unitx, guint unity)
1014 printf("%s()\n", __PRETTY_FUNCTION__);
1016 unit2latlon(unitx, unity, lat, lon);
1018 snprintf(buffer, sizeof(buffer), "%s: %.02f %s", _("Distance"),
1019 calculate_distance(_gps.lat, _gps.lon, lat, lon)
1020 * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
1021 MACRO_BANNER_SHOW_INFO(_window, buffer);
1023 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1026 void cmenu_add_route(guint unitx, guint unity)
1028 printf("%s()\n", __PRETTY_FUNCTION__);
1029 MACRO_PATH_INCREMENT_TAIL(_route);
1030 _route.tail->unitx = x2unit(_cmenu_position_x);
1031 _route.tail->unity = y2unit(_cmenu_position_y);
1032 route_find_nearest_point();
1034 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1037 void cmenu_route_add_way(guint unitx, guint unity)
1040 gchar tmp1[16], tmp2[16], *p_latlon;
1044 GtkWidget *txt_scroll;
1045 GtkWidget *txt_desc;
1046 printf("%s()\n", __PRETTY_FUNCTION__);
1048 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
1049 GTK_WINDOW(_window),
1050 GTK_DIALOG_MODAL, GTK_STOCK_OK,
1051 GTK_RESPONSE_ACCEPT,
1053 GTK_RESPONSE_REJECT, NULL);
1055 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1056 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
1058 gtk_table_attach(GTK_TABLE(table),
1059 label = gtk_label_new(_("Lat, Lon")),
1060 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
1061 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1063 unit2latlon(unitx, unity, lat, lon);
1064 lat_format(lat, tmp1);
1065 lon_format(lon, tmp2);
1066 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
1067 gtk_table_attach(GTK_TABLE(table),
1068 label = gtk_label_new(p_latlon),
1069 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
1070 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
1073 gtk_table_attach(GTK_TABLE(table),
1074 label = gtk_label_new(_("Description")),
1075 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
1076 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1078 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
1079 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
1081 gtk_table_attach(GTK_TABLE(table),
1083 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
1085 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
1086 GTK_POLICY_AUTOMATIC,
1087 GTK_POLICY_AUTOMATIC);
1089 txt_desc = gtk_text_view_new();
1090 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
1092 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
1093 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
1095 gtk_widget_show_all(dialog);
1097 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
1098 GtkTextBuffer *tbuf;
1099 GtkTextIter ti1, ti2;
1102 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
1103 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
1104 gtk_text_buffer_get_end_iter(tbuf, &ti2);
1105 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
1108 /* There's a description. Add a waypoint. */
1109 MACRO_PATH_INCREMENT_TAIL(_route);
1110 _route.tail->unitx = unitx;
1111 _route.tail->unity = unity;
1112 _route.tail->time = 0;
1113 _route.tail->altitude = NAN;
1115 MACRO_PATH_INCREMENT_WTAIL(_route);
1116 _route.wtail->point = _route.tail;
1118 = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
1125 hildon_note_new_confirmation(GTK_WINDOW(dialog),
1127 ("Creating a \"waypoint\" with no description actually "
1128 "adds a break point. Is that what you want?"));
1130 if (GTK_RESPONSE_OK ==
1131 gtk_dialog_run(GTK_DIALOG(confirm))) {
1132 /* There's no description. Add a break by adding a (0, 0)
1133 * point (if necessary), and then the ordinary route point. */
1134 if (_route.tail->unity) {
1135 MACRO_PATH_INCREMENT_TAIL(_route);
1136 *_route.tail = _point_null;
1139 MACRO_PATH_INCREMENT_TAIL(_route);
1140 _route.tail->unitx = unitx;
1141 _route.tail->unity = unity;
1142 _route.tail->time = 0;
1143 _route.tail->altitude = NAN;
1145 gtk_widget_destroy(confirm);
1147 gtk_widget_destroy(confirm);
1152 route_find_nearest_point();
1154 MACRO_QUEUE_DRAW_AREA();
1157 gtk_widget_destroy(dialog);
1158 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1161 gboolean cmenu_cb_loc_show_latlon(GtkAction * action)
1163 printf("%s()\n", __PRETTY_FUNCTION__);
1165 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1167 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1171 gboolean cmenu_cb_loc_clip_latlon(GtkAction * action)
1173 printf("%s()\n", __PRETTY_FUNCTION__);
1175 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1177 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1181 gboolean cmenu_cb_loc_route_to(GtkAction * action)
1183 printf("%s()\n", __PRETTY_FUNCTION__);
1185 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1187 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1191 gboolean cmenu_cb_loc_distance_to(GtkAction * action)
1193 printf("%s()\n", __PRETTY_FUNCTION__);
1195 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1197 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1201 gboolean cmenu_cb_loc_add_route(GtkAction * action)
1203 printf("%s()\n", __PRETTY_FUNCTION__);
1205 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1207 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1211 gboolean cmenu_cb_loc_add_way(GtkAction * action)
1213 printf("%s()\n", __PRETTY_FUNCTION__);
1215 cmenu_route_add_way(x2unit(_cmenu_position_x),
1216 y2unit(_cmenu_position_y));
1218 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1222 gboolean cmenu_cb_loc_add_poi(GtkAction * action)
1224 printf("%s()\n", __PRETTY_FUNCTION__);
1226 poi_dialog(ACTION_ADD_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1228 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1232 gboolean cb_add_poi(GtkAction * action)
1234 printf("%s()\n", __PRETTY_FUNCTION__);
1236 poi_dialog(ACTION_ADD_POI, _gps.lat, _gps.lon);
1238 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1242 gboolean cmenu_cb_loc_set_home(GtkAction * action)
1244 printf("%s()\n", __PRETTY_FUNCTION__);
1246 _pos.unitx = x2unit(_cmenu_position_x);
1247 _pos.unity = y2unit(_cmenu_position_y);
1248 unit2latlon(_pos.unitx, _pos.unity, _home.lat, _home.lon);
1250 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1254 gboolean cmenu_cb_loc_set_gps(GtkAction * action)
1256 printf("%s()\n", __PRETTY_FUNCTION__);
1258 _pos.unitx = x2unit(_cmenu_position_x);
1259 _pos.unity = y2unit(_cmenu_position_y);
1260 unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
1262 /* Move mark to new location. */
1265 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1269 gboolean cmenu_cb_way_show_latlon(GtkAction * action)
1272 printf("%s()\n", __PRETTY_FUNCTION__);
1274 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1275 y2unit(_cmenu_position_y))))
1276 cmenu_show_latlon(way->point->unitx, way->point->unity);
1278 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1282 gboolean cmenu_cb_way_show_desc(GtkAction * action)
1285 printf("%s()\n", __PRETTY_FUNCTION__);
1287 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1288 y2unit(_cmenu_position_y)))) {
1289 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1292 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1296 gboolean cmenu_cb_way_clip_latlon(GtkAction * action)
1299 printf("%s()\n", __PRETTY_FUNCTION__);
1301 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1302 y2unit(_cmenu_position_y))))
1303 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1305 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1309 gboolean cmenu_cb_way_clip_desc(GtkAction * action)
1312 printf("%s()\n", __PRETTY_FUNCTION__);
1314 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1315 y2unit(_cmenu_position_y))))
1316 gtk_clipboard_set_text(gtk_clipboard_get
1317 (GDK_SELECTION_CLIPBOARD), way->desc,
1320 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1324 gboolean cmenu_cb_way_route_to(GtkAction * action)
1327 printf("%s()\n", __PRETTY_FUNCTION__);
1329 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1330 y2unit(_cmenu_position_y))))
1331 cmenu_route_to(way->point->unitx, way->point->unity);
1333 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1337 gboolean cmenu_cb_way_distance_to(GtkAction * action)
1340 printf("%s()\n", __PRETTY_FUNCTION__);
1342 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1343 y2unit(_cmenu_position_y))))
1344 route_show_distance_to(way->point);
1346 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1350 gboolean cmenu_cb_way_delete(GtkAction * action)
1353 printf("%s()\n", __PRETTY_FUNCTION__);
1355 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1356 y2unit(_cmenu_position_y)))) {
1357 gchar buffer[BUFFER_SIZE];
1360 snprintf(buffer, sizeof(buffer), "%s:\n%s\n",
1361 _("Confirm delete of waypoint"), way->desc);
1362 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
1364 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1365 Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
1368 /* Delete surrounding route data, too. */
1369 if (way == _route.whead)
1370 pdel_min = _route.head;
1372 pdel_min = way[-1].point;
1374 if (way == _route.wtail)
1375 pdel_max = _route.tail;
1377 pdel_max = way[1].point;
1379 /* Find largest continuous segment around the waypoint, EXCLUDING
1380 * pdel_min and pdel_max. */
1381 for (pdel_start = way->point - 1; pdel_start->unity
1382 && pdel_start > pdel_min; pdel_start--) {
1384 for (pdel_end = way->point + 1; pdel_end->unity
1385 && pdel_end < pdel_max; pdel_end++) {
1388 /* If pdel_end is set to _route.tail, and if _route.tail is a
1389 * non-zero point, then delete _route.tail. */
1390 if (pdel_end == _route.tail && pdel_end->unity)
1391 pdel_end++; /* delete _route.tail too */
1392 /* else, if *both* endpoints are zero points, delete one. */
1393 else if (!pdel_start->unity && !pdel_end->unity)
1396 /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
1397 num_del = pdel_end - pdel_start - 1;
1399 memmove(pdel_start + 1, pdel_end,
1400 (_route.tail - pdel_end + 1) * sizeof(Point));
1401 _route.tail -= num_del;
1403 /* Remove waypoint and move/adjust subsequent waypoints. */
1405 while (way++ != _route.wtail) {
1407 way[-1].point -= num_del;
1411 route_find_nearest_point();
1414 gtk_widget_destroy(confirm);
1417 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1421 gboolean cmenu_cb_way_add_poi(GtkAction * action)
1424 printf("%s()\n", __PRETTY_FUNCTION__);
1426 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
1427 poi_dialog(ACTION_ADD_POI, way->point->unitx, way->point->unity);
1429 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1433 gboolean cmenu_cb_poi_route_to(GtkAction * action)
1436 printf("%s()\n", __PRETTY_FUNCTION__);
1439 (x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1441 latlon2unit(poi.lat, poi.lon, unitx, unity);
1442 cmenu_route_to(unitx, unity);
1445 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1449 gboolean cmenu_cb_poi_distance_to(GtkAction * action)
1452 printf("%s()\n", __PRETTY_FUNCTION__);
1454 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1456 latlon2unit(poi.lat, poi.lon, unitx, unity);
1457 cmenu_distance_to(unitx, unity);
1460 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1464 gboolean cmenu_cb_poi_add_route(GtkAction * action)
1467 printf("%s()\n", __PRETTY_FUNCTION__);
1469 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1471 latlon2unit(poi.lat, poi.lon, unitx, unity);
1472 cmenu_add_route(unitx, unity);
1475 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1479 gboolean cmenu_cb_poi_add_way(GtkAction * action)
1482 printf("%s()\n", __PRETTY_FUNCTION__);
1484 if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1486 latlon2unit(poi.lat, poi.lon, unitx, unity);
1487 cmenu_route_add_way(unitx, unity);
1490 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1494 gboolean cmenu_cb_poi_edit_poi(GtkAction * action)
1496 printf("%s()\n", __PRETTY_FUNCTION__);
1498 poi_dialog(ACTION_EDIT_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1500 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);