]> git.street.me.uk Git - andy/viking.git/blob - src/vikmapsource.c
SF Features#116: Add an Acquire From URL option.
[andy/viking.git] / src / vikmapsource.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * viking
4  * Copyright (C) 2009-2010, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
5  * 
6  * viking is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  * 
11  * viking is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along
17  * with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20  /**
21   * SECTION:vikmapsource
22   * @short_description: the base class to describe map source
23   * 
24   * The #VikMapSource class is both the interface and the base class
25   * for the hierarchie of map source.
26   */
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "vikviewport.h"
32 #include "vikcoord.h"
33 #include "mapcoord.h"
34
35 #include "vikmapsource.h"
36
37 static void vik_map_source_init (VikMapSource *object);
38 static void vik_map_source_finalize (GObject *object);
39 static void vik_map_source_class_init (VikMapSourceClass *klass);
40
41 static gboolean _supports_download_only_new (VikMapSource *object);
42
43 G_DEFINE_ABSTRACT_TYPE (VikMapSource, vik_map_source, G_TYPE_OBJECT);
44
45 static void
46 vik_map_source_init (VikMapSource *object)
47 {
48         /* TODO: Add initialization code here */
49 }
50
51 static void
52 vik_map_source_finalize (GObject *object)
53 {
54         /* TODO: Add deinitalization code here */
55
56         G_OBJECT_CLASS (vik_map_source_parent_class)->finalize (object);
57 }
58
59 static void
60 vik_map_source_class_init (VikMapSourceClass *klass)
61 {
62         GObjectClass* object_class = G_OBJECT_CLASS (klass);
63
64         klass->get_copyright = NULL;
65         klass->get_license = NULL;
66         klass->get_license_url = NULL;
67         klass->get_logo = NULL;
68         klass->get_uniq_id = NULL;
69         klass->get_label = NULL;
70         klass->get_tilesize_x = NULL;
71         klass->get_tilesize_y = NULL;
72         klass->get_drawmode = NULL;
73         klass->is_direct_file_access = NULL;
74         klass->supports_download_only_new = _supports_download_only_new;
75         klass->coord_to_mapcoord = NULL;
76         klass->mapcoord_to_center_coord = NULL;
77         klass->download = NULL;
78         klass->download_handle_init = NULL;
79         klass->download_handle_cleanup = NULL;
80         
81         object_class->finalize = vik_map_source_finalize;
82 }
83
84 gboolean
85 _supports_download_only_new (VikMapSource *self)
86 {
87         // Default feature: does not support
88         return FALSE;
89 }
90
91 /**
92  * vik_map_source_get_copyright:
93  * @self: the VikMapSource of interest.
94  * @bbox: bounding box of interest.
95  * @zoom: the zoom level of interest.
96  * @fct: the callback function to use to return matching copyrights.
97  * @data: the user data to use to call the callbaack function.
98  *
99  * Retrieve copyright(s) for the corresponding bounding box and zoom level.
100  */
101 void
102 vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data)
103 {
104         VikMapSourceClass *klass;
105         g_return_if_fail (self != NULL);
106         g_return_if_fail (VIK_IS_MAP_SOURCE (self));
107         klass = VIK_MAP_SOURCE_GET_CLASS(self);
108
109         g_return_if_fail (klass->get_copyright != NULL);
110
111         (*klass->get_copyright)(self, bbox, zoom, fct, data);
112 }
113
114 const gchar *
115 vik_map_source_get_license (VikMapSource *self)
116 {
117         VikMapSourceClass *klass;
118         g_return_val_if_fail (self != NULL, NULL);
119         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
120         klass = VIK_MAP_SOURCE_GET_CLASS(self);
121
122         g_return_val_if_fail (klass->get_license != NULL, NULL);
123
124         return (*klass->get_license)(self);
125 }
126
127 const gchar *
128 vik_map_source_get_license_url (VikMapSource *self)
129 {
130         VikMapSourceClass *klass;
131         g_return_val_if_fail (self != NULL, NULL);
132         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
133         klass = VIK_MAP_SOURCE_GET_CLASS(self);
134
135         g_return_val_if_fail (klass->get_license_url != NULL, NULL);
136
137         return (*klass->get_license_url)(self);
138 }
139
140 const GdkPixbuf *
141 vik_map_source_get_logo (VikMapSource *self)
142 {
143         VikMapSourceClass *klass;
144         g_return_val_if_fail (self != NULL, NULL);
145         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
146         klass = VIK_MAP_SOURCE_GET_CLASS(self);
147
148         g_return_val_if_fail (klass->get_logo != NULL, NULL);
149
150         return (*klass->get_logo)(self);
151 }
152
153 guint16
154 vik_map_source_get_uniq_id (VikMapSource *self)
155 {
156         VikMapSourceClass *klass;
157         g_return_val_if_fail (self != NULL, (guint16 )0);
158         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
159         klass = VIK_MAP_SOURCE_GET_CLASS(self);
160
161         g_return_val_if_fail (klass->get_uniq_id != NULL, (guint16 )0);
162
163         return (*klass->get_uniq_id)(self);
164 }
165
166 const gchar *
167 vik_map_source_get_label (VikMapSource *self)
168 {
169         VikMapSourceClass *klass;
170         g_return_val_if_fail (self != NULL, NULL);
171         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
172         klass = VIK_MAP_SOURCE_GET_CLASS(self);
173
174         g_return_val_if_fail (klass->get_label != NULL, NULL);
175
176         return (*klass->get_label)(self);
177 }
178
179 guint16
180 vik_map_source_get_tilesize_x (VikMapSource *self)
181 {
182         VikMapSourceClass *klass;
183         g_return_val_if_fail (self != NULL, (guint16 )0);
184         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
185         klass = VIK_MAP_SOURCE_GET_CLASS(self);
186
187         g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0);
188
189         return (*klass->get_tilesize_x)(self);
190 }
191
192 guint16
193 vik_map_source_get_tilesize_y (VikMapSource *self)
194 {
195         VikMapSourceClass *klass;
196         g_return_val_if_fail (self != NULL, (guint16 )0);
197         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
198         klass = VIK_MAP_SOURCE_GET_CLASS(self);
199
200         g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0);
201
202         return (*klass->get_tilesize_y)(self);
203 }
204
205 VikViewportDrawMode
206 vik_map_source_get_drawmode (VikMapSource *self)
207 {
208         VikMapSourceClass *klass;
209         g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0);
210         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0);
211         klass = VIK_MAP_SOURCE_GET_CLASS(self);
212
213         g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0);
214
215         return (*klass->get_drawmode)(self);
216 }
217
218 /**
219  * vik_map_source_is_direct_file_access:
220  * @self: the VikMapSource of interest.
221  *
222  *   Return true when we can bypass all this download malarky
223  *   Treat the files as a pre generated data set in OSM tile server layout: tiledir/%d/%d/%d.png
224  */
225 gboolean
226 vik_map_source_is_direct_file_access (VikMapSource * self)
227 {
228         VikMapSourceClass *klass;
229         g_return_val_if_fail (self != NULL, 0);
230         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
231         klass = VIK_MAP_SOURCE_GET_CLASS(self);
232
233         g_return_val_if_fail (klass->is_direct_file_access != NULL, 0);
234
235         return (*klass->is_direct_file_access)(self);
236 }
237
238 gboolean
239 vik_map_source_supports_download_only_new (VikMapSource * self)
240 {
241         VikMapSourceClass *klass;
242         g_return_val_if_fail (self != NULL, 0);
243         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
244         klass = VIK_MAP_SOURCE_GET_CLASS(self);
245
246         g_return_val_if_fail (klass->supports_download_only_new != NULL, 0);
247
248         return (*klass->supports_download_only_new)(self);
249 }
250
251 gboolean
252 vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
253 {
254         VikMapSourceClass *klass;
255         g_return_val_if_fail (self != NULL, FALSE);
256         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE);
257         klass = VIK_MAP_SOURCE_GET_CLASS(self);
258
259         g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE);
260
261         return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest);
262 }
263
264 void
265 vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
266 {
267         VikMapSourceClass *klass;
268         g_return_if_fail (self != NULL);
269         g_return_if_fail (VIK_IS_MAP_SOURCE (self));
270         klass = VIK_MAP_SOURCE_GET_CLASS(self);
271
272         g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
273
274         (*klass->mapcoord_to_center_coord)(self, src, dest);
275 }
276
277 int
278 vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle)
279 {
280         VikMapSourceClass *klass;
281         g_return_val_if_fail (self != NULL, 0);
282         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
283         klass = VIK_MAP_SOURCE_GET_CLASS(self);
284
285         g_return_val_if_fail (klass->download != NULL, 0);
286
287         return (*klass->download)(self, src, dest_fn, handle);
288 }
289
290 void *
291 vik_map_source_download_handle_init (VikMapSource *self)
292 {
293         VikMapSourceClass *klass;
294         g_return_val_if_fail (self != NULL, 0);
295         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
296         klass = VIK_MAP_SOURCE_GET_CLASS(self);
297
298         g_return_val_if_fail (klass->download_handle_init != NULL, 0);
299
300         return (*klass->download_handle_init)(self);
301 }
302
303 void
304 vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle)
305 {
306         VikMapSourceClass *klass;
307         g_return_if_fail (self != NULL);
308         g_return_if_fail (VIK_IS_MAP_SOURCE (self));
309         klass = VIK_MAP_SOURCE_GET_CLASS(self);
310
311         g_return_if_fail (klass->download_handle_cleanup != NULL);
312
313         (*klass->download_handle_cleanup)(self, handle);
314 }