]>
Commit | Line | Data |
---|---|---|
9c4555df GB |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
1d035105 | 4 | * Copyright (C) 2011, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> |
9c4555df GB |
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 | #ifdef HAVE_CONFIG_H | |
22 | #include "config.h" | |
23 | #endif | |
24 | #include <string.h> | |
25 | ||
26 | #include <glib/gprintf.h> | |
27 | #include <glib/gi18n.h> | |
28 | ||
29 | #include "viking.h" | |
30 | #include "babel.h" | |
31 | #include "gpx.h" | |
32 | #include "acquire.h" | |
33 | ||
34 | /** | |
35 | * See http://wiki.openstreetmap.org/wiki/API_v0.6#GPS_Traces | |
36 | */ | |
37 | #define DOWNLOAD_URL_FMT "api.openstreetmap.org/api/0.6/trackpoints?bbox=%s,%s,%s,%s&page=%d" | |
38 | ||
39 | typedef struct { | |
40 | GtkWidget *page_number; | |
41 | VikViewport *vvp; | |
42 | } datasource_osm_widgets_t; | |
43 | ||
44 | static gdouble last_page_number = 0; | |
45 | ||
307abf54 | 46 | static gpointer datasource_osm_init ( acq_vik_t *avt ); |
9c4555df | 47 | static void datasource_osm_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); |
ed691ed1 | 48 | static void datasource_osm_get_cmd_string ( datasource_osm_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options ); |
9c4555df GB |
49 | static void datasource_osm_cleanup ( gpointer data ); |
50 | ||
51 | VikDataSourceInterface vik_datasource_osm_interface = { | |
52 | N_("OSM traces"), | |
53 | N_("OSM traces"), | |
9c4555df GB |
54 | VIK_DATASOURCE_ADDTOLAYER, |
55 | VIK_DATASOURCE_INPUTTYPE_NONE, | |
56 | TRUE, | |
57 | TRUE, | |
b2aa700f | 58 | TRUE, |
9c4555df GB |
59 | (VikDataSourceInitFunc) datasource_osm_init, |
60 | (VikDataSourceCheckExistenceFunc) NULL, | |
61 | (VikDataSourceAddSetupWidgetsFunc) datasource_osm_add_setup_widgets, | |
62 | (VikDataSourceGetCmdStringFunc) datasource_osm_get_cmd_string, | |
ed691ed1 | 63 | (VikDataSourceProcessFunc) a_babel_convert_from_url, |
9c4555df GB |
64 | (VikDataSourceProgressFunc) NULL, |
65 | (VikDataSourceAddProgressWidgetsFunc) NULL, | |
66 | (VikDataSourceCleanupFunc) datasource_osm_cleanup, | |
67 | (VikDataSourceOffFunc) NULL, | |
68 | }; | |
69 | ||
307abf54 | 70 | static gpointer datasource_osm_init ( acq_vik_t *avt ) |
9c4555df GB |
71 | { |
72 | datasource_osm_widgets_t *widgets = g_malloc(sizeof(*widgets)); | |
307abf54 RN |
73 | /* Keep reference to viewport */ |
74 | widgets->vvp = avt->vvp; | |
9c4555df GB |
75 | return widgets; |
76 | } | |
77 | ||
78 | static void datasource_osm_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ) | |
79 | { | |
80 | datasource_osm_widgets_t *widgets = (datasource_osm_widgets_t *)user_data; | |
81 | GtkWidget *page_number_label; | |
82 | page_number_label = gtk_label_new (_("Page number:")); | |
83 | widgets->page_number = gtk_spin_button_new_with_range(0, 100, 1); | |
84 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->page_number), last_page_number); | |
9b082b39 RN |
85 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), page_number_label, FALSE, FALSE, 5 ); |
86 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), widgets->page_number, FALSE, FALSE, 5 ); | |
9c4555df | 87 | gtk_widget_show_all(dialog); |
9c4555df GB |
88 | } |
89 | ||
ed691ed1 | 90 | static void datasource_osm_get_cmd_string ( datasource_osm_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options ) |
9c4555df GB |
91 | { |
92 | int page = 0; | |
93 | gdouble min_lat, max_lat, min_lon, max_lon; | |
94 | gchar sminlon[G_ASCII_DTOSTR_BUF_SIZE]; | |
95 | gchar smaxlon[G_ASCII_DTOSTR_BUF_SIZE]; | |
96 | gchar sminlat[G_ASCII_DTOSTR_BUF_SIZE]; | |
97 | gchar smaxlat[G_ASCII_DTOSTR_BUF_SIZE]; | |
98 | ||
1d035105 | 99 | /* get Viewport bounding box */ |
9c4555df GB |
100 | vik_viewport_get_min_max_lat_lon ( widgets->vvp, &min_lat, &max_lat, &min_lon, &max_lon ); |
101 | ||
102 | /* Convert as LANG=C double representation */ | |
103 | g_ascii_dtostr (sminlon, G_ASCII_DTOSTR_BUF_SIZE, min_lon); | |
104 | g_ascii_dtostr (smaxlon, G_ASCII_DTOSTR_BUF_SIZE, max_lon); | |
105 | g_ascii_dtostr (sminlat, G_ASCII_DTOSTR_BUF_SIZE, min_lat); | |
106 | g_ascii_dtostr (smaxlat, G_ASCII_DTOSTR_BUF_SIZE, max_lat); | |
107 | ||
108 | /* Retrieve the specified page number */ | |
109 | last_page_number = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->page_number)); | |
110 | page = last_page_number; | |
111 | ||
112 | *cmd = g_strdup_printf( DOWNLOAD_URL_FMT, sminlon, sminlat, smaxlon, smaxlat, page ); | |
a0e8bc69 | 113 | *input_file_type = NULL; |
ed691ed1 | 114 | options = NULL; |
9c4555df GB |
115 | } |
116 | ||
117 | static void datasource_osm_cleanup ( gpointer data ) | |
118 | { | |
119 | g_free ( data ); | |
120 | } | |
121 |