]> err.no Git - mapper/commitdiff
Route, track and menu changes.
authorKaj-Michael Lang <milang@onion.tal.org>
Thu, 13 Mar 2008 12:55:56 +0000 (14:55 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Thu, 13 Mar 2008 12:55:56 +0000 (14:55 +0200)
Move route specific operations from track.c to route.c,
handle waypoint announce check in gps position cb.
Move poi search menu enty under Poi menu.

src/cb.c
src/route.c
src/route.h
src/track.c
src/track.h
src/ui-common.c

index 17dc91fc838a56a03c0bb6dce6827760d483ce1a..4a0c3945dce0a7c27754b6a19ed2dcb54e1b8bc8 100644 (file)
--- a/src/cb.c
+++ b/src/cb.c
@@ -152,8 +152,11 @@ return TRUE;
 gboolean 
 menu_cb_track_insert_mark(GtkAction * action)
 {
-track_insert_mark();
-path_tree_view_update_store(track_tree_view, &_track);
+if (track_insert_mark()) {
+       map_render_paths();
+       MACRO_QUEUE_DRAW_AREA();
+       path_tree_view_update_store(track_tree_view, &_track);
+}
 return TRUE;
 }
 
@@ -1079,9 +1082,9 @@ _gps->data.unity = y2unit(_cmenu_position_y);
 unit2latlon(_gps->data.unitx, _gps->data.unity, _gps->data.lat, _gps->data.lon);
 
 /* Move mark to new location. */
-map_refresh_mark();
 _gps->data.time=time(NULL);
 track_add(&_gps->data);
+map_refresh_mark();
 
 return TRUE;
 }
index 3144f60650eddf3a704738d10bfd6e6e75ed2d40..8c61c36f763100a8f3e81d621c832845cad2f6aa 100644 (file)
    ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\
   + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity)))
 
-void route_find_nearest_point(void);
-void cancel_autoroute(gboolean temporary);
-void route_show_distance_to_last(void);
-void route_set_destination_from_last(void);
+static gboolean show_directions=TRUE;
 
 typedef struct _OriginToggleInfo OriginToggleInfo;
 struct _OriginToggleInfo {
@@ -50,6 +47,11 @@ struct _OriginToggleInfo {
        GtkWidget *txt_to;
 };
 
+void route_find_nearest_point(void);
+void route_cancel_autoroute(gboolean temporary);
+void route_show_distance_to_last(void);
+void route_set_destination_from_last(void);
+
 void
 route_init(void)
 {
@@ -71,7 +73,7 @@ GtkWidget *confirm;
 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), _("Really clear the route?"));
 
 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
-       cancel_autoroute(FALSE);
+       route_cancel_autoroute(FALSE);
        route_deinit();
        route_init();
        route_find_nearest_point();
@@ -81,6 +83,37 @@ _dest.valid=FALSE;
 gtk_widget_destroy(confirm);
 }
 
