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>
32 #include <unicode/udat.h>
33 #include <unicode/ustring.h>
34 #include <unicode/uloc.h>
35 #include <unicode/ucal.h>
36 #include <unicode/utmscale.h>
39 #define PROGRESS_POPUP_SHOW 0
42 static UChar *uastrcpy(const char *chars);
43 static void ICU_set_timezone(const char *timezone);
44 static int get_timezone_isdst(int* isdst);
45 static void get_gmt_offset(char *str_buf, int size);
47 static char* get_timezone_str();
48 static char* get_city_name_result();
49 static bool get_city_name(char* tzname);
51 static char* s_result;
52 static int query_callback(void *NotUsed, int argc, char **argv, char **azColName);
55 static int setting_time_main_create(void *cb);
56 static int setting_time_main_destroy(void *cb);
57 static int setting_time_main_update(void *cb);
58 static int setting_time_main_cleanup(void *cb);
60 setting_view setting_view_time_main = {
61 .create = setting_time_main_create,
62 .destroy = setting_time_main_destroy,
63 .update = setting_time_main_update,
64 .cleanup = setting_time_main_cleanup,
67 static void setting_time_reboot_resp_cb(void *data, Evas_Object *obj,
70 #if TIME_CHANGED_HEYNOTY_CALLBACK
71 void time_changed_callback(void *data)
73 SETTING_TRACE_DEBUG("time and timezone have been changed: TIME_CHANGED_HEYNOTY_CALLBACK");
74 SettingTimeUG *ad = (SettingTimeUG *)data;
76 int ret = setting_time_update_cb(ad);
78 SETTING_TRACE("FAIL: setting_time_update_db(ad)\n");
81 if(EINA_TRUE == ad->is_datefield_selected) {
82 /* Timezone is not changed and a selected value of the datefield is already changed */
83 SETTING_TRACE("Datefield is selected\n");
89 // vconfset to update timezone
90 char pTZPath[__MAX_PATH_SIZE];
91 ssize_t nLen = readlink(SETTING_TZONE_SYMLINK_PATH, pTZPath, sizeof(pTZPath)-1);
96 SETTING_TRACE("parse error for SETTING_TZONE_SYMLINK_PATH");
100 if (!__setting_set_city_tzone(&pTZPath[20])) {
101 SETTING_TRACE("__setting_set_city_tzone ERROR");
105 setting_time_main_update(data);
107 char *timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
108 setting_retm_if(timezone == NULL, "get vonf failed");
110 ICU_set_timezone(timezone);
115 void setting_time_update_time_date_format_string(SettingTimeUG *ad)
125 char time_str[MAX_ARGS];
128 ts = localtime_r(&ctime, &ts_ret);
131 /* set time in particular format */
132 ret = setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224, &value, &err);
133 if (ret == SETTING_RETURN_FAIL)
134 value = VCONFKEY_TIME_FORMAT_12;
137 case VCONFKEY_TIME_FORMAT_12:
140 strftime(time_str, MAX_ARGS, "%l:%M %p ", &ts_ret);
144 case VCONFKEY_TIME_FORMAT_24:
146 strftime(time_str, MAX_ARGS, "%H:%M", &ts_ret);
155 elm_object_item_data_set(ad->data_time->item, ad->data_time);
156 elm_genlist_item_update(ad->data_time->item);
160 bool setting_update_timezone(SettingTimeUG *ad)
162 /* SETTING_TRACE_BEGIN; */
163 char time_zone_sub_str[CITY_BUF_SIZE + GMT_BUF_SIZE + 3] = { 0, };
164 char *pa_timezone = NULL;
165 char *pa_city = NULL;
169 pa_city = vconf_get_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT);
170 pa_timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_INT);
172 //if ((pa_timezone != NULL) && (_(pa_city) != NULL && safeStrCmp(_(pa_city), "NULL"))) {
173 if ((pa_timezone != NULL) && (_(pa_city) != NULL )) {
174 /* SETTING_TRACE_DEBUG("*** timezone: %s *** ", timezone); */
175 /* SETTING_TRACE_DEBUG("*** city: %s *** ", _(city)); */
176 /* SETTING_TRACE_DEBUG("*** ret: %d, dst: %d *** ", ret, dst); */
178 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s", _(pa_city), pa_timezone);
179 //ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s", pa_timezone, _(pa_city));
183 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT +09", _("IDS_WCL_BODY_CITYNAME_SEOUL"));
186 SETTING_TRACE("ad->data_tz:%p", ad->data_tz);
189 ad->data_tz->sub_desc = (char *)g_strdup(time_zone_sub_str);
190 elm_object_item_data_set(ad->data_tz->item, ad->data_tz);
191 elm_genlist_item_update(ad->data_tz->item);
196 bool __update_timezone_idler(SettingTimeUG *ad)
198 setting_update_timezone(ad);
199 ad->update_timezone_idler = NULL;
203 static void setting_time_main_int_vconf_change_cb(keynode_t *key, void *data)
205 /* SETTING_TRACE_BEGIN; */
206 ret_if(NULL == data);
207 SettingTimeUG *ad = data;
208 int status = vconf_keynode_get_int(key);
209 char *vconf_name = vconf_keynode_get_name(key);
210 /* SETTING_TRACE("vconf_name:%s", vconf_name); */
212 if (!safeStrCmp(vconf_name, VCONFKEY_REGIONFORMAT_TIME1224)) {
215 /* VCONFKEY_REGIONFORMAT_TIME1224 1:12H 2:24H */
216 if (status <= 2 && status > 0) /* 1, 2 */
217 --status; /* set to 0 or 1 */
219 status = 0; /* set 12H */
221 /* TODO assert 1 or 0 */
222 ad->data_time->chk_status = !status;
224 char datefield_format[MAX_DATETIME_FORMAT_LEN + 1] = {0, };
226 const char *time_format = NULL;
227 if (ad->data_time->chk_status)//12 hours
229 time_format = "%I : %M %p";
231 time_format = "%H : %M";
234 //get date format from datefiled itself, if elm_datetime_add() supports set date-format via ICU.
235 #ifdef SUPPORT_DATEFIELD_DATE_FORMAT_AUTOSET
236 const char *old_format = elm_datetime_format_get(ad->data_time->eo_check);
237 snprintf(datefield_format, MAX_DATE_FORMAT_LEN + 1, //add one space " "
239 safeStrNCat(datefield_format, time_format, MAX_DATETIME_FORMAT_LEN);
240 SETTING_TRACE("datefield_format:%s", datefield_format);
242 int value = SETTING_DATE_FORMAT_DD_MM_YYYY;
245 char *date_format_str[] = { "%d %b %Y", "%b %d %Y", "%Y %b %d", "%Y %d %b" };
246 int ret = setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
247 if (ret == SETTING_RETURN_FAIL)
248 value = SETTING_DATE_FORMAT_DD_MM_YYYY;
250 snprintf(datefield_format, MAX_DATETIME_FORMAT_LEN,
251 "%s %s", date_format_str[value], time_format);
254 elm_datetime_format_set(ad->data_time->eo_check, datefield_format);
259 /* ***************************************************
263 ***************************************************/
264 static void setting_time_main_datefield_change_cb(void *data, Evas_Object *obj,
269 ret_if(data == NULL);
270 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
271 SettingTimeUG *ad = list_item->userdata;
273 if (EINA_FALSE == ad->is_datefield_selected) {
274 SETTING_TRACE("Datefield is not selected\n");
278 // If auto update is on, don't anything while the datefield has been updated (i.e., time runs)
279 if (1 == setting_time_check_automatic_time_update_state()) {
280 SETTING_TRACE("AUTO_TIME ON: no action");
284 // otherwise, we apply a new date which has been changed by a user
288 elm_datetime_value_get(obj, &_tm);
290 SETTING_TRACE("year : %d, month : %d, day : %d, hour : %d, min : %d",
291 _tm.tm_year, _tm.tm_mon, _tm.tm_mday, _tm.tm_hour, _tm.tm_min);
292 if (2037 < _tm.tm_year) {
293 setting_create_simple_popup(ad, ad->win_get,
294 NULL, _(ERR_BIGGER_THAN_2037));
297 #if SUPPORT_SCREEN_PROTECTED /* if not lock the current state, after set the time, the screen will become dimmed */
298 pm_lock_state(LCD_NORMAL, STAY_CUR_STATE, 0);
303 if (get_timezone_isdst(&isdst) == SETTING_RETURN_SUCCESS) {
304 _tm.tm_isdst = isdst;
307 SETTING_TRACE_ERROR("get_timezone_isdst() failed");
311 /* local time -> gmtime */
312 time_t the_time = mktime(&_tm); /* represent local time */
313 ad->changed_time = the_time;
315 if ( (time(NULL)/ONE_MINUTE) == (the_time/ONE_MINUTE) )
317 SETTING_TRACE("Time is not changed\n");
318 //current time didn't change
322 #if PROGRESS_POPUP_SHOW
323 // remove popup if created
324 if (ad->pop_progress) {
325 evas_object_del(ad->pop_progress);
326 ad->pop_progress = NULL;
331 setting_create_popup_with_progressbar(ad, ad->win_get, "pending_list",
332 NULL, NULL, NULL, 0, TRUE, TRUE);
335 // invoke API to change time
336 int ret = sysman_set_datetime(the_time);
337 setting_retm_if(ret == -1, "sysman_set_datetime call failed");
342 Eina_Bool __refresh_date_timer(void *data)
345 SettingTimeUG *ad = data;
347 time_t ctime = time(NULL);
349 struct tm *ts = localtime_r(&ctime, &ts_ret);
352 time_t diff = abs(ctime - ad->changed_time);
353 if (diff <=1 || diff >= 60) {
356 elm_datetime_value_set(ad->data_time->eo_check, &ts_ret);
362 static void __setting_time_main_exp_cb(void *data, Evas_Object *obj,
365 ret_if(NULL == data || NULL == event_info);
367 SettingTimeUG *ad = (SettingTimeUG *) data;
368 Elm_Object_Item *parentItem = event_info; /* parent item */
369 Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem); /* parent data */
370 Evas_Object *scroller = elm_object_item_widget_get(parentItem);
373 if (data_parentItem == ad->data_time_fmt) {
375 rgd = elm_radio_add(scroller);
376 elm_radio_value_set(rgd, -1);
377 setting_create_Gendial_exp_sub_field(scroller,
378 &(ad->itc_1icon_1text_sub),
379 NULL, NULL, parentItem,
380 SWALLOW_Type_1RADIO, rgd,
381 VCONFKEY_TIME_FORMAT_12,
382 "IDS_COM_BODY_12_HOURS",
385 setting_create_Gendial_exp_sub_field(scroller,
386 &(ad->itc_1icon_1text_sub),
387 NULL, NULL, parentItem,
388 SWALLOW_Type_1RADIO, rgd,
389 VCONFKEY_TIME_FORMAT_24,
390 "IDS_ST_BODY_24_HOURS",
393 setting_update_chk_status(rgd,
394 data_parentItem->int_slp_setting_binded);
396 } else if (data_parentItem == ad->data_date_fmt) {
397 rgd = elm_radio_add(scroller);
398 elm_radio_value_set(rgd, -1);
399 setting_create_Gendial_exp_sub_field(scroller,
400 &(ad->itc_1icon_1text_sub),
401 NULL, NULL, parentItem,
402 SWALLOW_Type_1RADIO, rgd,
403 SETTING_DATE_FORMAT_DD_MM_YYYY,
404 "IDS_ST_BODY_DDMMYYYY_DOT",
407 setting_create_Gendial_exp_sub_field(scroller,
408 &(ad->itc_1icon_1text_sub),
409 NULL, NULL, parentItem,
410 SWALLOW_Type_1RADIO, rgd,
411 SETTING_DATE_FORMAT_MM_DD_YYYY,
412 "IDS_ST_BODY_MM_DD_YYYY_DOT",
415 setting_create_Gendial_exp_sub_field(scroller,
416 &(ad->itc_1icon_1text_sub),
417 NULL, NULL, parentItem,
418 SWALLOW_Type_1RADIO, rgd,
419 SETTING_DATE_FORMAT_YYYY_MM_DD,
420 "IDS_COM_BODY_YYYYMMDD",
423 setting_create_Gendial_exp_sub_field(scroller,
424 &(ad->itc_1icon_1text_sub),
425 NULL, NULL, parentItem,
426 SWALLOW_Type_1RADIO, rgd,
427 SETTING_DATE_FORMAT_YYYY_DD_MM,
428 "IDS_ST_BODY_YYYY_DD_MM_DOT",
431 setting_update_chk_status(rgd,
432 data_parentItem->int_slp_setting_binded);
434 } else if (data_parentItem == ad->data_firstday_week_fmt) {
435 rgd = elm_radio_add(scroller);
436 elm_radio_value_set(rgd, -1);
437 setting_create_Gendial_exp_sub_field(scroller,
438 &(ad->itc_1icon_1text_sub),
439 NULL, rgd, parentItem,
440 SWALLOW_Type_1RADIO, rgd,
441 SETTING_WEEKOFDAY_FORMAT_SUNDAY,
442 "IDS_ST_BODY_SUNDAY", NULL);
444 setting_create_Gendial_exp_sub_field(scroller,
445 &(ad->itc_1icon_1text_sub),
446 NULL, rgd, parentItem,
447 SWALLOW_Type_1RADIO, rgd,
448 SETTING_WEEKOFDAY_FORMAT_MONDAY,
449 "IDS_ST_BODY_MONDAY", NULL);
451 setting_update_chk_status(rgd,
452 data_parentItem->int_slp_setting_binded);
456 static int setting_time_main_create(void *cb)
459 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
461 SettingTimeUG *ad = (SettingTimeUG *) cb;
465 char *title = _("IDS_ST_BODY_DATE_AND_TIME");
467 ad->is_datefield_selected = EINA_FALSE;
469 setting_call_back_func l_button_cb = NULL;
470 setting_call_back_func r_button_cb = NULL;
472 service_h service = ad->bundle_data;
474 service_get_extra_data(service, "caller", &caller);
475 service_get_extra_data(service, "lbutton", &l_btn);
477 l_button_cb = setting_time_main_click_softkey_caller_exist_left_cb;
478 service_get_extra_data(service, "title", &title);
479 service_get_extra_data(service, "rbutton", &r_btn);
481 r_button_cb = setting_time_main_click_softkey_caller_exist_right_cb;
483 Evas_Object *scroller; /* scroller is a genlist */
487 char *lbtn_str = (char *)g_strdup(l_btn);
488 bool same_flag = FALSE;
489 if (0 == safeStrCmp(l_btn, _("IDS_COM_BODY_BACK"))) {
490 l_btn = (char *)dgettext("sys_string", "IDS_COM_BODY_BACK");
494 Evas_Object *controllbar = NULL;
496 scroller = elm_genlist_add(ad->win_main_layout);
497 elm_object_style_set(scroller, "dialogue");
498 if(scroller == NULL) {
499 SETTING_TRACE_ERROR("Cannot set scroller object as contento of layout");
500 // free allocated data before return.
502 return SETTING_DRAW_ERR_FAIL_SCROLLER;
505 elm_genlist_clear(scroller);
507 setting_create_layout_navi_bar(ad->win_main_layout,
516 elm_toolbar_item_append(controllbar, IMG_PREVIOUS, l_btn, l_button_cb, ad);
517 elm_object_item_disabled_set(elm_toolbar_item_append(controllbar, NULL, "", NULL, NULL), EINA_TRUE);
518 elm_object_item_disabled_set(elm_toolbar_item_append(controllbar, NULL, "", NULL, NULL), EINA_TRUE);
519 elm_toolbar_item_append(controllbar, IMG_NEXT, r_btn, r_button_cb, ad);
522 setting_time_main_controlbar_lbtn_label_set(controllbar,
530 l_btn = _("IDS_COM_BODY_BACK");
531 title = _("IDS_ST_BODY_DATE_AND_TIME");
533 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
536 setting_time_main_click_softkey_left_cb,
540 ad->scrl_main = scroller;
545 Elm_Object_Item *item;
547 item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
548 ELM_GENLIST_ITEM_NONE, NULL, NULL);
549 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
550 setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, &value,
552 bool auto_flag = value;
557 setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
558 setting_time_main_mouse_up_Gendial_list_cb,
559 ad, SWALLOW_Type_1TOGGLE, NULL,
561 "IDS_ST_BODY_AUTOMATIC_UPDATE", NULL,
562 setting_time_main_chk_btn_cb);
564 ad->data_auto->userdata = ad;
566 SETTING_TRACE_ERROR("ad->data_auto is NULL");
569 setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
570 ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
571 NULL, NULL, 0, SETTING_TIME_AUTO_UPDATE_DESC, NULL,
573 elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL),
574 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
577 setting_set_i18n("worldclock", SETTING_TIME_SHARE_LOCAL_PATH);
579 char time_zone_sub_str[CITY_BUF_SIZE + GMT_BUF_SIZE + 3] = { 0, };
580 char *pa_timezone = NULL;
581 char *pa_city = NULL;
583 pa_city = vconf_get_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT); // IDS_WCL_BODY_CITYNAME_SEOUL
584 pa_timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_INT); // "Asia/Seoul"
586 if ((pa_timezone != NULL) && (_(pa_city) != NULL)) {
588 // don't use hard coded value
589 // get value from current timezone
591 char str_buf[GMT_BUF_SIZE] = {0, };
592 get_gmt_offset(str_buf, GMT_BUF_SIZE);
594 char* timezone_str = get_timezone_str();
596 bool ret = get_city_name(timezone_str);
598 SETTING_TRACE(">>>>>> RESULT : %s", get_city_name_result());
600 char* cityname_id = get_city_name_result();
602 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s", _(cityname_id), _(str_buf));
608 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT +09", _("IDS_WCL_BODY_CITYNAME_SEOUL"));
612 /* UI create time zone */
614 setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2),
615 setting_time_main_mouse_up_Gendial_list_cb,
616 ad, SWALLOW_Type_INVALID, NULL,
617 NULL, 0, "IDS_ST_BODY_TIME_ZONE",
618 time_zone_sub_str, NULL);
620 ad->data_tz->userdata = ad;
622 SETTING_TRACE_ERROR("ad->data_tz is NULL");
625 /* create DATE_AND_TIME */
628 setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224,
630 if (ret == SETTING_RETURN_FAIL) {
631 value = VCONFKEY_TIME_FORMAT_12;
633 bool is_12hours = (value == VCONFKEY_TIME_FORMAT_12 ? TRUE : FALSE);
634 char *date_format_str[] = { "%d %b %Y", "%b %d %Y", "%Y %b %d", "%Y %d %b" };
636 setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
637 if (ret == SETTING_RETURN_FAIL)
638 value = SETTING_DATE_FORMAT_DD_MM_YYYY;
640 /* UI format string */
642 setting_create_Gendial_field_def(scroller, &(ad->itc_layout),
643 setting_time_main_mouse_up_Gendial_list_cb,
644 ad, SWALLOW_Type_LAYOUT_DATEFIELD,
645 NULL, NULL, is_12hours,
646 "IDS_ST_BODY_DATE_AND_TIME",
647 date_format_str[value],
648 setting_time_main_datefield_change_cb);
650 ad->data_time->userdata = ad;
651 ad->data_time->isItemDisableFlag = auto_flag;
653 SETTING_TRACE_ERROR("ad->data_time is NULL");
655 item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
656 ELM_GENLIST_ITEM_NONE, NULL, NULL);
657 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
659 /* UI create "Time format" */
660 setting_enable_expandable_genlist(scroller, ad,
661 __setting_time_main_exp_cb, NULL);
663 char* pa_time_format = get_pa_time_format_str();
664 ad->data_time_fmt = setting_create_Gendial_exp_parent_field(scroller,
665 &(ad->itc_2text_3_parent),
666 setting_time_main_mouse_up_Gendial_list_cb,
667 ad, SWALLOW_Type_INVALID,
668 "IDS_ST_BODY_TIME_FORMAT",
670 if (ad->data_time_fmt) {
671 ad->data_time_fmt->int_slp_setting_binded =
672 INT_SLP_SETTING_REGIONFORMAT_TIME1224;
674 SETTING_TRACE_ERROR("ad->data_time_fmt is NULL");
676 G_FREE(pa_time_format);
678 #if APPLIED_DATATIME_DATA_FORMAT
679 char* pa_date_format = get_pa_date_format_str();
680 ad->data_date_fmt = setting_create_Gendial_exp_parent_field(scroller,
681 &(ad->itc_2text_3_parent),
682 setting_time_main_mouse_up_Gendial_list_cb,
683 ad, SWALLOW_Type_INVALID,
684 "IDS_ST_BODY_DATE_FORMAT",
686 if (ad->data_date_fmt) {
687 ad->data_date_fmt->int_slp_setting_binded =
688 INT_SLP_SETTING_DATE_FORMAT;
690 SETTING_TRACE_ERROR("ad->data_date_fmt is NULL");
692 G_FREE(pa_date_format);
695 #if APPLIED_DATATIME_FIRSTDAY_WEEK
696 char* pa_week = get_pa_week_format_str();
697 ad->data_firstday_week_fmt =
698 setting_create_Gendial_exp_parent_field(scroller,
699 &(ad->itc_2text_3_parent),
700 setting_time_main_mouse_up_Gendial_list_cb,
701 ad, SWALLOW_Type_INVALID,
702 "IDS_CLD_BODY_FIRST_DAY_OF_WEEK",
704 if (ad->data_firstday_week_fmt) {
705 ad->data_firstday_week_fmt->int_slp_setting_binded =
706 INT_SLP_SETTING_WEEK_FORMAT;
708 SETTING_TRACE_ERROR("ad->data_firstday_week_fmt is NULL");
713 item = elm_genlist_item_append(scroller, &itc_bottom_seperator, NULL, NULL,
714 ELM_GENLIST_ITEM_NONE, NULL, NULL);
715 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
720 setting_disable_genlist_item(ad->data_tz->item);
723 setting_disable_genlist_item(ad->data_time->item);
727 setting_view_time_main.is_create = 1;
729 #if TIME_CHANGED_HEYNOTY_CALLBACK
730 /* ---------------------------------------------------------------- */
731 /* heynoti registration */
732 /* ---------------------------------------------------------------- */
733 ad->noti_fd = heynoti_init();
735 if (ad->noti_fd == -1) {
736 SETTING_TRACE("heynoti_init FAIL");
737 return SETTING_RETURN_FAIL;
739 SETTING_TRACE("heynoti_init OK");
742 if (-1 == heynoti_subscribe(ad->noti_fd, SETTING_TIME_CHANGED, time_changed_callback, (void *)ad)) {
743 SETTING_TRACE("heynoti_subscribe FAIL");
745 SETTING_TRACE("heynoti_subscribe OK");
748 if (-1 == heynoti_attach_handler(ad->noti_fd)) {
749 SETTING_TRACE("heynoti_attach_handler FAIL");
751 SETTING_TRACE("heynoti_attach_handler OK");
755 /* register vconf key to get event callback for converting 12/24H */
756 ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
757 setting_time_main_int_vconf_change_cb, ad);
758 setting_retvm_if(ret < 0, ret, "%s notifications Failed(%d)",
759 (char *)VCONFKEY_REGIONFORMAT_TIME1224, ret);
761 /* register vconf key to get event callback for date format */
762 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DATE_FORMAT_INT,
763 setting_time_main_int_vconf_change_cb, ad);
764 setting_retvm_if(ret < 0, ret, "%s notifications Failed(%d)",
765 (char *)VCONFKEY_SETAPPL_DATE_FORMAT_INT, ret);
767 /* to avoid update time-diff, every per 3s to update. */
768 ad->update_timer = ecore_timer_add(3, (Ecore_Task_Cb) __refresh_date_timer, ad);
770 return SETTING_RETURN_SUCCESS;
773 static int setting_time_main_destroy(void *cb)
777 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
779 SettingTimeUG *ad = (SettingTimeUG *) cb;
781 #if TIME_CHANGED_HEYNOTY_CALLBACK
782 /* Closing heynoti */
783 if (ad->noti_fd != -1)//first need to check the fd validation
785 heynoti_unsubscribe(ad->noti_fd, SETTING_TIME_CHANGED, time_changed_callback);
786 //heynoti_detach_handler() will be done in heynoti_close().
787 heynoti_close(ad->noti_fd);
791 if (ad->update_timer) {
792 ecore_timer_del(ad->update_timer);
793 ad->update_timer = NULL;
796 #if PROGRESS_POPUP_SHOW
797 if (ad->pop_progress) {
798 evas_object_del(ad->pop_progress);
799 ad->pop_progress = NULL;
803 if (ad->update_timezone_idler) {
804 ecore_idler_del(ad->update_timezone_idler);
805 ad->update_timezone_idler = NULL;
807 if (ad->refresh_time_idler) {
808 ecore_idler_del(ad->refresh_time_idler);
809 ad->refresh_time_idler = NULL;
811 vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
812 setting_time_main_int_vconf_change_cb);
813 vconf_ignore_key_changed(VCONFKEY_SETAPPL_DATE_FORMAT_INT,
814 setting_time_main_int_vconf_change_cb);
816 if (ad->ly_main != NULL) {
817 evas_object_del(ad->ly_main);
818 setting_view_time_main.is_create = 0;
821 return SETTING_RETURN_SUCCESS;
824 static int setting_time_main_update(void *cb)
827 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
829 SettingTimeUG *ad = (SettingTimeUG *) cb;
831 if (ad->ly_main != NULL) {
832 evas_object_show(ad->ly_main);
834 if (ad->update_timezone_idler) {
835 ecore_idler_del(ad->update_timezone_idler);
836 ad->update_timezone_idler = NULL;
838 ad->update_timezone_idler =
839 ecore_idler_add((Ecore_Task_Cb) __update_timezone_idler, ad);
841 if (ad->refresh_time_idler) {
842 ecore_idler_del(ad->refresh_time_idler);
843 ad->refresh_time_idler = NULL;
845 ad->refresh_time_idler = ecore_idler_add(setting_update_datefield, ad);
847 return SETTING_RETURN_SUCCESS;
850 static int setting_time_main_cleanup(void *cb)
853 return SETTING_RETURN_SUCCESS;
857 /* ***************************************************
861 ****************************************************/
863 int setting_time_check_automatic_time_update_state()
871 setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
878 static int __setting_set_city_tzone(const char* pTZPath)
880 // let's get city & timezone string from pTZPath
882 char szTimezone[GMT_BUF_SIZE] = {0,};
883 char* pStr = strdup(pTZPath);
885 // 2. timezone string +/-<n> ex. +9, -1
886 get_gmt_offset(szTimezone, GMT_BUF_SIZE);
888 int ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_INT, szTimezone);
891 SETTING_TRACE("set vconf failed");
896 /** @todo replace with vconf ID */
897 ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_ID, pStr);
904 setting_time_main_launch_worldclock_result_ug_cb(ui_gadget_h ug,
905 service_h result, void *priv)
909 retm_if(priv == NULL, "Data parameter is NULL");
911 SettingTimeUG *ad = (SettingTimeUG *) priv;
915 service_get_extra_data(result, "city", &city);
916 service_get_extra_data(result, "tzpath", &tzpath);
919 SETTING_TRACE("tzpath from worldclock UG is null.");
922 SETTING_TRACE("tzpath : %s", tzpath );
925 /* --------------------------------------------------------------------- */
926 char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1];
927 safeCopyStr(tz_path, SETTING_TIME_ZONEINFO_PATH, MAX_COMMON_BUFFER_LEN / 4);
928 g_strlcat(tz_path, tzpath, sizeof(tz_path));
929 SETTING_TRACE("full tz_path:%s", tz_path);
931 int ret = sysman_set_timezone(tz_path);
933 SETTING_TRACE("tzpath is not valid.");
936 SETTING_TRACE("sysman_set_timezone - successful : %s \n", tz_path);
938 ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city);
939 setting_retm_if(ret != 0, "set vconf failed");
941 // parse city and GMT offset from tzpath and system time property
942 // set the strings in vconf which will be used while updating display of timezone
943 if (!__setting_set_city_tzone(tzpath)) {
944 SETTING_TRACE("__setting_set_city_tzone ERROR")
948 // update the display for timezone
949 setting_update_timezone(ad);
950 heynoti_publish(SETTING_TIME_CHANGED);
954 void setting_time_main_launch_worldclock_destroy_ug_cb(ui_gadget_h ug,
958 /* if(ug) ug_destroy(ug); */
959 /* restore the '<-' button on the navigate bar */
961 SettingTimeUG *ad = (SettingTimeUG *) priv;
964 ad->ug_loading = NULL;
966 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
968 Evas_Object *back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
970 if (back_btn != NULL) {
971 elm_object_style_set(back_btn, NAVI_BACK_BUTTON_STYLE); /* take into effect */
976 void setting_time_main_launch_worldclock_layout_ug_cb(ui_gadget_h ug,
981 SettingTimeUG *ad = (SettingTimeUG *) priv;
987 base = (Evas_Object *) ug_get_layout(ug);
992 case UG_MODE_FULLVIEW:
993 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
995 elm_win_resize_object_add(ad->win_get, base);
996 evas_object_show(base);
1005 void setting_time_main_launch_worldclock_sg(void *data)
1007 SETTING_TRACE_BEGIN;
1009 retm_if(data == NULL, "Data parameter is NULL");
1011 SettingTimeUG *ad = (SettingTimeUG *) data;
1013 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
1014 setting_retm_if(!cbs, "calloc failed");
1015 cbs->layout_cb = setting_time_main_launch_worldclock_layout_ug_cb;
1016 cbs->result_cb = setting_time_main_launch_worldclock_result_ug_cb;
1017 cbs->destroy_cb = setting_time_main_launch_worldclock_destroy_ug_cb;
1018 cbs->priv = (void *)ad;
1020 SETTING_TRACE("to load ug[%s]", "worldclock-efl");
1022 ug_create(ad->ug, "worldclock-efl", UG_MODE_FULLVIEW, NULL, cbs);
1023 if (NULL == ad->ug_loading) { /* error handling */
1031 Eina_Bool setting_update_datefield(void *cb)
1033 SETTING_TRACE_BEGIN;
1034 retvm_if(cb == NULL, EINA_FALSE, "Data parameter is NULL");
1035 SettingTimeUG *ad = (SettingTimeUG *) cb;
1037 __refresh_date_timer(ad);
1038 ad->refresh_time_idler = NULL;
1042 /* ***************************************************
1046 ****************************************************/
1049 setting_time_main_click_softkey_left_cb(void *data, Evas_Object *obj,
1052 SETTING_TRACE_BEGIN;
1053 retm_if(data == NULL, "Data parameter is NULL");
1055 SettingTimeUG *ad = (SettingTimeUG *) data;
1057 /* Send destroy request */
1058 ug_destroy_me(ad->ug);
1061 /* ***************************************************
1065 ****************************************************/
1068 setting_time_main_click_softkey_caller_exist_left_cb(void *data,
1072 SETTING_TRACE_BEGIN;
1074 retm_if(data == NULL, "Data parameter is NULL");
1076 SettingTimeUG *ad = (SettingTimeUG *) data;
1078 /* Create Bundle and send message */
1080 if (service_create(&svc))
1083 service_add_extra_data(svc, "result", "lbutton_click");
1084 ug_send_result(ad->ug, svc);
1086 service_destroy(svc);
1088 /* Send destroy request */
1089 ug_destroy_me(ad->ug);
1093 setting_time_main_click_softkey_caller_exist_right_cb(void *data,
1097 SETTING_TRACE_BEGIN;
1099 retm_if(data == NULL, "Data parameter is NULL");
1101 SettingTimeUG *ad = (SettingTimeUG *) data;
1103 /* Create Bundle and send message */
1105 if (service_create(&svc))
1108 service_add_extra_data(svc, "result", "rbutton_click");
1109 ug_send_result(ad->ug, svc);
1111 service_destroy(svc);
1113 /* Send destroy request */
1114 ug_destroy_me(ad->ug);
1117 static void setting_time_reboot_resp_cb(void *data, Evas_Object *obj,
1120 SETTING_TRACE_BEGIN;
1121 int response_type = btn_type(obj);
1122 if (POPUP_RESPONSE_OK == response_type) {
1123 setting_time_main_btn_update_ok_cb(data);
1124 } else if (POPUP_RESPONSE_CANCEL == response_type) {
1125 setting_time_main_btn_update_cancel_cb(data);
1128 SettingTimeUG *ad = data;
1131 evas_object_del(ad->pop);
1137 setting_time_main_chk_btn_cb(void *data, Evas_Object *obj, void *event_info)
1139 SETTING_TRACE_BEGIN;
1141 retm_if(data == NULL, "Data parameter is NULL");
1142 SettingTimeUG *ad = NULL;
1143 Setting_GenGroupItem_Data *list_item =
1144 (Setting_GenGroupItem_Data *) data;
1145 ad = list_item->userdata;
1146 list_item->chk_status = elm_check_state_get(obj); /* for genlist update status */
1148 ad->chk_auto = ad->data_auto->eo_check;
1150 ad->chk_dst = ad->data_dst->eo_check;
1152 if (ad->data_time) {
1153 elm_object_focus_set(ad->data_time->eo_check, EINA_FALSE);
1157 if (obj == ad->chk_auto) {
1159 setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1162 (void) setting_set_bool_slp_key (BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, SETTING_ON_OFF_BTN_OFF, &err);
1163 elm_check_state_set(ad->chk_auto, 0);
1166 setting_enable_genlist_item(ad->data_tz->item);
1169 if (ad->data_time) {
1170 ad->data_time->isItemDisableFlag = FALSE;
1171 setting_enable_evas_object(ad->data_time->eo_check);
1172 setting_enable_genlist_item(ad->data_time->item);
1177 setting_create_popup_with_btn(ad, ad->win_get, NULL,
1178 _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"),
1179 setting_time_reboot_resp_cb,
1181 dgettext("sys_string",
1183 _("IDS_COM_SK_CANCEL"));
1189 static void setting_time_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
1192 SETTING_TRACE_BEGIN;
1194 setting_retm_if(data == NULL, "Data parameter is NULL");
1196 retm_if(event_info == NULL, "Invalid argument: event info is NULL");
1197 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1198 elm_genlist_item_selected_set(item, 0);
1199 Setting_GenGroupItem_Data *list_item =
1200 (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
1202 SettingTimeUG *ad = (SettingTimeUG *) data;
1203 SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
1205 if (ad->data_time && 0 != safeStrCmp("IDS_ST_BODY_DATE_AND_TIME", list_item->keyStr)) {
1206 elm_object_focus_set(ad->data_time->eo_check, EINA_FALSE);
1209 if (!safeStrCmp("IDS_ST_BODY_TIME_ZONE", list_item->keyStr)) {
1210 ad->is_datefield_selected = EINA_FALSE;
1211 if (1 == setting_time_check_automatic_time_update_state()) {
1212 setting_create_simple_popup(ad, ad->win_get,
1213 NULL, _(AUTO_TIME_UPDATE_ON));
1215 setting_time_main_launch_worldclock_sg(ad);
1218 } else if (!safeStrCmp("IDS_ST_BODY_DATE_AND_TIME", list_item->keyStr)) {
1219 ad->is_datefield_selected = EINA_TRUE;
1220 if (1 == setting_time_check_automatic_time_update_state()) {
1221 setting_create_simple_popup(ad, ad->win_get,
1222 NULL, _(AUTO_TIME_UPDATE_ON));
1224 /* setting_view_change(&setting_view_time_main, &setting_view_time_time, ad); */
1226 } else if (!safeStrCmp("IDS_ST_BODY_AUTOMATIC_UPDATE", list_item->keyStr)) {
1227 ad->is_datefield_selected = EINA_FALSE;
1228 int old_status = elm_check_state_get(list_item->eo_check);
1230 list_item->chk_status = !old_status;
1231 elm_check_state_set(list_item->eo_check, list_item->chk_status);
1233 if (!list_item->chk_status) {
1235 setting_set_bool_slp_key
1236 (BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1237 SETTING_ON_OFF_BTN_OFF, &err);
1240 setting_enable_genlist_item(ad->data_tz->item);
1243 if (ad->data_time) {
1244 ad->data_time->isItemDisableFlag = FALSE;
1245 setting_enable_evas_object(ad->data_time->eo_check);
1246 setting_enable_genlist_item(ad->data_time->item);
1251 setting_create_popup_with_btn(ad, ad->win_get, NULL,
1252 _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"),
1253 setting_time_reboot_resp_cb,
1255 dgettext("sys_string", "IDS_COM_SK_OK"),
1256 _("IDS_COM_SK_CANCEL"));
1259 } else if (!safeStrCmp("IDS_ST_BODY_TIME_FORMAT", list_item->keyStr)
1260 || !safeStrCmp("IDS_ST_BODY_DATE_FORMAT", list_item->keyStr)
1261 || !safeStrCmp("IDS_CLD_BODY_FIRST_DAY_OF_WEEK", list_item->keyStr)) {
1262 ad->is_datefield_selected = EINA_FALSE;
1263 bool status = !elm_genlist_item_expanded_get(item);
1264 elm_genlist_item_expanded_set(item, status);
1269 void setting_time_main_btn_update_ok_cb(void *cb)
1271 SETTING_TRACE_BEGIN;
1272 SettingTimeUG *ad = (SettingTimeUG *) cb;
1273 int err; /* error check */
1274 setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1275 SETTING_ON_OFF_BTN_ON, &err);
1276 elm_check_state_set(ad->data_auto->eo_check, 1);
1277 ad->data_auto->chk_status = 1;
1279 sysman_request_reboot();
1281 /* We'd better check return value from sysman_request_reboot() function. */
1282 /* It will return 0 on success or -1 if failed. */
1286 void setting_time_main_btn_update_cancel_cb(void *cb)
1288 SETTING_TRACE_BEGIN;
1289 SettingTimeUG *ad = (SettingTimeUG *) cb;
1291 int err; /* error check */
1293 retm_if(cb == NULL, "Data parameter is NULL");
1294 setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1295 SETTING_ON_OFF_BTN_OFF, &err);
1296 elm_check_state_set(ad->data_auto->eo_check, 0);
1297 ad->data_auto->chk_status = 0;
1302 static UChar *uastrcpy(const char *chars)
1306 len = safeStrLen(chars);
1307 str = (UChar *) malloc(sizeof(UChar) *(len + 1));
1310 u_uastrcpy(str, chars);
1315 static int get_timezone_isdst(int* isdst)
1317 SETTING_TRACE_BEGIN;
1321 enum { BUFFERSIZE = 1024 };
1322 char buf[BUFFERSIZE];
1323 ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
1329 /* handle error condition */
1333 ts = localtime(&ctime);
1335 return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
1338 SETTING_TRACE(" == tz_path = %s", buf);
1339 SETTING_TRACE(" == isdst = %d\n", ts->tm_isdst);
1340 *isdst = ts->tm_isdst;
1342 return SETTING_RETURN_SUCCESS;
1346 static void ICU_set_timezone(const char *timezone)
1348 SETTING_TRACE("ICU_set_timezone = %s ", timezone);
1349 UErrorCode ec = U_ZERO_ERROR;
1350 UChar *str = uastrcpy(timezone);
1352 ucal_setDefaultTimeZone(str, &ec);
1353 if (U_SUCCESS(ec)) {
1354 SETTING_TRACE("ucal_setDefaultTimeZone() SUCCESS ");
1356 SETTING_TRACE("ucal_setDefaultTimeZone() FAILED : %s ",
1363 static void setting_time_main_controlbar_lbtn_label_set(
1364 Evas_Object *controlbar,
1367 SETTING_TRACE_BEGIN;
1368 setting_retm_if(controlbar == NULL, "controlbar parameter is NULL");
1369 setting_retm_if(label == NULL, "label parameter is NULL");
1371 Evas_Object *eo_lbtn = NULL;
1372 Elm_Object_Item *first_item = NULL;
1374 first_item = elm_toolbar_first_item_get(controlbar);
1375 setting_retm_if(first_item == NULL, "get first_item failed");
1377 eo_lbtn = elm_object_item_part_content_get(first_item, "object");
1378 setting_retm_if(eo_lbtn == NULL, "get eo_lbtn failed");
1380 elm_object_text_set(eo_lbtn, label);
1385 * ex) timezone : Asia/Seoul --> returns "+09"
1389 static void get_gmt_offset(char *str_buf, int size)
1391 SETTING_TRACE(" before GMT processing : %s", str_buf);
1392 // timezone string +/-<n> ex. +9, -1
1393 time_t t = time(0); // get unix time. sec.
1396 data = localtime(&t); // save time as structure.
1397 setting_retm_if(!data, "data is NULL");
1398 data->tm_isdst = 0; // summer time, not applied.
1399 time_t a = mktime(data);
1402 data->tm_isdst = 0; // summer time, not applied.
1403 time_t b = mktime(data);
1405 int gmtoffset_hour = (a-b)/3600; // result : hour.
1406 int gmtoffset_min = ((a-b)%3600)/60; // result : min.
1407 if(gmtoffset_min != 0) {
1411 snprintf(str_buf, size, "%+d:%02u", gmtoffset_hour, gmtoffset_min);
1412 SETTING_TRACE("szTimezone is of a valid format: GMT: %s", str_buf);
1417 static char* get_timezone_str()
1419 SETTING_TRACE_BEGIN;
1421 enum { BUFFERSIZE = 1024 };
1422 char buf[BUFFERSIZE];
1423 ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
1429 /* handle error condition */
1431 return g_strdup(buf+20); //Asia/Seoul
1434 static char* get_city_name_result()
1440 // in_str = "Asia/Seoul"
1441 static bool get_city_name(char* tzname)
1443 sqlite3 *pSQLite3 = NULL;
1444 char *szErrMsg = NULL;
1446 int rst = sqlite3_open( "/opt/dbspace/.worldclock.db", &pSQLite3);
1449 printf( "Can't open database: %s\n", sqlite3_errmsg( pSQLite3 ));
1450 sqlite3_close( pSQLite3 );
1456 printf("Database opened!!\n");
1457 char query_str[256];
1458 snprintf(query_str, 256, "SELECT city FROM city_table where tz_path=\"%s\"", tzname);
1459 printf("%s \n", query_str);
1460 rst = sqlite3_exec(pSQLite3, query_str, query_callback, 0, &szErrMsg);
1464 sqlite3_free( szErrMsg );
1465 sqlite3_close( pSQLite3 );
1466 printf("Database close!!\n");
1470 static int query_callback(void *NotUsed, int argc, char **argv, char **azColName)
1473 printf("%s\n", argv[i] ? argv[i] : "NULL");
1474 s_result = g_strdup(argv[i] ? argv[i] : "NULL");
1480 int main(int argc, char* argv[])
1484 // exporting - current status
1485 if ( (argc == 2) && (0 == strcmp(argv[1], "export"))) {
1488 else if ( (argc == 2) && (0 == strcmp(argv[1], "timezone_init"))) {
1490 //////////////////////////////////////////////////////////////////////////
1491 char* tz_path_zone_city = get_timezone_str();
1492 bool ret = get_city_name(tz_path_zone_city);
1494 printf(">>>>>> RESULT : %s \n", get_city_name_result());
1496 //////////////////////////////////////////////////////////////////////////
1501 ret = setting_cfg_create();