]>
Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
0f08bd0d GB |
33 | static void _supports_if_modified_since (VikMapSource *object); |
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 | ||
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; | |
65 | ||
66 | object_class->finalize = vik_map_source_finalize; | |
67 | } | |
68 | ||
0f08bd0d GB |
69 | void |
70 | _supports_if_modified_since (VikMapSource *self) | |
71 | { | |
72 | // Default feature: does not support | |
73 | return FALSE; | |
74 | } | |
820c59f4 GB |
75 | |
76 | guint8 | |
77 | vik_map_source_get_uniq_id (VikMapSource *self) | |
78 | { | |
79 | VikMapSourceClass *klass; | |
80 | g_return_val_if_fail (self != NULL, (guint8 )0); | |
81 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint8 )0); | |
82 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
83 | ||
84 | g_return_val_if_fail (klass->get_uniq_id != NULL, (guint8 )0); | |
85 | ||
86 | return (*klass->get_uniq_id)(self); | |
87 | } | |
88 | ||
db03733a GB |
89 | const gchar * |
90 | vik_map_source_get_label (VikMapSource *self) | |
91 | { | |
92 | VikMapSourceClass *klass; | |
93 | g_return_val_if_fail (self != NULL, NULL); | |
94 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL); | |
95 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
96 | ||
97 | g_return_val_if_fail (klass->get_label != NULL, NULL); | |
98 | ||
99 | return (*klass->get_label)(self); | |
100 | } | |
101 | ||
820c59f4 GB |
102 | guint16 |
103 | vik_map_source_get_tilesize_x (VikMapSource *self) | |
104 | { | |
105 | VikMapSourceClass *klass; | |
106 | g_return_val_if_fail (self != NULL, (guint16 )0); | |
107 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0); | |
108 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
109 | ||
110 | g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0); | |
111 | ||
112 | return (*klass->get_tilesize_x)(self); | |
113 | } | |
114 | ||
115 | guint16 | |
116 | vik_map_source_get_tilesize_y (VikMapSource *self) | |
117 | { | |
118 | VikMapSourceClass *klass; | |
119 | g_return_val_if_fail (self != NULL, (guint16 )0); | |
120 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0); | |
121 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
122 | ||
123 | g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0); | |
124 | ||
125 | return (*klass->get_tilesize_y)(self); | |
126 | } | |
127 | ||
128 | VikViewportDrawMode | |
129 | vik_map_source_get_drawmode (VikMapSource *self) | |
130 | { | |
131 | VikMapSourceClass *klass; | |
132 | g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0); | |
133 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0); | |
134 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
135 | ||
136 | g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0); | |
137 | ||
138 | return (*klass->get_drawmode)(self); | |
139 | } | |
140 | ||
0f08bd0d GB |
141 | gboolean |
142 | vik_map_source_supports_if_modified_since (VikMapSource * self) | |
143 | { | |
144 | VikMapSourceClass *klass; | |
145 | g_return_val_if_fail (self != NULL, 0); | |
146 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
147 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
148 | ||
149 | g_return_val_if_fail (klass->supports_if_modified_since != NULL, 0); | |
150 | ||
151 | return (*klass->supports_if_modified_since)(self); | |
152 | } | |
153 | ||
820c59f4 GB |
154 | gboolean |
155 | vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ) | |
156 | { | |
157 | VikMapSourceClass *klass; | |
158 | g_return_val_if_fail (self != NULL, FALSE); | |
159 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE); | |
160 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
161 | ||
162 | g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE); | |
163 | ||
164 | return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest); | |
165 | } | |
166 | ||
167 | void | |
168 | vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest) | |
169 | { | |
170 | VikMapSourceClass *klass; | |
171 | g_return_if_fail (self != NULL); | |
172 | g_return_if_fail (VIK_IS_MAP_SOURCE (self)); | |
173 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
174 | ||
175 | g_return_if_fail (klass->mapcoord_to_center_coord != NULL); | |
176 | ||
177 | return (*klass->mapcoord_to_center_coord)(self, src, dest); | |
178 | } | |
179 | ||
180 | int | |
181 | vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn) | |
182 | { | |
183 | VikMapSourceClass *klass; | |
184 | g_return_val_if_fail (self != NULL, 0); | |
185 | g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0); | |
186 | klass = VIK_MAP_SOURCE_GET_CLASS(self); | |
187 | ||
188 | g_return_val_if_fail (klass->download != NULL, 0); | |
189 | ||
190 | return (*klass->download)(self, src, dest_fn); | |
191 | } |