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>
31 #include "mapper-types.h"
33 #include "ui-common.h"
37 gboolean map_cb_configure(GtkWidget * widget, GdkEventConfigure * event)
39 printf("%s(%d, %d)\n", __PRETTY_FUNCTION__,
40 _map_widget->allocation.width, _map_widget->allocation.height);
42 _screen_width_pixels = _map_widget->allocation.width;
43 _screen_height_pixels = _map_widget->allocation.height;
44 _screen_grids_halfwidth = pixel2grid(_screen_width_pixels) / 2;
45 _screen_grids_halfheight = pixel2grid(_screen_height_pixels) / 2;
47 /* Set _scale_rect. */
48 _scale_rect.x = (_screen_width_pixels - SCALE_WIDTH) / 2;
49 _scale_rect.width = SCALE_WIDTH;
50 pango_layout_set_text(_scale_layout, "0", -1);
51 pango_layout_get_pixel_size(_scale_layout, NULL, &_scale_rect.height);
52 _scale_rect.y = _screen_height_pixels - _scale_rect.height - 1;
54 MACRO_RECALC_FOCUS_BASE();
55 MACRO_RECALC_FOCUS_SIZE();
57 _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth));
58 _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight));
60 WORLD_SIZE_UNITS - grid2unit(_screen_grids_halfwidth) - 1;
62 WORLD_SIZE_UNITS - grid2unit(_screen_grids_halfheight) - 1;
64 map_center_unit(_center.unitx, _center.unity);
66 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
70 gboolean menu_cb_route_download(GtkAction * action)
72 printf("%s()\n", __PRETTY_FUNCTION__);
74 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
78 gboolean menu_cb_route_open(GtkAction * action)
80 printf("%s()\n", __PRETTY_FUNCTION__);
84 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
88 gboolean menu_cb_route_distnext(GtkAction * action)
90 printf("%s()\n", __PRETTY_FUNCTION__);
92 route_show_distance_to_next();
94 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
98 gboolean menu_cb_route_distlast(GtkAction * action)
100 printf("%s()\n", __PRETTY_FUNCTION__);
102 route_show_distance_to_last();
104 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
108 gboolean menu_cb_route_reset(GtkAction * action)
110 printf("%s()\n", __PRETTY_FUNCTION__);
112 route_find_nearest_point();
113 MACRO_MAP_RENDER_DATA();
114 MACRO_QUEUE_DRAW_AREA();
116 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
120 gboolean menu_cb_route_clear(GtkAction * action)
122 printf("%s()\n", __PRETTY_FUNCTION__);
124 cancel_autoroute(FALSE);
125 MACRO_PATH_FREE(_route);
126 MACRO_PATH_INIT(_route);
127 route_find_nearest_point();
130 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
134 gboolean menu_cb_track_open(GtkAction * action)
136 printf("%s()\n", __PRETTY_FUNCTION__);
140 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
144 gboolean menu_cb_track_save(GtkAction * action)
146 printf("%s()\n", __PRETTY_FUNCTION__);
150 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
154 gboolean menu_cb_track_insert_break(GtkAction * action)
156 printf("%s()\n", __PRETTY_FUNCTION__);
158 track_insert_break();
160 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
164 gboolean menu_cb_track_insert_mark(GtkAction * action)
166 printf("%s()\n", __PRETTY_FUNCTION__);
170 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
174 gboolean menu_cb_track_distlast(GtkAction * action)
176 printf("%s()\n", __PRETTY_FUNCTION__);
178 track_show_distance_from_last();
180 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
184 gboolean menu_cb_track_distfirst(GtkAction * action)
186 printf("%s()\n", __PRETTY_FUNCTION__);
188 track_show_distance_from_first();
190 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
194 gboolean menu_cb_route_save(GtkAction * action)
196 GnomeVFSHandle *handle;
197 printf("%s()\n", __PRETTY_FUNCTION__);
199 if (open_file(NULL, &handle, NULL, &_route_dir_uri, NULL,
200 GTK_FILE_CHOOSER_ACTION_SAVE)) {
201 if (write_gpx(&_route, handle)) {
202 MACRO_BANNER_SHOW_INFO(_window, _("Route Saved"));
204 popup_error(_window, _("Error writing GPX file."));
205 gnome_vfs_close(handle);
208 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
212 gboolean menu_cb_track_clear(GtkAction * action)
214 printf("%s()\n", __PRETTY_FUNCTION__);
218 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
222 gboolean menu_cb_show_tracks(GtkAction * action)
224 printf("%s()\n", __PRETTY_FUNCTION__);
226 _show_tracks ^= TRACKS_MASK;
227 if (gtk_check_menu_item_get_active
228 (GTK_CHECK_MENU_ITEM(_menu_show_tracks_item))) {
229 _show_tracks |= TRACKS_MASK;
231 MACRO_QUEUE_DRAW_AREA();
232 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now shown"));
234 _show_tracks &= ~TRACKS_MASK;
236 MACRO_BANNER_SHOW_INFO(_window, _("Tracks are now hidden"));
239 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
243 gboolean menu_cb_show_scale(GtkAction * action)
245 printf("%s()\n", __PRETTY_FUNCTION__);
248 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
249 (_menu_show_scale_item));
250 MACRO_QUEUE_DRAW_AREA();
252 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
256 gboolean menu_cb_show_routes(GtkAction * action)
258 printf("%s()\n", __PRETTY_FUNCTION__);
260 if (gtk_check_menu_item_get_active
261 (GTK_CHECK_MENU_ITEM(_menu_show_routes_item))) {
262 _show_tracks |= ROUTES_MASK;
264 MACRO_QUEUE_DRAW_AREA();
265 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now shown"));
267 _show_tracks &= ~ROUTES_MASK;
269 MACRO_BANNER_SHOW_INFO(_window, _("Routes are now hidden"));
272 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
276 gboolean menu_cb_show_velvec(GtkAction * action)
278 printf("%s()\n", __PRETTY_FUNCTION__);
281 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
282 (_menu_show_velvec_item));
285 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
289 gboolean menu_cb_show_poi(GtkAction * action)
291 printf("%s()\n", __PRETTY_FUNCTION__);
294 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
295 (_menu_show_poi_item));
298 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
302 gboolean menu_cb_gps_show_info(GtkAction * action)
304 printf("%s()\n", __PRETTY_FUNCTION__);
307 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
308 (_menu_gps_show_info_item));
312 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
316 gboolean menu_cb_ac_lead(GtkAction * action)
318 guint new_center_unitx, new_center_unity;
319 printf("%s()\n", __PRETTY_FUNCTION__);
321 _center_mode = CENTER_LEAD;
322 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lead"));
323 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
324 map_center_unit(new_center_unitx, new_center_unity);
326 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
330 gboolean menu_cb_ac_latlon(GtkAction * action)
332 guint new_center_unitx, new_center_unity;
333 printf("%s()\n", __PRETTY_FUNCTION__);
335 _center_mode = CENTER_LATLON;
336 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Mode: Lat/Lon"));
337 MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
338 map_center_unit(new_center_unitx, new_center_unity);
340 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
344 gboolean menu_cb_ac_none(GtkAction * action)
346 printf("%s()\n", __PRETTY_FUNCTION__);
348 _center_mode = -_center_mode;
349 MACRO_BANNER_SHOW_INFO(_window, _("Auto-Center Off"));
351 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
355 gboolean menu_cb_goto_latlon(GtkAction * action)
362 printf("%s()\n", __PRETTY_FUNCTION__);
364 dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"),
366 GTK_DIALOG_MODAL, GTK_STOCK_OK,
369 GTK_RESPONSE_REJECT, NULL);
371 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
372 table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0);
374 gtk_table_attach(GTK_TABLE(table),
375 label = gtk_label_new(_("Latitude")),
376 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
377 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
379 gtk_table_attach(GTK_TABLE(table),
380 txt_lat = gtk_entry_new(),
381 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
382 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
384 gtk_table_attach(GTK_TABLE(table),
385 label = gtk_label_new(_("Longitude")),
386 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
387 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
389 gtk_table_attach(GTK_TABLE(table),
390 txt_lon = gtk_entry_new(),
391 1, 2, 1, 2, GTK_FILL, 0, 2, 4);
392 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
395 g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT,
396 HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
397 g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT,
398 HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
401 /* Initialize with the current center position. */
405 unit2latlon(_center.unitx, _center.unity, lat, lon);
406 snprintf(buffer, sizeof(buffer), "%.06f", lat);
407 gtk_label_set_text(GTK_LABEL(txt_lat), buffer);
408 snprintf(buffer, sizeof(buffer), "%.06f", lon);
409 gtk_label_set_text(GTK_LABEL(txt_lon), buffer);
412 gtk_widget_show_all(dialog);
414 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
420 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
421 lat = strtof(text, &error_check);
422 if (text == error_check || lat < -90.f || lat > 90.f) {
423 popup_error(dialog, _("Invalid Latitude"));
427 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
428 lon = strtof(text, &error_check);
429 if (text == error_check || lon < -180.f || lon > 180.f) {
430 popup_error(dialog, _("Invalid Longitude"));
434 latlon2unit(lat, lon, unitx, unity);
435 if (_center_mode > 0)
436 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
437 (_menu_ac_none_item),
439 map_center_unit(unitx, unity);
442 gtk_widget_destroy(dialog);
443 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
447 gboolean menu_cb_goto_gps(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 map_center_unit(_pos.unitx, _pos.unity);
457 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
461 gboolean menu_cb_goto_nextway(GtkAction * action)
463 printf("%s()\n", __PRETTY_FUNCTION__);
465 if (_next_way && _next_way->point->unity) {
466 if (_center_mode > 0)
467 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
468 (_menu_ac_none_item),
471 map_center_unit(_next_way->point->unitx,
472 _next_way->point->unity);
474 MACRO_BANNER_SHOW_INFO(_window,
475 _("There is no next waypoint."));
478 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
482 gboolean menu_cb_goto_nearpoi(GtkAction * action)
484 printf("%s()\n", __PRETTY_FUNCTION__);
489 if (_center_mode > 0) {
490 /* Auto-Center is enabled - use the GPS position. */
491 unit2latlon(_pos.unitx, _pos.unity, lat, lon);
493 /* Auto-Center is disabled - use the view center. */
494 unit2latlon(_center.unitx, _center.unity, lat, lon);
498 sqlite3_bind_double(_stmt_select_nearest_poi, 1, lat)
500 sqlite3_bind_double(_stmt_select_nearest_poi, 2, lon)
501 && SQLITE_ROW == sqlite3_step(_stmt_select_nearest_poi)) {
504 const gchar *poi_label, *cat_label;
507 sqlite3_column_double(_stmt_select_nearest_poi, 0);
509 sqlite3_column_double(_stmt_select_nearest_poi, 1);
511 sqlite3_column_text(_stmt_select_nearest_poi, 2);
513 sqlite3_column_text(_stmt_select_nearest_poi, 3);
515 latlon2unit(lat, lon, unitx, unity);
517 g_strdup_printf("%s (%s)", poi_label, cat_label);
518 MACRO_BANNER_SHOW_INFO(_window, banner);
521 if (_center_mode > 0)
522 gtk_check_menu_item_set_active
523 (GTK_CHECK_MENU_ITEM(_menu_ac_none_item),
526 map_center_unit(unitx, unity);
528 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
530 sqlite3_reset(_stmt_select_nearest_poi);
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 menu_cb_zoomin(GtkAction * action)
556 printf("%s()\n", __PRETTY_FUNCTION__);
560 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
564 gboolean menu_cb_zoomout(GtkAction * action)
566 printf("%s()\n", __PRETTY_FUNCTION__);
570 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
574 gboolean menu_cb_fullscreen(GtkAction * action)
576 printf("%s()\n", __PRETTY_FUNCTION__);
579 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
580 (_menu_fullscreen_item))))
581 gtk_window_fullscreen(GTK_WINDOW(_window));
583 gtk_window_unfullscreen(GTK_WINDOW(_window));
585 gtk_idle_add((GSourceFunc) window_present, NULL);
587 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
591 gboolean menu_cb_enable_gps(GtkAction * action)
593 printf("%s()\n", __PRETTY_FUNCTION__);
596 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
597 (_menu_enable_gps_item)))) {
599 set_conn_state(RCVR_DOWN);
604 ("Cannot enable GPS until a GPS Receiver MAC "
605 "is set in the Settings dialog box."));
606 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
607 (_menu_enable_gps_item),
611 if (_conn_state > RCVR_OFF)
612 set_conn_state(RCVR_OFF);
615 _speed_excess = FALSE;
619 gtk_widget_set_sensitive(GTK_WIDGET(_menu_gps_details_item),
621 gtk_widget_set_sensitive(GTK_WIDGET(_menu_gps_reset_item), _enable_gps);
623 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
627 gboolean menu_cb_auto_download(GtkAction * action)
629 printf("%s()\n", __PRETTY_FUNCTION__);
631 if ((_auto_download =
632 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM
633 (_menu_auto_download_item)))) {
634 if (_curr_repo->url == REPOTYPE_NONE)
637 ("NOTE: You must set a Map URI in the current repository in "
638 "order to download maps."));
642 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
646 gboolean menu_cb_gps_reset(GtkAction * action)
648 printf("%s()\n", __PRETTY_FUNCTION__);
652 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
656 gboolean menu_cb_gps_details(GtkAction * action)
658 printf("%s()\n", __PRETTY_FUNCTION__);
662 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
666 gboolean menu_cb_settings(GtkAction * action)
668 printf("%s()\n", __PRETTY_FUNCTION__);
670 if (settings_dialog()) {
671 /* Settings have changed - reconnect to receiver. */
673 set_conn_state(RCVR_DOWN);
678 MACRO_RECALC_FOCUS_BASE();
679 MACRO_RECALC_FOCUS_SIZE();
682 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
686 gboolean menu_cb_help(GtkAction * action)
688 printf("%s()\n", __PRETTY_FUNCTION__);
691 ossohelp_show(_osso, HELP_ID_INTRO, 0);
694 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
698 gboolean menu_cb_about(GtkAction * action)
700 printf("%s()\n", __PRETTY_FUNCTION__);
703 ossohelp_show(_osso, HELP_ID_ABOUT, OSSO_HELP_SHOW_DIALOG);
705 gtk_show_about_dialog(GTK_WINDOW(_window), "name", "OSM-Mapper",
706 "version", "0.1", NULL);
709 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
713 gboolean window_cb_key_press(GtkWidget * widget, GdkEventKey * event)
715 CustomKey custom_key;
716 printf("%s()\n", __PRETTY_FUNCTION__);
718 switch (event->keyval) {
719 case HILDON_HARDKEY_UP:
720 custom_key = CUSTOM_KEY_UP;
722 case HILDON_HARDKEY_DOWN:
723 custom_key = CUSTOM_KEY_DOWN;
725 case HILDON_HARDKEY_LEFT:
726 custom_key = CUSTOM_KEY_LEFT;
728 case HILDON_HARDKEY_RIGHT:
729 custom_key = CUSTOM_KEY_RIGHT;
731 case HILDON_HARDKEY_SELECT:
732 custom_key = CUSTOM_KEY_SELECT;
734 case HILDON_HARDKEY_INCREASE:
735 custom_key = CUSTOM_KEY_INCREASE;
737 case HILDON_HARDKEY_DECREASE:
738 custom_key = CUSTOM_KEY_DECREASE;
740 case HILDON_HARDKEY_FULLSCREEN:
741 custom_key = CUSTOM_KEY_FULLSCREEN;
743 case HILDON_HARDKEY_ESC:
744 custom_key = CUSTOM_KEY_ESC;
747 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
751 switch (_action[custom_key]) {
752 case CUSTOM_ACTION_PAN_NORTH:
753 map_pan(0, -PAN_UNITS);
756 case CUSTOM_ACTION_PAN_WEST:
757 map_pan(-PAN_UNITS, 0);
760 case CUSTOM_ACTION_PAN_SOUTH:
761 map_pan(0, PAN_UNITS);
764 case CUSTOM_ACTION_PAN_EAST:
765 map_pan(PAN_UNITS, 0);
768 case CUSTOM_ACTION_TOGGLE_AUTOCENTER:
769 switch (_center_mode) {
771 case CENTER_WAS_LEAD:
772 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
773 (_menu_ac_lead_item),
777 case CENTER_WAS_LATLON:
778 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
779 (_menu_ac_latlon_item),
785 case CUSTOM_ACTION_ZOOM_IN:
786 case CUSTOM_ACTION_ZOOM_OUT:
787 if (!_key_zoom_timeout_sid) {
788 g_printf("Z: %d %d\n", _key_zoom_new, _zoom);
789 _key_zoom_new = _zoom
790 + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN
791 ? -_curr_repo->view_zoom_steps
792 : _curr_repo->view_zoom_steps);
793 /* Remember, _key_zoom_new is unsigned. */
794 if (_key_zoom_new < MAX_ZOOM) {
796 snprintf(buffer, sizeof(buffer), "%s %d",
797 _("Zoom to Level"), _key_zoom_new);
798 MACRO_BANNER_SHOW_INFO(_window, buffer);
799 _key_zoom_timeout_sid =
800 g_timeout_add(500, map_key_zoom_timeout,
806 case CUSTOM_ACTION_TOGGLE_FULLSCREEN:
807 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
808 (_menu_fullscreen_item),
812 case CUSTOM_ACTION_TOGGLE_TRACKS:
813 switch (_show_tracks) {
815 /* Nothing shown, nothing saved; just set both. */
816 _show_tracks = TRACKS_MASK | ROUTES_MASK;
818 case TRACKS_MASK << 16:
819 case ROUTES_MASK << 16:
820 case (ROUTES_MASK | TRACKS_MASK) << 16:
821 /* Something was saved and nothing changed since.
823 _show_tracks = _show_tracks >> 16;
826 /* There is no history, or they changed something
827 * since the last historical change. Save and
829 _show_tracks = _show_tracks << 16;
831 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
832 (_menu_show_routes_item),
833 _show_tracks & ROUTES_MASK);
835 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
836 (_menu_show_tracks_item),
837 _show_tracks & TRACKS_MASK);
839 case CUSTOM_ACTION_TOGGLE_SCALE:
840 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
841 (_menu_show_scale_item),
845 case CUSTOM_ACTION_TOGGLE_POI:
846 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
847 (_menu_show_poi_item),
850 case CUSTOM_ACTION_CHANGE_REPO:{
851 GList *curr = g_list_find(_repo_list, _curr_repo);
855 /* Loop until we reach a next-able repo, or until we get
856 * back to the current repo. */
857 while ((curr = (curr->next ? curr->next : _repo_list))
858 && !((RepoData *) curr->data)->nextable
859 && curr->data != _curr_repo) {
862 if (curr->data != _curr_repo) {
863 repo_set_curr(curr->data);
864 gtk_check_menu_item_set_active
865 (GTK_CHECK_MENU_ITEM(_curr_repo->menu_item),
870 ("There are no other next-able repositories."));
875 case CUSTOM_ACTION_RESET_BLUETOOTH:
879 case CUSTOM_ACTION_ROUTE_DISTNEXT:
880 route_show_distance_to_next();
883 case CUSTOM_ACTION_ROUTE_DISTLAST:
884 route_show_distance_to_last();
887 case CUSTOM_ACTION_TRACK_BREAK:
888 track_insert_break();
891 case CUSTOM_ACTION_TRACK_DISTLAST:
892 track_show_distance_from_last();
895 case CUSTOM_ACTION_TRACK_DISTFIRST:
896 track_show_distance_from_first();
899 case CUSTOM_ACTION_TOGGLE_GPS:
900 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
901 (_menu_enable_gps_item),
905 case CUSTOM_ACTION_TOGGLE_GPSINFO:
906 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
907 (_menu_gps_show_info_item),
911 case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
912 _speed_limit_on ^= 1;
916 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
921 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
924 gboolean window_cb_key_release(GtkWidget * widget, GdkEventKey * event)
926 printf("%s()\n", __PRETTY_FUNCTION__);
928 switch (event->keyval) {
929 case HILDON_HARDKEY_INCREASE:
930 case HILDON_HARDKEY_DECREASE:
931 if (_key_zoom_timeout_sid) {
932 g_source_remove(_key_zoom_timeout_sid);
933 _key_zoom_timeout_sid = 0;
934 map_set_zoom(_key_zoom_new);
941 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
944 void cmenu_show_latlon(guint unitx, guint unity)
947 gchar buffer[80], tmp1[16], tmp2[16];
948 printf("%s()\n", __PRETTY_FUNCTION__);
950 unit2latlon(unitx, unity, lat, lon);
951 lat_format(lat, tmp1);
952 lon_format(lon, tmp2);
954 snprintf(buffer, sizeof(buffer),
956 "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
958 MACRO_BANNER_SHOW_INFO(_window, buffer);
960 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
963 void cmenu_clip_latlon(guint unitx, guint unity)
967 printf("%s()\n", __PRETTY_FUNCTION__);
969 unit2latlon(unitx, unity, lat, lon);
971 snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
973 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
976 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
979 void cmenu_route_to(guint unitx, guint unity)
985 printf("%s()\n", __PRETTY_FUNCTION__);
987 unit2latlon(unitx, unity, lat, lon);
989 g_ascii_formatd(strlat, 32, "%.06f", lat);
990 g_ascii_formatd(strlon, 32, "%.06f", lon);
991 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
993 route_download(buffer);
995 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
998 void cmenu_distance_to(guint unitx, guint unity)
1002 printf("%s()\n", __PRETTY_FUNCTION__);
1004 unit2latlon(unitx, unity, lat, lon);
1006 snprintf(buffer, sizeof(buffer), "%s: %.02f %s", _("Distance"),
1007 calculate_distance(_gps.lat, _gps.lon, lat, lon)
1008 * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
1009 MACRO_BANNER_SHOW_INFO(_window, buffer);
1011 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1014 void cmenu_add_route(guint unitx, guint unity)
1016 printf("%s()\n", __PRETTY_FUNCTION__);
1017 MACRO_PATH_INCREMENT_TAIL(_route);
1018 _route.tail->unitx = x2unit(_cmenu_position_x);
1019 _route.tail->unity = y2unit(_cmenu_position_y);
1020 route_find_nearest_point();
1022 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1025 void cmenu_route_add_way(guint unitx, guint unity)
1028 gchar tmp1[16], tmp2[16], *p_latlon;
1032 GtkWidget *txt_scroll;
1033 GtkWidget *txt_desc;
1034 printf("%s()\n", __PRETTY_FUNCTION__);
1036 dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
1037 GTK_WINDOW(_window),
1038 GTK_DIALOG_MODAL, GTK_STOCK_OK,
1039 GTK_RESPONSE_ACCEPT,
1041 GTK_RESPONSE_REJECT, NULL);
1043 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1044 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
1046 gtk_table_attach(GTK_TABLE(table),
1047 label = gtk_label_new(_("Lat, Lon")),
1048 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
1049 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1051 unit2latlon(unitx, unity, lat, lon);
1052 lat_format(lat, tmp1);
1053 lon_format(lon, tmp2);
1054 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
1055 gtk_table_attach(GTK_TABLE(table),
1056 label = gtk_label_new(p_latlon),
1057 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
1058 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
1061 gtk_table_attach(GTK_TABLE(table),
1062 label = gtk_label_new(_("Description")),
1063 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
1064 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1066 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
1067 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
1069 gtk_table_attach(GTK_TABLE(table),
1071 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
1073 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
1074 GTK_POLICY_AUTOMATIC,
1075 GTK_POLICY_AUTOMATIC);
1077 txt_desc = gtk_text_view_new();
1078 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
1080 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
1081 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
1083 gtk_widget_show_all(dialog);
1085 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
1086 GtkTextBuffer *tbuf;
1087 GtkTextIter ti1, ti2;
1090 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
1091 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
1092 gtk_text_buffer_get_end_iter(tbuf, &ti2);
1093 desc = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
1096 /* There's a description. Add a waypoint. */
1097 MACRO_PATH_INCREMENT_TAIL(_route);
1098 _route.tail->unitx = unitx;
1099 _route.tail->unity = unity;
1100 _route.tail->time = 0;
1101 _route.tail->altitude = NAN;
1103 MACRO_PATH_INCREMENT_WTAIL(_route);
1104 _route.wtail->point = _route.tail;
1106 = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
1113 hildon_note_new_confirmation(GTK_WINDOW(dialog),
1115 ("Creating a \"waypoint\" with no description actually "
1116 "adds a break point. Is that what you want?"));
1118 if (GTK_RESPONSE_OK ==
1119 gtk_dialog_run(GTK_DIALOG(confirm))) {
1120 /* There's no description. Add a break by adding a (0, 0)
1121 * point (if necessary), and then the ordinary route point. */
1122 if (_route.tail->unity) {
1123 MACRO_PATH_INCREMENT_TAIL(_route);
1124 *_route.tail = _point_null;
1127 MACRO_PATH_INCREMENT_TAIL(_route);
1128 _route.tail->unitx = unitx;
1129 _route.tail->unity = unity;
1130 _route.tail->time = 0;
1131 _route.tail->altitude = NAN;
1133 gtk_widget_destroy(confirm);
1135 gtk_widget_destroy(confirm);
1140 route_find_nearest_point();
1142 MACRO_QUEUE_DRAW_AREA();
1145 gtk_widget_destroy(dialog);
1146 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1149 gboolean cmenu_cb_loc_show_latlon(GtkAction * action)
1151 printf("%s()\n", __PRETTY_FUNCTION__);
1153 cmenu_show_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1155 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1159 gboolean cmenu_cb_loc_clip_latlon(GtkAction * action)
1161 printf("%s()\n", __PRETTY_FUNCTION__);
1163 cmenu_clip_latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1165 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1169 gboolean cmenu_cb_loc_route_to(GtkAction * action)
1171 printf("%s()\n", __PRETTY_FUNCTION__);
1173 cmenu_route_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1175 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1179 gboolean cmenu_cb_loc_distance_to(GtkAction * action)
1181 printf("%s()\n", __PRETTY_FUNCTION__);
1183 cmenu_distance_to(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1185 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1189 gboolean cmenu_cb_loc_add_route(GtkAction * action)
1191 printf("%s()\n", __PRETTY_FUNCTION__);
1193 cmenu_add_route(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1195 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1199 gboolean cmenu_cb_loc_add_way(GtkAction * action)
1201 printf("%s()\n", __PRETTY_FUNCTION__);
1203 cmenu_route_add_way(x2unit(_cmenu_position_x),
1204 y2unit(_cmenu_position_y));
1206 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1210 gboolean cmenu_cb_loc_add_poi(GtkAction * action)
1212 printf("%s()\n", __PRETTY_FUNCTION__);
1214 poi_dialog(ACTION_ADD_POI,
1215 x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1217 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1221 gboolean cmenu_cb_loc_set_gps(GtkAction * action)
1223 printf("%s()\n", __PRETTY_FUNCTION__);
1225 _pos.unitx = x2unit(_cmenu_position_x);
1226 _pos.unity = y2unit(_cmenu_position_y);
1227 unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
1229 /* Move mark to new location. */
1232 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1236 gboolean cmenu_cb_way_show_latlon(GtkAction * action)
1239 printf("%s()\n", __PRETTY_FUNCTION__);
1241 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1242 y2unit(_cmenu_position_y))))
1243 cmenu_show_latlon(way->point->unitx, way->point->unity);
1245 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1249 gboolean cmenu_cb_way_show_desc(GtkAction * action)
1252 printf("%s()\n", __PRETTY_FUNCTION__);
1254 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1255 y2unit(_cmenu_position_y)))) {
1256 MACRO_BANNER_SHOW_INFO(_window, way->desc);
1259 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1263 gboolean cmenu_cb_way_clip_latlon(GtkAction * action)
1266 printf("%s()\n", __PRETTY_FUNCTION__);
1268 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1269 y2unit(_cmenu_position_y))))
1270 cmenu_clip_latlon(way->point->unitx, way->point->unity);
1272 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1276 gboolean cmenu_cb_way_clip_desc(GtkAction * action)
1279 printf("%s()\n", __PRETTY_FUNCTION__);
1281 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1282 y2unit(_cmenu_position_y))))
1283 gtk_clipboard_set_text(gtk_clipboard_get
1284 (GDK_SELECTION_CLIPBOARD), way->desc,
1287 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1291 gboolean cmenu_cb_way_route_to(GtkAction * action)
1294 printf("%s()\n", __PRETTY_FUNCTION__);
1296 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1297 y2unit(_cmenu_position_y))))
1298 cmenu_route_to(way->point->unitx, way->point->unity);
1300 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1304 gboolean cmenu_cb_way_distance_to(GtkAction * action)
1307 printf("%s()\n", __PRETTY_FUNCTION__);
1309 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1310 y2unit(_cmenu_position_y))))
1311 route_show_distance_to(way->point);
1313 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1317 gboolean cmenu_cb_way_delete(GtkAction * action)
1320 printf("%s()\n", __PRETTY_FUNCTION__);
1322 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1323 y2unit(_cmenu_position_y)))) {
1324 gchar buffer[BUFFER_SIZE];
1327 snprintf(buffer, sizeof(buffer), "%s:\n%s\n",
1328 _("Confirm delete of waypoint"), way->desc);
1330 hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
1332 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
1333 Point *pdel_min, *pdel_max, *pdel_start, *pdel_end;
1336 /* Delete surrounding route data, too. */
1337 if (way == _route.whead)
1338 pdel_min = _route.head;
1340 pdel_min = way[-1].point;
1342 if (way == _route.wtail)
1343 pdel_max = _route.tail;
1345 pdel_max = way[1].point;
1347 /* Find largest continuous segment around the waypoint, EXCLUDING
1348 * pdel_min and pdel_max. */
1349 for (pdel_start = way->point - 1; pdel_start->unity
1350 && pdel_start > pdel_min; pdel_start--) {
1352 for (pdel_end = way->point + 1; pdel_end->unity
1353 && pdel_end < pdel_max; pdel_end++) {
1356 /* If pdel_end is set to _route.tail, and if _route.tail is a
1357 * non-zero point, then delete _route.tail. */
1358 if (pdel_end == _route.tail && pdel_end->unity)
1359 pdel_end++; /* delete _route.tail too */
1360 /* else, if *both* endpoints are zero points, delete one. */
1361 else if (!pdel_start->unity && !pdel_end->unity)
1364 /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
1365 num_del = pdel_end - pdel_start - 1;
1367 memmove(pdel_start + 1, pdel_end,
1368 (_route.tail - pdel_end + 1) * sizeof(Point));
1369 _route.tail -= num_del;
1371 /* Remove waypoint and move/adjust subsequent waypoints. */
1373 while (way++ != _route.wtail) {
1375 way[-1].point -= num_del;
1379 route_find_nearest_point();
1382 gtk_widget_destroy(confirm);
1385 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1389 gboolean cmenu_cb_way_add_poi(GtkAction * action)
1392 printf("%s()\n", __PRETTY_FUNCTION__);
1394 if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x),
1395 y2unit(_cmenu_position_y))))
1396 poi_dialog(ACTION_ADD_POI, way->point->unitx,
1399 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1403 gboolean cmenu_cb_poi_route_to(GtkAction * action)
1406 printf("%s()\n", __PRETTY_FUNCTION__);
1409 (x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1411 latlon2unit(poi.lat, poi.lon, unitx, unity);
1412 cmenu_route_to(unitx, unity);
1415 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1419 gboolean cmenu_cb_poi_distance_to(GtkAction * action)
1422 printf("%s()\n", __PRETTY_FUNCTION__);
1425 (x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1427 latlon2unit(poi.lat, poi.lon, unitx, unity);
1428 cmenu_distance_to(unitx, unity);
1431 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1435 gboolean cmenu_cb_poi_add_route(GtkAction * action)
1438 printf("%s()\n", __PRETTY_FUNCTION__);
1441 (x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1443 latlon2unit(poi.lat, poi.lon, unitx, unity);
1444 cmenu_add_route(unitx, unity);
1447 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1451 gboolean cmenu_cb_poi_add_way(GtkAction * action)
1454 printf("%s()\n", __PRETTY_FUNCTION__);
1457 (x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
1459 latlon2unit(poi.lat, poi.lon, unitx, unity);
1460 cmenu_route_add_way(unitx, unity);
1463 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1467 gboolean cmenu_cb_poi_edit_poi(GtkAction * action)
1469 printf("%s()\n", __PRETTY_FUNCTION__);
1471 poi_dialog(ACTION_EDIT_POI,
1472 x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
1474 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);