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