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