]> git.street.me.uk Git - andy/viking.git/commitdiff
Allow to select between Google and Geonames for searching method
authorGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Sun, 18 Jan 2009 11:17:26 +0000 (11:17 +0000)
committerGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Sun, 18 Jan 2009 11:17:26 +0000 (11:17 +0000)
configure.ac
src/Makefile.am
src/dialog.c
src/geonamessearch.c
src/geonamessearch.h
src/googlesearch.c
src/googlesearch.h
src/menu.xml.h
src/util.c
src/util.h
src/vikwindow.c

index 1cd8a0be33b559d1603e56514d95f79f35e2ffca..04cee8f5957624e7a79b3454ec375fe2e7258866 100644 (file)
@@ -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)])],
index d12f10bdf9d83533fdea285b217d45c2728e2936..af98ec1f356c96e37057d091ce0886aaef0ac3f8 100644 (file)
@@ -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 \
index 071092ed6d0923fad2582b69baacf6012d4a2323..06965fd15095e230f2e963403b1e7f6f5d0b5afe 100644 (file)
 #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 <glib/gi18n.h>
@@ -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);
 
index a95860693408336d0100504620e7e57eba56e48b..ae58bef82a5bcb2a7296b8f351cfd0893cd653d5 100644 (file)
@@ -31,6 +31,7 @@
 #include <glib/gi18n.h>
 
 #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;
index b38eab51d2ee632e1ea538b2084ebdd8399bfd8c..d9e1a6115b95d563bafd78679bd22bd0fd329986 100644 (file)
@@ -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]);
index b7c7a72970c719c4cf10261a2eea3d3ef63994d6..2e2749de2aed4243cda1a0b68561a5fe842b085c 100644 (file)
@@ -31,6 +31,7 @@
 #include <glib/gi18n.h>
 
 #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;
index 56f89931408b78523dbf317aaf97892dd0807f30..9704112fec0bb38d86e51c0d6bd87c2a057ffffd 100644 (file)
@@ -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
index f7fe602da8eea9c16416dc684cfba8f9a429385c..d9cf08fc46ef27fd2ba0ceb0aa389d24904a7bd6 100644 (file)
@@ -44,7 +44,7 @@ static const char *menu_xml =
 #endif
        "      <menuitem action='ModeMercator'/>"
        "      <separator/>"
-       "      <menuitem action='GeoNamesSearch'/>"
+       "      <menuitem action='GotoSearch'/>"
        "      <menuitem action='GotoLL'/>"
        "      <menuitem action='GotoUTM'/>"
        "      <separator/>"
@@ -109,7 +109,7 @@ static const char *menu_xml =
        "      <separator/>"
        "    </placeholder>"
        "    <placeholder name='ViewToolItems'>"
-       "      <toolitem action='GeoNamesSearch'/>"
+       "      <toolitem action='GotoSearch'/>"
        "      <separator/>"
        "    </placeholder>"
        "    <placeholder name='ToolItems'>"
index 79da8ffcc1e2c0655fe2b4f149376138c798e0b5..975fce06f1a0be8a8395a321ff1c8067fe74c413 100644 (file)
@@ -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);
+}
+
index 1766cd4e80d0aefaeeed77a2379f3260d550e936..8bb12e75f609efdf0ba1f979f26d12dba20a2c31 100644 (file)
@@ -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
 
index 46aec3cc4ae632a8483831a00392058f36d48950..da4b0efad00078a4ea56a071405b26f99d10ab0a 100644 (file)
 #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"),                         "<control>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          },