tizen 2.3.1 release
[apps/home/settings.git] / setting-time / src / setting-time-main.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 #include <setting-time-main.h>
23 #include <dd-deviced-managed.h>
24 #include <dd-deviced.h>
25
26 #include <stdio.h>
27 #include <malloc.h>
28 #include <time.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <sqlite3.h>
32
33 #include <vconf.h>
34 #include <vconf-keys.h>
35
36 #include <unicode/udat.h>
37 #include <unicode/ustring.h>
38 #include <unicode/uloc.h>
39 #include <unicode/ucal.h>
40 #include <unicode/utmscale.h>
41
42 #define ONE_MINUTE 60
43 #define PROGRESS_POPUP_SHOW 0
44 #define DEF_BUF_SIZE 256
45
46 /*  ICU utilities*/
47 static UChar *uastrcpy(const char *chars);
48 static void ICU_set_timezone(const char *timezone);
49 static void get_gmt_offset(char *str_buf, int size);
50
51 static char *get_timezone_str();
52 static char *get_city_name_result();
53 static bool get_city_name(char *tzname);
54 static char *get_timezone_displayname();
55
56 static char *s_result;
57 static int query_callback(void *NotUsed, int argc, char **argv, char **azColName);
58 static bool setting_update_timezone(SettingTimeUG *ad);
59
60 static int setting_time_main_create(void *cb);
61 static int setting_time_main_destroy(void *cb);
62 static int setting_time_main_update(void *cb);
63 static int setting_time_main_cleanup(void *cb);
64
65 setting_view setting_view_time_main = {
66         .create = setting_time_main_create,
67         .destroy = setting_time_main_destroy,
68         .update = setting_time_main_update,
69         .cleanup = setting_time_main_cleanup,
70 };
71
72 #if UN_SUPPORT_TIME_DYNAMIC_UPDATE
73 static void setting_time_reboot_resp_cb(void *data, Evas_Object *obj,
74                                         void *event_info);
75 #endif
76
77 bool __update_timezone_idler(SettingTimeUG *ad)
78 {
79         setting_update_timezone(ad);
80         ecore_idler_del(ad->update_timezone_idler);
81         ad->update_timezone_idler = NULL;
82         return 0;
83 }
84
85 void time_changed_callback(keynode_t *key, void *data)
86 {
87
88         SETTING_TRACE_DEBUG("time and timezone have been changed: TIME_CHANGED_HEYNOTY_CALLBACK");
89         SettingTimeUG *ad = (SettingTimeUG *)data;
90
91         int ret = setting_time_update_cb(ad);
92         if (ret != 0) {
93                 SETTING_TRACE("FAIL: setting_time_update_db(ad)\n");
94         }
95
96 #if 0
97         SETTING_TRACE("ad->is_datefield_selected:%d", ad->is_datefield_selected)
98         if (EINA_TRUE == ad->is_datefield_selected) {
99                 /* Timezone is not changed and a selected value of the datefield is already changed */
100                 SETTING_TRACE("Datefield is selected\n");
101                 return ;
102         }
103 #endif
104
105         tzset();
106         /* vconfset to update timezone */
107         char pTZPath[__MAX_PATH_SIZE];
108         ssize_t nLen = readlink(SETTING_TZONE_SYMLINK_PATH, pTZPath, sizeof(pTZPath) - 1);
109         if (nLen != -1) {
110                 pTZPath[nLen] = '\0';
111         } else {
112                 SETTING_TRACE("parse error for SETTING_TZONE_SYMLINK_PATH");
113                 return;
114         }
115
116         if (!__setting_set_city_tzone(&pTZPath[20])) {
117                 SETTING_TRACE("__setting_set_city_tzone ERROR");
118                 return;
119         }
120         char *timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
121         setting_retm_if(timezone == NULL, "get vonf failed");
122         ICU_set_timezone(timezone);
123         FREE(timezone);
124
125         /* update timezone */
126         if (ad->update_timezone_idler) {
127                 ecore_idler_del(ad->update_timezone_idler);
128                 ad->update_timezone_idler = NULL;
129         }
130         ad->update_timezone_idler =
131             ecore_idler_add((Ecore_Task_Cb) __update_timezone_idler, ad);
132         /* update time */
133         if (ad->refresh_time_idler) {
134                 ecore_idler_del(ad->refresh_time_idler);
135                 ad->refresh_time_idler = NULL;
136         }
137         ad->refresh_time_idler = ecore_idler_add(setting_update_datefield, ad);
138 }
139
140 void setting_time_update_time_date_format_string(SettingTimeUG *ad)
141 {
142         SETTING_TRACE_BEGIN;
143
144         struct tm *ts;
145         struct tm ts_ret;
146         time_t ctime;
147
148         int ret, value, err;
149
150         char time_str[MAX_ARGS];
151
152         ctime = time(NULL);
153         ts = localtime_r(&ctime, &ts_ret);
154         ret_if(!ts);
155
156         /* set time in particular format */
157         ret = setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224, &value, &err);
158         if (ret == SETTING_RETURN_FAIL)
159                 value = VCONFKEY_TIME_FORMAT_12;
160
161         switch (value) {
162                 case VCONFKEY_TIME_FORMAT_12: {
163                                 /* Get Time */
164                                 strftime(time_str, MAX_ARGS, "%l:%M %p ", &ts_ret);
165                         }
166                         break;
167
168                 case VCONFKEY_TIME_FORMAT_24: {
169                                 strftime(time_str, MAX_ARGS, "%H:%M", &ts_ret);
170                         }
171                         break;
172                 default:
173                         /* do nothing */
174                         break;
175         }
176
177         if (ad->data_time) {
178                 elm_object_item_data_set(ad->data_time->item, ad->data_time);
179                 elm_genlist_item_update(ad->data_time->item);
180         }
181 }
182
183 bool setting_update_timezone(SettingTimeUG *ad)
184 {
185         /* SETTING_TRACE_BEGIN; */
186         char time_zone_sub_str[CITY_BUF_SIZE + GMT_BUF_SIZE + 3] = { 0, };
187         char *displayTimezone = NULL;
188         char gmt_offset[GMT_BUF_SIZE] = {0, };
189         int ret = 0;
190
191         /*  get time zone */
192         displayTimezone = get_timezone_displayname();
193         get_gmt_offset(gmt_offset, GMT_BUF_SIZE);
194
195         if (displayTimezone != NULL) {
196                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s",
197                                displayTimezone, gmt_offset);
198                 retv_if(ret < 0, 0);
199         } else {
200                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "Korean Standard Time, GMT +9:00");
201                 retv_if(ret < 0, 0);
202         }
203         SETTING_TRACE("ad->data_tz:%p", ad->data_tz);
204
205         if (ad->data_tz) {
206                 ad->data_tz->sub_desc = (char *)g_strdup(time_zone_sub_str);
207                 elm_object_item_data_set(ad->data_tz->item, ad->data_tz);
208                 elm_genlist_item_update(ad->data_tz->item);
209         }
210
211         FREE(displayTimezone);
212
213         return 0;
214 }
215
216 static void setting_time_main_int_vconf_change_cb(keynode_t *key, void *data)
217 {
218         SETTING_TRACE_BEGIN;
219         ret_if(NULL == data);
220         SettingTimeUG *ad = data;
221
222         char *vconf_name = vconf_keynode_get_name(key);
223         /* SETTING_TRACE("vconf_name:%s", vconf_name); */
224
225         if (!safeStrCmp(vconf_name, VCONFKEY_REGIONFORMAT_TIME1224) ||
226             !safeStrCmp(vconf_name, VCONFKEY_SETAPPL_DATE_FORMAT_INT)) {
227                 char *time;
228                 static char time_arr[DEF_BUF_SIZE];
229                 char *pa_time_format = get_pa_time_format_str();
230                 if (pa_time_format) {
231                         if (!strncmp(pa_time_format, "IDS_COM_BODY_12_HOURS", strlen("IDS_COM_BODY_12_HOURS")))
232                                 time = __setting_phone_lang_get_by_pattern("en_US", "hhmm");
233                         else
234                                 time = __setting_phone_lang_get_by_pattern("en_US", "Hm");
235                 }
236
237                 strncpy(time_arr, time, DEF_BUF_SIZE);
238                 time_arr[DEF_BUF_SIZE - 1] = '\0';
239
240                 elm_object_text_set(ad->data_time->btn_right, time_arr);
241                 FREE(pa_time_format);
242         }
243 }
244
245 static void __update_time_via_sim_card(void *data)
246 {
247         setting_retm_if(data == NULL, "Data parameter is NULL");
248         SettingTimeUG *ad = (SettingTimeUG *) data;
249         int ret = 0;
250         int t_nitz = 0;
251         int t_offset = 0;
252         ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_GMT, &t_nitz);
253         ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, &t_offset);
254         char *tzpath = vconf_get_str(VCONFKEY_TELEPHONY_NITZ_ZONE);
255         if (ret != 0 || isEmptyStr(tzpath)) {
256                 /*setting_create_simple_popup(ad, ad->ly_main, */
257                 /*                          NULL, _(NOT_SUPPORT_AUTO_UPDATE_DESC)); */
258                 return;
259         }
260         ret = 0;/*reset.. */
261
262         /* a.time zone */
263         SETTING_TRACE("tz_path:%s", tzpath);
264
265         char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1];
266         safeCopyStr(tz_path, SETTING_TIME_ZONEINFO_PATH, MAX_COMMON_BUFFER_LEN / 4);
267         g_strlcat(tz_path, tzpath, sizeof(tz_path));
268         SETTING_TRACE("full tz_path:%s", tz_path);
269         ret = alarmmgr_set_timezone(tz_path);
270         if (ret < 0) {
271                 SETTING_TRACE("tzpath is not valid.");
272                 return;
273         } else
274                 SETTING_TRACE("alarmmgr_set_timezone - successful : %s \n", tz_path);
275         if (!__setting_set_city_tzone(tzpath)) {
276                 SETTING_TRACE("__setting_set_city_tzone ERROR")
277                 return;
278         }
279         get_city_name(tzpath);
280         char *city = get_city_name_result();
281         SETTING_TRACE("city:%s", city);
282         if (city) {
283                 ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city);
284                 setting_retm_if(ret != 0, "set vconf[%s] failed", VCONFKEY_SETAPPL_CITYNAME_INDEX_INT);
285         }
286         setting_update_timezone(ad);
287
288         /* b.TIME AND DATE */
289         int t_uptime = 0;
290         FILE *fp = fopen("/proc/uptime", "r");
291         if (fp) {
292                 if (!fscanf(fp, "%d", &t_uptime)) {
293                         SETTING_TRACE_ERROR("fscanf error");
294                 }
295                 fclose(fp);
296                 fp = NULL;
297         } else {
298                 SETTING_TRACE_ERROR("fopen error");
299         }
300
301         SETTING_TRACE("t_nitz:%d, t_offset:%d, t_uptime:%d", t_nitz, t_offset, t_uptime);
302         time_t t_current = t_nitz + t_uptime - t_offset;
303         SETTING_TRACE("t_current:%d", t_current);
304         ret = alarmmgr_set_datetime(t_current);
305         setting_retm_if(ret == -1, "alarmmgr_set_datetime call failed");
306         if (ad->data_time) {
307                 struct tm ts_ret;
308                 struct tm *ts = localtime_r(&t_current, &ts_ret);
309                 ret_if(!ts);
310                 setting_enable_evas_object(ad->data_time->btn_left);
311                 setting_enable_evas_object(ad->data_time->btn_right);
312         }
313
314         /* time change - event */
315         static int t_event_val = -1;
316         vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED, t_event_val);
317
318         FREE(tzpath);
319 }
320
321
322 static void setting_time_main_bool_vconf_change_cb(keynode_t *key, void *data)
323 {
324         /* SETTING_TRACE_BEGIN; */
325         ret_if(NULL == data);
326         SettingTimeUG *ad = data;
327         int status = vconf_keynode_get_bool(key);
328         char *vconf_name = vconf_keynode_get_name(key);
329
330         if (!safeStrCmp(vconf_name, VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL)) {
331                 if (ad->data_auto) {
332                         ad->is_datefield_selected = EINA_FALSE;
333
334                         setting_update_gl_item_chk_status(ad->data_auto, status);
335
336                         if (!ad->data_auto->chk_status) {
337                                 if (ad->data_tz) {
338                                         setting_enable_genlist_item(ad->data_tz->item);
339                                 }
340
341                                 if (ad->data_time) {
342                                         ad->data_time->isItemDisableFlag = FALSE;
343                                         /*setting_ensable_evas_object(ad->data_time->eo_check); */
344                                         setting_enable_evas_object(ad->data_time->btn_left);
345                                         setting_enable_evas_object(ad->data_time->btn_right);
346                                         setting_enable_genlist_item(ad->data_time->item);
347                                 }
348
349
350                         } else {
351 #if UN_SUPPORT_TIME_DYNAMIC_UPDATE
352                                 ad->pop =
353                                     setting_create_popup_with_btn(ad, ad->win_get, NULL,
354                                                                   _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"),
355                                                                   setting_time_reboot_resp_cb,
356                                                                   0, 2,
357                                                                   dgettext("sys_string", "IDS_COM_SK_OK"),
358                                                                   _("IDS_COM_SK_CANCEL"));
359 #else
360                                 if (ad->data_tz) {
361                                         setting_disable_genlist_item(ad->data_tz->item);
362                                 }
363
364                                 if (ad->data_time) {
365                                         ad->data_time->isItemDisableFlag = FALSE;
366                                         /*setting_disable_evas_object(ad->data_time->eo_check); */
367                                         setting_disable_evas_object(ad->data_time->btn_left);
368                                         setting_disable_evas_object(ad->data_time->btn_right);
369                                         setting_disable_genlist_item(ad->data_time->item);
370                                 }
371
372                                 __update_time_via_sim_card(ad);
373 #endif
374                         }
375                 }
376         }
377 }
378
379 static void __sim_time_info_chg_cb(keynode_t *key, void *data)
380 {
381         SETTING_TRACE_BEGIN;
382         ret_if(NULL == data);
383         SettingTimeUG *ad = data;
384         char *vconf_name = vconf_keynode_get_name(key);
385         /*SETTING_TRACE("vconf_name:%s", vconf_name);*/
386         if (!safeStrCmp(vconf_name, VCONFKEY_TELEPHONY_NITZ_GMT)
387             || !safeStrCmp(vconf_name, VCONFKEY_TELEPHONY_NITZ_EVENT_GMT)
388             || !safeStrCmp(vconf_name, VCONFKEY_TELEPHONY_NITZ_ZONE)) {
389                 int value = 0;
390                 int err = 0;
391                 setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, &value,
392                                          &err);
393                 if (value) {
394                         int ret = 0;
395                         int t_nitz = 0;
396                         int t_offset = 0;
397                         ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_GMT, &t_nitz);
398                         ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, &t_offset);
399                         char *tzpath = vconf_get_str(VCONFKEY_TELEPHONY_NITZ_ZONE);
400                         if (ret != 0 || isEmptyStr(tzpath)) {
401                                 if (ad->data_auto) {
402                                         setting_disable_genlist_item(ad->data_auto->item);
403                                 }
404                                 if (ad->data_tz) {
405                                         setting_enable_genlist_item(ad->data_tz->item);
406                                 }
407                                 if (ad->data_time) {
408                                         setting_enable_genlist_item(ad->data_time->item);
409                                 }
410                                 return;
411                         }
412                         FREE(tzpath);
413
414                         if (ad->data_auto) {
415                                 setting_enable_genlist_item(ad->data_auto->item);
416                         }
417                         if (ad->data_tz) {
418                                 setting_disable_genlist_item(ad->data_tz->item);
419                         }
420                         if (ad->data_time) {
421                                 setting_disable_genlist_item(ad->data_time->item);
422                         }
423
424                         __update_time_via_sim_card(ad);
425                 }
426         }
427 }
428
429 #if 0
430 static int __setting_time_check_enable_automatic_update()
431 {
432         /*to read TAPI vconfs */
433         int ret = 0;
434         int t_nitz = 0;
435         int t_offset = 0;
436         ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_GMT, &t_nitz);
437         ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, &t_offset);
438         char *tzpath = vconf_get_str(VCONFKEY_TELEPHONY_NITZ_ZONE);
439         if (ret == 0 && !isEmptyStr(tzpath))
440                 return 1;
441         else
442                 return 0;
443 }
444 #endif
445
446 /* ***************************************************
447  *
448  *basic func
449  *
450  ***************************************************/
451 static void setting_time_main_datefield_set_cb(void *data, Evas_Object *object, void *event_info)
452 {
453         SETTING_TRACE_BEGIN;
454         SETTING_TRACE("SETTING_DATETIME");
455
456
457         /*Setting_GenGroupItem_Data *item_data = param->item_data; */
458         /* error check */
459         ret_if(data == NULL);
460         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
461         SettingTimeUG *ad = list_item->userdata;
462
463         Evas_Object *obj = list_item->eo_check; /* elm_datetime_add */
464
465         if (obj) {
466                 elm_object_signal_emit(list_item->eo_check /* elm_datetime_xxx*/, "picker,action,value,set", "");
467         } else {
468                 SETTING_TRACE_ERROR("list_item->eo_check is NULL");
469         }
470
471         ad->is_datefield_selected = EINA_TRUE;
472
473 #ifdef USE_TIMER_UPDATE_TIME_IN_TIME_VIEW
474         if (ad->update_timer) {
475                 ecore_timer_reset(ad->update_timer);
476                 ecore_timer_freeze(ad->update_timer);
477         }
478 #endif
479
480         /* If auto update is on, don't anything while the datefield has been updated (i.e., time runs) */
481         if (1 == setting_time_check_automatic_time_update_state()) {
482                 SETTING_TRACE("AUTO_TIME ON: no action");
483                 SETTING_TRACE_END;
484 #ifdef USE_TIMER_UPDATE_TIME_IN_TIME_VIEW
485                 if (ad->update_timer) {
486                         ecore_timer_thaw(ad->update_timer);
487                 }
488 #endif
489                 return;
490         }
491
492         struct tm _tm;
493         elm_datetime_value_get(obj, &_tm);
494
495         SETTING_TRACE("year : %d, month : %d, day : %d, hour : %d, min : %d",
496                       _tm.tm_year, _tm.tm_mon, _tm.tm_mday, _tm.tm_hour, _tm.tm_min);
497
498         _tm.tm_isdst = -1;
499         _tm.tm_sec = 0;
500
501         /*  local time  -> gmtime */
502         time_t the_time = mktime(&_tm); /* represent local time */
503
504         /* invoke API to change time */
505         int ret = alarmmgr_set_systime(the_time);
506
507 #ifdef USE_TIMER_UPDATE_TIME_IN_TIME_VIEW
508         if (ad->update_timer) {
509                 ecore_timer_thaw(ad->update_timer);
510         }
511 #endif
512
513 #if 1
514         time_t cctime = time(NULL);
515         struct tm ts_ret;
516         struct tm *ts = localtime_r(&cctime, &ts_ret);
517         SETTING_TRACE("After alarmmgr_set_systime() ....year : %d, month : %d, day : %d, hour : %d, min : %d",
518                       ts_ret.tm_year, ts_ret.tm_mon, ts_ret.tm_mday, ts_ret.tm_hour, ts_ret.tm_min);
519 #endif
520         Evas_Object *popup = NULL;
521         popup = evas_object_data_get(obj, "popup");
522         if (popup) {
523                 evas_object_del(popup);
524                 popup = NULL;
525         }
526         setting_retm_if(ret == -1, "alarmmgr_set_systime call failed");
527 }
528
529 #ifdef USE_TIMER_UPDATE_TIME_IN_TIME_VIEW
530 Eina_Bool __refresh_date_timer(void *data)
531 {
532         /*SETTING_TRACE_BEGIN; */
533         SettingTimeUG *ad = data;
534         if (ad->data_time) {
535                 time_t ctime = time(NULL);
536                 struct tm ts_ret;
537                 struct tm *ts = localtime_r(&ctime, &ts_ret);
538                 retv_if(!ts, 1);
539
540                 struct tm ui_time;
541                 elm_datetime_value_get(ad->data_time->eo_check, &ui_time);
542                 if ((ctime / ONE_MINUTE) != (mktime(&ui_time) / ONE_MINUTE)) {
543                         SETTING_TRACE("To refresh the UI element after 1 minute passed.\t in %s", __FUNCTION__);
544                         elm_datetime_value_set(ad->data_time->eo_check, &ts_ret);
545                         setting_update_timezone(ad);
546                 }
547         }
548         return 1;
549 }
550 #endif
551
552 static void __setting_time_main_exp_cb(void *data, Evas_Object *obj,
553                                        void *event_info)
554 {
555         ret_if(NULL == data || NULL == event_info);
556         SETTING_TRACE_BEGIN;
557         SettingTimeUG *ad = (SettingTimeUG *) data;
558         Elm_Object_Item *parentItem = event_info;       /* parent item */
559         Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem);      /* parent data */
560         Evas_Object *scroller = elm_object_item_widget_get(parentItem);
561
562         Evas_Object *rgd;
563         if (data_parentItem == ad->data_time_fmt) {
564                 setting_genlist_item_groupstyle_set(data_parentItem, data_parentItem->exp_style);
565
566                 rgd = elm_radio_add(scroller);
567                 elm_radio_value_set(rgd, -1);
568                 setting_create_Gendial_exp_sub_field_with_group_style(scroller,
569                                                                       &itc_multiline_1text_1icon,
570                                                                       /*&(ad->itc_1icon_1text_sub), */
571                                                                       NULL, NULL, parentItem,
572                                                                       SWALLOW_Type_1RADIO, rgd,
573                                                                       VCONFKEY_TIME_FORMAT_12,
574                                                                       "IDS_COM_BODY_12_HOURS",
575                                                                       NULL, SETTING_GROUP_STYLE_CENTER);
576
577                 setting_create_Gendial_exp_sub_field_with_group_style(scroller,
578                                                                       &itc_multiline_1text_1icon,
579                                                                       /* &(ad->itc_1icon_1text_sub), */
580                                                                       NULL, NULL, parentItem,
581                                                                       SWALLOW_Type_1RADIO, rgd,
582                                                                       VCONFKEY_TIME_FORMAT_24,
583                                                                       "IDS_ST_BODY_24_HOURS",
584                                                                       NULL, SETTING_GROUP_STYLE_BOTTOM);
585
586                 setting_update_chk_status(rgd,
587                                           data_parentItem->int_slp_setting_binded);
588
589         } else if (data_parentItem == ad->data_date_fmt) {
590                 rgd = elm_radio_add(scroller);
591                 elm_radio_value_set(rgd, -1);
592                 setting_create_Gendial_exp_sub_field(scroller,
593                                                      &itc_multiline_1text_1icon,
594                                                      /* &(ad->itc_1icon_1text_sub), */
595                                                      NULL, NULL, parentItem,
596                                                      SWALLOW_Type_1RADIO, rgd,
597                                                      SETTING_DATE_FORMAT_DD_MM_YYYY,
598                                                      "IDS_ST_BODY_DDMMYYYY_DOT",
599                                                      NULL);
600
601                 setting_create_Gendial_exp_sub_field(scroller,
602                                                      &itc_multiline_1text_1icon,
603                                                      /* &(ad->itc_1icon_1text_sub), */
604                                                      NULL, NULL, parentItem,
605                                                      SWALLOW_Type_1RADIO, rgd,
606                                                      SETTING_DATE_FORMAT_MM_DD_YYYY,
607                                                      "IDS_ST_BODY_MM_DD_YYYY_DOT",
608                                                      NULL);
609
610                 setting_create_Gendial_exp_sub_field(scroller,
611                                                      &itc_multiline_1text_1icon,
612                                                      /* &(ad->itc_1icon_1text_sub), */
613                                                      NULL, NULL, parentItem,
614                                                      SWALLOW_Type_1RADIO, rgd,
615                                                      SETTING_DATE_FORMAT_YYYY_MM_DD,
616                                                      "IDS_COM_BODY_YYYYMMDD",
617                                                      NULL);
618
619                 setting_create_Gendial_exp_sub_field(scroller,
620                                                      &itc_multiline_1text_1icon,
621                                                      /* &(ad->itc_1icon_1text_sub), */
622                                                      NULL, NULL, parentItem,
623                                                      SWALLOW_Type_1RADIO, rgd,
624                                                      SETTING_DATE_FORMAT_YYYY_DD_MM,
625                                                      "IDS_ST_BODY_YYYY_DD_MM_DOT",
626                                                      NULL);
627
628                 setting_update_chk_status(rgd,
629                                           data_parentItem->int_slp_setting_binded);
630
631         } else if (data_parentItem == ad->data_firstday_week_fmt) {
632                 rgd = elm_radio_add(scroller);
633                 elm_radio_value_set(rgd, -1);
634                 setting_create_Gendial_exp_sub_field(scroller,
635                                                      &itc_multiline_1text_1icon,
636                                                      /* &(ad->itc_1icon_1text_sub), */
637                                                      NULL, rgd, parentItem,
638                                                      SWALLOW_Type_1RADIO, rgd,
639                                                      SETTING_WEEKOFDAY_FORMAT_SUNDAY,
640                                                      "IDS_ST_BODY_SUNDAY", NULL);
641
642                 setting_create_Gendial_exp_sub_field(scroller,
643                                                      &itc_multiline_1text_1icon,
644                                                      /* &(ad->itc_1icon_1text_sub), */
645                                                      NULL, rgd, parentItem,
646                                                      SWALLOW_Type_1RADIO, rgd,
647                                                      SETTING_WEEKOFDAY_FORMAT_MONDAY,
648                                                      "IDS_ST_BODY_MONDAY", NULL);
649
650                 setting_update_chk_status(rgd,
651                                           data_parentItem->int_slp_setting_binded);
652         }
653 }
654
655 static int setting_time_main_create(void *cb)
656 {
657         SETTING_TRACE_BEGIN;
658         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
659
660         SettingTimeUG *ad = (SettingTimeUG *) cb;
661
662         char *l_btn = NULL;
663         char *title = _(DATE_TIME_STR_DATE_AND_TIME);
664         char *caller = NULL;
665         ad->is_datefield_selected = EINA_FALSE;
666
667         app_control_h service = ad->bundle_data;
668
669         app_control_get_extra_data(service, "caller", &caller);
670         app_control_get_extra_data(service, "title", &title);
671
672         Evas_Object *scroller;  /*  scroller is a genlist */
673
674         ad->caller = caller;
675
676         l_btn = _("IDS_COM_BODY_BACK");
677         title = DATE_TIME_STR_DATE_AND_TIME;
678         gchar *title_str = NULL;
679
680         if (title)
681                 title_str = title;
682
683         ad->ly_main =
684             setting_create_layout_navi_bar_genlist(ad->win_main_layout,
685                                                    ad->win_get, title_str,
686                                                    l_btn, NULL,
687                                                    setting_time_main_click_softkey_left_cb,
688                                                    NULL, ad, &scroller,
689                                                    &ad->navi_bar);
690
691         ad->scrl_main = scroller;
692         elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
693
694         int value;
695         int err;
696         int ret = 0;
697         Elm_Object_Item *item;
698
699         item = elm_genlist_item_append(scroller, &itc_seperator, NULL, NULL,
700                                        ELM_GENLIST_ITEM_NONE, NULL, NULL);
701         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
702         setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, &value,
703                                  &err);
704
705         /*int enable_automatic = __setting_time_check_enable_automatic_update(); */
706         bool auto_flag = value;
707
708         if (auto_flag) { /*do special process only when auto mode */
709                 /*to read TAPI vconfs */
710                 int ret = 0;
711                 int t_nitz = 0;
712                 int t_offset = 0;
713                 ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_GMT, &t_nitz);
714                 ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, &t_offset);
715                 char *tzpath = vconf_get_str(VCONFKEY_TELEPHONY_NITZ_ZONE);
716                 if (ret == 0 && !isEmptyStr(tzpath)) {
717                         /*1.to update timezone */
718                         char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1];
719                         safeCopyStr(tz_path, SETTING_TIME_ZONEINFO_PATH, MAX_COMMON_BUFFER_LEN / 4);
720                         g_strlcat(tz_path, tzpath, sizeof(tz_path));
721                         SETTING_TRACE("full tz_path:%s", tz_path);
722                         ret = alarmmgr_set_timezone(tz_path);
723                         if (ret < 0) {
724                                 SETTING_TRACE("tzpath is not valid.");
725                         } else
726                                 SETTING_TRACE("alarmmgr_set_timezone - successful : %s \n", tz_path);
727                         if (!__setting_set_city_tzone(tzpath)) {
728                                 SETTING_TRACE("__setting_set_city_tzone ERROR")
729                         }
730                         get_city_name(tzpath);
731                         char *city = get_city_name_result();
732                         SETTING_TRACE("city:%s", city);
733                         ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city);
734
735                         /* 2.to set current time */
736                         int t_uptime = 0;
737                         FILE *fp = fopen("/proc/uptime", "r");
738                         if (fp) {
739                                 if (!fscanf(fp, "%d", &t_uptime)) {
740                                         SETTING_TRACE_ERROR("fscanf error");
741                                 }
742                                 fclose(fp);
743                                 fp = NULL;
744                         } else {
745                                 SETTING_TRACE_ERROR("fopen error");
746                         }
747
748                         SETTING_TRACE("t_nitz:%d, t_offset:%d, t_uptime:%d", t_nitz, t_offset, t_uptime);
749                         time_t t_current = t_nitz + t_uptime - t_offset;
750                         SETTING_TRACE("t_current:%d", t_current);
751                         ret = alarmmgr_set_systime(t_current);
752                 }
753                 FREE(tzpath);
754         }
755
756         /*  UI automatic */
757         /*if (!isEmulBin()) { */
758         ad->data_auto =
759             setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
760                                              setting_time_main_mouse_up_Gendial_list_cb,
761                                              ad, SWALLOW_Type_1ICON_1RADIO, NULL,
762                                              NULL, value,
763                                              DATE_TIME_STR_AUTOMATIC_UPDATE, NULL,
764                                              setting_time_main_chk_btn_cb);
765         if (ad->data_auto) {
766                 ad->data_auto->userdata = ad;
767         } else {
768                 SETTING_TRACE_ERROR("ad->data_auto is NULL");
769         }
770
771         /*ADD_GL_HELP(scroller,SETTING_TIME_AUTO_UPDATE_DESC); */
772         /*} */
773
774
775         /* create DATE_AND_TIME */
776         ad->data_time =
777             setting_create_Gendial_field_def(scroller, &(ad->itc_layout),
778                                              setting_time_main_mouse_up_Gendial_list_cb,
779                                              ad, SWALLOW_Type_LAYOUT_DATEFIELD,
780                                              NULL, NULL, 0,
781                                              DATE_TIME_STR_DATE_AND_TIME,
782                                              NULL,
783                                              NULL);
784         if (ad->data_time) {
785                 ad->data_time->userdata = ad;
786                 ad->data_time->nf = ad->navi_bar;
787                 ad->data_time->isItemDisableFlag = auto_flag;
788                 ad->data_time->activated_cb = setting_time_main_datefield_set_cb;
789                 elm_genlist_item_select_mode_set(ad->data_time->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
790
791                 Elm_Object_Item *item = elm_genlist_item_append(scroller, &(itc_bottom_line), NULL, NULL,
792                                                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
793                 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
794
795         } else {
796                 SETTING_TRACE_ERROR("ad->data_time is NULL");
797         }
798
799         /*ADD_GL_SEPARATOR(scroller); */
800         setting_set_i18n("worldclock", SETTING_TIME_SHARE_LOCAL_PATH);
801         char time_zone_sub_str[CITY_BUF_SIZE + GMT_BUF_SIZE + 3] = { 0, };
802         char *displayTimezone = NULL;
803
804         displayTimezone = get_timezone_displayname();
805
806         if (displayTimezone != NULL) {
807
808                 /* don't use hard coded value */
809                 /* get value from current timezone */
810
811                 char str_buf[GMT_BUF_SIZE] = {0, };
812                 get_gmt_offset(str_buf, GMT_BUF_SIZE);
813
814                 char *timezone_str = get_timezone_str();
815
816                 SETTING_TRACE("timezone : %s, displayTimezone :%s, gmt_offset : %s",
817                               timezone_str, displayTimezone, _(str_buf));
818                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s",
819                                displayTimezone, _(str_buf));
820
821                 FREE(timezone_str);
822                 retv_if(ret < 0, 0);
823         } else {
824                 /* default code */
825                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "Korean Standard Time, GMT +9:00");
826                 retv_if(ret < 0, 0);
827         }
828         FREE(displayTimezone);
829
830         /*  UI create time zone */
831         ad->data_tz =
832             setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2),
833                                              setting_time_main_mouse_up_Gendial_list_cb,
834                                              ad, SWALLOW_Type_INVALID, NULL,
835                                              NULL, 0, DATE_TIME_STR_TIME_ZONE,
836                                              time_zone_sub_str, NULL);
837         if (ad->data_tz) {
838                 ad->data_tz->userdata = ad;
839         } else {
840                 SETTING_TRACE_ERROR("ad->data_tz is NULL");
841         }
842
843         /*  UI create "Time format" */
844         setting_enable_expandable_genlist(scroller, ad,
845                                           __setting_time_main_exp_cb, NULL);
846
847         char *pa_time_format = get_pa_time_format_str();
848         ad->data_time_fmt = setting_create_Gendial_exp_parent_field(scroller,
849                                                                     &(ad->itc_2text_3_parent),
850                                                                     setting_time_main_mouse_up_Gendial_list_cb,
851                                                                     ad, SWALLOW_Type_INVALID,
852                                                                     DATE_TIME_STR_TIME_FORMAT,
853                                                                     pa_time_format,
854                                                                     SETTING_GROUP_STYLE_TOP, SETTING_GROUP_STYLE_NONE);
855         if (ad->data_time_fmt) {
856                 ad->data_time_fmt->int_slp_setting_binded =
857                     INT_SLP_SETTING_REGIONFORMAT_TIME1224;
858                 ad->data_time_fmt->group_style = SETTING_GROUP_STYLE_NONE;
859
860                 if (ad->is_expand_time_format_list && ad->data_time_fmt->item) {
861                         elm_genlist_item_expanded_set(ad->data_time_fmt->item, TRUE);
862                 }
863         } else {
864                 SETTING_TRACE_ERROR("ad->data_time_fmt is NULL");
865         }
866         G_FREE(pa_time_format);
867
868 #if APPLIED_DATATIME_DATA_FORMAT
869         char *pa_date_format = get_pa_date_format_str();
870         ad->data_date_fmt = setting_create_Gendial_exp_parent_field(scroller,
871                                                                     &(ad->itc_2text_3_parent),
872                                                                     setting_time_main_mouse_up_Gendial_list_cb,
873                                                                     ad, SWALLOW_Type_INVALID,
874                                                                     DATE_TIME_STR_TIME_FORMAT,
875                                                                     pa_time_format, SETTING_GROUP_STYLE_CENTER,
876                                                                     SETTING_GROUP_STYLE_CENTER);
877         if (ad->data_date_fmt) {
878                 ad->data_date_fmt->int_slp_setting_binded =
879                     INT_SLP_SETTING_DATE_FORMAT;
880         } else {
881                 SETTING_TRACE_ERROR("ad->data_date_fmt is NULL");
882         }
883         G_FREE(pa_date_format);
884 #endif
885
886 #if APPLIED_DATATIME_FIRSTDAY_WEEK
887         char *pa_week = get_pa_week_format_str();
888         ad->data_firstday_week_fmt =
889             setting_create_Gendial_exp_parent_field(scroller,
890                                                     &(ad->itc_2text_3_parent),
891                                                     setting_time_main_mouse_up_Gendial_list_cb,
892                                                     ad, SWALLOW_Type_INVALID,
893                                                     "IDS_CLD_BODY_FIRST_DAY_OF_WEEK",
894                                                     pa_week, SETTING_GROUP_STYLE_CENTER,
895                                                     SETTING_GROUP_STYLE_BOTTOM);
896         if (ad->data_firstday_week_fmt) {
897                 ad->data_firstday_week_fmt->int_slp_setting_binded =
898                     INT_SLP_SETTING_WEEK_FORMAT;
899         } else {
900                 SETTING_TRACE_ERROR("ad->data_firstday_week_fmt is NULL");
901         }
902         G_FREE(pa_week);
903 #endif
904
905         /*item = elm_genlist_item_append(scroller, &itc_bottom_seperator, NULL, NULL, */
906         /*                          ELM_GENLIST_ITEM_NONE, NULL, NULL); */
907         /*elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); */
908
909 #if 0
910         if (!enable_automatic) {
911                 if (ad->data_auto) {
912                         setting_disable_genlist_item(ad->data_auto->item);
913                 }
914         }
915 #endif
916
917         if (auto_flag) {
918                 if (ad->data_tz) {
919                         setting_disable_genlist_item(ad->data_tz->item);
920                 }
921                 if (ad->data_time) {
922                         setting_disable_genlist_item(ad->data_time->item);
923                 }
924         }
925
926         setting_view_time_main.is_create = 1;
927         vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, time_changed_callback, (void *)ad);
928
929         /*  register vconf key to get event callback for converting 12/24H */
930         vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, setting_time_main_int_vconf_change_cb, ad);
931         /*  register vconf key to get event callback for date format */
932         vconf_notify_key_changed(VCONFKEY_SETAPPL_DATE_FORMAT_INT, setting_time_main_int_vconf_change_cb, ad);
933
934         vconf_notify_key_changed(VCONFKEY_TELEPHONY_NITZ_GMT, __sim_time_info_chg_cb, ad);
935         vconf_notify_key_changed(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, __sim_time_info_chg_cb, ad);
936         vconf_notify_key_changed(VCONFKEY_TELEPHONY_NITZ_ZONE, __sim_time_info_chg_cb, ad);
937
938         vconf_notify_key_changed(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL,
939                                  setting_time_main_bool_vconf_change_cb, ad);
940
941         /* to avoid update time-diff, every per 3s to update. */
942 #ifdef USE_TIMER_UPDATE_TIME_IN_TIME_VIEW
943         ad->update_timer = ecore_timer_add(3, (Ecore_Task_Cb) __refresh_date_timer, ad);
944 #endif
945         return SETTING_RETURN_SUCCESS;
946 }
947
948 static int setting_time_main_destroy(void *cb)
949 {
950         SETTING_TRACE_BEGIN;
951         /* error check */
952         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
953
954         SettingTimeUG *ad = (SettingTimeUG *) cb;
955
956         /*      __finalize_resource(ad); */
957         if (ad->caller)
958                 FREE(ad->caller);
959
960 #ifdef USE_TIMER_UPDATE_TIME_IN_TIME_VIEW
961         if (ad->update_timer) {
962                 ecore_timer_del(ad->update_timer);
963                 ad->update_timer = NULL;
964         }
965 #endif
966
967 #if PROGRESS_POPUP_SHOW
968         if (ad->pop_progress) {
969                 evas_object_del(ad->pop_progress);
970                 ad->pop_progress = NULL;
971         }
972 #endif
973
974         if (ad->update_timezone_idler) {
975                 ecore_idler_del(ad->update_timezone_idler);
976                 ad->update_timezone_idler = NULL;
977         }
978
979         /* timer */
980         if (ad->refresh_time_idler) {
981                 ecore_idler_del(ad->refresh_time_idler);
982                 ad->refresh_time_idler = NULL;
983         }
984
985         vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED,
986                                  time_changed_callback);
987
988         vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
989                                  setting_time_main_int_vconf_change_cb);
990         vconf_ignore_key_changed(VCONFKEY_SETAPPL_DATE_FORMAT_INT,
991                                  setting_time_main_int_vconf_change_cb);
992
993         vconf_ignore_key_changed(VCONFKEY_TELEPHONY_NITZ_GMT, __sim_time_info_chg_cb);
994         vconf_ignore_key_changed(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, __sim_time_info_chg_cb);
995         vconf_ignore_key_changed(VCONFKEY_TELEPHONY_NITZ_ZONE, __sim_time_info_chg_cb);
996
997         vconf_ignore_key_changed(VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL,
998                                  setting_time_main_bool_vconf_change_cb);
999
1000         if (ad->ly_main != NULL) {
1001                 evas_object_del(ad->ly_main);
1002                 ad->ly_main = NULL;
1003                 setting_view_time_main.is_create = 0;
1004         }
1005
1006         return SETTING_RETURN_SUCCESS;
1007 }
1008
1009 static int setting_time_main_update(void *cb)
1010 {
1011         SETTING_TRACE_BEGIN;
1012         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
1013
1014         SettingTimeUG *ad = (SettingTimeUG *) cb;
1015
1016         if (ad->ly_main != NULL) {
1017                 evas_object_show(ad->ly_main);
1018                 /* update timezone */
1019                 if (ad->update_timezone_idler) {
1020                         ecore_idler_del(ad->update_timezone_idler);
1021                         ad->update_timezone_idler = NULL;
1022                 }
1023                 ad->update_timezone_idler =
1024                     ecore_idler_add((Ecore_Task_Cb) __update_timezone_idler, ad);
1025                 /* update time */
1026                 if (ad->refresh_time_idler) {
1027                         ecore_idler_del(ad->refresh_time_idler);
1028                         ad->refresh_time_idler = NULL;
1029                 }
1030                 ad->refresh_time_idler = ecore_idler_add(setting_update_datefield, ad);
1031         }
1032         return SETTING_RETURN_SUCCESS;
1033 }
1034
1035 static int setting_time_main_cleanup(void *cb)
1036 {
1037         SETTING_TRACE_BEGIN;
1038         return SETTING_RETURN_SUCCESS;
1039 }
1040
1041
1042 /* ***************************************************
1043  **
1044  **general func
1045  **
1046  ****************************************************/
1047
1048 int setting_time_check_automatic_time_update_state()
1049 {
1050         SETTING_TRACE_BEGIN;
1051         int bvalue = 0;
1052         int err = 0;
1053
1054         setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1055                                  &bvalue, &err);
1056
1057         return bvalue;
1058
1059 }
1060
1061 static int __setting_set_city_tzone(const char *pTZPath)
1062 {
1063         /* let's get city & timezone string from pTZPath */
1064         /* 1. city name */
1065         char szTimezone[GMT_BUF_SIZE] = {0,};
1066         char *pStr = strdup(pTZPath);
1067
1068         /* 2. timezone string +/-<n> ex. +9, -1 */
1069         get_gmt_offset(szTimezone, GMT_BUF_SIZE);
1070
1071         /* set timezone_id */
1072         /** @todo replace with vconf ID */
1073         vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_ID, pStr);
1074         FREE(pStr);
1075
1076         return TRUE;
1077 }
1078
1079 static void
1080 setting_time_main_launch_worldclock_result_ug_cb(ui_gadget_h ug,
1081                                                  app_control_h result, void *priv)
1082 {
1083         SETTING_TRACE_BEGIN;
1084         /* error check */
1085         retm_if(priv == NULL, "Data parameter is NULL");
1086
1087         SettingTimeUG *ad = (SettingTimeUG *) priv;
1088
1089         char *city = NULL;
1090         char *tzpath = NULL;
1091         app_control_get_extra_data(result, "city", &city);
1092         app_control_get_extra_data(result, "tzpath", &tzpath);
1093
1094         if (!tzpath) {
1095                 SETTING_TRACE("tzpath from worldclock UG is null.");
1096                 return;
1097         } else {
1098                 SETTING_TRACE("tzpath : %s", tzpath);
1099         }
1100         SETTING_TRACE("city : %s", city);
1101
1102         /* --------------------------------------------------------------------- */
1103         char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1];
1104         safeCopyStr(tz_path, SETTING_TIME_ZONEINFO_PATH, MAX_COMMON_BUFFER_LEN / 4);
1105         g_strlcat(tz_path, tzpath, sizeof(tz_path));
1106         SETTING_TRACE("full tz_path:%s", tz_path);
1107
1108         int ret = alarmmgr_set_timezone(tz_path);
1109         if (ret < 0) {
1110                 SETTING_TRACE("tzpath is not valid.");
1111                 if (tzpath)
1112                         FREE(tzpath);
1113                 if (city)
1114                         FREE(city);
1115                 return;
1116         } else
1117                 SETTING_TRACE("alarmmgr_set_timezone - successful : %s \n", tz_path);
1118
1119         ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city);
1120         setting_retm_if(ret != 0, "set vconf failed");
1121
1122         /* parse city and GMT offset from tzpath and system time property */
1123         /* set the strings in vconf which will be used while updating display of timezone */
1124         if (!__setting_set_city_tzone(tzpath)) {
1125                 SETTING_TRACE("__setting_set_city_tzone ERROR");
1126                 if (tzpath)
1127                         FREE(tzpath);
1128                 if (city)
1129                         FREE(city);
1130                 return;
1131         }
1132
1133         /* update the display for timezone */
1134         setting_update_timezone(ad);
1135         static int t_event_val = -1;
1136         vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED, t_event_val);
1137         if (tzpath)
1138                 FREE(tzpath);
1139         if (city)
1140                 FREE(city);
1141         SETTING_TRACE_END;
1142 }
1143
1144 void setting_time_main_launch_worldclock_destroy_ug_cb(ui_gadget_h ug,
1145                                                        void *priv)
1146 {
1147         SETTING_TRACE_BEGIN;
1148         /* if(ug) ug_destroy(ug); */
1149         /* restore the '<-' button on the navigate bar */
1150         ret_if(!priv);
1151         SettingTimeUG *ad = (SettingTimeUG *) priv;
1152         if (ug) {
1153                 setting_ug_destroy(ug);
1154                 ad->ug_loading = NULL;
1155         }
1156         Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
1157         ret_if(!navi_it);
1158         Evas_Object *back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
1159
1160         if (back_btn != NULL) {
1161                 elm_object_style_set(back_btn, NAVI_BACK_BUTTON_STYLE); /* take into effect */
1162         }
1163
1164         elm_object_tree_focus_allow_set(ad->ly_main, EINA_TRUE);
1165 }
1166
1167 void setting_time_main_launch_worldclock_layout_ug_cb(ui_gadget_h ug,
1168                                                       enum ug_mode mode,
1169                                                       void *priv)
1170 {
1171         SETTING_TRACE_BEGIN;
1172         /*SettingTimeUG *ad = (SettingTimeUG *) priv; */
1173         Evas_Object *base;
1174
1175         if (!priv)
1176                 return;
1177
1178         base = (Evas_Object *) ug_get_layout(ug);
1179         if (!base)
1180                 return;
1181
1182         switch (mode) {
1183                 case UG_MODE_FULLVIEW:
1184                         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
1185                                                          EVAS_HINT_EXPAND);
1186                         /*elm_win_resize_object_add(ad->win_get, base); */
1187                         evas_object_show(base);
1188                         break;
1189                 default:
1190                         break;
1191         }
1192         SETTING_TRACE_END;
1193 }
1194
1195
1196 void setting_time_main_launch_worldclock_sg(void *data)
1197 {
1198         SETTING_TRACE_BEGIN;
1199         /* error check */
1200         retm_if(data == NULL, "Data parameter is NULL");
1201
1202         SettingTimeUG *ad = (SettingTimeUG *) data;
1203
1204         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
1205         setting_retm_if(!cbs, "calloc failed");
1206         cbs->layout_cb = setting_time_main_launch_worldclock_layout_ug_cb;
1207         cbs->result_cb = setting_time_main_launch_worldclock_result_ug_cb;
1208         cbs->destroy_cb = setting_time_main_launch_worldclock_destroy_ug_cb;
1209         cbs->priv = (void *)ad;
1210
1211         elm_object_tree_focus_allow_set(ad->ly_main, EINA_FALSE);
1212         SETTING_TRACE("to load ug[%s]", "worldclock-efl");
1213         ad->ug_loading =
1214             setting_ug_create(ad->ug, "worldclock-efl", UG_MODE_FULLVIEW, NULL, cbs);
1215         if (NULL == ad->ug_loading) {   /* error handling */
1216         }
1217
1218         FREE(cbs);
1219         return;
1220 }
1221
1222
1223 Eina_Bool setting_update_datefield(void *cb)
1224 {
1225         SETTING_TRACE_BEGIN;
1226         retvm_if(cb == NULL, EINA_FALSE, "Data parameter is NULL");
1227         SettingTimeUG *ad = (SettingTimeUG *) cb;
1228
1229         if (ad->data_time) {
1230                 time_t cctime = time(NULL);
1231                 struct tm ts_ret;
1232                 struct tm *ts = localtime_r(&cctime, &ts_ret);
1233                 SETTING_TRACE("year : %d, month : %d, day : %d, hour : %d, min : %d",
1234                               ts_ret.tm_year, ts_ret.tm_mon, ts_ret.tm_mday, ts_ret.tm_hour, ts_ret.tm_min);
1235                 SETTING_TRACE("time : %s", ctime(&cctime));
1236                 if (ts) {
1237 #if 0
1238                         if (ad->data_time->eo_check)
1239                                 elm_datetime_value_set(ad->data_time->eo_check, &ts_ret);
1240 #endif
1241
1242                         char *date = __setting_phone_lang_get_by_pattern("en_US", "MMM/d/yyyy");
1243                         char *time;
1244                         static char date_arr[DEF_BUF_SIZE], time_arr[DEF_BUF_SIZE];
1245                         char *pa_time_format = get_pa_time_format_str();
1246                         if (!strncmp(pa_time_format, "IDS_COM_BODY_12_HOURS", strlen("IDS_COM_BODY_12_HOURS")))
1247                                 time = __setting_phone_lang_get_by_pattern("en_US", "hhmm");
1248                         else
1249                                 time = __setting_phone_lang_get_by_pattern("en_US", "Hm");
1250
1251                         strncpy(date_arr, date, DEF_BUF_SIZE);
1252                         strncpy(time_arr, time, DEF_BUF_SIZE);
1253
1254                         date_arr[DEF_BUF_SIZE - 1] = '\0';
1255                         time_arr[DEF_BUF_SIZE - 1] = '\0';
1256
1257                         elm_object_text_set(ad->data_time->btn_left, date_arr);
1258                         evas_object_resize(ad->data_time->btn_left, 300, -1);
1259                         elm_object_text_set(ad->data_time->btn_right, time_arr);
1260                         evas_object_resize(ad->data_time->btn_right, 270, -1);
1261                         FREE(pa_time_format);
1262                 }
1263         }
1264         if (ad->refresh_time_idler) {
1265                 ecore_idler_del(ad->refresh_time_idler);
1266                 ad->refresh_time_idler = NULL;
1267         }
1268         return 0;
1269 }
1270
1271 /* ***************************************************
1272  **
1273  **call back func
1274  **
1275  ****************************************************/
1276
1277 void
1278 setting_time_main_click_softkey_left_cb(void *data, Evas_Object *obj,
1279                                         void *event_info)
1280 {
1281         SETTING_TRACE_BEGIN;
1282         retm_if(data == NULL, "Data parameter is NULL");
1283
1284         SettingTimeUG *ad = (SettingTimeUG *) data;
1285
1286         /*__finalize_resource(ad); */
1287
1288         /* Send destroy request */
1289         ug_destroy_me(ad->ug);
1290 }
1291
1292 /* ***************************************************
1293  **
1294  **call back func
1295  **
1296  ****************************************************/
1297
1298 void
1299 setting_time_main_click_softkey_caller_exist_left_cb(void *data,
1300                                                      Evas_Object *obj,
1301                                                      void *event_info)
1302 {
1303         SETTING_TRACE_BEGIN;
1304         /* error check */
1305         retm_if(data == NULL, "Data parameter is NULL");
1306
1307         SettingTimeUG *ad = (SettingTimeUG *) data;
1308
1309         /*  Create Bundle and send message */
1310         app_control_h svc;
1311         if (app_control_create(&svc))
1312                 return;
1313
1314         app_control_add_extra_data(svc, "result", "lbutton_click");
1315         ug_send_result(ad->ug, svc);
1316
1317         app_control_destroy(svc);
1318
1319         /* Send destroy request */
1320         ug_destroy_me(ad->ug);
1321 }
1322
1323 void
1324 setting_time_main_click_softkey_caller_exist_right_cb(void *data,
1325                                                       Evas_Object *obj,
1326                                                       void *event_info)
1327 {
1328         SETTING_TRACE_BEGIN;
1329         /* error check */
1330         retm_if(data == NULL, "Data parameter is NULL");
1331
1332         SettingTimeUG *ad = (SettingTimeUG *) data;
1333
1334         /*  Create Bundle and send message */
1335         app_control_h svc;
1336         if (app_control_create(&svc))
1337                 return;
1338
1339         app_control_add_extra_data(svc, "result", "rbutton_click");
1340         ug_send_result(ad->ug, svc);
1341
1342         app_control_destroy(svc);
1343
1344         /* Send destroy request */
1345         ug_destroy_me(ad->ug);
1346 }
1347
1348 #if UN_SUPPORT_TIME_DYNAMIC_UPDATE
1349 static void setting_time_reboot_resp_cb(void *data, Evas_Object *obj,
1350                                         void *event_info)
1351 {
1352         SETTING_TRACE_BEGIN;
1353         int response_type = btn_type(obj);
1354         if (POPUP_RESPONSE_OK == response_type) {
1355                 setting_time_main_btn_update_ok_cb(data);
1356         } else if (POPUP_RESPONSE_CANCEL == response_type) {
1357                 setting_time_main_btn_update_cancel_cb(data);
1358         }
1359
1360         SettingTimeUG *ad = data;
1361         if (ad->pop) {
1362                 evas_object_del(ad->pop);
1363                 ad->pop = NULL;
1364         }
1365 }
1366 #endif
1367
1368 static void __time_auto_update(void *data)
1369 {
1370         SETTING_TRACE_BEGIN;
1371         setting_retm_if(data == NULL, "Data parameter is NULL");
1372         SettingTimeUG *ad = (SettingTimeUG *) data;
1373         int err;
1374         setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1375                                  SETTING_ON_OFF_BTN_ON, &err);
1376         if (ad->data_tz) {
1377                 setting_disable_genlist_item(ad->data_tz->item);
1378         }
1379
1380 #if 0
1381         elm_object_text_set(ad->data_time->btn_left, date);
1382         evas_object_resize(ad->data_time->btn_left, 300, -1);
1383 #endif
1384
1385 #if 1
1386         if (ad->data_time) {
1387                 ad->data_time->isItemDisableFlag = FALSE;
1388                 /*setting_disable_evas_object(ad->data_time->eo_check); */
1389                 setting_disable_evas_object(ad->data_time->btn_left);
1390                 setting_disable_evas_object(ad->data_time->btn_right);
1391                 setting_disable_genlist_item(ad->data_time->item);
1392         }
1393 #endif
1394         __update_time_via_sim_card(ad);
1395         SETTING_TRACE_END;
1396 }
1397
1398 static void
1399 setting_time_main_chk_btn_cb(void *data, Evas_Object *obj, void *event_info)
1400 {
1401         SETTING_TRACE_BEGIN;
1402         /* error check */
1403         retm_if(data == NULL, "Data parameter is NULL");
1404         SettingTimeUG *ad = NULL;
1405         Setting_GenGroupItem_Data *list_item =
1406             (Setting_GenGroupItem_Data *) data;
1407         ad = list_item->userdata;
1408         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
1409         /*if (ad->data_auto) */
1410         /*      ad->chk_auto = ad->data_auto->eo_check; */
1411
1412 #if 0
1413         if (ad->data_time) {
1414                 elm_object_focus_set(ad->data_time->eo_check, EINA_FALSE);
1415         }
1416 #endif
1417
1418         int err;
1419         if (obj == ad->data_auto->eo_check) {
1420                 int bvalue;
1421                 setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1422                                          &bvalue, &err);
1423                 if (bvalue) {
1424                         (void) setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, SETTING_ON_OFF_BTN_OFF, &err);
1425                         setting_update_gl_item_chk_status(ad->data_auto, 0);
1426
1427                         if (ad->data_tz) {
1428                                 setting_enable_genlist_item(ad->data_tz->item);
1429                         }
1430
1431                         if (ad->data_time) {
1432                                 ad->data_time->isItemDisableFlag = FALSE;
1433                                 /*setting_disable_evas_object(ad->data_time->eo_check); */
1434                                 setting_enable_evas_object(ad->data_time->btn_left);
1435                                 setting_enable_evas_object(ad->data_time->btn_right);
1436                                 setting_enable_genlist_item(ad->data_time->item);
1437                         }
1438
1439
1440
1441                 } else {
1442 #if UN_SUPPORT_TIME_DYNAMIC_UPDATE
1443                         ad->pop =
1444                             setting_create_popup_with_btn(ad, ad->win_get, NULL,
1445                                                           _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"),
1446                                                           setting_time_reboot_resp_cb,
1447                                                           0, 2,
1448                                                           dgettext("sys_string",
1449                                                                    "IDS_COM_SK_OK"),
1450                                                           _("IDS_COM_SK_CANCEL"));
1451 #else
1452                         __time_auto_update(ad);
1453 #endif
1454                 }
1455         }
1456         SETTING_TRACE_END;
1457 }
1458
1459 static void setting_time_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
1460                                                        void *event_info)
1461 {
1462         SETTING_TRACE_BEGIN;
1463         /* error check */
1464         setting_retm_if(data == NULL, "Data parameter is NULL");
1465
1466         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
1467         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1468         elm_genlist_item_selected_set(item, 0);
1469         Setting_GenGroupItem_Data *list_item =
1470             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
1471
1472         SettingTimeUG *ad = (SettingTimeUG *) data;
1473         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
1474
1475 #if 0
1476         if (ad->data_time && ad->data_time != list_item) {
1477                 elm_object_focus_set(ad->data_time->eo_check, EINA_FALSE);
1478         }
1479 #endif
1480
1481         if (ad->data_tz == list_item) {
1482                 ad->is_datefield_selected = EINA_FALSE;
1483                 if (1 == setting_time_check_automatic_time_update_state()) {
1484                         setting_create_simple_popup(ad, ad->win_get,
1485                                                     NULL, _(AUTO_TIME_UPDATE_ON));
1486                 } else {
1487                         setting_time_main_launch_worldclock_sg(ad);
1488                 }
1489
1490         } else if (ad->data_time == list_item) {
1491                 ad->is_datefield_selected = EINA_TRUE;
1492                 if (1 == setting_time_check_automatic_time_update_state()) {
1493                         setting_create_simple_popup(ad, ad->win_get,
1494                                                     NULL, _(AUTO_TIME_UPDATE_ON));
1495                 } else {
1496                         /* setting_view_change(&setting_view_time_main, &setting_view_time_time, ad); */
1497                 }
1498         } else if (ad->data_auto == list_item) {
1499                 ad->is_datefield_selected = EINA_FALSE;
1500                 int old_status = list_item->chk_status;
1501                 /* new status */
1502                 setting_update_gl_item_chk_status(list_item, !old_status);
1503                 int err = 0;
1504                 if (!list_item->chk_status) {
1505                         (void)
1506                         setting_set_bool_slp_key
1507                         (BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1508                          SETTING_ON_OFF_BTN_OFF, &err);
1509
1510                         if (ad->data_tz) {
1511                                 setting_enable_genlist_item(ad->data_tz->item);
1512                         }
1513
1514                         if (ad->data_time) {
1515                                 ad->data_time->isItemDisableFlag = FALSE;
1516                                 setting_enable_evas_object(ad->data_time->eo_check);
1517                                 setting_enable_genlist_item(ad->data_time->item);
1518                         }
1519
1520                 } else {
1521 #if UN_SUPPORT_TIME_DYNAMIC_UPDATE
1522                         ad->pop =
1523                             setting_create_popup_with_btn(ad, ad->win_get, NULL,
1524                                                           _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"),
1525                                                           setting_time_reboot_resp_cb,
1526                                                           0, 2,
1527                                                           dgettext("sys_string", "IDS_COM_SK_OK"),
1528                                                           _("IDS_COM_SK_CANCEL"));
1529 #else
1530                         __time_auto_update(ad);
1531 #endif
1532                 }
1533
1534         } else if (ad->data_time_fmt == list_item
1535                    || ad->data_date_fmt == list_item
1536                    || ad->data_firstday_week_fmt == list_item) {
1537                 ad->is_datefield_selected = EINA_FALSE;
1538                 bool status = !elm_genlist_item_expanded_get(item);
1539                 elm_genlist_item_expanded_set(item, status);
1540         }
1541 }
1542
1543
1544 void setting_time_main_btn_update_ok_cb(void *cb)
1545 {
1546         SETTING_TRACE_BEGIN;
1547         SettingTimeUG *ad = (SettingTimeUG *) cb;
1548         int err;                /* error check */
1549         setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1550                                  SETTING_ON_OFF_BTN_ON, &err);
1551         setting_update_gl_item_chk_status(ad->data_auto, 1);
1552
1553         deviced_request_reboot();
1554
1555         /*  We'd better check return value from deviced_request_reboot() function. */
1556         /*  It will return 0 on success or -1 if failed. */
1557 }
1558
1559
1560 void setting_time_main_btn_update_cancel_cb(void *cb)
1561 {
1562         SETTING_TRACE_BEGIN;
1563         SettingTimeUG *ad = (SettingTimeUG *) cb;
1564
1565         int err;                /* error check */
1566
1567         retm_if(cb == NULL, "Data parameter is NULL");
1568         setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1569                                  SETTING_ON_OFF_BTN_OFF, &err);
1570         setting_update_gl_item_chk_status(ad->data_auto, 0);
1571
1572 }
1573
1574
1575 static UChar *uastrcpy(const char *chars)
1576 {
1577         int len = 0;
1578         UChar *str = NULL;
1579         len = safeStrLen(chars);
1580         str = (UChar *) malloc(sizeof(UChar) * (len + 1));
1581         if (!str)
1582                 return NULL;
1583         u_uastrcpy(str, chars);
1584         return str;
1585 }
1586
1587 static void ICU_set_timezone(const char *timezone)
1588 {
1589         SETTING_TRACE("ICU_set_timezone = %s ", timezone);
1590         UErrorCode ec = U_ZERO_ERROR;
1591         UChar *str = uastrcpy(timezone);
1592
1593         ucal_setDefaultTimeZone(str, &ec);
1594         if (U_SUCCESS(ec)) {
1595                 SETTING_TRACE("ucal_setDefaultTimeZone() SUCCESS ");
1596         } else {
1597                 SETTING_TRACE("ucal_setDefaultTimeZone() FAILED : %s ",
1598                               u_errorName(ec));
1599         }
1600         FREE(str);
1601 }
1602
1603 /**
1604  * ex) timezone : Asia/Seoul --> returns "+09"
1605  *
1606  * char outstr2[4];
1607  */
1608 static void get_gmt_offset(char *str_buf, int size)
1609 {
1610         /* timezone string +/-<n> ex. +9, -1 */
1611         time_t t = time(0);     /* get unix time. sec. */
1612
1613         struct tm *data;
1614         data = localtime(&t);           /* save time as structure. */
1615
1616         setting_retm_if(!data, "data is NULL");
1617
1618         int gmtoffset_hour = (data->tm_gmtoff) / 3600;          /* result : hour. */
1619         int gmtoffset_min = ((data->tm_gmtoff) % 3600) / 60;    /* result : min. */
1620
1621 #if 0
1622         if (gmtoffset_min != 0) {
1623                 SETTING_TRACE("gmtoffset_min != 0 -------> %d", gmtoffset_min);
1624                 gmtoffset_min = 30;
1625         }
1626 #endif
1627
1628         /*snprintf(str_buf, size, "%+d:%02u", gmtoffset_hour, gmtoffset_min); */
1629         snprintf(str_buf, size, "%+d:%02d", gmtoffset_hour, abs(gmtoffset_min));
1630         SETTING_TRACE_DEBUG("szTimezone is of a valid format: GMT: %s", str_buf);
1631
1632         int ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_INT, str_buf);
1633         if (ret == -1) {
1634                 SETTING_TRACE_ERROR("set vconf failed");
1635         }
1636
1637 }
1638
1639
1640 /* automatic */
1641 static char *get_timezone_str()
1642 {
1643         SETTING_TRACE_BEGIN;
1644
1645         enum { BUFFERSIZE = 1024 };
1646         char buf[BUFFERSIZE];
1647         ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf) - 1);
1648
1649         if (len != -1) {
1650                 buf[len] = '\0';
1651         } else {
1652                 /* handle error condition */
1653         }
1654         return g_strdup(buf + 20);              /*Asia/Seoul */
1655 }
1656
1657 static char *get_city_name_result()
1658 {
1659         return s_result;
1660 }
1661
1662
1663 /* in_str = "Asia/Seoul" */
1664 static bool get_city_name(char *tzname)
1665 {
1666         sqlite3 *pSQLite3 = NULL;
1667         char    *szErrMsg = NULL;
1668
1669         int rst = sqlite3_open("/opt/dbspace/.worldclock.db", &pSQLite3);
1670         if (rst) {
1671                 SETTING_TRACE("Can't open database: %s", sqlite3_errmsg(pSQLite3));
1672                 sqlite3_close(pSQLite3);
1673                 pSQLite3 = NULL;
1674                 return false;
1675         } else {
1676                 SETTING_TRACE("Database opened!!");
1677                 char query_str[DEF_BUF_SIZE];
1678                 snprintf(query_str, DEF_BUF_SIZE, "SELECT city FROM city_table where tz_path=\"%s\"", tzname);
1679                 SETTING_TRACE("%s \n", query_str);
1680                 rst = sqlite3_exec(pSQLite3, query_str, query_callback, 0, &szErrMsg);
1681         }
1682
1683         sqlite3_free(szErrMsg);
1684         sqlite3_close(pSQLite3);
1685         SETTING_TRACE("Database close!!\n");
1686         return true;
1687 }
1688
1689 static int query_callback(void *NotUsed, int argc, char **argv, char **azColName)
1690 {
1691         int i = 0;
1692         SETTING_TRACE("%s\n", argv[i] ? argv[i] : "NULL");
1693         s_result = g_strdup(argv[i] ? argv[i] : "NULL");
1694         return 0;
1695 };
1696
1697 static char *get_timezone_displayname()
1698 {
1699         SETTING_TRACE_BEGIN;
1700
1701         UErrorCode status = U_ZERO_ERROR;;
1702         UChar displayName[SETTING_STR_SLP_LEN] = {0, };
1703         char *timezone_str = NULL;
1704         const char *localeID = uloc_getDefault();
1705
1706         time_t t = time(0);
1707         struct tm *data = localtime(&t);
1708
1709         ICU_set_timezone(get_timezone_str());
1710
1711         UCalendar *cal = ucal_open(NULL, -1, localeID, UCAL_GREGORIAN, &status);
1712         if (U_FAILURE(status))
1713                 SETTING_TRACE_ERROR("ucal_open got an error : %d", status);
1714
1715         status = U_ZERO_ERROR;
1716
1717         /* get timezone display name (check dst) */
1718         if (data) {
1719                 if (data->tm_isdst)
1720                         ucal_getTimeZoneDisplayName(cal, UCAL_DST, localeID, displayName, SETTING_STR_SLP_LEN, &status);
1721                 else
1722                         ucal_getTimeZoneDisplayName(cal, UCAL_STANDARD, localeID, displayName, SETTING_STR_SLP_LEN, &status);
1723         }
1724
1725         if (U_FAILURE(status))
1726                 SETTING_TRACE_ERROR("ucal_getTimeZoneDisplayName got an error : %s, %d", displayName, status);
1727         status = U_ZERO_ERROR;
1728
1729         ucal_close(cal);
1730
1731         int len = 0;
1732         int len_str = 0;
1733         int len_utf8 = 0;
1734
1735         len = u_strlen(displayName);
1736         len_str = sizeof(char) * 4 * (len + 1);
1737         timezone_str = (char *)calloc(1, len_str);
1738         if (!timezone_str) {
1739                 SETTING_TRACE_ERROR("timezone string is null");
1740                 return NULL;
1741         }
1742
1743         u_strToUTF8(timezone_str, len_str, &len_utf8, displayName, len, &status);
1744
1745         SETTING_TRACE("timezone : %s, %s", displayName, timezone_str);
1746
1747         SETTING_TRACE_END;
1748         return timezone_str;
1749
1750 }
1751