sync with master
[apps/core/preloaded/indicator-win.git] / modules / clock / clock.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *  http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <vconf.h>
20 #include <heynoti.h>
21 #include <runtime_info.h>
22 #include <Ecore_X.h>
23 #include <unicode/udat.h>
24 #include <unicode/udatpg.h>
25 #include <unicode/ustring.h>
26
27 #include "common.h"
28 #include "indicator.h"
29 #include "indicator_ui.h"
30 #include "indicator_gui.h"
31 #include "indicator_icon_util.h"
32 #include "indicator_util.h"
33 #include "modules.h"
34
35 #define SYSTEM_RESUME                           "system_wakeup"
36
37 #define TIME_FONT_SIZE_24       34
38 #define TIME_FONT_SIZE_12       30
39 #define TIME_FONT_SIZE_BATTERY  32
40 #define TIME_FONT_COLOR         243, 243, 243, 255
41
42 #define AMPM_FONT_SIZE          24
43 #define AMPM_FONT_COLOR         243, 243, 243, 255
44 #define LABEL_STRING            "<font_size=%d>%s" \
45                                 "</font_size></font>"
46
47 #define BATTERY_TIMER_INTERVAL          3
48 #define BATTERY_TIMER_INTERVAL_CHARGING 30
49
50 #define CLOCK_STR_LEN 256
51
52 enum {
53         INDICATOR_CLOCK_MODE_12H = 0,
54         INDICATOR_CLOCK_MODE_24H,
55         INDICATOR_CLOCK_MODE_MAX
56 };
57
58 static int notifd;
59 static int clock_mode = INDICATOR_CLOCK_MODE_12H;
60 static int apm_length = 0;
61 static int apm_position = 0;
62 static Ecore_Timer *timer = NULL;
63 static Ecore_Timer *battery_timer = NULL;
64 static Ecore_Timer *battery_charging_timer = NULL;
65 static int battery_charging = 0;
66 static int battery_charging_first = 0;
67
68 static int register_clock_module(void *data);
69 static int unregister_clock_module(void);
70 static int hib_enter_clock_module(void);
71 static int hib_leave_clock_module(void *data);
72 static int language_changed_cb(void *data);
73 static int region_changed_cb(void *data);
74 static int wake_up_cb(void *data);
75
76 #define ICON_PRIORITY   INDICATOR_PRIORITY_FIXED6
77 #define MODULE_NAME             "clock"
78
79 static void indicator_get_time_by_region(char* output, void* data);
80 static void ICU_set_timezone(const char *timezone);
81 static void indicator_clock_display_battery_percentage(void *data,int win_type );
82
83 Indicator_Icon_Object sysclock[INDICATOR_WIN_MAX] = {
84 {
85         .win_type = INDICATOR_WIN_PORT,
86         .type = INDICATOR_TXT_ICON,
87         .name = MODULE_NAME,
88         .priority = ICON_PRIORITY,
89         .always_top = EINA_FALSE,
90         .txt_obj = {0,},
91         .img_obj = {0,},
92         .obj_exist = EINA_FALSE,
93         .exist_in_view = EINA_FALSE,
94         .init = register_clock_module,
95         .fini = unregister_clock_module,
96         .hib_enter = hib_enter_clock_module,
97         .hib_leave = hib_leave_clock_module,
98         .lang_changed = NULL,
99         .region_changed = region_changed_cb,
100         .lang_changed = language_changed_cb,
101         .wake_up = wake_up_cb
102 },
103 {
104         .win_type = INDICATOR_WIN_LAND,
105         .type = INDICATOR_TXT_ICON,
106         .name = MODULE_NAME,
107         .priority = ICON_PRIORITY,
108         .always_top = EINA_FALSE,
109         .txt_obj = {0,},
110         .img_obj = {0,},
111         .obj_exist = EINA_FALSE,
112         .exist_in_view = EINA_FALSE,
113         .init = register_clock_module,
114         .fini = unregister_clock_module,
115         .hib_enter = hib_enter_clock_module,
116         .hib_leave = hib_leave_clock_module,
117         .lang_changed = NULL,
118         .region_changed = region_changed_cb,
119         .lang_changed = language_changed_cb,
120         .wake_up = wake_up_cb
121 }
122 };
123
124 static void set_app_state(void* data)
125 {
126         int i = 0;
127
128         for (i=0 ; i<INDICATOR_WIN_MAX ; i++)
129         {
130                 sysclock[i].ad = data;
131         }
132 }
133
134 static void indicator_clock_changed_cb(void *data)
135 {
136         char time_str[32];
137         char time_buf[128], ampm_buf[128];
138         char buf[CLOCK_STR_LEN];
139         char icu_apm[CLOCK_STR_LEN] = {0,};
140
141         struct tm *ts = NULL;
142         time_t ctime;
143         int len;
144         int font_size;
145
146         retif(data == NULL, , "Invalid parameter!");
147
148         if(indicator_util_get_update_flag()==0)
149         {
150                 DBG("need to update");
151                 return;
152         }
153
154         if (battery_timer != NULL || battery_charging_timer != NULL)
155         {
156                 DBG("battery is displaying. ignore clock callback");
157                 return;
158         }
159
160         ctime = time(NULL);
161         ts = localtime(&ctime);
162         if (ts == NULL)
163                 return;
164
165         if (timer != NULL) {
166                 ecore_timer_del(timer);
167                 timer = NULL;
168         }
169
170         memset(time_str, 0x00, sizeof(time_str));
171         memset(time_buf, 0x00, sizeof(time_buf));
172         memset(ampm_buf, 0x00, sizeof(ampm_buf));
173         memset(buf, 0x00, sizeof(buf));
174
175         timer =
176             ecore_timer_add(60 - ts->tm_sec, (void *)indicator_clock_changed_cb,
177                             data);
178
179         indicator_get_time_by_region(icu_apm,data);
180
181         if (clock_mode == INDICATOR_CLOCK_MODE_12H) {
182                 char bf1[32] = { 0, };
183                 int hour;
184
185                 if(apm_length>0 && apm_length<=4)
186                 {
187                         snprintf(ampm_buf, sizeof(ampm_buf),LABEL_STRING, AMPM_FONT_SIZE,icu_apm);
188                 }
189                 else
190                 {
191                         if (ts->tm_hour >= 0 && ts->tm_hour < 12)
192                                 snprintf(ampm_buf, sizeof(ampm_buf),
193                                          LABEL_STRING, AMPM_FONT_SIZE,
194                                          "AM");
195                         else
196                                 snprintf(ampm_buf, sizeof(ampm_buf),
197                                          LABEL_STRING, AMPM_FONT_SIZE,
198                                          "PM");
199                 }
200
201                 strftime(bf1, sizeof(bf1), "%l", ts);
202                 hour = atoi(bf1);
203                 strftime(bf1, sizeof(bf1), ":%M", ts);
204
205                 snprintf(time_str, sizeof(time_str), "%d%s", hour, bf1);
206                 font_size = TIME_FONT_SIZE_12;
207                 indicator_signal_emit(data,"indicator.clock.ampm","indicator.prog");
208         }
209         else{
210                 font_size = TIME_FONT_SIZE_24;
211                 strftime(time_str, sizeof(time_str), "%H:%M", ts);
212                 indicator_signal_emit(data,"indicator.clock.default","indicator.prog");
213         }
214
215         snprintf(time_buf, sizeof(time_buf), LABEL_STRING, font_size, time_str);
216
217         if(apm_position == 0)
218                 len = snprintf(buf, sizeof(buf), "%s%s", ampm_buf, time_buf);
219         else
220                 len = snprintf(buf, sizeof(buf), "%s%s", time_buf, ampm_buf);
221
222         if (len < 0) {
223                 ERR("Unexpected ERROR!");
224                 return;
225         }
226
227         INFO("[CLOCK MODULE] Timer Status : %d Time: %s", timer, buf);
228
229         indicator_part_text_emit(data,"elm.text.clock", buf);
230
231         return;
232 }
233
234 static void indicator_clock_format_changed_cb(keynode_t *node, void *data)
235 {
236         retif(data == NULL, , "Invalid parameter!");
237
238         int r = -1;
239
240         bool is_24hour_enabled = false;
241
242         INFO("[Enter] indicator_clock_format_changed_cb");
243
244         r = runtime_info_get_value_bool(
245                         RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, &is_24hour_enabled);
246
247         if( r==RUNTIME_INFO_ERROR_NONE&&is_24hour_enabled==true)
248         {
249                 clock_mode = INDICATOR_CLOCK_MODE_24H;
250         }
251         else
252         {
253                 clock_mode = INDICATOR_CLOCK_MODE_12H;
254         }
255
256         char *timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
257         ICU_set_timezone(timezone);
258         indicator_clock_changed_cb(data);
259         free(timezone);
260 }
261
262 static void indicator_clock_pm_state_change_cb(keynode_t *node, void *data)
263 {
264         int status = 0;
265
266         retif(data == NULL, , "Invalid parameter!");
267
268         vconf_get_int(VCONFKEY_PM_STATE, &status);
269
270         switch(status)
271         {
272                 case VCONFKEY_PM_STATE_LCDOFF:
273                         if (timer != NULL) {
274                                 ecore_timer_del(timer);
275                                 timer = NULL;
276                         }
277
278                         if (battery_timer != NULL) {
279                                 ecore_timer_del(battery_timer);
280                                 battery_timer = NULL;
281                         }
282
283                         if (battery_charging_timer != NULL) {
284                                 ecore_timer_del(battery_charging_timer);
285                                 battery_charging_timer = NULL;
286                         }
287                         break;
288                 default:
289                         break;
290         }
291
292 }
293
294 static void indicator_clock_battery_disp_changed_cb(keynode_t *node, void *data)
295 {
296         int status = 0;
297
298         vconf_get_int(VCONFKEY_BATTERY_DISP_STATE,&status);
299
300         DBG("indicator_clock_battery_disp_changed_cb(%d)",status);
301
302         if(status==2)
303         {
304                 indicator_clock_display_battery_percentage(data,0);
305                 indicator_clock_display_battery_percentage(data,1);
306         }
307         else
308         {
309                 indicator_clock_display_battery_percentage(data,status);
310         }
311 }
312
313 static void indicator_clock_charging_now_cb(keynode_t *node, void *data)
314 {
315         int status = 0;
316         int lock_state = 0;
317
318         retif(data == NULL, , "Invalid parameter!");
319
320         vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state);
321
322         vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &status);
323
324         battery_charging = status;
325
326         DBG("indicator_clock_charging_now_cb(%d)",status);
327
328         if(lock_state==VCONFKEY_IDLE_LOCK)
329         {
330                 DBG("indicator_clock_charging_now_cb:lock_state(%d)",lock_state);
331                 return;
332         }
333
334         if(battery_charging_first == 1&&status==1)
335         {
336                 DBG("indicator_clock_charging_now_cb : ignore(%d)",status);
337         }
338
339         if(status==1)
340         {
341                 battery_charging_first = 1;
342                 indicator_clock_display_battery_percentage(data,0);
343         }
344 }
345
346 static void indicator_clock_battery_capacity_cb(keynode_t *node, void *data)
347 {
348         retif(data == NULL, , "Invalid parameter!");
349
350         if(battery_charging==1&&battery_charging_timer!=NULL)
351         {
352                 DBG("indicator_clock_battery_capacity_cb:battery_charging(%d)",battery_charging);
353                 indicator_clock_display_battery_percentage(data,0);
354         }
355 }
356
357
358 static void indicator_clock_usb_cb(keynode_t *node, void *data)
359 {
360         int status = 0;
361
362         retif(data == NULL, , "Invalid parameter!");
363
364         vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &status);
365
366         DBG("indicator_clock_usb_cb(%d)",status);
367
368         if(status==VCONFKEY_SYSMAN_USB_DISCONNECTED)
369         {
370                 battery_charging_first = 0;
371                 if (battery_charging_timer != NULL)
372                 {
373                         ecore_timer_del(battery_charging_timer);
374                         battery_charging_timer = NULL;
375                 }
376                 indicator_clock_changed_cb(data);
377         }
378 }
379
380 static void indicator_clock_battery_display_cb(void *data)
381 {
382         INFO("indicator_clock_battery_charging_stop_cb");
383
384         if (battery_timer != NULL) {
385                 ecore_timer_del(battery_timer);
386                 battery_timer = NULL;
387         }
388
389         indicator_clock_changed_cb(data);
390 }
391
392 static void indicator_clock_battery_charging_stop_cb(void *data)
393 {
394
395         INFO("indicator_clock_battery_charging_stop_cb");
396
397         if (battery_charging_timer != NULL) {
398                 ecore_timer_del(battery_charging_timer);
399                 battery_charging_timer = NULL;
400         }
401
402         indicator_clock_changed_cb(data);
403 }
404
405 static void indicator_clock_lock_state_cb(keynode_t *node, void *data)
406 {
407         int status = 0;
408
409         retif(data == NULL, , "Invalid parameter!");
410
411         vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &status);
412
413         DBG("indicator_clock_lock_state_cb(%d)",status);
414
415         if(status==VCONFKEY_IDLE_UNLOCK && battery_charging==1)
416         {
417                 battery_charging_first = 1;
418                 indicator_clock_display_battery_percentage(data,0);
419         }
420
421 }
422
423 static void indicator_clock_display_battery_percentage(void *data,int win_type )
424 {
425         int ret = FAIL;
426         int status = 0;
427         int battery_capa = 0;
428         char buf[256] = {0,};
429         char temp[256] = {0,};
430         struct appdata *ad = (struct appdata *)data;
431
432
433         if(battery_charging_timer!=NULL)
434         {
435                 INFO("30sec timer alive");
436                 return;
437         }
438
439         ret = vconf_get_bool(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, &status);
440         if (ret != OK)
441                 ERR("Fail to get [%s: %d]",
442                         VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, ret);
443
444         if(status)
445         {
446                 ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &battery_capa);
447                 if (ret != OK)
448                 {
449                         ERR("Fail to get [VCONFKEY_SYSMAN_BATTERY_CAPACITY:%d]", ret);
450                         return;
451                 }
452                 if (battery_capa < 0)
453                 {
454                         INFO("Invalid Battery Capacity: %d", battery_capa);
455                         return;
456                 }
457
458                 INFO("Battery Capacity: %d", battery_capa);
459
460                 if (battery_capa > 100)
461                         battery_capa = 100;
462
463                 snprintf(temp, sizeof(temp), "%d%%",battery_capa);
464
465                 snprintf(buf, sizeof(buf), LABEL_STRING, TIME_FONT_SIZE_BATTERY, temp);
466
467                 INFO("indicator_clock_display_battery_percentage %s", buf);
468
469                 indicator_part_text_emit_by_win(&(ad->win[win_type]),"elm.text.clock", buf);
470
471                 if(battery_charging == 1)
472                 {
473
474                         battery_charging_timer =  ecore_timer_add(BATTERY_TIMER_INTERVAL_CHARGING, (void *)indicator_clock_battery_charging_stop_cb,data);
475                 }
476                 else
477                 {
478                         if (battery_timer != NULL) {
479                                 ecore_timer_del(battery_timer);
480                                 battery_timer = NULL;
481                         }
482
483                         battery_timer =  ecore_timer_add(BATTERY_TIMER_INTERVAL, (void *)indicator_clock_battery_display_cb,data);
484                 }
485         }
486
487 }
488
489
490 static int language_changed_cb(void *data)
491 {
492         DBG("language_changed_cb");
493         indicator_clock_changed_cb(data);
494         return OK;
495 }
496
497 static int region_changed_cb(void *data)
498 {
499         DBG("region_changed_cb");
500         indicator_clock_format_changed_cb(NULL, data);
501         return OK;
502 }
503
504 static int wake_up_cb(void *data)
505 {
506         int status = 0;
507
508         INFO("CLOCK wake_up_cb");
509
510         retif(data == NULL, FAIL, "Invalid parameter!");
511
512         vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &status);
513
514         DBG("wake_up_cb(%d)",status);
515
516         if(status==VCONFKEY_IDLE_UNLOCK && battery_charging==1)
517         {
518                 indicator_clock_display_battery_percentage(data,0);
519         }
520         else
521         {
522                 indicator_clock_changed_cb(data);
523         }
524         return OK;
525 }
526
527 static int register_clock_module(void *data)
528 {
529         int r = 0, ret = -1;
530
531         retif(data == NULL, FAIL, "Invalid parameter!");
532
533         set_app_state(data);
534
535         notifd = heynoti_init();
536
537         if (notifd < 0) {
538                 ERR("heynoti_init is failed");
539                 return r;
540         }
541
542         ret =
543             heynoti_subscribe(notifd, SYSTEM_RESUME, indicator_clock_changed_cb,
544                               data);
545         if (ret != OK) {
546                 ERR("Fail: register SYSTEM_RESUME");
547                 r = r | ret;
548         }
549
550         ret = heynoti_attach_handler(notifd);
551         if (ret != OK) {
552                 ERR("Failed to attach heynoti handler!");
553                 r = r | ret;
554         }
555
556         ret = vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED,
557                                        indicator_clock_format_changed_cb, data);
558         if (ret != OK) {
559                 ERR("Fail: register VCONFKEY_SYSTEM_TIME_CHANGED");
560                 r = r | ret;
561         }
562
563         ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
564                                        indicator_clock_format_changed_cb, data);
565         if (ret != OK) {
566                 ERR("Fail: register VCONFKEY_REGIONFORMAT_TIME1224");
567                 r = r | ret;
568         }
569
570         ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT,
571                                        indicator_clock_format_changed_cb, data);
572         if (ret != OK) {
573                 ERR("Fail: register VCONFKEY_SETAPPL_TIMEZONE_INT");
574                 r = r | ret;
575         }
576
577         ret = vconf_notify_key_changed(VCONFKEY_PM_STATE, indicator_clock_pm_state_change_cb, (void *)data);
578
579         if (ret != OK) {
580                 ERR("Fail: register VCONFKEY_PM_STATE");
581                 r = r | ret;
582         }
583
584         ret = vconf_notify_key_changed(VCONFKEY_BATTERY_DISP_STATE,
585                                        indicator_clock_battery_disp_changed_cb, data);
586         if (ret != OK) {
587                 ERR("Fail: register VCONFKEY_SETAPPL_TIMEZONE_INT");
588                 r = r | ret;
589         }
590
591         ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY,
592                                        indicator_clock_battery_capacity_cb, data);
593         if (ret != OK) {
594                 ERR("Failed to register callback!");
595                 r = r | ret;
596         }
597
598         ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW,
599                                        indicator_clock_charging_now_cb, data);
600         if (ret != OK) {
601                 ERR("Failed to register callback!");
602                 r = r | ret;
603         }
604
605         ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
606                                        indicator_clock_usb_cb, data);
607         if (ret != OK) {
608                 ERR("Failed to register callback!");
609                 r = r | ret;
610         }
611
612
613         ret = vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE,
614                                        indicator_clock_lock_state_cb, data);
615         if (ret != OK) {
616                 ERR("Failed to register callback!");
617                 r = r | ret;
618         }
619
620
621         indicator_clock_format_changed_cb(NULL, data);
622
623         return r;
624 }
625
626 static int unregister_clock_module(void)
627 {
628         int ret;
629
630         heynoti_unsubscribe(notifd, SYSTEM_RESUME, indicator_clock_changed_cb);
631
632         heynoti_close(notifd);
633         notifd = 0;
634
635         ret = vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED,
636                                                indicator_clock_format_changed_cb);
637         if (ret != OK)
638                 ERR("Fail: unregister VCONFKEY_SYSTEM_TIME_CHANGED");
639
640         ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
641                                        indicator_clock_format_changed_cb);
642         if (ret != OK)
643                 ERR("Fail: unregister VCONFKEY_REGIONFORMAT_TIME1224");
644
645         ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT,
646                                        indicator_clock_format_changed_cb);
647         if (ret != OK)
648                 ERR("Fail: unregister VCONFKEY_SETAPPL_TIMEZONE_INT");
649
650         ret = vconf_ignore_key_changed(VCONFKEY_PM_STATE,
651                                                indicator_clock_battery_disp_changed_cb);
652         if (ret != OK)
653                 ERR("Fail: unregister VCONFKEY_PM_STATE");
654
655         ret = vconf_ignore_key_changed(VCONFKEY_BATTERY_DISP_STATE,
656                                                indicator_clock_pm_state_change_cb);
657         if (ret != OK)
658                 ERR("Fail: unregister VCONFKEY_BATTERY_DISP_STATE");
659
660         ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY,
661                                                indicator_clock_battery_capacity_cb);
662         if (ret != OK)
663                 ERR("Fail: unregister VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW");
664
665         ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW,
666                                                indicator_clock_charging_now_cb);
667         if (ret != OK)
668                 ERR("Fail: unregister VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW");
669
670         ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
671                                                indicator_clock_usb_cb);
672         if (ret != OK)
673                 ERR("Fail: unregister VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW");
674
675
676         ret = vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE,
677                                                indicator_clock_lock_state_cb);
678         if (ret != OK)
679                 ERR("Fail: unregister VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW");
680
681         if (timer != NULL) {
682                 ecore_timer_del(timer);
683                 timer = NULL;
684         }
685         return OK;
686 }
687
688 static int hib_enter_clock_module(void)
689 {
690         int ret;
691
692         ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
693                                        indicator_clock_format_changed_cb);
694         if (ret != OK)
695                 ERR("Fail: unregister VCONFKEY_REGIONFORMAT_TIME1224");
696
697         if (timer != NULL) {
698                 ecore_timer_del(timer);
699                 timer = NULL;
700         }
701
702         return OK;
703 }
704
705 static int hib_leave_clock_module(void *data)
706 {
707         int ret;
708
709         retif(data == NULL, FAIL, "Invalid parameter!");
710
711         ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224,
712                                        indicator_clock_format_changed_cb, data);
713         retif(ret != OK, FAIL, "Failed to register callback!");
714
715         indicator_clock_format_changed_cb(NULL, data);
716         return OK;
717 }
718
719 void indicator_get_time_by_region(char* output,void *data)
720 {
721         retif(data == NULL, , "Data parameter is NULL");
722         retif(output == NULL, , "output parameter is NULL");
723
724
725         UChar customSkeleton[CLOCK_STR_LEN] = { 0, };
726         UErrorCode status = U_ZERO_ERROR;
727         UDateFormat *formatter = NULL;
728
729         UChar bestPattern[CLOCK_STR_LEN] = { 0, };
730         UChar formatted[CLOCK_STR_LEN] = { 0, };
731
732         char bestPatternString[CLOCK_STR_LEN] = { 0, };
733         char formattedString[CLOCK_STR_LEN] = { 0, };
734
735         UDateTimePatternGenerator *pattern_generator = NULL;
736
737         char *time_skeleton = "hhmm";
738
739         char *locale = vconf_get_str(VCONFKEY_REGIONFORMAT);
740         if (locale == NULL) {
741                 DBG("[Error] get value of VCONFKEY_REGIONFORMAT fail.");
742         }
743
744         u_uastrncpy(customSkeleton, time_skeleton, strlen(time_skeleton));
745
746         pattern_generator = udatpg_open(locale, &status);
747
748         int32_t bestPatternCapacity = (int32_t) (sizeof(bestPattern) / sizeof((bestPattern)[0]));
749         (void)udatpg_getBestPattern(pattern_generator, customSkeleton,
750                                     u_strlen(customSkeleton), bestPattern,
751                                     bestPatternCapacity, &status);
752
753         u_austrcpy(bestPatternString, bestPattern);
754         u_uastrcpy(bestPattern,"a");
755
756         if(bestPatternString[0] == 'a')
757         {
758                 apm_position = 0;
759         }
760         else
761         {
762                 apm_position = 1;
763         }
764
765         UDate date = ucal_getNow();
766         formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status);
767         int32_t formattedCapacity = (int32_t) (sizeof(formatted) / sizeof((formatted)[0]));
768         (void)udat_format(formatter, date, formatted, formattedCapacity, NULL, &status);
769         u_austrcpy(formattedString, formatted);
770
771         DBG("DATE & TIME is %s %s %d %s", locale, formattedString, u_strlen(formatted), bestPatternString);
772
773         apm_length = u_strlen(formatted);
774
775         udatpg_close(pattern_generator);
776
777         udat_close(formatter);
778
779         if(strlen(formattedString)<CLOCK_STR_LEN)
780         {
781                 strncpy(output,formattedString,strlen(formattedString));
782         }
783         else
784         {
785                 strncpy(output,formattedString,CLOCK_STR_LEN-1);
786         }
787
788         return;
789 }
790
791 static UChar *uastrcpy(const char *chars)
792 {
793         int len = 0;
794         UChar *str = NULL;
795         len = strlen(chars);
796         str = (UChar *) malloc(sizeof(UChar) *(len + 1));
797         if (!str)
798                 return NULL;
799         u_uastrcpy(str, chars);
800         return str;
801 }
802
803 static void ICU_set_timezone(const char *timezone)
804 {
805         if(timezone == NULL)
806         {
807                 ERR("TIMEZONE is NULL");
808                 return;
809         }
810
811         DBG("ICU_set_timezone = %s ", timezone);
812         UErrorCode ec = U_ZERO_ERROR;
813         UChar *str = uastrcpy(timezone);
814
815         ucal_setDefaultTimeZone(str, &ec);
816         if (U_SUCCESS(ec)) {
817                 DBG("ucal_setDefaultTimeZone() SUCCESS ");
818         } else {
819                 DBG("ucal_setDefaultTimeZone() FAILED : %s ",
820                               u_errorName(ec));
821         }
822         free(str);
823 }
824
825