]> git.street.me.uk Git - andy/viking.git/commitdiff
Use google maps search string as comment for new immediately created waypoint.
authorQuy Tonthat <qtonthat@gmail.com>
Thu, 31 May 2007 12:01:22 +0000 (12:01 +0000)
committerQuy Tonthat <qtonthat@gmail.com>
Thu, 31 May 2007 12:01:22 +0000 (12:01 +0000)
After a successful search, before any operation that moves the map area,
a waypoint can be created for the resulted location by using "New Waypoint"
from the context menu of a TrackWaypoint layer. The "New Waypoint" dialog
will then use the search string as default "Comment".

Signed-off-by: Quy Tonthat <qtonthat@gmail.com>
src/dialog.c
src/googlesearch.c
src/googlesearch.h
src/vikwindow.c
src/vikwindow.h

index 0eb91c48e1088a3107698438c2b390138d21efd2..360a54110e8bcfff1f230945efa12974d9938b30 100644 (file)
@@ -24,6 +24,7 @@
 #include "garminsymbols.h"
 #include "degrees_converters.h"
 #include "authors.h"
+#include "googlesearch.h"
 
 #include <stdlib.h>
 #include <string.h>
@@ -212,6 +213,9 @@ gboolean a_dialog_new_waypoint ( GtkWindow *parent, gchar **dest, VikWaypoint *w
 
   commentlabel = gtk_label_new ("Comment:");
   commententry = gtk_entry_new ();
+  gchar *cmt =  a_googlesearch_get_search_string_for_this_place(parent);
+  if (cmt)
+    gtk_entry_set_text(GTK_ENTRY(commententry), cmt);
 
   imagelabel = gtk_label_new ("Image:");
   imageentry = vik_file_entry_new ();
index 044c130761a4ad5a18e05161c244e6a6c0f4af6c..b6cf3ac1f659172b2ed9b5e1e37d7a49af20f108 100644 (file)
 #define GOOGLE_SEARCH_PATTERN_2 ",lng: "
 
 static gchar *last_search_str = NULL;
+static VikCoord *last_coord = NULL;
+static gchar *last_successful_search_str = NULL;
+
+gchar * a_googlesearch_get_search_string_for_this_place(VikWindow *vw)
+{
+  VikViewport *vvp = vik_window_viewport(vw);
+  VikCoord *cur_center = vik_viewport_get_center(vvp);
+  if (vik_coord_equals(cur_center, last_coord)) {
+    return(last_successful_search_str);
+  }
+  else
+    return NULL;
+}
 
 static gboolean prompt_try_again(VikWindow *vw)
 {
@@ -205,6 +218,14 @@ static int google_search_get_coord(VikWindow *vw, VikViewport *vvp, gchar *srch_
 
   vik_coord_load_from_latlon ( coord, vik_viewport_get_coord_mode(vvp), &ll );
 
+  if (last_coord)
+    g_free(last_coord);
+  last_coord = g_malloc(sizeof(VikCoord));
+  *last_coord = *coord;
+  if (last_successful_search_str)
+    g_free(last_successful_search_str);
+  last_successful_search_str = g_strdup(last_search_str);
+
 done:
   g_free(escaped_srch_str);
   g_free(uri);
index 80fe5a28aecd240a2fb754b217580ecce22fdd8f..9704112fec0bb38d86e51c0d6bd87c2a057ffffd 100644 (file)
@@ -2,5 +2,5 @@
 #define __VIK_GOOGLESEARCH_H
 
 extern void a_google_search(VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp);
-
+gchar * a_googlesearch_get_search_string_for_this_place(VikWindow *vw);
 #endif
index 5a9972b607f3adcde92844f760ae337ff0ea7ca4..a8aea04b9be050c39308baadd27d4e49846fdbc8 100644 (file)
@@ -185,6 +185,11 @@ GType vik_window_get_type (void)
   return vw_type;
 }
 
+VikViewport * vik_window_viewport(VikWindow *vw)
+{
+  return(vw->viking_vvp);
+}
+
 void vik_window_selected_layer(VikWindow *vw, VikLayer *vl)
 {
   int i, j, tool_count;
index e1f7ab02d5bcb56cb04382e72667f770d4b39d2a..7feba1d2c9a98309a3981ab5cb8df1aac2d4bb33 100644 (file)
@@ -51,6 +51,7 @@ VikWindow *vik_window_new ();
 void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean changefilename );
 struct _VikLayer;
 void vik_window_selected_layer(VikWindow *vw, struct _VikLayer *vl);
+struct _VikViewport * vik_window_viewport(VikWindow *vw);
 
 G_END_DECLS