Fix the different issue of Setting's time and Indicator's time and Fix N_SE-13536
[apps/home/settings.git] / setting-time / src / setting-time-main.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <setting-time-main.h>
23 #include <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 static bool setting_update_timezone(SettingTimeUG *ad);
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 bool __update_timezone_idler(SettingTimeUG *ad)
71 {
72         setting_update_timezone(ad);
73         ad->update_timezone_idler = NULL;
74         return 0;
75 }
76 #if TIME_CHANGED_HEYNOTY_CALLBACK
77 void time_changed_callback(void *data)
78 {
79         SETTING_TRACE_DEBUG("time and timezone have been changed: TIME_CHANGED_HEYNOTY_CALLBACK");
80         SettingTimeUG *ad = (SettingTimeUG *)data;
81
82         int ret = setting_time_update_cb(ad);
83         if (ret != 0) {
84                 SETTING_TRACE("FAIL: setting_time_update_db(ad)\n");
85         }
86
87         SETTING_TRACE("ad->is_datefield_selected:%d", ad->is_datefield_selected)
88         if(EINA_TRUE == ad->is_datefield_selected) {
89                 /* Timezone is not changed and a selected value of the datefield is already changed */
90                 SETTING_TRACE("Datefield is selected\n");
91                 return ;
92         }
93
94         tzset();
95         // vconfset to update timezone
96         char pTZPath[__MAX_PATH_SIZE];
97         ssize_t nLen = readlink(SETTING_TZONE_SYMLINK_PATH, pTZPath, sizeof(pTZPath)-1);
98         if (nLen != -1) {
99                 pTZPath[nLen] = '\0';
100         } else {
101                 SETTING_TRACE("parse error for SETTING_TZONE_SYMLINK_PATH");
102                 return;
103         }
104
105         if (!__setting_set_city_tzone(&pTZPath[20])) {
106                 SETTING_TRACE("__setting_set_city_tzone ERROR");
107                 return;
108         }
109         char *timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
110         setting_retm_if(timezone == NULL, "get vonf failed");
111         ICU_set_timezone(timezone);
112         FREE(timezone);
113
114         // update timezone
115         if (ad->update_timezone_idler) {
116                 ecore_idler_del(ad->update_timezone_idler);
117                 ad->update_timezone_idler = NULL;
118         }
119         ad->update_timezone_idler =
120             ecore_idler_add((Ecore_Task_Cb) __update_timezone_idler, ad);
121         // update time
122         if (ad->refresh_time_idler) {
123                 ecore_idler_del(ad->refresh_time_idler);
124                 ad->refresh_time_idler = NULL;
125         }
126         ad->refresh_time_idler = ecore_idler_add(setting_update_datefield, ad);
127 }
128 #endif
129
130 void setting_time_update_time_date_format_string(SettingTimeUG *ad)
131 {
132         SETTING_TRACE_BEGIN;
133
134         struct tm *ts;
135         struct tm ts_ret;
136         time_t ctime;
137
138         int ret, value, err;
139
140         char time_str[MAX_ARGS];
141
142         ctime = time(NULL);
143         ts = localtime_r(&ctime, &ts_ret);
144         ret_if(!ts);
145
146         /* set time in particular format */
147         ret = setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224, &value, &err);
148         if (ret == SETTING_RETURN_FAIL)
149                 value = VCONFKEY_TIME_FORMAT_12;
150
151         switch (value) {
152         case VCONFKEY_TIME_FORMAT_12:
153                 {
154                         /* Get Time */
155                         strftime(time_str, MAX_ARGS, "%l:%M %p ", &ts_ret);
156                 }
157                 break;
158
159         case VCONFKEY_TIME_FORMAT_24:
160                 {
161                         strftime(time_str, MAX_ARGS, "%H:%M", &ts_ret);
162                 }
163                 break;
164         default:
165                 /* do nothing */
166                 break;
167         }
168
169         if (ad->data_time) {
170                 elm_object_item_data_set(ad->data_time->item, ad->data_time);
171                 elm_genlist_item_update(ad->data_time->item);
172         }
173 }
174
175 bool setting_update_timezone(SettingTimeUG *ad)
176 {
177         /* SETTING_TRACE_BEGIN; */
178         char time_zone_sub_str[CITY_BUF_SIZE + GMT_BUF_SIZE + 3] = { 0, };
179         char *pa_timezone = NULL;
180         char *pa_city = NULL;
181         int ret = 0;
182
183         /*  get time zone */
184         pa_city = vconf_get_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT);
185         pa_timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_INT);
186
187         //if ((pa_timezone != NULL) && (_(pa_city) != NULL && safeStrCmp(_(pa_city), "NULL"))) {
188         if ((pa_timezone != NULL) && (_(pa_city) != NULL )) {
189                 /* SETTING_TRACE_DEBUG("*** timezone: %s *** ", timezone); */
190                 /* SETTING_TRACE_DEBUG("*** city: %s *** ", _(city)); */
191                 /* SETTING_TRACE_DEBUG("*** ret: %d, dst: %d *** ", ret, dst); */
192
193                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s", _(pa_city), pa_timezone);
194                 //ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s", pa_timezone, _(pa_city));
195                 FREE(pa_city);
196                 retv_if(ret < 0, 0);
197         } else {
198                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT +09", _("IDS_WCL_BODY_CITYNAME_SEOUL"));
199                 retv_if(ret < 0, 0);
200         }
201         SETTING_TRACE("ad->data_tz:%p", ad->data_tz);
202
203         if (ad->data_tz) {
204                 ad->data_tz->sub_desc = (char *)g_strdup(time_zone_sub_str);
205                 elm_object_item_data_set(ad->data_tz->item, ad->data_tz);
206                 elm_genlist_item_update(ad->data_tz->item);
207         }
208         return 0;
209 }
210
211
212 static void setting_time_main_int_vconf_change_cb(keynode_t *key, void *data)
213 {
214         /* SETTING_TRACE_BEGIN; */
215         ret_if(NULL == data);
216         SettingTimeUG *ad = data;
217         int status = vconf_keynode_get_int(key);
218         char *vconf_name = vconf_keynode_get_name(key);
219         /* SETTING_TRACE("vconf_name:%s", vconf_name); */
220
221         if (!safeStrCmp(vconf_name, VCONFKEY_REGIONFORMAT_TIME1224)) {
222
223                 if (ad->data_time) {
224                         /* VCONFKEY_REGIONFORMAT_TIME1224 1:12H 2:24H */
225                         if (status <= 2 && status > 0)  /*  1, 2 */
226                                 --status;       /*  set to 0 or 1 */
227                         else
228                                 status = 0;     /*  set 12H       */
229
230                         /*  TODO assert 1 or 0 */
231                         ad->data_time->chk_status = !status;
232
233                         char datefield_format[MAX_DATETIME_FORMAT_LEN + 1] = {0, };
234
235                         const char *time_format = NULL;
236                         if (ad->data_time->chk_status)//12 hours
237                         {
238                                 time_format = "%I : %M %p";
239                         } else { //24 hours
240                                 time_format = "%H : %M";
241                         }
242
243 //get date format from datefiled itself, if elm_datetime_add() supports set date-format via ICU.
244 #ifdef SUPPORT_DATEFIELD_DATE_FORMAT_AUTOSET
245                         const char *old_format = elm_datetime_format_get(ad->data_time->eo_check);
246                         snprintf(datefield_format, MAX_DATE_FORMAT_LEN + 1, //add one space " "
247                                  "%s", old_format);
248                         safeStrNCat(datefield_format, time_format, MAX_DATETIME_FORMAT_LEN);
249                         SETTING_TRACE("datefield_format:%s", datefield_format);
250 #else
251                         int value = SETTING_DATE_FORMAT_DD_MM_YYYY;
252                         int err = -1;
253
254                         char *date_format_str[] = { "%d %b %Y", "%b %d %Y", "%Y %b %d", "%Y %d %b" };
255                         int ret = setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
256                         if (ret == SETTING_RETURN_FAIL)
257                                 value = SETTING_DATE_FORMAT_DD_MM_YYYY;
258
259                         snprintf(datefield_format, MAX_DATETIME_FORMAT_LEN,
260                                  "%s %s", date_format_str[value], time_format);
261 #endif
262
263                         elm_datetime_format_set(ad->data_time->eo_check, datefield_format);
264                 }
265         }
266 }
267
268 /* ***************************************************
269  *
270  *basic func
271  *
272  ***************************************************/
273 static void setting_time_main_datefield_change_cb(void *data, Evas_Object *obj,
274                                       void *event_info)
275 {
276         SETTING_TRACE_BEGIN;
277         /* error check */
278         ret_if(data == NULL);
279         Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
280         SettingTimeUG *ad = list_item->userdata;
281
282         if (EINA_FALSE == ad->is_datefield_selected) {
283                 SETTING_TRACE("Datefield is not selected\n");
284                 return;
285         }
286
287         // If auto update is on, don't anything while the datefield has been updated (i.e., time runs)
288         if (1 == setting_time_check_automatic_time_update_state()) {
289                 SETTING_TRACE("AUTO_TIME ON: no action");
290                 SETTING_TRACE_END;
291                 return;
292         } else {
293                 // otherwise, we apply a new date which has been changed by a user
294         }
295
296         struct tm _tm;
297         elm_datetime_value_get(obj, &_tm);
298
299         SETTING_TRACE("year : %d, month : %d, day : %d, hour : %d, min : %d",
300                       _tm.tm_year, _tm.tm_mon, _tm.tm_mday, _tm.tm_hour, _tm.tm_min);
301         if (2037 < _tm.tm_year) {
302                 setting_create_simple_popup(ad, ad->win_get,
303                                             NULL, _(ERR_BIGGER_THAN_2037));
304                 return;
305         }
306 #if SUPPORT_SCREEN_PROTECTED    /* if not lock the current state, after set the time, the screen will become dimmed */
307         pm_lock_state(LCD_NORMAL, STAY_CUR_STATE, 0);
308 #endif
309         _tm.tm_sec = 0;
310
311         int isdst;
312         if (get_timezone_isdst(&isdst) == SETTING_RETURN_SUCCESS) {
313                 _tm.tm_isdst = isdst;
314         } else {
315                 // error
316                 SETTING_TRACE_ERROR("get_timezone_isdst() failed");
317                 return;
318         }
319
320         /*  local time  -> gmtime */
321         time_t the_time = mktime(&_tm); /* represent local time */
322
323         if ( (time(NULL)/ONE_MINUTE) == (the_time/ONE_MINUTE) )
324         {
325                 SETTING_TRACE("Time is not changed\n");
326                 //current time didn't change
327                 return;
328         }
329
330 #if PROGRESS_POPUP_SHOW
331         // remove popup if created
332         if (ad->pop_progress) {
333                 evas_object_del(ad->pop_progress);
334                 ad->pop_progress = NULL;
335         }
336
337         // create new popup
338         ad->pop_progress =
339                 setting_create_popup_with_progressbar(ad, ad->win_get, "pending_list",
340                                                       NULL, NULL, NULL, 0, TRUE, TRUE);
341 #endif
342
343         // invoke API to change time
344         int ret = sysman_set_datetime(the_time);
345         setting_retm_if(ret == -1, "sysman_set_datetime call failed");
346
347         SETTING_TRACE_END;
348 }
349
350 Eina_Bool __refresh_date_timer(void *data)
351 {
352         //SETTING_TRACE_BEGIN;
353         SettingTimeUG *ad = data;
354         if (ad->data_time) {
355                 time_t ctime = time(NULL);
356                 struct tm ts_ret;
357                 struct tm *ts = localtime_r(&ctime, &ts_ret);
358                 retv_if(!ts, 1);
359
360                 struct tm ui_time;
361                 elm_datetime_value_get(ad->data_time->eo_check, &ui_time);
362                 if ( (ctime/ONE_MINUTE) != (mktime(&ui_time)/ONE_MINUTE) )
363                 {
364                         SETTING_TRACE("To refresh the UI element after 1 minute passed.\t in %s", __FUNCTION__);
365                         elm_datetime_value_set(ad->data_time->eo_check, &ts_ret);
366                 }
367         }
368         return 1;
369 }
370
371 static void __setting_time_main_exp_cb(void *data, Evas_Object *obj,
372                                        void *event_info)
373 {
374         ret_if(NULL == data || NULL == event_info);
375         SETTING_TRACE_BEGIN;
376         SettingTimeUG *ad = (SettingTimeUG *) data;
377         Elm_Object_Item *parentItem = event_info;       /* parent item */
378         Setting_GenGroupItem_Data *data_parentItem = elm_object_item_data_get(parentItem);      /* parent data */
379         Evas_Object *scroller = elm_object_item_widget_get(parentItem);
380
381         Evas_Object *rgd;
382         if (data_parentItem == ad->data_time_fmt) {
383
384                 rgd = elm_radio_add(scroller);
385                 elm_radio_value_set(rgd, -1);
386                 setting_create_Gendial_exp_sub_field(scroller,
387                                                      &(ad->itc_1icon_1text_sub),
388                                                      NULL, NULL, parentItem,
389                                                      SWALLOW_Type_1RADIO, rgd,
390                                                      VCONFKEY_TIME_FORMAT_12,
391                                                      "IDS_COM_BODY_12_HOURS",
392                                                      NULL);
393
394                 setting_create_Gendial_exp_sub_field(scroller,
395                                                      &(ad->itc_1icon_1text_sub),
396                                                      NULL, NULL, parentItem,
397                                                      SWALLOW_Type_1RADIO, rgd,
398                                                      VCONFKEY_TIME_FORMAT_24,
399                                                      "IDS_ST_BODY_24_HOURS",
400                                                      NULL);
401
402                 setting_update_chk_status(rgd,
403                                           data_parentItem->int_slp_setting_binded);
404
405         } else if (data_parentItem == ad->data_date_fmt) {
406                 rgd = elm_radio_add(scroller);
407                 elm_radio_value_set(rgd, -1);
408                 setting_create_Gendial_exp_sub_field(scroller,
409                                                      &(ad->itc_1icon_1text_sub),
410                                                      NULL, NULL, parentItem,
411                                                      SWALLOW_Type_1RADIO, rgd,
412                                                      SETTING_DATE_FORMAT_DD_MM_YYYY,
413                                                      "IDS_ST_BODY_DDMMYYYY_DOT",
414                                                      NULL);
415
416                 setting_create_Gendial_exp_sub_field(scroller,
417                                                      &(ad->itc_1icon_1text_sub),
418                                                      NULL, NULL, parentItem,
419                                                      SWALLOW_Type_1RADIO, rgd,
420                                                      SETTING_DATE_FORMAT_MM_DD_YYYY,
421                                                      "IDS_ST_BODY_MM_DD_YYYY_DOT",
422                                                      NULL);
423
424                 setting_create_Gendial_exp_sub_field(scroller,
425                                                      &(ad->itc_1icon_1text_sub),
426                                                      NULL, NULL, parentItem,
427                                                      SWALLOW_Type_1RADIO, rgd,
428                                                      SETTING_DATE_FORMAT_YYYY_MM_DD,
429                                                      "IDS_COM_BODY_YYYYMMDD",
430                                                      NULL);
431
432                 setting_create_Gendial_exp_sub_field(scroller,
433                                                      &(ad->itc_1icon_1text_sub),
434                                                      NULL, NULL, parentItem,
435                                                      SWALLOW_Type_1RADIO, rgd,
436                                                      SETTING_DATE_FORMAT_YYYY_DD_MM,
437                                                      "IDS_ST_BODY_YYYY_DD_MM_DOT",
438                                                      NULL);
439
440                 setting_update_chk_status(rgd,
441                                           data_parentItem->int_slp_setting_binded);
442
443         } else if (data_parentItem == ad->data_firstday_week_fmt) {
444                 rgd = elm_radio_add(scroller);
445                 elm_radio_value_set(rgd, -1);
446                 setting_create_Gendial_exp_sub_field(scroller,
447                                                      &(ad->itc_1icon_1text_sub),
448                                                      NULL, rgd, parentItem,
449                                                      SWALLOW_Type_1RADIO, rgd,
450                                                      SETTING_WEEKOFDAY_FORMAT_SUNDAY,
451                                                      "IDS_ST_BODY_SUNDAY", NULL);
452
453                 setting_create_Gendial_exp_sub_field(scroller,
454                                                      &(ad->itc_1icon_1text_sub),
455                                                      NULL, rgd, parentItem,
456                                                      SWALLOW_Type_1RADIO, rgd,
457                                                      SETTING_WEEKOFDAY_FORMAT_MONDAY,
458                                                      "IDS_ST_BODY_MONDAY", NULL);
459
460                 setting_update_chk_status(rgd,
461                                           data_parentItem->int_slp_setting_binded);
462         }
463 }
464
465 static int setting_time_main_create(void *cb)
466 {
467         SETTING_TRACE_BEGIN;
468         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
469
470         SettingTimeUG *ad = (SettingTimeUG *) cb;
471
472         char *l_btn = NULL;
473         char *r_btn = NULL;
474         char *title = _("IDS_ST_BODY_DATE_AND_TIME");
475         char *caller = NULL;
476         ad->is_datefield_selected = EINA_FALSE;
477
478         setting_call_back_func l_button_cb = NULL;
479         setting_call_back_func r_button_cb = NULL;
480
481         service_h service = ad->bundle_data;
482
483         service_get_extra_data(service, "caller", &caller);
484         service_get_extra_data(service, "lbutton", &l_btn);
485         if(l_btn)
486                 l_button_cb = setting_time_main_click_softkey_caller_exist_left_cb;
487         service_get_extra_data(service, "title", &title);
488         service_get_extra_data(service, "rbutton", &r_btn);
489         if(r_btn)
490                 r_button_cb = setting_time_main_click_softkey_caller_exist_right_cb;
491
492         Evas_Object *scroller;  /*  scroller is a genlist */
493
494         ad->caller = caller;
495         if (ad->caller) {
496                 char *lbtn_str = (char *)g_strdup(l_btn);
497                 bool same_flag = FALSE;
498                 if (0 == safeStrCmp(l_btn, _("IDS_COM_BODY_BACK"))) {
499                         l_btn = (char *)dgettext("sys_string", "IDS_COM_BODY_BACK");
500                         same_flag = TRUE;
501                 }
502
503                 Evas_Object *controllbar = NULL;
504
505                 scroller = elm_genlist_add(ad->win_main_layout);
506                 elm_object_style_set(scroller, "dialogue");
507                 if(scroller == NULL) {
508                         SETTING_TRACE_ERROR("Cannot set scroller object  as contento of layout");
509                         // free allocated data before return.
510                         FREE(lbtn_str);
511                         return SETTING_DRAW_ERR_FAIL_SCROLLER;
512                 }
513
514                 elm_genlist_clear(scroller);
515                 ad->ly_main =
516                             setting_create_layout_navi_bar(ad->win_main_layout,
517                                                            ad->win_get,
518                                                            title,
519                                                            NULL, NULL, NULL,
520                                                            NULL, NULL, NULL,
521                                                            ad, scroller,
522                                                            &ad->navi_bar,
523                                                            &controllbar);
524
525                 elm_toolbar_item_append(controllbar, IMG_PREVIOUS, l_btn, l_button_cb, ad);
526                 elm_object_item_disabled_set(elm_toolbar_item_append(controllbar, NULL, "", NULL, NULL), EINA_TRUE);
527                 elm_object_item_disabled_set(elm_toolbar_item_append(controllbar, NULL, "", NULL, NULL), EINA_TRUE);
528                 elm_toolbar_item_append(controllbar, IMG_NEXT, r_btn, r_button_cb, ad);
529
530                 if (same_flag) {
531                         setting_time_main_controlbar_lbtn_label_set(controllbar,
532                                                                     lbtn_str);
533                 }
534                 if (lbtn_str) {
535                         G_FREE(lbtn_str);
536                 }
537
538         } else {
539                 l_btn = _("IDS_COM_BODY_BACK");
540                 title = _("IDS_ST_BODY_DATE_AND_TIME");
541                 ad->ly_main =
542                     setting_create_layout_navi_bar_genlist(ad->win_main_layout,
543                                                            ad->win_get, title,
544                                                            l_btn, NULL,
545                                                            setting_time_main_click_softkey_left_cb,
546                                                            NULL, ad, &scroller,
547                                                            &ad->navi_bar);
548         }
549         ad->scrl_main = scroller;
550
551         int value;
552         int err;
553         int ret = 0;
554         Elm_Object_Item *item;
555
556         item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
557                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
558         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
559         setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, &value,
560                                  &err);
561         bool auto_flag = value;
562
563         /*  UI automatic */
564         if (!isEmulBin()) {
565                 ad->data_auto =
566                     setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon),
567                                                      setting_time_main_mouse_up_Gendial_list_cb,
568                                                      ad, SWALLOW_Type_1TOGGLE, NULL,
569                                                      NULL, value,
570                                                      "IDS_ST_BODY_AUTOMATIC_UPDATE", NULL,
571                                                      setting_time_main_chk_btn_cb);
572                 if (ad->data_auto) {
573                         ad->data_auto->userdata = ad;
574                 } else {
575                         SETTING_TRACE_ERROR("ad->data_auto is NULL");
576                 }
577
578                 setting_create_Gendial_field_def(scroller, &itc_multiline_text, NULL,
579                                                  ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
580                                                  NULL, NULL, 0, SETTING_TIME_AUTO_UPDATE_DESC, NULL,
581                                                  NULL);
582                 elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL),
583                                                  ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
584         }
585
586         setting_set_i18n("worldclock", SETTING_TIME_SHARE_LOCAL_PATH);
587
588         char time_zone_sub_str[CITY_BUF_SIZE + GMT_BUF_SIZE + 3] = { 0, };
589         char *pa_timezone = NULL;
590         char *pa_city = NULL;
591
592         pa_city = vconf_get_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT);   // IDS_WCL_BODY_CITYNAME_SEOUL
593         pa_timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_INT);             // "Asia/Seoul"
594
595         if ((pa_timezone != NULL) && (_(pa_city) != NULL)) {
596
597                 // don't use hard coded value
598                 // get value from current timezone
599
600                 char str_buf[GMT_BUF_SIZE] = {0, };
601                 get_gmt_offset(str_buf, GMT_BUF_SIZE);
602
603                 char* timezone_str = get_timezone_str();
604
605                 bool ret = get_city_name(timezone_str);
606                 if (ret) {
607                         SETTING_TRACE(">>>>>> RESULT : %s", get_city_name_result());
608                 }
609                 char* cityname_id = get_city_name_result();
610
611                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT %s", _(cityname_id), _(str_buf));
612                 FREE(pa_city);
613                 FREE(pa_timezone);
614                 retv_if(ret < 0, 0);
615         } else {
616                 // default code
617                 ret = snprintf(time_zone_sub_str, CITY_BUF_SIZE + GMT_BUF_SIZE + 2, "%s, GMT +09", _("IDS_WCL_BODY_CITYNAME_SEOUL"));
618                 retv_if(ret < 0, 0);
619         }
620
621         /*  UI create time zone */
622         ad->data_tz =
623             setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2),
624                                              setting_time_main_mouse_up_Gendial_list_cb,
625                                              ad, SWALLOW_Type_INVALID, NULL,
626                                              NULL, 0, "IDS_ST_BODY_TIME_ZONE",
627                                              time_zone_sub_str, NULL);
628         if (ad->data_tz) {
629                 ad->data_tz->userdata = ad;
630         } else {
631                 SETTING_TRACE_ERROR("ad->data_tz is NULL");
632         }
633
634         /* create DATE_AND_TIME */
635         /* DATE_AND_TIME */
636         ret =
637             setting_get_int_slp_key(INT_SLP_SETTING_REGIONFORMAT_TIME1224,
638                                     &value, &err);
639         if (ret == SETTING_RETURN_FAIL) {
640                 value = VCONFKEY_TIME_FORMAT_12;
641         }
642         bool is_12hours = (value == VCONFKEY_TIME_FORMAT_12 ? TRUE : FALSE);
643         char *date_format_str[] = { "%d %b %Y", "%b %d %Y", "%Y %b %d", "%Y %d %b" };
644         ret =
645             setting_get_int_slp_key(INT_SLP_SETTING_DATE_FORMAT, &value, &err);
646         if (ret == SETTING_RETURN_FAIL)
647                 value = SETTING_DATE_FORMAT_DD_MM_YYYY;
648
649         /*  UI format string */
650         ad->data_time =
651             setting_create_Gendial_field_def(scroller, &(ad->itc_layout),
652                                              setting_time_main_mouse_up_Gendial_list_cb,
653                                              ad, SWALLOW_Type_LAYOUT_DATEFIELD,
654                                              NULL, NULL, is_12hours,
655                                              "IDS_ST_BODY_DATE_AND_TIME",
656                                              date_format_str[value],
657                                              setting_time_main_datefield_change_cb);
658         if (ad->data_time) {
659                 ad->data_time->userdata = ad;
660                 ad->data_time->isItemDisableFlag = auto_flag;
661         } else {
662                 SETTING_TRACE_ERROR("ad->data_time is NULL");
663         }
664         item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
665                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
666         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
667
668         /*  UI create "Time format" */
669         setting_enable_expandable_genlist(scroller, ad,
670                                           __setting_time_main_exp_cb, NULL);
671
672         char* pa_time_format = get_pa_time_format_str();
673         ad->data_time_fmt = setting_create_Gendial_exp_parent_field(scroller,
674                                                     &(ad->itc_2text_3_parent),
675                                                     setting_time_main_mouse_up_Gendial_list_cb,
676                                                     ad, SWALLOW_Type_INVALID,
677                                                     "IDS_ST_BODY_TIME_FORMAT",
678                                                     pa_time_format);
679         if (ad->data_time_fmt) {
680                 ad->data_time_fmt->int_slp_setting_binded =
681                         INT_SLP_SETTING_REGIONFORMAT_TIME1224;
682         } else {
683                 SETTING_TRACE_ERROR("ad->data_time_fmt is NULL");
684         }
685         G_FREE(pa_time_format);
686
687 #if APPLIED_DATATIME_DATA_FORMAT
688         char* pa_date_format = get_pa_date_format_str();
689         ad->data_date_fmt = setting_create_Gendial_exp_parent_field(scroller,
690                                                     &(ad->itc_2text_3_parent),
691                                                     setting_time_main_mouse_up_Gendial_list_cb,
692                                                     ad, SWALLOW_Type_INVALID,
693                                                     "IDS_ST_BODY_DATE_FORMAT",
694                                                     pa_time_format);
695         if (ad->data_date_fmt) {
696                 ad->data_date_fmt->int_slp_setting_binded =
697                         INT_SLP_SETTING_DATE_FORMAT;
698         } else {
699                 SETTING_TRACE_ERROR("ad->data_date_fmt is NULL");
700         }
701         G_FREE(pa_date_format);
702 #endif
703
704 #if APPLIED_DATATIME_FIRSTDAY_WEEK
705     char* pa_week = get_pa_week_format_str();
706         ad->data_firstday_week_fmt =
707             setting_create_Gendial_exp_parent_field(scroller,
708                                                     &(ad->itc_2text_3_parent),
709                                                     setting_time_main_mouse_up_Gendial_list_cb,
710                                                     ad, SWALLOW_Type_INVALID,
711                                                     "IDS_CLD_BODY_FIRST_DAY_OF_WEEK",
712                                                     pa_week);
713         if (ad->data_firstday_week_fmt) {
714                 ad->data_firstday_week_fmt->int_slp_setting_binded =
715                         INT_SLP_SETTING_WEEK_FORMAT;
716         } else {
717                 SETTING_TRACE_ERROR("ad->data_firstday_week_fmt is NULL");
718         }
719     G_FREE(pa_week);
720 #endif
721
722         item = elm_genlist_item_append(scroller, &itc_bottom_seperator, NULL, NULL,
723                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
724         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
725
726         if (auto_flag)
727         {
728                 if (ad->data_tz) {
729                         setting_disable_genlist_item(ad->data_tz->item);
730                 }
731                 if (ad->data_time) {
732                         setting_disable_genlist_item(ad->data_time->item);
733                 }
734         }
735
736         setting_view_time_main.is_create = 1;
737
738 #if TIME_CHANGED_HEYNOTY_CALLBACK
739         /* ---------------------------------------------------------------- */
740         /*  heynoti registration */
741         /* ---------------------------------------------------------------- */
742         ad->noti_fd = heynoti_init();
743
744         if (ad->noti_fd == -1) {
745                 SETTING_TRACE("heynoti_init FAIL");
746                 return SETTING_RETURN_FAIL;
747         } else {
748                 SETTING_TRACE("heynoti_init OK");
749         }
750
751         if (-1 == heynoti_subscribe(ad->noti_fd, SETTING_TIME_CHANGED, time_changed_callback, (void *)ad)) {
752                 SETTING_TRACE("heynoti_subscribe FAIL");
753         } else {
754                 SETTING_TRACE("heynoti_subscribe OK");
755         }
756
757         if (-1 == heynoti_attach_handler(ad->noti_fd)) {
758                 SETTING_TRACE("heynoti_attach_handler FAIL");
759         } else {
760                 SETTING_TRACE("heynoti_attach_handler OK");
761         }
762 #endif
763
764         /*  register vconf key to get event callback for converting 12/24H */
765         ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
766                                      setting_time_main_int_vconf_change_cb, ad);
767         setting_retvm_if(ret < 0, ret, "%s notifications Failed(%d)",
768                          (char *)VCONFKEY_REGIONFORMAT_TIME1224, ret);
769
770         /*  register vconf key to get event callback for date format */
771         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DATE_FORMAT_INT,
772                                      setting_time_main_int_vconf_change_cb, ad);
773         setting_retvm_if(ret < 0, ret, "%s notifications Failed(%d)",
774                          (char *)VCONFKEY_SETAPPL_DATE_FORMAT_INT, ret);
775
776         /* to avoid update time-diff, every per 3s to update. */
777         ad->update_timer = ecore_timer_add(3, (Ecore_Task_Cb) __refresh_date_timer, ad);
778
779         return SETTING_RETURN_SUCCESS;
780 }
781
782 static int setting_time_main_destroy(void *cb)
783 {
784         SETTING_TRACE_BEGIN;
785         /* error check */
786         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
787
788         SettingTimeUG *ad = (SettingTimeUG *) cb;
789
790 #if TIME_CHANGED_HEYNOTY_CALLBACK
791         /* Closing heynoti */
792         if (ad->noti_fd != -1)//first need to check the fd validation
793         {
794                 heynoti_unsubscribe(ad->noti_fd, SETTING_TIME_CHANGED, time_changed_callback);
795                 //heynoti_detach_handler() will be done in heynoti_close().
796                 heynoti_close(ad->noti_fd);
797                 ad->noti_fd = -1;
798         }
799 #endif
800         if (ad->update_timer) {
801                 ecore_timer_del(ad->update_timer);
802                 ad->update_timer = NULL;
803         }
804
805 #if PROGRESS_POPUP_SHOW
806         if (ad->pop_progress) {
807                 evas_object_del(ad->pop_progress);
808                 ad->pop_progress = NULL;
809         }
810 #endif
811
812         if (ad->update_timezone_idler) {
813                 ecore_idler_del(ad->update_timezone_idler);
814                 ad->update_timezone_idler = NULL;
815         }
816         if (ad->refresh_time_idler) {
817                 ecore_idler_del(ad->refresh_time_idler);
818                 ad->refresh_time_idler = NULL;
819         }
820         vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
821                                  setting_time_main_int_vconf_change_cb);
822         vconf_ignore_key_changed(VCONFKEY_SETAPPL_DATE_FORMAT_INT,
823                                  setting_time_main_int_vconf_change_cb);
824
825         if (ad->ly_main != NULL) {
826                 evas_object_del(ad->ly_main);
827                 setting_view_time_main.is_create = 0;
828         }
829
830         return SETTING_RETURN_SUCCESS;
831 }
832
833 static int setting_time_main_update(void *cb)
834 {
835         SETTING_TRACE_BEGIN;
836         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
837
838         SettingTimeUG *ad = (SettingTimeUG *) cb;
839
840         if (ad->ly_main != NULL) {
841                 evas_object_show(ad->ly_main);
842                 // update timezone
843                 if (ad->update_timezone_idler) {
844                         ecore_idler_del(ad->update_timezone_idler);
845                         ad->update_timezone_idler = NULL;
846                 }
847                 ad->update_timezone_idler =
848                     ecore_idler_add((Ecore_Task_Cb) __update_timezone_idler, ad);
849                 // update time
850                 if (ad->refresh_time_idler) {
851                         ecore_idler_del(ad->refresh_time_idler);
852                         ad->refresh_time_idler = NULL;
853                 }
854                 ad->refresh_time_idler = ecore_idler_add(setting_update_datefield, ad);
855         }
856         return SETTING_RETURN_SUCCESS;
857 }
858
859 static int setting_time_main_cleanup(void *cb)
860 {
861         SETTING_TRACE_BEGIN;
862         return SETTING_RETURN_SUCCESS;
863 }
864
865
866 /* ***************************************************
867  **
868  **general func
869  **
870  ****************************************************/
871
872 int setting_time_check_automatic_time_update_state()
873 {
874         SETTING_TRACE_BEGIN;
875         int bvalue = 0;
876         int ret = 0;
877         int err = 0;
878
879         ret =
880             setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
881                                      &bvalue, &err);
882
883         return bvalue;
884
885 }
886
887 static int __setting_set_city_tzone(const char* pTZPath)
888 {
889         // let's get city & timezone string from pTZPath
890         // 1. city name
891         char szTimezone[GMT_BUF_SIZE] = {0,};
892         char* pStr = strdup(pTZPath);
893
894         // 2. timezone string +/-<n> ex. +9, -1
895         get_gmt_offset(szTimezone, GMT_BUF_SIZE);
896
897         int ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_INT, szTimezone);
898         if (ret == -1) {
899                 FREE(pStr);
900                 SETTING_TRACE("set vconf failed");
901                 return FALSE;
902         }
903
904         // set timezone_id
905         /** @todo replace with vconf ID */
906         ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_ID, pStr);
907         FREE(pStr);
908
909         return TRUE;
910 }
911
912 static void
913 setting_time_main_launch_worldclock_result_ug_cb(ui_gadget_h ug,
914                                                  service_h result, void *priv)
915 {
916         SETTING_TRACE_BEGIN;
917         /* error check */
918         retm_if(priv == NULL, "Data parameter is NULL");
919
920         SettingTimeUG *ad = (SettingTimeUG *) priv;
921
922         char *city = NULL;
923         char *tzpath = NULL;
924         service_get_extra_data(result, "city", &city);
925         service_get_extra_data(result, "tzpath", &tzpath);
926
927         if (!tzpath) {
928                 SETTING_TRACE("tzpath from worldclock UG is null.");
929                 return;
930         } else {
931                 SETTING_TRACE("tzpath : %s", tzpath );
932         }
933
934         /* --------------------------------------------------------------------- */
935         char tz_path[MAX_COMMON_BUFFER_LEN / 4 + 1];
936         safeCopyStr(tz_path, SETTING_TIME_ZONEINFO_PATH, MAX_COMMON_BUFFER_LEN / 4);
937         g_strlcat(tz_path, tzpath, sizeof(tz_path));
938         SETTING_TRACE("full tz_path:%s", tz_path);
939
940         int ret = sysman_set_timezone(tz_path);
941         if (ret < 0) {
942                 SETTING_TRACE("tzpath is not valid.");
943                 return;
944         } else
945                 SETTING_TRACE("sysman_set_timezone - successful : %s \n", tz_path);
946
947         ret = vconf_set_str(VCONFKEY_SETAPPL_CITYNAME_INDEX_INT, city);
948         setting_retm_if(ret != 0, "set vconf failed");
949
950         // parse city and GMT offset from tzpath and system time property
951         // set the strings in vconf which will be used while updating display of timezone
952         if (!__setting_set_city_tzone(tzpath)) {
953                 SETTING_TRACE("__setting_set_city_tzone ERROR")
954                 return;
955         }
956
957         // update the display for timezone
958         setting_update_timezone(ad);
959         heynoti_publish(SETTING_TIME_CHANGED);
960         SETTING_TRACE_END;
961 }
962
963 void setting_time_main_launch_worldclock_destroy_ug_cb(ui_gadget_h ug,
964                                                        void *priv)
965 {
966         SETTING_TRACE_BEGIN;
967         /* if(ug) ug_destroy(ug); */
968         /* restore the '<-' button on the navigate bar */
969         ret_if(!priv);
970         SettingTimeUG *ad = (SettingTimeUG *) priv;
971         if (ug) {
972                 ug_destroy(ug);
973                 ad->ug_loading = NULL;
974         }
975         Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
976         ret_if(!navi_it);
977         Evas_Object *back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
978
979         if (back_btn != NULL) {
980                 elm_object_style_set(back_btn, NAVI_BACK_BUTTON_STYLE); /* take into effect */
981         }
982
983 }
984
985 void setting_time_main_launch_worldclock_layout_ug_cb(ui_gadget_h ug,
986                                                       enum ug_mode mode,
987                                                       void *priv)
988 {
989         SETTING_TRACE_BEGIN;
990         SettingTimeUG *ad = (SettingTimeUG *) priv;
991         Evas_Object *base;
992
993         if (!priv)
994                 return;
995
996         base = (Evas_Object *) ug_get_layout(ug);
997         if (!base)
998                 return;
999
1000         switch (mode) {
1001         case UG_MODE_FULLVIEW:
1002                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
1003                                                  EVAS_HINT_EXPAND);
1004                 elm_win_resize_object_add(ad->win_get, base);
1005                 evas_object_show(base);
1006                 break;
1007         default:
1008                 break;
1009         }
1010         SETTING_TRACE_END;
1011 }
1012
1013
1014 void setting_time_main_launch_worldclock_sg(void *data)
1015 {
1016         SETTING_TRACE_BEGIN;
1017         /* error check */
1018         retm_if(data == NULL, "Data parameter is NULL");
1019
1020         SettingTimeUG *ad = (SettingTimeUG *) data;
1021
1022         struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
1023         setting_retm_if(!cbs, "calloc failed");
1024         cbs->layout_cb = setting_time_main_launch_worldclock_layout_ug_cb;
1025         cbs->result_cb = setting_time_main_launch_worldclock_result_ug_cb;
1026         cbs->destroy_cb = setting_time_main_launch_worldclock_destroy_ug_cb;
1027         cbs->priv = (void *)ad;
1028
1029         SETTING_TRACE("to load ug[%s]", "worldclock-efl");
1030         ad->ug_loading =
1031             ug_create(ad->ug, "worldclock-efl", UG_MODE_FULLVIEW, NULL, cbs);
1032         if (NULL == ad->ug_loading) {   /* error handling */
1033         }
1034
1035         FREE(cbs);
1036         return;
1037 }
1038
1039
1040 Eina_Bool setting_update_datefield(void *cb)
1041 {
1042         SETTING_TRACE_BEGIN;
1043         retvm_if(cb == NULL, EINA_FALSE, "Data parameter is NULL");
1044         SettingTimeUG *ad = (SettingTimeUG *) cb;
1045
1046         //__refresh_date_timer(ad);
1047         if (ad->data_time) {
1048                 time_t ctime = time(NULL);
1049                 struct tm ts_ret;
1050                 struct tm *ts = localtime_r(&ctime, &ts_ret);
1051                 if (ts) elm_datetime_value_set(ad->data_time->eo_check, &ts_ret);
1052         }
1053         ad->refresh_time_idler = NULL;
1054         return 0;
1055 }
1056
1057 /* ***************************************************
1058  **
1059  **call back func
1060  **
1061  ****************************************************/
1062
1063 void
1064 setting_time_main_click_softkey_left_cb(void *data, Evas_Object *obj,
1065                                         void *event_info)
1066 {
1067         SETTING_TRACE_BEGIN;
1068         retm_if(data == NULL, "Data parameter is NULL");
1069
1070         SettingTimeUG *ad = (SettingTimeUG *) data;
1071
1072         /* Send destroy request */
1073         ug_destroy_me(ad->ug);
1074 }
1075
1076 /* ***************************************************
1077  **
1078  **call back func
1079  **
1080  ****************************************************/
1081
1082 void
1083 setting_time_main_click_softkey_caller_exist_left_cb(void *data,
1084                                                      Evas_Object *obj,
1085                                                      void *event_info)
1086 {
1087         SETTING_TRACE_BEGIN;
1088         /* error check */
1089         retm_if(data == NULL, "Data parameter is NULL");
1090
1091         SettingTimeUG *ad = (SettingTimeUG *) data;
1092
1093         /*  Create Bundle and send message */
1094         service_h svc;
1095         if (service_create(&svc))
1096                 return;
1097
1098         service_add_extra_data(svc, "result", "lbutton_click");
1099         ug_send_result(ad->ug, svc);
1100
1101         service_destroy(svc);
1102
1103         /* Send destroy request */
1104         ug_destroy_me(ad->ug);
1105 }
1106
1107 void
1108 setting_time_main_click_softkey_caller_exist_right_cb(void *data,
1109                                                       Evas_Object *obj,
1110                                                       void *event_info)
1111 {
1112         SETTING_TRACE_BEGIN;
1113         /* error check */
1114         retm_if(data == NULL, "Data parameter is NULL");
1115
1116         SettingTimeUG *ad = (SettingTimeUG *) data;
1117
1118         /*  Create Bundle and send message */
1119         service_h svc;
1120         if (service_create(&svc))
1121                 return;
1122
1123         service_add_extra_data(svc, "result", "rbutton_click");
1124         ug_send_result(ad->ug, svc);
1125
1126         service_destroy(svc);
1127
1128         /* Send destroy request */
1129         ug_destroy_me(ad->ug);
1130 }
1131
1132 static void setting_time_reboot_resp_cb(void *data, Evas_Object *obj,
1133                                         void *event_info)
1134 {
1135         SETTING_TRACE_BEGIN;
1136         int response_type = btn_type(obj);
1137         if (POPUP_RESPONSE_OK == response_type) {
1138                 setting_time_main_btn_update_ok_cb(data);
1139         } else if (POPUP_RESPONSE_CANCEL == response_type) {
1140                 setting_time_main_btn_update_cancel_cb(data);
1141         }
1142
1143         SettingTimeUG *ad = data;
1144         if (ad->pop)
1145         {
1146                 evas_object_del(ad->pop);
1147                 ad->pop = NULL;
1148         }
1149 }
1150
1151 static void
1152 setting_time_main_chk_btn_cb(void *data, Evas_Object *obj, void *event_info)
1153 {
1154         SETTING_TRACE_BEGIN;
1155         /* error check */
1156         retm_if(data == NULL, "Data parameter is NULL");
1157         SettingTimeUG *ad = NULL;
1158         Setting_GenGroupItem_Data *list_item =
1159             (Setting_GenGroupItem_Data *) data;
1160         ad = list_item->userdata;
1161         list_item->chk_status = elm_check_state_get(obj);       /*  for genlist update status */
1162         if (ad->data_auto)
1163                 ad->chk_auto = ad->data_auto->eo_check;
1164         if (ad->data_dst)
1165                 ad->chk_dst = ad->data_dst->eo_check;
1166
1167         if (ad->data_time) {
1168                 elm_object_focus_set(ad->data_time->eo_check, EINA_FALSE);
1169         }
1170
1171         int err;
1172         if (obj == ad->chk_auto) {
1173                 int bvalue;
1174                 setting_get_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1175                                          &bvalue, &err);
1176                 if (bvalue) {
1177                         (void) setting_set_bool_slp_key (BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE, SETTING_ON_OFF_BTN_OFF, &err);
1178                         elm_check_state_set(ad->chk_auto, 0);
1179
1180                         if (ad->data_tz) {
1181                                 setting_enable_genlist_item(ad->data_tz->item);
1182                         }
1183
1184                         if (ad->data_time) {
1185                                 ad->data_time->isItemDisableFlag = FALSE;
1186                                 setting_enable_evas_object(ad->data_time->eo_check);
1187                                 setting_enable_genlist_item(ad->data_time->item);
1188                         }
1189
1190                 } else {
1191                         ad->pop =
1192                             setting_create_popup_with_btn(ad, ad->win_get, NULL,
1193                                                  _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"),
1194                                                  setting_time_reboot_resp_cb,
1195                                                  0, 2,
1196                                                  dgettext("sys_string",
1197                                                        "IDS_COM_SK_OK"),
1198                                                  _("IDS_COM_SK_CANCEL"));
1199                 }
1200         }
1201 }
1202
1203
1204 static void setting_time_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
1205                                            void *event_info)
1206 {
1207         SETTING_TRACE_BEGIN;
1208         /* error check */
1209         setting_retm_if(data == NULL, "Data parameter is NULL");
1210
1211         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
1212         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
1213         elm_genlist_item_selected_set(item, 0);
1214         Setting_GenGroupItem_Data *list_item =
1215             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
1216
1217         SettingTimeUG *ad = (SettingTimeUG *) data;
1218         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
1219
1220         if (ad->data_time && 0 != safeStrCmp("IDS_ST_BODY_DATE_AND_TIME", list_item->keyStr)) {
1221                 elm_object_focus_set(ad->data_time->eo_check, EINA_FALSE);
1222         }
1223
1224         if (!safeStrCmp("IDS_ST_BODY_TIME_ZONE", list_item->keyStr)) {
1225                 ad->is_datefield_selected = EINA_FALSE;
1226                 if (1 == setting_time_check_automatic_time_update_state()) {
1227                         setting_create_simple_popup(ad, ad->win_get,
1228                                                     NULL, _(AUTO_TIME_UPDATE_ON));
1229                 } else {
1230                         setting_time_main_launch_worldclock_sg(ad);
1231                 }
1232
1233         } else if (!safeStrCmp("IDS_ST_BODY_DATE_AND_TIME", list_item->keyStr)) {
1234                 ad->is_datefield_selected = EINA_TRUE;
1235                 if (1 == setting_time_check_automatic_time_update_state()) {
1236                         setting_create_simple_popup(ad, ad->win_get,
1237                                                     NULL, _(AUTO_TIME_UPDATE_ON));
1238                 } else {
1239                         /* setting_view_change(&setting_view_time_main, &setting_view_time_time, ad); */
1240                 }
1241         } else if (!safeStrCmp("IDS_ST_BODY_AUTOMATIC_UPDATE", list_item->keyStr)) {
1242                 ad->is_datefield_selected = EINA_FALSE;
1243                 int old_status = elm_check_state_get(list_item->eo_check);
1244                 /* new status */
1245                 list_item->chk_status = !old_status;
1246                 elm_check_state_set(list_item->eo_check, list_item->chk_status);
1247                 int err = 0;
1248                 if (!list_item->chk_status) {
1249                         (void)
1250                             setting_set_bool_slp_key
1251                             (BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1252                              SETTING_ON_OFF_BTN_OFF, &err);
1253
1254                         if (ad->data_tz) {
1255                                 setting_enable_genlist_item(ad->data_tz->item);
1256                         }
1257
1258                         if (ad->data_time) {
1259                                 ad->data_time->isItemDisableFlag = FALSE;
1260                                 setting_enable_evas_object(ad->data_time->eo_check);
1261                                 setting_enable_genlist_item(ad->data_time->item);
1262                         }
1263
1264                 } else {
1265                         ad->pop =
1266                             setting_create_popup_with_btn(ad, ad->win_get, NULL,
1267                                                  _("IDS_ST_POP_RESTART_PHONE_TO_USE_AUTOMATIC_UPDATE_Q"),
1268                                                  setting_time_reboot_resp_cb,
1269                                                  0, 2,
1270                                                  dgettext("sys_string", "IDS_COM_SK_OK"),
1271                                                  _("IDS_COM_SK_CANCEL"));
1272                 }
1273
1274         } else if (!safeStrCmp("IDS_ST_BODY_TIME_FORMAT", list_item->keyStr)
1275                    || !safeStrCmp("IDS_ST_BODY_DATE_FORMAT", list_item->keyStr)
1276                    || !safeStrCmp("IDS_CLD_BODY_FIRST_DAY_OF_WEEK", list_item->keyStr)) {
1277                 ad->is_datefield_selected = EINA_FALSE;
1278                 bool status = !elm_genlist_item_expanded_get(item);
1279                 elm_genlist_item_expanded_set(item, status);
1280         }
1281 }
1282
1283
1284 void setting_time_main_btn_update_ok_cb(void *cb)
1285 {
1286         SETTING_TRACE_BEGIN;
1287         SettingTimeUG *ad = (SettingTimeUG *) cb;
1288         int err;                /* error check */
1289         setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1290                                  SETTING_ON_OFF_BTN_ON, &err);
1291         elm_check_state_set(ad->data_auto->eo_check, 1);
1292         ad->data_auto->chk_status = 1;
1293
1294         sysman_request_reboot();
1295
1296         /*  We'd better check return value from sysman_request_reboot() function. */
1297         /*  It will return 0 on success or -1 if failed. */
1298 }
1299
1300
1301 void setting_time_main_btn_update_cancel_cb(void *cb)
1302 {
1303         SETTING_TRACE_BEGIN;
1304         SettingTimeUG *ad = (SettingTimeUG *) cb;
1305
1306         int err;                /* error check */
1307
1308         retm_if(cb == NULL, "Data parameter is NULL");
1309         setting_set_bool_slp_key(BOOL_SLP_SETTING_AUTOMATIC_TIME_UPDATE,
1310                                  SETTING_ON_OFF_BTN_OFF, &err);
1311         elm_check_state_set(ad->data_auto->eo_check, 0);
1312         ad->data_auto->chk_status = 0;
1313
1314 }
1315
1316
1317 static UChar *uastrcpy(const char *chars)
1318 {
1319         int len = 0;
1320         UChar *str = NULL;
1321         len = safeStrLen(chars);
1322         str = (UChar *) malloc(sizeof(UChar) *(len + 1));
1323         if (!str)
1324                 return NULL;
1325         u_uastrcpy(str, chars);
1326         return str;
1327 }
1328
1329
1330 static int get_timezone_isdst(int* isdst)
1331 {
1332         SETTING_TRACE_BEGIN;
1333     struct tm *ts;
1334     time_t ctime;
1335
1336     enum { BUFFERSIZE = 1024 };
1337     char buf[BUFFERSIZE];
1338     ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
1339
1340     if (len != -1) {
1341         buf[len] = '\0';
1342     }
1343     else {
1344         /* handle error condition */
1345     }
1346
1347     ctime = time(NULL);
1348     ts = localtime(&ctime);
1349         if ( ! ts ) {
1350                 return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
1351         }
1352
1353     SETTING_TRACE(" == tz_path = %s", buf);
1354     SETTING_TRACE(" == isdst = %d\n", ts->tm_isdst);
1355         *isdst = ts->tm_isdst;
1356
1357         return SETTING_RETURN_SUCCESS;
1358 }
1359
1360
1361 static void ICU_set_timezone(const char *timezone)
1362 {
1363         SETTING_TRACE("ICU_set_timezone = %s ", timezone);
1364         UErrorCode ec = U_ZERO_ERROR;
1365         UChar *str = uastrcpy(timezone);
1366
1367         ucal_setDefaultTimeZone(str, &ec);
1368         if (U_SUCCESS(ec)) {
1369                 SETTING_TRACE("ucal_setDefaultTimeZone() SUCCESS ");
1370         } else {
1371                 SETTING_TRACE("ucal_setDefaultTimeZone() FAILED : %s ",
1372                               u_errorName(ec));
1373         }
1374         FREE(str);
1375 }
1376
1377
1378 static void setting_time_main_controlbar_lbtn_label_set(
1379                                                         Evas_Object *controlbar,
1380                                                         char *label)
1381 {
1382         SETTING_TRACE_BEGIN;
1383         setting_retm_if(controlbar == NULL, "controlbar parameter is NULL");
1384         setting_retm_if(label == NULL, "label parameter is NULL");
1385
1386         Evas_Object *eo_lbtn = NULL;
1387         Elm_Object_Item *first_item = NULL;
1388
1389         first_item = elm_toolbar_first_item_get(controlbar);
1390         setting_retm_if(first_item == NULL, "get first_item failed");
1391
1392         eo_lbtn = elm_object_item_part_content_get(first_item, "object");
1393         setting_retm_if(eo_lbtn == NULL, "get eo_lbtn failed");
1394
1395         elm_object_text_set(eo_lbtn, label);
1396 }
1397
1398
1399 /**
1400  * ex) timezone : Asia/Seoul --> returns "+09"
1401  *
1402  * char outstr2[4];
1403  */
1404 static void get_gmt_offset(char *str_buf, int size)
1405 {
1406         SETTING_TRACE(" before GMT processing : %s", str_buf);
1407         // timezone string +/-<n> ex. +9, -1
1408         time_t t = time(0);     // get unix time. sec.
1409
1410         struct tm* data;
1411         data = localtime(&t);           // save time as structure.
1412         setting_retm_if(!data, "data is NULL");
1413         data->tm_isdst = 0;                     // summer time, not applied.
1414         time_t a = mktime(data);
1415
1416         data = gmtime(&a);
1417         data->tm_isdst = 0;                     // summer time, not applied.
1418         time_t b = mktime(data);
1419
1420         int gmtoffset_hour = (a-b)/3600;        // result : hour.
1421         int gmtoffset_min = ((a-b)%3600)/60;    // result : min.
1422         if(gmtoffset_min != 0) {
1423                 gmtoffset_min = 30;
1424         }
1425
1426         snprintf(str_buf, size, "%+d:%02u", gmtoffset_hour, gmtoffset_min);
1427         SETTING_TRACE("szTimezone is of a valid format: GMT: %s", str_buf);
1428 }
1429
1430
1431 // automatic
1432 static char* get_timezone_str()
1433 {
1434     SETTING_TRACE_BEGIN;
1435
1436     enum { BUFFERSIZE = 1024 };
1437     char buf[BUFFERSIZE];
1438     ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
1439
1440     if (len != -1) {
1441         buf[len] = '\0';
1442     }
1443     else {
1444         /* handle error condition */
1445     }
1446     return g_strdup(buf+20);            //Asia/Seoul
1447 }
1448
1449 static char* get_city_name_result()
1450 {
1451         return s_result;
1452 }
1453
1454
1455 // in_str = "Asia/Seoul"
1456 static bool get_city_name(char* tzname)
1457 {
1458         sqlite3 *pSQLite3 = NULL;
1459         char    *szErrMsg = NULL;
1460
1461         int rst = sqlite3_open( "/opt/dbspace/.worldclock.db", &pSQLite3);
1462         if ( rst )
1463         {
1464                 printf( "Can't open database: %s\n", sqlite3_errmsg( pSQLite3 ));
1465                 sqlite3_close( pSQLite3 );
1466                 pSQLite3 = NULL;
1467                 return false;
1468         }
1469         else
1470         {
1471                 printf("Database opened!!\n");
1472                 char query_str[256];
1473                 snprintf(query_str, 256, "SELECT city FROM city_table where tz_path=\"%s\"", tzname);
1474                 printf("%s \n", query_str);
1475                 rst = sqlite3_exec(pSQLite3, query_str, query_callback, 0, &szErrMsg);
1476         }
1477
1478         //객체해제
1479         sqlite3_free( szErrMsg );
1480         sqlite3_close( pSQLite3 );
1481         printf("Database close!!\n");
1482         return true;
1483 }
1484
1485 static int query_callback(void *NotUsed, int argc, char **argv, char **azColName)
1486 {
1487     int i = 0;
1488     printf("%s\n", argv[i] ? argv[i] : "NULL");
1489         s_result = g_strdup(argv[i] ? argv[i] : "NULL");
1490     return 0;
1491 };
1492
1493
1494 #if 0                   /* example */
1495 int main(int argc, char* argv[])
1496 {
1497         g_type_init ();
1498         int ret;
1499         // exporting - current status
1500         if ( (argc == 2) && (0 == strcmp(argv[1], "export"))) {
1501                         setting_export();
1502         }
1503         else if ( (argc == 2) && (0 == strcmp(argv[1], "timezone_init"))) {
1504
1505                 //////////////////////////////////////////////////////////////////////////
1506                 char* tz_path_zone_city = get_timezone_str();
1507                 bool ret = get_city_name(tz_path_zone_city);
1508                 if (ret) {
1509                         printf(">>>>>> RESULT : %s \n", get_city_name_result());
1510                 }
1511                 //////////////////////////////////////////////////////////////////////////
1512         }
1513         else {
1514                 // cfg create
1515                 // TRUE or FALSE
1516                 ret = setting_cfg_create();
1517         }
1518         return 0;
1519 }
1520 #endif
1521
1522
1523