fixed duplicated UI update on time change
[apps/core/preloaded/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 <sysman.h>
24
25 #include <stdio.h>
26 #include <malloc.h>
27 #include <time.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <sqlite3.h>
31
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>
37
38 #define ONE_MINUTE 60
39 #define PROGRESS_POPUP_SHOW 0
40
41 /*  ICU utilities*/
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);
46
47 static char* get_timezone_str();
48 static char* get_city_name_result();
49 static bool get_city_name(char* tzname);
50
51 static char* s_result;
52 static int query_callback(void *NotUsed, int argc, char **argv, char **azColName);
53
54
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);
59
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,
65 };
66
67 static void setting_time_reboot_resp_cb(void *data, Evas_Object *obj,
68                                         void *event_info);
69
70 #if TIME_CHANGED_HEYNOTY_CALLBACK
71 void time_changed_callback(void *data)
72 {
73         SETTING_TRACE_DEBUG("time and timezone have been changed: TIME_CHANGED_HEYNOTY_CALLBACK");
74         SettingTimeUG *ad = (SettingTimeUG *)data;
75
76         int ret = setting_time_update_cb(ad);
77         if (ret != 0) {
78                 SETTING_TRACE("FAIL: setting_time_update_db(ad)\n");
79         }
80
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");
84                 return ;
85         }
86
87         tzset();
88
89         // vconfset to update timezone
90         char pTZPath[__MAX_PATH_SIZE];
91         ssize_t nLen = readlink(SETTING_TZONE_SYMLINK_PATH, pTZPath, sizeof(pTZPath)-1);
92
93         if (nLen != -1) {
94                 pTZPath[nLen] = '\0';
95         } else {
96                 SETTING_TRACE("parse error for SETTING_TZONE_SYMLINK_PATH");
97                 return;
98         }
99
100         if (!__setting_set_city_tzone(&pTZPath[20])) {
101                 SETTING_TRACE("__setting_set_city_tzone ERROR");
102                 return;
103         }
104
105         setting_time_main_update(data);
106
107         char *timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
108         setting_retm_if(timezone == NULL, "get vonf failed");
109
110         ICU_set_timezone(timezone);
111         FREE(timezone);
112 }
113 #endif
114
115 void setting_time_update_time_date_format_string(SettingTimeUG *ad)
116 {
117         SETTING_TRACE_BEGIN;
118
119         struct tm *ts;
120         struct tm ts_ret;
121         time_t ctime;
122
123         int ret, value, err;
124
125         char time_str[MAX_ARGS];
126
127         ctime = time(NULL);
128         ts = localtime_r(&ctime, &ts_ret);
129         ret_if(!ts);
130
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;
135
136         switch (value) {
137         case VCONFKEY_TIME_FORMAT_12:
138                 {
139                         /* Get Time */
140                         strftime(time_str, MAX_ARGS, "%l:%M %p ", &ts_ret);
141                 }
142                 break;
143
144         case VCONFKEY_TIME_FORMAT_24:
145                 {
146                         strftime(time_str, MAX_ARGS, "%H:%M", &ts_ret);
147                 }
148                 break;
149         default:
150                 /* do nothing */
151                 break;
152         }
153
154         if (ad->data_time) {
155                 elm_object_item_data_set(ad->data_time->item, ad->data_time);
156                 elm_genlist_item_update(ad->data_time->item);
157         }
158 }
159
160 bool setting_update_timezone(SettingTimeUG *ad)
161 {
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;
166         int ret = 0;
167
168         /*  get time zone */
169         pa_city = vconf_get_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT);
170         pa_timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_INT);
171
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); */
177
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));
180                 FREE(pa_city);
181                 retv_if(ret < 0, 0);
182         } else {
183                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT +09", _("IDS_WCL_BODY_CITYNAME_SEOUL"));
184                 retv_if(ret < 0, 0);
185         }
186         SETTING_TRACE("ad->data_tz:%p", ad->data_tz);
187
188         if (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);
192         }
193         return 0;
194 }
195
196 bool __update_timezone_idler(SettingTimeUG *ad)
197 {
198         setting_update_timezone(ad);
199         ad->update_timezone_idler = NULL;
200         return 0;
201 }
202
203 static void setting_time_main_int_vconf_change_cb(keynode_t *key, void *data)
204 {
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); */
211
212         if (!safeStrCmp(vconf_name, VCONFKEY_REGIONFORMAT_TIME1224)) {
213
214                 if (ad->data_time) {
215                         /* VCONFKEY_REGIONFORMAT_TIME1224 1:12H 2:24H */
216                         if (status <= 2 && status > 0)  /*  1, 2 */
217                                 --status;       /*  set to 0 or 1 */
218                         else
219                                 status = 0;     /*  set 12H       */
220
221                         /*  TODO assert 1 or 0 */
222                         ad->data_time->chk_status = !status;
223
224                         char datefield_format[MAX_DATETIME_FORMAT_LEN + 1] = {0, };
225
226                         const char *time_format = NULL;
227                         if (ad->data_time->chk_status)//12 hours
228                         {
229                                 time_format = "%I : %M %p";
230                         } else { //24 hours
231                                 time_format = "%H : %M";
232                         }
233
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 " "
238                                  "%s", old_format);
239                         safeStrNCat(datefield_format, time_format, MAX_DATETIME_FORMAT_LEN);
240                         SETTING_TRACE("datefield_format:%s", datefield_format);
241 #else
242                         int value = SETTING_DATE_FORMAT_DD_MM_YYYY;
243                         int err = -1;
244
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;
249
250                         snprintf(datefield_format, MAX_DATETIME_FORMAT_LEN,
251                                  "%s %s", date_format_str[value], time_format);
252 #endif
253
254                         elm_datetime_format_set(ad->data_time->eo_check, datefield_format);
255                 }
256         }
257 }
258
259 /* ***************************************************
260  *
261  *basic func
262  *
263  ***************************************************/
264 static void setting_time_main_datefield_change_cb(void *data, Evas_Object *obj,
265                                       void *event_info)
266 {
267         SETTING_TRACE_BEGIN;
268         /* error check */
269         ret_if(data == NULL);
270         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
271         SettingTimeUG *ad = list_item->userdata;
272
273         if (EINA_FALSE == ad->is_datefield_selected) {
274                 SETTING_TRACE("Datefield is not selected\n");
275                 return;
276         }
277
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");
281                 SETTING_TRACE_END;
282                 return;
283         } else {
284                 // otherwise, we apply a new date which has been changed by a user
285         }
286
287         struct tm _tm;
288         elm_datetime_value_get(obj, &_tm);
289
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));
295                 return;
296         }
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);
299 #endif
300         _tm.tm_sec = 0;
301
302         int isdst;
303         if (get_timezone_isdst(&isdst) == SETTING_RETURN_SUCCESS) {
304                 _tm.tm_isdst = isdst;
305         } else {
306                 // error
307                 SETTING_TRACE_ERROR("get_timezone_isdst() failed");
308                 return;
309         }
310
311         /*  local time  -> gmtime */
312         time_t the_time = mktime(&_tm); /* represent local time */
313         ad->changed_time = the_time;
314
315         if ( (time(NULL)/ONE_MINUTE) == (the_time/ONE_MINUTE) )
316         {
317                 SETTING_TRACE("Time is not changed\n");
318                 //current time didn't change
319                 return;
320         }
321
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;
327         }
328
329         // create new popup
330         ad->pop_progress =
331                 setting_create_popup_with_progressbar(ad, ad->win_get, "pending_list",
332                                                       NULL, NULL, NULL, 0, TRUE, TRUE);
333 #endif
334
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");
338
339         SETTING_TRACE_END;
340 }
341
342 Eina_Bool __refresh_date_timer(void *data)
343 {
344         SETTING_TRACE_BEGIN;
345         SettingTimeUG *ad = data;
346         if (ad->data_time) {
347                 time_t ctime = time(NULL);
348                 struct tm ts_ret;
349                 struct tm *ts = localtime_r(&ctime, &ts_ret);
350                 retv_if(!ts, 1);
351
352                 time_t diff = abs(ctime - ad->changed_time);
353                 if (diff <=1 || diff >= 60) {
354                         diff = 0;
355                 } else {
356                         elm_datetime_value_set(ad->data_time->eo_check, &ts_ret);
357                 }
358         }
359         return 1;
360 }
361
362 static void __setting_time_main_exp_cb(void *data, Evas_Object *obj,
363                                        void *event_info)
364 {
365         ret_if(NULL == data || NULL == event_info);
366         SETTING_TRACE_BEGIN;
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);
371
372         Evas_Object *rgd;
373         if (data_parentItem == ad->data_time_fmt) {
374
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",
383                                                      NULL);
384
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",
391                                                      NULL);
392
393                 setting_update_chk_status(rgd,
394                                           data_parentItem->int_slp_setting_binded);
395
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",
405                                                      NULL);
406
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",
413                                                      NULL);
414
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",
421                                                      NULL);
422
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",
429                                                      NULL);
430
431                 setting_update_chk_status(rgd,
432                                           data_parentItem->int_slp_setting_binded);
433
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);
443
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);
450
451                 setting_update_chk_status(rgd,
452                                           data_parentItem->int_slp_setting_binded);
453         }
454 }
455
456 static int setting_time_main_create(void *cb)
457 {
458         SETTING_TRACE_BEGIN;
459         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
460
461         SettingTimeUG *ad = (SettingTimeUG *) cb;
462
463         char *l_btn = NULL;
464         char *r_btn = NULL;
465         char *title = _("IDS_ST_BODY_DATE_AND_TIME");
466         char *caller = NULL;
467         ad->is_datefield_selected = EINA_FALSE;
468
469         setting_call_back_func l_button_cb = NULL;
470         setting_call_back_func r_button_cb = NULL;
471
472         service_h service = ad->bundle_data;
473
474         service_get_extra_data(service, "caller", &caller);
475         service_get_extra_data(service, "lbutton", &l_btn);
476         if(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);
480         if(r_btn)
481                 r_button_cb = setting_time_main_click_softkey_caller_exist_right_cb;
482
483         Evas_Object *scroller;  /*  scroller is a genlist */
484
485         ad->caller = caller;
486         if (ad->caller) {
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");
491                         same_flag = TRUE;
492                 }
493
494                 Evas_Object *controllbar = NULL;
495
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.
501                         FREE(lbtn_str);
502                         return SETTING_DRAW_ERR_FAIL_SCROLLER;
503                 }
504
505                 elm_genlist_clear(scroller);
506                 ad->ly_main =
507                             setting_create_layout_navi_bar(ad->win_main_layout,
508                                                            ad->win_get,
509                                                            title,
510                                                            NULL, NULL, NULL,
511                                                            NULL, NULL, NULL,
512                                                            ad, scroller,
513                                                            &ad->navi_bar,
514                                                            &controllbar);
515
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);
520
521                 if (same_flag) {
522                         setting_time_main_controlbar_lbtn_label_set(controllbar,
523                                                                     lbtn_str);
524                 }
525                 if (lbtn_str) {
526                         G_FREE(lbtn_str);
527                 }
528
529         } else {
530                 l_btn = _("IDS_COM_BODY_BACK");
531                 title = _("IDS_ST_BODY_DATE_AND_TIME");
532                 ad->ly_main =
533                     setting_create_layout_navi_bar_genlist(ad->win_main_layout,
534                                                            ad->win_get, title,
535                                                            l_btn, NULL,
536                                                            setting_time_main_click_softkey_left_cb,
537                                                            NULL, ad, &scroller,
538                                                            &ad->navi_bar);
539         }
540         ad->scrl_main = scroller;
541
542         int value;
543         int err;
544         int ret = 0;
545         Elm_Object_Item *item;
546
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,
551                                  &err);
552         bool auto_flag = value;
553
554         /*  UI automatic */
555         if (!isEmulBin()) {
556                 ad->data_auto =
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,
560                                                      NULL, value,
561                                                      "IDS_ST_BODY_AUTOMATIC_UPDATE", NULL,
562                                                      setting_time_main_chk_btn_cb);
563                 if (ad->data_auto) {
564                         ad->data_auto->userdata = ad;
565                 } else {
566                         SETTING_TRACE_ERROR("ad->data_auto is NULL");
567                 }
568
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,
572                                                  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);
575         }
576
577         setting_set_i18n("worldclock", SETTING_TIME_SHARE_LOCAL_PATH);
578
579         char time_zone_sub_str[CITY_BUF_SIZE + GMT_BUF_SIZE + 3] = { 0, };
580         char *pa_timezone = NULL;
581         char *pa_city = NULL;
582
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"
585
586         if ((pa_timezone != NULL) && (_(pa_city) != NULL)) {
587
588                 // don't use hard coded value
589                 // get value from current timezone
590
591                 char str_buf[GMT_BUF_SIZE] = {0, };
592                 get_gmt_offset(str_buf, GMT_BUF_SIZE);
593
594                 char* timezone_str = get_timezone_str();
595
596                 bool ret = get_city_name(timezone_str);
597                 if (ret) {
598                         SETTING_TRACE(">>>>>> RESULT : %s", get_city_name_result());
599                 }
600                 char* cityname_id = get_city_name_result();
601
602                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s", _(cityname_id), _(str_buf));
603                 FREE(pa_city);
604                 FREE(pa_timezone);
605                 retv_if(ret < 0, 0);
606         } else {
607                 // default code
608                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT +09", _("IDS_WCL_BODY_CITYNAME_SEOUL"));
609                 retv_if(ret < 0, 0);
610         }
611
612         /*  UI create time zone */
613         ad->data_tz =
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);
619         if (ad->data_tz) {
620                 ad->data_tz->userdata = ad;
621         } else {
622                 SETTING_TRACE_ERROR("ad->data_tz is NULL");
623         }
624
625         /* create DATE_AND_TIME */
626         /* DATE_AND_TIME */
627         ret =
628             setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224,
629                                     &value, &err);
630         if (ret == SETTING_RETURN_FAIL) {
631                 value = VCONFKEY_TIME_FORMAT_12;
632         }
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" };
635         ret =
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;
639
640         /*  UI format string */
641         ad->data_time =
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);
649         if (ad->data_time) {
650                 ad->data_time->userdata = ad;
651                 ad->data_time->isItemDisableFlag = auto_flag;
652         } else {
653                 SETTING_TRACE_ERROR("ad->data_time is NULL");
654         }
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);
658
659         /*  UI create "Time format" */
660         setting_enable_expandable_genlist(scroller, ad,
661                                           __setting_time_main_exp_cb, NULL);
662
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",
669                                                     pa_time_format);
670         if (ad->data_time_fmt) {
671                 ad->data_time_fmt->int_slp_setting_binded =
672                         INT_SLP_SETTING_REGIONFORMAT_TIME1224;
673         } else {
674                 SETTING_TRACE_ERROR("ad->data_time_fmt is NULL");
675         }
676         G_FREE(pa_time_format);
677
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",
685                                                     pa_time_format);
686         if (ad->data_date_fmt) {
687                 ad->data_date_fmt->int_slp_setting_binded =
688                         INT_SLP_SETTING_DATE_FORMAT;
689         } else {
690                 SETTING_TRACE_ERROR("ad->data_date_fmt is NULL");
691         }
692         G_FREE(pa_date_format);
693 #endif
694
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",
703                                                     pa_week);
704         if (ad->data_firstday_week_fmt) {
705                 ad->data_firstday_week_fmt->int_slp_setting_binded =
706                         INT_SLP_SETTING_WEEK_FORMAT;
707         } else {
708                 SETTING_TRACE_ERROR("ad->data_firstday_week_fmt is NULL");
709         }
710     G_FREE(pa_week);
711 #endif
712
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);
716
717         if (auto_flag)
718         {
719                 if (ad->data_tz) {
720                         setting_disable_genlist_item(ad->data_tz->item);
721                 }
722                 if (ad->data_time) {
723                         setting_disable_genlist_item(ad->data_time->item);
724                 }
725         }
726
727         setting_view_time_main.is_create = 1;
728
729 #if TIME_CHANGED_HEYNOTY_CALLBACK
730         /* ---------------------------------------------------------------- */
731         /*  heynoti registration */
732         /* ---------------------------------------------------------------- */
733         ad->noti_fd = heynoti_init();
734
735         if (ad->noti_fd == -1) {
736                 SETTING_TRACE("heynoti_init FAIL");
737                 return SETTING_RETURN_FAIL;
738         } else {
739                 SETTING_TRACE("heynoti_init OK");
740         }
741
742         if (-1 == heynoti_subscribe(ad->noti_fd, SETTING_TIME_CHANGED, time_changed_callback, (void *)ad)) {
743                 SETTING_TRACE("heynoti_subscribe FAIL");
744         } else {
745                 SETTING_TRACE("heynoti_subscribe OK");
746         }
747
748         if (-1 == heynoti_attach_handler(ad->noti_fd)) {
749                 SETTING_TRACE("heynoti_attach_handler FAIL");
750         } else {
751                 SETTING_TRACE("heynoti_attach_handler OK");
752         }
753 #endif
754
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);
760
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);
766
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);
769
770         return SETTING_RETURN_SUCCESS;
771 }
772
773 static int setting_time_main_destroy(void *cb)
774 {
775         SETTING_TRACE_BEGIN;
776         /* error check */
777         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
778
779         SettingTimeUG *ad = (SettingTimeUG *) cb;
780
781 #if TIME_CHANGED_HEYNOTY_CALLBACK
782         /* Closing heynoti */
783         if (ad->noti_fd != -1)//first need to check the fd validation
784         {
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);
788                 ad->noti_fd = -1;
789         }
790 #endif
791         if (ad->update_timer) {
792                 ecore_timer_del(ad->update_timer);
793                 ad->update_timer = NULL;
794         }
795
796 #if PROGRESS_POPUP_SHOW
797         if (ad->pop_progress) {
798                 evas_object_del(ad->pop_progress);
799                 ad->pop_progress = NULL;
800         }
801 #endif
802
803         if (ad->update_timezone_idler) {
804                 ecore_idler_del(ad->update_timezone_idler);
805                 ad->update_timezone_idler = NULL;
806         }
807         if (ad->refresh_time_idler) {
808                 ecore_idler_del(ad->refresh_time_idler);
809                 ad->refresh_time_idler = NULL;
810         }
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);
815
816         if (ad->ly_main != NULL) {
817                 evas_object_del(ad->ly_main);
818                 setting_view_time_main.is_create = 0;
819         }
820
821         return SETTING_RETURN_SUCCESS;
822 }
823
824 static int setting_time_main_update(void *cb)
825 {
826         SETTING_TRACE_BEGIN;
827         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
828
829         SettingTimeUG *ad = (SettingTimeUG *) cb;
830
831         if (ad->ly_main != NULL) {
832                 evas_object_show(ad->ly_main);
833                 // update timezone
834                 if (ad->update_timezone_idler) {
835                         ecore_idler_del(ad->update_timezone_idler);
836                         ad->update_timezone_idler = NULL;
837                 }
838                 ad->update_timezone_idler =
839                     ecore_idler_add((Ecore_Task_Cb) __update_timezone_idler, ad);
840                 // update time
841                 if (ad->refresh_time_idler) {
842                         ecore_idler_del(ad->refresh_time_idler);
843                         ad->refresh_time_idler = NULL;
844                 }
845                 ad->refresh_time_idler = ecore_idler_add(setting_update_datefield, ad);
846         }
847         return SETTING_RETURN_SUCCESS;
848 }
849
850 static int setting_time_main_cleanup(void *cb)
851 {
852         SETTING_TRACE_BEGIN;
853         return SETTING_RETURN_SUCCESS;
854 }
855
856
857 /* ***************************************************
858  **
859  **general func
860  **
861  ****************************************************/
862
863 int setting_time_check_automatic_time_update_state()
864 {
865         SETTING_TRACE_BEGIN;
866         int bvalue = 0;
867         int ret = 0;
868         int err = 0;
869
870         ret =
871             setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
872                                      &bvalue, &err);
873
874         return bvalue;
875
876 }
877
878 static int __setting_set_city_tzone(const char* pTZPath)
879 {
880         // let's get city & timezone string from pTZPath
881         // 1. city name
882         char szTimezone[GMT_BUF_SIZE] = {0,};
883         char* pStr = strdup(pTZPath);
884
885         // 2. timezone string +/-<n> ex. +9, -1
886         get_gmt_offset(szTimezone, GMT_BUF_SIZE);
887
888         int ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_INT, szTimezone);
889         if (ret == -1) {
890                 FREE(pStr);
891                 SETTING_TRACE("set vconf failed");
892                 return FALSE;
893         }
894
895         // set timezone_id
896         /** @todo replace with vconf ID */
897         ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_ID, pStr);
898         FREE(pStr);
899
900         return TRUE;
901 }
902
903 static void
904 setting_time_main_launch_worldclock_result_ug_cb(ui_gadget_h ug,
905                                                  service_h result, void *priv)
906 {
907         SETTING_TRACE_BEGIN;
908         /* error check */
909         retm_if(priv == NULL, "Data parameter is NULL");
910
911         SettingTimeUG *ad = (SettingTimeUG *) priv;
912
913         char *city = NULL;
914         char *tzpath = NULL;
915         service_get_extra_data(result, "city", &city);
916         service_get_extra_data(result, "tzpath", &tzpath);
917
918         if (!tzpath) {
919                 SETTING_TRACE("tzpath from worldclock UG is null.");
920                 return;
921         } else {
922                 SETTING_TRACE("tzpath : %s", tzpath );
923         }
924
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);
930
931         int ret = sysman_set_timezone(tz_path);
932         if (ret < 0) {
933                 SETTING_TRACE("tzpath is not valid.");
934                 return;
935         } else
936                 SETTING_TRACE("sysman_set_timezone - successful : %s \n", tz_path);
937
938         ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city);
939         setting_retm_if(ret != 0, "set vconf failed");
940
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")
945                 return;
946         }
947
948         // update the display for timezone
949         setting_update_timezone(ad);
950         heynoti_publish(SETTING_TIME_CHANGED);
951         SETTING_TRACE_END;
952 }
953
954 void setting_time_main_launch_worldclock_destroy_ug_cb(ui_gadget_h ug,
955                                                        void *priv)
956 {
957         SETTING_TRACE_BEGIN;
958         /* if(ug) ug_destroy(ug); */
959         /* restore the '<-' button on the navigate bar */
960         ret_if(!priv);
961         SettingTimeUG *ad = (SettingTimeUG *) priv;
962         if (ug) {
963                 ug_destroy(ug);
964                 ad->ug_loading = NULL;
965         }
966         Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
967         ret_if(!navi_it);
968         Evas_Object *back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
969
970         if (back_btn != NULL) {
971                 elm_object_style_set(back_btn, NAVI_BACK_BUTTON_STYLE); /* take into effect */
972         }
973
974 }
975
976 void setting_time_main_launch_worldclock_layout_ug_cb(ui_gadget_h ug,
977                                                       enum ug_mode mode,
978                                                       void *priv)
979 {
980         SETTING_TRACE_BEGIN;
981         SettingTimeUG *ad = (SettingTimeUG *) priv;
982         Evas_Object *base;
983
984         if (!priv)
985                 return;
986
987         base = (Evas_Object *) ug_get_layout(ug);
988         if (!base)
989                 return;
990
991         switch (mode) {
992         case UG_MODE_FULLVIEW:
993                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
994                                                  EVAS_HINT_EXPAND);
995                 elm_win_resize_object_add(ad->win_get, base);
996                 evas_object_show(base);
997                 break;
998         default:
999                 break;
1000         }
1001         SETTING_TRACE_END;
1002 }
1003
1004
1005 void setting_time_main_launch_worldclock_sg(void *data)
1006 {
1007         SETTING_TRACE_BEGIN;
1008         /* error check */
1009         retm_if(data == NULL, "Data parameter is NULL");
1010
1011         SettingTimeUG *ad = (SettingTimeUG *) data;
1012
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;
1019
1020         SETTING_TRACE("to load ug[%s]", "worldclock-efl");
1021         ad->ug_loading =
1022             ug_create(ad->ug, "worldclock-efl", UG_MODE_FULLVIEW, NULL, cbs);
1023         if (NULL == ad->ug_loading) {   /* error handling */
1024         }
1025
1026         FREE(cbs);
1027         return;
1028 }
1029
1030
1031 Eina_Bool setting_update_datefield(void *cb)
1032 {
1033         SETTING_TRACE_BEGIN;
1034         retvm_if(cb == NULL, EINA_FALSE, "Data parameter is NULL");
1035         SettingTimeUG *ad = (SettingTimeUG *) cb;
1036
1037         __refresh_date_timer(ad);
1038         ad->refresh_time_idler = NULL;
1039         return 0;
1040 }
1041
1042 /* ***************************************************
1043  **
1044  **call back func
1045  **
1046  ****************************************************/
1047
1048 void
1049 setting_time_main_click_softkey_left_cb(void *data, Evas_Object *obj,
1050                                         void *event_info)
1051 {
1052         SETTING_TRACE_BEGIN;
1053         retm_if(data == NULL, "Data parameter is NULL");
1054
1055         SettingTimeUG *ad = (SettingTimeUG *) data;
1056
1057         /* Send destroy request */
1058         ug_destroy_me(ad->ug);
1059 }
1060
1061 /* ***************************************************
1062  **
1063  **call back func
1064  **
1065  ****************************************************/
1066
1067 void
1068 setting_time_main_click_softkey_caller_exist_left_cb(void *data,
1069                                                      Evas_Object *obj,
1070                                                      void *event_info)
1071 {
1072         SETTING_TRACE_BEGIN;
1073         /* error check */
1074         retm_if(data == NULL, "Data parameter is NULL");
1075
1076         SettingTimeUG *ad = (SettingTimeUG *) data;
1077
1078         /*  Create Bundle and send message */
1079         service_h svc;
1080         if (service_create(&svc))
1081                 return;
1082
1083         service_add_extra_data(svc, "result", "lbutton_click");
1084         ug_send_result(ad->ug, svc);
1085
1086         service_destroy(svc);
1087
1088         /* Send destroy request */
1089         ug_destroy_me(ad->ug);
1090 }
1091
1092 void
1093 setting_time_main_click_softkey_caller_exist_right_cb(void *data,
1094                                                       Evas_Object *obj,
1095                                                       void *event_info)
1096 {
1097         SETTING_TRACE_BEGIN;
1098         /* error check */
1099         retm_if(data == NULL, "Data parameter is NULL");
1100
1101         SettingTimeUG *ad = (SettingTimeUG *) data;
1102
1103         /*  Create Bundle and send message */
1104         service_h svc;
1105         if (service_create(&svc))
1106                 return;
1107
1108         service_add_extra_data(svc, "result", "rbutton_click");
1109         ug_send_result(ad->ug, svc);
1110
1111         service_destroy(svc);
1112
1113         /* Send destroy request */
1114         ug_destroy_me(ad->ug);
1115 }
1116
1117 static void setting_time_reboot_resp_cb(void *data, Evas_Object *obj,
1118                                         void *event_info)
1119 {
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);
1126         }
1127
1128         SettingTimeUG *ad = data;
1129         if (ad->pop)
1130         {
1131                 evas_object_del(ad->pop);
1132                 ad->pop = NULL;
1133         }
1134 }
1135
1136 static void
1137 setting_time_main_chk_btn_cb(void *data, Evas_Object *obj, void *event_info)
1138 {
1139         SETTING_TRACE_BEGIN;
1140         /* error check */
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 */
1147         if (ad->data_auto)
1148                 ad->chk_auto = ad->data_auto->eo_check;
1149         if (ad->data_dst)
1150                 ad->chk_dst = ad->data_dst->eo_check;
1151
1152         if (ad->data_time) {
1153                 elm_object_focus_set(ad->data_time->eo_check, EINA_FALSE);
1154         }
1155
1156         int err;
1157         if (obj == ad->chk_auto) {
1158                 int bvalue;
1159                 setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1160                                          &bvalue, &err);
1161                 if (bvalue) {
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);
1164
1165                         if (ad->data_tz) {
1166                                 setting_enable_genlist_item(ad->data_tz->item);
1167                         }
1168
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);
1173                         }
1174
1175                 } else {
1176                         ad->pop =
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,
1180                                                  0, 2,
1181                                                  dgettext("sys_string",
1182                                                        "IDS_COM_SK_OK"),
1183                                                  _("IDS_COM_SK_CANCEL"));
1184                 }
1185         }
1186 }
1187
1188
1189 static void setting_time_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
1190                                            void *event_info)
1191 {
1192         SETTING_TRACE_BEGIN;
1193         /* error check */
1194         setting_retm_if(data == NULL, "Data parameter is NULL");
1195
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);
1201
1202         SettingTimeUG *ad = (SettingTimeUG *) data;
1203         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
1204
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);
1207         }
1208
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));
1214                 } else {
1215                         setting_time_main_launch_worldclock_sg(ad);
1216                 }
1217
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));
1223                 } else {
1224                         /* setting_view_change(&setting_view_time_main, &setting_view_time_time, ad); */
1225                 }
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);
1229                 /* new status */
1230                 list_item->chk_status = !old_status;
1231                 elm_check_state_set(list_item->eo_check, list_item->chk_status);
1232                 int err = 0;
1233                 if (!list_item->chk_status) {
1234                         (void)
1235                             setting_set_bool_slp_key
1236                             (BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1237                              SETTING_ON_OFF_BTN_OFF, &err);
1238
1239                         if (ad->data_tz) {
1240                                 setting_enable_genlist_item(ad->data_tz->item);
1241                         }
1242
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);
1247                         }
1248
1249                 } else {
1250                         ad->pop =
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,
1254                                                  0, 2,
1255                                                  dgettext("sys_string", "IDS_COM_SK_OK"),
1256                                                  _("IDS_COM_SK_CANCEL"));
1257                 }
1258
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);
1265         }
1266 }
1267
1268
1269 void setting_time_main_btn_update_ok_cb(void *cb)
1270 {
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;
1278
1279         sysman_request_reboot();
1280
1281         /*  We'd better check return value from sysman_request_reboot() function. */
1282         /*  It will return 0 on success or -1 if failed. */
1283 }
1284
1285
1286 void setting_time_main_btn_update_cancel_cb(void *cb)
1287 {
1288         SETTING_TRACE_BEGIN;
1289         SettingTimeUG *ad = (SettingTimeUG *) cb;
1290
1291         int err;                /* error check */
1292
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;
1298
1299 }
1300
1301
1302 static UChar *uastrcpy(const char *chars)
1303 {
1304         int len = 0;
1305         UChar *str = NULL;
1306         len = safeStrLen(chars);
1307         str = (UChar *) malloc(sizeof(UChar) *(len + 1));
1308         if (!str)
1309                 return NULL;
1310         u_uastrcpy(str, chars);
1311         return str;
1312 }
1313
1314
1315 static int get_timezone_isdst(int* isdst)
1316 {
1317         SETTING_TRACE_BEGIN;
1318     struct tm *ts;
1319     time_t ctime;
1320
1321     enum { BUFFERSIZE = 1024 };
1322     char buf[BUFFERSIZE];
1323     ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
1324
1325     if (len != -1) {
1326         buf[len] = '\0';
1327     }
1328     else {
1329         /* handle error condition */
1330     }
1331
1332     ctime = time(NULL);
1333     ts = localtime(&ctime);
1334         if ( ! ts ) {
1335                 return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
1336         }
1337
1338     SETTING_TRACE(" == tz_path = %s", buf);
1339     SETTING_TRACE(" == isdst = %d\n", ts->tm_isdst);
1340         *isdst = ts->tm_isdst;
1341
1342         return SETTING_RETURN_SUCCESS;
1343 }
1344
1345
1346 static void ICU_set_timezone(const char *timezone)
1347 {
1348         SETTING_TRACE("ICU_set_timezone = %s ", timezone);
1349         UErrorCode ec = U_ZERO_ERROR;
1350         UChar *str = uastrcpy(timezone);
1351
1352         ucal_setDefaultTimeZone(str, &ec);
1353         if (U_SUCCESS(ec)) {
1354                 SETTING_TRACE("ucal_setDefaultTimeZone() SUCCESS ");
1355         } else {
1356                 SETTING_TRACE("ucal_setDefaultTimeZone() FAILED : %s ",
1357                               u_errorName(ec));
1358         }
1359         FREE(str);
1360 }
1361
1362
1363 static void setting_time_main_controlbar_lbtn_label_set(
1364                                                         Evas_Object *controlbar,
1365                                                         char *label)
1366 {
1367         SETTING_TRACE_BEGIN;
1368         setting_retm_if(controlbar == NULL, "controlbar parameter is NULL");
1369         setting_retm_if(label == NULL, "label parameter is NULL");
1370
1371         Evas_Object *eo_lbtn = NULL;
1372         Elm_Object_Item *first_item = NULL;
1373
1374         first_item = elm_toolbar_first_item_get(controlbar);
1375         setting_retm_if(first_item == NULL, "get first_item failed");
1376
1377         eo_lbtn = elm_object_item_part_content_get(first_item, "object");
1378         setting_retm_if(eo_lbtn == NULL, "get eo_lbtn failed");
1379
1380         elm_object_text_set(eo_lbtn, label);
1381 }
1382
1383
1384 /**
1385  * ex) timezone : Asia/Seoul --> returns "+09"
1386  *
1387  * char outstr2[4];
1388  */
1389 static void get_gmt_offset(char *str_buf, int size)
1390 {
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.
1394
1395         struct tm* data;
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);
1400
1401         data = gmtime(&a);
1402         data->tm_isdst = 0;                     // summer time, not applied.
1403         time_t b = mktime(data);
1404
1405         int gmtoffset_hour = (a-b)/3600;        // result : hour.
1406         int gmtoffset_min = ((a-b)%3600)/60;    // result : min.
1407         if(gmtoffset_min != 0) {
1408                 gmtoffset_min = 30;
1409         }
1410
1411         snprintf(str_buf, size, "%+d:%02u", gmtoffset_hour, gmtoffset_min);
1412         SETTING_TRACE("szTimezone is of a valid format: GMT: %s", str_buf);
1413 }
1414
1415
1416 // automatic
1417 static char* get_timezone_str()
1418 {
1419     SETTING_TRACE_BEGIN;
1420
1421     enum { BUFFERSIZE = 1024 };
1422     char buf[BUFFERSIZE];
1423     ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
1424
1425     if (len != -1) {
1426         buf[len] = '\0';
1427     }
1428     else {
1429         /* handle error condition */
1430     }
1431     return g_strdup(buf+20);            //Asia/Seoul
1432 }
1433
1434 static char* get_city_name_result()
1435 {
1436         return s_result;
1437 }
1438
1439
1440 // in_str = "Asia/Seoul"
1441 static bool get_city_name(char* tzname)
1442 {
1443         sqlite3 *pSQLite3 = NULL;
1444         char    *szErrMsg = NULL;
1445
1446         int rst = sqlite3_open( "/opt/dbspace/.worldclock.db", &pSQLite3);
1447         if ( rst )
1448         {
1449                 printf( "Can't open database: %s\n", sqlite3_errmsg( pSQLite3 ));
1450                 sqlite3_close( pSQLite3 );
1451                 pSQLite3 = NULL;
1452                 return false;
1453         }
1454         else
1455         {
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);
1461         }
1462
1463         //객체해제
1464         sqlite3_free( szErrMsg );
1465         sqlite3_close( pSQLite3 );
1466         printf("Database close!!\n");
1467         return true;
1468 }
1469
1470 static int query_callback(void *NotUsed, int argc, char **argv, char **azColName)
1471 {
1472     int i = 0;
1473     printf("%s\n", argv[i] ? argv[i] : "NULL");
1474         s_result = g_strdup(argv[i] ? argv[i] : "NULL");
1475     return 0;
1476 };
1477
1478
1479 #if 0                   /* example */
1480 int main(int argc, char* argv[])
1481 {
1482         g_type_init ();
1483         int ret;
1484         // exporting - current status
1485         if ( (argc == 2) && (0 == strcmp(argv[1], "export"))) {
1486                         setting_export();
1487         }
1488         else if ( (argc == 2) && (0 == strcmp(argv[1], "timezone_init"))) {
1489
1490                 //////////////////////////////////////////////////////////////////////////
1491                 char* tz_path_zone_city = get_timezone_str();
1492                 bool ret = get_city_name(tz_path_zone_city);
1493                 if (ret) {
1494                         printf(">>>>>> RESULT : %s \n", get_city_name_result());
1495                 }
1496                 //////////////////////////////////////////////////////////////////////////
1497         }
1498         else {
1499                 // cfg create
1500                 // TRUE or FALSE
1501                 ret = setting_cfg_create();
1502         }
1503         return 0;
1504 }
1505 #endif
1506
1507
1508