]>
Commit | Line | Data |
---|---|---|
820c59f4 GB |
1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ |
2 | /* | |
3 | * viking | |
82aa018d | 4 | * Copyright (C) 2009-2010, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> |
820c59f4 GB |
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 | */ | |
aa69d106 GB |
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 | */ | |
820c59f4 GB |
27 | #ifdef HAVE_CONFIG_H |
28 | #include "config.h" | |
29 | #endif | |
30 | ||
31 | #include "vikviewport.h" | |
32 | #include "vikcoord.h" | |
33 | #include "mapcoord.h" | |
4e815e90 | 34 | #include "download.h" |
820c59f4 GB |
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 | ||
c81ded98 | 41 | static gboolean _supports_download_only_new (VikMapSource *object); |
0f08bd0d | 42 | |
d840e6de | 43 | G_DEFINE_ABSTRACT_TYPE (VikMapSource, vik_map_source, G_TYPE_OBJECT); |
820c59f4 | 44 | |
820c59f4 GB |
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 | ||
82aa018d | 64 | klass->get_copyright = NULL; |
53ac8302 GB |
65 | klass->get_license = NULL; |
66 | klass->get_license_url = NULL; | |
26336cf0 | 67 | klass->get_logo = NULL; |
2eb18edc | 68 | klass->get_name = NULL; |
820c59f4 | 69 | klass->get_uniq_id = NULL; |
db03733a | 70 | klass->get_label = NULL; |
820c59f4 GB |
71 | klass->get_tilesize_x = NULL; |
72 | klass->get_tilesize_y = NULL; | |
73 | klass->get_drawmode = NULL; | |
2673b29d | 74 | klass->is_direct_file_access = NULL; |
0fb11294 | 75 | klass->is_mbtiles = NULL; |
c81ded98 | 76 | klass->supports_download_only_new = _supports_download_only_new; |
e633ddef RN |
77 | klass->get_zoom_min = NULL; |
78 | klass->get_zoom_max = NULL; | |
820c59f4 GB |
79 | klass->coord_to_mapcoord = NULL; |
80 | klass->mapcoord_to_center_coord = NULL; | |
81 | klass->download = NULL; | |
825413ba SW |
82 | klass->download_handle_init = NULL; |
83 | klass->download_handle_cleanup = NULL; | |
820c59f4 GB |
84 | |
85 | object_class->finalize = vik_map_source_finalize; | |
86 | } | |
87 | ||
e8cf3d97 | 88 | gboolean |
c81ded98 | 89 | _supports_download_only_new (VikMapSource *self) |
0f08bd0d GB |
90 | { |
91 | // Default feature: does not support | |
92 | return FALSE; | |
93 | } | |
820c59f4 | 94 | |
68b1d6c0 GB |
95 | /** |
96 | * vik_map_source_get_copyright: | |
97 | * @self: the VikMapSource of interest. | |
98 | * @bbox: bounding box of interest. | |
99 | * @zoom: the zoom level of interest. | |
100 | * @fct: the callback function to use to return matching copyrights. | |
101 | * @data: the user data to use to call the callbaack function. | |
102 | * | |
17281ebd | 103 | * Retrieve copyright(s) for the corresponding bounding box and zoom level. |
68b1d6c0 GB |
104 | */ |
105 | void | |
551ee033 | 106 | vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data) |
82aa018d GB |
107 | { |
108 | VikMapSourceClass *klass; | |
68b1d6c0 GB |
109 | g_return_if_fail (self != NULL); |
110 | g_return_if_fail (VIK_IS_MAP_SOURCE (self)); | |
82aa018d GB |
111 | klass = VIK_MAP_SOURCE_GET_CLASS(self); |
112 | ||
68b1d6c0 | 113 | g_return_if_fail (klass->get_copyright != NULL); |
82aa018d | 114 | |
68b1d6c0 | 115 | (*klass->get_copyright)(self, bbox, zoom, fct, data); |
82aa018d GB |
116 | } |
117 | ||
53ac8302 GB |
118 | const gchar * |
119 | vik_map_source_get_license (VikMapSource *self) | |
120 | { | |
121 | VikMapSourceClass *klass; | |
122 | g_return_val_if_fail (self != NULL, NULL); | |
123 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
124 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
125 | ||
126 | g_return_val_if_fail (klass->get_license != NULL, NULL); | |
127 | ||
128 | return (*klass->get_license)(self); | |
129 | } | |
130 | ||
131 | const gchar * | |
132 | vik_map_source_get_license_url (VikMapSource *self) | |
133 | { | |
134 | VikMapSourceClass *klass; | |
135 | g_return_val_if_fail (self != NULL, NULL); | |
136 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
137 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
138 | ||
139 | g_return_val_if_fail (klass->get_license_url != NULL, NULL); | |
140 | ||
141 | return (*klass->get_license_url)(self); | |
142 | } | |
143 | ||
26336cf0 GB |
144 | const GdkPixbuf * |
145 | vik_map_source_get_logo (VikMapSource *self) | |
146 | { | |
147 | VikMapSourceClass *klass; | |
148 | g_return_val_if_fail (self != NULL, NULL); | |
149 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
150 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
151 | ||
152 | g_return_val_if_fail (klass->get_logo != NULL, NULL); | |
153 | ||
154 | return (*klass->get_logo)(self); | |
155 | } | |
156 | ||
2eb18edc RN |
157 | const gchar * |
158 | vik_map_source_get_name (VikMapSource *self) | |
159 | { | |
160 | VikMapSourceClass *klass; | |
161 | g_return_val_if_fail (self != NULL, NULL); | |
162 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
163 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
164 | ||
165 | g_return_val_if_fail (klass->get_name != NULL, NULL); | |
166 | ||
167 | return (*klass->get_name)(self); | |
168 | } | |
169 | ||
d7e495b2 | 170 | guint16 |
820c59f4 GB |
171 | vik_map_source_get_uniq_id (VikMapSource *self) |
172 | { | |
173 | VikMapSourceClass *klass; | |
d7e495b2 RN |
174 | g_return_val_if_fail (self != NULL, (guint16 )0); |
175 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0); | |
820c59f4 GB |
176 | klass = VIK_MAP_SOURCE_GET_CLASS(self); |
177 | ||
d7e495b2 | 178 | g_return_val_if_fail (klass->get_uniq_id != NULL, (guint16 )0); |
820c59f4 GB |
179 | |
180 | return (*klass->get_uniq_id)(self); | |
181 | } | |
182 | ||
db03733a GB |
183 | const gchar * |
184 | vik_map_source_get_label (VikMapSource *self) | |
185 | { | |
186 | VikMapSourceClass *klass; | |
187 | g_return_val_if_fail (self != NULL, NULL); | |
188 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
189 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
190 | ||
191 | g_return_val_if_fail (klass->get_label != NULL, NULL); | |
192 | ||
193 | return (*klass->get_label)(self); | |
194 | } | |
195 | ||
820c59f4 GB |
196 | guint16 |
197 | vik_map_source_get_tilesize_x (VikMapSource *self) | |
198 | { | |
199 | VikMapSourceClass *klass; | |
200 | g_return_val_if_fail (self != NULL, (guint16 )0); | |
201 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0); | |
202 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
203 | ||
204 | g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0); | |
205 | ||
206 | return (*klass->get_tilesize_x)(self); | |
207 | } | |
208 | ||
209 | guint16 | |
210 | vik_map_source_get_tilesize_y (VikMapSource *self) | |
211 | { | |
212 | VikMapSourceClass *klass; | |
213 | g_return_val_if_fail (self != NULL, (guint16 )0); | |
214 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0); | |
215 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
216 | ||
217 | g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0); | |
218 | ||
219 | return (*klass->get_tilesize_y)(self); | |
220 | } | |
221 | ||
222 | VikViewportDrawMode | |
223 | vik_map_source_get_drawmode (VikMapSource *self) | |
224 | { | |
225 | VikMapSourceClass *klass; | |
226 | g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0); | |
227 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0); | |
228 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
229 | ||
230 | g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0); | |
231 | ||
232 | return (*klass->get_drawmode)(self); | |
233 | } | |
234 | ||
2673b29d RN |
235 | /** |
236 | * vik_map_source_is_direct_file_access: | |
237 | * @self: the VikMapSource of interest. | |
238 | * | |
239 | * Return true when we can bypass all this download malarky | |
0314a439 | 240 | * Treat the files as a pre generated data set in OSM tile server layout: tiledir/%d/%d/%d.png |
2673b29d RN |
241 | */ |
242 | gboolean | |
243 | vik_map_source_is_direct_file_access (VikMapSource * self) | |
244 | { | |
245 | VikMapSourceClass *klass; | |
246 | g_return_val_if_fail (self != NULL, 0); | |
247 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
248 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
249 | ||
250 | g_return_val_if_fail (klass->is_direct_file_access != NULL, 0); | |
251 | ||
252 | return (*klass->is_direct_file_access)(self); | |
253 | } | |
254 | ||
0fb11294 RN |
255 | /** |
256 | * vik_map_source_is_mbtiles: | |
257 | * @self: the VikMapSource of interest. | |
258 | * | |
259 | * Return true when the map is in an MB Tiles format. | |
260 | * See http://github.com/mapbox/mbtiles-spec | |
261 | * (Read Only ATM) | |
262 | */ | |
263 | gboolean | |
264 | vik_map_source_is_mbtiles (VikMapSource * self) | |
265 | { | |
266 | VikMapSourceClass *klass; | |
267 | g_return_val_if_fail (self != NULL, 0); | |
268 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
269 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
270 | ||
271 | g_return_val_if_fail (klass->is_mbtiles != NULL, 0); | |
272 | ||
273 | return (*klass->is_mbtiles)(self); | |
274 | } | |
275 | ||
0f08bd0d | 276 | gboolean |
c81ded98 | 277 | vik_map_source_supports_download_only_new (VikMapSource * self) |
0f08bd0d GB |
278 | { |
279 | VikMapSourceClass *klass; | |
280 | g_return_val_if_fail (self != NULL, 0); | |
281 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
282 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
283 | ||
c81ded98 | 284 | g_return_val_if_fail (klass->supports_download_only_new != NULL, 0); |
0f08bd0d | 285 | |
c81ded98 | 286 | return (*klass->supports_download_only_new)(self); |
0f08bd0d GB |
287 | } |
288 | ||
e633ddef RN |
289 | /** |
290 | * | |
291 | */ | |
292 | guint8 | |
293 | vik_map_source_get_zoom_min (VikMapSource * self) | |
294 | { | |
295 | VikMapSourceClass *klass; | |
296 | g_return_val_if_fail (self != NULL, 0); | |
297 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
298 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
299 | g_return_val_if_fail (klass->get_zoom_min != NULL, 0); | |
300 | return (*klass->get_zoom_min)(self); | |
301 | } | |
302 | ||
303 | /** | |
304 | * | |
305 | */ | |
306 | guint8 | |
307 | vik_map_source_get_zoom_max (VikMapSource * self) | |
308 | { | |
309 | VikMapSourceClass *klass; | |
310 | g_return_val_if_fail (self != NULL, 18); | |
311 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 18); | |
312 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
313 | g_return_val_if_fail (klass->get_zoom_max != NULL, 18); | |
314 | return (*klass->get_zoom_max)(self); | |
315 | } | |
316 | ||
820c59f4 GB |
317 | gboolean |
318 | vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ) | |
319 | { | |
320 | VikMapSourceClass *klass; | |
321 | g_return_val_if_fail (self != NULL, FALSE); | |
322 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE); | |
323 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
324 | ||
325 | g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE); | |
326 | ||
327 | return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest); | |
328 | } | |
329 | ||
330 | void | |
331 | vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest) | |
332 | { | |
333 | VikMapSourceClass *klass; | |
334 | g_return_if_fail (self != NULL); | |
335 | g_return_if_fail (VIK_IS_MAP_SOURCE (self)); | |
336 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
337 | ||
338 | g_return_if_fail (klass->mapcoord_to_center_coord != NULL); | |
339 | ||
41810542 | 340 | (*klass->mapcoord_to_center_coord)(self, src, dest); |
820c59f4 GB |
341 | } |
342 | ||
4e815e90 RN |
343 | /** |
344 | * vik_map_source_download: | |
345 | * @self: The VikMapSource of interest. | |
346 | * @src: The map location to download | |
347 | * @dest_fn: The filename to save the result in | |
348 | * @handle: Potential reusable Curl Handle (may be NULL) | |
349 | * | |
350 | * Returns: How successful the download was as per the type #DownloadResult_t | |
351 | */ | |
352 | DownloadResult_t | |
825413ba | 353 | vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle) |
820c59f4 GB |
354 | { |
355 | VikMapSourceClass *klass; | |
356 | g_return_val_if_fail (self != NULL, 0); | |
357 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
358 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
359 | ||
360 | g_return_val_if_fail (klass->download != NULL, 0); | |
361 | ||
825413ba SW |
362 | return (*klass->download)(self, src, dest_fn, handle); |
363 | } | |
364 | ||
365 | void * | |
366 | vik_map_source_download_handle_init (VikMapSource *self) | |
367 | { | |
368 | VikMapSourceClass *klass; | |
369 | g_return_val_if_fail (self != NULL, 0); | |
370 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
371 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
372 | ||
373 | g_return_val_if_fail (klass->download_handle_init != NULL, 0); | |
374 | ||
375 | return (*klass->download_handle_init)(self); | |
376 | } | |
377 | ||
378 | void | |
379 | vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle) | |
380 | { | |
381 | VikMapSourceClass *klass; | |
2949dd77 GB |
382 | g_return_if_fail (self != NULL); |
383 | g_return_if_fail (VIK_IS_MAP_SOURCE (self)); | |
825413ba SW |
384 | klass = VIK_MAP_SOURCE_GET_CLASS(self); |
385 | ||
2949dd77 | 386 | g_return_if_fail (klass->download_handle_cleanup != NULL); |
825413ba | 387 | |
2949dd77 | 388 | (*klass->download_handle_cleanup)(self, handle); |
820c59f4 | 389 | } |