]> err.no Git - mapper/commitdiff
Add a enum for the gpx path prepend/append/new modes instead of arbitrary numbers.
authorKaj-Michael Lang <milang@tal.org>
Wed, 19 Mar 2008 14:12:36 +0000 (16:12 +0200)
committerKaj-Michael Lang <milang@tal.org>
Wed, 19 Mar 2008 14:12:36 +0000 (16:12 +0200)
src/config-gconf.c
src/gpx.c
src/gpx.h
src/route.c
src/track.c

index 8d7cfd4a430fe41b0a7599d5aedb8a244ad1b084..87864d47e4e05b72595bf7f91d129fc7b8df9149 100644 (file)
@@ -426,7 +426,7 @@ gint size;
 
 pfile = gnome_vfs_uri_make_full_from_relative(config_dir, file);
 if (GNOME_VFS_OK == gnome_vfs_read_entire_file(pfile, &size, &bytes))
-       gpx_parse(path, bytes, size, 0);        /* 0 to replace track. */
+       gpx_parse(path, bytes, size, GPX_PATH_NEW);
 g_free(pfile);
 }
 
index 2b8ef15a0f60df2675f75864a5090ae97eccfea3..6a60b2539a0cfdc10f178e5420afbd390b12a70a 100644 (file)
--- a/src/gpx.c
+++ b/src/gpx.c
@@ -497,8 +497,14 @@ va_end(args);
 data->state = ERROR;
 }
 
+/**
+ * Parse a buffer of GPX data.
+ *
+ * XXX: Add support for parsing directly from file if the file is local.
+ *
+ */
 gboolean