+/**
+ * Check if we should announce upcoming waypoints. 
+ */
+void
+route_check_waypoint_announce(GpsData *gps)
+{
+guint announce_thres_unsquared;
+
+if (!gps)
+       return;
+
+announce_thres_unsquared=(20+(guint)gps->speed)*_announce_notice_ratio*3;
+
+if (_next_way_dist_squared < (announce_thres_unsquared * announce_thres_unsquared))
+       announce_waypoint(_next_way->desc);
+}
+
+/**
+ * Check if we should re-calculate route
+ */
+void
+route_autoroute_check(void)
+{
+if (_autoroute_data.enabled && !_autoroute_data.in_progress && _near_point_dist_squared > 400) {
+       MACRO_BANNER_SHOW_INFO(_window, _("Recalculating directions..."));
+       _autoroute_data.in_progress = TRUE;
+       show_directions = FALSE;
+       g_idle_add((GSourceFunc)auto_route_dl_idle, NULL);
+}
+}
+
 gboolean 
 route_open_file(void)
 {
@@ -90,7 +123,7 @@ gint size;
 if (file_open_get_contents(&_route_dir_uri, &buffer, &size)) {
        /* If auto is enabled, append the route, otherwise replace it. */
        if (parse_gpx(&_route, buffer, size, _autoroute_data.enabled ? 0 : 1)) {
-               cancel_autoroute(FALSE);
+               route_cancel_autoroute(FALSE);
 
                MACRO_BANNER_SHOW_INFO(_window, _("Route Opened"));
                /* Find the nearest route point, if we're connected. */
@@ -169,7 +202,7 @@ return TRUE;
  * Cancel the current auto-route.
  */
 void 
-cancel_autoroute(gboolean temporary)
+route_cancel_autoroute(gboolean temporary)
 {
 if (_autoroute_data.enabled) {
        if (!temporary) {
@@ -437,7 +470,7 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
                route_find_nearest_point();
 
                /* Cancel any autoroute that might be occurring. */
-               cancel_autoroute(FALSE);
+               route_cancel_autoroute(FALSE);
 
                map_force_redraw();
 
index 2cba12a5e064ccc69b937c10c0f3521e210efd01..31a65bfe1245953edd009d558fdbd2be099520d2 100644 (file)
@@ -45,13 +45,20 @@ void route_deinit(void);
 
 gboolean route_open_file(void);
 gboolean route_save(void);
+gboolean route_download(gchar * to);
 void route_clear(void);
+
+void route_check_waypoint_announce(GpsData *gps);
+void route_autoroute_check(void);
+
 gboolean auto_route_dl_idle();
-gboolean route_download(gchar * to);
+
 WayPoint *find_nearest_waypoint(guint unitx, guint unity);
+
 gboolean route_update_nears(gboolean quick);
+
+gboolean route_show_distance_to(Point * point);
 void route_show_distance_to_last();
 void route_show_distance_to_next();
-gboolean route_show_distance_to(Point * point);
 
 #endif
index db223f8b3b04f0092d5875e3fcc73d921d9cd1b6..c1797ac832d6d8ca625d166d0e8e88ffbd560daa 100644 (file)
@@ -28,6 +28,9 @@ struct sql_select_stmt {
 };
 static struct sql_select_stmt sql;
 
+/* Add sensitivity */
+static gint sensitivity=3;
+
 void
 track_init(void)
 {
@@ -116,29 +119,22 @@ if (_track.head != _track.tail) {
 }
 
 /**
- * Add a point to the _track list.  This function is slightly overloaded,
- * since it is what houses the check for "have we moved
- * significantly": it also initiates the re-calculation of the _near_point
- * data, as well as calling osso_display_state_on() when we have the focus.
+ * Add a point to the _track list.
  *
- * If a non-zero time is given, then the current position (as taken from the
- * _gps variable) is appended to _track with the given time.  If time is zero,
- * then _point_null is appended to _track with time zero (this produces a "break"
- * in the track).
+ * If a non-null gps is given, then the current position is appended 
+ * to _track with the given time.  If gps is null, then _point_null is 
+ * appended to _track with time zero (this produces a "break" in the track).
  */
-void 
+gboolean
 track_add(GpsData *gps)
 {
-gboolean show_directions = TRUE;
-gint announce_thres_unsquared;
-
 if (!gps) {
        MACRO_PATH_INCREMENT_TAIL(_track);
        *_track.tail=_point_null;
-       return;
+       return FALSE;
 }
 
-if (abs((gint)gps->unitx-_track.tail->unitx) > _draw_width || abs((gint)gps->unity-_track.tail->unity) > _draw_width) {
+if (abs((gint)gps->unitx-_track.tail->unitx) > sensitivity || abs((gint)gps->unity-_track.tail->unity) > sensitivity) {
 
        /* If gps is available, update the nearest-waypoint data. */
        if (gps && _route.head != _route.tail && (gps->newly_fixed ? (route_find_nearest_point(), TRUE) : route_update_nears(TRUE))) {
@@ -152,8 +148,8 @@ if (abs((gint)gps->unitx-_track.tail->unitx) > _draw_width || abs((gint)gps->uni
 
                /* Instead of calling map_render_paths(), we'll draw the new line
                 * ourselves and call gtk_widget_queue_draw_area(). */
-               map_render_segment(_gc[COLORABLE_TRACK], _gc[COLORABLE_TRACK_BREAK],
-                                       _track.tail->unitx, _track.tail->unity, gps->unitx, gps->unity);
+               map_render_segment(_gc[COLORABLE_TRACK], _gc[COLORABLE_TRACK_BREAK], 
+                       _track.tail->unitx, _track.tail->unity, gps->unitx, gps->unity);
 
                if (_track.tail->unity && _track.tail->unitx) {
                        tx1 = unit2x(_track.tail->unitx);
@@ -192,27 +188,9 @@ if (abs((gint)gps->unitx-_track.tail->unitx) > _draw_width || abs((gint)gps->uni
        _track.points++;
 }
 
-if (_autoroute_data.enabled && !_autoroute_data.in_progress && _near_point_dist_squared > 400) {
-       MACRO_BANNER_SHOW_INFO(_window, _("Recalculating directions..."));
-       _autoroute_data.in_progress = TRUE;
-       show_directions = FALSE;
-       g_idle_add((GSourceFunc)auto_route_dl_idle, NULL);
-}
-
-announce_thres_unsquared=(20+(guint)gps->speed)*_announce_notice_ratio*3;
-
-/* Check if we should announce upcoming waypoints. */
-if (gps && show_directions && _next_way_dist_squared < (announce_thres_unsquared * announce_thres_unsquared)) {
-       if (_enable_voice && strcmp(_next_way->desc, _last_spoken_phrase)) {
-               g_free(_last_spoken_phrase);
-               _last_spoken_phrase=g_strdup(_next_way->desc);
-               speak_text(_last_spoken_phrase);
-       }
-       MACRO_BANNER_SHOW_INFO(_window, _next_way->desc);
-}
-
 /* Keep the display on if we are moving. */
 KEEP_DISPLAY_ON();
+return TRUE;
 }
 
 gboolean 
@@ -289,13 +267,13 @@ GtkWidget *table;
 GtkWidget *label;
 GtkWidget *txt_scroll;
 GtkWidget *txt_desc;
+gboolean ret;
 
 dialog = gtk_dialog_new_with_buttons(_("Insert Mark"),
-                                    GTK_WINDOW(_window),
-                                    GTK_DIALOG_MODAL, GTK_STOCK_OK,
-                                    GTK_RESPONSE_ACCEPT,
-                                    GTK_STOCK_CANCEL,
-                                    GTK_RESPONSE_REJECT, NULL);
+                                       GTK_WINDOW(_window), GTK_DIALOG_MODAL, 
+                                       GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+                                       GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, 
+                                       NULL);
 
 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
 
@@ -323,10 +301,11 @@ txt_desc = gtk_text_view_new();
 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
 
 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
-gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 450, 80);
+gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 450, 100);
 
 gtk_widget_show_all(dialog);
 
+ret=FALSE;
 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
        GtkTextBuffer *tbuf;
        GtkTextIter ti1, ti2;
@@ -342,10 +321,9 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
                continue;
        }
 
-       map_render_paths();
-       MACRO_QUEUE_DRAW_AREA();
+       ret=TRUE;
        break;
 }
 gtk_widget_destroy(dialog);
-return TRUE;
+return ret;
 }
index 5bba3a3e0e29019b29a1e5cf4788cd1504a74b72..ffd179e75351d7c180f77da992429b7dde892413 100644 (file)
@@ -26,7 +26,7 @@ struct {
 void track_init(void);
 void track_deinit(void);
 
-void track_add(GpsData *gps);
+gboolean track_add(GpsData *gps);
 gboolean track_insert_break(void);
 gboolean track_insert_mark(void);
 gboolean track_save(void);
index 821c9ab14774cc012e9a044625efe3ce24acee6e..eded8ba460cbadf2a8ea5396d9c6a04d87c3355e 100644 (file)
@@ -58,10 +58,10 @@ static GtkActionGroup *map_repos_action_group;
 static GtkUIManager *ui;
 
 struct ui_notebook_struct {
-    GtkWidget *notebook;
-    gint map;
-    gint gps;
-    gint heading;
+       GtkWidget *notebook;
+       gint map;
+       gint gps;
+       gint heading;
        gint route;
        gint track;
        gint qpoi;
@@ -116,7 +116,6 @@ static const gchar *mapper_ui =
 "     </menu>"
 "    </menu>"
 "    <menu action='search'>"
-"      <menuitem action='poi_search'/>"
 "      <menuitem action='search_address'/>"
 "    </menu>"
 "    <menu action='track'>"
@@ -145,6 +144,7 @@ static const gchar *mapper_ui =
 "    </menu>"
 "    <menu action='poi'>"
 "      <menuitem action='poi_categories'/>"
+"      <menuitem action='poi_search'/>"
 #if 0
 "      <separator/>"
 "      <menuitem action='poi_import'/>"
@@ -256,11 +256,11 @@ static GtkActionEntry ui_entries[] = {
        {"poi_settings", GTK_STOCK_PREFERENCES, N_("_Settings..."), NULL, NULL, NULL },
        {"poi_add", GTK_STOCK_ADD, N_("_Add"), "<control>A", NULL, G_CALLBACK(cb_poi_add) },
        {"poi_quick_add", GTK_STOCK_ABOUT, N_("_Quick Add"), "<control>E", NULL, G_CALLBACK(cb_poi_add) },
+       {"poi_search", GTK_STOCK_FIND, N_("_Search..."), NULL, NULL, G_CALLBACK(cb_poi_search) },
        {"poi_import", GTK_STOCK_OPEN, N_("_Import..."), NULL, NULL, NULL },
        {"poi_export", GTK_STOCK_SAVE, N_("_Export..."), NULL, NULL, NULL },
 
        {"search", NULL, N_("_Search"), NULL, NULL, NULL },
-       {"poi_search", GTK_STOCK_FIND, N_("_Search..."), "<control>P", NULL, G_CALLBACK(cb_poi_search) },
        {"search_address", GTK_STOCK_FIND, N_("Address..."), "<control>F", NULL, G_CALLBACK(menu_cb_search_address) },
 
        {"map", NULL, N_("_Map"), NULL, NULL, NULL },
@@ -805,7 +805,10 @@ gps_location_update(Gps *gps)
 {
 g_assert(gps);
 if (filter_check(&filter, &gps->data, &map_loc)==TRUE) {
-       track_add(&_gps->data);
+       if (track_add(&_gps->data)) {
+               route_check_waypoint_announce(&_gps->data);
+               route_autoroute_check();
+       }
        map_refresh_mark();
 }
 return FALSE;