1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) 2009-2010, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
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.
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.
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/>.
21 * SECTION:vikmapsource
22 * @short_description: the base class to describe map source
24 * The #VikMapSource class is both the interface and the base class
25 * for the hierarchie of map source.
31 #include "vikviewport.h"
35 #include "vikmapsource.h"
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);
41 static gboolean _supports_download_only_new (VikMapSource *object);
43 G_DEFINE_TYPE_EXTENDED (VikMapSource, vik_map_source, G_TYPE_OBJECT, (GTypeFlags)G_TYPE_FLAG_ABSTRACT,);
46 vik_map_source_init (VikMapSource *object)
48 /* TODO: Add initialization code here */
52 vik_map_source_finalize (GObject *object)
54 /* TODO: Add deinitalization code here */
56 G_OBJECT_CLASS (vik_map_source_parent_class)->finalize (object);
60 vik_map_source_class_init (VikMapSourceClass *klass)
62 GObjectClass* object_class = G_OBJECT_CLASS (klass);
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->supports_download_only_new = _supports_download_only_new;
74 klass->coord_to_mapcoord = NULL;
75 klass->mapcoord_to_center_coord = NULL;
76 klass->download = NULL;
77 klass->download_handle_init = NULL;
78 klass->download_handle_cleanup = NULL;
80 object_class->finalize = vik_map_source_finalize;
84 _supports_download_only_new (VikMapSource *self)
86 // Default feature: does not support
91 * vik_map_source_get_copyright:
92 * @self: the VikMapSource of interest.
93 * @bbox: bounding box of interest.
94 * @zoom: the zoom level of interest.
95 * @fct: the callback function to use to return matching copyrights.
96 * @data: the user data to use to call the callbaack function.
98 * Retrieve copyright(s) for the corresponding bounding box and zoom level.
101 vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data)
103 VikMapSourceClass *klass;
104 g_return_if_fail (self != NULL);
105 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
106 klass = VIK_MAP_SOURCE_GET_CLASS(self);
108 g_return_if_fail (klass->get_copyright != NULL);
110 (*klass->get_copyright)(self, bbox, zoom, fct, data);
114 vik_map_source_get_license (VikMapSource *self)
116 VikMapSourceClass *klass;
117 g_return_val_if_fail (self != NULL, NULL);
118 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
119 klass = VIK_MAP_SOURCE_GET_CLASS(self);
121 g_return_val_if_fail (klass->get_license != NULL, NULL);
123 return (*klass->get_license)(self);
127 vik_map_source_get_license_url (VikMapSource *self)
129 VikMapSourceClass *klass;
130 g_return_val_if_fail (self != NULL, NULL);
131 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
132 klass = VIK_MAP_SOURCE_GET_CLASS(self);
134 g_return_val_if_fail (klass->get_license_url != NULL, NULL);
136 return (*klass->get_license_url)(self);
140 vik_map_source_get_logo (VikMapSource *self)
142 VikMapSourceClass *klass;
143 g_return_val_if_fail (self != NULL, NULL);
144 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
145 klass = VIK_MAP_SOURCE_GET_CLASS(self);
147 g_return_val_if_fail (klass->get_logo != NULL, NULL);
149 return (*klass->get_logo)(self);
153 vik_map_source_get_uniq_id (VikMapSource *self)
155 VikMapSourceClass *klass;
156 g_return_val_if_fail (self != NULL, (guint8 )0);
157 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint8 )0);
158 klass = VIK_MAP_SOURCE_GET_CLASS(self);
160 g_return_val_if_fail (klass->get_uniq_id != NULL, (guint8 )0);
162 return (*klass->get_uniq_id)(self);
166 vik_map_source_get_label (VikMapSource *self)
168 VikMapSourceClass *klass;
169 g_return_val_if_fail (self != NULL, NULL);
170 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
171 klass = VIK_MAP_SOURCE_GET_CLASS(self);
173 g_return_val_if_fail (klass->get_label != NULL, NULL);
175 return (*klass->get_label)(self);
179 vik_map_source_get_tilesize_x (VikMapSource *self)
181 VikMapSourceClass *klass;
182 g_return_val_if_fail (self != NULL, (guint16 )0);
183 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
184 klass = VIK_MAP_SOURCE_GET_CLASS(self);
186 g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0);
188 return (*klass->get_tilesize_x)(self);
192 vik_map_source_get_tilesize_y (VikMapSource *self)
194 VikMapSourceClass *klass;
195 g_return_val_if_fail (self != NULL, (guint16 )0);
196 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
197 klass = VIK_MAP_SOURCE_GET_CLASS(self);
199 g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0);
201 return (*klass->get_tilesize_y)(self);
205 vik_map_source_get_drawmode (VikMapSource *self)
207 VikMapSourceClass *klass;
208 g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0);
209 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0);
210 klass = VIK_MAP_SOURCE_GET_CLASS(self);
212 g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0);
214 return (*klass->get_drawmode)(self);
218 vik_map_source_supports_download_only_new (VikMapSource * self)
220 VikMapSourceClass *klass;
221 g_return_val_if_fail (self != NULL, 0);
222 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
223 klass = VIK_MAP_SOURCE_GET_CLASS(self);
225 g_return_val_if_fail (klass->supports_download_only_new != NULL, 0);
227 return (*klass->supports_download_only_new)(self);
231 vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
233 VikMapSourceClass *klass;
234 g_return_val_if_fail (self != NULL, FALSE);
235 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE);
236 klass = VIK_MAP_SOURCE_GET_CLASS(self);
238 g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE);
240 return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest);
244 vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
246 VikMapSourceClass *klass;
247 g_return_if_fail (self != NULL);
248 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
249 klass = VIK_MAP_SOURCE_GET_CLASS(self);
251 g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
253 (*klass->mapcoord_to_center_coord)(self, src, dest);
257 vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle)
259 VikMapSourceClass *klass;
260 g_return_val_if_fail (self != NULL, 0);
261 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
262 klass = VIK_MAP_SOURCE_GET_CLASS(self);
264 g_return_val_if_fail (klass->download != NULL, 0);
266 return (*klass->download)(self, src, dest_fn, handle);
270 vik_map_source_download_handle_init (VikMapSource *self)
272 VikMapSourceClass *klass;
273 g_return_val_if_fail (self != NULL, 0);
274 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
275 klass = VIK_MAP_SOURCE_GET_CLASS(self);
277 g_return_val_if_fail (klass->download_handle_init != NULL, 0);
279 return (*klass->download_handle_init)(self);
283 vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle)
285 VikMapSourceClass *klass;
286 g_return_if_fail (self != NULL);
287 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
288 klass = VIK_MAP_SOURCE_GET_CLASS(self);
290 g_return_if_fail (klass->download_handle_cleanup != NULL);
292 (*klass->download_handle_cleanup)(self, handle);