]> git.street.me.uk Git - andy/viking.git/blame_incremental - src/vikmapsource.c
Fix printing of DEBUG message since glib 2.32
[andy/viking.git] / src / vikmapsource.c
... / ...
CommitLineData
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
37static void vik_map_source_init (VikMapSource *object);
38static void vik_map_source_finalize (GObject *object);
39static void vik_map_source_class_init (VikMapSourceClass *klass);
40
41static gboolean _supports_download_only_new (VikMapSource *object);
42
43G_DEFINE_TYPE_EXTENDED (VikMapSource, vik_map_source, G_TYPE_OBJECT, (GTypeFlags)G_TYPE_FLAG_ABSTRACT,);
44
45static void
46vik_map_source_init (VikMapSource *object)
47{
48 /* TODO: Add initialization code here */
49}
50
51static void
52vik_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
59static void
60vik_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->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;
79
80 object_class->finalize = vik_map_source_finalize;
81}
82
83gboolean
84_supports_download_only_new (VikMapSource *self)
85{
86 // Default feature: does not support
87 return FALSE;
88}
89
90/**
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.
97 *
98 * Retrieve copyright(s) for the corresponding bounding box and zoom level.
99 */
100void
101vik_map_source_get_copyright (VikMapSource *self, LatLonBBox bbox, gdouble zoom, void (*fct)(VikViewport*,const gchar*), void *data)
102{
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);
107
108 g_return_if_fail (klass->get_copyright != NULL);
109
110 (*klass->get_copyright)(self, bbox, zoom, fct, data);
111}
112
113const gchar *
114vik_map_source_get_license (VikMapSource *self)
115{
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);
120
121 g_return_val_if_fail (klass->get_license != NULL, NULL);
122
123 return (*klass->get_license)(self);
124}
125
126const gchar *
127vik_map_source_get_license_url (VikMapSource *self)
128{
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);
133
134 g_return_val_if_fail (klass->get_license_url != NULL, NULL);
135
136 return (*klass->get_license_url)(self);
137}
138
139const GdkPixbuf *
140vik_map_source_get_logo (VikMapSource *self)
141{
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);
146
147 g_return_val_if_fail (klass->get_logo != NULL, NULL);
148
149 return (*klass->get_logo)(self);
150}
151
152guint8
153vik_map_source_get_uniq_id (VikMapSource *self)
154{
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);
159
160 g_return_val_if_fail (klass->get_uniq_id != NULL, (guint8 )0);
161
162 return (*klass->get_uniq_id)(self);
163}
164
165const gchar *
166vik_map_source_get_label (VikMapSource *self)
167{
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);
172
173 g_return_val_if_fail (klass->get_label != NULL, NULL);
174
175 return (*klass->get_label)(self);
176}
177
178guint16
179vik_map_source_get_tilesize_x (VikMapSource *self)
180{
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);
185
186 g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0);
187
188 return (*klass->get_tilesize_x)(self);
189}
190
191guint16
192vik_map_source_get_tilesize_y (VikMapSource *self)
193{
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);
198
199 g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0);
200
201 return (*klass->get_tilesize_y)(self);
202}
203
204VikViewportDrawMode
205vik_map_source_get_drawmode (VikMapSource *self)
206{
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);
211
212 g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0);
213
214 return (*klass->get_drawmode)(self);
215}
216
217gboolean
218vik_map_source_supports_download_only_new (VikMapSource * self)
219{
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);
224
225 g_return_val_if_fail (klass->supports_download_only_new != NULL, 0);
226
227 return (*klass->supports_download_only_new)(self);
228}
229
230gboolean
231vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
232{
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);
237
238 g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE);
239
240 return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest);
241}
242
243void
244vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
245{
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);
250
251 g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
252
253 (*klass->mapcoord_to_center_coord)(self, src, dest);
254}
255
256int
257vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle)
258{
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);
263
264 g_return_val_if_fail (klass->download != NULL, 0);
265
266 return (*klass->download)(self, src, dest_fn, handle);
267}
268
269void *
270vik_map_source_download_handle_init (VikMapSource *self)
271{
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);
276
277 g_return_val_if_fail (klass->download_handle_init != NULL, 0);
278
279 return (*klass->download_handle_init)(self);
280}
281
282void
283vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle)
284{
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);
289
290 g_return_if_fail (klass->download_handle_cleanup != NULL);
291
292 (*klass->download_handle_cleanup)(self, handle);
293}