fix for applying wayland (removing X)
[apps/home/settings.git] / setting-phone / src / setting-phone.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@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 /**
23  *@defgroup setting-phone
24  *UG creation code for setting-phone
25  *
26  * - display
27  * - event notification
28  * - dispaly language
29  * - region format
30  */
31
32 #include <setting-phone.h>
33 #include <libxml/xmlmemory.h>
34 #include "unicode/unum.h"
35 #include <iniparser.h>
36 #include <locale.h>
37 #include <setting-cfg.h>
38
39 #include <eventsystem.h>
40
41 #ifndef UG_MODULE_API
42 #define UG_MODULE_API __attribute__ ((visibility("default")))
43 #endif
44
45 #define SETTING_PHONE_EDJ_PATH          EDJDIR
46 #define SETTING_PHONE_GENLIST_EDJ_NAME  SETTING_PHONE_EDJ_PATH"/setting-genlist.edj"
47
48
49 setting_view *__get_phone_view_to_load(app_control_h service)
50 {
51         SETTING_TRACE_BEGIN;
52
53         char *viewtype = NULL;
54         app_control_get_extra_data(service, "viewtype", &viewtype);
55         if (!viewtype) {
56                 return NULL;
57         }
58
59         SETTING_TRACE("viewtype:%s", viewtype);
60
61         if (!safeStrCmp(viewtype, "language")) {
62                 char *caller = NULL;
63
64                 app_control_get_extra_data(service, "caller", &caller);
65                 if (caller) {
66                         setting_view_node_table_register(&setting_view_phone_display_language, NULL);
67                         FREE(viewtype);
68                         FREE(caller);
69                         return &setting_view_phone_display_language;
70                 } else {
71                         setting_view_node_table_register(&setting_view_phone_language_region, NULL);
72                         setting_view_node_table_register(&setting_view_phone_display_language,
73                                                          &setting_view_phone_language_region);
74                         setting_view_node_table_register(&setting_view_phone_region_format,
75                                                          &setting_view_phone_language_region);
76                         FREE(viewtype);
77                         return &setting_view_phone_language_region;
78                 }
79         } else if (!safeStrCmp(viewtype, "license")) {
80                 setting_view_node_table_register(&setting_view_phone_license_main, NULL);
81                 FREE(viewtype);
82                 return &setting_view_phone_license_main;
83         }
84 #ifdef ENABLE_TICKER_NOTI
85         else if (!safeStrCmp(viewtype, "notification")) {
86                 setting_view_node_table_register(&setting_view_phone_ticker_notification, NULL);
87                 setting_view_node_table_register(&setting_view_phone_ticker_notification_details, &setting_view_phone_ticker_notification);
88                 FREE(viewtype);
89                 return &setting_view_phone_ticker_notification;
90         }
91 #endif
92         else if (!safeStrCmp(viewtype, "region")) {
93                 setting_view_node_table_register(&setting_view_phone_region_format, NULL);
94                 FREE(viewtype);
95                 return &setting_view_phone_region_format;
96         } else {
97                 FREE(viewtype);
98                 return NULL;    /* &setting_view_phone_main; */
99         }
100 }
101
102 Evas_Object *__get_phone_layout_to_return(app_control_h service, void *priv)
103 {
104         SETTING_TRACE_BEGIN;
105         SettingPhoneUG *phoneUG = priv;
106         char *viewtype = NULL;
107
108         app_control_get_extra_data(service, "viewtype", &viewtype);
109         if (!viewtype) {
110                 return NULL;
111         }
112         SETTING_TRACE("viewtype:%s", viewtype);
113
114         if (!safeStrCmp(viewtype, "language")) {
115                 FREE(viewtype);
116                 return phoneUG->ly_language;
117         } else if (!safeStrCmp(viewtype, "license")) {
118                 FREE(viewtype);
119                 return phoneUG->ly_license;
120         } else if (!safeStrCmp(viewtype, "notification")) {
121                 FREE(viewtype);
122                 return phoneUG->ly_ticker;
123         } else if (!safeStrCmp(viewtype, "region")) {
124                 FREE(viewtype);
125                 return phoneUG->ly_region;
126         } else {
127                 FREE(viewtype);
128                 return NULL;    /* &setting_view_phone_main; */
129         }
130
131 }
132
133
134 const char *get_language_by_mobile_country_code(char *mcc)
135 {
136         const char *simLanguage = NULL;
137         char temp[128] = {0,};
138         Eina_List *elist = NULL;
139         setting_lang_entry *pnode = NULL;
140         Eina_List *langlist = setting_get_language_list();
141
142         EINA_LIST_FOREACH(langlist, elist, pnode) {
143                 if (strstr(pnode->mcc, mcc) != NULL) {
144                         snprintf(temp, 127, "%s.UTF-8", pnode->locale);
145                 }
146         }
147
148         if (safeStrLen(temp) > 0) {
149                 simLanguage = (char *)strdup(temp);
150                 SETTING_TRACE_DEBUG("simLanguage: %s", simLanguage);
151         }
152
153         return simLanguage;
154 }
155
156
157 static void setting_phone_update_item(void *data)
158 {
159         setting_retm_if(data == NULL, "data is NULL");
160         SettingPhoneUG *ad = (SettingPhoneUG *) data;
161
162         Setting_GenGroupItem_Data *item_to_update = NULL;
163
164         item_to_update = ad->data_display_language;
165         retm_if(!item_to_update, "ad->data_display_language is NULL");
166
167         if (item_to_update) {
168                 item_to_update->sub_desc = get_pa_display_language_str();
169                 elm_object_item_data_set(item_to_update->item, item_to_update);
170                 elm_genlist_item_update(item_to_update->item);
171         }
172
173         char *pa_region = vconf_get_str(VCONFKEY_REGIONFORMAT);
174         if (pa_region == NULL) {
175                 SETTING_TRACE_ERROR
176                 ("[Error] get value of VCONFKEY_REGIONFORMAT fail.");
177                 return;
178         }
179
180         item_to_update = ad->data_region_fmt;
181         retm_if(!item_to_update, "ad->data_region_fmt is NULL");
182
183         if (item_to_update) {
184                 int region_automatic = 1;
185                 int ret = vconf_get_bool(VCONFKEY_SETAPPL_REGION_AUTOMATIC_BOOL, &region_automatic);
186                 if (ret == VCONF_ERROR) {
187                         SETTING_TRACE_ERROR("get vconf region automatic err.");
188                 }
189
190                 if (region_automatic == 1) {
191                         item_to_update->sub_desc = (char *)g_strdup(_("IDS_ST_BODY_ANSWERINGMODE_AUTOMATIC"));
192                 } else {
193                         item_to_update->sub_desc = setting_phone_lang_get_region_str(pa_region);
194                 }
195                 item_to_update->keyStr = (char *)g_strdup(_(REGION_FORMAT_LOWER));
196                 elm_object_item_data_set(item_to_update->item, item_to_update);
197                 elm_genlist_item_update(item_to_update->item);
198         }
199
200         if (ad->data_region_fmt_example) {
201
202                 char *example_desc =
203                     setting_phone_lang_get_example_desc(pa_region, ad);
204                 ad->data_region_fmt_example->keyStr =
205                     (char *)g_strdup(example_desc);
206                 FREE(example_desc);
207                 elm_object_item_data_set(ad->data_region_fmt_example->item, ad->data_region_fmt_example);
208                 elm_genlist_item_update(ad->data_region_fmt_example->item);
209         }
210
211         FREE(pa_region);
212 }
213
214 char *setting_phone_lang_get_region_str(const char *region)
215 {
216         SETTING_TRACE_BEGIN;
217         setting_retvm_if(region == NULL, NULL, "region parameter is NULL");
218         const char *localeID = NULL;
219         UChar displayname[SETTING_STR_SLP_LEN] = { 0, };
220         UErrorCode status = U_ZERO_ERROR;
221         char *ret_str = NULL;
222
223         const char *pa_lang = vconf_get_str(VCONFKEY_LANGSET);
224         if (pa_lang) {
225                 char *q = strchr(pa_lang, '.');
226                 if (q) {
227                         *q = '\0';
228                 }
229                 SETTING_TRACE("pa_lang:%s", pa_lang);
230                 int err = -1;
231                 uloc_setDefault(pa_lang, &err);
232                 free((void *)pa_lang);
233                 pa_lang = NULL;
234         } else {
235                 SETTING_TRACE_ERROR("get vconf failed");
236         }
237
238         localeID = uloc_getDefault();
239         uloc_getDisplayName(region, localeID, displayname, SETTING_STR_SLP_LEN,
240                             &status);
241
242         char *str_displayname = setting_phone_lang_str_to_utf8(displayname);
243         if (str_displayname == NULL) {
244                 SETTING_TRACE("Get displayname in utf8 failed");
245                 return NULL;
246         }
247         int len = 0;
248         UErrorCode errcode;
249         char source[256] = {0,};
250         UChar dest[256] = {0,};
251         if (strlen(str_displayname) < 256) {
252                 strcpy(source, str_displayname);
253         } else {
254                 FREE(str_displayname);
255                 return NULL;
256         }
257         u_strFromUTF8(dest, 256, &len, source, 256, &errcode);
258         u_strToUpper(dest, 1, dest, 1, "", &errcode);
259         u_strToUTF8(source, 256, NULL, dest, 256, &errcode);
260         ret_str = (char *)g_strdup(source);
261
262         FREE(str_displayname);
263         return ret_str;
264 }
265
266 /**
267 * Change language string to UTF8 format, the invoker need to free the return string
268 *
269 * @param unichars The source string will be translated.
270 *
271 * @return UTF8 format string.
272 */
273 char *setting_phone_lang_str_to_utf8(const UChar *unichars)
274 {
275         retv_if(unichars == NULL, NULL);
276         int len = 0;
277         int len_str = 0;
278         int len_utf8 = 0;
279         char *str = NULL;
280         UErrorCode status = U_ZERO_ERROR;
281
282         len = u_strlen(unichars);
283         len_str = sizeof(char)*4*(len+1);
284         str = (char *)calloc(1, len_str);
285         if (!str) {
286                 return NULL;
287         }
288
289         u_strToUTF8(str, len_str, &len_utf8, unichars, len, &status);
290         return str;
291 }
292
293 char *setting_phone_lang_get_by_pattern(const char *locale, const char *skeleton, void *data)
294 {
295         setting_retvm_if(!locale, NULL, "locale parameter is NULL");
296         setting_retvm_if(data == NULL, NULL, "Data parameter is NULL");
297
298         SettingPhoneUG *ad = (SettingPhoneUG *) data;
299
300         /*remove ".UTF-8" in locale */
301         char locale_tmp[32] = {0,};
302         if (strlen(locale) < 32)        {
303                 strcpy(locale_tmp, locale);
304         } else {
305                 return NULL;
306         }
307         char *p = safeStrStr(locale_tmp, ".UTF-8");
308         if (p) {
309                 *p = 0;
310         }
311
312         char *ret_str = NULL;
313         UChar customSkeleton[SETTING_STR_SLP_LEN] = { 0, };
314         UErrorCode status = U_ZERO_ERROR;
315         UDateFormat *formatter = NULL;
316
317         UChar bestPattern[SETTING_STR_SLP_LEN] = { 0, };
318         UChar formatted[SETTING_STR_SLP_LEN] = { 0, };
319
320         char bestPatternString[SETTING_STR_SLP_LEN] = { 0, };
321         char formattedString[SETTING_STR_SLP_LEN] = { 0, };
322
323         u_uastrncpy(customSkeleton, skeleton, safeStrLen(skeleton));
324
325         if (ad->pattern_generator == NULL
326             || safeStrCmp(locale_tmp, ad->prev_locale) != 0) {
327                 if (ad->pattern_generator != NULL) {
328                         udatpg_close(ad->pattern_generator);
329                         ad->pattern_generator = NULL;
330                 }
331                 ad->pattern_generator = udatpg_open(locale_tmp, &status);
332         }
333
334         int32_t bestPatternCapacity =
335             (int32_t)(sizeof(bestPattern) / sizeof((bestPattern)[0]));
336         (void)udatpg_getBestPattern(ad->pattern_generator, customSkeleton,
337                                     u_strlen(customSkeleton), bestPattern,
338                                     bestPatternCapacity, &status);
339
340         u_austrcpy(bestPatternString, bestPattern);
341         SETTING_TRACE("BestPattern is %s", bestPatternString);
342
343         UDate date = ucal_getNow();
344         formatter =
345             udat_open(UDAT_IGNORE, UDAT_IGNORE, locale_tmp, NULL, -1, bestPattern,
346                       -1, &status);
347         int32_t formattedCapacity =
348             (int32_t)(sizeof(formatted) / sizeof((formatted)[0]));
349         (void)udat_format(formatter, date, formatted, formattedCapacity, NULL,
350                           &status);
351         u_austrcpy(formattedString, formatted);
352         SETTING_TRACE("DATE & TIME is %s", formattedString);
353
354         udat_close(formatter);
355
356         ret_str = g_strdup(formattedString);
357         return ret_str;
358 }
359
360 #if 1
361 static char *__setting_phone_number_format_get(const char *region)
362 {
363         SETTING_TRACE_BEGIN;
364         setting_retvm_if(region == NULL, NULL, "region parameter is NULL");
365         UNumberFormat *fmt = NULL;
366         UErrorCode status = U_ZERO_ERROR;
367         char decimal[MAX_DISPLAY_NAME_LEN_ON_UI] = { 0 };
368         char separator[MAX_DISPLAY_NAME_LEN_ON_UI] = { 0 };
369         char decimal_ch = 0;
370         char separator_ch = 0;
371         UChar u_decimal[MAX_DISPLAY_NAME_LEN_ON_UI] = { 0 };
372         UChar u_thousand[MAX_DISPLAY_NAME_LEN_ON_UI] = { 0 };
373         fmt = unum_open(UNUM_DEFAULT, NULL, -1, region, NULL, &status);
374         unum_getSymbol(fmt, UNUM_DECIMAL_SEPARATOR_SYMBOL, u_decimal, MAX_DISPLAY_NAME_LEN_ON_UI, &status);
375         u_austrcpy(decimal, u_decimal);
376         unum_getSymbol(fmt, UNUM_GROUPING_SEPARATOR_SYMBOL, u_thousand, MAX_DISPLAY_NAME_LEN_ON_UI, &status);
377         u_austrcpy(separator, u_thousand);
378
379         int len_seq = safeStrLen(separator);
380         decimal_ch = decimal[0];
381         separator_ch = separator[0];
382         if (len_seq == 2 || len_seq == 0) {
383                 separator_ch = 32;
384         }
385         if (len_seq == 3 && !safeStrCmp(separator, "\xe2\x80\x99")) {
386                 separator_ch = 39;
387         }
388
389         len_seq = safeStrLen(decimal);
390         if (len_seq == 2 || len_seq == 0) {
391                 decimal_ch = 44;
392         }
393         SETTING_TRACE("separator, decimal = %c, %c", separator_ch, decimal_ch);
394
395         unum_close(fmt);
396
397         /*make example */
398         char loc_number[MAX_DISPLAY_NAME_LEN_ON_UI] = {0,};
399         snprintf(loc_number, sizeof(loc_number), "1%c234%c567%c89", separator_ch, separator_ch, decimal_ch);
400         SETTING_TRACE("loc_number = %s", loc_number);
401         return g_strdup(loc_number); /* should be freed by caller */
402 }
403 #endif
404
405
406 #if 0
407 static char *__setting_phone_number_format_get(const char *region)
408 {
409         setting_retvm_if(region == NULL, NULL, "region parameter is NULL");
410         UNumberFormat *fmt = NULL;
411         UErrorCode status = U_ZERO_ERROR;
412         UChar number_uchar[MAX_DISPLAY_NAME_LEN_ON_UI] = {0,};
413         char number_char[MAX_DISPLAY_NAME_LEN_ON_UI] = {0,};
414         double example_number = 1234567.89;
415
416         fmt = unum_open(UNUM_DEFAULT, NULL, -1, region, NULL, &status);
417         unum_formatDouble(fmt, example_number, number_uchar, MAX_DISPLAY_NAME_LEN_ON_UI, NULL, &status);
418         u_austrcpy(number_char, number_uchar);
419         SETTING_TRACE("number_char = %s", number_char);
420         unum_close(fmt);
421
422         return g_strdup(number_char); /* should be freed by caller */
423 }
424 #endif
425
426 #if 0
427 static char *__setting_phone_number_format_get(const char *region)
428 {
429         SETTING_TRACE_BEGIN;
430         struct lconv *locale = NULL;
431         char *decimal = NULL;
432         char *separator = NULL;
433         char decimal_ch = 0;
434         char separator_ch = 0;
435
436         locale = localeconv();
437         SETTING_TRACE("check localeconv");
438         decimal = locale->decimal_point;
439         separator = locale->thousands_sep;
440         int len_seq = safeStrLen(separator);
441         decimal_ch = decimal[0];
442         separator_ch = separator[0];
443         if (len_seq == 2 || len_seq == 0) {
444                 separator_ch = 32;
445         }
446         SETTING_TRACE("separator, decimal = %c, %c", separator_ch, decimal_ch);
447
448         /*make example */
449         char loc_number[MAX_DISPLAY_NAME_LEN_ON_UI] = {0,};
450         snprintf(loc_number, sizeof(loc_number), "1%c234%c567%c89", separator_ch, separator_ch, decimal_ch);
451         SETTING_TRACE("loc_number = %s", loc_number);
452         return g_strdup(loc_number); /* should be freed by caller */
453 }
454 #endif
455
456 char *setting_phone_lang_get_example_desc(const char *region, void *data)
457 {
458         setting_retvm_if(region == NULL, NULL, "region parameter is NULL");
459         setting_retvm_if(data == NULL, NULL, "Data parameter is NULL");
460         char *date = setting_phone_lang_get_by_pattern(region,
461                                                        UDAT_YEAR_MONTH_WEEKDAY_DAY,
462                                                        data);
463
464         enum appcore_time_format timeformat = APPCORE_TIME_FORMAT_12;
465         int ret = appcore_get_timeformat(&timeformat);
466         if (ret == -1) {
467                 SETTING_TRACE_ERROR("call appcore_get_timeformat fail.");
468                 timeformat = APPCORE_TIME_FORMAT_12;
469         }
470
471         char *time_skeleton = "hhmm";
472         if (timeformat == APPCORE_TIME_FORMAT_24) {
473                 time_skeleton = "HHmm";
474         }
475
476         /*char *region_jp = vconf_get_str(VCONFKEY_REGIONFORMAT); */
477         char *time = NULL;
478
479         /*if (safeStrStr(region_jp, "ja_JP") == NULL) { */
480         time = setting_phone_lang_get_by_pattern(region, time_skeleton, data);
481         /*}else{
482                 time = setting_phone_lang_get_by_pattern("en_GB.UTF-8", time_skeleton, data);
483         }*/
484
485         char *number = __setting_phone_number_format_get(region);
486
487         Eina_Strbuf *temp_str = eina_strbuf_new();
488         char *r_str_text = NULL;
489         eina_strbuf_append_printf(temp_str,
490                                   "%s", _("IDS_ST_BODY_REGIONAL_EXAMPLE"));
491         eina_strbuf_append_printf(temp_str, "<br>%s : %s", _("IDS_ST_BODY_DATE"), date);
492         eina_strbuf_append_printf(temp_str, "<br>%s : %s", _("IDS_ST_HEADER_TIME"), time);
493         eina_strbuf_append_printf(temp_str, "<br>%s : %s", _("IDS_ST_BODY_NUMBER"), number);
494
495         SETTING_TRACE("temp_str: %s", temp_str);
496         r_str_text = eina_strbuf_string_steal(temp_str);
497         /* eina_strbuf_string_free(temp_str); */
498         eina_strbuf_free(temp_str);
499         SETTING_TRACE("r_str_text: %s", r_str_text);
500
501         G_FREE(date);
502         G_FREE(time);
503         G_FREE(number);
504         return r_str_text;      /* will be freed in calling place */
505 }
506
507
508 static void setting_phone_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
509                                        void *event_info)
510 {
511         SettingPhoneUG *ad = (SettingPhoneUG *) data;
512         /* setting_view_update(&setting_view_about_main, ad); */
513         setting_view_update(ad->view_to_load, ad);
514 }
515
516 static void *setting_phone_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
517                                         app_control_h service, void *priv)
518 {
519         setting_retvm_if((!priv), NULL, "!priv");
520         SETTING_TRACE_BEGIN;
521         SettingPhoneUG *phoneUG = priv;
522         phoneUG->ug = ug;
523
524         phoneUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
525         phoneUG->win_get = (Evas_Object *) ug_get_window();
526         evas_object_show(phoneUG->win_main_layout);
527         phoneUG->evas = evas_object_evas_get(phoneUG->win_main_layout);
528
529         setting_retvm_if(phoneUG->win_main_layout == NULL, NULL,
530                          "cannot get main window ");
531
532         /* --------------------------------------------------------- */
533         char *pa_path = NULL;;
534
535         /*elm_theme_extension_add(NULL, SETTING_PHONE_GENLIST_EDJ_NAME); */
536
537         pa_path = vconf_get_str(VCONFKEY_LANGSET);
538         if (!pa_path) {
539                 SETTING_TRACE
540                 ("%s*** language setting has no proper value (nil) ***%s",
541                  SETTING_FONT_BGREEN, SETTING_FONT_BLACK);
542                 return NULL;
543         }
544         /* set launguage */
545         bindtextdomain(SETTING_PACKAGE, SETTING_LOCALEDIR);
546         FREE(pa_path);
547         /* ---------------------------------------------------------     */
548         int value = 0;
549         int err;
550         int ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
551         if (ret != 0) {
552                 SETTING_TRACE("fail to get vconf");
553         }
554         if (value == VCONFKEY_TELEPHONY_SIM_INSERTED) {
555                 phoneUG->handle = tel_init(NULL);
556                 SETTING_TRACE("phoneUG->handle:%d", phoneUG->handle);
557                 memset(&(phoneUG->imsi), 0, sizeof(TelSimImsiInfo_t));
558                 if (phoneUG->handle
559                     && TAPI_API_SUCCESS == tel_get_sim_imsi(phoneUG->handle, &(phoneUG->imsi))) {
560                         SETTING_TRACE_SECURE_DEBUG("********************************************");
561                         SETTING_TRACE_SECURE_DEBUG("imsi.szMcc: [%s]", phoneUG->imsi.szMcc);
562                         SETTING_TRACE_SECURE_DEBUG("imsi.szMnc: [%s]", phoneUG->imsi.szMnc);
563                         SETTING_TRACE_SECURE_DEBUG("imsi.szMsin: [%s]", phoneUG->imsi.szMsin);
564                         SETTING_TRACE_SECURE_DEBUG("********************************************");
565
566                         phoneUG->sim_lang = get_language_by_mobile_country_code(phoneUG->imsi.szMcc);
567                 }
568         }
569         if (!phoneUG->sim_lang) {
570                 /* if CSC has updated configuration for setting, initial vconf value changes. */
571                 phoneUG->sim_lang = vconf_get_str(VCONFKEY_LANGSET); /* allocated */
572         }
573         SETTING_TRACE("sim_lang: [%s]", phoneUG->sim_lang);
574
575         /* register view node table */
576         setting_view_node_table_intialize();
577
578         setting_create_Gendial_itc("1line", &(phoneUG->itc_1text_1icon_2));
579         setting_create_Gendial_itc("1line", &(phoneUG->itc_1text_1icon));
580
581         /* 2 text - genlist > items */
582         setting_create_Gendial_itc("dialogue/2text", &(phoneUG->itc_1icon_2text));
583
584         setting_create_Gendial_itc("1line", &(phoneUG->itc_1text_tb));
585         setting_create_Gendial_itc("1line", &(phoneUG->itc_1text));
586         setting_create_Gendial_itc("2line.top", &(phoneUG->itc_2text_3_parent));
587         setting_create_Gendial_itc("1line", &(phoneUG->itc_1icon_1text_sub));
588
589
590         setting_create_Gendial_itc("2line.top", &(phoneUG->itc_2text_2));
591         setting_create_Gendial_itc("multiline/1text",
592                                    &(phoneUG->itc_bg_1icon));
593         phoneUG->pattern_generator = NULL;
594         phoneUG->prev_locale = NULL;
595         /*  creating a view. */
596         phoneUG->bundle_data = service;
597         phoneUG->view_to_load = __get_phone_view_to_load(service);
598         setting_retvm_if(NULL == phoneUG->view_to_load, NULL,
599                          "NULL == phoneUG->view_to_load");
600         setting_view_node_set_cur_view(phoneUG->view_to_load);
601         setting_view_create(phoneUG->view_to_load, (void *)phoneUG);
602         evas_object_event_callback_add(phoneUG->win_main_layout,
603                                        EVAS_CALLBACK_RESIZE,
604                                        setting_phone_ug_cb_resize, phoneUG);
605         return __get_phone_layout_to_return(service, phoneUG);
606 }
607
608 static void setting_phone_ug_on_start(ui_gadget_h ug, app_control_h service,
609                                       void *priv)
610 {
611 }
612
613 static void setting_phone_ug_on_pause(ui_gadget_h ug, app_control_h service,
614                                       void *priv)
615 {
616 }
617
618 static void setting_phone_ug_on_resume(ui_gadget_h ug, app_control_h service,
619                                        void *priv)
620 {
621         SETTING_TRACE_BEGIN;
622         ret_if(!priv);
623         SettingPhoneUG *phoneUG = priv;
624
625         Eina_Bool is_freezed = evas_object_freeze_events_get(phoneUG->navi_bar);
626         SETTING_TRACE_DEBUG("is_freezed : %d", is_freezed);
627         if (is_freezed)
628                 evas_object_freeze_events_set(phoneUG->navi_bar, EINA_FALSE);
629 }
630
631 static void setting_phone_ug_on_destroy(ui_gadget_h ug, app_control_h service,
632                                         void *priv)
633 {
634         SETTING_TRACE_BEGIN;
635         setting_retm_if((!ug || !priv), "!ug || !priv");
636         SettingPhoneUG *phoneUG = priv;
637
638         evas_object_event_callback_del(phoneUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_phone_ug_cb_resize);     /* fix flash issue for gallery */
639         phoneUG->ug = ug;
640
641         if (phoneUG->handle && tel_deinit(phoneUG->handle) != TAPI_API_SUCCESS) {
642                 SETTING_TRACE_ERROR("tel_deinit failed");
643         }
644         /*  called when this shared gadget is terminated. similar with app_exit */
645         if (&setting_view_phone_language_region == phoneUG->view_to_load) {
646                 setting_view_destroy(&setting_view_phone_display_language,
647                                      phoneUG);
648                 setting_view_destroy(&setting_view_phone_region_format,
649                                      phoneUG);
650                 setting_view_destroy(&setting_view_phone_language_region, phoneUG);
651         }
652 #ifdef ENABLE_TICKER_NOTI
653         else if (&setting_view_phone_ticker_notification ==
654                  phoneUG->view_to_load) {
655                 setting_view_destroy(&setting_view_phone_ticker_notification,
656                                      phoneUG);
657                 setting_view_destroy(&setting_view_phone_ticker_notification_details, phoneUG);
658
659         }
660 #endif
661         else if (&setting_view_phone_license_main == phoneUG->view_to_load) {
662                 setting_view_destroy(&setting_view_phone_license_main, phoneUG);
663         }
664
665         FREE(phoneUG->sim_lang);
666
667         if (NULL != ug_get_layout(phoneUG->ug)) {
668                 evas_object_hide((Evas_Object *) ug_get_layout(phoneUG->ug));
669                 evas_object_del((Evas_Object *) ug_get_layout(phoneUG->ug));
670         }
671
672         SETTING_TRACE_END;
673 }
674
675 static void setting_phone_ug_on_message(ui_gadget_h ug, app_control_h msg,
676                                         app_control_h service, void *priv)
677 {
678         SETTING_TRACE_BEGIN;
679         setting_retm_if(NULL == priv, "priv is NULL");
680         char *pid_str = NULL;
681
682         app_control_get_extra_data(msg, "DEADPID", &pid_str);
683         if (pid_str) {
684                 errno = 0;
685                 int pid = (int)g_ascii_strtod(pid_str, NULL);
686                 SETTING_TRACE_DEBUG("pid = %d", pid);
687                 setting_retm_if(errno == ERANGE, "call g_ascii_strtod fail");
688
689                 int ret = app_terminate_dead_cb(pid, priv);
690                 setting_retm_if(ret != 0, "call app_terminate_dead_cb fail");
691         }
692 }
693
694 static void setting_phone_ug_on_event(ui_gadget_h ug, enum ug_event event,
695                                       app_control_h service, void *priv)
696 {
697         SETTING_TRACE_BEGIN;
698
699         SettingPhoneUG *ad = (SettingPhoneUG *) priv;
700         switch (event) {
701                 case UG_EVENT_LOW_MEMORY:
702                         break;
703                 case UG_EVENT_LOW_BATTERY:
704                         break;
705                 case UG_EVENT_REGION_CHANGE: {
706                                 if (ad->gl_lang_region && setting_view_phone_language_region.is_create) {
707                                         elm_genlist_realized_items_update(ad->gl_lang_region);
708                                         setting_phone_update_item(ad);
709                                 }
710                         }
711                         break;
712                 case UG_EVENT_LANG_CHANGE: {
713                                 ad->lang_change = EINA_TRUE;
714
715                                 if (ad->gl_lang_region && setting_view_phone_language_region.is_create) {
716                                         elm_genlist_realized_items_update(ad->gl_lang_region);
717                                         setting_phone_update_item(ad);
718                                 }
719
720                                 setting_navi_items_update(ad->navi_bar);
721                         }
722                         break;
723
724                 case UG_EVENT_ROTATE_PORTRAIT:
725                         break;
726                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
727                         break;
728                 case UG_EVENT_ROTATE_LANDSCAPE:
729                         break;
730                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
731                         break;
732                 default:
733                         break;
734         }
735 }
736
737 static void setting_phone_ug_on_key_event(ui_gadget_h ug,
738                                           enum ug_key_event event,
739                                           app_control_h service, void *priv)
740 {
741         SETTING_TRACE_BEGIN;
742         SettingPhoneUG *ad = (SettingPhoneUG *) priv;
743
744         SETTING_TRACE("event:%d", event);
745         switch (event) {
746                 case UG_KEY_EVENT_END: {
747                                 if (elm_naviframe_top_item_get(ad->navi_bar) ==
748                                     elm_naviframe_bottom_item_get(ad->navi_bar)) {
749                                         ug_destroy_me(ug);
750                                 } else {
751                                         setting_view_cb_at_endKey(ad);
752                                 }
753                         }
754                         break;
755                 default:
756                         break;
757         }
758 }
759
760 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
761 {
762         SETTING_TRACE_BEGIN;
763         SettingPhoneUG *phoneUG = calloc(1, sizeof(SettingPhoneUG));
764         setting_retvm_if(!phoneUG, -1, "Create SettingPhoneUG obj failed");
765
766         ops->create = setting_phone_ug_on_create;
767         ops->start = setting_phone_ug_on_start;
768         ops->pause = setting_phone_ug_on_pause;
769         ops->resume = setting_phone_ug_on_resume;
770         ops->destroy = setting_phone_ug_on_destroy;
771         ops->message = setting_phone_ug_on_message;
772         ops->event = setting_phone_ug_on_event;
773         ops->key_event = setting_phone_ug_on_key_event;
774         ops->priv = phoneUG;
775         ops->opt = UG_OPT_INDICATOR_ENABLE;
776
777         return 0;
778 }
779
780 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
781 {
782         SETTING_TRACE_BEGIN;
783         struct SettingPhoneUG *phoneUG;
784         setting_retm_if(!ops, "ops == NULL");
785
786         phoneUG = ops->priv;
787         if (phoneUG) {
788                 FREE(phoneUG);
789         }
790 }
791
792 /************* n-depth search **************/
793 static Setting_Cfg_Node_T s_cfg_node_array[] = {
794         {"IDS_ST_HEADER_DISPLAY_LANGUAGE", NULL, "viewtype:language;caller:setting", Cfg_Item_Pos_Level0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
795         {"IDS_ST_BODY_REGION", NULL, "viewtype:region", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
796         {"IDS_ST_BODY_KEYBOARD", NULL, "viewtype:language", 0, 0, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
797 };
798
799
800 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv, char **applocale)
801 {
802         SETTING_TRACE_BEGIN;
803         SETTING_TRACE(">> setting-phone-efl DB search code");
804         setting_retvm_if(!priv || !applocale, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "pplist/applocale is NULL");
805
806         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
807
808         Eina_List **pplist = (Eina_List **)priv;
809         int i;
810         int size = sizeof(s_cfg_node_array) / sizeof(s_cfg_node_array[0]);
811         for (i = 0; i < size; i++) {
812                 Setting_Cfg_Node_T *node = setting_plugin_search_item_subindex_add(s_cfg_node_array[i].key_name, s_cfg_node_array[i].ug_args, IMG_LanguageInput, s_cfg_node_array[i].item_type,  s_cfg_node_array[i].data, "Language and Region");
813                 *pplist = eina_list_append(*pplist, node);
814         }
815         return 0;
816 }
817
818 void set_language_helper(char *lang)
819 {
820         int ret = vconf_set_str(VCONFKEY_LANGSET, lang);
821         if (ret == 0) {
822                 /* on success */
823                 /* set event system */
824                 setting_set_event_system(SYS_EVENT_LANGUAGE_SET,
825                                          EVT_KEY_LANGUAGE_SET,
826                                          lang);
827
828         }
829 }
830
831 int set_regionformat_helper(char *region)
832 {
833
834         int ret = vconf_set_str(VCONFKEY_REGIONFORMAT, region);
835         if (ret == 0) {
836                 /* set event system */
837                 setting_set_event_system(SYS_EVENT_REGION_FORMAT,
838                                          EVT_KEY_REGION_FORMAT,
839                                          region);
840         }
841         return ret;
842 }
843