]>
Commit | Line | Data |
---|---|---|
3333c069 EB |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
4 | * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | * | |
20 | */ | |
21 | #include <string.h> | |
22 | ||
23 | #include "viking.h" | |
24 | #include "babel.h" | |
25 | #include "gpx.h" | |
26 | #include "acquire.h" | |
27 | ||
28 | typedef struct { | |
29 | GtkWidget *num_spin; | |
30 | GtkWidget *center_entry; | |
31 | } datasource_gc_widgets_t; | |
32 | ||
33 | ||
92255687 | 34 | static gpointer datasource_gc_add_widgets ( GtkWidget *dialog, VikViewport *vvp ); |
3333c069 EB |
35 | static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gchar **cmd, gchar **input_type ); |
36 | static void datasource_gc_first_cleanup ( gpointer data ); | |
92255687 | 37 | static gchar *datasource_gc_check_existence (); |
3333c069 EB |
38 | |
39 | VikDataSourceInterface vik_datasource_gc_interface = { | |
40 | "Acquire from gc", | |
41 | VIK_DATASOURCE_SHELL_CMD, | |
42 | VIK_DATASOURCE_ADDTOLAYER, | |
92255687 | 43 | (VikDataSourceCheckExistenceFunc) datasource_gc_check_existence, |
3333c069 EB |
44 | (VikDataSourceAddWidgetsFunc) datasource_gc_add_widgets, |
45 | (VikDataSourceGetCmdStringFunc) datasource_gc_get_cmd_string, | |
46 | (VikDataSourceFirstCleanupFunc) datasource_gc_first_cleanup, | |
47 | (VikDataSourceProgressFunc) NULL, | |
48 | (VikDataSourceAddProgressWidgetsFunc) NULL, | |
49 | (VikDataSourceCleanupFunc) NULL | |
50 | }; | |
51 | ||
92255687 EB |
52 | static gchar *datasource_gc_check_existence () |
53 | { | |
54 | gchar *gcget_location = g_find_program_in_path("gcget"); | |
55 | if ( gcget_location ) { | |
56 | g_free(gcget_location); | |
57 | return NULL; | |
58 | } | |
59 | return g_strdup("Can't find gcget in path! Check that you have installed gcget correctly."); | |
60 | } | |
3333c069 | 61 | |
92255687 | 62 | static gpointer datasource_gc_add_widgets ( GtkWidget *dialog, VikViewport *vvp ) |
3333c069 EB |
63 | { |
64 | datasource_gc_widgets_t *widgets = g_malloc(sizeof(*widgets)); | |
65 | GtkWidget *num_label, *center_label; | |
66 | struct LatLon ll; | |
67 | gchar *s_ll; | |
68 | ||
69 | num_label = gtk_label_new ("Number geocaches:"); | |
70 | widgets->num_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new( 100, 1, 1000, 10, 20, 50 )), 25, 0 ); | |
71 | center_label = gtk_label_new ("Centered around:"); | |
72 | widgets->center_entry = gtk_entry_new(); | |
73 | ||
74 | vik_coord_to_latlon ( vik_viewport_get_center(vvp), &ll ); | |
75 | s_ll = g_strdup_printf("%f,%f", ll.lat, ll.lon ); | |
76 | gtk_entry_set_text ( GTK_ENTRY(widgets->center_entry), s_ll ); | |
77 | g_free ( s_ll ); | |
78 | ||
79 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), num_label, FALSE, FALSE, 5 ); | |
80 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->num_spin, FALSE, FALSE, 5 ); | |
81 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), center_label, FALSE, FALSE, 5 ); | |
82 | gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), widgets->center_entry, FALSE, FALSE, 5 ); | |
83 | gtk_widget_show_all(dialog); | |
84 | return widgets; | |
85 | } | |
86 | ||
87 | static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gchar **cmd, gchar **input_type ) | |
88 | { | |
3333c069 | 89 | /* TODO: we don't actually need GPSBabel... :-) */ |
92255687 EB |
90 | gchar *safe_string = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->center_entry) ) ); |
91 | *cmd = g_strdup_printf( "gcget %s %d", safe_string, gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widgets->num_spin) ) ); | |
3333c069 | 92 | *input_type = g_strdup("geo"); |
92255687 | 93 | g_free ( safe_string ); |
3333c069 EB |
94 | } |
95 | ||
96 | static void datasource_gc_first_cleanup ( gpointer data ) | |
97 | { | |
98 | g_free ( data ); | |
99 | } |