4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7 * Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 #include "location-map-types.h"
28 #include "map-service.h"
29 #include "location-map-pref.h"
31 struct _LocationMapPref {
32 gchar *provider_name; ///< Name of the service provier
33 gchar *language; ///< Language of the service preference.
34 gchar *country; ///< Country of the service preference.
35 gchar *distance_unit; ///< Distance unit of the service preference.
36 GHashTable *properties; ///< properties of the service preference.
40 location_map_pref_get_property_key (const LocationMapPref *pref)
42 g_return_val_if_fail (pref, NULL);
44 if (!pref->properties) return NULL;
46 return g_hash_table_get_keys (pref->properties);
50 location_map_pref_get_language (const LocationMapPref *pref)
52 g_return_val_if_fail (pref, NULL);
54 return pref->language;
58 location_map_pref_get_country (const LocationMapPref *pref)
60 g_return_val_if_fail (pref, NULL);
66 location_map_pref_get_distance_unit (const LocationMapPref *pref)
68 g_return_val_if_fail (pref, NULL);
70 return pref->distance_unit;
73 EXPORT_API gconstpointer
74 location_map_pref_get_property (const LocationMapPref *pref, gconstpointer key)
76 g_return_val_if_fail (pref, NULL);
77 g_return_val_if_fail (key, NULL);
78 if (!pref->properties) return NULL;
80 return (gconstpointer) g_hash_table_lookup (pref->properties, key);
84 location_map_pref_get_provider_name (const LocationMapPref *pref)
86 g_return_val_if_fail (pref, NULL);
88 return pref->provider_name;
92 location_map_pref_set_provider_name (LocationMapPref *pref, const gchar *name)
94 g_return_val_if_fail (pref, FALSE);
96 if (pref->provider_name) {
97 g_free (pref->provider_name);
98 pref->provider_name = NULL;
101 if (name) pref->provider_name = g_strdup ((gchar *)name);
107 location_map_pref_set_language (LocationMapPref *pref, const gchar * language)
109 g_return_val_if_fail (pref, FALSE);
111 if (pref->language) {
112 g_free (pref->language);
113 pref->language = NULL;
116 if (language) pref->language = g_strdup(language);
122 location_map_pref_set_country (LocationMapPref *pref, const gchar *country)
124 g_return_val_if_fail (pref, FALSE);
127 g_free (pref->country);
128 pref->country = NULL;
131 if (country) pref->country = g_strdup(country);
138 location_map_pref_set_distance_unit (LocationMapPref *pref, const gchar * unit)
140 g_return_val_if_fail (pref, FALSE);
142 if (pref->distance_unit) {
143 g_free (pref->distance_unit);
144 pref->distance_unit = NULL;
147 if (unit) pref->distance_unit = g_strdup (unit);
153 location_map_pref_set_property (LocationMapPref *pref, gconstpointer key, gconstpointer value)
155 g_return_val_if_fail (pref, FALSE);
156 g_return_val_if_fail (key, FALSE);
157 if (!pref->properties) return FALSE;
160 gchar *re_key = g_strdup (key);
161 gchar *re_val = g_strdup (value);
162 g_hash_table_insert (pref->properties, re_key, re_val);
163 } else g_hash_table_remove (pref->properties, key);
168 EXPORT_API LocationMapPref *
169 location_map_pref_new (void)
171 LocationMapPref *pref = g_slice_new0(LocationMapPref);
172 if (!pref) return NULL;
174 pref->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
179 static void property_copy (gpointer key, gpointer value, gpointer user_data)
181 g_return_if_fail (key);
182 g_return_if_fail (value);
183 g_return_if_fail (user_data);
185 GHashTable *properties = (GHashTable *) user_data;
187 gchar *re_key = g_strdup (key);
188 gchar *re_val = g_strdup (value);
189 g_hash_table_insert (properties, re_key, re_val);
192 EXPORT_API LocationMapPref *
193 location_map_pref_copy (LocationMapPref *pref)
195 g_return_val_if_fail (pref, NULL);
197 LocationMapPref *new_pref = location_map_pref_new();
198 if (!new_pref) return NULL;
200 location_map_pref_set_provider_name (new_pref, location_map_pref_get_provider_name(pref));
201 location_map_pref_set_language (new_pref, location_map_pref_get_language(pref));
202 location_map_pref_set_distance_unit (new_pref, location_map_pref_get_distance_unit(pref));
205 g_hash_table_foreach (pref->properties, property_copy, new_pref->properties);
211 location_map_pref_free (LocationMapPref * pref)
213 g_return_if_fail(pref);
215 location_map_pref_set_provider_name (pref, NULL);
216 location_map_pref_set_language (pref, NULL);
217 location_map_pref_set_distance_unit (pref, NULL);
218 g_hash_table_destroy (pref->properties);
220 g_slice_free (LocationMapPref, pref);