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.
26 #include "location-log.h"
27 #include "location-types.h"
28 #include "location-pref.h"
30 #include "map-service.h"
32 #include "location-poi.h"
34 struct _LocationPOIPreference {
35 guint max_result_cnt; ///< Maximum number of results
36 LocationPOIPrefSortOrder sort_order; ///< Sort order
37 gchar* item; ///< Sory by item
38 GHashTable *properties;
41 struct _LocationPOIFilter {
42 // "CATEGORY", "KEYWORD", "POINAME"
43 GHashTable *properties;
47 location_poi_pref_get_max_result (const LocationPOIPreference *pref)
49 g_return_val_if_fail(pref, 0);
51 return pref->max_result_cnt;
55 location_poi_pref_get_sort_by (const LocationPOIPreference *pref)
57 g_return_val_if_fail(pref, NULL);
62 EXPORT_API LocationPOIPrefSortOrder
63 location_poi_pref_get_sort_order (const LocationPOIPreference *pref)
65 g_return_val_if_fail(pref, LOCATION_POI_PRE_SO_NONE);
67 return pref->sort_order;
71 location_poi_pref_get_property_key (const LocationPOIPreference *pref)
73 g_return_val_if_fail (pref, NULL);
74 if (!pref->properties) return NULL;
76 return g_hash_table_get_keys (pref->properties);
80 location_poi_pref_get_property (const LocationPOIPreference *pref, gconstpointer key)
82 g_return_val_if_fail (pref, NULL);
83 g_return_val_if_fail (key, NULL);
85 if (!pref->properties) return NULL;
87 return g_hash_table_lookup (pref->properties, key);
92 location_poi_pref_set_max_result (LocationPOIPreference *pref, guint max_num)
94 g_return_val_if_fail(pref, FALSE);
95 g_return_val_if_fail(max_num > 0, FALSE);
97 pref->max_result_cnt = max_num;
103 location_poi_pref_set_sort_by(LocationPOIPreference * pref, const gchar * item)
105 g_return_val_if_fail(pref, FALSE);
112 if (item) pref->item = g_strdup(item);
118 location_poi_pref_set_sort_order (LocationPOIPreference *pref, LocationPOIPrefSortOrder sort_order)
120 g_return_val_if_fail(pref, FALSE);
122 if (sort_order < LOCATION_POI_PREF_SO_ASC || sort_order > LOCATION_POI_PREF_SO_DESC) return FALSE;
124 pref->sort_order = sort_order;
130 location_poi_pref_set_property (LocationPOIPreference *pref, gconstpointer key, gconstpointer value)
132 g_return_val_if_fail(pref, FALSE);
133 g_return_val_if_fail(key, FALSE);
134 g_return_val_if_fail(pref->properties, FALSE);
137 gchar *re_key = g_strdup (key);
138 gchar *re_val = g_strdup (value);
139 g_hash_table_insert (pref->properties, re_key, re_val);
140 } else g_hash_table_remove (pref->properties, key);
145 EXPORT_API LocationPOIPreference *
146 location_poi_pref_new (void)
148 LocationPOIPreference *pref = g_slice_new0 (LocationPOIPreference);
149 g_return_val_if_fail(pref, NULL);
151 pref->sort_order = LOCATION_POI_PREF_SO_ASC;
152 pref->max_result_cnt = 25;
153 pref->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
158 static void poi_pref_property_copy_cb (gpointer key, gpointer value, gpointer user_data)
160 g_return_if_fail (key);
161 g_return_if_fail (value);
162 g_return_if_fail (user_data);
164 LocationPOIPreference *pref = (LocationPOIPreference *) user_data;
165 if (pref->properties) {
166 gchar *re_key = g_strdup (key);
167 gchar *re_val = g_strdup (value);
168 g_hash_table_insert (pref->properties, re_key, re_val);
172 EXPORT_API LocationPOIPreference *
173 location_poi_pref_copy (LocationPOIPreference *pref)
175 LocationPOIPreference *new_pref = location_poi_pref_new();
176 g_return_val_if_fail (new_pref, NULL);
178 location_poi_pref_set_sort_by(new_pref, location_poi_pref_get_sort_by(pref));
179 location_poi_pref_set_sort_order(new_pref, location_poi_pref_get_sort_order(pref));
180 location_poi_pref_set_max_result(new_pref, location_poi_pref_get_max_result(pref));
182 g_hash_table_foreach (pref->properties, poi_pref_property_copy_cb ,new_pref);
188 location_poi_pref_free (LocationPOIPreference * pref)
190 g_return_if_fail(pref);
192 location_poi_pref_set_sort_by(pref, NULL);
193 if (pref->properties) g_hash_table_destroy (pref->properties);
195 g_slice_free(LocationPOIPreference, pref);
199 location_poi_filter_set (const LocationPOIFilter *filter, gconstpointer key, gconstpointer value)
201 g_return_val_if_fail(filter, FALSE);
202 g_return_val_if_fail(key, FALSE);
204 if (filter->properties) {
206 gchar *re_key = g_strdup (key);
207 gchar *re_val = g_strdup (value);
208 g_hash_table_insert (filter->properties, re_key, re_val);
209 } else g_hash_table_remove (filter->properties, key);
218 location_poi_filter_get (const LocationPOIFilter *filter, gconstpointer key)
220 g_return_val_if_fail(filter, NULL);
221 g_return_val_if_fail(key, NULL);
223 if (filter->properties) {
224 return g_hash_table_lookup (filter->properties, key);
230 location_poi_filter_get_key (const LocationPOIFilter *filter)
232 g_return_val_if_fail(filter, NULL);
234 if (filter->properties) {
235 return g_hash_table_get_keys (filter->properties);
241 EXPORT_API LocationPOIFilter *
242 location_poi_filter_new (void)
244 LocationPOIFilter *filter = g_slice_new0(LocationPOIFilter);
245 g_return_val_if_fail (filter, NULL);
247 filter->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
252 static void poi_filter_copy_cb (gpointer key, gpointer value, gpointer user_data)
254 g_return_if_fail (key);
255 g_return_if_fail (value);
256 g_return_if_fail (user_data);
258 LocationPOIFilter *filter = (LocationPOIFilter *) user_data;
259 if (filter->properties) {
260 gchar *re_key = g_strdup (key);
261 gchar *re_val = g_strdup (value);
262 g_hash_table_insert (filter->properties, re_key, re_val);
266 EXPORT_API LocationPOIFilter *
267 location_poi_filter_copy (LocationPOIFilter *filter)
269 g_return_val_if_fail (filter, NULL);
271 LocationPOIFilter * new_filter = location_poi_filter_new();
272 g_return_val_if_fail (new_filter, NULL);
274 if (new_filter->properties) g_hash_table_foreach (filter->properties, poi_filter_copy_cb, new_filter);
280 location_poi_filter_free (LocationPOIFilter *filter)
282 g_return_if_fail(filter);
284 if (filter->properties) {
285 g_hash_table_destroy (filter->properties);
286 filter->properties = NULL;
288 g_slice_free(LocationPOIFilter, filter);