2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2011, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
5 * Copyright (C) 2015, Rob Norris <rw_norris@hotmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <glib/gprintf.h>
28 #include <glib/gi18n.h>
36 * See http://wiki.openstreetmap.org/wiki/API_v0.6#GPS_Traces
38 #define DOWNLOAD_URL_FMT "api.openstreetmap.org/api/0.6/trackpoints?bbox=%s,%s,%s,%s&page=%d"
41 GtkWidget *page_number;
43 } datasource_osm_widgets_t;
45 static gdouble last_page_number = 0;
47 static gpointer datasource_osm_init ( acq_vik_t *avt );
48 static void datasource_osm_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
49 static void datasource_osm_get_process_options ( datasource_osm_widgets_t *widgets, ProcessOptions *po, DownloadFileOptions *options, const gchar *notused1, const gchar *notused2);
50 static void datasource_osm_cleanup ( gpointer data );
52 VikDataSourceInterface vik_datasource_osm_interface = {
55 VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT,
56 VIK_DATASOURCE_INPUTTYPE_NONE,
60 (VikDataSourceInitFunc) datasource_osm_init,
61 (VikDataSourceCheckExistenceFunc) NULL,
62 (VikDataSourceAddSetupWidgetsFunc) datasource_osm_add_setup_widgets,
63 (VikDataSourceGetProcessOptionsFunc) datasource_osm_get_process_options,
64 (VikDataSourceProcessFunc) a_babel_convert_from,
65 (VikDataSourceProgressFunc) NULL,
66 (VikDataSourceAddProgressWidgetsFunc) NULL,
67 (VikDataSourceCleanupFunc) datasource_osm_cleanup,
68 (VikDataSourceOffFunc) NULL,
77 static gpointer datasource_osm_init ( acq_vik_t *avt )
79 datasource_osm_widgets_t *widgets = g_malloc(sizeof(*widgets));
80 /* Keep reference to viewport */
81 widgets->vvp = avt->vvp;
85 static void datasource_osm_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data )
87 datasource_osm_widgets_t *widgets = (datasource_osm_widgets_t *)user_data;
88 GtkWidget *page_number_label;
89 page_number_label = gtk_label_new (_("Page number:"));
90 widgets->page_number = gtk_spin_button_new_with_range(0, 100, 1);
91 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->page_number), last_page_number);
93 /* Packing all widgets */
94 GtkBox *box = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
95 gtk_box_pack_start ( box, page_number_label, FALSE, FALSE, 5 );
96 gtk_box_pack_start ( box, widgets->page_number, FALSE, FALSE, 5 );
97 gtk_widget_show_all(dialog);
100 static void datasource_osm_get_process_options ( datasource_osm_widgets_t *widgets, ProcessOptions *po, DownloadFileOptions *options, const gchar *notused1, const gchar *notused2)
103 gdouble min_lat, max_lat, min_lon, max_lon;
104 gchar sminlon[G_ASCII_DTOSTR_BUF_SIZE];
105 gchar smaxlon[G_ASCII_DTOSTR_BUF_SIZE];
106 gchar sminlat[G_ASCII_DTOSTR_BUF_SIZE];
107 gchar smaxlat[G_ASCII_DTOSTR_BUF_SIZE];
109 /* get Viewport bounding box */
110 vik_viewport_get_min_max_lat_lon ( widgets->vvp, &min_lat, &max_lat, &min_lon, &max_lon );
112 /* Convert as LANG=C double representation */
113 g_ascii_dtostr (sminlon, G_ASCII_DTOSTR_BUF_SIZE, min_lon);
114 g_ascii_dtostr (smaxlon, G_ASCII_DTOSTR_BUF_SIZE, max_lon);
115 g_ascii_dtostr (sminlat, G_ASCII_DTOSTR_BUF_SIZE, min_lat);
116 g_ascii_dtostr (smaxlat, G_ASCII_DTOSTR_BUF_SIZE, max_lat);
118 /* Retrieve the specified page number */
119 last_page_number = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->page_number));
120 page = last_page_number;
122 // NB Download is of GPX type
123 po->url = g_strdup_printf( DOWNLOAD_URL_FMT, sminlon, sminlat, smaxlon, smaxlat, page );
124 options = NULL; // i.e. use the default download settings
127 static void datasource_osm_cleanup ( gpointer data )