4bdc66e333cce1fd2459468136c61c79c3d052de
[platform/core/location/maps-plugin-here.git] / heremaps-uc / src / heremaps-uc.c
1 /*
2  * heremaps-uc
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jongmun Woo <jongmun.woo@samsung.com>, Seechan Kim <cbible.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include "heremaps-uc-common.h"
23
24 static Evas_Object *create_conformant(Evas_Object * parent)
25 {
26         LS_FUNC_ENTER
27         Evas_Object *conformant = NULL;
28
29         conformant = elm_conformant_add(parent);
30         elm_win_conformant_set(parent, EINA_TRUE);
31         elm_win_resize_object_add(parent, conformant);
32         evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
33         evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
34         evas_object_show(conformant);
35
36         LS_FUNC_EXIT
37         return conformant;
38 }
39
40 static Evas_Object *create_layout(Evas_Object * parent)
41 {
42         LS_FUNC_ENTER
43         Evas_Object *layout = NULL;
44
45         if (parent != NULL) {
46                 layout = elm_layout_add(parent);
47                 elm_object_content_set(parent, layout);
48                 evas_object_show(layout);
49         }
50
51         LS_FUNC_EXIT
52         return layout;
53 }
54
55 static void win_del(void *data, Evas_Object * obj, void *event)
56 {
57         LS_FUNC_ENTER
58         elm_exit();
59 }
60
61 static void save_vconf(int value, heremaps_uc_app_data *ad)
62 {
63         int enabled = 0;
64         int ret = 0;
65
66         ret = vconf_get_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled);
67         if (ret != 0)
68                 LS_LOGE("Fail to get vconf value");
69         else if (enabled != value) {
70                 ret = vconf_set_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, value);
71                 if (ret != 0)
72                         LS_LOGE("Fail to set vconf value");
73         }
74 }
75
76 static void disagree_btn_cb(void *data, Evas_Object * obj, void *event)
77 {
78         LS_FUNC_ENTER
79         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) data;
80
81         save_vconf(0, ad);
82
83         elm_exit();
84 }
85
86 static void agree_btn_cb(void *data, Evas_Object * obj, void *event)
87 {
88         LS_FUNC_ENTER
89         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) data;
90
91         save_vconf(1, ad);
92
93         elm_exit();
94 }
95
96 static void back_btn_cb(void *data, Evas_Object * obj, void *event)
97 {
98         LS_FUNC_ENTER
99         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) data;
100
101         save_vconf(0, ad);
102         elm_exit();
103 }
104
105 static Evas_Object *create_win(const char *name)
106 {
107         LS_FUNC_ENTER
108         Evas_Object *eo;
109
110         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
111         if (eo) {
112                 elm_win_title_set(eo, name);
113                 elm_win_borderless_set(eo, EINA_TRUE);
114                 evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
115                 elm_win_alpha_set(eo, EINA_TRUE);
116                 if (elm_win_wm_rotation_supported_get(eo)) {
117                         int rots[4] = { 0, 90, 180, 270 };
118                         elm_win_wm_rotation_available_rotations_set(eo, (const int *)(&rots), 4);
119                 }
120         }
121         return eo;
122 }
123
124 static Evas_Object *create_popup(Evas_Object *layout, heremaps_uc_app_data *ad)
125 {
126         LS_FUNC_ENTER
127         Evas_Object *popup;
128         Evas_Object *disagree_btn, *agree_btn;
129
130         /* popup */
131         popup = elm_popup_add(layout);
132         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
133         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, back_btn_cb, ad);
134         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
135         elm_object_part_text_set(popup, "title,text", P_("IDS_POSITIONING_CONSENT_TITLE"));
136         elm_object_text_set(popup, P_("IDS_POSITIONING_CONSENT_BODY"));
137
138         /* Disagree button */
139         disagree_btn = elm_button_add(popup);
140         elm_object_style_set(disagree_btn, "popup");
141         elm_object_text_set(disagree_btn, P_("IDS_ST_BUTTON_DISAGREE"));
142         elm_object_part_content_set(popup, "button1", disagree_btn);
143         evas_object_smart_callback_add(disagree_btn, "clicked", disagree_btn_cb, ad);
144
145         /* Agree button */
146         agree_btn = elm_button_add(popup);
147         elm_object_style_set(agree_btn, "popup");
148         elm_object_text_set(agree_btn, P_("IDS_ST_BUTTON_AGREE"));
149         elm_object_part_content_set(popup, "button2", agree_btn);
150         evas_object_smart_callback_add(agree_btn, "clicked", agree_btn_cb, ad);
151
152         evas_object_show(popup);
153         LS_FUNC_EXIT
154         return popup;
155 }
156
157 static bool _app_create_cb(void *user_data)
158 {
159         LS_FUNC_ENTER
160
161         return true;
162 }
163
164 static void _app_terminate_cb(void *user_data)
165 {
166         LS_FUNC_ENTER
167 }
168
169 static void _app_pause_cb(void *user_data)
170 {
171         LS_FUNC_ENTER
172 }
173
174 static void _app_resume_cb(void *user_data)
175 {
176         LS_FUNC_ENTER
177 }
178
179 static void _app_control_cb(app_control_h app_control, void *user_data)
180 {
181         LS_FUNC_ENTER
182
183         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) user_data;
184         LS_RETURN_IF_FAILED(ad);
185
186         if (ad->win_main) {
187                 evas_object_del(ad->win_main);
188                 ad->win_main = NULL;
189         }
190
191         elm_app_base_scale_set(2.6);
192         elm_config_accel_preference_set("3d");
193
194         bindtextdomain(HEREMAPS_UC_PKG, LOCALE_DIR);
195
196         save_vconf(-1, ad);
197
198         ad->win_main = create_win(HEREMAPS_UC_PKG);
199         ad->conformant = create_conformant(ad->win_main);
200         ad->layout_main = create_layout(ad->conformant);
201
202         ad->popup = create_popup(ad->layout_main, ad);
203
204         evas_object_show(ad->win_main);
205         LS_FUNC_EXIT
206 }
207
208 /*
209 static void _app_low_memory_cb(void *user_data)
210 {
211         LS_FUNC_ENTER
212 }
213
214 static void _app_low_battery_cb(void *user_data)
215 {
216         LS_FUNC_ENTER
217 }
218
219 static void _app_device_orientation_cb(app_event_info_h event_info, void *user_data)
220 {
221         LS_FUNC_ENTER
222         LS_RETURN_IF_FAILED(event_info);
223         LS_RETURN_IF_FAILED(user_data);
224
225         heremaps_uc_app_data *ad = (heremaps_uc_app_data *)user_data;
226         app_device_orientation_e orientation;
227         app_event_get_device_orientation(event_info, &orientation);
228         elm_win_rotation_with_resize_set(ad->win_main, orientation);
229 }
230 */
231
232 static void _app_language_changed_cb(app_event_info_h event_info, void *user_data)
233 {
234         LS_FUNC_ENTER
235
236         char *locale = vconf_get_str(VCONFKEY_LANGSET);
237         if (locale) elm_language_set(locale);
238 }
239
240 int main(int argc, char *argv[])
241 {
242         LS_FUNC_ENTER
243
244         int ret = 0;
245         heremaps_uc_app_data ad = {0,};
246
247         ui_app_lifecycle_callback_s event_callback = {0,};
248         app_event_handler_h handlers[5] = {NULL, };
249
250         event_callback.create = _app_create_cb;
251         event_callback.terminate = _app_terminate_cb;
252         event_callback.app_control = _app_control_cb;
253         event_callback.pause = _app_pause_cb;
254         event_callback.resume = _app_resume_cb;
255
256         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed_cb, NULL);
257
258         ret = APP_ERROR_NONE;
259         ret = ui_app_main(argc, argv, &event_callback, &ad);
260
261         if (ret != APP_ERROR_NONE)
262                 LS_LOGE("ui_app_main() is failed. err=%d", ret);
263
264         return ret;
265
266         LS_FUNC_EXIT
267 }