191993ae924787154ebf741ae685f4ee66262017
[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 #include <stdlib.h>
24 #include <system_info.h>
25
26 #define EDJE_PATH "/usr/apps/org.tizen.heremaps-uc/res/edje/heremaps-uc.edj"
27
28 typedef enum {
29         TIZEN_PROFILE_UNKNOWN = 0,
30         TIZEN_PROFILE_MOBILE = 0x1,
31         TIZEN_PROFILE_WEARABLE = 0x2,
32         TIZEN_PROFILE_TV = 0x4,
33         TIZEN_PROFILE_IVI = 0x8,
34         TIZEN_PROFILE_COMMON = 0x10,
35 } tizen_profile_t;
36
37 static tizen_profile_t _get_tizen_profile()
38 {
39         static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
40         if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
41                 return profile;
42
43         char *profileName;
44         system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
45         switch (*profileName) {
46                 case 'm':
47                 case 'M':
48                         profile = TIZEN_PROFILE_MOBILE;
49                         break;
50                 case 'w':
51                 case 'W':
52                         profile = TIZEN_PROFILE_WEARABLE;
53                         break;
54                 case 't':
55                 case 'T':
56                         profile = TIZEN_PROFILE_TV;
57                         break;
58                 case 'i':
59                 case 'I':
60                         profile = TIZEN_PROFILE_IVI;
61                         break;
62                 default: // common or unknown ==> ALL ARE COMMON.
63                         profile = TIZEN_PROFILE_COMMON;
64         }
65         free(profileName);
66
67         return profile;
68 }
69
70 static Evas_Object *create_conformant(Evas_Object * parent)
71 {
72         LS_FUNC_ENTER
73         Evas_Object *conformant = NULL;
74
75         conformant = elm_conformant_add(parent);
76         elm_win_conformant_set(parent, EINA_TRUE);
77         elm_win_resize_object_add(parent, conformant);
78         evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
79         evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
80         evas_object_show(conformant);
81
82         LS_FUNC_EXIT
83         return conformant;
84 }
85
86 static Evas_Object *create_layout(Evas_Object * parent)
87 {
88         LS_FUNC_ENTER
89         Evas_Object *layout = NULL;
90
91         if (parent != NULL) {
92                 layout = elm_layout_add(parent);
93                 elm_object_content_set(parent, layout);
94                 evas_object_show(layout);
95         }
96
97         LS_FUNC_EXIT
98         return layout;
99 }
100
101 static void win_del(void *data, Evas_Object * obj, void *event)
102 {
103         LS_FUNC_ENTER
104         elm_exit();
105 }
106
107 static void save_vconf(int value)
108 {
109         int enabled = 0;
110         int ret = 0;
111
112         ret = vconf_get_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled);
113         if (ret != 0)
114                 LS_LOGE("Fail to get vconf value");
115         else if (enabled != value) {
116                 ret = vconf_set_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, value);
117                 if (ret != 0)
118                         LS_LOGE("Fail to set vconf value");
119         }
120 }
121
122 static void disagree_btn_cb(void *data, Evas_Object * obj, void *event)
123 {
124         LS_FUNC_ENTER
125         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) data;
126         LS_RETURN_IF_FAILED(ad);
127
128         save_vconf(0);
129         ad->btn_clicked = 1;
130
131         elm_exit();
132 }
133
134 static void agree_btn_cb(void *data, Evas_Object * obj, void *event)
135 {
136         LS_FUNC_ENTER
137         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) data;
138         LS_RETURN_IF_FAILED(ad);
139
140         save_vconf(1);
141         ad->btn_clicked = 1;
142
143         elm_exit();
144 }
145
146 static void back_btn_cb(void *data, Evas_Object * obj, void *event)
147 {
148         LS_FUNC_ENTER
149         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) data;
150         LS_RETURN_IF_FAILED(ad);
151
152         save_vconf(0);
153         ad->btn_clicked = 1;
154         elm_exit();
155 }
156
157 static Evas_Object *create_win(const char *name)
158 {
159         LS_FUNC_ENTER
160         Evas_Object *eo;
161
162         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
163         if (eo) {
164                 elm_win_title_set(eo, name);
165                 elm_win_borderless_set(eo, EINA_TRUE);
166                 evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
167                 elm_win_alpha_set(eo, EINA_TRUE);
168                 if (elm_win_wm_rotation_supported_get(eo)) {
169                         int rots[4] = { 0, 90, 180, 270 };
170                         elm_win_wm_rotation_available_rotations_set(eo, (const int *)(&rots), 4);
171                 }
172         }
173         return eo;
174 }
175
176 static void anchor_clicked_cb(void *data, Evas_Object *obj, void *event_info)
177 {
178         LS_FUNC_ENTER
179         Elm_Entry_Anchor_Info *ai = event_info;
180         LS_RETURN_IF_FAILED(ai);
181
182         app_control_h ac = NULL;
183         app_control_create(&ac);
184         app_control_set_operation(ac, APP_CONTROL_OPERATION_VIEW);
185         app_control_set_uri(ac, ai->name);
186         app_control_send_launch_request(ac, NULL, NULL);
187         app_control_destroy(ac);
188 }
189
190 static Evas_Object *create_popup_tv(Evas_Object *layout, heremaps_uc_app_data *ad)
191 {
192         LS_FUNC_ENTER
193         Evas_Object *popup;
194         Evas_Object *disagree_btn, *agree_btn;
195
196         /* popup */
197         popup = elm_popup_add(layout);
198         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, back_btn_cb, ad);
199         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
200         elm_object_part_text_set(popup, "title,text", P_("IDS_POSITIONING_CONSENT_TITLE"));
201
202         Evas_Object *box = elm_box_add(popup);
203         elm_box_align_set(box, 0.5, 0);
204         elm_object_part_content_set(popup, "elm.swallow.content", box);
205         evas_object_show(box);
206
207         char buf[4096] = {0};
208         char *str1 = P_("IDS_POSITIONING_CONSENT_BODY");
209         char *str2 = "<color=#006fd1ff underline=on underline_color=#006fd1ff><a href=http://here.com/terms/service-terms>http://here.com/terms/service-terms</a></color>";
210         char *str3 = "<color=#006fd1ff underline=on underline_color=#006fd1ff><a href=http://here.com/privacy/privacy-policy>http://here.com/privacy/privacy-policy</a></color>";
211         snprintf(buf, 4096, str1, str2, str3);
212         char *text = strdup(buf);
213
214         Evas_Object* entry = elm_entry_add(box);
215         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
216         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
217         elm_entry_editable_set(entry, EINA_FALSE);
218         elm_object_part_text_set(entry, "elm.text", text);
219         elm_entry_text_style_user_push(entry, "DEFAULT='align=center'");
220         elm_box_pack_end(box, entry);
221         evas_object_show(entry);
222
223         /* Disagree button */
224         disagree_btn = elm_button_add(popup);
225         elm_object_style_set(disagree_btn, "popup");
226         elm_object_text_set(disagree_btn, P_("IDS_ST_BUTTON_DISAGREE"));
227         elm_object_part_content_set(popup, "button1", disagree_btn);
228         evas_object_smart_callback_add(disagree_btn, "clicked", disagree_btn_cb, ad);
229
230         /* Agree button */
231         agree_btn = elm_button_add(popup);
232         elm_object_style_set(agree_btn, "popup");
233         elm_object_text_set(agree_btn, P_("IDS_ST_BUTTON_AGREE"));
234         elm_object_part_content_set(popup, "button2", agree_btn);
235         evas_object_smart_callback_add(agree_btn, "clicked", agree_btn_cb, ad);
236
237         evas_object_show(popup);
238         LS_FUNC_EXIT
239         return popup;
240 }
241
242 static Evas_Object *create_popup_wearable(Evas_Object *layout, heremaps_uc_app_data *ad)
243 {
244         LS_FUNC_ENTER
245         Evas_Object *popup;
246         Evas_Object *agree_btn;
247
248         /* popup */
249         popup = elm_popup_add(layout);
250         elm_object_style_set(popup, "circle");
251         evas_object_size_hint_weight_set(popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
252         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, back_btn_cb, ad);
253
254         Evas_Object *popupLayout = elm_layout_add(popup);
255         elm_layout_theme_set(popupLayout, "layout", "popup", "content/circle/buttons1");
256         evas_object_size_hint_align_set(popupLayout, EVAS_HINT_FILL, EVAS_HINT_FILL);
257         evas_object_size_hint_weight_set(popupLayout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
258         elm_object_part_text_set(popupLayout, "elm.text.title", P_("IDS_POSITIONING_CONSENT_TITLE"));
259         elm_object_content_set(popup, popupLayout);
260
261         Evas_Object *box = elm_box_add(popupLayout);
262         elm_box_align_set(box, 0.5, 0);
263         elm_object_part_content_set(popupLayout, "elm.swallow.content", box);
264         evas_object_show(box);
265
266         char buf[4096] = {0};
267         char *str1 = P_("IDS_POSITIONING_CONSENT_BODY");
268         char *str2 = "<color=#006fd1ff underline=on underline_color=#006fd1ff><a href=http://here.com/terms/service-terms>http://here.com/terms/service-terms</a></color>";
269         char *str3 = "<color=#006fd1ff underline=on underline_color=#006fd1ff><a href=http://here.com/privacy/privacy-policy>http://here.com/privacy/privacy-policy</a></color>";
270         snprintf(buf, 4096, str1, str2, str3);
271         char *text = strdup(buf);
272
273         Evas_Object* entry = elm_entry_add(box);
274         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
275         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
276         elm_entry_editable_set(entry, EINA_FALSE);
277         elm_object_part_text_set(entry, "elm.text", text);
278         elm_entry_text_style_user_push(entry, "DEFAULT='align=center'");
279         elm_box_pack_end(box, entry);
280         evas_object_show(entry);
281
282         /* Agree button */
283         agree_btn = elm_button_add(popup);
284         elm_object_style_set(agree_btn, "popup/circle");
285         evas_object_size_hint_weight_set(agree_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
286         elm_object_part_text_set(agree_btn, "elm.text", P_("IDS_ST_BUTTON_AGREE"));
287
288         evas_object_smart_callback_add(agree_btn, "clicked", agree_btn_cb, ad);
289         elm_object_part_content_set(popup, "button1", agree_btn);
290
291         evas_object_show(popup);
292         LS_FUNC_EXIT
293         return popup;
294 }
295
296 static Evas_Object *create_popup(Evas_Object *layout, heremaps_uc_app_data *ad)
297 {
298         LS_FUNC_ENTER
299         Evas_Object *popup;
300         Evas_Object *disagree_btn, *agree_btn;
301
302         /* popup */
303         popup = elm_popup_add(layout);
304         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
305         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, back_btn_cb, ad);
306         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
307         elm_object_part_text_set(popup, "title,text", P_("IDS_POSITIONING_CONSENT_TITLE"));
308
309         Evas_Object *box = elm_box_add(popup);
310         elm_box_align_set(box, 0.5, 0);
311         elm_object_part_content_set(popup, "elm.swallow.content", box);
312         evas_object_show(box);
313
314         char buf[4096] = {0};
315         char *str1 = P_("IDS_POSITIONING_CONSENT_BODY");
316         char *str2 = "<color=#006fd1ff underline=on underline_color=#006fd1ff><a href=http://here.com/terms/service-terms>http://here.com/terms/service-terms</a></color>";
317         char *str3 = "<color=#006fd1ff underline=on underline_color=#006fd1ff><a href=http://here.com/privacy/privacy-policy>http://here.com/privacy/privacy-policy</a></color>";
318         snprintf(buf, 4096, str1, str2, str3);
319         char *text = strdup(buf);
320
321         Evas_Object* entry = elm_entry_add(box);
322         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
323         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
324         elm_entry_editable_set(entry, EINA_FALSE);
325         elm_object_part_text_set(entry, "elm.text", text);
326         elm_entry_text_style_user_push(entry, "DEFAULT='align=center'");
327         evas_object_smart_callback_add(entry, "anchor,clicked", anchor_clicked_cb, NULL);
328         elm_box_pack_end(box, entry);
329         evas_object_show(entry);
330
331         /* Disagree button */
332         disagree_btn = elm_button_add(popup);
333         elm_object_style_set(disagree_btn, "popup");
334         elm_object_text_set(disagree_btn, P_("IDS_ST_BUTTON_DISAGREE"));
335         elm_object_part_content_set(popup, "button1", disagree_btn);
336         evas_object_smart_callback_add(disagree_btn, "clicked", disagree_btn_cb, ad);
337
338         /* Agree button */
339         agree_btn = elm_button_add(popup);
340         elm_object_style_set(agree_btn, "popup");
341         elm_object_text_set(agree_btn, P_("IDS_ST_BUTTON_AGREE"));
342         elm_object_part_content_set(popup, "button2", agree_btn);
343         evas_object_smart_callback_add(agree_btn, "clicked", agree_btn_cb, ad);
344
345         evas_object_show(popup);
346         LS_FUNC_EXIT
347         return popup;
348 }
349
350 static bool _app_create_cb(void *user_data)
351 {
352         LS_FUNC_ENTER
353
354         return true;
355 }
356
357 static void _app_terminate_cb(void *user_data)
358 {
359         LS_FUNC_ENTER
360 }
361
362 static void _app_pause_cb(void *user_data)
363 {
364         LS_FUNC_ENTER
365         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) user_data;
366         LS_RETURN_IF_FAILED(ad);
367
368         if (ad->btn_clicked == 0)
369                 save_vconf(0);
370
371         elm_exit();
372 }
373
374 static void _app_resume_cb(void *user_data)
375 {
376         LS_FUNC_ENTER
377 }
378
379 static void _app_control_cb(app_control_h app_control, void *user_data)
380 {
381         LS_FUNC_ENTER
382
383         heremaps_uc_app_data *ad = (heremaps_uc_app_data *) user_data;
384         LS_RETURN_IF_FAILED(ad);
385
386         if (ad->win_main) {
387                 evas_object_del(ad->win_main);
388                 ad->win_main = NULL;
389         }
390
391         elm_app_base_scale_set(2.6);
392         elm_config_accel_preference_set("3d");
393
394         bindtextdomain(HEREMAPS_UC_PKG, LOCALE_DIR);
395
396         save_vconf(-1);
397         ad->btn_clicked = 0;
398
399         ad->win_main = create_win(HEREMAPS_UC_PKG);
400         ad->conformant = create_conformant(ad->win_main);
401         ad->layout_main = create_layout(ad->conformant);
402
403         if (_get_tizen_profile() == TIZEN_PROFILE_WEARABLE)
404                 ad->popup = create_popup_wearable(ad->layout_main, ad);
405         else if (_get_tizen_profile() == TIZEN_PROFILE_TV)
406                 ad->popup = create_popup_tv(ad->layout_main, ad);
407         else
408                 ad->popup = create_popup(ad->layout_main, ad);
409
410         evas_object_show(ad->win_main);
411         LS_FUNC_EXIT
412 }
413
414 /*
415 static void _app_low_memory_cb(void *user_data)
416 {
417         LS_FUNC_ENTER
418 }
419
420 static void _app_low_battery_cb(void *user_data)
421 {
422         LS_FUNC_ENTER
423 }
424
425 static void _app_device_orientation_cb(app_event_info_h event_info, void *user_data)
426 {
427         LS_FUNC_ENTER
428         LS_RETURN_IF_FAILED(event_info);
429         LS_RETURN_IF_FAILED(user_data);
430
431         heremaps_uc_app_data *ad = (heremaps_uc_app_data *)user_data;
432         app_device_orientation_e orientation;
433         app_event_get_device_orientation(event_info, &orientation);
434         elm_win_rotation_with_resize_set(ad->win_main, orientation);
435 }
436 */
437
438 static void _app_language_changed_cb(app_event_info_h event_info, void *user_data)
439 {
440         LS_FUNC_ENTER
441
442         char *locale = vconf_get_str(VCONFKEY_LANGSET);
443         if (locale) {
444                 elm_language_set(locale);
445                 free(locale);
446         }
447 }
448
449 int main(int argc, char *argv[])
450 {
451         LS_FUNC_ENTER
452
453         int ret = 0;
454         heremaps_uc_app_data ad = {0,};
455
456         ui_app_lifecycle_callback_s event_callback = {0,};
457         app_event_handler_h handlers[5] = {NULL, };
458
459         event_callback.create = _app_create_cb;
460         event_callback.terminate = _app_terminate_cb;
461         event_callback.app_control = _app_control_cb;
462         event_callback.pause = _app_pause_cb;
463         event_callback.resume = _app_resume_cb;
464
465         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed_cb, NULL);
466
467         ret = APP_ERROR_NONE;
468         ret = ui_app_main(argc, argv, &event_callback, &ad);
469
470         if (ret != APP_ERROR_NONE)
471                 LS_LOGE("ui_app_main() is failed. err=%d", ret);
472
473         return ret;
474
475         LS_FUNC_EXIT
476 }