clock: do not release global handle
[apps/core/preloaded/indicator-win.git] / src / modules / clock / clock.c
1 /*
2  *  Indicator
3  *
4  * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <vconf.h>
24 //#include <Ecore_X.h>
25 #include <utils_i18n.h>
26 #include <system_settings.h>
27
28 #include "common.h"
29 #include "indicator.h"
30 #include "main.h"
31 #include "indicator_gui.h"
32 #include "icon.h"
33 #include "util.h"
34 #include "modules.h"
35 #include "box.h"
36 #include "log.h"
37
38 #define SYSTEM_RESUME           "system_wakeup"
39
40 #define TIME_FONT_SIZE_24               ELM_SCALE_SIZE(30)
41 #define TIME_FONT_SIZE_12               ELM_SCALE_SIZE(30)
42 #define AMPM_FONT_SIZE          ELM_SCALE_SIZE(29)
43
44 #define TIME_FONT_COLOR         200, 200, 200, 255
45 #define AMPM_FONT_COLOR         200, 200, 200, 255
46 #define LABEL_STRING            "<font_size=%d>%s" \
47         "</font_size>"
48 #define LABEL_STRING_FONT               "%s</font>"
49
50 #define BATTERY_TIMER_INTERVAL          3
51 #define BATTERY_TIMER_INTERVAL_CHARGING 30
52
53 #define CLOCK_STR_LEN 128
54
55 enum {
56         INDICATOR_CLOCK_MODE_12H = 0,
57         INDICATOR_CLOCK_MODE_24H,
58         INDICATOR_CLOCK_MODE_MAX
59 };
60
61 int clock_mode = INDICATOR_CLOCK_MODE_12H;
62 int clock_hour = 0;
63 static const char *colon = ":";
64 static const char *ratio = "&#x2236;";
65
66 static int apm_length = 0;
67 static int apm_position = 0;
68 extern Ecore_Timer *clock_timer;
69
70 static i18n_udatepg_h _last_generator;
71 static char *_last_locale = NULL;
72 static int battery_charging = 0;
73
74 static int register_clock_module(void *data);
75 static int unregister_clock_module(void);
76 static int language_changed_cb(void *data);
77 static int region_changed_cb(void *data);
78 static int wake_up_cb(void *data);
79 #ifdef _SUPPORT_SCREEN_READER
80 static int register_clock_tts(void *data,int win_type);
81 #endif
82
83 #define ICON_PRIORITY   INDICATOR_PRIORITY_FIXED8
84 #define MODULE_NAME             "clock"
85
86 static void indicator_get_apm_by_region(char* output, void* data);
87 static void indicator_get_time_by_region(char* output, void* data);
88
89 #ifdef _SUPPORT_SCREEN_READER
90 static void ICU_set_timezone(const char *timezone);
91 #endif
92
93 icon_s sysclock = {
94         .type = INDICATOR_TXT_ICON,
95         .name = MODULE_NAME,
96         .priority = ICON_PRIORITY,
97         .always_top = EINA_FALSE,
98         .img_obj = {0,},
99         .obj_exist = EINA_FALSE,
100         .exist_in_view = EINA_FALSE,
101         .init = register_clock_module,
102         .fini = unregister_clock_module,
103         .region_changed = region_changed_cb,
104         .lang_changed = language_changed_cb,
105         .wake_up = wake_up_cb,
106 };
107
108
109
110 void cal_delete_last_generator(void)
111 {
112         if (_last_locale) {
113                 free(_last_locale);
114                 _last_locale = NULL;
115         }
116         if (_last_generator) {
117                 i18n_udatepg_destroy(_last_generator);
118                 _last_generator = NULL;
119         }
120 }
121
122
123
124 static i18n_udatepg_h __cal_get_pattern_generator(const char *locale, int *status)
125 {
126         if (!_last_generator || !_last_locale || strcmp(locale, _last_locale)) {
127
128                 cal_delete_last_generator();
129
130                 _last_locale = strdup(locale);
131
132                 int ret = i18n_udatepg_create(locale, &_last_generator);
133                 if (ret != I18N_ERROR_NONE) {
134                         _E("i18n_udatepg_create failed %d", ret);
135                         _last_generator = NULL;
136                 }
137         }
138         return _last_generator;
139 }
140
141
142
143 static void set_app_state(void* data)
144 {
145         sysclock.ad = data;
146 }
147
148
149
150 static void indicator_clock_changed_cb(void *data)
151 {
152         char time_str[CLOCK_STR_LEN] = {0,};
153         char time_buf[CLOCK_STR_LEN] = {0,};
154         char ampm_buf[CLOCK_STR_LEN] = {0,};
155         char ampm_str[CLOCK_STR_LEN] = {0,};
156         char buf[CLOCK_STR_LEN] = {0,};
157         char result[CLOCK_STR_LEN] = {0,};
158         char icu_apm[CLOCK_STR_LEN] = {0,};
159
160         struct tm *ts = NULL;
161         time_t ctime;
162         struct appdata *ad = NULL;
163         int len;
164         int font_size;
165         int ampm_size = AMPM_FONT_SIZE;
166
167         ret_if(!data);
168
169         ad = (struct appdata *)data;
170
171         if (icon_get_update_flag() == 0) return;
172
173         /* Set time */
174         ctime = time(NULL);
175         ts = localtime(&ctime);
176         if (ts == NULL) {
177                 _E("Fail to get localtime !");
178                 return;
179         }
180
181         if (clock_timer != NULL) {
182                 ecore_timer_del(clock_timer);
183                 clock_timer = NULL;
184         }
185
186         memset(time_str, 0x00, sizeof(time_str));
187         memset(ampm_str, 0x00, sizeof(ampm_str));
188         memset(time_buf, 0x00, sizeof(time_buf));
189         memset(ampm_buf, 0x00, sizeof(ampm_buf));
190         memset(buf, 0x00, sizeof(buf));
191
192         clock_timer = ecore_timer_add(60 - ts->tm_sec, (void *)indicator_clock_changed_cb, data);
193         if(!clock_timer) {
194                 _E("Fail to add timer !");
195         }
196
197         indicator_get_apm_by_region(icu_apm,data);
198         indicator_get_time_by_region(time_buf,data);
199
200
201         if (clock_mode == INDICATOR_CLOCK_MODE_12H) {
202                 char bf1[32] = { 0, };
203                 int hour;
204                 static int pre_hour = 0;
205                 const char *region = NULL;
206
207                 int bRegioncheck = 0;
208                 char *lang1 = "it_IT";
209
210                 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
211                 ret_if(!region);
212
213                 if (strncmp(region,lang1,strlen(lang1)) == 0) bRegioncheck = 1;
214
215                 if (apm_length>=4 || bRegioncheck==1) {
216                         if (ts->tm_hour >= 0 && ts->tm_hour < 12) {
217                                 snprintf(ampm_buf, sizeof(ampm_buf),"%s","AM");
218                         } else {
219                                 snprintf(ampm_buf, sizeof(ampm_buf),"%s","PM");
220                         }
221                 } else {
222                         snprintf(ampm_buf, sizeof(ampm_buf),"%s",icu_apm);
223                 }
224
225                 strftime(bf1, sizeof(bf1), "%l", ts);
226                 hour = atoi(bf1);
227                 strftime(bf1, sizeof(bf1), ":%M", ts);
228
229                 font_size = TIME_FONT_SIZE_12;
230                 clock_hour = hour;
231
232                 if ((pre_hour<10 && hour>=10)||(pre_hour>=10 && hour<10)) {
233                         box_update_display(&(ad->win));
234                 }
235
236                 pre_hour = hour;
237         } else {
238                 font_size = TIME_FONT_SIZE_24;
239         }
240
241         snprintf(time_str, sizeof(time_str), LABEL_STRING, font_size, time_buf);
242         snprintf(ampm_str, sizeof(ampm_str), LABEL_STRING, ampm_size, ampm_buf);
243
244         if (clock_mode == INDICATOR_CLOCK_MODE_12H) {
245                 if (apm_position == 0) {
246                         len = snprintf(buf, sizeof(buf), "%s %s", ampm_str, time_str);
247                 } else {
248                         len = snprintf(buf, sizeof(buf), "%s %s", time_str, ampm_str);
249                 }
250         } else {
251                 len = snprintf(buf, sizeof(buf), "%s", time_str);
252         }
253
254         snprintf(result, sizeof(result), LABEL_STRING_FONT, buf);
255         if (len < 0) {
256                 _E("Unexpected ERROR!");
257                 return;
258         }
259
260         _D("[CLOCK MODULE] Timer Status : %d Time: %s", clock_timer, result);
261         util_part_text_emit(data, "elm.text.clock", result);
262
263         return;
264 }
265
266
267
268 static void _clock_format_changed_cb(keynode_t *node, void *data)
269 {
270         struct appdata *ad = NULL;
271         int mode_24 = 0;
272         i18n_timezone_h timezone;
273
274         ret_if(!data);
275
276         ad = (struct appdata *)data;
277
278         if (vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224,&mode_24) < 0)
279         {
280                 ERR("Error getting VCONFKEY_REGIONFORMAT_TIME1224 value");
281                 return;
282         }
283
284         /* Check Time format. If timeformat have invalid value, Set to 12H */
285         if( mode_24==VCONFKEY_TIME_FORMAT_24)
286         {
287                 if(clock_mode == INDICATOR_CLOCK_MODE_12H)
288                 {
289                         clock_mode = INDICATOR_CLOCK_MODE_24H;
290                         box_update_display(&(ad->win));
291                 }
292         }
293         else
294         {
295                 if(clock_mode==INDICATOR_CLOCK_MODE_24H)
296                 {
297                         clock_mode = INDICATOR_CLOCK_MODE_12H;
298                         box_update_display(&(ad->win));
299                 }
300         }
301
302         char *timezone_str = util_get_timezone_str();
303
304         int ret = i18n_timezone_create(&timezone, timezone_str);
305         if (ret != I18N_ERROR_NONE) {
306                 _E("Unable to create timzone handle for %s: %d", timezone_str, ret);
307                 free(timezone_str);
308                 return;
309         }
310
311         ret = i18n_timezone_set_default(timezone);
312         if (ret != I18N_ERROR_NONE) {
313                 _E("Unable to set default timzone: %d", ret);
314                 i18n_timezone_destroy(timezone);
315                 free(timezone_str);
316                 return;
317         }
318
319         indicator_clock_changed_cb(data);
320         i18n_timezone_destroy(timezone);
321         free(timezone_str);
322 }
323
324
325
326 static void indicator_clock_charging_now_cb(keynode_t *node, void *data)
327 {
328         int status = 0;
329
330         retif(data == NULL, , "Invalid parameter!");
331
332
333         vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &status);
334
335         battery_charging = status;
336 }
337
338
339
340 static int language_changed_cb(void *data)
341 {
342         const char *pa_lang = vconf_get_str(VCONFKEY_LANGSET);
343         DBG("language_changed_cb %s",pa_lang);
344         indicator_clock_changed_cb(data);
345         return OK;
346 }
347
348
349
350 static int region_changed_cb(void *data)
351 {
352         _clock_format_changed_cb(NULL, data);
353         return OK;
354 }
355
356
357
358 static int wake_up_cb(void *data)
359 {
360         indicator_clock_changed_cb(data);
361
362         return OK;
363 }
364
365
366
367 /*static void _time_changed(system_settings_key_e key, void *data)
368 {
369         DBG("_time_changed");
370         _clock_format_changed_cb(NULL,data);
371 }*/
372
373
374
375 static void regionformat_changed(keynode_t *node, void *data)
376 {
377         DBG("regionformat_changed");
378         _clock_format_changed_cb(NULL,data);
379 }
380
381
382
383 static void timezone_int_changed(keynode_t *node, void *data)
384 {
385         DBG("timezone_int_changed");
386         _clock_format_changed_cb(NULL,data);
387 }
388
389
390
391 static void timezone_id_changed(keynode_t *node, void *data)
392 {
393         char *szTimezone = NULL;
394         szTimezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
395
396         DBG("timezone_id_changed %s",szTimezone);
397         _clock_format_changed_cb(NULL,data);
398 }
399
400
401
402 static int register_clock_module(void *data)
403 {
404         int r = 0, ret = -1;
405
406         retif(data == NULL, FAIL, "Invalid parameter!");
407
408         set_app_state(data);
409
410         /*ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_TIME_CHANGED, _time_changed, data);
411         if (ret != OK) {
412                 r = r | ret;
413         }*/
414
415         ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, regionformat_changed, data);
416         if (ret != OK) {
417                 r = r | ret;
418         }
419
420         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT, timezone_int_changed, data);
421         if (ret != OK) {
422                 r = r | ret;
423         }
424
425         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_ID, timezone_id_changed, data);
426         if (ret != OK) {
427                 r = r | ret;
428         }
429
430         ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, regionformat_changed, data);
431         if (ret != OK) {
432                 r = r | ret;
433         }
434         _clock_format_changed_cb(NULL, data);
435         indicator_clock_charging_now_cb(NULL,data);
436
437         return r;
438 }
439
440
441
442 static int unregister_clock_module(void)
443 {
444         int ret = VCONF_OK;
445
446         //ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_TIME_CHANGED);
447         ret = ret | vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, regionformat_changed);
448         ret = ret | vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT, timezone_int_changed);
449         ret = ret | vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_ID, timezone_id_changed);
450         ret = ret | vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, regionformat_changed);
451
452         if (clock_timer != NULL) {
453                 ecore_timer_del(clock_timer);
454                 clock_timer = NULL;
455         }
456
457         cal_delete_last_generator();
458
459         return ret;
460 }
461
462
463
464 static inline char *_extend_heap(char *buffer, int *sz, int incsz)
465 {
466         char *tmp;
467
468         *sz += incsz;
469         tmp = realloc(buffer, *sz);
470         if (!tmp) {
471                 ERR("Heap");
472                 return NULL;
473         }
474
475         return tmp;
476 }
477
478
479
480 static char *_string_replacer(const char *src, const char *pattern, const char *replace)
481 {
482         const char *ptr;
483         char *tmp = NULL;
484         char *ret = NULL;
485         int idx = 0;
486         int out_idx = 0;
487         int out_sz = 0;
488         enum {
489                 STATE_START,
490                 STATE_FIND,
491                 STATE_CHECK,
492                 STATE_END,
493         } state;
494
495         if (!src || !pattern)
496                 return NULL;
497
498         out_sz = strlen(src);
499         ret = strdup(src);
500         if (!ret) {
501                 ERR("Heap");
502                 return NULL;
503         }
504
505         out_idx = 0;
506         for (state = STATE_START, ptr = src; state != STATE_END; ptr++) {
507                 switch (state) {
508                 case STATE_START:
509                         if (*ptr == '\0') {
510                                 state = STATE_END;
511                         } else if (!isblank(*ptr)) {
512                                 state = STATE_FIND;
513                                 ptr--;
514                         }
515                         break;
516                 case STATE_FIND:
517                         if (*ptr == '\0') {
518                                 state = STATE_END;
519                         } else if (*ptr == *pattern) {
520                                 state = STATE_CHECK;
521                                 ptr--;
522                                 idx = 0;
523                         } else {
524                                 ret[out_idx] = *ptr;
525                                 out_idx++;
526                                 if (out_idx == out_sz) {
527                                         tmp = _extend_heap(ret, &out_sz, strlen(replace) + 1);
528                                         if (!tmp) {
529                                                 free(ret);
530                                                 return NULL;
531                                         }
532                                         ret = tmp;
533                                 }
534                         }
535                         break;
536                 case STATE_CHECK:
537                         if (!pattern[idx]) {
538                                 /*!
539      * If there is no space for copying the replacement,
540      * Extend size of the return buffer.
541      */
542                                 if (out_sz - out_idx < strlen(replace) + 1) {
543                                         tmp = _extend_heap(ret, &out_sz, strlen(replace) + 1);
544                                         if (!tmp) {
545                                                 free(ret);
546                                                 return NULL;
547                                         }
548                                         ret = tmp;
549                                 }
550
551                                 strcpy(ret + out_idx, replace);
552                                 out_idx += strlen(replace);
553
554                                 state = STATE_FIND;
555                                 ptr--;
556                         } else if (*ptr != pattern[idx]) {
557                                 ptr -= idx;
558
559                                 /* Copy the first matched character */
560                                 ret[out_idx] = *ptr;
561                                 out_idx++;
562                                 if (out_idx == out_sz) {
563                                         tmp = _extend_heap(ret, &out_sz, strlen(replace) + 1);
564                                         if (!tmp) {
565                                                 free(ret);
566                                                 return NULL;
567                                         }
568
569                                         ret = tmp;
570                                 }
571
572                                 state = STATE_FIND;
573                         } else {
574                                 idx++;
575                         }
576                         break;
577                 default:
578                         break;
579                 }
580         }
581
582         ret[out_idx] = '\0';
583         return ret;
584 }
585
586
587
588 void indicator_get_apm_by_region(char* output,void *data)
589 {
590         retif(data == NULL, , "Data parameter is NULL");
591         retif(output == NULL, , "output parameter is NULL");
592
593         i18n_uchar u_custom_skeleton[CLOCK_STR_LEN] = { 0, };
594         i18n_uchar u_timezone[64] = {0,};
595         i18n_uchar u_best_pattern[CLOCK_STR_LEN] = { 0, };
596         i18n_uchar u_formatted[CLOCK_STR_LEN] = { 0, };
597
598         i18n_udate_format_h formatter;
599         int32_t best_pattern_len, formatted_len;
600
601         char s_best_pattern[CLOCK_STR_LEN] = { 0, };
602         char s_formatted[CLOCK_STR_LEN] = { 0, };
603
604         int status = 0;
605
606         i18n_udatepg_h pattern_generator = NULL;
607
608         char *locale = vconf_get_str(VCONFKEY_REGIONFORMAT);
609         if(locale == NULL)
610         {
611                 ERR("[Error] get value of fail.");
612                 return;
613         }
614
615         /* Remove ".UTF-8" in locale */
616         char locale_tmp[32] = {0,};
617         strncpy(locale_tmp, locale, sizeof(locale_tmp)-1);
618         char *p = util_safe_str(locale_tmp, ".UTF-8");
619         if (p) {
620                 *p = 0;
621         }
622         free(locale);
623
624         i18n_ustring_copy_ua_n(u_custom_skeleton, "hhmm", ARRAY_SIZE(u_custom_skeleton));
625
626         pattern_generator = __cal_get_pattern_generator (locale_tmp, &status);
627         if (pattern_generator == NULL) {
628                 return ;
629         }
630
631         int ret = i18n_udatepg_get_best_pattern(pattern_generator, u_custom_skeleton, i18n_ustring_get_length(u_custom_skeleton),
632                         u_best_pattern, (int32_t)ARRAY_SIZE(u_best_pattern), &best_pattern_len);
633         if (ret != I18N_ERROR_NONE) {
634                 _E("i18n_udatepg_get_best_pattern failed: %d", ret);
635                 return;
636         }
637
638         i18n_ustring_copy_au(s_best_pattern, u_best_pattern);
639         i18n_ustring_copy_ua(u_best_pattern, "a");
640
641         char *timezone_id = util_get_timezone_str();
642         DBG("TimeZone is %s", timezone_id);
643
644         if (s_best_pattern[0] == 'a') {
645                 apm_position = 0;
646         }
647         else {
648                 apm_position = 1;
649         }
650
651         i18n_udate date;
652         ret = i18n_ucalendar_get_now(&date);
653         if (ret != I18N_ERROR_NONE) {
654                 ERR("i18n_ucalendar_get_now failed: %d", ret);
655                 free(timezone_id);
656                 return;
657         }
658         if (timezone_id) {
659                 i18n_ustring_copy_ua_n(u_timezone, timezone_id, ARRAY_SIZE(u_timezone));
660         }
661
662         ret = i18n_udate_create(I18N_UDATE_PATTERN, I18N_UDATE_PATTERN, locale_tmp, timezone_id ? u_timezone : NULL, -1,
663                         u_best_pattern, -1, &formatter);
664         if (ret != I18N_ERROR_NONE) {
665                 free(timezone_id);
666                 return;
667         }
668
669         free(timezone_id);
670
671         ret = i18n_udate_format_date(formatter, date, u_formatted, ARRAY_SIZE(s_formatted), NULL, &formatted_len);
672         if (ret != I18N_ERROR_NONE) {
673                 i18n_udate_destroy(formatter);
674                 return;
675         }
676
677         i18n_udate_destroy(formatter);
678
679         i18n_ustring_copy_au(s_formatted, u_formatted);
680         apm_length = i18n_ustring_get_length(u_formatted);
681
682         if (strlen(s_formatted) < CLOCK_STR_LEN) {
683                 strncpy(output, s_formatted, strlen(s_formatted));
684         }
685         else {
686                 strncpy(output, s_formatted, CLOCK_STR_LEN - 1);
687         }
688
689         return;
690 }
691
692
693
694 void indicator_get_time_by_region(char* output,void *data)
695 {
696         retif(data == NULL, , "Data parameter is NULL");
697         retif(output == NULL, , "output parameter is NULL");
698
699         i18n_uchar u_custom_skeleton[CLOCK_STR_LEN] = { 0, };
700         i18n_uchar u_timezone[64] = {0,};
701         i18n_uchar u_best_pattern[CLOCK_STR_LEN] = { 0, };
702         i18n_uchar u_formatted[CLOCK_STR_LEN] = { 0, };
703
704         int status = 0;
705         i18n_udate_format_h formatter = NULL;
706
707         char s_best_pattern[CLOCK_STR_LEN] = { 0, };
708         char s_formatted[CLOCK_STR_LEN] = { 0, };
709         char *s_convert_formatted = NULL;
710
711         char s_time_skeleton[20] = {0,};
712         i18n_udatepg_h pattern_generator = NULL;
713
714         int32_t best_pattern_len, formatted_len;
715
716         if (clock_mode == INDICATOR_CLOCK_MODE_12H) {
717                 strcpy(s_time_skeleton, "hm");
718         }
719         else {
720                 strcpy(s_time_skeleton, "Hm");
721         }
722         char *locale = vconf_get_str(VCONFKEY_REGIONFORMAT);
723         if (locale == NULL) {
724                 ERR("[Error] get value of fail.");
725                 return;
726         }
727
728         /* Remove ".UTF-8" in locale */
729         char locale_tmp[32] = {0,};
730         strncpy(locale_tmp, locale, sizeof(locale_tmp)-1);
731         char *p = util_safe_str(locale_tmp, ".UTF-8");
732         if (p) {
733                 *p = 0;
734         }
735         free(locale);
736
737         i18n_ustring_copy_ua_n(u_custom_skeleton, s_time_skeleton, ARRAY_SIZE(u_custom_skeleton));
738
739         pattern_generator = __cal_get_pattern_generator (locale_tmp, &status);
740         if (pattern_generator == NULL) {
741                 return;
742         }
743
744         int ret = i18n_udatepg_get_best_pattern(pattern_generator, u_custom_skeleton, i18n_ustring_get_length(u_custom_skeleton),
745                                 u_best_pattern, ARRAY_SIZE(u_best_pattern), &best_pattern_len);
746         if (ret != I18N_ERROR_NONE) {
747                 _E("i18n_udatepg_get_best_pattern failed: %d", ret);
748                 return;
749         }
750
751         char a_best_pattern[64] = {0,};
752         i18n_ustring_copy_au(a_best_pattern, u_best_pattern);
753
754         char *a_best_pattern_fixed = strtok(a_best_pattern, "a");
755         a_best_pattern_fixed = strtok(a_best_pattern_fixed, " ");
756         if (a_best_pattern_fixed) {
757                 i18n_ustring_copy_ua(u_best_pattern, a_best_pattern_fixed);
758         }
759
760         i18n_ustring_copy_au(s_best_pattern, u_best_pattern);
761
762         DBG("BestPattern is %s", s_best_pattern);
763
764         i18n_udate date;
765         ret = i18n_ucalendar_get_now(&date);
766         if (ret != I18N_ERROR_NONE) {
767                 ERR("i18n_ucalendar_get_now failed: %d", ret);
768                 return;
769         }
770
771         char* timezone_id = util_get_timezone_str();
772         DBG("TimeZone is %s", timezone_id);
773
774         if (timezone_id) {
775                 i18n_ustring_copy_ua_n(u_timezone, timezone_id, ARRAY_SIZE(u_timezone));
776         }
777
778         ret = i18n_udate_create(I18N_UDATE_PATTERN, I18N_UDATE_PATTERN, locale_tmp, timezone_id ? u_timezone : NULL, -1,
779                         u_best_pattern, -1, &formatter);
780         if (ret != I18N_ERROR_NONE) {
781                 free(timezone_id);
782                 return;
783         }
784
785         free(timezone_id);
786
787         ret = i18n_udate_format_date(formatter, date, u_formatted, ARRAY_SIZE(s_formatted), NULL, &formatted_len);
788         if (ret != I18N_ERROR_NONE) {
789                 i18n_udate_destroy(formatter);
790                 return;
791         }
792
793         i18n_udate_destroy(formatter);
794
795         i18n_ustring_copy_au(s_formatted, u_formatted);
796         DBG("DATE & TIME is %s %s %d %s", locale_tmp, s_formatted, i18n_ustring_get_length(u_formatted), s_best_pattern);
797
798         DBG("24H :: Before change %s", s_formatted);
799         s_convert_formatted = _string_replacer(s_formatted, colon, ratio);
800         DBG("24H :: After change %s", s_convert_formatted);
801
802         if (!s_convert_formatted) {
803                 DBG("_string_replacer return NULL");
804                 return;
805         }
806
807         if (strlen(s_convert_formatted) < CLOCK_STR_LEN) {
808                 strncpy(output, s_convert_formatted, strlen(s_convert_formatted));
809         }
810         else {
811                 strncpy(output, s_convert_formatted, CLOCK_STR_LEN - 1);
812         }
813
814         free(s_convert_formatted);
815
816         return;
817 }
818
819
820 #ifdef _SUPPORT_SCREEN_READER
821 static void ICU_set_timezone(const char *timezone)
822 {
823         i18n_timezone_h tmz;
824
825         if (timezone == NULL) {
826                 ERR("TIMEZONE is NULL");
827                 return;
828         }
829
830         int ret = i18n_timezone_create(&tmz, timezone);
831         if (ret != I18N_ERROR_NONE) {
832                 ERR("Unable to create timezone handle from %s: %d", timezone, ret);
833                 return;
834         }
835
836         ret = i18n_timezone_set_default(tmz);
837         if (ret != I18N_ERROR_NONE) {
838                 ERR("Unable to set default timezone to %s: %d", timezone, ret);
839         }
840
841         i18n_timezone_destroy(tmz);
842 }
843 #endif
844
845
846
847 #ifdef _SUPPORT_SCREEN_READER
848 static char *_access_info_cb(void *data, Evas_Object *obj)
849 {
850         Evas_Object *item = data;
851         char *tmp = NULL;
852         char time_str[32];
853         char time_buf[128], ampm_buf[128];
854         char buf[CLOCK_STR_LEN];
855         char buf1[CLOCK_STR_LEN];
856         int ret = 0;
857         int battery_capa = 0;
858         int hour = 0;
859         int minute = 0;
860         char strHour[128] = { 0, };
861         char strMin[128] = { 0, };
862
863
864         struct tm *ts = NULL;
865         time_t ctime;
866         int len;
867
868         retif(data == NULL,NULL, "Invalid parameter!");
869         char *timezone = util_get_timezone_str();
870         ICU_set_timezone(timezone);
871         if(timezone!=NULL)
872                 free(timezone);
873
874         /* Set time */
875         ctime = time(NULL);
876         ts = localtime(&ctime);
877         if (ts == NULL)
878                 return NULL;
879
880         memset(time_str, 0x00, sizeof(time_str));
881         memset(time_buf, 0x00, sizeof(time_buf));
882         memset(ampm_buf, 0x00, sizeof(ampm_buf));
883         memset(buf, 0x00, sizeof(buf));
884         memset(buf1, 0x00, sizeof(buf1));
885
886         if (clock_mode == INDICATOR_CLOCK_MODE_12H) {
887                 char bf1[32] = { 0, };
888
889                 if (ts->tm_hour >= 0 && ts->tm_hour < 12)
890                         strncpy(ampm_buf, _("IDS_IDLE_OPT_AM_ABB"),sizeof(ampm_buf)-1);
891                 else
892                         strncpy(ampm_buf, _("IDS_IDLE_OPT_PM_ABB"),sizeof(ampm_buf)-1);
893
894                 strftime(bf1, sizeof(bf1), "%l", ts);
895                 hour = atoi(bf1);
896                 strftime(bf1, sizeof(bf1), "%M", ts);
897                 minute = atoi(bf1);
898         }
899         else{
900                 char bf1[32] = { 0, };
901
902                 strftime(bf1, sizeof(bf1), "%H", ts);
903                 hour = atoi(bf1);
904                 strftime(bf1, sizeof(bf1), "%M", ts);
905                 minute = atoi(bf1);
906         }
907
908         if(hour ==1)
909         {
910                 strncpy(strHour, _("IDS_COM_BODY_1_HOUR"),sizeof(strHour));
911         }
912         else
913         {
914                 snprintf(strHour, sizeof(strHour), _("IDS_COM_POP_PD_HOURS"),hour);
915         }
916
917         if(minute ==1)
918         {
919                 strncpy(strMin, _("IDS_COM_BODY_1_MINUTE"),sizeof(strMin));
920         }
921         else
922         {
923                 snprintf(strMin, sizeof(strMin), _("IDS_COM_BODY_PD_MINUTES"),minute);
924         }
925
926         if(clock_mode == INDICATOR_CLOCK_MODE_12H)
927                 snprintf(time_str, sizeof(time_str), "%s, %s, %s", strHour, strMin,ampm_buf);
928         else
929                 snprintf(time_str, sizeof(time_str), "%s, %s", strHour, strMin);
930
931
932         ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &battery_capa);
933         if (ret != OK)
934         {
935                 return NULL;
936         }
937         if (battery_capa < 0)
938         {
939                 return NULL;
940         }
941
942         if (battery_capa > 100)
943                 battery_capa = 100;
944         snprintf(buf1, sizeof(buf1), _("IDS_IDLE_BODY_PD_PERCENT_OF_BATTERY_POWER_REMAINING"), battery_capa);
945
946         snprintf(buf, sizeof(buf), "%s, %s, %s", time_str, buf1, _("IDS_IDLE_BODY_STATUS_BAR_ITEM"));
947
948         DBG("buf: %s", buf);
949         tmp = strdup(buf);
950         if (!tmp) return NULL;
951         return tmp;
952 }
953
954
955
956 static int register_clock_tts(void *data,int win_type)
957 {
958         int r = 0, ret = -1;
959
960         retif(data == NULL, FAIL, "Invalid parameter!");
961
962         Evas_Object *to = NULL;
963         Evas_Object *ao = NULL;
964         struct appdata *ad = data;
965
966         to = (Evas_Object *) edje_object_part_object_get(elm_layout_edje_get(ad->win[win_type].layout), "elm.rect.clock.access");
967         ao = util_access_object_register(to, ad->win[win_type].layout);
968         util_access_object_info_cb_set(ao,ELM_ACCESS_INFO,_access_info_cb,data);
969         return 0;
970 }
971 #endif
972