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