X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/391505be276a168d83bbc7c2b926b6580d7ac139..0944940fe9a9268a45669a140cac4c5e3d1cd036:/src/datasource_gc.c?ds=sidebyside diff --git a/src/datasource_gc.c b/src/datasource_gc.c index 5b297e6a..b3b6b2c5 100644 --- a/src/datasource_gc.c +++ b/src/datasource_gc.c @@ -1,7 +1,7 @@ /* * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * - * Copyright (C) 2003-2005, Evan Battaglia + * Copyright (C) 2003-2007, Evan Battaglia * * 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 @@ -32,6 +32,10 @@ #include "acquire.h" #include "preferences.h" +// Could have an array of programs instead... +#define GC_PROGRAM1 "geo-nearest" +#define GC_PROGRAM2 "geo-html2gpx" + /* params will be geocaching.username, geocaching.password */ /* we have to make sure these don't collide. */ #define VIKING_GC_PARAMS_GROUP_KEY "geocaching" @@ -40,7 +44,7 @@ typedef struct { GtkWidget *num_spin; - GtkWidget *center_entry; + GtkWidget *center_entry; // TODO make separate widgets for lat/lon GtkWidget *miles_radius_spin; GdkGC *circle_gc; @@ -64,14 +68,17 @@ VikDataSourceInterface vik_datasource_gc_interface = { VIK_DATASOURCE_SHELL_CMD, VIK_DATASOURCE_ADDTOLAYER, VIK_DATASOURCE_INPUTTYPE_NONE, + TRUE, // Yes automatically update the display - otherwise we won't see the geocache waypoints! TRUE, (VikDataSourceInitFunc) datasource_gc_init, (VikDataSourceCheckExistenceFunc) datasource_gc_check_existence, (VikDataSourceAddSetupWidgetsFunc) datasource_gc_add_setup_widgets, (VikDataSourceGetCmdStringFunc) datasource_gc_get_cmd_string, + (VikDataSourceProcessFunc) NULL, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, - (VikDataSourceCleanupFunc) datasource_gc_cleanup + (VikDataSourceCleanupFunc) datasource_gc_cleanup, + (VikDataSourceOffFunc) NULL, }; static VikLayerParam prefs[] = { @@ -99,12 +106,25 @@ static gpointer datasource_gc_init ( ) static gchar *datasource_gc_check_existence () { - gchar *gcget_location = g_find_program_in_path("gcget"); - if ( gcget_location ) { - g_free(gcget_location); - return NULL; + gboolean OK1 = FALSE; + gboolean OK2 = FALSE; + + gchar *location1 = g_find_program_in_path(GC_PROGRAM1); + if ( location1 ) { + g_free(location1); + OK1 = TRUE; } - return g_strdup(_("Can't find gcget in path! Check that you have installed gcget correctly.")); + + gchar *location2 = g_find_program_in_path(GC_PROGRAM2); + if ( location2 ) { + g_free(location2); + OK2 = TRUE; + } + + if ( OK1 && OK2 ) + return NULL; + + return g_strdup_printf(_("Can't find %s or %s in path! Check that you have installed it correctly."), GC_PROGRAM1, GC_PROGRAM2); } static void datasource_gc_draw_circle ( datasource_gc_widgets_t *widgets ) @@ -167,11 +187,11 @@ static void datasource_gc_add_setup_widgets ( GtkWidget *dialog, VikViewport *vv gchar *s_ll; num_label = gtk_label_new (_("Number geocaches:")); - widgets->num_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new( 100, 1, 1000, 10, 20, 50 )), 25, 0 ); + widgets->num_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new( 20, 1, 1000, 10, 20, 0 )), 10, 0 ); center_label = gtk_label_new (_("Centered around:")); widgets->center_entry = gtk_entry_new(); miles_radius_label = gtk_label_new ("Miles Radius:"); - widgets->miles_radius_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new( 100, 1, 1000, 5, 20, 50 )), 25, 2 ); + widgets->miles_radius_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new( 5, 1, 1000, 1, 20, 0 )), 25, 1 ); vik_coord_to_latlon ( vik_viewport_get_center(vvp), &ll ); s_ll = g_strdup_printf("%f,%f", ll.lat, ll.lon ); @@ -182,7 +202,7 @@ static void datasource_gc_add_setup_widgets ( GtkWidget *dialog, VikViewport *vv widgets->vvp = vvp; widgets->circle_gc = vik_viewport_new_gc ( vvp, "#000000", 3 ); gdk_gc_set_function ( widgets->circle_gc, GDK_INVERT ); - widgets->circle_onscreen = FALSE; + widgets->circle_onscreen = TRUE; datasource_gc_draw_circle ( widgets ); g_signal_connect_swapped ( G_OBJECT(widgets->center_entry), "changed", G_CALLBACK(datasource_gc_draw_circle), widgets ); @@ -199,14 +219,32 @@ static void datasource_gc_add_setup_widgets ( GtkWidget *dialog, VikViewport *vv static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gchar **cmd, gchar **input_file_type ) { - gchar *safe_string = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->center_entry) ) ); + //gchar *safe_string = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->center_entry) ) ); gchar *safe_user = g_shell_quote ( a_preferences_get ( VIKING_GC_PARAMS_NAMESPACE "username")->s ); gchar *safe_pass = g_shell_quote ( a_preferences_get ( VIKING_GC_PARAMS_NAMESPACE "password")->s ); - *cmd = g_strdup_printf( "gcget -u %s -p %s %s %d %.2lf", safe_user, safe_pass, safe_string, - gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widgets->num_spin) ), - gtk_spin_button_get_value_as_float ( GTK_SPIN_BUTTON(widgets->miles_radius_spin) ) ); + gdouble lat, lon; + if ( 2 != sscanf ( gtk_entry_get_text ( GTK_ENTRY(widgets->center_entry) ), "%lf,%lf", &lat, &lon ) ) { + g_warning (_("Broken input - using some defaults")); + lat = a_vik_get_default_lat(); + lon = a_vik_get_default_long(); + } + + // Unix specific shell commands + // 1. Remove geocache webpages (maybe be from different location) + // 2, Gets upto n geocaches as webpages for the specified user in radius r Miles + // 3. Converts webpages into a single waypoint file, ignoring zero location waypoints '-z' + // Probably as they are premium member only geocaches and user is only a basic member + // Final output is piped into GPSbabel - hence removal of *html is done at beginning of the command sequence + *cmd = g_strdup_printf( "rm -f ~/.geo/caches/*html ; %s -P -n%d -r%.1fM -u %s -p %s %.4f %.4f ; %s -z ~/.geo/caches/*html ", + GC_PROGRAM1, + gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widgets->num_spin) ), + gtk_spin_button_get_value_as_float ( GTK_SPIN_BUTTON(widgets->miles_radius_spin) ), + safe_user, + safe_pass, + lat, lon, + GC_PROGRAM2 ); *input_file_type = NULL; - g_free ( safe_string ); + //g_free ( safe_string ); g_free ( safe_user ); g_free ( safe_pass ); }