From ba4a5e11da0979cdab59ac2e8a157bbaa7835fa7 Mon Sep 17 00:00:00 2001 From: Guilhem Bonnefille Date: Sun, 18 Jan 2009 11:17:26 +0000 Subject: [PATCH] Allow to select between Google and Geonames for searching method --- configure.ac | 22 ++++++++++++++++++++++ src/Makefile.am | 1 + src/dialog.c | 15 ++++++++++++++- src/geonamessearch.c | 22 +--------------------- src/geonamessearch.h | 1 - src/googlesearch.c | 22 +--------------------- src/googlesearch.h | 1 - src/menu.xml.h | 4 ++-- src/util.c | 22 ++++++++++++++++++++++ src/util.h | 2 ++ src/vikwindow.c | 13 ++++++++++++- 11 files changed, 77 insertions(+), 48 deletions(-) diff --git a/configure.ac b/configure.ac index 1cd8a0be..04cee8f5 100644 --- a/configure.ac +++ b/configure.ac @@ -207,6 +207,28 @@ case $ac_cv_enable_realtimegpstracking in esac AM_CONDITIONAL([REALTIME_GPS_TRACKING], [test x$ac_cv_enable_realtimegpstracking = xyes]) +AC_ARG_WITH(search, + [AC_HELP_STRING([--with-search], + [specify google or geonames for searching (default is google)])], + [case "x$withval" in + "xgoogle") + VIK_CONFIG_SEARCH=VIK_CONFIG_SEARCH_GOOGLE + ;; + "xgeonames") + VIK_CONFIG_SEARCH=VIK_CONFIG_SEARCH_GEONAMES + ;; + *) + AC_MSG_ERROR([Please, set a value for search method]) + esac], + [VIK_CONFIG_SEARCH=VIK_CONFIG_SEARCH_GOOGLE]) +AC_DEFINE_UNQUOTED(VIK_CONFIG_SEARCH_GOOGLE, 1, + [Id. for searching via GOOGLE]) +AC_DEFINE_UNQUOTED(VIK_CONFIG_SEARCH_GEONAMES, 2, + [Id. for searching via GEONAMES]) +AC_DEFINE_UNQUOTED(VIK_CONFIG_SEARCH, ${VIK_CONFIG_SEARCH}, + [Method for the search]) + + AC_ARG_WITH(mapcache, [AC_HELP_STRING([--with-mapcache], [specify the size of the map cache (default is 50331648)])], diff --git a/src/Makefile.am b/src/Makefile.am index d12f10bd..af98ec1f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -65,6 +65,7 @@ libviking_a_SOURCES = \ datasource_gc.c \ datasource_bfilter.c \ datasources.h \ + googlesearch.c googlesearch.h \ dem.c dem.h \ vikdemlayer.h vikdemlayer.c \ vikfilelist.c vikfilelist.h \ diff --git a/src/dialog.c b/src/dialog.c index 071092ed..06965fd1 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -28,7 +28,12 @@ #include "garminsymbols.h" #include "degrees_converters.h" #include "authors.h" +#ifdef VIK_CONFIG_GOOGLE +#include "googlesearch.h" +#endif +#ifdef VIK_CONFIG_GEONAMES #include "geonamessearch.h" +#endif #include "util.h" #include @@ -239,7 +244,15 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w commentlabel = gtk_label_new (_("Comment:")); commententry = gtk_entry_new (); - gchar *cmt = a_geonamessearch_get_search_string_for_this_place(VIK_WINDOW(parent)); + gchar *cmt = NULL; +#if defined(VIK_CONFIG_GOOGLE) && VIK_CONFIG_SEARCH==VIK_CONFIG_SEARCH_GOOGLE + //if (strcmp(VIK_CONFIG_SEARCH,"google")) + cmt = a_googlesearch_get_search_string_for_this_place(VIK_WINDOW(parent)); +#endif +#if defined(VIK_CONFIG_GEONAMES) && VIK_CONFIG_SEARCH==VIK_CONFIG_SEARCH_GEONAMES + //if (strcmp(VIK_CONFIG_SEARCH,"geonames")) + cmt = a_geonamessearch_get_search_string_for_this_place(VIK_WINDOW(parent)); +#endif if (cmt) gtk_entry_set_text(GTK_ENTRY(commententry), cmt); diff --git a/src/geonamessearch.c b/src/geonamessearch.c index a9586069..ae58bef8 100644 --- a/src/geonamessearch.c +++ b/src/geonamessearch.c @@ -31,6 +31,7 @@ #include #include "viking.h" +#include "util.h" #include "curl_download.h" #define GEONAMES_WIKIPEDIA_URL_FMT "http://ws.geonames.org/wikipediaBoundingBoxJSON?formatted=true&north=%f&south=%f&east=%f&west=%f" @@ -498,27 +499,6 @@ static int parse_file_for_latlon(VikWindow *vw, gchar *file_name, struct LatLon return (found); } -gchar *uri_escape(gchar *str) -{ - gchar *esc_str = g_malloc(3*strlen(str)); - gchar *dst = esc_str; - gchar *src; - - for (src = str; *src; src++) { - if (*src == ' ') - *dst++ = '+'; - else if (g_ascii_isalnum(*src)) - *dst++ = *src; - else { - g_sprintf(dst, "%%%02X", *src); - dst += 3; - } - } - *dst = '\0'; - - return(esc_str); -} - gchar *download_url(gchar *uri) { FILE *tmp_file; diff --git a/src/geonamessearch.h b/src/geonamessearch.h index b38eab51..d9e1a611 100644 --- a/src/geonamessearch.h +++ b/src/geonamessearch.h @@ -4,7 +4,6 @@ /* Finding a named place */ extern void a_geonames_search(VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp); gchar * a_geonamessearch_get_search_string_for_this_place(VikWindow *vw); -gchar *uri_escape(gchar *str); /* Finding Wikipedia entries within a certain box */ extern void a_geonames_wikipedia_box(VikWindow *vw, VikTrwLayer *vtl, VikLayersPanel *vlp, struct LatLon maxmin[2]); diff --git a/src/googlesearch.c b/src/googlesearch.c index b7c7a729..2e2749de 100644 --- a/src/googlesearch.c +++ b/src/googlesearch.c @@ -31,6 +31,7 @@ #include #include "viking.h" +#include "util.h" #include "curl_download.h" #define GOOGLE_SEARCH_URL_FMT "http://maps.google.com/maps?q=%s&output=js" @@ -179,27 +180,6 @@ done: } -gchar *uri_escape(gchar *str) -{ - gchar *esc_str = g_malloc(3*strlen(str)); - gchar *dst = esc_str; - gchar *src; - - for (src = str; *src; src++) { - if (*src == ' ') - *dst++ = '+'; - else if (g_ascii_isalnum(*src)) - *dst++ = *src; - else { - g_sprintf(dst, "%%%02X", *src); - dst += 3; - } - } - *dst = '\0'; - - return(esc_str); -} - static int google_search_get_coord(VikWindow *vw, VikViewport *vvp, gchar *srch_str, VikCoord *coord) { FILE *tmp_file; diff --git a/src/googlesearch.h b/src/googlesearch.h index 56f89931..9704112f 100644 --- a/src/googlesearch.h +++ b/src/googlesearch.h @@ -3,5 +3,4 @@ extern void a_google_search(VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp); gchar * a_googlesearch_get_search_string_for_this_place(VikWindow *vw); -gchar *uri_escape(gchar *str); #endif diff --git a/src/menu.xml.h b/src/menu.xml.h index f7fe602d..d9cf08fc 100644 --- a/src/menu.xml.h +++ b/src/menu.xml.h @@ -44,7 +44,7 @@ static const char *menu_xml = #endif " " " " - " " + " " " " " " " " @@ -109,7 +109,7 @@ static const char *menu_xml = " " " " " " - " " + " " " " " " " " diff --git a/src/util.c b/src/util.c index 79da8ffc..975fce06 100644 --- a/src/util.c +++ b/src/util.c @@ -88,3 +88,25 @@ void new_email(GtkWindow *parent, const gchar * address) g_free(uri); uri = NULL; } + +gchar *uri_escape(gchar *str) +{ + gchar *esc_str = g_malloc(3*strlen(str)); + gchar *dst = esc_str; + gchar *src; + + for (src = str; *src; src++) { + if (*src == ' ') + *dst++ = '+'; + else if (g_ascii_isalnum(*src)) + *dst++ = *src; + else { + g_sprintf(dst, "%%%02X", *src); + dst += 3; + } + } + *dst = '\0'; + + return(esc_str); +} + diff --git a/src/util.h b/src/util.h index 1766cd4e..8bb12e75 100644 --- a/src/util.h +++ b/src/util.h @@ -30,5 +30,7 @@ void open_url(GtkWindow *parent, const gchar * url); void new_email(GtkWindow *parent, const gchar * address); +gchar *uri_escape(gchar *str); + #endif diff --git a/src/vikwindow.c b/src/vikwindow.c index 46aec3cc..da4b0efa 100644 --- a/src/vikwindow.c +++ b/src/vikwindow.c @@ -27,7 +27,12 @@ #include "background.h" #include "acquire.h" #include "datasources.h" +#ifdef VIK_CONFIG_GOOGLE +#include "googlesearch.h" +#endif +#ifdef VIK_CONFIG_GEONAMES #include "geonamessearch.h" +#endif #include "dems.h" #include "print.h" #include "preferences.h" @@ -1491,7 +1496,13 @@ static void acquire_from_gc ( GtkAction *a, VikWindow *vw ) static void goto_address( GtkAction *a, VikWindow *vw) { +#if defined(VIK_CONFIG_GOOGLE) && VIK_CONFIG_SEARCH==VIK_CONFIG_SEARCH_GOOGLE + a_google_search(vw, vw->viking_vlp, vw->viking_vvp); +#endif +#if defined(VIK_CONFIG_GEONAMES) && VIK_CONFIG_SEARCH==VIK_CONFIG_SEARCH_GEONAMES a_geonames_search(vw, vw->viking_vlp, vw->viking_vvp); +#endif + } static void preferences_cb ( GtkAction *a, VikWindow *vw ) @@ -1958,7 +1969,7 @@ static GtkActionEntry entries[] = { { "Exit", GTK_STOCK_QUIT, N_("E_xit"), "W", N_("Exit the program"), (GCallback)window_close }, { "SaveExit", GTK_STOCK_QUIT, N_("Save and Exit"), NULL, N_("Save and Exit the program"), (GCallback)save_file_and_exit }, - { "GeoNamesSearch", GTK_STOCK_JUMP_TO, N_("Go To GeoNames location"), NULL, N_("Go to address/place using GeoNames search"), (GCallback)goto_address }, + { "GotoSearch", GTK_STOCK_JUMP_TO, N_("Go To location"), NULL, N_("Go to address/place using text search"), (GCallback)goto_address }, { "GotoLL", GTK_STOCK_QUIT, N_("_Go to Lat\\/Lon..."), NULL, N_("Go to arbitrary lat\\/lon coordinate"), (GCallback)draw_goto_cb }, { "GotoUTM", GTK_STOCK_QUIT, N_("Go to UTM..."), NULL, N_("Go to arbitrary UTM coordinate"), (GCallback)draw_goto_cb }, { "SetBGColor",GTK_STOCK_SELECT_COLOR, N_("Set Background Color..."), NULL, NULL, (GCallback)set_bg_color }, -- 2.39.5