3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 *@defgroup setting-phone
20 *UG creation code for setting-phone
23 * - event notification
28 #include <setting-phone.h>
29 #include <libxml/xmlmemory.h>
31 #include "unicode/unum.h"
34 #define UG_MODULE_API __attribute__ ((visibility("default")))
37 setting_view *__get_phone_view_to_load(service_h service)
41 char *viewtype = NULL;
43 service_get_extra_data(service, "viewtype", &viewtype);
47 SETTING_TRACE("viewtype:%s", viewtype);
49 if (!safeStrCmp(viewtype, "language")) {
52 service_get_extra_data(service, "caller", &caller);
54 setting_view_node_table_register(&setting_view_phone_display_language, NULL);
55 return &setting_view_phone_display_language;
57 setting_view_node_table_register(&setting_view_phone_language_region, NULL);
58 setting_view_node_table_register(&setting_view_phone_display_language,
59 &setting_view_phone_language_region);
60 setting_view_node_table_register(&setting_view_phone_region_format,
61 &setting_view_phone_language_region);
63 return &setting_view_phone_language_region;
66 return NULL; /* &setting_view_phone_main; */
70 Evas_Object *__get_phone_layout_to_return(service_h service, void *priv)
73 SettingPhoneUG *phoneUG = priv;
74 char *viewtype = NULL;
76 service_get_extra_data(service, "viewtype", &viewtype);
79 SETTING_TRACE("viewtype:%s", viewtype);
81 if (!safeStrCmp(viewtype, "language")) {
82 return phoneUG->ly_language;
84 return NULL; /* &setting_view_phone_main; */
90 const char *get_language_by_mobile_country_code(int mcc)
92 const char *simLanguage = NULL;
95 case 262: /* GERMAN */
96 simLanguage = "de_DE.UTF-8";
99 simLanguage = "nl_NL.UTF-8";
101 case 214: /* SPAINISH */
102 simLanguage = "es_ES.UTF-8";
104 case 268: /* PORTUGUESE */
105 simLanguage = "pt_PT.UTF-8";
107 case 202: /* GREEK */
108 simLanguage = "el_GR.UTF-8";
110 case 222: /* ITALIAN */
111 simLanguage = "it_IT.UTF-8";
113 case 208: /* FRENCH */
114 simLanguage = "fr_FR.UTF-8";
116 case 286: /* TURKISH */
117 simLanguage = "tr_TR.UTF-8";
119 case 450: /* KOREAN */
120 simLanguage = "ko_KR.UTF-8";
122 case 440: /* JAPAN */
123 simLanguage = "ja_JP.UTF-8";
125 case 460: /* CHINA */
126 simLanguage = "zh_CN.UTF-8";
128 case 454: /* CANTONESE */
129 simLanguage = "zh_HK.UTF-8";
131 case 466: /* TAIWAN */
132 simLanguage = "zh_TW.UTF-8";
134 case 250: /* RUSSIAN */
135 simLanguage = "ru_RU.UTF-8";
137 default: /* get value from db/menu_widget/language at vconf */
138 simLanguage = "en_US.UTF-8";
146 static void setting_phone_update_item(void *data)
148 setting_retm_if(data == NULL, "data is NULL");
149 SettingPhoneUG *ad = (SettingPhoneUG *) data;
151 Setting_GenGroupItem_Data* item_to_update = NULL;
153 item_to_update = ad->data_display_language;
154 retm_if (!item_to_update, "ad->data_display_language is NULL");
156 if (item_to_update) {
157 item_to_update->sub_desc = get_pa_display_language_str();
158 elm_object_item_data_set(item_to_update->item, item_to_update);
159 elm_genlist_item_update(item_to_update->item);
162 char *pa_region = vconf_get_str(VCONFKEY_REGIONFORMAT);
163 if (pa_region == NULL) {
165 ("[Error] get value of VCONFKEY_REGIONFORMAT fail.");
169 item_to_update = ad->data_region_fmt;
170 retm_if (!item_to_update, "ad->data_region_fmt is NULL");
172 if (item_to_update) {
173 item_to_update->sub_desc = setting_phone_lang_get_region_str(pa_region);
174 elm_object_item_data_set(item_to_update->item, item_to_update);
175 elm_genlist_item_update(item_to_update->item);
178 if (ad->data_region_fmt_example) {
180 setting_phone_lang_get_example_desc(pa_region, ad);
181 ad->data_region_fmt_example->keyStr =
182 (char *)g_strdup(example_desc);
184 elm_object_item_data_set(ad->data_region_fmt_example->item, ad->data_region_fmt_example);
185 elm_genlist_item_update(ad->data_region_fmt_example->item);
189 if (ad->pop_progress)
191 evas_object_del(ad->pop_progress);
197 char *setting_phone_lang_get_region_str(const char *region)
200 setting_retvm_if(region == NULL, NULL, "region parameter is NULL");
201 const char *localeID = NULL;
202 UChar displayname[SETTING_STR_SLP_LEN] = { 0, };
203 UErrorCode status = U_ZERO_ERROR;
204 char *ret_str = NULL;
206 const char *pa_lang = vconf_get_str(VCONFKEY_LANGSET);
208 char *q = strchr(pa_lang, '.');
212 SETTING_TRACE("pa_lang:%s", pa_lang);
214 uloc_setDefault(pa_lang, &err);
215 free((void *)pa_lang);
218 SETTING_TRACE_ERROR("get vconf failed");
221 localeID = uloc_getDefault();
222 uloc_getDisplayName(region, localeID, displayname, SETTING_STR_SLP_LEN,
225 if (U_FAILURE(status)) {
226 SETTING_TRACE("NO : uloc_getDisplayName : %d ", status);
228 SETTING_TRACE(" OK : uloc_getDisplayName : %s ", displayname);
231 char *str_displayname = setting_phone_lang_str_to_utf8(displayname);
232 ret_str = (char *)g_strdup(str_displayname);
234 if (str_displayname) {
235 FREE(str_displayname);
241 * Change language string to UTF8 format, the invoker need to free the return string
243 * @param unichars The source string will be translated.
245 * @return UTF8 format string.
247 char *setting_phone_lang_str_to_utf8(const UChar *unichars)
249 retv_if(unichars == NULL, NULL);
254 UErrorCode status = U_ZERO_ERROR;
256 len = u_strlen(unichars);
257 len_str = sizeof(char) *4 * (len + 1);
258 str = (char *)calloc(1, len_str);
262 u_strToUTF8(str, len_str, &len_utf8, unichars, len, &status);
266 char *setting_phone_lang_get_by_pattern(const char *locale,
267 const char *skeleton, void *data)
269 setting_retvm_if(!locale, NULL, "locale parameter is NULL");
270 setting_retvm_if(data == NULL, NULL, "Data parameter is NULL");
272 SettingPhoneUG *ad = (SettingPhoneUG *) data;
274 char *ret_str = NULL;
275 UChar customSkeleton[SETTING_STR_SLP_LEN] = { 0, };
276 UErrorCode status = U_ZERO_ERROR;
277 UDateFormat *formatter = NULL;
279 UChar bestPattern[SETTING_STR_SLP_LEN] = { 0, };
280 UChar formatted[SETTING_STR_SLP_LEN] = { 0, };
282 char bestPatternString[SETTING_STR_SLP_LEN] = { 0, };
283 char formattedString[SETTING_STR_SLP_LEN] = { 0, };
285 u_uastrncpy(customSkeleton, skeleton, safeStrLen(skeleton));
287 if (ad->pattern_generator == NULL
288 || safeStrCmp(locale, ad->prev_locale) != 0) {
289 if (ad->pattern_generator != NULL) {
290 udatpg_close(ad->pattern_generator);
291 ad->pattern_generator = NULL;
293 ad->pattern_generator = udatpg_open(locale, &status);
296 int32_t bestPatternCapacity =
297 (int32_t) (sizeof(bestPattern) / sizeof((bestPattern)[0]));
298 (void)udatpg_getBestPattern(ad->pattern_generator, customSkeleton,
299 u_strlen(customSkeleton), bestPattern,
300 bestPatternCapacity, &status);
302 u_austrcpy(bestPatternString, bestPattern);
303 SETTING_TRACE("BestPattern is %s", bestPatternString);
305 UDate date = ucal_getNow();
307 udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern,
309 int32_t formattedCapacity =
310 (int32_t) (sizeof(formatted) / sizeof((formatted)[0]));
311 (void)udat_format(formatter, date, formatted, formattedCapacity, NULL,
313 u_austrcpy(formattedString, formatted);
314 SETTING_TRACE("DATE & TIME is %s", formattedString);
316 udat_close(formatter);
318 ret_str = g_strdup(formattedString);
322 static char *__setting_phone_number_format_get(const char *region)
324 setting_retvm_if(region == NULL, NULL, "region parameter is NULL");
325 UNumberFormat *fmt = NULL;
326 UErrorCode status = U_ZERO_ERROR;
327 UChar number_uchar[MAX_DISPLAY_NAME_LEN_ON_UI] = {0,};
328 char number_char[MAX_DISPLAY_NAME_LEN_ON_UI] = {0,};
329 double example_number = 1234567.89;
331 fmt = unum_open(UNUM_DEFAULT, NULL, -1, region, NULL, &status);
332 unum_formatDouble(fmt, example_number, number_uchar, MAX_DISPLAY_NAME_LEN_ON_UI, NULL, &status);
333 u_austrcpy(number_char, number_uchar);
334 SETTING_TRACE("number_char = %s", number_char);
337 return g_strdup(number_char); /* should be freed by caller */
340 char *setting_phone_lang_get_example_desc(const char *region, void *data)
342 setting_retvm_if(region == NULL, NULL, "region parameter is NULL");
343 setting_retvm_if(data == NULL, NULL, "Data parameter is NULL");
344 char *date = setting_phone_lang_get_by_pattern(region,
345 UDAT_YEAR_MONTH_WEEKDAY_DAY,
348 enum appcore_time_format timeformat = APPCORE_TIME_FORMAT_12;
349 int ret = appcore_get_timeformat(&timeformat);
351 SETTING_TRACE_ERROR("call appcore_get_timeformat fail.");
352 timeformat = APPCORE_TIME_FORMAT_12;
355 char *time_skeleton = "hhmm";
356 if (timeformat == APPCORE_TIME_FORMAT_24) {
357 time_skeleton = "HHmm";
360 char *time = setting_phone_lang_get_by_pattern(region, time_skeleton, data);
362 char *number = __setting_phone_number_format_get(region);
364 Eina_Strbuf *temp_str = eina_strbuf_new();
365 char *r_str_text = NULL;
366 eina_strbuf_append_printf(temp_str,
367 "%s", _("IDS_ST_BODY_REGIONAL_EXAMPLE"));
368 eina_strbuf_append_printf(temp_str, "<br>%s : %s", _("IDS_ST_BODY_DATE"), date);
369 eina_strbuf_append_printf(temp_str, "<br>%s : %s", _("IDS_COM_BODY_DETAILS_TIME"), time);
370 eina_strbuf_append_printf(temp_str, "<br>%s : %s", _("IDS_ST_BODY_NUMBER"), number);
372 r_str_text = eina_strbuf_string_steal(temp_str);
373 /* eina_strbuf_string_free(temp_str); */
374 eina_strbuf_free(temp_str);
378 return r_str_text; /* will be freed in calling place */
382 static void setting_phone_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
385 SettingPhoneUG *ad = (SettingPhoneUG *) data;
386 /* setting_view_update(&setting_view_about_main, ad); */
387 setting_view_update(ad->view_to_load, ad);
390 static void *setting_phone_ug_on_create(ui_gadget_h ug, enum ug_mode mode,
391 service_h service, void *priv)
393 setting_retvm_if((!priv), NULL, "!priv");
395 SettingPhoneUG *phoneUG = priv;
398 phoneUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
399 phoneUG->win_get = (Evas_Object *) ug_get_window();
400 evas_object_show(phoneUG->win_main_layout);
401 phoneUG->evas = evas_object_evas_get(phoneUG->win_main_layout);
403 setting_retvm_if(phoneUG->win_main_layout == NULL, NULL,
404 "cannot get main window ");
406 /* --------------------------------------------------------- */
407 char *pa_path = NULL;;
409 pa_path = vconf_get_str(VCONFKEY_LANGSET);
412 ("%s*** language setting has no proper value (nil) ***%s",
413 SETTING_FONT_BGREEN, SETTING_FONT_BLACK);
417 setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
419 /* --------------------------------------------------------- */
422 int ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
424 SETTING_TRACE("fail to get vconf");
426 if (value == VCONFKEY_TELEPHONY_SIM_INSERTED) {
427 phoneUG->handle = tel_init(NULL);
428 SETTING_TRACE("phoneUG->handle:%d", phoneUG->handle);
429 memset(&(phoneUG->imsi), 0, sizeof(TelSimImsiInfo_t));
431 && TAPI_API_SUCCESS == tel_get_sim_imsi(phoneUG->handle, &(phoneUG->imsi))) {
432 SETTING_TRACE("********************************************");
433 //SETTING_TRACE("imsi.bValid: [%d]", phoneUG->imsi.bValid);
434 SETTING_TRACE("imsi.szMcc: [%s]", phoneUG->imsi.szMcc);
435 SETTING_TRACE("imsi.szMnc: [%s]", phoneUG->imsi.szMnc);
436 SETTING_TRACE("imsi.szMsin: [%s]", phoneUG->imsi.szMsin);
437 SETTING_TRACE("********************************************");
439 phoneUG->sim_lang = get_language_by_mobile_country_code(atoi(phoneUG->imsi.szMcc));
442 if (!phoneUG->sim_lang) {
443 /* if CSC has updated configuration for setting, initial vconf value changes. */
444 phoneUG->sim_lang = vconf_get_str(VCONFKEY_LANGSET); /* allocated */
446 SETTING_TRACE("sim_lang: [%s]", phoneUG->sim_lang);
448 /* register view node table */
449 setting_view_node_table_intialize();
451 setting_create_Gendial_itc("dialogue/1text.1icon.2",
452 &(phoneUG->itc_1text_1icon_2));
453 setting_create_Gendial_itc("dialogue/1text.1icon",
454 &(phoneUG->itc_1text_1icon));
456 // 2 text - genlist > items
457 setting_create_Gendial_itc("dialogue/2text", &(phoneUG->itc_1icon_2text));
459 setting_create_Gendial_itc("dialogue/1text", &(phoneUG->itc_1text));
460 setting_create_Gendial_itc("dialogue/2text.3/expandable",
461 &(phoneUG->itc_2text_3_parent));
462 setting_create_Gendial_itc("dialogue/1text.1icon/expandable2",
463 &(phoneUG->itc_1icon_1text_sub));
465 phoneUG->itc_seperator.item_style = "dialogue/separator";
466 phoneUG->itc_seperator.func.text_get = NULL;
467 phoneUG->itc_seperator.func.content_get = NULL;
468 phoneUG->itc_seperator.func.state_get = NULL;
469 phoneUG->itc_seperator.func.del = NULL;
471 setting_create_Gendial_itc("dialogue/2text.3", &(phoneUG->itc_2text_2));
472 setting_create_Gendial_itc("multiline/1text",
473 &(phoneUG->itc_bg_1icon));
474 phoneUG->pattern_generator = NULL;
475 phoneUG->prev_locale = NULL;
476 /* creating a view. */
477 phoneUG->bundle_data = service;
478 phoneUG->view_to_load = __get_phone_view_to_load(service);
479 setting_retvm_if(NULL == phoneUG->view_to_load, NULL,
480 "NULL == phoneUG->view_to_load");
481 setting_view_node_set_cur_view(phoneUG->view_to_load);
482 setting_view_create(phoneUG->view_to_load, (void *)phoneUG);
483 evas_object_event_callback_add(phoneUG->win_main_layout,
484 EVAS_CALLBACK_RESIZE,
485 setting_phone_ug_cb_resize, phoneUG);
486 return __get_phone_layout_to_return(service, phoneUG);
489 static void setting_phone_ug_on_start(ui_gadget_h ug, service_h service,
494 static void setting_phone_ug_on_pause(ui_gadget_h ug, service_h service,
499 static void setting_phone_ug_on_resume(ui_gadget_h ug, service_h service,
504 static void setting_phone_ug_on_destroy(ui_gadget_h ug, service_h service,
508 setting_retm_if((!ug || !priv), "!ug || !priv");
509 SettingPhoneUG *phoneUG = priv;
511 evas_object_event_callback_del(phoneUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_phone_ug_cb_resize); /* fix flash issue for gallery */
514 if (phoneUG->handle && tel_deinit(phoneUG->handle) != TAPI_API_SUCCESS) {
515 SETTING_TRACE_ERROR("tel_deinit failed");
517 /* called when this shared gadget is terminated. similar with app_exit */
518 if (&setting_view_phone_language_region == phoneUG->view_to_load) {
519 setting_view_destroy(&setting_view_phone_display_language,
521 setting_view_destroy(&setting_view_phone_region_format,
523 setting_view_destroy(&setting_view_phone_language_region, phoneUG);
526 if (NULL != ug_get_layout(phoneUG->ug)) {
527 evas_object_hide((Evas_Object *) ug_get_layout(phoneUG->ug));
528 evas_object_del((Evas_Object *) ug_get_layout(phoneUG->ug));
534 static void setting_phone_ug_on_message(ui_gadget_h ug, service_h msg,
535 service_h service, void *priv)
538 setting_retm_if(NULL == priv, "priv is NULL");
539 char *pid_str = NULL;
541 service_get_extra_data(msg, "DEADPID", &pid_str);
545 int pid = (int)g_ascii_strtod(pid_str, NULL);
546 SETTING_TRACE_DEBUG("pid = %d",pid);
547 setting_retm_if(errno == ERANGE, "call g_ascii_strtod fail");
549 int ret = app_terminate_dead_cb(pid, priv);
550 setting_retm_if(ret != 0, "call app_terminate_dead_cb fail");
554 static void setting_phone_ug_on_event(ui_gadget_h ug, enum ug_event event,
555 service_h service, void *priv)
559 SettingPhoneUG *ad = (SettingPhoneUG *) priv;
561 case UG_EVENT_LOW_MEMORY:
563 case UG_EVENT_LOW_BATTERY:
565 case UG_EVENT_REGION_CHANGE:
567 if (ad->gl_lang_region && setting_view_phone_language_region.is_create) {
568 elm_genlist_realized_items_update(ad->gl_lang_region);
569 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
571 elm_object_item_text_set(navi_it, _(KeyStr_LanguageRegion));
572 setting_phone_update_item(ad);
576 case UG_EVENT_LANG_CHANGE:
578 if (ad->gl_lang_region && setting_view_phone_language_region.is_create) {
579 elm_genlist_realized_items_update(ad->gl_lang_region);
580 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
582 elm_object_item_text_set(navi_it, _(KeyStr_LanguageRegion));
583 setting_phone_update_item(ad);
586 if (ad->pop_progress) {
587 evas_object_del(ad->pop_progress);
593 case UG_EVENT_ROTATE_PORTRAIT:
595 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
597 case UG_EVENT_ROTATE_LANDSCAPE:
599 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
606 static void setting_phone_ug_on_key_event(ui_gadget_h ug,
607 enum ug_key_event event,
608 service_h service, void *priv)
611 SettingPhoneUG *ad = (SettingPhoneUG *) priv;
613 SETTING_TRACE("event:%d", event);
615 case UG_KEY_EVENT_END:
617 if (elm_naviframe_top_item_get(ad->navi_bar) ==
618 elm_naviframe_bottom_item_get(ad->navi_bar)) {
621 setting_view_cb_at_endKey(ad);
630 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
633 SettingPhoneUG *phoneUG = calloc(1, sizeof(SettingPhoneUG));
634 setting_retvm_if(!phoneUG, -1, "Create SettingPhoneUG obj failed");
636 ops->create = setting_phone_ug_on_create;
637 ops->start = setting_phone_ug_on_start;
638 ops->pause = setting_phone_ug_on_pause;
639 ops->resume = setting_phone_ug_on_resume;
640 ops->destroy = setting_phone_ug_on_destroy;
641 ops->message = setting_phone_ug_on_message;
642 ops->event = setting_phone_ug_on_event;
643 ops->key_event = setting_phone_ug_on_key_event;
645 ops->opt = UG_OPT_INDICATOR_ENABLE;
650 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
653 struct SettingPhoneUG *phoneUG;
654 setting_retm_if(!ops, "ops == NULL");
662 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
667 char *ug_type = NULL;
669 service_get_extra_data(service, "viewtype", &ug_type);
670 #if SUPPORT_RUN_SYSTEM_COMMAND
671 ret += excuteCmd(SETTING_POSTINST_FILE, 1, ug_type);
673 if (0 == safeStrCmp(ug_type, "language")) {
674 // INT_SLP_SETTING_LANG
675 ret += vconf_set_int(VCONFKEY_SETAPPL_LANG_INT, 9);
676 ret += vconf_set_str(VCONFKEY_LANGSET, "en_GB.UTF-8");
677 ret += vconf_set_str(VCONFKEY_REGIONFORMAT,"en_GB.UTF-8");
681 if (0 == safeStrCmp(ug_type, "language"))
683 SETTING_TRACE("Begin to reset language & region...");
685 //b .reset default localeid
687 uloc_setDefault("en_US", &err);
689 //c. reset date&time format
690 vconf_set_int(VCONFKEY_SETAPPL_DATE_FORMAT_INT, SETTING_DATE_FORMAT_DD_MM_YYYY);
692 //d. terminate other apps
693 // ret += aul_app_get_running_app_info(app_terminate_func, NULL);