3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.tizenopensource.org/license
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "timer_utils.h"
19 #include "clock_fwk_widget.h"
21 * Debug function: to read time setted last time
22 * This function requires data as parameters
24 * timer_vconf_load_start_time()
25 * @param[in] data Pointer to user data, which contains the data of application
27 * @return indicate whether it succeed
29 int timer_vconf_load_start_time(void *data)
31 retvm_if(!data, FAILED, "data null");
32 struct appdata *ad = (struct appdata *)data;
36 nErr = vconf_get_int(VCONF_TIMER_START_TIME, &start_time);
37 retvm_if(nErr != SUCCESS, FAILED, "vconf_get_int error");
39 ad->chour[0] = '0' + (start_time / 100000) % 10;
40 ad->chour[1] = '0' + (start_time / 10000) % 10;
43 ad->cminute[0] = '0' + (start_time / 1000) % 10;
44 ad->cminute[1] = '0' + (start_time / 100) % 10;
45 ad->cminute[2] = '\0';
47 ad->csecond[0] = '0' + (start_time / 10) % 10;
48 ad->csecond[1] = '0' + start_time % 10;
49 ad->csecond[2] = '\0';
54 * Debug function: to save the setted time
55 * This function requires data as parameters
57 * timer_vconf_set_start_time()
58 * @param[in] data Pointer to user data, which contains the data of application
60 * @return indicate whether it succeed
62 int timer_vconf_set_start_time(void *data)
64 retvm_if(!data, FAILED, "data null");
65 struct appdata *ad = (struct appdata *)data;
69 start_time += (ad->chour[0] - '0') * 100000;
70 start_time += (ad->chour[1] - '0') * 10000;
71 start_time += (ad->cminute[0] - '0') * 1000;
72 start_time += (ad->cminute[1] - '0') * 100;
73 start_time += (ad->csecond[0] - '0') * 10;
74 start_time += ad->csecond[1] - '0';
76 nErr = vconf_set_int(VCONF_TIMER_START_TIME, start_time);
77 retvm_if(nErr != SUCCESS, FAILED, "vconf_set_int error");
78 vconf_sync_key(VCONF_TIMER_START_TIME);
83 * Debug function: to get which unit is focused last time
84 * This function requires data as parameters
86 * timer_vconf_load_focus_id()
87 * @param[in] data Pointer to user data, which contains the data of application
89 * @return indicate whether it succeed
91 int timer_vconf_load_focus_id(void *data)
93 retvm_if(!data, FAILED, "data null");
94 struct appdata *ad = (struct appdata *)data;
96 int panel_focus_id = 0;
98 nErr = vconf_get_int(VCONF_TIMER_PANEL_FOCUS_ID, &panel_focus_id);
99 retvm_if(nErr != SUCCESS, FAILED, "vconf_get_int error");
100 ad->entry_number = panel_focus_id;
105 * Debug function: to save which unit is focused
106 * This function requires data as parameters
108 * timer_vconf_set_focus_id()
109 * @param[in] data Pointer to user data, which contains the data of application
111 * @return indicate whether it succeed
113 int timer_vconf_set_focus_id(void *data)
115 retvm_if(!data, FAILED, "data null");
116 struct appdata *ad = (struct appdata *)data;
118 int panel_focus_id = ad->entry_number;
120 nErr = vconf_set_int(VCONF_TIMER_PANEL_FOCUS_ID, panel_focus_id);
121 retvm_if(nErr != SUCCESS, FAILED, "vconf_set_int error");
122 vconf_sync_key(VCONF_TIMER_PANEL_FOCUS_ID);
126 //***************************************************************
127 // when start counting ,call this function to register to alarm-manager
128 //***************************************************************
129 int timer_utils_register_alarm(void *data)
131 retvm_if(!data, FAILED, "data null");
134 struct appdata *ad = (struct appdata *)data;
137 timer_utils_unregister_alarm(data);
140 alert_t = time(NULL);
141 alert_t += ad->due_time.tv_sec;
143 AData *pAlarm = alarmdb_create_data();
144 retvm_if(!pAlarm, FAILED, "pAlarm null");
145 pAlarm->enable = ALARM_DB_ENABLE_ON;
146 pAlarm->author = ALARM_DB_AUTHOR_TIMER;
147 snprintf(pAlarm->name, sizeof(pAlarm->name), "%s",
148 STRING_TIMER_IDS_TMR_POP_TIME_IS_UP_);
149 pAlarm->stime = alert_t;
150 pAlarm->atime = alert_t;
151 pAlarm->repeat_once = EINA_TRUE;
152 pAlarm->volume = DEFAULT_ALARM_DB_VOLUME;
153 pAlarm->type = DEFAULT_ALARM_DB_TYPE;
155 snprintf(pAlarm->tone, sizeof(pAlarm->tone), "%s",
156 ALARM_SOUND_PATH "/" TIMER_DEF_TONE);
158 nErr = clk_fwk_alarmmgr_create(pAlarm);
159 CLK_GOTO_IF_RUN(nErr != SUCCESS, End, ret =
160 TIMER_POPUP_ID_ALARMMGR, "alarmapp_mgr_create error");
161 nErr = alarmdb_add_data(pAlarm);
162 CLK_GOTO_IF_RUN(IS_EQUAL(nErr, -1), End, ret =
163 TIMER_POPUP_ID_ALARMDB, "alarmdb_add_data error");
164 ad->alarm_mgr_id = pAlarm->alarm_mgr_id;
165 ad->slp_alarm_id = pAlarm->id;
168 alarmdb_free_data(pAlarm);
173 //***************************************************************
174 // when stop counting ,call this function to unregister to alarm-manager
175 //***************************************************************
176 int timer_utils_unregister_alarm(void *data)
178 retv_if(!data, FAILED);
180 ADList *list = alarmdb_get_data_list_by_author(ALARM_DB_AUTHOR_TIMER);
183 retv_if(!list, SUCCESS);
186 if (IS_EQUAL(alarm->enable, ALARM_DB_ENABLE_ON)) {
187 alarmmgr_remove_alarm(alarm->alarm_mgr_id);
191 alarmdb_del_data(alarm->id);
193 alarmdb_free_data_list(list);
198 * Debug function: to read time which is saved in vconf
199 * This function requires data as parameters
201 * _timer_utils_read_setting_time()
202 * @param[in] data Pointer to user data, which contains the data of application
206 int timer_utils_time_get(void *data)
208 retvm_if(!data, FAILED, "data null");
209 struct appdata *ad = (struct appdata *)data;
211 ad->due_time.tv_sec =
212 atoi(ad->chour) * 3600 + atoi(ad->cminute) * 60 +
213 atoi(ad->csecond) + 1;
214 ad->due_time.tv_usec = 0;
219 * Debug function: to check whether the start time is zero
220 * if all zero, return 1, else return 0;
221 * This function requires data as parameters
223 * _timer_utils_read_setting_time()
224 * @param[in] data Pointer to user data, which contains the data of application
228 Eina_Bool is_timer_utils_time_validate(struct appdata * ad)
230 retvm_if(NULL_CHECK(ad), EINA_FALSE, "ad null");
231 return IS_EQUAL(0, ad->due_time.tv_sec) ? EINA_FALSE : EINA_TRUE;
235 * Debug function: to read alarm info from server
236 * This function requires data as parameters
238 * timer_utils_read_alarm_state()
239 * @param[in] data Pointer to user data, which contains the data of application
241 * @return indicates whether it is successful.
243 TIMER_VIEW_PAGE timer_utils_read_alarm_state(void *data)
245 retvm_if(!data, TIMER_VIEW_PAGE_SETTING, "data null");
246 TIMER_VIEW_PAGE ret = TIMER_VIEW_PAGE_MAX;
247 struct appdata *ad = (struct appdata *)data;
249 AData *alarm_data = NULL;
251 ADList *list = alarmdb_get_data_list_by_author(ALARM_DB_AUTHOR_TIMER);
252 retv_if(!list, TIMER_VIEW_PAGE_SETTING);
253 ad->slp_alarm_id = list->ad.id;
254 alarmdb_free_data_list(list);
256 alarm_data = alarmdb_get_data(ad->slp_alarm_id);
257 retvm_if(!alarm_data, TIMER_VIEW_PAGE_SETTING, "get data error");
259 current_t = time(NULL);
260 if (alarm_data->atime < current_t) {
261 timer_utils_unregister_alarm(data);
262 ret = TIMER_VIEW_PAGE_SETTING;
264 ad->due_time.tv_sec = alarm_data->atime - current_t;
265 ad->due_time.tv_usec = 0;
266 ret = TIMER_VIEW_PAGE_MOTION;
268 alarmdb_free_data(alarm_data);
273 void set_default_time(struct appdata *ad)
275 retm_if(!ad, "ad null");
280 ad->cminute[0] = '0';
281 ad->cminute[1] = '1';
282 ad->cminute[2] = '\0';
284 ad->csecond[0] = '0';
285 ad->csecond[1] = '0';
286 ad->csecond[2] = '\0';
291 * This function is used to show views
292 * @param data[in] pointer to struct appdata
293 * @param bVisible[in] Eina_Bool to controlbar visible(EINA_TRUE) or invisible(EINA_FALSE)
294 * @return when success, return SUCCESS or FAILED if error
297 int timer_show_view(void *data, Eina_Bool bVisible)
299 retvm_if(!data, FAILED, "data null");
300 struct appdata *ad = (struct appdata *)data;
301 EVAS_OBJECT_SHOWIF(ad->layout);
302 //set controbbar visible
303 if (ad->controlbar_cb) {
304 (ad->controlbar_cb) (bVisible);
311 * This function is used to create popup
312 * @param parent[in] pointer to evas object parent
313 * @param result[in] int, popup type
317 void timer_widget_create_popup(Evas_Object * parent, TIMER_POPUP_ID id)
319 retm_if(!parent, "parent null");
320 char msg[BUF_SIZE_256] = { 0, };
323 case TIMER_POPUP_ID_ALARMMGR:
324 snprintf(msg, sizeof(msg), "%s",
325 STRING_TIMER_ALARM_SERVER_FAILED_);
327 case TIMER_POPUP_ID_ALARMDB:
328 snprintf(msg, sizeof(msg), "%s", STRING_TIMER_DB_FAILED_);
331 snprintf(msg, sizeof(msg), "%s",
332 STRING_TIMER_IDS_COM_POP_INTERNAL_ERROR_S_);
335 widget_create_popup(parent, msg, NULL, 1.0, NULL, NULL);
338 void timer_utils_view_change(struct appdata *ad)
341 TIMER_EFFECT_ID effect_id;
342 if (!IS_EQUAL(ad->page, TIMER_VIEW_PAGE_MOTION)) {
343 effect_id = TIMER_EFFECT_ID_LEFT;
344 timer_view_motion.create(ad);
345 elm_object_part_content_set(ad->eo_effect,
346 STRING_TIMER_ELM_SWALLOW_RIGHT,
347 ad->view_motion->eo_content);
349 effect_id = TIMER_EFFECT_ID_RIGHT;
350 timer_view_setting.create(ad);
351 elm_object_part_content_set(ad->eo_effect,
352 STRING_TIMER_ELM_SWALLOW_LEFT,
353 ad->view_setting->eo_content);
355 if (IS_EQUAL(ad->page, TIMER_VIEW_PAGE_MOTION)) {
356 timer_view_setting.destroy(ad);
357 Evas_Object *eo = elm_object_part_content_unset(ad->eo_effect,
358 STRING_TIMER_ELM_SWALLOW_RIGHT);
359 elm_object_part_content_set(ad->eo_effect,
360 STRING_TIMER_ELM_SWALLOW_CENTER,
363 timer_view_motion.destroy(ad);
364 Evas_Object *eo = elm_object_part_content_unset(ad->eo_effect,
365 STRING_TIMER_ELM_SWALLOW_LEFT);
366 elm_object_part_content_set(ad->eo_effect,
367 STRING_TIMER_ELM_SWALLOW_CENTER,
372 void timer_repaint_time(void *data)
374 retm_if(NULL_CHECK(data), "data null");
375 struct appdata *ad = (struct appdata *)data;
376 motion_view *view = ad->view_motion;
377 retm_if(NULL_CHECK(view), "view null");
378 struct timeval time_past = { 0, };
379 char time_str[BUF_SIZE] = { 0, };
383 ad->current_systime.tv_sec - ad->start_systime.tv_sec;
385 ad->current_systime.tv_usec - ad->start_systime.tv_usec;
386 if ((time_past.tv_sec) && (time_past.tv_usec < 0)) {
387 time_past.tv_sec -= 1;
388 time_past.tv_usec += 1000000;
390 //reduce due-time according to time passed
391 ad->due_time.tv_sec -= time_past.tv_sec;
392 ad->due_time.tv_usec -= time_past.tv_usec;
393 if ((ad->due_time.tv_sec) && (ad->due_time.tv_usec < 0)) {
394 ad->due_time.tv_sec -= 1;
395 ad->due_time.tv_usec += 1000000;
398 gmtime_r(&ad->due_time.tv_sec, &show_time);
400 strftime(time_str, BUF_SIZE, "%02H:%02M:%S", &show_time);
401 edje_object_part_text_set(_EDJ(view->eo_content),
402 STRING_TIMER_MOTION_TIME, time_str);