]>
Commit | Line | Data |
---|---|---|
3a4b95f6 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> |
3a4b95f6 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 | */ | |
19 | ||
aa69d106 GB |
20 | /** |
21 | * SECTION:vikmapsourcedefault | |
22 | * @short_description: the base class implementing most of generic features | |
23 | * | |
24 | * The #VikMapSourceDefault class is the base class implementing most of | |
25 | * generic feature, using properties or reducing complexity of some | |
26 | * functions. | |
27 | */ | |
28 | ||
3a4b95f6 | 29 | #include "vikmapsourcedefault.h" |
31f3c5e7 | 30 | #include "vikenumtypes.h" |
f66ea3ec | 31 | #include "download.h" |
717db381 | 32 | #include "string.h" |
3a4b95f6 | 33 | |
551ee033 | 34 | static void map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data); |
53ac8302 GB |
35 | static const gchar *map_source_get_license (VikMapSource *self); |
36 | static const gchar *map_source_get_license_url (VikMapSource *self); | |
26336cf0 | 37 | static const GdkPixbuf *map_source_get_logo (VikMapSource *self); |
82aa018d | 38 | |
2eb18edc | 39 | static const gchar *map_source_get_name (VikMapSource *self); |
d7e495b2 | 40 | static guint16 map_source_get_uniq_id (VikMapSource *self); |
db03733a | 41 | static const gchar *map_source_get_label (VikMapSource *self); |
3a4b95f6 GB |
42 | static guint16 map_source_get_tilesize_x (VikMapSource *self); |
43 | static guint16 map_source_get_tilesize_y (VikMapSource *self); | |
44 | static VikViewportDrawMode map_source_get_drawmode (VikMapSource *self); | |
14b57d17 | 45 | static const gchar *map_source_get_file_extension (VikMapSource *self); |
3a4b95f6 | 46 | |
4e815e90 | 47 | static DownloadResult_t _download ( VikMapSource *self, MapCoord *src, const gchar *dest_fn, void *handle ); |
f66ea3ec GB |
48 | static void * _download_handle_init ( VikMapSource *self ); |
49 | static void _download_handle_cleanup ( VikMapSource *self, void *handle ); | |
50 | ||
3a4b95f6 GB |
51 | typedef struct _VikMapSourceDefaultPrivate VikMapSourceDefaultPrivate; |
52 | struct _VikMapSourceDefaultPrivate | |
53 | { | |
82aa018d GB |
54 | /* legal stuff */ |
55 | gchar *copyright; | |
53ac8302 GB |
56 | gchar *license; |
57 | gchar *license_url; | |
26336cf0 GB |
58 | GdkPixbuf *logo; |
59 | ||
2eb18edc | 60 | gchar *name; |
d7e495b2 | 61 | guint16 uniq_id; |
db03733a | 62 | gchar *label; |
3a4b95f6 GB |
63 | guint16 tilesize_x; |
64 | guint16 tilesize_y; | |
65 | VikViewportDrawMode drawmode; | |
14b57d17 | 66 | gchar *file_extension; |
3a4b95f6 GB |
67 | }; |
68 | ||
69 | #define VIK_MAP_SOURCE_DEFAULT_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIK_TYPE_MAP_SOURCE_DEFAULT, VikMapSourceDefaultPrivate)) | |
70 | ||
31f3c5e7 GB |
71 | /* properties */ |
72 | enum | |
73 | { | |
74 | PROP_0, | |
75 | ||
2eb18edc | 76 | PROP_NAME, |
31f3c5e7 | 77 | PROP_ID, |
db03733a | 78 | PROP_LABEL, |
31f3c5e7 GB |
79 | PROP_TILESIZE_X, |
80 | PROP_TILESIZE_Y, | |
81 | PROP_DRAWMODE, | |
82aa018d | 82 | PROP_COPYRIGHT, |
53ac8302 GB |
83 | PROP_LICENSE, |
84 | PROP_LICENSE_URL, | |
14b57d17 | 85 | PROP_FILE_EXTENSION, |
31f3c5e7 | 86 | }; |
3a4b95f6 | 87 | |
d840e6de | 88 | G_DEFINE_ABSTRACT_TYPE (VikMapSourceDefault, vik_map_source_default, VIK_TYPE_MAP_SOURCE); |
3a4b95f6 GB |
89 | |
90 | static void | |
91 | vik_map_source_default_init (VikMapSourceDefault *object) | |
92 | { | |
db03733a GB |
93 | VikMapSourceDefault *self = VIK_MAP_SOURCE_DEFAULT (object); |
94 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE (self); | |
95 | ||
96 | priv->label = NULL; | |
82aa018d | 97 | priv->copyright = NULL; |
53ac8302 GB |
98 | priv->license = NULL; |
99 | priv->license_url = NULL; | |
26336cf0 | 100 | priv->logo = NULL; |
2eb18edc | 101 | priv->name = NULL; |
14b57d17 | 102 | priv->file_extension = NULL; |
3a4b95f6 GB |
103 | } |
104 | ||
105 | static void | |
106 | vik_map_source_default_finalize (GObject *object) | |
107 | { | |
db03733a GB |
108 | VikMapSourceDefault *self = VIK_MAP_SOURCE_DEFAULT (object); |
109 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE (self); | |
3a4b95f6 | 110 | |
db03733a GB |
111 | g_free (priv->label); |
112 | priv->label = NULL; | |
82aa018d GB |
113 | g_free (priv->copyright); |
114 | priv->copyright = NULL; | |
53ac8302 GB |
115 | g_free (priv->license); |
116 | priv->license = NULL; | |
117 | g_free (priv->license_url); | |
118 | priv->license_url = NULL; | |
26336cf0 GB |
119 | g_free (priv->logo); |
120 | priv->license_url = NULL; | |
2eb18edc RN |
121 | g_free (priv->name); |
122 | priv->name = NULL; | |
14b57d17 RN |
123 | g_free (priv->file_extension); |
124 | priv->file_extension = NULL; | |
2eb18edc | 125 | |
db03733a | 126 | G_OBJECT_CLASS (vik_map_source_default_parent_class)->finalize (object); |
3a4b95f6 GB |
127 | } |
128 | ||
31f3c5e7 GB |
129 | static void |
130 | vik_map_source_default_set_property (GObject *object, | |
131 | guint property_id, | |
132 | const GValue *value, | |
133 | GParamSpec *pspec) | |
134 | { | |
135 | VikMapSourceDefault *self = VIK_MAP_SOURCE_DEFAULT (object); | |
136 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE (self); | |
137 | ||
138 | switch (property_id) | |
139 | { | |
2eb18edc RN |
140 | case PROP_NAME: |
141 | // Sanitize the name here for file usage | |
142 | // A simple check just to prevent containing slashes ATM | |
143 | g_free (priv->name); | |
144 | priv->name = g_strdup(g_value_get_string (value)); | |
145 | g_strdelimit (priv->name, "\\/", 'x' ); | |
146 | break; | |
147 | ||
31f3c5e7 GB |
148 | case PROP_ID: |
149 | priv->uniq_id = g_value_get_uint (value); | |
150 | break; | |
151 | ||
9f58c4b4 | 152 | case PROP_LABEL: |
db03733a GB |
153 | g_free (priv->label); |
154 | priv->label = g_strdup(g_value_get_string (value)); | |
155 | break; | |
156 | ||
31f3c5e7 GB |
157 | case PROP_TILESIZE_X: |
158 | priv->tilesize_x = g_value_get_uint (value); | |
159 | break; | |
160 | ||
161 | case PROP_TILESIZE_Y: | |
162 | priv->tilesize_y = g_value_get_uint (value); | |
163 | break; | |
164 | ||
165 | case PROP_DRAWMODE: | |
166 | priv->drawmode = g_value_get_enum(value); | |
167 | break; | |
168 | ||
82aa018d GB |
169 | case PROP_COPYRIGHT: |
170 | g_free (priv->copyright); | |
171 | priv->copyright = g_strdup(g_value_get_string (value)); | |
172 | break; | |
173 | ||
53ac8302 GB |
174 | case PROP_LICENSE: |
175 | g_free (priv->license); | |
176 | priv->license = g_strdup(g_value_get_string (value)); | |
177 | break; | |
178 | ||
179 | case PROP_LICENSE_URL: | |
180 | g_free (priv->license_url); | |
181 | priv->license_url = g_strdup(g_value_get_string (value)); | |
182 | break; | |
183 | ||
14b57d17 RN |
184 | case PROP_FILE_EXTENSION: |
185 | g_free (priv->file_extension); | |
186 | priv->file_extension = g_strdup(g_value_get_string(value)); | |
187 | break; | |
188 | ||
31f3c5e7 GB |
189 | default: |
190 | /* We don't have any other property... */ | |
191 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | |
192 | break; | |
193 | } | |
194 | } | |
195 | ||
196 | static void | |
197 | vik_map_source_default_get_property (GObject *object, | |
198 | guint property_id, | |
199 | GValue *value, | |
200 | GParamSpec *pspec) | |
201 | { | |
202 | VikMapSourceDefault *self = VIK_MAP_SOURCE_DEFAULT (object); | |
203 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE (self); | |
204 | ||
205 | switch (property_id) | |
206 | { | |
2eb18edc RN |
207 | case PROP_NAME: |
208 | g_value_set_string (value, priv->name); | |
209 | break; | |
210 | ||
31f3c5e7 GB |
211 | case PROP_ID: |
212 | g_value_set_uint (value, priv->uniq_id); | |
213 | break; | |
214 | ||
db03733a GB |
215 | case PROP_LABEL: |
216 | g_value_set_string (value, priv->label); | |
217 | break; | |
218 | ||
31f3c5e7 GB |
219 | case PROP_TILESIZE_X: |
220 | g_value_set_uint (value, priv->tilesize_x); | |
221 | break; | |
222 | ||
223 | case PROP_TILESIZE_Y: | |
224 | g_value_set_uint (value, priv->tilesize_y); | |
225 | break; | |
226 | ||
227 | case PROP_DRAWMODE: | |
228 | g_value_set_enum (value, priv->drawmode); | |
229 | break; | |
230 | ||
82aa018d GB |
231 | case PROP_COPYRIGHT: |
232 | g_value_set_string (value, priv->copyright); | |
233 | break; | |
234 | ||
53ac8302 GB |
235 | case PROP_LICENSE: |
236 | g_value_set_string (value, priv->license); | |
237 | break; | |
238 | ||
239 | case PROP_LICENSE_URL: | |
240 | g_value_set_string (value, priv->license_url); | |
241 | break; | |
242 | ||
14b57d17 RN |
243 | case PROP_FILE_EXTENSION: |
244 | g_value_set_string (value, priv->file_extension); | |
245 | break; | |
246 | ||
31f3c5e7 GB |
247 | default: |
248 | /* We don't have any other property... */ | |
249 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | |
250 | break; | |
251 | } | |
252 | } | |
253 | ||
3a4b95f6 GB |
254 | static void |
255 | vik_map_source_default_class_init (VikMapSourceDefaultClass *klass) | |
256 | { | |
257 | GObjectClass* object_class = G_OBJECT_CLASS (klass); | |
258 | VikMapSourceClass* parent_class = VIK_MAP_SOURCE_CLASS (klass); | |
31f3c5e7 GB |
259 | GParamSpec *pspec = NULL; |
260 | ||
261 | object_class->set_property = vik_map_source_default_set_property; | |
262 | object_class->get_property = vik_map_source_default_get_property; | |
263 | ||
3a4b95f6 | 264 | /* Overiding methods */ |
82aa018d | 265 | parent_class->get_copyright = map_source_get_copyright; |
53ac8302 GB |
266 | parent_class->get_license = map_source_get_license; |
267 | parent_class->get_license_url = map_source_get_license_url; | |
26336cf0 | 268 | parent_class->get_logo = map_source_get_logo; |
2eb18edc | 269 | parent_class->get_name = map_source_get_name; |
3a4b95f6 | 270 | parent_class->get_uniq_id = map_source_get_uniq_id; |
db03733a | 271 | parent_class->get_label = map_source_get_label; |
3a4b95f6 GB |
272 | parent_class->get_tilesize_x = map_source_get_tilesize_x; |
273 | parent_class->get_tilesize_y = map_source_get_tilesize_y; | |
274 | parent_class->get_drawmode = map_source_get_drawmode; | |
14b57d17 | 275 | parent_class->get_file_extension = map_source_get_file_extension; |
f66ea3ec GB |
276 | parent_class->download = _download; |
277 | parent_class->download_handle_init = _download_handle_init; | |
278 | parent_class->download_handle_cleanup = _download_handle_cleanup; | |
279 | ||
280 | /* Default implementation of methods */ | |
281 | klass->get_uri = NULL; | |
282 | klass->get_hostname = NULL; | |
283 | klass->get_download_options = NULL; | |
3a4b95f6 | 284 | |
2eb18edc RN |
285 | pspec = g_param_spec_string ("name", |
286 | "Name", | |
287 | "The name of the map that may be used as the file cache directory", | |
288 | "Unknown" /* default value */, | |
289 | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); | |
290 | g_object_class_install_property (object_class, PROP_NAME, pspec); | |
291 | ||
31f3c5e7 GB |
292 | pspec = g_param_spec_uint ("id", |
293 | "Id of the tool", | |
294 | "Set the id", | |
295 | 0 /* minimum value */, | |
9593ef7d | 296 | G_MAXUINT /* maximum value */, |
31f3c5e7 GB |
297 | 0 /* default value */, |
298 | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); | |
299 | g_object_class_install_property (object_class, PROP_ID, pspec); | |
300 | ||
db03733a GB |
301 | pspec = g_param_spec_string ("label", |
302 | "Label", | |
303 | "The label of the map source", | |
304 | "<no-set>" /* default value */, | |
305 | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); | |
306 | g_object_class_install_property (object_class, PROP_LABEL, pspec); | |
307 | ||
31f3c5e7 GB |
308 | pspec = g_param_spec_uint ("tilesize-x", |
309 | "TileSizeX", | |
310 | "Set the size of the tile (x)", | |
311 | 0 /* minimum value */, | |
312 | G_MAXUINT16 /* maximum value */, | |
313 | 0 /* default value */, | |
f0d4496f | 314 | G_PARAM_READWRITE); |
31f3c5e7 GB |
315 | g_object_class_install_property (object_class, PROP_TILESIZE_X, pspec); |
316 | ||
317 | pspec = g_param_spec_uint ("tilesize-y", | |
318 | "TileSizeY", | |
319 | "Set the size of the tile (y)", | |
320 | 0 /* minimum value */, | |
321 | G_MAXUINT16 /* maximum value */, | |
322 | 0 /* default value */, | |
f0d4496f | 323 | G_PARAM_READWRITE); |
31f3c5e7 GB |
324 | g_object_class_install_property (object_class, PROP_TILESIZE_Y, pspec); |
325 | ||
326 | pspec = g_param_spec_enum("drawmode", | |
327 | "Drawmode", | |
328 | "The mode used to draw map", | |
329 | VIK_TYPE_VIEWPORT_DRAW_MODE, | |
330 | VIK_VIEWPORT_DRAWMODE_UTM, | |
331 | G_PARAM_READWRITE); | |
332 | g_object_class_install_property(object_class, PROP_DRAWMODE, pspec); | |
333 | ||
82aa018d GB |
334 | pspec = g_param_spec_string ("copyright", |
335 | "Copyright", | |
336 | "The copyright of the map source", | |
337 | NULL, | |
9f58c4b4 | 338 | G_PARAM_READWRITE); |
82aa018d GB |
339 | g_object_class_install_property (object_class, PROP_COPYRIGHT, pspec); |
340 | ||
53ac8302 GB |
341 | pspec = g_param_spec_string ("license", |
342 | "License", | |
343 | "The license of the map source", | |
344 | NULL, | |
345 | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); | |
346 | g_object_class_install_property (object_class, PROP_LICENSE, pspec); | |
347 | ||
348 | pspec = g_param_spec_string ("license-url", | |
349 | "License URL", | |
350 | "The URL of the license of the map source", | |
351 | NULL, | |
352 | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); | |
353 | g_object_class_install_property (object_class, PROP_LICENSE_URL, pspec); | |
354 | ||
14b57d17 RN |
355 | pspec = g_param_spec_string ("file-extension", |
356 | "File Extension", | |
357 | "The file extension of tile files on disk", | |
358 | ".png" /* default value */, | |
359 | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); | |
360 | g_object_class_install_property (object_class, PROP_FILE_EXTENSION, pspec); | |
361 | ||
3a4b95f6 GB |
362 | g_type_class_add_private (klass, sizeof (VikMapSourceDefaultPrivate)); |
363 | ||
364 | object_class->finalize = vik_map_source_default_finalize; | |
365 | } | |
366 | ||
68b1d6c0 | 367 | static void |
551ee033 | 368 | map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data) |
82aa018d | 369 | { |
68b1d6c0 GB |
370 | /* Just ignore bbox and zoom level */ |
371 | g_return_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self)); | |
372 | ||
82aa018d GB |
373 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); |
374 | ||
68b1d6c0 | 375 | (*fct) (data, priv->copyright); |
82aa018d GB |
376 | } |
377 | ||
53ac8302 GB |
378 | static const gchar * |
379 | map_source_get_license (VikMapSource *self) | |
380 | { | |
381 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), NULL); | |
382 | ||
383 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); | |
384 | ||
385 | return priv->license; | |
386 | } | |
387 | ||
388 | static const gchar * | |
389 | map_source_get_license_url (VikMapSource *self) | |
390 | { | |
391 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), NULL); | |
392 | ||
393 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); | |
394 | ||
395 | return priv->license_url; | |
396 | } | |
397 | ||
26336cf0 GB |
398 | static const GdkPixbuf * |
399 | map_source_get_logo (VikMapSource *self) | |
400 | { | |
401 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), NULL); | |
402 | ||
403 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); | |
404 | ||
405 | return priv->logo; | |
406 | } | |
407 | ||
2eb18edc RN |
408 | static const gchar * |
409 | map_source_get_name (VikMapSource *self) | |
410 | { | |
411 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), NULL); | |
412 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); | |
413 | return priv->name; | |
414 | } | |
415 | ||
d7e495b2 | 416 | static guint16 |
3a4b95f6 GB |
417 | map_source_get_uniq_id (VikMapSource *self) |
418 | { | |
d7e495b2 | 419 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), (guint16)0); |
3a84e537 GB |
420 | |
421 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); | |
3a4b95f6 GB |
422 | |
423 | return priv->uniq_id; | |
424 | } | |
425 | ||
db03733a GB |
426 | static const gchar * |
427 | map_source_get_label (VikMapSource *self) | |
428 | { | |
429 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), NULL); | |
430 | ||
431 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); | |
432 | ||
433 | return priv->label; | |
434 | } | |
435 | ||
3a4b95f6 GB |
436 | static guint16 |
437 | map_source_get_tilesize_x (VikMapSource *self) | |
438 | { | |
3a84e537 GB |
439 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), (guint16)0); |
440 | ||
3a4b95f6 | 441 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); |
3a4b95f6 GB |
442 | |
443 | return priv->tilesize_x; | |
444 | } | |
445 | ||
446 | static guint16 | |
447 | map_source_get_tilesize_y (VikMapSource *self) | |
448 | { | |
3a84e537 GB |
449 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), (guint16)0); |
450 | ||
3a4b95f6 | 451 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); |
3a4b95f6 GB |
452 | |
453 | return priv->tilesize_y; | |
454 | } | |
455 | ||
456 | static VikViewportDrawMode | |
457 | map_source_get_drawmode (VikMapSource *self) | |
458 | { | |
3a84e537 GB |
459 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), (VikViewportDrawMode)0); |
460 | ||
3a4b95f6 | 461 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); |
3a4b95f6 GB |
462 | |
463 | return priv->drawmode; | |
464 | } | |
f66ea3ec | 465 | |
4e815e90 | 466 | static DownloadResult_t |
f66ea3ec GB |
467 | _download ( VikMapSource *self, MapCoord *src, const gchar *dest_fn, void *handle ) |
468 | { | |
f66ea3ec GB |
469 | gchar *uri = vik_map_source_default_get_uri(VIK_MAP_SOURCE_DEFAULT(self), src); |
470 | gchar *host = vik_map_source_default_get_hostname(VIK_MAP_SOURCE_DEFAULT(self)); | |
686baff0 | 471 | DownloadFileOptions *options = vik_map_source_default_get_download_options(VIK_MAP_SOURCE_DEFAULT(self)); |
4e815e90 | 472 | DownloadResult_t res = a_http_download_get_url ( host, uri, dest_fn, options, handle ); |
f66ea3ec GB |
473 | g_free ( uri ); |
474 | g_free ( host ); | |
475 | return res; | |
476 | } | |
477 | ||
14b57d17 RN |
478 | static const gchar * |
479 | map_source_get_file_extension (VikMapSource *self) | |
480 | { | |
481 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT(self), NULL); | |
482 | VikMapSourceDefaultPrivate *priv = VIK_MAP_SOURCE_DEFAULT_PRIVATE(self); | |
483 | return priv->file_extension; | |
484 | } | |
485 | ||
f66ea3ec GB |
486 | static void * |
487 | _download_handle_init ( VikMapSource *self ) | |
488 | { | |
489 | return a_download_handle_init (); | |
490 | } | |
491 | ||
492 | ||
493 | static void | |
494 | _download_handle_cleanup ( VikMapSource *self, void *handle ) | |
495 | { | |
41810542 | 496 | a_download_handle_cleanup ( handle ); |
f66ea3ec GB |
497 | } |
498 | ||
499 | gchar * | |
500 | vik_map_source_default_get_uri( VikMapSourceDefault *self, MapCoord *src ) | |
501 | { | |
502 | VikMapSourceDefaultClass *klass; | |
503 | g_return_val_if_fail (self != NULL, 0); | |
504 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT (self), 0); | |
505 | klass = VIK_MAP_SOURCE_DEFAULT_GET_CLASS(self); | |
506 | ||
507 | g_return_val_if_fail (klass->get_uri != NULL, 0); | |
508 | ||
509 | return (*klass->get_uri)(self, src); | |
510 | } | |
511 | ||
512 | gchar * | |
513 | vik_map_source_default_get_hostname( VikMapSourceDefault *self ) | |
514 | { | |
515 | VikMapSourceDefaultClass *klass; | |
516 | g_return_val_if_fail (self != NULL, 0); | |
517 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT (self), 0); | |
518 | klass = VIK_MAP_SOURCE_DEFAULT_GET_CLASS(self); | |
519 | ||
520 | g_return_val_if_fail (klass->get_hostname != NULL, 0); | |
521 | ||
522 | return (*klass->get_hostname)(self); | |
523 | } | |
524 | ||
686baff0 | 525 | DownloadFileOptions * |
f66ea3ec GB |
526 | vik_map_source_default_get_download_options( VikMapSourceDefault *self ) |
527 | { | |
528 | VikMapSourceDefaultClass *klass; | |
529 | g_return_val_if_fail (self != NULL, 0); | |
530 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT (self), 0); | |
531 | klass = VIK_MAP_SOURCE_DEFAULT_GET_CLASS(self); | |
532 | ||
533 | g_return_val_if_fail (klass->get_download_options != NULL, 0); | |
534 | ||
535 | return (*klass->get_download_options)(self); | |
536 | } | |
717db381 RN |
537 | |
538 | gchar * | |
539 | vik_map_source_default_get_url_display( VikMapSourceDefault *self, MapCoord *src ) | |
540 | { | |
541 | VikMapSourceDefaultClass *klass; | |
542 | g_return_val_if_fail (self != NULL, 0); | |
543 | g_return_val_if_fail (VIK_IS_MAP_SOURCE_DEFAULT (self), 0); | |
544 | klass = VIK_MAP_SOURCE_DEFAULT_GET_CLASS(self); | |
545 | ||
546 | g_return_val_if_fail (klass->get_uri != NULL, 0); | |
547 | g_return_val_if_fail (klass->get_hostname != NULL, 0); | |
548 | ||
549 | gchar *newstr = NULL; | |
550 | gchar *hostname = (*klass->get_hostname)(self); | |
551 | gchar *url = (*klass->get_uri)(self, src); | |
552 | if ( hostname && strlen(hostname)>1 ) { | |
553 | if ( strstr (hostname, "://") == NULL ) { | |
554 | //prepend http | |
555 | newstr = g_strdup_printf ( "http://%s", hostname ); | |
556 | } | |
557 | else { | |
558 | newstr = g_strdup ( hostname ); | |
559 | } | |
560 | } | |
561 | if ( url && strlen(url)>1 ) { | |
562 | if ( newstr ) { | |
563 | gchar *tmp = g_strdup ( newstr ); | |
564 | newstr = g_strdup_printf ( "%s%s", newstr, url ); | |
565 | g_free ( tmp ); | |
566 | } | |
567 | else { | |
568 | newstr = g_strdup ( url ); | |
569 | } | |
570 | } | |
571 | ||
572 | return newstr; | |
573 | } |