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://floralicense.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.
23 #include "edc_string.h"
24 #include "camera_utils.h"
25 #include "cam_property.h"
26 #include "cam_toolbar_edc_callback.h"
27 #include "cam_recording_edc_callback.h"
29 #define REC_ICON_TIMER_INTERVAL (1)
30 #define REC_TIMER_INTERVAL (0.5)
31 #define PAUSE_TIMER_INTERVAL (0.5)
32 #define PAUSE_TIMEOUT (120)
33 #define SECONDS_IN_HOUR (1*60*60)
36 CAM_REC_STATE_RECORDING,
39 #define TIME_FORMAT_MAX_LEN (128)
40 /* static int rec_state = CAM_REC_STATE_RECORDING; */
41 static double paused_time = 0.0;
42 Eina_Bool recording_update_time_cb(void *data);
43 Eina_Bool recording_update_icon_cb(void *data);
44 Eina_Bool pause_timeout_cb(void *data);
46 static void __recording_set_state(void *data, int new_state)
49 struct appdata *ad = (struct appdata *)data;
50 cam_ret_if(ad == NULL);
52 if (new_state == CAM_REC_STATE_RECORDING) {
53 if (ad->rec_time_updater) {
54 ecore_timer_thaw(ad->rec_time_updater);
56 if (ad->rec_icon_updater) {
57 ecore_timer_thaw(ad->rec_icon_updater);
59 if (ad->rec_pause_timer) {
60 ecore_timer_del(ad->rec_pause_timer);
61 ad->rec_pause_timer = NULL;
63 edje_object_signal_emit(_EDJ(ad->recording_edje), "state,rec", "program");
64 } else if (new_state == CAM_REC_STATE_PAUSE) {
65 if (ad->rec_time_updater) {
66 ecore_timer_freeze(ad->rec_time_updater);
68 if (ad->rec_icon_updater) {
69 ecore_timer_freeze(ad->rec_icon_updater);
71 if (ad->rec_pause_timer) {
72 ecore_timer_del(ad->rec_pause_timer);
73 ad->rec_pause_timer = NULL;
76 ad->rec_pause_timer = ecore_timer_add(REC_TIMER_INTERVAL, pause_timeout_cb, ad);
77 edje_object_signal_emit(_EDJ(ad->recording_edje), "state,pause", "program");
79 ad->recording_state = new_state;
82 /* you can use this function to set time text for recording */
83 void recording_set_time(void *data, int hh, int mm, int ss)
86 struct appdata *ad = (struct appdata *)data;
87 if (ad->recording_edje) {
88 char time_text[100] = "";
89 snprintf(time_text, sizeof(time_text), "%" CAM_TIME_FORMAT "", hh, mm, ss);
90 edje_object_part_text_set(_EDJ(ad->recording_edje), RECORDING_TEXT, time_text);
94 Eina_Bool pause_timeout_cb(void *data)
96 struct appdata *ad = (struct appdata *)data;
97 cam_retv_if(ad == NULL, FALSE);
98 CamAppData *camapp = NULL;
99 camapp = ad->camapp_handle;
100 if (camapp == NULL) {
101 if (ad->rec_pause_timer)
102 ad->rec_pause_timer = NULL;
103 return ECORE_CALLBACK_CANCEL;
106 paused_time += PAUSE_TIMER_INTERVAL;
107 if (paused_time >= PAUSE_TIMEOUT) {
108 camapp->rec_stop_type = CAM_REC_STOP_NORMAL;
109 ad->recording_commit = ecore_idler_add(cam_video_idler_record_stop, ad);
111 if (ad->rec_pause_timer)
112 ad->rec_pause_timer = NULL;
113 return ECORE_CALLBACK_CANCEL;
115 if (ad->recording_edje) {
116 const char *state = edje_object_part_state_get(_EDJ(ad->recording_edje), RECORDING_IMAGE, NULL);
118 if (strcmp(state, "pause") == 0) {
119 edje_object_signal_emit(_EDJ(ad->recording_edje), "indicator,hide", "program");
120 } else if (strcmp(state, "invisible") == 0) {
121 edje_object_signal_emit(_EDJ(ad->recording_edje), "indicator,show", "program");
124 return ECORE_CALLBACK_RENEW;
127 Eina_Bool recording_update_icon_cb(void *data)
129 struct appdata *ad = (struct appdata *)data;
130 static int count = 0;
132 cam_critical(LOG_UI, "appdata is NULL");
133 /* ad->rec_icon_updater = NULL; */
134 return ECORE_CALLBACK_CANCEL;
137 edje_object_signal_emit(_EDJ(ad->recording_edje), "state,rec", "program");
139 edje_object_signal_emit(_EDJ(ad->recording_edje), "state,rec1", "program");
142 return ECORE_CALLBACK_RENEW;
145 Eina_Bool recording_update_time_cb(void *data)
148 struct appdata *ad = (struct appdata *)data;
149 CamAppData *camapp = NULL;
151 cam_critical(LOG_UI, "appdata is NULL");
152 return ECORE_CALLBACK_CANCEL;
154 camapp = ad->camapp_handle;
155 if (camapp == NULL) {
156 cam_critical(LOG_UI, "cam_handle is NULL");
157 ad->rec_time_updater = NULL;
158 return ECORE_CALLBACK_CANCEL;
160 char time_text[100] = "";
161 if (camapp->rec_elapsed < SECONDS_IN_HOUR)
162 snprintf(time_text, sizeof(time_text), "%" CAM_TIME_FORMAT "", CAM_TIME_ARGS(camapp->rec_elapsed));
164 snprintf(time_text, sizeof(time_text), "%" CAM_TIME_FORMAT2 "", CAM_TIME_ARGS2(camapp->rec_elapsed));
165 cam_debug(LOG_UI, "current time %s", time_text);
166 if (ad->recording_edje) {
167 edje_object_part_text_set(_EDJ(ad->recording_edje), RECORDING_TEXT, _(time_text));
170 if (camapp->size_limit != CAM_REC_NORMAL_MAX_SIZE) {
173 char *filename = NULL;
174 int fname_size = 0;/*unused*/
175 guint64 size_limit = 0;
176 gdouble pbar_position = 0.0;
177 gdouble size_limit_in_mega = 0.0;
178 gdouble rec_filesize_in_mega = 0.0;
179 cam_mm_get_filename(&filename, &fname_size);
180 if (camapp->rec_filesize) {
181 size_limit = (guint64)camapp->size_limit;
182 pbar_position = camapp->rec_filesize / (gdouble) size_limit;
183 cam_app_set_progressbar_value(ad, pbar_position);
185 if (camapp->size_limit < 1024) {
186 snprintf(str, sizeof(str), "%dK", camapp->size_limit);
188 size_limit_in_mega = (gdouble)camapp->size_limit/(gdouble)1024;
189 snprintf(str, sizeof(str), "%.1fM", size_limit_in_mega);
192 if (camapp->rec_filesize < 1024) {
193 snprintf(str2, sizeof(str2), "%dK", camapp->rec_filesize);
195 rec_filesize_in_mega = (gdouble)camapp->rec_filesize/(gdouble)1024;
196 snprintf(str2, sizeof(str2), "%.1fM", rec_filesize_in_mega);
199 edje_object_part_text_set(_EDJ(ad->recording_edje), "progressbar_text", str);
200 edje_object_part_text_set(_EDJ(ad->recording_edje), "file_size_text", str2);
204 gchar * target_path = NULL;
205 target_path = (gchar*)cam_app_get_target_path();
207 if (target_path != NULL) {
208 gint64 free_space = cam_get_free_space(target_path);
209 gint64 capacity_space = cam_get_capacity_space(target_path);
210 ration = (double)free_space/(double)capacity_space;
212 DEBUG_TRACE("ration : %f ", ration);
215 char time_left_text[TIME_FORMAT_MAX_LEN + 1] = { '\0', };
216 guint64 remain_rec_time = 0;
217 remain_rec_time = cam_system_get_remain_rec_time((void*)ad);
218 DEBUG_TRACE("%d",remain_rec_time);
219 if (remain_rec_time < SECONDS_IN_HOUR) {
220 snprintf(time_left_text, TIME_FORMAT_MAX_LEN, "%" CAM_TIME_FORMAT "", CAM_TIME_ARGS(remain_rec_time));
221 DEBUG_TRACE("%s",time_left_text);
223 snprintf(time_left_text, TIME_FORMAT_MAX_LEN, "%" CAM_TIME_FORMAT2 "", CAM_TIME_ARGS2(remain_rec_time));
224 DEBUG_TRACE("%s",time_left_text);
226 edje_object_part_text_set(_EDJ(ad->recording_edje), RECORDING_LEFT_TEXT, _(time_left_text));
229 edje_object_part_text_set(_EDJ(ad->recording_edje), RECORDING_LEFT_TEXT, _(""));
231 return ECORE_CALLBACK_RENEW;
234 int load_recording_edje(struct appdata *ad)
236 CamAppData *camapp = NULL;
237 cam_retvm_if(ad == NULL, EXIT_FAILURE, "appdata is NULL");
238 camapp = ad->camapp_handle;
239 cam_retvm_if(camapp == NULL, EXIT_FAILURE, "cam_handle is NULL");
241 cam_toolbar_update(ad);
242 DEL_EVAS_OBJECT(ad->recording_edje);
244 elm_object_part_content_unset(ad->ug_base, "recording_layout");
246 DEBUG_TRACE("ad->target_direction %d", ad->target_direction);
247 switch (ad->target_direction) {
248 case CAM_TARGET_DIRECTION_LANDSCAPE:
249 ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_EDJ_NAME, "recording_layout");
251 case CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE:
252 ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_INVERSE_EDJ_NAME, "recording_layout");
254 case CAM_TARGET_DIRECTION_PORTRAIT:
255 ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_VERTICAL_EDJ_NAME, "recording_layout");
257 case CAM_TARGET_DIRECTION_PORTRAIT_INVERSE:
258 ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_VERTICAL_INVERSE_EDJ_NAME, "recording_layout");
261 DEBUG_TRACE("note:reach un-able reached codes");
264 cam_retv_if(ad->recording_edje == NULL, -1);
265 elm_object_part_content_set(ad->ug_base, "recording_layout", ad->recording_edje);
267 if (camapp->size_limit != CAM_REC_NORMAL_MAX_SIZE) {
270 gdouble size_limit_in_mega = 0.0;
271 camapp->rec_filesize =0;
273 if (camapp->size_limit < 1024) {
274 snprintf(str, sizeof(str), "%dK", camapp->size_limit);
276 size_limit_in_mega = (gdouble)camapp->size_limit/(gdouble)1024;
277 snprintf(str, sizeof(str), "%.1fM", size_limit_in_mega);
280 snprintf(str2, sizeof(str), "%dK", 0);
281 cam_app_create_progressbar(ad);
283 /* cam_app_set_progressbar_value(ad, 0.0); */
284 elm_object_part_content_set(ad->recording_edje, "progressbar", ad->progressbar);
285 edje_object_part_text_set(_EDJ(ad->recording_edje), "progressbar_text", str);
286 edje_object_part_text_set(_EDJ(ad->recording_edje), "file_size_text", str2);
288 camapp->rec_elapsed = 0;
289 __recording_set_state(ad, CAM_REC_STATE_RECORDING);
290 recording_set_time(ad, 0, 0, 0);
291 if (ad->rec_time_updater != NULL)
292 ecore_timer_del(ad->rec_time_updater);
293 if (ad->rec_icon_updater != NULL)
294 ecore_timer_del(ad->rec_icon_updater);
295 ad->rec_time_updater = ecore_timer_add(REC_TIMER_INTERVAL, recording_update_time_cb, ad);
296 ad->rec_icon_updater = ecore_timer_add(REC_ICON_TIMER_INTERVAL, recording_update_icon_cb, ad);
301 int unload_recording_edje(struct appdata *ad)
303 cam_retv_if(ad == NULL, -1);
304 cam_app_destroy_progressbar(ad);
305 DEL_EVAS_OBJECT(ad->recording_edje);
306 REMOVE_TIMER(ad->rec_time_updater);
307 REMOVE_TIMER(ad->rec_icon_updater);
309 cam_toolbar_update(ad);
314 int cam_recording_rotate(struct appdata *ad)
316 cam_retv_if(ad == NULL, -1);
317 CamAppData *camapp = ad->camapp_handle;
318 cam_retvm_if(camapp == NULL, EXIT_FAILURE, "cam_handle is NULL");
320 evas_object_hide(ad->indicator_edje);
321 elm_object_part_content_unset(ad->recording_edje, "progressbar");
322 evas_object_hide(ad->progressbar);
323 DEL_EVAS_OBJECT(ad->recording_edje);
325 elm_object_part_content_unset(ad->ug_base, "recording_layout");
327 switch (ad->target_direction) {
328 case CAM_TARGET_DIRECTION_LANDSCAPE:
329 ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_EDJ_NAME, "recording_layout");
331 case CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE:
332 ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_INVERSE_EDJ_NAME, "recording_layout");
334 case CAM_TARGET_DIRECTION_PORTRAIT:
335 ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_VERTICAL_EDJ_NAME, "recording_layout");
337 case CAM_TARGET_DIRECTION_PORTRAIT_INVERSE:
338 ad->recording_edje = cam_app_load_edj(ad->ug_base, CAM_RECORDING_VERTICAL_INVERSE_EDJ_NAME, "recording_layout");
341 DEBUG_TRACE("note:reach un-able reached codes");
344 cam_retv_if(ad->recording_edje == NULL, -1);
345 elm_object_part_content_set(ad->ug_base, "recording_layout", ad->recording_edje);
347 if (ad->recording_state == CAM_REC_STATE_RECORDING) {
348 edje_object_signal_emit(_EDJ(ad->recording_edje), "state,rec", "program");
349 } else if (ad->recording_state == CAM_REC_STATE_PAUSE) {
350 edje_object_signal_emit(_EDJ(ad->recording_edje), "state,pause", "program");
352 char time_text[100] = "";
353 if (camapp->rec_elapsed < 3600)
354 snprintf(time_text, sizeof(time_text), "%" CAM_TIME_FORMAT "",
355 CAM_TIME_ARGS(camapp->rec_elapsed));
357 snprintf(time_text, sizeof(time_text), "%" CAM_TIME_FORMAT2 "",
358 CAM_TIME_ARGS2(camapp->rec_elapsed));
359 cam_debug(LOG_UI, "current time %s", time_text);
360 if (ad->recording_edje) {
361 edje_object_part_text_set(_EDJ(ad->recording_edje), RECORDING_TEXT, _(time_text));
363 if (ad->progressbar) {
366 char *filename = NULL;
368 guint64 size_limit = 0;
369 gdouble pbar_position = 0.0;
370 cam_mm_get_filename(&filename, &fname_size);
371 if (camapp->rec_filesize) {
372 size_limit = (guint64)camapp->size_limit;
373 pbar_position =camapp->rec_filesize/ (double)size_limit;
374 cam_app_set_progressbar_value(ad, pbar_position);
375 snprintf(str, sizeof(str), "%dK", camapp->size_limit);
376 snprintf(str2, sizeof(str2), "%dK", camapp->rec_filesize);
377 elm_object_part_content_set(ad->recording_edje, "progressbar", ad->progressbar);
378 edje_object_part_text_set(_EDJ(ad->recording_edje), "progressbar_text", str);
379 edje_object_part_text_set(_EDJ(ad->recording_edje), "progressbar_text", str2);