]>
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 | */ | |
19 | #ifdef HAVE_CONFIG_H | |
20 | #include "config.h" | |
21 | #endif | |
22 | ||
23 | #include "vikviewport.h" | |
24 | #include "vikcoord.h" | |
25 | #include "mapcoord.h" | |
26 | ||
27 | #include "vikmapsource.h" | |
28 | ||
29 | static void vik_map_source_init (VikMapSource *object); | |
30 | static void vik_map_source_finalize (GObject *object); | |
31 | static void vik_map_source_class_init (VikMapSourceClass *klass); | |
32 | ||
c81ded98 | 33 | static gboolean _supports_download_only_new (VikMapSource *object); |
0f08bd0d | 34 | |
820c59f4 GB |
35 | G_DEFINE_TYPE_EXTENDED (VikMapSource, vik_map_source, G_TYPE_OBJECT, (GTypeFlags)G_TYPE_FLAG_ABSTRACT,); |
36 | ||
820c59f4 GB |
37 | static void |
38 | vik_map_source_init (VikMapSource *object) | |
39 | { | |
40 | /* TODO: Add initialization code here */ | |
41 | } | |
42 | ||
43 | static void | |
44 | vik_map_source_finalize (GObject *object) | |
45 | { | |
46 | /* TODO: Add deinitalization code here */ | |
47 | ||
48 | G_OBJECT_CLASS (vik_map_source_parent_class)->finalize (object); | |
49 | } | |
50 | ||
51 | static void | |
52 | vik_map_source_class_init (VikMapSourceClass *klass) | |
53 | { | |
54 | GObjectClass* object_class = G_OBJECT_CLASS (klass); | |
55 | ||
82aa018d | 56 | klass->get_copyright = NULL; |
53ac8302 GB |
57 | klass->get_license = NULL; |
58 | klass->get_license_url = NULL; | |
820c59f4 | 59 | klass->get_uniq_id = NULL; |
db03733a | 60 | klass->get_label = NULL; |
820c59f4 GB |
61 | klass->get_tilesize_x = NULL; |
62 | klass->get_tilesize_y = NULL; | |
63 | klass->get_drawmode = NULL; | |
c81ded98 | 64 | klass->supports_download_only_new = _supports_download_only_new; |
820c59f4 GB |
65 | klass->coord_to_mapcoord = NULL; |
66 | klass->mapcoord_to_center_coord = NULL; | |
67 | klass->download = NULL; | |
825413ba SW |
68 | klass->download_handle_init = NULL; |
69 | klass->download_handle_cleanup = NULL; | |
820c59f4 GB |
70 | |
71 | object_class->finalize = vik_map_source_finalize; | |
72 | } | |
73 | ||
e8cf3d97 | 74 | gboolean |
c81ded98 | 75 | _supports_download_only_new (VikMapSource *self) |
0f08bd0d GB |
76 | { |
77 | // Default feature: does not support | |
78 | return FALSE; | |
79 | } | |
820c59f4 | 80 | |
82aa018d GB |
81 | const gchar * |
82 | vik_map_source_get_copyright (VikMapSource *self) | |
83 | { | |
84 | VikMapSourceClass *klass; | |
85 | g_return_val_if_fail (self != NULL, NULL); | |
86 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
87 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
88 | ||
89 | g_return_val_if_fail (klass->get_copyright != NULL, NULL); | |
90 | ||
91 | return (*klass->get_copyright)(self); | |
92 | } | |
93 | ||
53ac8302 GB |
94 | const gchar * |
95 | vik_map_source_get_license (VikMapSource *self) | |
96 | { | |
97 | VikMapSourceClass *klass; | |
98 | g_return_val_if_fail (self != NULL, NULL); | |
99 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
100 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
101 | ||
102 | g_return_val_if_fail (klass->get_license != NULL, NULL); | |
103 | ||
104 | return (*klass->get_license)(self); | |
105 | } | |
106 | ||
107 | const gchar * | |
108 | vik_map_source_get_license_url (VikMapSource *self) | |
109 | { | |
110 | VikMapSourceClass *klass; | |
111 | g_return_val_if_fail (self != NULL, NULL); | |
112 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
113 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
114 | ||
115 | g_return_val_if_fail (klass->get_license_url != NULL, NULL); | |
116 | ||
117 | return (*klass->get_license_url)(self); | |
118 | } | |
119 | ||
820c59f4 GB |
120 | guint8 |
121 | vik_map_source_get_uniq_id (VikMapSource *self) | |
122 | { | |
123 | VikMapSourceClass *klass; | |
124 | g_return_val_if_fail (self != NULL, (guint8 )0); | |
125 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint8 )0); | |
126 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
127 | ||
128 | g_return_val_if_fail (klass->get_uniq_id != NULL, (guint8 )0); | |
129 | ||
130 | return (*klass->get_uniq_id)(self); | |
131 | } | |
132 | ||
db03733a GB |
133 | const gchar * |
134 | vik_map_source_get_label (VikMapSource *self) | |
135 | { | |
136 | VikMapSourceClass *klass; | |
137 | g_return_val_if_fail (self != NULL, NULL); | |
138 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
139 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
140 | ||
141 | g_return_val_if_fail (klass->get_label != NULL, NULL); | |
142 | ||
143 | return (*klass->get_label)(self); | |
144 | } | |
145 | ||
820c59f4 GB |
146 | guint16 |
147 | vik_map_source_get_tilesize_x (VikMapSource *self) | |
148 | { | |
149 | VikMapSourceClass *klass; | |
150 | g_return_val_if_fail (self != NULL, (guint16 )0); | |
151 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0); | |
152 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
153 | ||
154 | g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0); | |
155 | ||
156 | return (*klass->get_tilesize_x)(self); | |
157 | } | |
158 | ||
159 | guint16 | |
160 | vik_map_source_get_tilesize_y (VikMapSource *self) | |
161 | { | |
162 | VikMapSourceClass *klass; | |
163 | g_return_val_if_fail (self != NULL, (guint16 )0); | |
164 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0); | |
165 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
166 | ||
167 | g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0); | |
168 | ||
169 | return (*klass->get_tilesize_y)(self); | |
170 | } | |
171 | ||
172 | VikViewportDrawMode | |
173 | vik_map_source_get_drawmode (VikMapSource *self) | |
174 | { | |
175 | VikMapSourceClass *klass; | |
176 | g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0); | |
177 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0); | |
178 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
179 | ||
180 | g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0); | |
181 | ||
182 | return (*klass->get_drawmode)(self); | |
183 | } | |
184 | ||
0f08bd0d | 185 | gboolean |
c81ded98 | 186 | vik_map_source_supports_download_only_new (VikMapSource * self) |
0f08bd0d GB |
187 | { |
188 | VikMapSourceClass *klass; | |
189 | g_return_val_if_fail (self != NULL, 0); | |
190 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
191 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
192 | ||
c81ded98 | 193 | g_return_val_if_fail (klass->supports_download_only_new != NULL, 0); |
0f08bd0d | 194 | |
c81ded98 | 195 | return (*klass->supports_download_only_new)(self); |
0f08bd0d GB |
196 | } |
197 | ||
820c59f4 GB |
198 | gboolean |
199 | vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ) | |
200 | { | |
201 | VikMapSourceClass *klass; | |
202 | g_return_val_if_fail (self != NULL, FALSE); | |
203 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE); | |
204 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
205 | ||
206 | g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE); | |
207 | ||
208 | return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest); | |
209 | } | |
210 | ||
211 | void | |
212 | vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest) | |
213 | { | |
214 | VikMapSourceClass *klass; | |
215 | g_return_if_fail (self != NULL); | |
216 | g_return_if_fail (VIK_IS_MAP_SOURCE (self)); | |
217 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
218 | ||
219 | g_return_if_fail (klass->mapcoord_to_center_coord != NULL); | |
220 | ||
41810542 | 221 | (*klass->mapcoord_to_center_coord)(self, src, dest); |
820c59f4 GB |
222 | } |
223 | ||
224 | int | |
825413ba | 225 | vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle) |
820c59f4 GB |
226 | { |
227 | VikMapSourceClass *klass; | |
228 | g_return_val_if_fail (self != NULL, 0); | |
229 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
230 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
231 | ||
232 | g_return_val_if_fail (klass->download != NULL, 0); | |
233 | ||
825413ba SW |
234 | return (*klass->download)(self, src, dest_fn, handle); |
235 | } | |
236 | ||
237 | void * | |
238 | vik_map_source_download_handle_init (VikMapSource *self) | |
239 | { | |
240 | VikMapSourceClass *klass; | |
241 | g_return_val_if_fail (self != NULL, 0); | |
242 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
243 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
244 | ||
245 | g_return_val_if_fail (klass->download_handle_init != NULL, 0); | |
246 | ||
247 | return (*klass->download_handle_init)(self); | |
248 | } | |
249 | ||
250 | void | |
251 | vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle) | |
252 | { | |
253 | VikMapSourceClass *klass; | |
2949dd77 GB |
254 | g_return_if_fail (self != NULL); |
255 | g_return_if_fail (VIK_IS_MAP_SOURCE (self)); | |
825413ba SW |
256 | klass = VIK_MAP_SOURCE_GET_CLASS(self); |
257 | ||
2949dd77 | 258 | g_return_if_fail (klass->download_handle_cleanup != NULL); |
825413ba | 259 | |
2949dd77 | 260 | (*klass->download_handle_cleanup)(self, handle); |
820c59f4 | 261 | } |