From 7a3a9c2ee53ce5c64e821fce9edf39600bf4e0c3 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Wed, 27 Jun 2007 16:27:25 +0300 Subject: [PATCH] Fix route save. Move save operation from cb.c to route.c --- src/cb.c | 10 +--------- src/route.c | 57 ++++++++++++++++++++++++++++++++--------------------- src/route.h | 5 +++++ 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/cb.c b/src/cb.c index 6d8a0e9..aa08bdb 100644 --- a/src/cb.c +++ b/src/cb.c @@ -194,17 +194,9 @@ gboolean menu_cb_track_distfirst(GtkAction * action) gboolean menu_cb_route_save(GtkAction * action) { - GnomeVFSHandle *handle; printf("%s()\n", __PRETTY_FUNCTION__); - if (open_file(NULL, &handle, NULL, &_route_dir_uri, NULL, - GTK_FILE_CHOOSER_ACTION_SAVE)) { - if (write_gpx(&_route, handle)) { - MACRO_BANNER_SHOW_INFO(_window, _("Route Saved")); - } else - popup_error(_window, _("Error writing GPX file.")); - gnome_vfs_close(handle); - } + route_save(); vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); return TRUE; diff --git a/src/route.c b/src/route.c index 48b7bd4..55e406d 100644 --- a/src/route.c +++ b/src/route.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -16,8 +17,6 @@ #include #include #include -#include -#include #include "utils.h" #include "gps.h" @@ -43,25 +42,40 @@ struct _OriginToggleInfo { gboolean route_open_file() { - gchar *buffer; - gint size; - - if (open_file(&buffer, NULL, &size, &_route_dir_uri, NULL, - GTK_FILE_CHOOSER_ACTION_OPEN)) { - /* If auto is enabled, append the route, otherwise replace it. */ - if (parse_gpx(&_route, buffer, size, - _autoroute_data.enabled ? 0 : 1)) { - cancel_autoroute(FALSE); +gchar *buffer; +gint size; + +if (open_file(&buffer, NULL, &size, &_route_dir_uri, NULL, GTK_FILE_CHOOSER_ACTION_OPEN)) { + /* If auto is enabled, append the route, otherwise replace it. */ + if (parse_gpx(&_route, buffer, size, _autoroute_data.enabled ? 0 : 1)) { + cancel_autoroute(FALSE); + + /* Find the nearest route point, if we're connected. */ + route_find_nearest_point(); + + map_force_redraw(); + MACRO_BANNER_SHOW_INFO(_window, _("Route Opened")); + } else + popup_error(_window, _("Error parsing GPX file.")); + g_free(buffer); +} +} - /* Find the nearest route point, if we're connected. */ - route_find_nearest_point(); +gboolean +route_save(void) +{ +GnomeVFSHandle *handle; - map_force_redraw(); - MACRO_BANNER_SHOW_INFO(_window, _("Route Opened")); - } else - popup_error(_window, _("Error parsing GPX file.")); - g_free(buffer); +if (file_save(_route_dir_uri, _route_dir_uri, &handle)) { + if (write_gpx(&_route, handle)) { + MACRO_BANNER_SHOW_INFO(_window, _("Route Saved")); + } else { + popup_error(_window, _("Error writing GPX file.")); } + gnome_vfs_close(handle); + return TRUE; +} +return FALSE; } gboolean origin_type_selected(GtkWidget * toggle, OriginToggleInfo * oti) @@ -191,15 +205,12 @@ gboolean auto_route_dl_idle() #ifdef WITH_HILDON if (_iap_connected && !_curl_sid) - _curl_sid = g_timeout_add(100, - (GSourceFunc) curl_download_timeout, - NULL); #else if (!_curl_sid) +#endif _curl_sid = g_timeout_add(100, (GSourceFunc) curl_download_timeout, NULL); -#endif _autoroute_data.in_progress = TRUE; @@ -487,7 +498,7 @@ gboolean route_download(gchar * to) return TRUE; } -WayPoint *find_nearest_waypoint(guint unitx, guint unity, guint _zoom) +WayPoint *find_nearest_waypoint(guint unitx, guint unity) { WayPoint *wcurr; WayPoint *wnear; diff --git a/src/route.h b/src/route.h index f83178c..448a29b 100644 --- a/src/route.h +++ b/src/route.h @@ -43,6 +43,11 @@ guint64 _next_wpt_dist_squared; /** The singleton auto-route-download data. */ AutoRouteDownloadData _autoroute_data; +gboolean route_open_file(); +gboolean route_save(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); #endif -- 2.39.5