]> git.street.me.uk Git - andy/viking.git/blobdiff - src/geonamessearch.c
gtk_object_sink has been deprecated since gtk version 2.10, use g_object_ref_sink...
[andy/viking.git] / src / geonamessearch.c
index 0a6b1be86ea46dd66cee917d819f4582d83d60bd..b63d3eed993a05010265d12624676967edef6424 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
- * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ * Copyright (C) 2009, Hein Ragas
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,7 +17,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Created by Quy Tonthat <qtonthat@gmail.com>
  */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -34,8 +33,7 @@
 #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"
-#define GEONAMES_SEARCH_URL_FMT "http://ws.geonames.org/searchJSON?formatted=true&style=medium&maxRows=10&lang=en&q=%s"
+#define GEONAMES_WIKIPEDIA_URL_FMT "http://ws.geonames.org/wikipediaBoundingBoxJSON?formatted=true&north=%s&south=%s&east=%s&west=%s"
 #define GEONAMES_COUNTRY_PATTERN "\"countryName\": \""
 #define GEONAMES_LONGITUDE_PATTERN "\"lng\": "
 #define GEONAMES_NAME_PATTERN "\"name\": \""
@@ -100,6 +98,7 @@ static void none_found(VikWindow *vw)
 
   GtkWidget *search_label = gtk_label_new(_("No entries found!"));
   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), search_label, FALSE, FALSE, 5 );
+  gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
   gtk_widget_show_all(dialog);
 
   gtk_dialog_run ( GTK_DIALOG(dialog) );
@@ -137,6 +136,13 @@ GList *a_select_geoname_from_list(GtkWindow *parent, GList *geonames, gboolean m
                                                   GTK_STOCK_OK,
                                                   GTK_RESPONSE_ACCEPT,
                                                   NULL);
+  /* When something is selected then OK */
+  gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+  GtkWidget *response_w = NULL;
+#if GTK_CHECK_VERSION (2, 20, 0)
+  /* Default to not apply - as initially nothing is selected! */
+  response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT );
+#endif
   GtkWidget *label = gtk_label_new ( msg );
   GtkTreeStore *store;
   if (multiple_selection_allowed)
@@ -190,6 +196,8 @@ GList *a_select_geoname_from_list(GtkWindow *parent, GList *geonames, gboolean m
   gtk_widget_show ( label );
   gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), view, FALSE, FALSE, 0);
   gtk_widget_show ( view );
+  if ( response_w )
+    gtk_widget_grab_focus ( response_w );
   while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
   {
     GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
@@ -399,7 +407,7 @@ gchar *download_url(gchar *uri)
   tmp_file = fdopen(tmp_fd, "r+");
 
   // TODO: curl may not be available
-  if (curl_download_uri(uri, tmp_file, NULL)) {  // error
+  if (curl_download_uri(uri, tmp_file, NULL, 0, NULL)) {  // error
     fclose(tmp_file);
     tmp_file = NULL;
     g_remove(tmpname);
@@ -421,7 +429,16 @@ void a_geonames_wikipedia_box(VikWindow *vw, VikTrwLayer *vtl, VikLayersPanel *v
   VikWaypoint *wiki_wp;
   found_geoname *wiki_geoname;
 
-  uri = g_strdup_printf(GEONAMES_WIKIPEDIA_URL_FMT, maxmin[0].lat, maxmin[1].lat, maxmin[0].lon, maxmin[1].lon);
+  /* encode doubles in a C locale */
+  gchar *north = a_coords_dtostr(maxmin[0].lat);
+  gchar *south = a_coords_dtostr(maxmin[1].lat);
+  gchar *east = a_coords_dtostr(maxmin[0].lon);
+  gchar *west = a_coords_dtostr(maxmin[1].lon);
+  uri = g_strdup_printf(GEONAMES_WIKIPEDIA_URL_FMT, north, south, east, west);
+  g_free(north); north = NULL;
+  g_free(south); south = NULL;
+  g_free(east);  east = NULL;
+  g_free(west);  west = NULL;
   tmpname = download_url(uri);
   if (!tmpname) {
     none_found(vw);