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 <glib-object.h>
28 #include "location-log.h"
29 #include "location-pref.h"
31 #include "module-internal.h"
33 #include "map-internal.h"
34 #include "map-service.h"
35 #include "location-ielement.h"
42 static void map_service_ielement_interface_init (LocationIElementInterface *iface);
44 G_DEFINE_TYPE_WITH_CODE (MapService, map_service, G_TYPE_OBJECT,
45 G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, map_service_ielement_interface_init));
48 _get_lang (gchar country_code[3], gchar lang_code[3])
50 if (!country_code || !lang_code) return;
51 gchar* langset = vconf_get_str(VCONFKEY_LANGSET);
52 LOCATION_LOGD("getenv: %s", langset);
58 country_code[0] = 'U';
59 country_code[1] = 'S';
60 country_code[2] = '\0';
62 gchar* langset_upper = g_ascii_strup(langset, -1);
63 lang_code[0] = langset_upper[0];
64 lang_code[1] = langset_upper[1];
66 country_code[0] = langset_upper[3];
67 country_code[1] = langset_upper[4];
68 country_code[2] = '\0';
69 g_free(langset_upper);
71 LOCATION_LOGD("Language: %s, Country: %s", lang_code, country_code);
76 map_service_dispose (GObject *gobject)
78 LOCATION_LOGD("map_service_dispose");
80 G_OBJECT_CLASS (map_service_parent_class)->dispose (gobject);
84 map_service_finalize (GObject *gobject)
86 LOCATION_LOGD("map_service_finalize");
87 MapServicePrivate* priv = GET_PRIVATE(gobject);
88 module_free(priv->mod, "map-service");
90 G_OBJECT_CLASS (map_service_parent_class)->finalize (gobject);
94 map_service_get_property (GObject *object,
99 MapServicePrivate *priv = GET_PRIVATE (object);
101 g_return_if_fail(priv->mod);
102 g_return_if_fail(priv->mod->handler);
103 switch (property_id){
104 case PROP_SERVICE_NAME:{
105 char* service_name = NULL;
106 if(priv->mod->ops.get_service_name){
107 if( LOCATION_ERROR_NONE != priv->mod->ops.get_service_name(priv->mod->handler, &service_name) ){
111 LOCATION_LOGD("Get prop>> Service name: %s", service_name);
112 g_value_set_string(value, service_name);
113 g_free(service_name);
117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
123 map_service_ielement_interface_init (LocationIElementInterface *iface)
125 iface->get_geocode = (TYPE_GET_GEOCODE)map_service_get_geocode;
126 iface->get_geocode_freeform = (TYPE_GET_GEOCODE_FREEFORM)map_service_get_geocode_freeform;
127 iface->get_reversegeocode = (TYPE_GET_REVERSEGEOCODE)map_service_get_reversegeocode;
128 iface->get_geocode_async = (TYPE_GET_GEOCODE_ASYNC)map_service_get_geocode_async;
129 iface->get_geocode_freeform_async = (TYPE_GET_GEOCODE_FREEFORM_ASYNC)map_service_get_geocode_freeform_async;
130 iface->get_reversegeocode_async = (TYPE_GET_REVERSEGEOCODE_ASYNC)map_service_get_reversegeocode_async;
131 iface->search_poi = (TYPE_SEARCH_POI) map_service_search_poi;
132 iface->search_poi_by_area = (TYPE_SEARCH_POI_BY_AREA) map_service_search_poi_by_area;
133 iface->search_poi_by_address = (TYPE_SEARCH_POI_BY_ADDR) map_service_search_poi_by_address;
134 iface->search_poi_by_freeform = (TYPE_SEARCH_POI_BY_FREEFORM) map_service_search_poi_by_freeform;
135 iface->cancel_poi_request = (TYPE_CANCEL_POI_REQUEST) map_service_cancel_poi_request;
136 iface->request_route = (TYPE_REQUEST_ROUTE) map_service_request_route;
137 iface->cancel_route_request = (TYPE_CANCEL_ROUTE_REQUEST) map_service_cancel_route_request;
138 iface->is_supported_map_provider_capability = (TYPE_IS_SUPPORTED_MAP_PROVIDER_CAPABILITY) map_service_is_supported_map_provider_capability;
139 iface->get_map_provider_capability_key = (TYPE_GET_MAP_PROVIDER_CAPABILITY_KEY) map_service_get_map_provider_capability_key;
144 map_service_init (MapService *self)
146 LOCATION_LOGD("map_service_init");
147 MapServicePrivate* priv = GET_PRIVATE(self);
149 priv->mod = (LocationServiceMod*)module_new("map-service");
150 if(!priv->mod) LOCATION_LOGW("module loading failed");
151 priv->pref = location_pref_new ();
152 if(!priv->pref) LOCATION_LOGW("Service preference failed");
154 gchar country[3], lang[3];
155 _get_lang (country, lang);
156 location_pref_set_language (priv->pref, lang);
157 location_pref_set_distance_unit (priv->pref, "MI");
158 location_pref_set_provider_name (priv->pref, "decarta");
162 map_service_class_init (MapServiceClass *klass)
164 LOCATION_LOGD("map_service_class_init");
165 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
168 gobject_class->get_property = map_service_get_property;
170 gobject_class->dispose = map_service_dispose;
171 gobject_class->finalize = map_service_finalize;
173 g_type_class_add_private (klass, sizeof (MapServicePrivate));
175 pspec = g_param_spec_string ("service provider",
176 "map service provider name prop",
177 "map service provider name",
180 g_object_class_install_property (gobject_class,
186 map_service_get_pref(GObject *obj)
188 LOCATION_LOGD("map_service_get_pref");
189 MapServicePrivate* priv = GET_PRIVATE(obj);
190 if (!priv) return NULL;
191 if (!priv->pref) return NULL;
193 LocationPreference *pref = location_pref_copy(priv->pref);
199 map_service_set_pref (GObject *obj, LocationPreference *pref)
201 LOCATION_LOGD("map_service_set_pref");
202 MapServicePrivate* priv = GET_PRIVATE(obj);
203 if (!priv) return FALSE;
204 if (!priv->pref) location_pref_free(priv->pref);
206 priv->pref = location_pref_copy (pref);