From ae941b4ce94b5dce4b3dec1cc39ced042d2e3c41 Mon Sep 17 00:00:00 2001 From: Harry G McGavran Jr Date: Fri, 18 Sep 2009 22:45:06 +0200 Subject: [PATCH] Fix magic scissors Searching the gpsbabel lists, there are some posts that the maps.google.com "output=js" has changed and gpsbabel types have had a hard time keeping up with the changes at maps.google.com. One suggestion was to use "output=kml" at maps.google.com and the input_type "kml" instead of "google" in gpsbabel. --- src/babel.c | 2 +- src/datasource_google.c | 4 ++-- src/download.c | 30 ++++++++++++++++++++++++++++++ src/download.h | 1 + src/viktrwlayer.c | 4 ++-- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/babel.c b/src/babel.c index 63b1ea58..50c90f74 100644 --- a/src/babel.c +++ b/src/babel.c @@ -276,7 +276,7 @@ gboolean a_babel_convert_from_shellcommand ( VikTrwLayer *vt, const char *input_ gboolean a_babel_convert_from_url ( VikTrwLayer *vt, const char *url, const char *input_type, BabelStatusFunc cb, gpointer user_data ) { - static DownloadOptions options = {NULL, 0, a_check_html_file}; + static DownloadOptions options = {NULL, 0, a_check_kml_file}; gint fd_src; int fetch_ret; gboolean ret = FALSE; diff --git a/src/datasource_google.c b/src/datasource_google.c index 11c567dc..08c6e942 100644 --- a/src/datasource_google.c +++ b/src/datasource_google.c @@ -31,7 +31,7 @@ #include "gpx.h" #include "acquire.h" -#define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s+to:%s&output=js" +#define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s+to:%s&output=kml" typedef struct { GtkWidget *from_entry, *to_entry; @@ -100,7 +100,7 @@ static void datasource_google_get_cmd_string ( datasource_google_widgets_t *widg to_quoted = g_strjoinv( "%20", to_split); *cmd = g_strdup_printf( GOOGLE_DIRECTIONS_STRING, from_quoted, to_quoted ); - *input_file_type = g_strdup("google"); + *input_file_type = g_strdup("kml"); g_free(last_from_str); g_free(last_to_str); diff --git a/src/download.c b/src/download.c index 27b123f2..9aefb479 100644 --- a/src/download.c +++ b/src/download.c @@ -72,6 +72,36 @@ gboolean a_check_map_file(FILE* f) return !a_check_html_file(f); } +gboolean a_check_kml_file(FILE* f) +{ + gchar **s; + gchar *bp; + fpos_t pos; + gchar buf[33]; + size_t nr; + gchar * html_str[] = { + " (bp - buf)); bp++) { + if (!(isspace(*bp))) + break; + } + if ((bp >= (buf + sizeof(buf) -1)) || ((bp - buf) >= nr)) + return FALSE; + for (s = html_str; *s; s++) { + if (strncasecmp(*s, bp, strlen(*s)) == 0) + return TRUE; + } + return FALSE; +} + static int download( const char *hostname, const char *uri, const char *fn, DownloadOptions *options, gboolean ftp) { FILE *f; diff --git a/src/download.h b/src/download.h index 7c1eb847..f4aa8df5 100644 --- a/src/download.h +++ b/src/download.h @@ -28,6 +28,7 @@ typedef gboolean (*VikFileContentCheckerFunc) (FILE*); gboolean a_check_map_file(FILE*); gboolean a_check_html_file(FILE*); +gboolean a_check_kml_file(FILE*); typedef struct { /** diff --git a/src/viktrwlayer.c b/src/viktrwlayer.c index f370e7f9..e6089c37 100644 --- a/src/viktrwlayer.c +++ b/src/viktrwlayer.c @@ -71,7 +71,7 @@ static gboolean return_true (gpointer a, gpointer b, gpointer c) { return TRUE; static g_hash_table_remove_all (GHashTable *ght) { g_hash_table_foreach_remove ( ght, (GHRFunc) return_true, FALSE ); } #endif -#define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s,%s+to:%s,%s&output=js" +#define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s,%s+to:%s,%s&output=kml" #define VIK_TRW_LAYER_TRACK_GC 13 #define VIK_TRW_LAYER_TRACK_GC_RATES 10 #define VIK_TRW_LAYER_TRACK_GC_MIN 0 @@ -3653,7 +3653,7 @@ static gboolean tool_magic_scissors_click ( VikTrwLayer *vtl, GdkEventButton *ev g_ascii_dtostr (startlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) start.lon), g_ascii_dtostr (endlat, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lat), g_ascii_dtostr (endlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lon)); - a_babel_convert_from_url ( vtl, url, "google", NULL, NULL ); + a_babel_convert_from_url ( vtl, url, "kml", NULL, NULL ); g_free ( url ); /* see if anything was done -- a track was added or appended to */ -- 2.39.5