]> git.street.me.uk Git - andy/viking.git/blame - src/datasource_osm.c
AC_OUTPUT doesn't need to take any arguments
[andy/viking.git] / src / datasource_osm.c
CommitLineData
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>
17acdaec 5 * Copyright (C) 2015, Rob Norris <rw_norris@hotmail.com>
9c4555df
GB
6 *
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.
11 *
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.
16 *
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
20 *
21 */
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25#include <string.h>
26
27#include <glib/gprintf.h>
28#include <glib/gi18n.h>
29
30#include "viking.h"
31#include "babel.h"
32#include "gpx.h"
33#include "acquire.h"
34
35/**
36 * See http://wiki.openstreetmap.org/wiki/API_v0.6#GPS_Traces
37 */
38#define DOWNLOAD_URL_FMT "api.openstreetmap.org/api/0.6/trackpoints?bbox=%s,%s,%s,%s&page=%d"
39
40typedef struct {
41 GtkWidget *page_number;
42 VikViewport *vvp;
43} datasource_osm_widgets_t;
44
45static gdouble last_page_number = 0;
46
307abf54 47static gpointer datasource_osm_init ( acq_vik_t *avt );
9c4555df 48static void datasource_osm_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
17acdaec 49static void datasource_osm_get_process_options ( datasource_osm_widgets_t *widgets, ProcessOptions *po, DownloadMapOptions *options, const gchar *notused1, const gchar *notused2);
9c4555df
GB
50static void datasource_osm_cleanup ( gpointer data );
51
52VikDataSourceInterface vik_datasource_osm_interface = {
53 N_("OSM traces"),
54 N_("OSM traces"),
9cc13848 55 VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT,
9c4555df
GB
56 VIK_DATASOURCE_INPUTTYPE_NONE,
57 TRUE,
58 TRUE,
b2aa700f 59 TRUE,
9c4555df
GB
60 (VikDataSourceInitFunc) datasource_osm_init,
61 (VikDataSourceCheckExistenceFunc) NULL,
62 (VikDataSourceAddSetupWidgetsFunc) datasource_osm_add_setup_widgets,
17acdaec
RN
63 (VikDataSourceGetProcessOptionsFunc) datasource_osm_get_process_options,
64 (VikDataSourceProcessFunc) a_babel_convert_from,
9c4555df
GB
65 (VikDataSourceProgressFunc) NULL,
66 (VikDataSourceAddProgressWidgetsFunc) NULL,
67 (VikDataSourceCleanupFunc) datasource_osm_cleanup,
68 (VikDataSourceOffFunc) NULL,
63959706
RN
69
70 NULL,
71 0,
72 NULL,
73 NULL,
74 0
9c4555df
GB
75};
76
307abf54 77static gpointer datasource_osm_init ( acq_vik_t *avt )
9c4555df
GB
78{
79 datasource_osm_widgets_t *widgets = g_malloc(sizeof(*widgets));
307abf54
RN
80 /* Keep reference to viewport */
81 widgets->vvp = avt->vvp;
9c4555df
GB
82 return widgets;
83}
84
85static void datasource_osm_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data )
86{
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);
8d79a14b
GB
92
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 );
9c4555df 97 gtk_widget_show_all(dialog);
9c4555df
GB
98}
99
17acdaec 100static void datasource_osm_get_process_options ( datasource_osm_widgets_t *widgets, ProcessOptions *po, DownloadMapOptions *options, const gchar *notused1, const gchar *notused2)
9c4555df
GB
101{
102 int page = 0;
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];
108
1d035105 109 /* get Viewport bounding box */
9c4555df
GB
110 vik_viewport_get_min_max_lat_lon ( widgets->vvp, &min_lat, &max_lat, &min_lon, &max_lon );
111
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);
117
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;
121
17acdaec
RN
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
9c4555df
GB
125}
126
127static void datasource_osm_cleanup ( gpointer data )
128{
129 g_free ( data );
130}
131