]> git.street.me.uk Git - andy/viking.git/blame - src/vikmapsource.c
Fix: Correctly rotate thumbnail images
[andy/viking.git] / src / vikmapsource.c
CommitLineData
820c59f4
GB
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2/*
3 * viking
4 * Copyright (C) Guilhem Bonnefille 2009 <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#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
29static void vik_map_source_init (VikMapSource *object);
30static void vik_map_source_finalize (GObject *object);
31static void vik_map_source_class_init (VikMapSourceClass *klass);
32
0f08bd0d
GB
33static void _supports_if_modified_since (VikMapSource *object);
34
820c59f4
GB
35G_DEFINE_TYPE_EXTENDED (VikMapSource, vik_map_source, G_TYPE_OBJECT, (GTypeFlags)G_TYPE_FLAG_ABSTRACT,);
36
820c59f4
GB
37static void
38vik_map_source_init (VikMapSource *object)
39{
40 /* TODO: Add initialization code here */
41}
42
43static void
44vik_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
51static void
52vik_map_source_class_init (VikMapSourceClass *klass)
53{
54 GObjectClass* object_class = G_OBJECT_CLASS (klass);
55
56 klass->get_uniq_id = NULL;
db03733a 57 klass->get_label = NULL;
820c59f4
GB
58 klass->get_tilesize_x = NULL;
59 klass->get_tilesize_y = NULL;
60 klass->get_drawmode = NULL;
0f08bd0d 61 klass->supports_if_modified_since = _supports_if_modified_since;
820c59f4
GB
62 klass->coord_to_mapcoord = NULL;
63 klass->mapcoord_to_center_coord = NULL;
64 klass->download = NULL;
825413ba
SW
65 klass->download_handle_init = NULL;
66 klass->download_handle_cleanup = NULL;
820c59f4
GB
67
68 object_class->finalize = vik_map_source_finalize;
69}
70
0f08bd0d
GB
71void
72_supports_if_modified_since (VikMapSource *self)
73{
74 // Default feature: does not support
75 return FALSE;
76}
820c59f4
GB
77
78guint8
79vik_map_source_get_uniq_id (VikMapSource *self)
80{
81 VikMapSourceClass *klass;
82 g_return_val_if_fail (self != NULL, (guint8 )0);
83 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint8 )0);
84 klass = VIK_MAP_SOURCE_GET_CLASS(self);
85
86 g_return_val_if_fail (klass->get_uniq_id != NULL, (guint8 )0);
87
88 return (*klass->get_uniq_id)(self);
89}
90
db03733a
GB
91const gchar *
92vik_map_source_get_label (VikMapSource *self)
93{
94 VikMapSourceClass *klass;
95 g_return_val_if_fail (self != NULL, NULL);
96 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
97 klass = VIK_MAP_SOURCE_GET_CLASS(self);
98
99 g_return_val_if_fail (klass->get_label != NULL, NULL);
100
101 return (*klass->get_label)(self);
102}
103
820c59f4
GB
104guint16
105vik_map_source_get_tilesize_x (VikMapSource *self)
106{
107 VikMapSourceClass *klass;
108 g_return_val_if_fail (self != NULL, (guint16 )0);
109 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
110 klass = VIK_MAP_SOURCE_GET_CLASS(self);
111
112 g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0);
113
114 return (*klass->get_tilesize_x)(self);
115}
116
117guint16
118vik_map_source_get_tilesize_y (VikMapSource *self)
119{
120 VikMapSourceClass *klass;
121 g_return_val_if_fail (self != NULL, (guint16 )0);
122 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
123 klass = VIK_MAP_SOURCE_GET_CLASS(self);
124
125 g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0);
126
127 return (*klass->get_tilesize_y)(self);
128}
129
130VikViewportDrawMode
131vik_map_source_get_drawmode (VikMapSource *self)
132{
133 VikMapSourceClass *klass;
134 g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0);
135 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0);
136 klass = VIK_MAP_SOURCE_GET_CLASS(self);
137
138 g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0);
139
140 return (*klass->get_drawmode)(self);
141}
142
0f08bd0d
GB
143gboolean
144vik_map_source_supports_if_modified_since (VikMapSource * self)
145{
146 VikMapSourceClass *klass;
147 g_return_val_if_fail (self != NULL, 0);
148 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
149 klass = VIK_MAP_SOURCE_GET_CLASS(self);
150
151 g_return_val_if_fail (klass->supports_if_modified_since != NULL, 0);
152
153 return (*klass->supports_if_modified_since)(self);
154}
155
820c59f4
GB
156gboolean
157vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
158{
159 VikMapSourceClass *klass;
160 g_return_val_if_fail (self != NULL, FALSE);
161 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE);
162 klass = VIK_MAP_SOURCE_GET_CLASS(self);
163
164 g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE);
165
166 return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest);
167}
168
169void
170vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
171{
172 VikMapSourceClass *klass;
173 g_return_if_fail (self != NULL);
174 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
175 klass = VIK_MAP_SOURCE_GET_CLASS(self);
176
177 g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
178
179 return (*klass->mapcoord_to_center_coord)(self, src, dest);
180}
181
182int
825413ba 183vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void *handle)
820c59f4
GB
184{
185 VikMapSourceClass *klass;
186 g_return_val_if_fail (self != NULL, 0);
187 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
188 klass = VIK_MAP_SOURCE_GET_CLASS(self);
189
190 g_return_val_if_fail (klass->download != NULL, 0);
191
825413ba
SW
192 return (*klass->download)(self, src, dest_fn, handle);
193}
194
195void *
196vik_map_source_download_handle_init (VikMapSource *self)
197{
198 VikMapSourceClass *klass;
199 g_return_val_if_fail (self != NULL, 0);
200 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
201 klass = VIK_MAP_SOURCE_GET_CLASS(self);
202
203 g_return_val_if_fail (klass->download_handle_init != NULL, 0);
204
205 return (*klass->download_handle_init)(self);
206}
207
208void
209vik_map_source_download_handle_cleanup (VikMapSource * self, void * handle)
210{
211 VikMapSourceClass *klass;
212 g_return_val_if_fail (self != NULL, 0);
213 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
214 klass = VIK_MAP_SOURCE_GET_CLASS(self);
215
216 g_return_val_if_fail (klass->download_handle_cleanup != NULL, 0);
217
218 return (*klass->download_handle_cleanup)(self, handle);
820c59f4 219}