2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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 "timer_utils.h"
18 #include "clock_fwk_widget.h"
20 * Debug function: to read time setted last time
21 * This function requires data as parameters
23 * timer_vconf_load_start_time()
24 * @param[in] data Pointer to user data, which contains the data of application
26 * @return indicate whether it succeed
28 int timer_vconf_load_start_time(void *data)
30 retvm_if(!data, FAILED, "data null");
31 struct appdata *ad = (struct appdata *)data;
35 nErr = vconf_get_int(VCONF_TIMER_START_TIME, &start_time);
36 retvm_if(nErr != SUCCESS, FAILED, "vconf_get_int error");
38 ad->chour[0] = '0' + (start_time / 100000) % 10;
39 ad->chour[1] = '0' + (start_time / 10000) % 10;
42 ad->cminute[0] = '0' + (start_time / 1000) % 10;
43 ad->cminute[1] = '0' + (start_time / 100) % 10;
44 ad->cminute[2] = '\0';
46 ad->csecond[0] = '0' + (start_time / 10) % 10;
47 ad->csecond[1] = '0' + start_time % 10;
48 ad->csecond[2] = '\0';
53 * Debug function: to save the setted time
54 * This function requires data as parameters
56 * timer_vconf_set_start_time()
57 * @param[in] data Pointer to user data, which contains the data of application
59 * @return indicate whether it succeed
61 int timer_vconf_set_start_time(void *data)
63 retvm_if(!data, FAILED, "data null");
64 struct appdata *ad = (struct appdata *)data;
68 start_time += (ad->chour[0] - '0') * 100000;
69 start_time += (ad->chour[1] - '0') * 10000;
70 start_time += (ad->cminute[0] - '0') * 1000;
71 start_time += (ad->cminute[1] - '0') * 100;
72 start_time += (ad->csecond[0] - '0') * 10;
73 start_time += ad->csecond[1] - '0';
75 nErr = vconf_set_int(VCONF_TIMER_START_TIME, start_time);
76 retvm_if(nErr != SUCCESS, FAILED, "vconf_set_int error");
77 vconf_sync_key(VCONF_TIMER_START_TIME);
82 * Debug function: to get which unit is focused last time
83 * This function requires data as parameters
85 * timer_vconf_load_focus_id()
86 * @param[in] data Pointer to user data, which contains the data of application
88 * @return indicate whether it succeed
90 int timer_vconf_load_focus_id(void *data)
92 retvm_if(!data, FAILED, "data null");
93 struct appdata *ad = (struct appdata *)data;
95 int panel_focus_id = 0;
97 nErr = vconf_get_int(VCONF_TIMER_PANEL_FOCUS_ID, &panel_focus_id);
98 retvm_if(nErr != SUCCESS, FAILED, "vconf_get_int error");
99 ad->entry_number = panel_focus_id;
104 * Debug function: to save which unit is focused
105 * This function requires data as parameters
107 * timer_vconf_set_focus_id()
108 * @param[in] data Pointer to user data, which contains the data of application
110 * @return indicate whether it succeed
112 int timer_vconf_set_focus_id(void *data)
114 retvm_if(!data, FAILED, "data null");
115 struct appdata *ad = (struct appdata *)data;
117 int panel_focus_id = ad->entry_number;
119 nErr = vconf_set_int(VCONF_TIMER_PANEL_FOCUS_ID, panel_focus_id);
120 retvm_if(nErr != SUCCESS, FAILED, "vconf_set_int error");
121 vconf_sync_key(VCONF_TIMER_PANEL_FOCUS_ID);
125 //***************************************************************
126 // when start counting ,call this function to register to alarm-manager
127 //***************************************************************
128 int timer_utils_register_alarm(void *data)
130 retvm_if(!data, FAILED, "data null");
133 struct appdata *ad = (struct appdata *)data;
136 timer_utils_unregister_alarm(data);
139 alert_t = time(NULL);
140 alert_t += ad->due_time.tv_sec;
142 AData *pAlarm = alarmdb_create_data();
143 retvm_if(!pAlarm, FAILED, "pAlarm null");
144 pAlarm->enable = ALARM_DB_ENABLE_ON;
145 pAlarm->author = ALARM_DB_AUTHOR_TIMER;
146 snprintf(pAlarm->name, sizeof(pAlarm->name), "%s",
147 STRING_TIMER_IDS_TMR_POP_TIME_IS_UP_);
148 pAlarm->stime = alert_t;
149 pAlarm->atime = alert_t;
150 pAlarm->repeat_once = EINA_TRUE;
151 pAlarm->volume = DEFAULT_ALARM_DB_VOLUME;
152 pAlarm->type = DEFAULT_ALARM_DB_TYPE;
154 snprintf(pAlarm->tone, sizeof(pAlarm->tone), "%s",
155 ALARM_SOUND_PATH "/" TIMER_DEF_TONE);
157 nErr = clk_fwk_alarmmgr_create(pAlarm);
158 CLK_GOTO_IF_RUN(nErr != SUCCESS, End, ret =
159 TIMER_POPUP_ID_ALARMMGR, "alarmapp_mgr_create error");
160 nErr = alarmdb_add_data(pAlarm);
161 CLK_GOTO_IF_RUN(IS_EQUAL(nErr, -1), End, ret =
162 TIMER_POPUP_ID_ALARMDB, "alarmdb_add_data error");
163 ad->alarm_mgr_id = pAlarm->alarm_mgr_id;
164 ad->slp_alarm_id = pAlarm->id;
167 alarmdb_free_data(pAlarm);
172 //***************************************************************
173 // when stop counting ,call this function to unregister to alarm-manager
174 //***************************************************************
175 int timer_utils_unregister_alarm(void *data)
177 retv_if(!data, FAILED);
179 ADList *list = alarmdb_get_data_list_by_author(ALARM_DB_AUTHOR_TIMER);
182 retv_if(!list, SUCCESS);
185 if (IS_EQUAL(alarm->enable, ALARM_DB_ENABLE_ON)) {
186 alarmmgr_remove_alarm(alarm->alarm_mgr_id);
190 alarmdb_del_data(alarm->id);
192 alarmdb_free_data_list(list);
197 * Debug function: to read time which is saved in vconf
198 * This function requires data as parameters
200 * _timer_utils_read_setting_time()
201 * @param[in] data Pointer to user data, which contains the data of application
205 int timer_utils_time_get(void *data)
207 retvm_if(!data, FAILED, "data null");
208 struct appdata *ad = (struct appdata *)data;
210 ad->due_time.tv_sec =
211 atoi(ad->chour) * 3600 + atoi(ad->cminute) * 60 +
212 atoi(ad->csecond) + 1;
213 ad->due_time.tv_usec = 0;
218 * Debug function: to check whether the start time is zero
219 * if all zero, return 1, else return 0;
220 * This function requires data as parameters
222 * _timer_utils_read_setting_time()
223 * @param[in] data Pointer to user data, which contains the data of application
227 Eina_Bool is_timer_utils_time_validate(struct appdata * ad)
229 retvm_if(NULL_CHECK(ad), EINA_FALSE, "ad null");
230 return IS_EQUAL(0, ad->due_time.tv_sec) ? EINA_FALSE : EINA_TRUE;
234 * Debug function: to read alarm info from server
235 * This function requires data as parameters
237 * timer_utils_read_alarm_state()
238 * @param[in] data Pointer to user data, which contains the data of application
240 * @return indicates whether it is successful.
242 TIMER_VIEW_PAGE timer_utils_read_alarm_state(void *data)
244 retvm_if(!data, TIMER_VIEW_PAGE_SETTING, "data null");
245 TIMER_VIEW_PAGE ret = TIMER_VIEW_PAGE_MAX;
246 struct appdata *ad = (struct appdata *)data;
248 AData *alarm_data = NULL;
250 ADList *list = alarmdb_get_data_list_by_author(ALARM_DB_AUTHOR_TIMER);
251 retv_if(!list, TIMER_VIEW_PAGE_SETTING);
252 ad->slp_alarm_id = list->ad.id;
253 alarmdb_free_data_list(list);
255 alarm_data = alarmdb_get_data(ad->slp_alarm_id);
256 retvm_if(!alarm_data, TIMER_VIEW_PAGE_SETTING, "get data error");
258 current_t = time(NULL);
259 if (alarm_data->atime < current_t) {
260 timer_utils_unregister_alarm(data);
261 ret = TIMER_VIEW_PAGE_SETTING;
263 ad->due_time.tv_sec = alarm_data->atime - current_t;
264 ad->due_time.tv_usec = 0;
265 ret = TIMER_VIEW_PAGE_MOTION;
267 alarmdb_free_data(alarm_data);
272 void set_default_time(struct appdata *ad)
274 retm_if(!ad, "ad null");
279 ad->cminute[0] = '0';
280 ad->cminute[1] = '1';
281 ad->cminute[2] = '\0';
283 ad->csecond[0] = '0';
284 ad->csecond[1] = '0';
285 ad->csecond[2] = '\0';
290 * This function is used to show views
291 * @param data[in] pointer to struct appdata
292 * @param bVisible[in] Eina_Bool to controlbar visible(EINA_TRUE) or invisible(EINA_FALSE)
293 * @return when success, return SUCCESS or FAILED if error
296 int timer_show_view(void *data, Eina_Bool bVisible)
298 retvm_if(!data, FAILED, "data null");
299 struct appdata *ad = (struct appdata *)data;
300 EVAS_OBJECT_SHOWIF(ad->layout);
301 //set controbbar visible
302 if (ad->controlbar_cb) {
303 (ad->controlbar_cb) (bVisible);
310 * This function is used to create popup
311 * @param parent[in] pointer to evas object parent
312 * @param result[in] int, popup type
316 void timer_widget_create_popup(Evas_Object * parent, TIMER_POPUP_ID id)
318 retm_if(!parent, "parent null");
319 char msg[BUF_SIZE_256] = { 0, };
322 case TIMER_POPUP_ID_ALARMMGR:
323 snprintf(msg, sizeof(msg), "%s",
324 STRING_TIMER_ALARM_SERVER_FAILED_);
326 case TIMER_POPUP_ID_ALARMDB:
327 snprintf(msg, sizeof(msg), "%s", STRING_TIMER_DB_FAILED_);
330 snprintf(msg, sizeof(msg), "%s",
331 STRING_TIMER_IDS_COM_POP_INTERNAL_ERROR_S_);
334 widget_create_popup(parent, msg, NULL, 1.0, NULL, NULL);
337 void timer_utils_create_effect(Evas_Object * eo_obj, TIMER_EFFECT_ID id,
338 Elm_Transit_Del_Cb on_done, void *data)
341 Evas_Coord ec_mov = IS_EQUAL(id, TIMER_EFFECT_ID_LEFT) ? -480 : 480;
342 Elm_Transit *transit = elm_transit_add();
343 // elm_transit_objects_final_state_keep_set(transit, EINA_TRUE);
344 elm_transit_object_add(transit, eo_obj);
345 elm_transit_effect_translation_add(transit, 0, 0, ec_mov, 0);
346 elm_transit_tween_mode_set(transit, ELM_TRANSIT_TWEEN_MODE_LINEAR);
347 elm_transit_duration_set(transit, 0.8);
348 elm_transit_del_cb_set(transit, on_done, data);
349 elm_transit_go(transit);
352 void timer_transit_done_Cb(void *data, Elm_Transit * transit)
355 struct appdata *ad = (struct appdata *)data;
356 if (IS_EQUAL(ad->page, TIMER_VIEW_PAGE_MOTION)) {
357 timer_view_setting.destroy(ad);
358 Evas_Object *eo = elm_object_part_content_unset(ad->eo_effect,
359 STRING_TIMER_ELM_SWALLOW_RIGHT);
360 elm_object_part_content_set(ad->eo_effect,
361 STRING_TIMER_ELM_SWALLOW_CENTER,
364 timer_view_motion.destroy(ad);
365 Evas_Object *eo = elm_object_part_content_unset(ad->eo_effect,
366 STRING_TIMER_ELM_SWALLOW_LEFT);
367 elm_object_part_content_set(ad->eo_effect,
368 STRING_TIMER_ELM_SWALLOW_CENTER,
373 void timer_utils_view_change(struct appdata *ad)
376 TIMER_EFFECT_ID effect_id;
377 if (!IS_EQUAL(ad->page, TIMER_VIEW_PAGE_MOTION)) {
378 effect_id = TIMER_EFFECT_ID_LEFT;
379 timer_view_motion.create(ad);
380 elm_object_part_content_set(ad->eo_effect,
381 STRING_TIMER_ELM_SWALLOW_RIGHT,
382 ad->view_motion->eo_content);
384 effect_id = TIMER_EFFECT_ID_RIGHT;
385 timer_view_setting.create(ad);
386 elm_object_part_content_set(ad->eo_effect,
387 STRING_TIMER_ELM_SWALLOW_LEFT,
388 ad->view_setting->eo_navibar);
390 timer_utils_create_effect(ad->eo_effect, effect_id,
391 timer_transit_done_Cb, ad);
394 void timer_repaint_time(void *data)
396 retm_if(NULL_CHECK(data), "data null");
397 struct appdata *ad = (struct appdata *)data;
398 motion_view *view = ad->view_motion;
399 retm_if(NULL_CHECK(view), "view null");
400 struct timeval time_past = { 0, };
401 char time_str[BUF_SIZE] = { 0, };
405 ad->current_systime.tv_sec - ad->start_systime.tv_sec;
407 ad->current_systime.tv_usec - ad->start_systime.tv_usec;
408 if ((time_past.tv_sec) && (time_past.tv_usec < 0)) {
409 time_past.tv_sec -= 1;
410 time_past.tv_usec += 1000000;
412 //reduce due-time according to time passed
413 ad->due_time.tv_sec -= time_past.tv_sec;
414 ad->due_time.tv_usec -= time_past.tv_usec;
415 if ((ad->due_time.tv_sec) && (ad->due_time.tv_usec < 0)) {
416 ad->due_time.tv_sec -= 1;
417 ad->due_time.tv_usec += 1000000;
420 gmtime_r(&ad->due_time.tv_sec, &show_time);
422 strftime(time_str, BUF_SIZE, "%02H:%02M:%S", &show_time);
423 edje_object_part_text_set(_EDJ(view->eo_content),
424 STRING_TIMER_MOTION_TIME, time_str);
426 char tmp_path[BUF_SIZE_256] = { 0, };
427 snprintf(tmp_path, sizeof(tmp_path),
428 IMAGES_PATH_HOUR STRING_TIMER_P03_TIMER_CLK_BG_02D_PNG,
429 show_time.tm_hour % 13);
430 elm_icon_file_set(view->eo_icon_hour, tmp_path, NULL);
431 snprintf(tmp_path, sizeof(tmp_path),
433 STRING_TIMER_P03_TIMER_CLK_SECOND_01_02D_PNG,
434 show_time.tm_min % 60);
435 elm_icon_file_set(view->eo_icon_min, tmp_path, NULL);
436 snprintf(tmp_path, sizeof(tmp_path),
438 STRING_TIMER_P03_TIMER_CLK_SECOND_02_02D_PNG,
439 show_time.tm_sec % 60);
440 elm_icon_file_set(view->eo_icon_sec, tmp_path, NULL);