Tizen 2.1 base
[apps/core/preloaded/ug-camera-efl.git] / src / edc-callback / cam_indicator_edc_callback.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
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
18 #include <stdio.h>
19 #include "camera_utils.h"
20
21 #include "cam_indicator_edc_callback.h"
22 #include "cam_common_edc_callback.h"
23 #include "cam_lbs.h"
24 #include "edc_string.h"
25 #include "edc_image_name.h"
26
27 #define CHARGING_INTERVAL       (0.5)
28 #define SECONDS_IN_HOUR (1*60*60)
29 #define SECONDS_RECORDING_MAX ((99*60*60)+(99*60)+99)
30
31 static char *storage_image[CAM_STORAGE_NUM] = {
32         INDICATOR_STORAGE_INTERNAL_ICON,
33         INDICATOR_STORAGE_CARD_ICON,
34         INDICATOR_STORAGE_INTERNAL_ICON,
35 };
36
37 #define CAM_BATTERY_LEVEL_MAX 8
38 static char *battery_image[CAM_BATTERY_LEVEL_MAX] = {
39         INDICATOR_BATTERY_LEVEL_00_ICON,
40         INDICATOR_BATTERY_LEVEL_01_ICON,
41         INDICATOR_BATTERY_LEVEL_02_ICON,
42         INDICATOR_BATTERY_LEVEL_03_ICON,
43         INDICATOR_BATTERY_LEVEL_04_ICON,
44         INDICATOR_BATTERY_LEVEL_05_ICON,
45         INDICATOR_BATTERY_FULL_ICON,
46         INDICATOR_BATTERY_CHARGE_ICON,
47 };
48
49 static char *gps_level_image[CAM_LBS_STATE_NUM] = {
50         INDICATOR_GPS_STATE_OFF_ICON,
51         INDICATOR_GPS_STATE_ON_ICON,
52         INDICATOR_GPS_STATE_CONNECT_ANI01_ICON,
53         INDICATOR_GPS_STATE_CONNECT_ANI02_ICON,
54         INDICATOR_GPS_STATE_CONNECT_ANI03_ICON,
55 };
56
57 static char *mute_image = INDICATOR_MUTE_ICON;
58
59 static Evas_Object *indicator_image_obj_battery = NULL;
60 static Evas_Object *indicator_image_obj_storage = NULL;
61 static Evas_Object *indicator_image_obj_gps_level = NULL;
62 static Evas_Object *indicator_image_obj_mute = NULL;
63
64
65 void indicator_update_storage(struct appdata *ad)
66 {
67         int mmc_state = -1;
68         debug_fenter(LOG_UI);
69         cam_retm_if(ad == NULL, "appdata is NULL");
70         cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
71         cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
72         const char *image_file = NULL;
73
74         vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_CAMERA_INT, &(ad->camapp_handle->storage));
75
76         if (ad->camapp_handle->storage == CAM_STORAGE_EXTERNAL) {
77                 if (!vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmc_state)) {
78                         if (mmc_state == VCONFKEY_SYSMAN_MMC_REMOVED) {
79                                 cam_info(LOG_UI, "MMC card is removed");
80                                 GValue value = { 0 };
81                                 CAM_GVALUE_SET_INT(value, CAM_STORAGE_INTERNAL);
82                                 cam_handle_value_set(ad, PROP_STORAGE, &value);
83                         }
84                 }
85         }
86
87         switch (ad->camapp_handle->storage) {
88         case CAM_STORAGE_INTERNAL:
89                 image_file = storage_image[CAM_STORAGE_INTERNAL];
90                 break;
91         case CAM_STORAGE_EXTERNAL:
92                 image_file = storage_image[CAM_STORAGE_EXTERNAL];
93                 break;
94         default:
95                 break;
96         }
97
98         if (!indicator_image_obj_storage) {
99                 indicator_image_obj_storage = elm_image_add(ad->indicator_edje);
100         }
101
102         cam_retm_if(indicator_image_obj_storage == NULL,
103                     "indicator_image_obj_storage is NULL");
104         elm_image_file_set(indicator_image_obj_storage, CAM_IMAGE_EDJ_NAME, image_file);
105
106         if (ad->camapp_handle->camera_mode == CAM_CAMCORDER_MODE
107                 && ad->is_recording == TRUE)
108                 edje_object_part_swallow(_EDJ(ad->indicator_edje), INDI_REC_STORAGE,
109                                  indicator_image_obj_storage);
110         else
111                 edje_object_part_swallow(_EDJ(ad->indicator_edje), INDICATOR_STORAGE,
112                                  indicator_image_obj_storage);
113
114         ad->remained_count = cam_system_get_still_count_by_resolution(ad);
115         indicator_update_remain_count(ad);
116 }
117
118 void indicator_update_gps_level(struct appdata *ad)
119 {
120         debug_fenter(LOG_UI);
121         cam_retm_if(ad == NULL, "appdata is NULL");
122         CamAppData *camapp = ad->camapp_handle;
123         cam_retm_if(camapp == NULL, "camapp is NULL");
124         cam_ret_if(ad->toolbar_hided);
125         cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
126         const char *image_file = NULL;
127         /*DEBUG_TRACE("====level : %d", ad->gps_level);*/
128         switch (camapp->gps_level) {
129         case CAM_LBS_STATE_DISABLE:
130                 image_file = gps_level_image[CAM_LBS_STATE_DISABLE];
131                 break;
132         case CAM_LBS_STATE_SERVICE_START:
133                 image_file = gps_level_image[CAM_LBS_STATE_SERVICE_START];
134                 break;
135         case CAM_LBS_STATE_SERVICE_ENABLE:
136                 image_file = gps_level_image[CAM_LBS_STATE_SERVICE_ENABLE];
137                 break;
138         case CAM_LBS_STATE_ACCURANCY_ROUGH:
139                 image_file = gps_level_image[CAM_LBS_STATE_ACCURANCY_ROUGH];
140                 break;
141         case CAM_LBS_STATE_ACCURANCY_DETAILED:
142                 image_file = gps_level_image[CAM_LBS_STATE_ACCURANCY_DETAILED];
143                 break;
144         default:
145                 image_file = gps_level_image[CAM_LBS_STATE_DISABLE];
146         }
147         if (!indicator_image_obj_gps_level) {
148                 indicator_image_obj_gps_level =
149                     elm_image_add(ad->indicator_edje);
150         }
151         cam_retm_if(indicator_image_obj_gps_level == NULL,
152                     "indicator_image_obj_gps_level is NULL");
153         elm_image_file_set(indicator_image_obj_gps_level, CAM_IMAGE_EDJ_NAME, image_file);
154
155         cam_debug(LOG_CAM, "ad->camapp_handle->camera_mode %d", camapp->camera_mode);
156         cam_debug(LOG_CAM, "ad->mm_state %d", ad->mm_state);
157
158         if (camapp->camera_mode == CAM_CAMCORDER_MODE
159                 && ad->is_recording == TRUE) {
160                 if (camapp->gps_level == CAM_LBS_STATE_DISABLE) {
161                         HIDE_EVAS_OBJECT(indicator_image_obj_gps_level);
162                         edje_object_part_unswallow(_EDJ(ad->indicator_edje), indicator_image_obj_gps_level);
163
164                 } else {
165                         SHOW_EVAS_OBJECT(indicator_image_obj_gps_level);
166                         edje_object_part_swallow(_EDJ(ad->indicator_edje),
167                                                 INDI_REC_GPS,
168                                                 indicator_image_obj_gps_level);
169                 }
170         } else {
171                 if (camapp->gps_level == CAM_LBS_STATE_DISABLE) {
172                         HIDE_EVAS_OBJECT(indicator_image_obj_gps_level);
173                         edje_object_part_unswallow(_EDJ(ad->indicator_edje), indicator_image_obj_gps_level);
174                 } else {
175                         SHOW_EVAS_OBJECT(indicator_image_obj_gps_level);
176                         edje_object_part_swallow(_EDJ(ad->indicator_edje),
177                                                 INDICATOR_GPS,
178                                                 indicator_image_obj_gps_level);
179                 }
180         }
181 }
182
183 void indicator_update_gps(struct appdata *ad)
184 {
185         debug_fenter(LOG_UI);
186         cam_retm_if(ad == NULL, "appdata is NULL");
187         cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
188         cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
189         indicator_update_gps_level(ad);
190 }
191
192 void indicator_update_remain_count(struct appdata *ad)
193 {
194         char remain[80] = "";
195         debug_fenter(LOG_UI);
196         cam_retm_if(ad == NULL, "appdata is NULL");
197         cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
198         cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
199
200         gint64 remained_count = 0;
201         remained_count = ad->remained_count;
202
203         if (ad->camapp_handle->camera_mode == CAM_CAMCORDER_MODE && ad->is_recording == TRUE) {
204                 snprintf(remain, sizeof(remain), "%s", " ");
205         } else {
206                 if (remained_count >= 0 && remained_count < 301) {
207                         snprintf(remain, sizeof(remain), "%d", (int)remained_count);
208                 } else {
209                         snprintf(remain, sizeof(remain), "%d", (int)remained_count);
210                         snprintf(remain, sizeof(remain), "%s", " ");
211                 }
212         }
213
214         DEBUG_TRACE("INDICATOR REMAIN = %s ", remain);
215
216         edje_object_part_text_set(_EDJ(ad->indicator_edje), INDICATOR_NUM, remain);
217 }
218
219 static Eina_Bool cam_indicator_battery_ani_cb(void *data)
220 {
221         struct appdata *ad = data;
222         CamAppData *camapp = NULL;
223         cam_retvm_if(ad == NULL, 0, "appdata is NULL");
224         camapp = ad->camapp_handle;
225         if (camapp == NULL) {
226                 ad->battery_animation_timer = NULL;
227                 return ECORE_CALLBACK_CANCEL;
228
229         }
230
231         if (indicator_image_obj_battery) {
232                 if (evas_object_visible_get(indicator_image_obj_battery))
233                         evas_object_hide(indicator_image_obj_battery);
234                 else
235                         evas_object_show(indicator_image_obj_battery);
236         }
237
238         return ECORE_CALLBACK_RENEW;
239 }
240
241 static void cam_indicator_draw_battery_ani(void *data)
242 {
243         struct appdata *ad = data;
244         CamAppData *camapp = NULL;
245         debug_fenter(LOG_UI);
246         cam_retm_if(ad == NULL, "appdata is NULL");
247         camapp = ad->camapp_handle;
248         cam_retm_if(camapp == NULL, "camapp_handle is NULL");
249         if (ad->battery_animation_timer) {
250                 cam_debug(LOG_UI, "battery_ani timer already exists! ");
251                 return;
252         }
253         ad->battery_animation_timer =
254             ecore_timer_add(CHARGING_INTERVAL, cam_indicator_battery_ani_cb, ad);
255 }
256
257 void indicator_update_battery(struct appdata *ad, int level)
258 {
259         cam_retm_if(ad == NULL, "appdata is NULL");
260         cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
261         cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
262         const char *image_file = NULL;
263         int battery_level = 0;
264         gboolean show_icon = TRUE;
265
266         if (ad->battery_animation_timer) {
267             ecore_timer_del(ad->battery_animation_timer);
268                 ad->battery_animation_timer = NULL;
269         }
270
271         if (ad->camapp_handle->battery_charging) {
272                 battery_level = 7;
273         } else {
274                 if (level > 15 && level <= 20) // step2
275                         battery_level = 2;
276                 else if (level > 5 && level <= 15) // step1
277                         battery_level = 1;
278                 else if (level < 5) {// blinking
279                         battery_level = 0;
280                         cam_indicator_draw_battery_ani((void *)ad);
281                 }
282                 else
283                         show_icon = FALSE;
284         }
285
286         cam_debug(LOG_CAM, "level [%d] img_index[%d] show state [%d]", level, battery_level, show_icon);
287
288         if (show_icon) {
289                 image_file = battery_image[battery_level];
290
291                 if (!indicator_image_obj_battery) {
292                         indicator_image_obj_battery = elm_image_add(ad->indicator_edje);
293                 }
294                 cam_retm_if(indicator_image_obj_battery == NULL, "indicator_image_obj_battery is NULL");
295                 elm_image_file_set(indicator_image_obj_battery, CAM_IMAGE_EDJ_NAME, image_file);
296                 if (ad->camapp_handle->camera_mode == CAM_CAMCORDER_MODE
297                         && ad->is_recording == TRUE)
298                         edje_object_part_swallow(_EDJ(ad->indicator_edje), INDI_REC_BATTERY, indicator_image_obj_battery);
299                 else
300                         edje_object_part_swallow(_EDJ(ad->indicator_edje), INDICATOR_BATTERY, indicator_image_obj_battery);
301         } else {
302                 if (indicator_image_obj_battery)
303                         evas_object_hide(indicator_image_obj_battery);
304         }
305 }
306
307 void indicator_update_mute_icon(struct appdata *ad)
308 {
309         cam_retm_if(ad == NULL, "appdata is NULL");
310         cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
311         cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
312         const char *image_file = NULL;
313
314         if ((ad->camapp_handle->camera_mode == CAM_CAMCORDER_MODE)
315                         && (ad->camapp_handle->recording_mode == CAM_RECORD_SLOW
316                                  || ad->camapp_handle->recording_mode == CAM_RECORD_FAST)) {
317                 if (ad->is_recording == TRUE) {
318                         image_file = mute_image;
319
320                         if (!indicator_image_obj_mute) {
321                                 indicator_image_obj_mute = elm_image_add(ad->indicator_edje);
322                         }
323
324                         cam_retm_if(indicator_image_obj_mute == NULL, "indicator_image_obj_mute is NULL");
325                         elm_image_file_set(indicator_image_obj_mute, CAM_IMAGE_EDJ_NAME, image_file);
326                         edje_object_part_swallow(_EDJ(ad->indicator_edje), INDI_REC_MUTE, indicator_image_obj_mute);
327                 } else {
328                         DEL_EVAS_OBJECT(indicator_image_obj_mute);
329                 }
330         } else {
331                 DEL_EVAS_OBJECT(indicator_image_obj_mute);
332         }
333 }
334
335 void cam_indicator_update(struct appdata *ad)
336 {
337 #ifndef CAMERA_MACHINE_I686
338         cam_retm_if(ad == NULL, "appdata is NULL");
339         cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
340         indicator_update_battery(ad, ad->camapp_handle->battery_level);
341         DEBUG_TRACE("charging = %d",ad->camapp_handle->battery_charging);
342         indicator_update_storage(ad);
343         indicator_update_gps(ad);
344         indicator_update_mute_icon(ad);
345 #endif
346         return;
347 }
348
349 void cam_indicator_set_show_state(struct appdata *ad, bool show)
350 {
351         cam_retm_if(ad == NULL, "appdata is NULL");
352
353         if (ad->indicator_edje) {
354                 if (show)
355                         evas_object_show(ad->indicator_edje);
356                 else
357                         evas_object_hide(ad->indicator_edje);
358         }
359 }
360
361 int cam_indicator_create(struct appdata *ad)
362 {
363         debug_fenter(LOG_UI);
364         cam_retvm_if(ad == NULL, EXIT_FAILURE, "appdata is NULL");
365
366         if (ad->indicator_edje != NULL) {
367                 cam_indicator_update(ad);
368                 evas_object_show(ad->indicator_edje);
369                 return EXIT_SUCCESS;
370         }
371
372         elm_object_part_content_unset(ad->ug_base, "indicator_layout");
373
374         switch (ad->target_direction) {
375         case CAM_TARGET_DIRECTION_LANDSCAPE:
376                 ad->indicator_edje = cam_app_load_edj(ad->ug_base, CAM_INDICATOR_EDJ_NAME, "indicator_landscape");
377                 break;
378         case CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE:
379                 ad->indicator_edje = cam_app_load_edj(ad->ug_base, CAM_INDICATOR_EDJ_NAME, "indicator_landscape_inverse");
380                 break;
381         case CAM_TARGET_DIRECTION_PORTRAIT:
382                 ad->indicator_edje = cam_app_load_edj(ad->ug_base, CAM_INDICATOR_EDJ_NAME, "indicator_portrait");
383                 break;
384         case CAM_TARGET_DIRECTION_PORTRAIT_INVERSE:
385                 ad->indicator_edje = cam_app_load_edj(ad->ug_base, CAM_INDICATOR_EDJ_NAME, "indicator_portrait_inverse");
386                 break;
387         default:
388                 DEBUG_TRACE("note:REACHED UN-ABLE REACHED CODES");
389         }
390
391         cam_retvm_if(ad->indicator_edje == NULL, EXIT_FAILURE, "indicator edje load fail !!!");
392         elm_object_part_content_set(ad->ug_base, "indicator_layout", ad->indicator_edje);
393         cam_indicator_update(ad);
394
395         return EXIT_SUCCESS;
396 }
397
398 int cam_indicator_destory(struct appdata *ad)
399 {
400         cam_retv_if(ad == NULL, -1);
401
402         DEL_EVAS_OBJECT(indicator_image_obj_battery);
403         DEL_EVAS_OBJECT(indicator_image_obj_storage);
404         DEL_EVAS_OBJECT(indicator_image_obj_gps_level);
405         DEL_EVAS_OBJECT(indicator_image_obj_mute);
406
407         DEL_EVAS_OBJECT(ad->indicator_edje);
408         return EXIT_SUCCESS;
409 }
410
411 int cam_indicator_rotate(struct appdata *ad)
412 {
413         cam_retv_if(ad == NULL, -1);
414         if (ad->indicator_edje) {
415                 /* delete indicator */
416                 evas_object_hide(ad->indicator_edje);
417                 cam_indicator_destory(ad);
418                 cam_indicator_create(ad);
419                 if (ad->indicator_edje) {
420                         indicator_toggle(ad, FALSE);
421                         evas_object_show(ad->indicator_edje);
422                 }
423         } else {
424                 return -1;
425         }
426         return 0;
427 }
428
429 void indicator_toggle(struct appdata *ad, gboolean hide)
430 {
431         cam_ret_if(ad == NULL || ad->indicator_edje == NULL);
432
433         if (!hide)
434                 indicator_update_gps(ad);
435 }