2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifdef VIK_CONFIG_GEOCACHES
32 GtkWidget *center_entry;
33 } datasource_gc_widgets_t;
36 static gpointer datasource_gc_init ( );
37 static void datasource_gc_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
38 static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gchar **cmd, gchar **input_type );
39 static void datasource_gc_cleanup ( gpointer data );
40 static gchar *datasource_gc_check_existence ();
42 VikDataSourceInterface vik_datasource_gc_interface = {
44 "Geocaching.com Caches",
45 VIK_DATASOURCE_SHELL_CMD,
46 VIK_DATASOURCE_ADDTOLAYER,
47 (VikDataSourceInitFunc) datasource_gc_init,
48 (VikDataSourceCheckExistenceFunc) datasource_gc_check_existence,
49 (VikDataSourceAddSetupWidgetsFunc) datasource_gc_add_setup_widgets,
50 (VikDataSourceGetCmdStringFunc) datasource_gc_get_cmd_string,
51 (VikDataSourceProgressFunc) NULL,
52 (VikDataSourceAddProgressWidgetsFunc) NULL,
53 (VikDataSourceCleanupFunc) datasource_gc_cleanup
56 static gpointer datasource_gc_init ( )
58 datasource_gc_widgets_t *widgets = g_malloc(sizeof(*widgets));
62 static gchar *datasource_gc_check_existence ()
64 gchar *gcget_location = g_find_program_in_path("gcget");
65 if ( gcget_location ) {
66 g_free(gcget_location);
69 return g_strdup("Can't find gcget in path! Check that you have installed gcget correctly.");
72 static void datasource_gc_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data )
74 datasource_gc_widgets_t *widgets = (datasource_gc_widgets_t *)user_data;
75 GtkWidget *num_label, *center_label;
79 num_label = gtk_label_new ("Number geocaches:");
80 widgets->num_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new( 100, 1, 1000, 10, 20, 50 )), 25, 0 );
81 center_label = gtk_label_new ("Centered around:");
82 widgets->center_entry = gtk_entry_new();
84 vik_coord_to_latlon ( vik_viewport_get_center(vvp), &ll );
85 s_ll = g_strdup_printf("%f,%f", ll.lat, ll.lon );
86 gtk_entry_set_text ( GTK_ENTRY(widgets->center_entry), s_ll );
89 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), num_label, FALSE, FALSE, 5 );
90 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->num_spin, FALSE, FALSE, 5 );
91 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), center_label, FALSE, FALSE, 5 );
92 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->center_entry, FALSE, FALSE, 5 );
93 gtk_widget_show_all(dialog);
96 static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gchar **cmd, gchar **input_type )
98 /* TODO: we don't actually need GPSBabel... :-) */
99 gchar *safe_string = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->center_entry) ) );
100 *cmd = g_strdup_printf( "gcget %s %d", safe_string, gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widgets->num_spin) ) );
101 *input_type = g_strdup("geo");
102 g_free ( safe_string );
105 static void datasource_gc_cleanup ( gpointer data )
109 #endif /* VIK_CONFIG_GEOCACHES */