2 * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <device/battery.h>
18 #include <device/callback.h>
20 #include "lockscreen.h"
22 #include "battery_ctrl.h"
24 #include "main_view.h"
28 static Ecore_Event_Handler *handler;
29 static Evas_Object *main_view;
32 // FIXME why this is needed?
33 static char *_replaceString(char *strInput, const char *strTarget, const char *strChange)
35 char* strResult; char* strTemp;
38 int nTargetLength = strlen(strTarget);
40 if (nTargetLength < 1) {
41 ERR("there is no target to chnage");
45 int nChangeLength = strlen(strChange);
47 if (nChangeLength != nTargetLength) {
48 for (i = 0; strInput[i] != '\0';) {
49 if (memcmp(&strInput[i], strTarget, nTargetLength) == 0) {
50 nCount++; //consider same string exist
60 strResult = (char *) malloc(i + 1 + nCount * (nChangeLength - nTargetLength));
69 if (memcmp(strInput, strTarget, nTargetLength) == 0) {
70 memcpy(strTemp, strChange, nChangeLength);
71 strTemp += nChangeLength; //move changed length
72 strInput += nTargetLength; // move target length
74 *strTemp++ = *strInput++; // original str cpy
83 static char *_text_from_percentage(int capacity)
86 char *newString = NULL;
87 newString = _replaceString(_("IDS_LCKSCN_BODY_CHARGING_C_PDP"), "%d%", "%d%%");
89 if (newString != NULL) {
90 snprintf(buff, sizeof(buff), newString , capacity);
93 snprintf(buff, sizeof(buff), _("IDS_LCKSCN_BODY_CHARGING_C_PDP") , capacity);
98 static int _battery_update(void)
100 if (lockscreen_battery_is_charging()) {
101 if (lockscreen_battery_level_get() == 100) {
102 lockscreen_main_view_battery_status_text_set(main_view, _("IDS_SM_POP_FULLY_CHARGED"));
104 char *buff = _text_from_percentage(lockscreen_battery_level_get());
105 lockscreen_main_view_battery_status_text_set(main_view, buff);
109 if (lockscreen_battery_level_get() == 100 && lockscreen_battery_is_connected()) {
110 lockscreen_main_view_battery_status_text_set(main_view, _("IDS_SM_POP_FULLY_CHARGED"));
112 lockscreen_main_view_battery_status_text_set(main_view, NULL);
118 static Eina_Bool _data_battery_update(void *data, int event, void *event_info)
124 int lock_battery_ctrl_init(Evas_Object *view)
126 if (lockscreen_battery_init()) {
127 FAT("lockscreen_battery_init failed. Battery related information will not be available");
130 handler = ecore_event_handler_add(LOCKSCREEN_EVENT_BATTERY_CHANGED, _data_battery_update, NULL);
132 FAT("ecore_event_handler_add failed on LOCKSCREEN_DATA_MODEL_EVENT_BATTERY_CHANGED event");
138 void lock_battery_ctrl_fini(void)
140 ecore_event_handler_del(handler);