-gpx_parse(Path *to_replace, gchar *buffer, gint size, gint policy_old)
+gpx_parse(Path *path, gchar *buffer, gint size, gpx_path_policy policy)
 {
 SaxData data;
 xmlSAXHandler sax_handler;
@@ -517,28 +523,32 @@ sax_handler.error = (errorSAXFunc) gpx_error;
 sax_handler.fatalError = (fatalErrorSAXFunc) gpx_error;
 
 xmlSAXUserParseMemory(&sax_handler, &data, buffer, size);
+
 g_string_free(data.chars, TRUE);
 
 if (data.state != FINISH) {
-       g_debug("GPX: Parser stopped in error state %d", data.state);
+       g_warning("GPX: Parser stopped in error state %d", data.state);
        return FALSE;
 }
 
-if (policy_old && to_replace->head != to_replace->tail) {
+switch (policy) {
+case GPX_PATH_APPEND:
+case GPX_PATH_PREPEND:
+       {
        Point *src_first;
        Path *src, *dest;
 
-       if (policy_old > 0) {
+       if (policy==GPX_PATH_APPEND) {
                /* Append to current path. Make sure last path point is zero. */
-               if (to_replace->tail->unity != 0) {
-                       MACRO_PATH_INCREMENT_TAIL((*to_replace));
-                       *to_replace->tail = _point_null;
+               if (path->tail->unity != 0) {
+                       MACRO_PATH_INCREMENT_TAIL((*path));
+                       *path->tail = _point_null;
                }
                src = &data.path;
-               dest = to_replace;
+               dest = path;
        } else {
                /* Prepend to current route. */
-               src = to_replace;
+               src = path;
                dest = &data.path;
        }
 
@@ -573,14 +583,20 @@ if (policy_old && to_replace->head != to_replace->tail) {
         * would free the string desc's that we just moved to data.route. */
        g_free(src->head);
        g_free(src->whead);
-       if (policy_old < 0)
-               (*to_replace) = *dest;
-} else {
-       MACRO_PATH_FREE((*to_replace));
+       if (policy==GPX_PATH_PREPEND)
+               (*path) = *dest;
+       }
+break;
+case GPX_PATH_NEW:
        /* Overwrite with data.route. */
-       (*to_replace) = data.path;
-       path_resize(to_replace, to_replace->tail - to_replace->head + 1);
-       path_wresize(to_replace, to_replace->wtail - to_replace->whead + 1);
+       MACRO_PATH_FREE((*path));
+       (*path) = data.path;
+       path_resize(path, path->tail - path->head + 1);
+       path_wresize(path, path->wtail - path->whead + 1);
+break;
+default:
+       g_assert_not_reached();
+break;
 }
 
 return TRUE;
index d6c5e5d03ca0e94c0da0801cda1d933fdb1e7407..d117b9db7fac6cb916f635b1fe8d3aaed919e3c5 100644 (file)
--- a/src/gpx.h
+++ b/src/gpx.h
@@ -5,8 +5,14 @@
 #include <libgnomevfs/gnome-vfs.h>
 #include "path.h"
 
+typedef enum {
+       GPX_PATH_PREPEND=-1,
+       GPX_PATH_NEW=0,
+       GPX_PATH_APPEND=1,
+} gpx_path_policy;
+
 void gpx_init(void);
 gboolean gpx_write(Path *path, GnomeVFSHandle *handle);
-gboolean gpx_parse(Path *to_replace, gchar *buffer, gint size, gint policy_old);
+gboolean gpx_parse(Path *to_replace, gchar *buffer, gint size, gpx_path_policy policy);
 
 #endif
index 3571922ce99030cf250b9f4d9a29680df2caf30d..7c54e87fedbb93b9b25be2947d9f37e8f05c5b1e 100644 (file)
@@ -109,7 +109,7 @@ gint size;
 
 if (file_open_get_contents(_route_dir_uri, &buffer, &size)) {
        /* If auto is enabled, append the route, otherwise replace it. */
-       if (gpx_parse(_route, buffer, size, _autoroute_data.enabled ? 0 : 1)) {
+       if (gpx_parse(_route, buffer, size, _autoroute_data.enabled ? GPX_PATH_APPEND : GPX_PATH_NEW)) {
                route_cancel_autoroute(FALSE);
 
                MACRO_BANNER_SHOW_INFO(_window, _("Route Opened"));
@@ -446,16 +446,13 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
 
        if (strncmp(rdl_data.bytes, "<?xml", strlen("<?xml"))) {
                /* Not an XML document - must be bad locations. */
-               popup_error(dialog,
-                           _("Could not generate directions. Make sure your "
-                            "source and destination are valid."));
+               popup_error(dialog, _("Could not generate directions. Make sure your source and destination are valid."));
                g_free(rdl_data.bytes);
                /* Let them try again. */
        }
        /* Else, if GPS is enabled, replace the route, otherwise append it. */
        else if (gpx_parse(_route, rdl_data.bytes, rdl_data.bytes_read,
-                          (gtk_toggle_button_get_active
-                           (GTK_TOGGLE_BUTTON(oti.rad_use_gps)) ? 0 : 1))) {
+                       (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oti.rad_use_gps)) ? GPX_PATH_NEW : GPX_PATH_APPEND))) {
                GtkTreeIter iter;
 
                /* Find the nearest route point, if we're connected. */
@@ -466,8 +463,7 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
 
                map_force_redraw();
 
-               if (gtk_toggle_button_get_active
-                   (GTK_TOGGLE_BUTTON(oti.chk_auto))) {
+               if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oti.chk_auto))) {
                        /* Kick off a timeout to start the first update. */
                        _autoroute_data.dest = gnome_vfs_escape_string(to);
                        _autoroute_data.enabled = TRUE;
index b075c2e79f1aa8da5160a86120b177e03105f99c..cff382bbcfecca5b573da755741d08d35a9df177 100644 (file)
@@ -209,7 +209,7 @@ gint size;
 gboolean r = FALSE;
 
 if (file_open_get_contents(&_track_file_uri, &buffer, &size)) {
-       if (gpx_parse(_track, buffer, size, -1)) {
+       if (gpx_parse(_track, buffer, size, GPX_PATH_NEW)) {
                map_force_redraw();
                MACRO_BANNER_SHOW_INFO(_window, _("Track Opened"));
                r = TRUE;