]>
Commit | Line | Data |
---|---|---|
357695f1 GB |
1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ |
2 | /* | |
3 | * viking | |
a482007a | 4 | * Copyright (C) 2009, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> |
357695f1 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 | */ | |
aa69d106 GB |
19 | |
20 | /** | |
21 | * SECTION:vikmaptype | |
22 | * @short_description: the adapter class to support old map source declaration | |
23 | * | |
24 | * The #VikMapType class handles is an adapter to allow to reuse | |
25 | * old map source (see #VikMapsLayer_MapType). | |
26 | */ | |
27 | ||
357695f1 GB |
28 | #ifdef HAVE_CONFIG_H |
29 | #include "config.h" | |
30 | #endif | |
31 | ||
32 | #include "vikmaptype.h" | |
33 | #include "vikmapslayer_compat.h" | |
4e815e90 | 34 | #include "download.h" |
357695f1 | 35 | |
2eb18edc | 36 | static const gchar *map_type_get_name (VikMapSource *self); |
d7e495b2 | 37 | static guint16 map_type_get_uniq_id (VikMapSource *self); |
608d87ec GB |
38 | static const gchar *map_type_get_label (VikMapSource *self); |
39 | static guint16 map_type_get_tilesize_x (VikMapSource *self); | |
40 | static guint16 map_type_get_tilesize_y (VikMapSource *self); | |
41 | static VikViewportDrawMode map_type_get_drawmode (VikMapSource *self); | |
357695f1 GB |
42 | static gboolean map_type_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ); |
43 | static void map_type_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest); | |
4e815e90 | 44 | static DownloadResult_t map_type_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void * handle); |
825413ba SW |
45 | static void * map_type_download_handle_init (VikMapSource * self); |
46 | static void map_type_download_handle_cleanup (VikMapSource * self, void * handle); | |
357695f1 GB |
47 | |
48 | typedef struct _VikMapTypePrivate VikMapTypePrivate; | |
49 | struct _VikMapTypePrivate | |
50 | { | |
db03733a | 51 | gchar *label; |
2eb18edc | 52 | gchar *name; |
357695f1 GB |
53 | VikMapsLayer_MapType map_type; |
54 | }; | |
55 | ||
56 | #define VIK_MAP_TYPE_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIK_TYPE_MAP_TYPE, VikMapTypePrivate)) | |
57 | ||
58 | ||
59 | G_DEFINE_TYPE (VikMapType, vik_map_type, VIK_TYPE_MAP_SOURCE); | |
60 | ||
61 | static void | |
62 | vik_map_type_init (VikMapType *object) | |
63 | { | |
db03733a GB |
64 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(object); |
65 | priv->label = NULL; | |
2eb18edc | 66 | priv->name = NULL; |
357695f1 GB |
67 | } |
68 | ||
69 | VikMapType * | |
db03733a | 70 | vik_map_type_new_with_id (VikMapsLayer_MapType map_type, const char *label) |
357695f1 GB |
71 | { |
72 | VikMapType *ret = (VikMapType *)g_object_new(vik_map_type_get_type(), NULL); | |
73 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(ret); | |
74 | priv->map_type = map_type; | |
db03733a | 75 | priv->label = g_strdup (label); |
357695f1 GB |
76 | return ret; |
77 | } | |
78 | ||
79 | static void | |
80 | vik_map_type_finalize (GObject *object) | |
81 | { | |
db03733a GB |
82 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(object); |
83 | g_free (priv->label); | |
84 | priv->label = NULL; | |
357695f1 GB |
85 | |
86 | G_OBJECT_CLASS (vik_map_type_parent_class)->finalize (object); | |
87 | } | |
88 | ||
89 | static void | |
90 | vik_map_type_class_init (VikMapTypeClass *klass) | |
91 | { | |
92 | GObjectClass* object_class = G_OBJECT_CLASS (klass); | |
93 | VikMapSourceClass* parent_class = VIK_MAP_SOURCE_CLASS (klass); | |
94 | ||
95 | /* Overiding methods */ | |
2eb18edc | 96 | parent_class->get_name = map_type_get_name; |
608d87ec GB |
97 | parent_class->get_uniq_id = map_type_get_uniq_id; |
98 | parent_class->get_label = map_type_get_label; | |
99 | parent_class->get_tilesize_x = map_type_get_tilesize_x; | |
100 | parent_class->get_tilesize_y = map_type_get_tilesize_y; | |
101 | parent_class->get_drawmode = map_type_get_drawmode; | |
357695f1 GB |
102 | parent_class->coord_to_mapcoord = map_type_coord_to_mapcoord; |
103 | parent_class->mapcoord_to_center_coord = map_type_mapcoord_to_center_coord; | |
104 | parent_class->download = map_type_download; | |
825413ba SW |
105 | parent_class->download_handle_init = map_type_download_handle_init; |
106 | parent_class->download_handle_cleanup = map_type_download_handle_cleanup; | |
357695f1 GB |
107 | |
108 | g_type_class_add_private (klass, sizeof (VikMapTypePrivate)); | |
109 | ||
110 | object_class->finalize = vik_map_type_finalize; | |
111 | } | |
112 | ||
2eb18edc RN |
113 | static const gchar * |
114 | map_type_get_name (VikMapSource *self) | |
115 | { | |
116 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
117 | g_return_val_if_fail (priv != NULL, NULL); | |
118 | ||
119 | return priv->name; | |
120 | } | |
121 | ||
d7e495b2 | 122 | static guint16 |
608d87ec GB |
123 | map_type_get_uniq_id (VikMapSource *self) |
124 | { | |
125 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
d7e495b2 | 126 | g_return_val_if_fail (priv != NULL, (guint16)0); |
608d87ec GB |
127 | |
128 | return priv->map_type.uniq_id; | |
129 | } | |
130 | ||
131 | static const gchar * | |
132 | map_type_get_label (VikMapSource *self) | |
133 | { | |
134 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
135 | g_return_val_if_fail (priv != NULL, FALSE); | |
136 | ||
137 | return priv->label; | |
138 | } | |
139 | ||
140 | static guint16 | |
141 | map_type_get_tilesize_x (VikMapSource *self) | |
142 | { | |
143 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
144 | g_return_val_if_fail (priv != NULL, (guint16)0); | |
145 | ||
146 | return priv->map_type.tilesize_x; | |
147 | } | |
148 | ||
149 | static guint16 | |
150 | map_type_get_tilesize_y (VikMapSource *self) | |
151 | { | |
152 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
153 | g_return_val_if_fail (priv != NULL, (guint16)0); | |
154 | ||
155 | return priv->map_type.tilesize_y; | |
156 | } | |
157 | ||
158 | static VikViewportDrawMode | |
159 | map_type_get_drawmode (VikMapSource *self) | |
160 | { | |
161 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
162 | g_return_val_if_fail (priv != NULL, (VikViewportDrawMode)0); | |
163 | ||
164 | return priv->map_type.drawmode; | |
165 | } | |
166 | ||
357695f1 GB |
167 | static gboolean |
168 | map_type_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ) | |
169 | { | |
170 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
171 | g_return_val_if_fail (priv != NULL, FALSE); | |
172 | ||
173 | return (priv->map_type.coord_to_mapcoord)(src, xzoom, yzoom, dest); | |
174 | } | |
175 | ||
176 | static void | |
177 | map_type_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest) | |
178 | { | |
179 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
180 | g_return_if_fail (self != NULL); | |
181 | ||
fb32d6d8 | 182 | (priv->map_type.mapcoord_to_center_coord)(src, dest); |
357695f1 GB |
183 | } |
184 | ||
4e815e90 | 185 | static DownloadResult_t |
825413ba | 186 | map_type_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn, void * handle) |
357695f1 GB |
187 | { |
188 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
189 | g_return_val_if_fail (priv != NULL, 0); | |
190 | ||
825413ba SW |
191 | return (priv->map_type.download)(src, dest_fn, handle); |
192 | } | |
193 | ||
194 | static void * | |
195 | map_type_download_handle_init (VikMapSource * self) | |
196 | { | |
197 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
198 | g_return_val_if_fail (priv != NULL, 0); | |
199 | ||
200 | return (priv->map_type.download_handle_init)(); | |
201 | } | |
202 | ||
203 | static void | |
204 | map_type_download_handle_cleanup (VikMapSource * self, void * handle) | |
205 | { | |
206 | VikMapTypePrivate *priv = VIK_MAP_TYPE_PRIVATE(self); | |
fb32d6d8 | 207 | g_return_if_fail ( priv != NULL ); |
825413ba | 208 | |
fb32d6d8 | 209 | (priv->map_type.download_handle_cleanup)(handle); |
357695f1 | 210 | } |