4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <setting-time-main.h>
33 #include <vconf-keys.h>
35 #include <unicode/udat.h>
36 #include <unicode/ustring.h>
37 #include <unicode/uloc.h>
38 #include <unicode/ucal.h>
39 #include <unicode/utmscale.h>
42 #define PROGRESS_POPUP_SHOW 0
45 static UChar *uastrcpy(const char *chars);
46 static void ICU_set_timezone(const char *timezone);
47 static int get_timezone_isdst(int* isdst);
48 static void get_gmt_offset(char *str_buf, int size);
50 static char* get_timezone_str();
51 static char* get_city_name_result();
52 static bool get_city_name(char* tzname);
54 static char* s_result;
55 static int query_callback(void *NotUsed, int argc, char **argv, char **azColName);
56 static bool setting_update_timezone(SettingTimeUG *ad);
58 static int setting_time_main_create(void *cb);
59 static int setting_time_main_destroy(void *cb);
60 static int setting_time_main_update(void *cb);
61 static int setting_time_main_cleanup(void *cb);
63 setting_view setting_view_time_main = {
64 .create = setting_time_main_create,
65 .destroy = setting_time_main_destroy,
66 .update = setting_time_main_update,
67 .cleanup = setting_time_main_cleanup,
70 static void setting_time_reboot_resp_cb(void *data, Evas_Object *obj,
73 bool __update_timezone_idler(SettingTimeUG *ad)
75 setting_update_timezone(ad);
76 ad->update_timezone_idler = NULL;
80 void time_changed_callback(keynode_t *key, void *data) {
82 SETTING_TRACE_DEBUG("time and timezone have been changed: TIME_CHANGED_HEYNOTY_CALLBACK");
83 SettingTimeUG *ad = (SettingTimeUG *)data;
85 int ret = setting_time_update_cb(ad);
87 SETTING_TRACE("FAIL: setting_time_update_db(ad)\n");
90 SETTING_TRACE("ad->is_datefield_selected:%d", ad->is_datefield_selected)
91 if(EINA_TRUE == ad->is_datefield_selected) {
92 /* Timezone is not changed and a selected value of the datefield is already changed */
93 SETTING_TRACE("Datefield is selected\n");
98 // vconfset to update timezone
99 char pTZPath[__MAX_PATH_SIZE];
100 ssize_t nLen = readlink(SETTING_TZONE_SYMLINK_PATH, pTZPath, sizeof(pTZPath)-1);
102 pTZPath[nLen] = '\0';
104 SETTING_TRACE("parse error for SETTING_TZONE_SYMLINK_PATH");
108 if (!__setting_set_city_tzone(&pTZPath[20])) {
109 SETTING_TRACE("__setting_set_city_tzone ERROR");
112 char *timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
113 setting_retm_if(timezone == NULL, "get vonf failed");
114 ICU_set_timezone(timezone);
118 if (ad->update_timezone_idler) {
119 ecore_idler_del(ad->update_timezone_idler);
120 ad->update_timezone_idler = NULL;
122 ad->update_timezone_idler =
123 ecore_idler_add((Ecore_Task_Cb) __update_timezone_idler, ad);
125 if (ad->refresh_time_idler) {
126 ecore_idler_del(ad->refresh_time_idler);
127 ad->refresh_time_idler = NULL;
129 ad->refresh_time_idler = ecore_idler_add(setting_update_datefield, ad);
132 void setting_time_update_time_date_format_string(SettingTimeUG *ad)
142 char time_str[MAX_ARGS];
145 ts = localtime_r(&ctime, &ts_ret);
148 /* set time in particular format */
149 ret = setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224, &value, &err);
150 if (ret == SETTING_RETURN_FAIL)
151 value = VCONFKEY_TIME_FORMAT_12;
154 case VCONFKEY_TIME_FORMAT_12:
157 strftime(time_str, MAX_ARGS, "%l:%M %p ", &ts_ret);
161 case VCONFKEY_TIME_FORMAT_24:
163 strftime(time_str, MAX_ARGS, "%H:%M", &ts_ret);
172 elm_object_item_data_set(ad->data_time->item, ad->data_time);
173 elm_genlist_item_update(ad->data_time->item);
177 bool setting_update_timezone(SettingTimeUG *ad)
179 /* SETTING_TRACE_BEGIN; */
180 char time_zone_sub_str[CITY_BUF_SIZE + GMT_BUF_SIZE + 3] = { 0, };
181 char *pa_timezone = NULL;
182 char *pa_city = NULL;
186 pa_city = vconf_get_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT);
187 pa_timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_INT);
189 //if ((pa_timezone != NULL) && (_(pa_city) != NULL && safeStrCmp(_(pa_city), "NULL"))) {
190 if ((pa_timezone != NULL) && (_(pa_city) != NULL )) {
191 /* SETTING_TRACE_DEBUG("*** timezone: %s *** ", timezone); */
192 /* SETTING_TRACE_DEBUG("*** city: %s *** ", _(city)); */
193 /* SETTING_TRACE_DEBUG("*** ret: %d, dst: %d *** ", ret, dst); */
195 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s", _(pa_city), pa_timezone);
196 //ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s", pa_timezone, _(pa_city));
200 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT +09", _("IDS_WCL_BODY_CITYNAME_SEOUL"));
203 SETTING_TRACE("ad->data_tz:%p", 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);
214 static void setting_time_main_int_vconf_change_cb(keynode_t *key, void *data)
216 /* SETTING_TRACE_BEGIN; */
217 ret_if(NULL == data);
218 SettingTimeUG *ad = data;
219 int status = vconf_keynode_get_int(key);
220 char *vconf_name = vconf_keynode_get_name(key);
221 /* SETTING_TRACE("vconf_name:%s", vconf_name); */
223 if (!safeStrCmp(vconf_name, VCONFKEY_REGIONFORMAT_TIME1224)) {
226 /* VCONFKEY_REGIONFORMAT_TIME1224 1:12H 2:24H */
227 if (status <= 2 && status > 0) /* 1, 2 */
228 --status; /* set to 0 or 1 */
230 status = 0; /* set 12H */
232 /* TODO assert 1 or 0 */
233 ad->data_time->chk_status = !status;
235 char datefield_format[MAX_DATETIME_FORMAT_LEN + 1] = {0, };
237 const char *time_format = NULL;
238 if (ad->data_time->chk_status)//12 hours
240 time_format = "%I : %M %p";
242 time_format = "%H : %M";
245 //get date format from datefiled itself, if elm_datetime_add() supports set date-format via ICU.
246 #ifdef SUPPORT_DATEFIELD_DATE_FORMAT_AUTOSET
247 const char *old_format = elm_datetime_format_get(ad->data_time->eo_check);
248 snprintf(datefield_format, MAX_DATE_FORMAT_LEN + 1, //add one space " "
250 safeStrNCat(datefield_format, time_format, MAX_DATETIME_FORMAT_LEN);
251 SETTING_TRACE("datefield_format:%s", datefield_format);
253 int value = SETTING_DATE_FORMAT_DD_MM_YYYY;
256 char *date_format_str[] = { "%d %b %Y", "%b %d %Y", "%Y %b %d", "%Y %d %b" };
257 int ret = setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
258 if (ret == SETTING_RETURN_FAIL)
259 value = SETTING_DATE_FORMAT_DD_MM_YYYY;
261 snprintf(datefield_format, MAX_DATETIME_FORMAT_LEN,
262 "%s %s", date_format_str[value], time_format);
265 elm_datetime_format_set(ad->data_time->eo_check, datefield_format);
270 /* ***************************************************
274 ***************************************************/
275 static void setting_time_main_datefield_change_cb(void *data, Evas_Object *obj,
280 ret_if(data == NULL);
281 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
282 SettingTimeUG *ad = list_item->userdata;
284 if (EINA_FALSE == ad->is_datefield_selected) {
285 SETTING_TRACE("Datefield is not selected\n");
289 // If auto update is on, don't anything while the datefield has been updated (i.e., time runs)
290 if (1 == setting_time_check_automatic_time_update_state()) {
291 SETTING_TRACE("AUTO_TIME ON: no action");
295 // otherwise, we apply a new date which has been changed by a user
299 elm_datetime_value_get(obj, &_tm);
301 SETTING_TRACE("year : %d, month : %d, day : %d, hour : %d, min : %d",
302 _tm.tm_year, _tm.tm_mon, _tm.tm_mday, _tm.tm_hour, _tm.tm_min);
303 if (2037 < _tm.tm_year) {
304 setting_create_simple_popup(ad, ad->win_get,
305 NULL, _(ERR_BIGGER_THAN_2037));
308 #if SUPPORT_SCREEN_PROTECTED /* if not lock the current state, after set the time, the screen will become dimmed */
309 pm_lock_state(LCD_NORMAL, STAY_CUR_STATE, 0);
314 if (get_timezone_isdst(&isdst) == SETTING_RETURN_SUCCESS) {
315 _tm.tm_isdst = isdst;
318 SETTING_TRACE_ERROR("get_timezone_isdst() failed");
322 /* local time -> gmtime */
323 time_t the_time = mktime(&_tm); /* represent local time */
325 if ( (time(NULL)/ONE_MINUTE) == (the_time/ONE_MINUTE) )
327 SETTING_TRACE("Time is not changed\n");
328 //current time didn't change
332 #if PROGRESS_POPUP_SHOW
333 // remove popup if created
334 if (ad->pop_progress) {
335 evas_object_del(ad->pop_progress);
336 ad->pop_progress = NULL;
341 setting_create_popup_with_progressbar(ad, ad->win_get, "pending_list",
342 NULL, NULL, NULL, 0, TRUE, TRUE);
345 // invoke API to change time
346 int ret = sysman_set_datetime(the_time);
347 setting_retm_if(ret == -1, "sysman_set_datetime call failed");
352 Eina_Bool __refresh_date_timer(void *data)
354 //SETTING_TRACE_BEGIN;
355 SettingTimeUG *ad = data;
357 time_t ctime = time(NULL);
359 struct tm *ts = localtime_r(&ctime, &ts_ret);
363 elm_datetime_value_get(ad->data_time->eo_check, &ui_time);
364 if ( (ctime/ONE_MINUTE) != (mktime(&ui_time)/ONE_MINUTE) )
366 SETTING_TRACE("To refresh the UI element after 1 minute passed.\t in %s", __FUNCTION__);
367 elm_datetime_value_set(ad->data_time->eo_check, &ts_ret);
373 static void __setting_time_main_exp_cb(void *data, Evas_Object *obj,
376 ret_if(NULL == data || NULL == event_info);
378 SettingTimeUG *ad = (SettingTimeUG *) data;
379 Elm_Object_Item *parentItem = event_info; /* parent item */
380 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
381 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
384 if (data_parentItem == ad->data_time_fmt) {
386 rgd = elm_radio_add(scroller);
387 elm_radio_value_set(rgd, -1);
388 setting_create_Gendial_exp_sub_field(scroller,
389 &(ad->itc_1icon_1text_sub),
390 NULL, NULL, parentItem,
391 SWALLOW_Type_1RADIO, rgd,
392 VCONFKEY_TIME_FORMAT_12,
393 "IDS_COM_BODY_12_HOURS",
396 setting_create_Gendial_exp_sub_field(scroller,
397 &(ad->itc_1icon_1text_sub),
398 NULL, NULL, parentItem,
399 SWALLOW_Type_1RADIO, rgd,
400 VCONFKEY_TIME_FORMAT_24,
401 "IDS_ST_BODY_24_HOURS",
404 setting_update_chk_status(rgd,
405 data_parentItem->int_slp_setting_binded);
407 } else if (data_parentItem == ad->data_date_fmt) {
408 rgd = elm_radio_add(scroller);
409 elm_radio_value_set(rgd, -1);
410 setting_create_Gendial_exp_sub_field(scroller,
411 &(ad->itc_1icon_1text_sub),
412 NULL, NULL, parentItem,
413 SWALLOW_Type_1RADIO, rgd,
414 SETTING_DATE_FORMAT_DD_MM_YYYY,
415 "IDS_ST_BODY_DDMMYYYY_DOT",
418 setting_create_Gendial_exp_sub_field(scroller,
419 &(ad->itc_1icon_1text_sub),
420 NULL, NULL, parentItem,
421 SWALLOW_Type_1RADIO, rgd,
422 SETTING_DATE_FORMAT_MM_DD_YYYY,
423 "IDS_ST_BODY_MM_DD_YYYY_DOT",
426 setting_create_Gendial_exp_sub_field(scroller,
427 &(ad->itc_1icon_1text_sub),
428 NULL, NULL, parentItem,
429 SWALLOW_Type_1RADIO, rgd,
430 SETTING_DATE_FORMAT_YYYY_MM_DD,
431 "IDS_COM_BODY_YYYYMMDD",
434 setting_create_Gendial_exp_sub_field(scroller,
435 &(ad->itc_1icon_1text_sub),
436 NULL, NULL, parentItem,
437 SWALLOW_Type_1RADIO, rgd,
438 SETTING_DATE_FORMAT_YYYY_DD_MM,
439 "IDS_ST_BODY_YYYY_DD_MM_DOT",
442 setting_update_chk_status(rgd,
443 data_parentItem->int_slp_setting_binded);
445 } else if (data_parentItem == ad->data_firstday_week_fmt) {
446 rgd = elm_radio_add(scroller);
447 elm_radio_value_set(rgd, -1);
448 setting_create_Gendial_exp_sub_field(scroller,
449 &(ad->itc_1icon_1text_sub),
450 NULL, rgd, parentItem,
451 SWALLOW_Type_1RADIO, rgd,
452 SETTING_WEEKOFDAY_FORMAT_SUNDAY,
453 "IDS_ST_BODY_SUNDAY", NULL);
455 setting_create_Gendial_exp_sub_field(scroller,
456 &(ad->itc_1icon_1text_sub),
457 NULL, rgd, parentItem,
458 SWALLOW_Type_1RADIO, rgd,
459 SETTING_WEEKOFDAY_FORMAT_MONDAY,
460 "IDS_ST_BODY_MONDAY", NULL);
462 setting_update_chk_status(rgd,
463 data_parentItem->int_slp_setting_binded);
468 * layyout create - remove a conformant
470 Evas_Object *setting_create_win_layout2(Evas_Object *win_layout,
471 Evas_Object *win_obj)
473 Evas_Object *layout = NULL;
474 //Evas_Object *conform = elm_conformant_add(win_obj);
476 layout = elm_layout_add(win_obj);
477 setting_retvm_if(layout == NULL, FALSE, "layout == NULL");
479 elm_layout_theme_set(layout, "layout", "application", "default");
480 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
481 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
482 elm_win_resize_object_add(win_obj, layout);
483 //elm_win_resize_object_add(win_obj, conform);
484 //elm_object_content_set(conform, layout);
486 Evas_Object *bg = setting_create_bg(layout, win_obj, "group_list");
487 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
488 evas_object_show(layout);
489 //evas_object_show(conform);
495 Evas_Object *setting_create_layout_navi_bar2(Evas_Object *win_layout, Evas_Object *win_obj, char *title_str, char *lbutton_str, char *rbutton_str, char *mbutton_str, setting_call_back_func lbutton_click_cb, setting_call_back_func rbutton_click_cb, setting_call_back_func mbutton_click_cb, void *cb_data, Evas_Object *eo_view, /*any container obj constructed on any evas obj */
496 Evas_Object **navi_bar,
497 Evas_Object **titleobj)
500 Evas_Object *layout = setting_create_win_layout2(win_layout, win_obj);
501 *navi_bar = setting_create_navi_bar(layout);
503 setting_create_navi_bar_buttons(title_str,
504 lbutton_str, rbutton_str, mbutton_str,
505 lbutton_click_cb, rbutton_click_cb,
506 mbutton_click_cb, cb_data, eo_view /*content */ ,
511 static int setting_time_main_create(void *cb)
514 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
516 SettingTimeUG *ad = (SettingTimeUG *) cb;
520 char *title = _("IDS_ST_BODY_DATE_AND_TIME");
522 ad->is_datefield_selected = EINA_FALSE;
524 setting_call_back_func l_button_cb = NULL;
525 setting_call_back_func r_button_cb = NULL;
527 service_h service = ad->bundle_data;
529 service_get_extra_data(service, "caller", &caller);
530 service_get_extra_data(service, "lbutton", &l_btn);
532 l_button_cb = setting_time_main_click_softkey_caller_exist_left_cb;
533 service_get_extra_data(service, "title", &title);
534 service_get_extra_data(service, "rbutton", &r_btn);
536 r_button_cb = setting_time_main_click_softkey_caller_exist_right_cb;
538 Evas_Object *scroller; /* scroller is a genlist */
542 /* for setup wizard */
543 char *lbtn_str = (char *)g_strdup(l_btn);
544 bool same_flag = FALSE;
545 if (0 == safeStrCmp(l_btn, _("IDS_COM_BODY_BACK"))) {
546 l_btn = (char *)dgettext("sys_string", "IDS_COM_BODY_BACK");
550 //Evas_Object *controllbar = NULL;
552 scroller = elm_genlist_add(ad->win_main_layout);
553 elm_object_style_set(scroller, "dialogue");
554 if(scroller == NULL) {
555 SETTING_TRACE_ERROR("Cannot set scroller object as contento of layout");
556 // free allocated data before return.
558 return SETTING_DRAW_ERR_FAIL_SCROLLER;
561 elm_genlist_clear(scroller);
563 setting_create_layout_navi_bar2(ad->win_main_layout,
572 Evas_Object *lbtn_obj = elm_button_add(ad->win_main_layout);
574 return SETTING_DRAW_ERR_FAIL_SCROLLER;
576 Evas_Object *licon_obj = elm_icon_add(ad->win_main_layout);
577 if(licon_obj == NULL)
578 return SETTING_DRAW_ERR_FAIL_SCROLLER;
579 elm_icon_file_set(licon_obj, IMG_PREVIOUS, NULL);
581 elm_object_style_set(lbtn_obj, "naviframe/toolbar/default");
582 elm_object_text_set(lbtn_obj, l_btn);
583 elm_object_part_content_set(lbtn_obj, "elm.swallow.content", licon_obj);
584 evas_object_smart_callback_add(lbtn_obj, "clicked", l_button_cb, ad);
587 Evas_Object *rbtn_obj = elm_button_add(ad->win_main_layout);
589 return SETTING_DRAW_ERR_FAIL_SCROLLER;
591 Evas_Object *ricon_obj = elm_icon_add(ad->win_main_layout);
592 if(ricon_obj == NULL)
593 return SETTING_DRAW_ERR_FAIL_SCROLLER;
594 elm_icon_file_set(ricon_obj, IMG_NEXT, NULL);
596 elm_object_style_set(rbtn_obj, "naviframe/toolbar/default");
597 elm_object_text_set(rbtn_obj, r_btn);
598 elm_object_part_content_set(rbtn_obj, "elm.swallow.content", ricon_obj);
599 evas_object_smart_callback_add(rbtn_obj, "clicked", r_button_cb, ad);
601 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
604 elm_object_item_part_content_set(navi_it, "toolbar_button1", lbtn_obj);
605 elm_object_item_part_content_set(navi_it, "toolbar_button2", rbtn_obj);
608 l_btn = _("IDS_COM_BODY_BACK");
609 title = _("IDS_ST_BODY_DATE_AND_TIME");
611 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
614 setting_time_main_click_softkey_left_cb,
618 ad->scrl_main = scroller;
623 Elm_Object_Item *item;
625 item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
626 ELM_GENLIST_ITEM_NONE, NULL, NULL);
627 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
628 setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, &value,
630 bool auto_flag = value;
632 if(auto_flag) //do special process only when auto mode
634 //to read TAPI vconfs
638 ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_GMT, &t_nitz);
639 ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, &t_offset);
640 char *tzpath = vconf_get_str(VCONFKEY_TELEPHONY_NITZ_ZONE);
641 if (ret == 0 && !isEmptyStr(tzpath))
643 //1.to update timezone
644 char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1];
645 safeCopyStr(tz_path, SETTING_TIME_ZONEINFO_PATH, MAX_COMMON_BUFFER_LEN / 4);
646 g_strlcat(tz_path, tzpath, sizeof(tz_path));
647 SETTING_TRACE("full tz_path:%s", tz_path);
648 ret = sysman_set_timezone(tz_path);
650 SETTING_TRACE("tzpath is not valid.");
652 SETTING_TRACE("sysman_set_timezone - successful : %s \n", tz_path);
653 if (!__setting_set_city_tzone(tzpath)) {
654 SETTING_TRACE("__setting_set_city_tzone ERROR")
656 if (get_city_name(tzpath)) {
657 SETTING_TRACE(">>>>>> RESULT : %s", get_city_name_result());
659 char* city = get_city_name_result();
660 SETTING_TRACE("city:%s", city);
661 ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city);
663 // 2.to set current time
665 FILE *fp = fopen("/proc/uptime", "r");
667 if (!fscanf(fp, "%d", &t_uptime)) {
668 SETTING_TRACE_ERROR("fscanf error");
673 SETTING_TRACE_ERROR("fopen error");
676 SETTING_TRACE("t_nitz:%d, t_offset:%d, t_uptime:%d", t_nitz, t_offset, t_uptime);
677 time_t t_current = t_nitz + t_uptime - t_offset;
678 SETTING_TRACE("t_current:%d", t_current);
679 ret = sysman_set_datetime(t_current);
686 setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
687 setting_time_main_mouse_up_Gendial_list_cb,
688 ad, SWALLOW_Type_1TOGGLE, NULL,
690 "IDS_ST_BODY_AUTOMATIC_UPDATE", NULL,
691 setting_time_main_chk_btn_cb);
693 ad->data_auto->userdata = ad;
695 SETTING_TRACE_ERROR("ad->data_auto is NULL");
698 setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
699 ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
700 NULL, NULL, 0, SETTING_TIME_AUTO_UPDATE_DESC, NULL,
702 elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL),
703 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
706 setting_set_i18n("worldclock", SETTING_TIME_SHARE_LOCAL_PATH);
708 char time_zone_sub_str[CITY_BUF_SIZE + GMT_BUF_SIZE + 3] = { 0, };
709 char *pa_timezone = NULL;
710 char *pa_city = NULL;
712 pa_city = vconf_get_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT); // IDS_WCL_BODY_CITYNAME_SEOUL
713 pa_timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_INT); // "Asia/Seoul"
715 if ((pa_timezone != NULL) && (_(pa_city) != NULL)) {
717 // don't use hard coded value
718 // get value from current timezone
720 char str_buf[GMT_BUF_SIZE] = {0, };
721 get_gmt_offset(str_buf, GMT_BUF_SIZE);
723 char* timezone_str = get_timezone_str();
725 bool ret = get_city_name(timezone_str);
727 SETTING_TRACE(">>>>>> RESULT : %s", get_city_name_result());
729 char* cityname_id = _(get_city_name_result());
730 SETTING_TRACE("cityname_id:%s", cityname_id);
731 if (cityname_id && 0 != safeStrCmp(cityname_id, "NULL"))
732 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s", cityname_id, _(str_buf));
734 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT +09", _("IDS_WCL_BODY_CITYNAME_SEOUL"));
741 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT +09", _("IDS_WCL_BODY_CITYNAME_SEOUL"));
745 /* UI create time zone */
747 setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2),
748 setting_time_main_mouse_up_Gendial_list_cb,
749 ad, SWALLOW_Type_INVALID, NULL,
750 NULL, 0, "IDS_ST_BODY_TIME_ZONE",
751 time_zone_sub_str, NULL);
753 ad->data_tz->userdata = ad;
755 SETTING_TRACE_ERROR("ad->data_tz is NULL");
758 /* create DATE_AND_TIME */
761 setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224,
763 if (ret == SETTING_RETURN_FAIL) {
764 value = VCONFKEY_TIME_FORMAT_12;
766 bool is_12hours = (value == VCONFKEY_TIME_FORMAT_12 ? TRUE : FALSE);
767 char *date_format_str[] = { "%d %b %Y", "%b %d %Y", "%Y %b %d", "%Y %d %b" };
769 setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
770 if (ret == SETTING_RETURN_FAIL)
771 value = SETTING_DATE_FORMAT_DD_MM_YYYY;
773 /* UI format string */
775 setting_create_Gendial_field_def(scroller, &(ad->itc_layout),
776 setting_time_main_mouse_up_Gendial_list_cb,
777 ad, SWALLOW_Type_LAYOUT_DATEFIELD,
778 NULL, NULL, is_12hours,
779 "IDS_ST_BODY_DATE_AND_TIME",
780 date_format_str[value],
781 setting_time_main_datefield_change_cb);
783 ad->data_time->userdata = ad;
784 ad->data_time->isItemDisableFlag = auto_flag;
786 SETTING_TRACE_ERROR("ad->data_time is NULL");
788 item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
789 ELM_GENLIST_ITEM_NONE, NULL, NULL);
790 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
792 /* UI create "Time format" */
793 setting_enable_expandable_genlist(scroller, ad,
794 __setting_time_main_exp_cb, NULL);
796 char* pa_time_format = get_pa_time_format_str();
797 ad->data_time_fmt = setting_create_Gendial_exp_parent_field(scroller,
798 &(ad->itc_2text_3_parent),
799 setting_time_main_mouse_up_Gendial_list_cb,
800 ad, SWALLOW_Type_INVALID,
801 "IDS_ST_BODY_TIME_FORMAT",
803 if (ad->data_time_fmt) {
804 ad->data_time_fmt->int_slp_setting_binded =
805 INT_SLP_SETTING_REGIONFORMAT_TIME1224;
807 SETTING_TRACE_ERROR("ad->data_time_fmt is NULL");
809 G_FREE(pa_time_format);
811 #if APPLIED_DATATIME_DATA_FORMAT
812 char* pa_date_format = get_pa_date_format_str();
813 ad->data_date_fmt = setting_create_Gendial_exp_parent_field(scroller,
814 &(ad->itc_2text_3_parent),
815 setting_time_main_mouse_up_Gendial_list_cb,
816 ad, SWALLOW_Type_INVALID,
817 "IDS_ST_BODY_DATE_FORMAT",
819 if (ad->data_date_fmt) {
820 ad->data_date_fmt->int_slp_setting_binded =
821 INT_SLP_SETTING_DATE_FORMAT;
823 SETTING_TRACE_ERROR("ad->data_date_fmt is NULL");
825 G_FREE(pa_date_format);
828 #if APPLIED_DATATIME_FIRSTDAY_WEEK
829 char* pa_week = get_pa_week_format_str();
830 ad->data_firstday_week_fmt =
831 setting_create_Gendial_exp_parent_field(scroller,
832 &(ad->itc_2text_3_parent),
833 setting_time_main_mouse_up_Gendial_list_cb,
834 ad, SWALLOW_Type_INVALID,
835 "IDS_CLD_BODY_FIRST_DAY_OF_WEEK",
837 if (ad->data_firstday_week_fmt) {
838 ad->data_firstday_week_fmt->int_slp_setting_binded =
839 INT_SLP_SETTING_WEEK_FORMAT;
841 SETTING_TRACE_ERROR("ad->data_firstday_week_fmt is NULL");
846 item = elm_genlist_item_append(scroller, &itc_bottom_seperator, NULL, NULL,
847 ELM_GENLIST_ITEM_NONE, NULL, NULL);
848 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
853 setting_disable_genlist_item(ad->data_tz->item);
856 setting_disable_genlist_item(ad->data_time->item);
860 setting_view_time_main.is_create = 1;
861 vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, time_changed_callback, (void *)ad);
863 /* register vconf key to get event callback for converting 12/24H */
864 ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
865 setting_time_main_int_vconf_change_cb, ad);
866 setting_retvm_if(ret < 0, ret, "%s notifications Failed(%d)",
867 (char *)VCONFKEY_REGIONFORMAT_TIME1224, ret);
869 /* register vconf key to get event callback for date format */
870 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DATE_FORMAT_INT,
871 setting_time_main_int_vconf_change_cb, ad);
872 setting_retvm_if(ret < 0, ret, "%s notifications Failed(%d)",
873 (char *)VCONFKEY_SETAPPL_DATE_FORMAT_INT, ret);
875 /* to avoid update time-diff, every per 3s to update. */
876 ad->update_timer = ecore_timer_add(3, (Ecore_Task_Cb) __refresh_date_timer, ad);
878 return SETTING_RETURN_SUCCESS;
881 static int setting_time_main_destroy(void *cb)
885 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
887 SettingTimeUG *ad = (SettingTimeUG *) cb;
889 if (ad->update_timer) {
890 ecore_timer_del(ad->update_timer);
891 ad->update_timer = NULL;
894 #if PROGRESS_POPUP_SHOW
895 if (ad->pop_progress) {
896 evas_object_del(ad->pop_progress);
897 ad->pop_progress = NULL;
901 if (ad->update_timezone_idler) {
902 ecore_idler_del(ad->update_timezone_idler);
903 ad->update_timezone_idler = NULL;
905 if (ad->refresh_time_idler) {
906 ecore_idler_del(ad->refresh_time_idler);
907 ad->refresh_time_idler = NULL;
910 vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED,
911 time_changed_callback);
913 vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
914 setting_time_main_int_vconf_change_cb);
915 vconf_ignore_key_changed(VCONFKEY_SETAPPL_DATE_FORMAT_INT,
916 setting_time_main_int_vconf_change_cb);
918 if (ad->ly_main != NULL) {
919 evas_object_del(ad->ly_main);
920 setting_view_time_main.is_create = 0;
923 return SETTING_RETURN_SUCCESS;
926 static int setting_time_main_update(void *cb)
929 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
931 SettingTimeUG *ad = (SettingTimeUG *) cb;
933 if (ad->ly_main != NULL) {
934 evas_object_show(ad->ly_main);
936 if (ad->update_timezone_idler) {
937 ecore_idler_del(ad->update_timezone_idler);
938 ad->update_timezone_idler = NULL;
940 ad->update_timezone_idler =
941 ecore_idler_add((Ecore_Task_Cb) __update_timezone_idler, ad);
943 if (ad->refresh_time_idler) {
944 ecore_idler_del(ad->refresh_time_idler);
945 ad->refresh_time_idler = NULL;
947 ad->refresh_time_idler = ecore_idler_add(setting_update_datefield, ad);
949 return SETTING_RETURN_SUCCESS;
952 static int setting_time_main_cleanup(void *cb)
955 return SETTING_RETURN_SUCCESS;
959 /* ***************************************************
963 ****************************************************/
965 int setting_time_check_automatic_time_update_state()
973 setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
980 static int __setting_set_city_tzone(const char* pTZPath)
982 // let's get city & timezone string from pTZPath
984 char szTimezone[GMT_BUF_SIZE] = {0,};
985 char* pStr = strdup(pTZPath);
987 // 2. timezone string +/-<n> ex. +9, -1
988 get_gmt_offset(szTimezone, GMT_BUF_SIZE);
990 int ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_INT, szTimezone);
993 SETTING_TRACE("set vconf failed");
998 /** @todo replace with vconf ID */
999 ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_ID, pStr);
1006 setting_time_main_launch_worldclock_result_ug_cb(ui_gadget_h ug,
1007 service_h result, void *priv)
1009 SETTING_TRACE_BEGIN;
1011 retm_if(priv == NULL, "Data parameter is NULL");
1013 SettingTimeUG *ad = (SettingTimeUG *) priv;
1016 char *tzpath = NULL;
1017 service_get_extra_data(result, "city", &city);
1018 service_get_extra_data(result, "tzpath", &tzpath);
1021 SETTING_TRACE("tzpath from worldclock UG is null.");
1024 SETTING_TRACE("tzpath : %s", tzpath );
1026 SETTING_TRACE("city : %s", city );
1028 /* --------------------------------------------------------------------- */
1029 char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1];
1030 safeCopyStr(tz_path, SETTING_TIME_ZONEINFO_PATH, MAX_COMMON_BUFFER_LEN / 4);
1031 g_strlcat(tz_path, tzpath, sizeof(tz_path));
1032 SETTING_TRACE("full tz_path:%s", tz_path);
1034 int ret = sysman_set_timezone(tz_path);
1036 SETTING_TRACE("tzpath is not valid.");
1039 SETTING_TRACE("sysman_set_timezone - successful : %s \n", tz_path);
1041 ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city);
1042 setting_retm_if(ret != 0, "set vconf failed");
1044 // parse city and GMT offset from tzpath and system time property
1045 // set the strings in vconf which will be used while updating display of timezone
1046 if (!__setting_set_city_tzone(tzpath)) {
1047 SETTING_TRACE("__setting_set_city_tzone ERROR")
1051 // update the display for timezone
1052 setting_update_timezone(ad);
1053 static int t_event_val = -1;
1054 vconf_set_int (VCONFKEY_SYSTEM_TIME_CHANGED, t_event_val);
1058 void setting_time_main_launch_worldclock_destroy_ug_cb(ui_gadget_h ug,
1061 SETTING_TRACE_BEGIN;
1062 /* if(ug) ug_destroy(ug); */
1063 /* restore the '<-' button on the navigate bar */
1065 SettingTimeUG *ad = (SettingTimeUG *) priv;
1068 ad->ug_loading = NULL;
1070 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
1072 Evas_Object *back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
1074 if (back_btn != NULL) {
1075 elm_object_style_set(back_btn, NAVI_BACK_BUTTON_STYLE); /* take into effect */
1080 void setting_time_main_launch_worldclock_layout_ug_cb(ui_gadget_h ug,
1084 SETTING_TRACE_BEGIN;
1085 SettingTimeUG *ad = (SettingTimeUG *) priv;
1091 base = (Evas_Object *) ug_get_layout(ug);
1096 case UG_MODE_FULLVIEW:
1097 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
1099 elm_win_resize_object_add(ad->win_get, base);
1100 evas_object_show(base);
1109 void setting_time_main_launch_worldclock_sg(void *data)
1111 SETTING_TRACE_BEGIN;
1113 retm_if(data == NULL, "Data parameter is NULL");
1115 SettingTimeUG *ad = (SettingTimeUG *) data;
1117 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
1118 setting_retm_if(!cbs, "calloc failed");
1119 cbs->layout_cb = setting_time_main_launch_worldclock_layout_ug_cb;
1120 cbs->result_cb = setting_time_main_launch_worldclock_result_ug_cb;
1121 cbs->destroy_cb = setting_time_main_launch_worldclock_destroy_ug_cb;
1122 cbs->priv = (void *)ad;
1124 SETTING_TRACE("to load ug[%s]", "worldclock-efl");
1126 ug_create(ad->ug, "worldclock-efl", UG_MODE_FULLVIEW, NULL, cbs);
1127 if (NULL == ad->ug_loading) { /* error handling */
1135 Eina_Bool setting_update_datefield(void *cb)
1137 SETTING_TRACE_BEGIN;
1138 retvm_if(cb == NULL, EINA_FALSE, "Data parameter is NULL");
1139 SettingTimeUG *ad = (SettingTimeUG *) cb;
1141 //__refresh_date_timer(ad);
1142 if (ad->data_time) {
1143 time_t ctime = time(NULL);
1145 struct tm *ts = localtime_r(&ctime, &ts_ret);
1146 if (ts) elm_datetime_value_set(ad->data_time->eo_check, &ts_ret);
1148 ad->refresh_time_idler = NULL;
1152 /* ***************************************************
1156 ****************************************************/
1159 setting_time_main_click_softkey_left_cb(void *data, Evas_Object *obj,
1162 SETTING_TRACE_BEGIN;
1163 retm_if(data == NULL, "Data parameter is NULL");
1165 SettingTimeUG *ad = (SettingTimeUG *) data;
1167 /* Send destroy request */
1168 ug_destroy_me(ad->ug);
1171 /* ***************************************************
1175 ****************************************************/
1178 setting_time_main_click_softkey_caller_exist_left_cb(void *data,
1182 SETTING_TRACE_BEGIN;
1184 retm_if(data == NULL, "Data parameter is NULL");
1186 SettingTimeUG *ad = (SettingTimeUG *) data;
1188 /* Create Bundle and send message */
1190 if (service_create(&svc))
1193 service_add_extra_data(svc, "result", "lbutton_click");
1194 ug_send_result(ad->ug, svc);
1196 service_destroy(svc);
1198 /* Send destroy request */
1199 ug_destroy_me(ad->ug);
1203 setting_time_main_click_softkey_caller_exist_right_cb(void *data,
1207 SETTING_TRACE_BEGIN;
1209 retm_if(data == NULL, "Data parameter is NULL");
1211 SettingTimeUG *ad = (SettingTimeUG *) data;
1213 /* Create Bundle and send message */
1215 if (service_create(&svc))
1218 service_add_extra_data(svc, "result", "rbutton_click");
1219 ug_send_result(ad->ug, svc);
1221 service_destroy(svc);
1223 /* Send destroy request */
1224 ug_destroy_me(ad->ug);
1227 static void setting_time_reboot_resp_cb(void *data, Evas_Object *obj,
1230 SETTING_TRACE_BEGIN;
1231 int response_type = btn_type(obj);
1232 if (POPUP_RESPONSE_OK == response_type) {
1233 setting_time_main_btn_update_ok_cb(data);
1234 } else if (POPUP_RESPONSE_CANCEL == response_type) {
1235 setting_time_main_btn_update_cancel_cb(data);
1238 SettingTimeUG *ad = data;
1241 evas_object_del(ad->pop);
1245 static void __time_auto_update(void *data)
1247 setting_retm_if(data == NULL, "Data parameter is NULL");
1248 SettingTimeUG *ad = (SettingTimeUG *) data;
1250 setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1251 SETTING_ON_OFF_BTN_ON, &err);
1253 setting_disable_genlist_item(ad->data_tz->item);
1256 if (ad->data_time) {
1257 ad->data_time->isItemDisableFlag = FALSE;
1258 setting_disable_evas_object(ad->data_time->eo_check);
1259 setting_disable_genlist_item(ad->data_time->item);
1266 ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_GMT, &t_nitz);
1267 ret += vconf_get_int(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT, &t_offset);
1268 char *tzpath = vconf_get_str(VCONFKEY_TELEPHONY_NITZ_ZONE);
1269 if (ret != 0 || isEmptyStr(tzpath))
1271 setting_create_simple_popup(ad, ad->win_get,
1272 NULL, _("TAPI doesn't support this sim card to update time automatically!"));
1278 SETTING_TRACE("tz_path:%s", tzpath);
1280 char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1];
1281 safeCopyStr(tz_path, SETTING_TIME_ZONEINFO_PATH, MAX_COMMON_BUFFER_LEN / 4);
1282 g_strlcat(tz_path, tzpath, sizeof(tz_path));
1283 SETTING_TRACE("full tz_path:%s", tz_path);
1284 ret = sysman_set_timezone(tz_path);
1286 SETTING_TRACE("tzpath is not valid.");
1289 SETTING_TRACE("sysman_set_timezone - successful : %s \n", tz_path);
1290 if (!__setting_set_city_tzone(tzpath)) {
1291 SETTING_TRACE("__setting_set_city_tzone ERROR")
1294 if (get_city_name(tzpath)) {
1295 SETTING_TRACE(">>>>>> RESULT : %s", get_city_name_result());
1297 char* city = get_city_name_result();
1298 SETTING_TRACE("city:%s", city);
1299 ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city);
1300 setting_retm_if(ret != 0, "set vconf failed");
1301 setting_update_timezone(ad);
1305 FILE *fp = fopen("/proc/uptime", "r");
1306 fscanf(fp, "%d", &t_uptime);
1307 SETTING_TRACE("t_nitz:%d, t_offset:%d, t_uptime:%d", t_nitz, t_offset, t_uptime);
1308 time_t t_current = t_nitz + t_uptime - t_offset;
1309 SETTING_TRACE("t_current:%d", t_current);
1310 ret = sysman_set_datetime(t_current);
1311 setting_retm_if(ret == -1, "sysman_set_datetime call failed");
1312 //ad->changed_time = t_current;
1313 if (ad->data_time) {
1315 struct tm *ts = localtime_r(&t_current, &ts_ret);
1317 elm_datetime_value_set(ad->data_time->eo_check, &ts_ret);
1320 // event notification
1321 static int t_event_val = -1;
1322 vconf_set_int (VCONFKEY_SYSTEM_TIME_CHANGED, t_event_val);
1326 setting_time_main_chk_btn_cb(void *data, Evas_Object *obj, void *event_info)
1328 SETTING_TRACE_BEGIN;
1330 retm_if(data == NULL, "Data parameter is NULL");
1331 SettingTimeUG *ad = NULL;
1332 Setting_GenGroupItem_Data *list_item =
1333 (Setting_GenGroupItem_Data *) data;
1334 ad = list_item->userdata;
1335 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
1337 ad->chk_auto = ad->data_auto->eo_check;
1339 ad->chk_dst = ad->data_dst->eo_check;
1341 if (ad->data_time) {
1342 elm_object_focus_set(ad->data_time->eo_check, EINA_FALSE);
1346 if (obj == ad->chk_auto) {
1348 setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1351 (void) setting_set_bool_slp_key (BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, SETTING_ON_OFF_BTN_OFF, &err);
1352 elm_check_state_set(ad->chk_auto, 0);
1355 setting_enable_genlist_item(ad->data_tz->item);
1358 if (ad->data_time) {
1359 ad->data_time->isItemDisableFlag = FALSE;
1360 setting_enable_evas_object(ad->data_time->eo_check);
1361 setting_enable_genlist_item(ad->data_time->item);
1365 #if UN_SUPPORT_TIME_DYNAMIC_UPDATE
1367 setting_create_popup_with_btn(ad, ad->win_get, NULL,
1368 _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"),
1369 setting_time_reboot_resp_cb,
1371 dgettext("sys_string",
1373 _("IDS_COM_SK_CANCEL"));
1375 __time_auto_update(ad);
1380 static void setting_time_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
1383 SETTING_TRACE_BEGIN;
1385 setting_retm_if(data == NULL, "Data parameter is NULL");
1387 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
1388 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1389 elm_genlist_item_selected_set(item, 0);
1390 Setting_GenGroupItem_Data *list_item =
1391 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
1393 SettingTimeUG *ad = (SettingTimeUG *) data;
1394 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
1396 if (ad->data_time && 0 != safeStrCmp("IDS_ST_BODY_DATE_AND_TIME", list_item->keyStr)) {
1397 elm_object_focus_set(ad->data_time->eo_check, EINA_FALSE);
1400 if (!safeStrCmp("IDS_ST_BODY_TIME_ZONE", list_item->keyStr)) {
1401 ad->is_datefield_selected = EINA_FALSE;
1402 if (1 == setting_time_check_automatic_time_update_state()) {
1403 setting_create_simple_popup(ad, ad->win_get,
1404 NULL, _(AUTO_TIME_UPDATE_ON));
1406 setting_time_main_launch_worldclock_sg(ad);
1409 } else if (!safeStrCmp("IDS_ST_BODY_DATE_AND_TIME", list_item->keyStr)) {
1410 ad->is_datefield_selected = EINA_TRUE;
1411 if (1 == setting_time_check_automatic_time_update_state()) {
1412 setting_create_simple_popup(ad, ad->win_get,
1413 NULL, _(AUTO_TIME_UPDATE_ON));
1415 /* setting_view_change(&setting_view_time_main, &setting_view_time_time, ad); */
1417 } else if (!safeStrCmp("IDS_ST_BODY_AUTOMATIC_UPDATE", list_item->keyStr)) {
1418 ad->is_datefield_selected = EINA_FALSE;
1419 int old_status = elm_check_state_get(list_item->eo_check);
1421 list_item->chk_status = !old_status;
1422 elm_check_state_set(list_item->eo_check, list_item->chk_status);
1424 if (!list_item->chk_status) {
1426 setting_set_bool_slp_key
1427 (BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1428 SETTING_ON_OFF_BTN_OFF, &err);
1431 setting_enable_genlist_item(ad->data_tz->item);
1434 if (ad->data_time) {
1435 ad->data_time->isItemDisableFlag = FALSE;
1436 setting_enable_evas_object(ad->data_time->eo_check);
1437 setting_enable_genlist_item(ad->data_time->item);
1441 #if UN_SUPPORT_TIME_DYNAMIC_UPDATE
1443 setting_create_popup_with_btn(ad, ad->win_get, NULL,
1444 _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"),
1445 setting_time_reboot_resp_cb,
1447 dgettext("sys_string", "IDS_COM_SK_OK"),
1448 _("IDS_COM_SK_CANCEL"));
1450 __time_auto_update(ad);
1454 } else if (!safeStrCmp("IDS_ST_BODY_TIME_FORMAT", list_item->keyStr)
1455 || !safeStrCmp("IDS_ST_BODY_DATE_FORMAT", list_item->keyStr)
1456 || !safeStrCmp("IDS_CLD_BODY_FIRST_DAY_OF_WEEK", list_item->keyStr)) {
1457 ad->is_datefield_selected = EINA_FALSE;
1458 bool status = !elm_genlist_item_expanded_get(item);
1459 elm_genlist_item_expanded_set(item, status);
1464 void setting_time_main_btn_update_ok_cb(void *cb)
1466 SETTING_TRACE_BEGIN;
1467 SettingTimeUG *ad = (SettingTimeUG *) cb;
1468 int err; /* error check */
1469 setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1470 SETTING_ON_OFF_BTN_ON, &err);
1471 elm_check_state_set(ad->data_auto->eo_check, 1);
1472 ad->data_auto->chk_status = 1;
1474 sysman_request_reboot();
1476 /* We'd better check return value from sysman_request_reboot() function. */
1477 /* It will return 0 on success or -1 if failed. */
1481 void setting_time_main_btn_update_cancel_cb(void *cb)
1483 SETTING_TRACE_BEGIN;
1484 SettingTimeUG *ad = (SettingTimeUG *) cb;
1486 int err; /* error check */
1488 retm_if(cb == NULL, "Data parameter is NULL");
1489 setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1490 SETTING_ON_OFF_BTN_OFF, &err);
1491 elm_check_state_set(ad->data_auto->eo_check, 0);
1492 ad->data_auto->chk_status = 0;
1497 static UChar *uastrcpy(const char *chars)
1501 len = safeStrLen(chars);
1502 str = (UChar *) malloc(sizeof(UChar) *(len + 1));
1505 u_uastrcpy(str, chars);
1510 static int get_timezone_isdst(int* isdst)
1512 SETTING_TRACE_BEGIN;
1516 enum { BUFFERSIZE = 1024 };
1517 char buf[BUFFERSIZE];
1518 ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
1524 /* handle error condition */
1528 ts = localtime(&ctime);
1530 return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
1533 SETTING_TRACE(" == tz_path = %s", buf);
1534 SETTING_TRACE(" == isdst = %d\n", ts->tm_isdst);
1535 *isdst = ts->tm_isdst;
1537 return SETTING_RETURN_SUCCESS;
1541 static void ICU_set_timezone(const char *timezone)
1543 SETTING_TRACE("ICU_set_timezone = %s ", timezone);
1544 UErrorCode ec = U_ZERO_ERROR;
1545 UChar *str = uastrcpy(timezone);
1547 ucal_setDefaultTimeZone(str, &ec);
1548 if (U_SUCCESS(ec)) {
1549 SETTING_TRACE("ucal_setDefaultTimeZone() SUCCESS ");
1551 SETTING_TRACE("ucal_setDefaultTimeZone() FAILED : %s ",
1558 static void setting_time_main_controlbar_lbtn_label_set(
1559 Evas_Object *controlbar,
1562 SETTING_TRACE_BEGIN;
1563 setting_retm_if(controlbar == NULL, "controlbar parameter is NULL");
1564 setting_retm_if(label == NULL, "label parameter is NULL");
1566 Evas_Object *eo_lbtn = NULL;
1567 Elm_Object_Item *first_item = NULL;
1569 first_item = elm_toolbar_first_item_get(controlbar);
1570 setting_retm_if(first_item == NULL, "get first_item failed");
1572 eo_lbtn = elm_object_item_part_content_get(first_item, "object");
1573 setting_retm_if(eo_lbtn == NULL, "get eo_lbtn failed");
1575 elm_object_text_set(eo_lbtn, label);
1580 * ex) timezone : Asia/Seoul --> returns "+09"
1584 static void get_gmt_offset(char *str_buf, int size)
1586 // timezone string +/-<n> ex. +9, -1
1587 time_t t = time(0); // get unix time. sec.
1590 data = localtime(&t); // save time as structure.
1591 setting_retm_if(!data, "data is NULL");
1592 data->tm_isdst = 0; // summer time, not applied.
1593 time_t a = mktime(data);
1596 data->tm_isdst = 0; // summer time, not applied.
1597 time_t b = mktime(data);
1599 int gmtoffset_hour = (a-b)/3600; // result : hour.
1600 int gmtoffset_min = ((a-b)%3600)/60; // result : min.
1601 if(gmtoffset_min != 0) {
1605 snprintf(str_buf, size, "%+d:%02u", gmtoffset_hour, gmtoffset_min);
1606 SETTING_TRACE("szTimezone is of a valid format: GMT: %s", str_buf);
1611 static char* get_timezone_str()
1613 SETTING_TRACE_BEGIN;
1615 enum { BUFFERSIZE = 1024 };
1616 char buf[BUFFERSIZE];
1617 ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
1623 /* handle error condition */
1625 return g_strdup(buf+20); //Asia/Seoul
1628 static char* get_city_name_result()
1634 // in_str = "Asia/Seoul"
1635 static bool get_city_name(char* tzname)
1637 sqlite3 *pSQLite3 = NULL;
1638 char *szErrMsg = NULL;
1640 int rst = sqlite3_open( "/opt/dbspace/.worldclock.db", &pSQLite3);
1643 printf( "Can't open database: %s\n", sqlite3_errmsg( pSQLite3 ));
1644 sqlite3_close( pSQLite3 );
1650 printf("Database opened!!\n");
1651 char query_str[256];
1652 snprintf(query_str, 256, "SELECT city FROM city_table where tz_path=\"%s\"", tzname);
1653 printf("%s \n", query_str);
1654 rst = sqlite3_exec(pSQLite3, query_str, query_callback, 0, &szErrMsg);
1658 sqlite3_free( szErrMsg );
1659 sqlite3_close( pSQLite3 );
1660 printf("Database close!!\n");
1664 static int query_callback(void *NotUsed, int argc, char **argv, char **azColName)
1667 printf("%s\n", argv[i] ? argv[i] : "NULL");
1668 s_result = g_strdup(argv[i] ? argv[i] : "NULL");
1674 int main(int argc, char* argv[])
1678 // exporting - current status
1679 if ( (argc == 2) && (0 == strcmp(argv[1], "export"))) {
1682 else if ( (argc == 2) && (0 == strcmp(argv[1], "timezone_init"))) {
1684 //////////////////////////////////////////////////////////////////////////
1685 char* tz_path_zone_city = get_timezone_str();
1686 bool ret = get_city_name(tz_path_zone_city);
1688 printf(">>>>>> RESULT : %s \n", get_city_name_result());
1690 //////////////////////////////////////////////////////////////////////////
1695 ret = setting_cfg_create();