Closes app now when you hit the back button. This is a temp fix to keep media workin...
[profile/ivi/ug-camera-efl.git] / src / cam_app.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 <X11/Xlib.h>
19 #include <X11/keysymdef.h>
20 #include <sys/wait.h>
21 #include <pthread.h>
22 #include <unistd.h>
23 #include <aul.h>
24 #include <power.h>
25 #include <syspopup_caller.h>
26 #include <ui-gadget.h>
27 #include <ui-gadget-module.h>
28
29 #include "cam.h"
30 #include "cam_app.h"
31 #include "edc_string.h"
32 #include "cam_sound.h"
33 #include "cam_continuous_shot.h"
34 #include "cam_file.h"
35 #include "cam_ta.h"
36 #include "cam_error.h"
37 #include "cam_config.h"
38 #include "cam_mm.h"
39 #include "cam_rec.h"
40 #include "cam_lbs.h"
41 #include "cam_popup.h"
42
43 #include "cam_common_edc_callback.h"
44 #include "cam_indicator_edc_callback.h"
45 #include "cam_recording_edc_callback.h"
46 #include "cam_toolbar_edc_callback.h"
47 #include "cam_zoom_edc_callback.h"
48 #include "cam_ev_edc_callback.h"
49 #include "camera_utils.h"
50
51 #include "cam_face_detection_focus.h"
52 #include "cam_ui_effect_utils.h"
53 #include "cam_ui_rotate_utils.h"
54
55 #include "cam_menu_composer.h"
56 #include "cam_device_capacity.h"
57
58 #ifdef ENABLE_CAPTURE_ANIMATION
59 #include "cam_animation.h"
60 #endif
61 #define GPS_TIME_OUT 220
62 #define ZSL_MAX_REL (1280*720)  /* 1m wide */
63 #define FOCUS_FOCUSED_TIME_OUT 2
64 #define THUMBNAIL_UPDATE_WAIT_TIME (100*1000)
65
66
67 /* 5m ZSL TEST*/
68 /* #define ZSL_5M_TEST (2560*1920) */
69
70 #define NEW_NOTI_API
71
72
73 static CamAppData *cam_handle = NULL;
74 static struct appdata *app_handle = NULL;
75
76 /* static Ecore_Idler *spy_rotation_idler=NULL; */
77
78 #define TEMP_SAVE_PATH "/tmp/temp_image.jpg"    /* not used maybe... */
79 #define SELF_SHOT_TEMP_SAVE_PATH "/tmp/self_temp_shot.jpg"
80
81 #define ZOOM_LONG_PRESS_INTERVAL 0.05   /* sec */
82
83 #define INAGE_FILE_NAME                 "IMAGE"
84 #define VIDEO_FILE_NAME                 "VIDEO"
85 #define TEMP_FILE_NAME                          ".camera_result"
86 #define IMAGE_FILE_EXTENSION            ".jpg"
87 #define VIDEO_FILE_EXTENSION_3GP        ".3gp"
88 #define VIDEO_FILE_EXTENSION_MP4        ".mp4"
89
90 #define SHUTTER_W_RATIO 0.1
91 #define SHUTTER_H_RATIO 0.34
92 #define SCREEN_RATIO 1.0
93 /* #define CAMAPP_SIG_HANDLING */
94
95 /* #define ENABLE_CHECK_CAM_STATUS       //provent camera hang,  */
96
97 #ifdef ENABLE_CHECK_CAM_STATUS
98 #define CAM_CHECK_STATUS_INTERVAL_TIME 10
99 #ifndef CAMAPP_SIG_HANDLING
100 #define CAMAPP_SIG_HANDLING
101 #endif
102 #endif
103
104
105 static int cam_app_start_rotate(struct appdata *ad, bool bInitial);
106
107 #ifdef ENABLE_CHECK_CAM_STATUS
108 static void cam_app_check_status();
109 #endif
110
111 static gboolean cam_power_key_press(void *data);
112 static void cam_app_update_gps_level(void *data, int gps_level);
113 static gboolean cam_app_return_ext_app(void *data, const char *r_file_path);
114
115 /* vconf changed cb */
116 static void cam_app_battery_update_cb(keynode_t *key, void *data);
117 static void cam_app_battery_status_cb(keynode_t *key, void *data);
118 static void cam_mmc_state_change_cb(keynode_t *key, void *data);
119 static void cam_torchlight_update_cb(keynode_t *key, void *data);
120
121 void cam_app_preview_start_coordinate(CamVideoRectangle src,
122                                       CamVideoRectangle dst,
123                                       CamVideoRectangle *result);
124 void cam_app_timeout_notice_response_cb(void *data, Evas_Object *obj, void *event_info);
125 static void cam_app_capture_error_popup_response_cb(void *data, Evas_Object *obj, void *event_info);
126 Eina_Bool cam_app_launch_after_preview_began(void *data);
127
128 static Eina_Bool cam_app_gps_timer_cb(void *data);
129 static void cam_app_timer_update_count(void *data);
130 static Eina_Bool __focus_guide_destroy(void *data);
131 static void __cam_capture_cb(camera_image_data_s* image,
132                                                         camera_image_data_s* postview, camera_image_data_s* thumbnail,void *user_data);
133 static Eina_Bool __cam_ug_destroy(void *data);
134 static Eina_Bool __cam_app_display_error_popup_idler(void *data);
135 static Eina_Bool __cam_continuous_af_timer_cb(void *data);
136
137
138 /* video streamming */
139 static gboolean video_stream_skip_flag = false;
140
141 /* thumbnail image check count */
142 static int g_thumbnail_image_check_count = 0;
143
144 /*popup */
145 gboolean g_blocking_popup = false;
146
147 void cam_app_set_blocking_popup()
148 {
149         g_blocking_popup = true;
150 }
151
152 void cam_app_free_blocking_popup()
153 {
154         g_blocking_popup = false;
155 }
156
157 gboolean cam_app_check_blocking_popup()
158 {
159         return !g_blocking_popup;
160 }
161
162 struct noti_callback {
163         char *setting_key;
164         void (*noti_func) (keynode_t *, void *);
165 };
166
167 #define CAMERA_NOTI_MAX         5
168 struct noti_callback notis[CAMERA_NOTI_MAX] = {
169         {VCONFKEY_SYSMAN_BATTERY_CAPACITY, *cam_app_battery_update_cb},
170         {VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, *cam_app_battery_update_cb},
171         {VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, *cam_app_battery_status_cb},
172         {VCONFKEY_SYSMAN_MMC_STATUS, *cam_mmc_state_change_cb},
173         {VCONFKEY_SETAPPL_ACCESSIBILITY_TORCH_LIGHT, *cam_torchlight_update_cb}
174 };
175
176 #ifdef CAMAPP_SIG_HANDLING
177 #include <signal.h>
178 static struct sigaction cam_app_act;
179 static struct sigaction cam_app_act_old;
180
181 static void cam_app_register_sigsegv(void);
182 static void cam_app_sigsegv_handler(int signal_no, siginfo_t *info,
183                                     void *context);
184 #endif
185
186 static void cam_app_pipe_handler(void *data, void *buffer, unsigned int nbyte);
187 static int cam_app_camera_state_manager(int previous, int current, gboolean by_asm);
188 static int cam_app_recorder_state_manager(int previous, int current, gboolean by_asm);
189
190 static void cam_app_close_ug(void *data);
191 Eina_Bool __ug_destory_postprocessing(void *data);
192
193 static Eina_Bool cam_app_timeout_checker_cb(void *data);
194
195 gdouble _get_current_time(void)
196 {
197         struct timeval tv;
198         gettimeofday(&tv, NULL);
199         return (gdouble) tv.tv_sec + (gdouble) tv.tv_usec / 1E6;
200 }
201
202 void cam_app_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
203 {
204         if (obj) {
205                 evas_object_del(obj);
206                 obj = NULL;
207         }
208 }
209
210 void cam_app_gps_popup_response_ok_cb(void *data, Evas_Object *obj, void *event_info)
211 {
212         struct appdata *ad = (struct appdata *)data;
213         cam_retm_if(ad == NULL, "appdata is NULL");
214         cam_ret_if(obj == NULL);
215
216         DEBUG_TRACE("show location ug");
217
218         if (ad->confirm_popup) {
219                 evas_object_del(ad->confirm_popup);
220                 ad->confirm_popup = NULL;
221         }
222
223         if (!cam_app_run_location_ug(data)) {
224                 DEBUG_TRACE("cam_app_run_location_ug() fail");
225                 GValue b_value = { 0, };
226                 g_value_init(&b_value, G_TYPE_BOOLEAN);
227                 g_value_set_boolean(&b_value, FALSE);
228                 cam_handle_value_set(ad, PROP_GPS, &b_value);
229
230                 cam_app_notice_popup(data, ("Location Setting launch fail"),
231                                                      cam_app_popup_response_cb);
232         }
233
234 }
235
236 void cam_app_gps_popup_response_cancel_cb(void *data, Evas_Object *obj, void *event_info)
237 {
238         struct appdata *ad = (struct appdata *)data;
239         cam_retm_if(ad == NULL, "appdata is NULL");
240         cam_ret_if(obj == NULL);
241         if (!cam_app_lbs_stop(ad))
242                         DEBUG_TRACE("cam_app_lbs_stop failed");
243         if (ad->confirm_popup) {
244                 evas_object_del(ad->confirm_popup);
245                 ad->confirm_popup = NULL;
246         }
247 }
248
249 static Eina_Bool cam_delay_popup(void *data)
250 {
251
252         cam_app_notice_popup(data, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA_DURING_CALL"),
253                              cam_app_timeout_notice_response_cb);
254         return ECORE_CALLBACK_CANCEL;
255
256 }
257 static void cam_add_longpress_key_timer(void *data)
258 {
259         struct appdata *ad = (struct appdata *)data;
260         cam_retm_if(ad == NULL, "appdata is NULL");
261         if (!ad->longpress_timer) {
262                 ad->longpress_timer = ecore_timer_add(0.5, cam_volume_key_press, ad);
263         }
264 }
265
266 static void cam_del_longpress_key_timer(void *data)
267 {
268         struct appdata *ad = (struct appdata *)data;
269         cam_retm_if(ad == NULL, "appdata is NULL");
270         if (ad->longpress_timer) {
271                 ecore_timer_del(ad->longpress_timer);
272                 ad->longpress_timer = 0;
273         }
274 }
275
276 #ifdef EFL_TEMP_CODE
277 void cam_win_transparent_set(void *data)
278 {
279         struct appdata *ad = (struct appdata *)data;
280         cam_ret_if(ad == NULL);
281
282         Evas *evas;
283         Evas_Object *rect;
284         evas = evas_object_evas_get(ad->win_main);
285         rect = evas_object_rectangle_add(evas);
286         evas_object_color_set(rect, 0, 0, 0, 0);
287         evas_object_render_op_set(rect, EVAS_RENDER_COPY);
288         evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
289         evas_object_show(rect);
290         elm_object_part_content_set(ad->ug_base, "transparent_layout", rect);
291 }
292 #endif
293
294 void cam_set_orient_value(void *data)
295 {
296         struct appdata *ad = (struct appdata *)data;
297         cam_retm_if(ad == NULL, "appdata is NULL");
298         CamAppData *camapp = NULL;
299         camapp = ad->camapp_handle;
300         cam_retm_if(camapp == NULL, "camapp_handle is NULL");
301
302         int orient_value = 0;
303         gboolean save_as_flip = FALSE;
304
305         if (cam_is_enabled_menu(ad, CAM_MENU_SAVE_AS_FLIP) && camapp->save_as_flip == TRUE)
306                 save_as_flip = TRUE;
307
308         switch (ad->rot_current) {
309         case APP_DEVICE_ORIENTATION_0:
310                 if (save_as_flip) {
311                         if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
312                                 orient_value = 7;
313                         } else {
314                                 if (camapp->self_portrait == TRUE)
315                                         orient_value = 6;
316                                 else
317                                         orient_value = 8;
318                         }
319                 } else {
320                         if (camapp->self_portrait == TRUE)
321                                 orient_value = 8;
322                         else
323                                 orient_value = 6;
324                 }
325                 break;
326         case APP_DEVICE_ORIENTATION_180:
327                 if (save_as_flip) {
328                         if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
329                                 orient_value = 5;
330                         } else {
331                                 if (camapp->self_portrait == TRUE)
332                                         orient_value = 8;
333                                 else
334                                         orient_value = 6;
335                         }
336                 } else {
337                         if (camapp->self_portrait == TRUE)
338                                 orient_value = 6;
339                         else
340                                 orient_value = 8;
341                 }
342                 break;
343         case APP_DEVICE_ORIENTATION_90:
344                 if (save_as_flip && camapp->camera_mode == CAM_CAMCORDER_MODE)
345                         orient_value = 4;
346                 else
347                         orient_value = 3;
348                 break;
349         case APP_DEVICE_ORIENTATION_270:
350                 if (save_as_flip && camapp->camera_mode == CAM_CAMCORDER_MODE)
351                         orient_value = 2;
352                 else
353                         orient_value = 1;
354                 break;
355         default:
356                 break;
357         }
358
359         DEBUG_TRACE("rot_cuttent=%d orient_value=%d\n", ad->rot_current, orient_value);
360
361         if (cam_mm_set_tag_img_orient(orient_value))
362                 DEBUG_TRACE("set image orient succeed %d", orient_value);
363         else
364                 DEBUG_TRACE("set image orient failed %d", orient_value);
365 }
366
367 int cam_noti_init(void *data)
368 {
369         struct appdata *ad = (struct appdata *)data;
370         int i = 0;
371
372         debug_fenter(LOG_UI);
373
374         cam_retvm_if(ad == NULL, EXIT_FAILURE, "appdata is NULL");
375
376         /* setting noti */
377         for (i = 0; i < CAMERA_NOTI_MAX; i++) {
378                 if (0 != vconf_notify_key_changed(notis[i].setting_key, notis[i].noti_func, ad)) {
379                         cam_critical(LOG_SYS, "vconf_notify_key_changed() failed. count=%d ", i);
380                 }
381         }
382
383         return EXIT_SUCCESS;
384 }
385
386 int cam_noti_deinit(void *data)
387 {
388         int i;
389         struct appdata *ad = (struct appdata *)data;
390
391         debug_fenter(LOG_SYS);
392
393         cam_retvm_if(ad == NULL, EXIT_FAILURE, "appdata is NULL");
394
395         for (i = 0; i < CAMERA_NOTI_MAX; i++) {
396                 vconf_ignore_key_changed(notis[i].setting_key, notis[i].noti_func);
397         }
398
399         return EXIT_SUCCESS;
400 }
401
402 void *cam_appdata_get(void)
403 {
404         if (app_handle) {
405                 return app_handle;
406         }
407         return NULL;
408 }
409
410 void cam_app_get_win_size(void* data)
411 {
412         struct appdata *ad = (struct appdata *)data;
413         cam_retm_if(ad == NULL, "appdata is NULL");
414
415         ecore_x_window_size_get(ad->main_xid, &(ad->win_height), &(ad->win_width));
416
417         cam_debug(LOG_UI, "main window ----- win_width, win_height: [%d, %d]", ad->win_width, ad->win_height);
418 }
419
420 int cam_appdata_init(void *data)
421 {
422         struct appdata *ad = (struct appdata *)data;
423         cam_retvm_if(ad == NULL, 0, "appdata is NULL");
424
425         app_handle = ad;
426
427         ad->main_pipe = ecore_pipe_add(cam_app_pipe_handler, ad);
428         ad->rot_current = app_get_device_orientation();
429         ad->rot_previous = ad->rot_current;
430
431         cam_app_get_win_size(ad);
432
433         CAM_TA_ACUM_ITEM_BEGIN("      cam_handle_create", 0);
434         if (!cam_handle_create(data)) {
435                 cam_critical(LOG_CAM, "cam_handle_create failed");
436                 return FALSE;
437         }
438         CAM_TA_ACUM_ITEM_END("      cam_handle_create", 0);
439
440         ad->last_camera_zoom_mode = 1;
441
442         return 1;
443 }
444
445 int cam_appdata_fini(void *data)
446 {
447         struct appdata *ad = (struct appdata *)data;
448
449         cam_retvm_if(ad == NULL, 0, "appdata is NULL");
450
451         cam_layout_del_all(ad);
452
453         if (ad->service_handle) {
454                 service_destroy(ad->service_handle);
455                 ad->service_handle = NULL;
456         }
457         if (ad->imageviewer_service) {
458                 service_destroy(ad->imageviewer_service);
459                 ad->imageviewer_service = NULL;
460         }
461         if (ad->key_down) {
462                 ecore_event_handler_del(ad->key_down);
463                 ad->key_down = NULL;
464         }
465         if (ad->key_up) {
466                 ecore_event_handler_del(ad->key_up);
467                 ad->key_up = NULL;
468         }
469         if (ad->mouse_up) {
470                 ecore_event_handler_del(ad->mouse_up);
471                 ad->mouse_up = NULL;
472         }
473         if (ad->mouse_down) {
474                 ecore_event_handler_del(ad->mouse_down);
475                 ad->mouse_down = NULL;
476         }
477         /* Remove Idle handler of capture callback. wh01.cho@samsung.com. 2010-12-15. */
478         if (ad->capture_cb_list) {
479                 cam_utils_remove_idler_all(ad);
480         }
481
482         REMOVE_IDLER(ad->recording_commit);
483         REMOVE_IDLER(ad->still_captured_idle);
484         REMOVE_IDLER(ad->capture_idle);
485         REMOVE_IDLER(ad->auto_shot_idle);
486         REMOVE_IDLER(ad->update_thumbnail_idler);
487
488         REMOVE_TIMER(ad->rec_icon_updater);
489         REMOVE_TIMER(ad->rec_time_updater);
490         REMOVE_TIMER(ad->rec_pause_timer);
491         REMOVE_TIMER(ad->check_af_timer);
492         REMOVE_TIMER(ad->continuous_shot_timer);
493         REMOVE_TIMER(ad->shutter_long_tap_timer);
494         REMOVE_TIMER(ad->timeout_checker);
495         REMOVE_TIMER(ad->setting_toolbar_hide_timer);
496         REMOVE_TIMER(ad->gps_animation_timer);
497         REMOVE_TIMER(ad->battery_animation_timer);
498         REMOVE_TIMER(ad->continuous_af_timer);
499         REMOVE_TIMER(ad->timer_timer);
500         REMOVE_TIMER(ad->longpress_timer);
501         REMOVE_TIMER(ad->focus_guide_hide_timer);
502
503         if( ad->setting_menu_composer != NULL){
504                 cam_compose_free(ad->setting_menu_composer);
505                 ad->setting_menu_composer = NULL;
506         }
507         if( ad->sub_menu_composer != NULL){
508                 cam_compose_free(ad->sub_menu_composer);
509                 ad->sub_menu_composer = NULL;
510         }
511         if (ad->camapp_handle) {
512                 cam_handle_free(ad);
513         }
514         if (ad->exe_args) {
515                 if (ad->exe_args->caller) {
516                         free(ad->exe_args->caller);
517                         ad->exe_args->caller = NULL;
518                 }
519                 free(ad->exe_args);
520                 ad->exe_args = NULL;
521         }
522
523         if (ad->file_reg_thread) {
524                 pthread_join(ad->file_reg_thread, NULL);
525         }
526
527         if (ad->file_reg_queue) {
528                 while (!g_queue_is_empty(ad->file_reg_queue)) {
529                         char *filename = NULL;
530                         filename = g_queue_pop_head(ad->file_reg_queue);
531
532                         cam_critical(LOG_FILE, "[%s] didn't processed",
533                                      filename);
534
535                         if (!strcmp(REG_THREAD_EXIT, filename)) {
536                                 free(filename);
537                         } else {
538                                 __cam_single_shot_reg_file(filename);
539                                 free(filename);
540                                 filename = NULL;
541                                 cam_debug(LOG_FILE, " register done.");
542                         }
543                 }
544                 g_queue_free(ad->file_reg_queue);
545                 ad->file_reg_queue = NULL;
546         }
547
548         /*  disconnect media content */
549         CAM_TA_ACUM_ITEM_BEGIN("    media_content_disconnect", 0);
550
551         if(media_content_disconnect() == MEDIA_CONTENT_ERROR_NONE) {
552                 DEBUG_TRACE("dis connection is success");
553         } else {
554                 cam_critical(LOG_SYS, " media_content_disconnect failed");
555         }
556
557         CAM_TA_ACUM_ITEM_END("    media_content_disconnect", 0);
558
559         cam_popup_delete(ad);
560
561         if (ad->main_pipe) {
562                 ecore_pipe_del(ad->main_pipe);
563                 ad->main_pipe = NULL;
564         }
565         /* init global handle */
566         app_handle = NULL;
567
568         return 1;
569 }
570
571 CamAppData *cam_handle_get(void)
572 {
573         if (cam_handle) {
574                 return cam_handle;
575         }
576         return NULL;
577 }
578
579 gboolean cam_app_init(void *data)
580 {
581         struct appdata *ad = (struct appdata *)data;
582         GError *error = NULL;
583
584         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
585
586         cam_face_detection_focus_init();
587
588         CAM_TA_ACUM_ITEM_BEGIN("    cam_appdata_init", 0);
589         if (!cam_appdata_init(ad)) {
590                 cam_critical(LOG_CAM, "cam_appdata_init failed");
591                 return FALSE;
592         }
593         CAM_TA_ACUM_ITEM_END("    cam_appdata_init", 0);
594
595         cam_retvm_if(ad->camapp_handle == NULL, FALSE, "camapp_handle is NULL");
596
597         CAM_TA_ACUM_ITEM_BEGIN("    cam_config_init", 0);
598         if (!cam_config_init(&error)) {
599                 cam_critical(LOG_SYS, "cam_config_init failed");
600                 if (error != NULL) {
601                         cam_critical(LOG_SYS, "cam_config_init error [%s]",
602                                      error->message);
603                         g_error_free(error);
604                         error = NULL;
605                 }
606                 return FALSE;
607         }
608         CAM_TA_ACUM_ITEM_END("    cam_config_init", 0);
609
610         CAM_TA_ACUM_ITEM_BEGIN("    cam_noti_init", 0);
611         if (EXIT_FAILURE == cam_noti_init(ad)) {
612                 cam_critical(LOG_CAM, "cam_noti_init failed");
613         }
614         CAM_TA_ACUM_ITEM_END("    cam_noti_init", 0);
615
616         CAM_TA_ACUM_ITEM_BEGIN("    cam_file_init", 0);
617         if (!cam_file_init(&error)) {
618                 cam_critical(LOG_FILE, "cam_file_init failed");
619                 if (error != NULL) {
620                         cam_critical(LOG_FILE, "cam_file_init error [%s]",
621                                      error->message);
622                         g_error_free(error);
623                         error = NULL;
624                 }
625                 return FALSE;
626         }
627         CAM_TA_ACUM_ITEM_END("    cam_file_init", 0);
628         CAM_TA_ACUM_ITEM_BEGIN("    cam_sound_init", 0);
629         if (!cam_sound_init(&error)) {
630                 cam_critical(LOG_SND, "cam_sound_init failed");
631                 if (error != NULL) {
632                         cam_critical(LOG_SND, "cam_sound_init error [%s]",
633                                      error->message);
634                         g_error_free(error);
635                         error = NULL;
636                 }
637                 return FALSE;
638         }
639         CAM_TA_ACUM_ITEM_END("    cam_sound_init", 0);
640         CAM_TA_ACUM_ITEM_BEGIN("    cam_lbs_init", 0);
641         if (!cam_lbs_init()) {
642                 cam_critical(LOG_FWK, "cam_lbs_init is failed");
643                 return FALSE;
644         }
645         CAM_TA_ACUM_ITEM_END("    cam_lbs_init", 0);
646
647         CAM_TA_ACUM_ITEM_BEGIN("    cam_app_create_file_register_thread", 0);
648         if (!cam_app_create_file_register_thread(ad)) {
649                 cam_critical(LOG_SYS,
650                              " cam_app_create_file_register_thread failed");
651                 return FALSE;
652         }
653         CAM_TA_ACUM_ITEM_END("    cam_app_create_file_register_thread", 0);
654
655         CAM_TA_ACUM_ITEM_BEGIN("    cam_continuous_shot_create_file_save_thread", 0);
656         if (!cam_continuous_shot_create_file_save_thread(ad)) {
657                 cam_critical(LOG_SYS,
658                              " cam_continuous_shot_create_file_save_thread failed");
659                 return FALSE;
660         }
661         CAM_TA_ACUM_ITEM_END("    cam_continuous_shot_create_file_save_thread", 0);
662
663 #ifdef CAMAPP_SIG_HANDLING
664         /* register singal handler */
665         CAM_TA_ACUM_ITEM_BEGIN("    cam_app_create_file_register_thread", 0);
666         cam_app_register_sigsegv();
667         CAM_TA_ACUM_ITEM_BEGIN("    cam_app_create_file_register_thread", 0);
668 #endif
669
670         if(media_content_connect() == MEDIA_CONTENT_ERROR_NONE) {
671                 DEBUG_TRACE("connection is success");
672         } else {
673                 cam_critical(LOG_SYS, " media_content_connect failed");
674                 return FALSE;
675         }
676         if (error != NULL) {
677                 g_error_free(error);
678                 error = NULL;
679         }
680         return TRUE;
681 }
682
683 gboolean cam_app_start(void *data)
684 {
685         CAM_TA_ACUM_ITEM_BEGIN("#########cam_app_start", 0);
686
687         struct appdata *ad = (struct appdata *)data;
688         CamAppData *camapp = NULL;
689
690         debug_fenter(LOG_CAM);
691
692         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
693         camapp = ad->camapp_handle;
694         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
695
696         /* init gps value */
697         camapp->gps_level = CAM_LBS_STATE_DISABLE;
698         camapp->gps = FALSE;
699         camapp->need_gps_on = FALSE;
700
701         /*init guideline value*/
702         camapp->guideline = FALSE;
703
704         CAM_TA_ACUM_ITEM_BEGIN("    cam_callback_init", 0);
705         if (!cam_callback_init(ad)) {
706                 cam_critical(LOG_CAM, "cam_init_mm_callback failed");
707                 return FALSE;
708         }
709         CAM_TA_ACUM_ITEM_END("    cam_callback_init", 0);
710
711         CAM_TA_ACUM_ITEM_BEGIN("      cam_app_init_attribute", 0);
712         if (!cam_app_init_attribute(ad, camapp->camera_mode)) {
713                 cam_critical(LOG_MM, "cam_app_init_attribute failed");
714         }
715         CAM_TA_ACUM_ITEM_END("      cam_app_init_attribute", 0);
716
717         CAM_TA_ACUM_ITEM_BEGIN("    cam_app_preview_start", 0);
718
719         cam_continuous_af_start(ad);
720         if (!cam_app_preview_start(ad)) {
721                 cam_critical(LOG_MM, "cam_app_preview_start failed");
722                 return FALSE;
723         }
724         CAM_TA_ACUM_ITEM_END("    cam_app_preview_start", 0);
725         cam_mm_set_mdnie_mode(TRUE);
726
727
728         if(!cam_key_grab_init(ad))
729                 DEBUG_TRACE("cam_key_grab_init fail");
730         cam_app_key_event_init(ad);
731         cam_app_timeout_checker_init(ad);
732
733 #ifdef ENABLE_CHECK_CAM_STATUS
734         alarm(CAM_CHECK_STATUS_INTERVAL_TIME);  /* start alarm */
735 #endif
736         CAM_TA_ACUM_ITEM_END("#########cam_app_start", 0);
737
738         ad->displayed_setting_popup = FALSE;
739
740         return TRUE;
741 }
742
743 gboolean cam_app_pause(void *data)
744 {
745         DEBUG_TRACE("#############cam_app_pause - START #############\n");
746         struct appdata *ad = (struct appdata *)data;
747         CamAppData *camapp = NULL;
748         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
749         camapp = ad->camapp_handle;
750         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
751
752         int mm_state = 0;
753         mm_state = cam_mm_get_state();
754
755         cam_mm_set_display_visible(FALSE);
756
757         if (ad->launching_mode == CAM_LAUNCHING_MODE_EXTERNAL) {
758                 if ((ad->exe_args->caller) && (strcmp(ad->exe_args->caller, "contacts") == 0)) {
759                         DEBUG_TRACE(" contact is paused ");
760                         service_h reply;
761                         service_create(&reply);
762                         service_add_extra_data(reply, "camera_end", "1");
763                         service_reply_to_launch_request(reply, ad->service_handle, SERVICE_RESULT_CANCELED);
764                         service_destroy(reply);
765                 }
766         }
767
768         if ((mm_state == RECORDER_STATE_RECORDING
769             || mm_state == RECORDER_STATE_PAUSED)
770             &&(camapp->camera_mode == CAM_CAMCORDER_MODE)) {
771                 int shutter_sound_state = 0;
772                 /* get current sound */
773                 cam_mm_get_shutter_sound(&shutter_sound_state);
774                 /* disable shutter sound */
775                 cam_mm_set_shutter_sound(FALSE);
776                 /*stop recording */
777                 cam_video_record_stop(ad);
778                 /*restore shutter sound */
779                 cam_mm_set_shutter_sound(shutter_sound_state);
780         }
781
782         cam_app_stop_capture(ad);
783
784         if(camapp->af_mode == CAM_FOCUS_FACE){
785                 cam_face_detection_reset();
786         }
787
788         if (ad->timer_activated)
789                 cam_app_cancel_timer(ad);
790
791         CAM_TA_ACUM_ITEM_BEGIN("    cam_app_preview_stop", 0);
792
793         if (camapp->camera_mode == CAM_CAMERA_MODE) {
794                 while (cam_mm_get_cam_state() == CAMERA_STATE_CAPTURING) {
795                         cam_critical(LOG_CAM, "state is capturing");
796                 }
797                 cam_app_preview_start(ad);
798         }
799
800         cam_mm_set_mdnie_mode(FALSE);
801
802         if (camapp->outdoor_visibility)
803                 cam_mm_set_outdoor_visibility(FALSE);
804
805         if (!cam_app_preview_stop()) {
806                 cam_critical(LOG_MM, "cam_app_preview_stop fail");
807         }
808         CAM_TA_ACUM_ITEM_END("    cam_app_preview_stop", 0);
809
810         if (EXIT_FAILURE == cam_noti_deinit(ad))
811                 cam_critical(LOG_UI, "cam_noti_deinit failed");
812
813         if(!cam_app_key_event_deinit(ad))
814                 cam_critical(LOG_UI, "cam_app_key_event_deinit failed");
815
816         if(!cam_key_grab_deinit(ad))
817                 cam_critical(LOG_UI, "cam_key_grab_deinit failed");
818
819         if (camapp->gps == TRUE) {
820                 int gps_level =CAM_LBS_STATE_DISABLE;
821                 gps_level = cam_lbs_get_state();
822                 if (gps_level >=CAM_LBS_STATE_SERVICE_ENABLE)
823                         camapp->need_gps_on= TRUE;
824                 if (ad->gps_animation_timer)
825                         REMOVE_TIMER(ad->gps_animation_timer);
826                 if (cam_app_lbs_stop(ad))
827                         DEBUG_TRACE("The LBS failed to stop");
828         }
829
830         cam_app_timeout_checker_remove();
831         DEBUG_TRACE("#############cam_app_pause - END #############\n");
832         return TRUE;
833 }
834
835 gboolean cam_app_resume(void *data)
836 {
837         struct appdata *ad = (struct appdata *)data;
838         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
839
840         CamAppData *camapp = NULL;
841         camapp = ad->camapp_handle;
842         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
843
844         int cam_state = -1;
845         debug_fenter(LOG_CAM);
846
847         if (!cam_condition_check_to_start_camera(ad)) {
848                 cam_critical(LOG_CAM, "cannot start camera");
849                 return ECORE_CALLBACK_CANCEL;
850         }
851
852         if(ad->launching_mode == CAM_LAUNCHING_MODE_NORMAL) {
853                 if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
854                         GValue value = {0, };
855                         CAM_GVALUE_SET_INT(value, CAM_CAMERA_MODE);
856                         if (!cam_handle_value_set(ad, PROP_MODE, &value)) {
857                                 return ECORE_CALLBACK_CANCEL;
858                         }
859                 }
860         }
861
862         indicator_update_storage(ad);
863         cam_app_timeout_checker_init(ad);
864
865         if (ad->imageviewer_ug == NULL) { /* home key destory imageviewer_ug */
866                 cam_state = cam_mm_get_state();
867                 cam_app_get_preview_offset_coordinate(ad);
868
869                 cam_continuous_af_start((void*)ad);
870                 CAM_TA_ACUM_ITEM_BEGIN("    cam_app_preview_start", 0);
871
872                 if (ad->torchlight_on && camapp->flash != CAM_FLASH_OFF)
873                         cam_mm_set_flash(CAM_FLASH_OFF);
874
875                 /* reset zoom */
876                 cam_mm_set_zoom(camapp->zoom_min);
877                 camapp->zoom_mode  = camapp->zoom_min;
878
879                 if (!cam_app_preview_start(ad)) {
880                         if (ad->fw_error_type == CAMERA_ERROR_SOUND_POLICY || ad->fw_error_type == RECORDER_ERROR_SOUND_POLICY) {
881                                 DEBUG_TRACE(" MM CAMCARORDER ERROR\n");
882                                 ecore_timer_add(0.01, cam_delay_popup, (void *)ad);
883                                 return TRUE;
884                         }
885
886                         cam_critical(LOG_MM, "cam_app_preview_start failed");
887                         cam_app_notice_popup(ad,
888                          "PREVIEW START FAILED !!",
889                          cam_app_timeout_notice_response_cb);
890                         return FALSE;
891                 }
892                 CAM_TA_ACUM_ITEM_END("    cam_app_preview_start", 0);
893                 cam_mm_set_mdnie_mode(TRUE);
894
895                 if (camapp->outdoor_visibility)
896                         cam_mm_set_outdoor_visibility(TRUE);
897
898                 if (camapp->camera_mode == CAM_CAMERA_MODE) {
899                         if(camapp->af_mode == CAM_FOCUS_FACE){
900                                 /*start face detection*/
901                                 if (cam_mm_is_supported_face_detection()) {
902                                         cam_mm_start_camera_face_detection(camapp->face_detect_cb, (void *)ad);
903                                         if (!cam_mm_set_preview_cb(cam_face_detection_focus_start_stream, (void*)ad)) {
904                                                 DEBUG_TRACE("preview callback set error");
905                                         }
906                                         cam_app_run_video_stream();
907                                 } else {
908                                         DEBUG_TRACE("not support face detect mode");
909                                 }
910                         }
911
912                 }
913                 CAM_TA_ACUM_ITEM_BEGIN("    cam_noti_init", 0);
914                 if (EXIT_FAILURE == cam_noti_init(ad))
915                         cam_critical(LOG_CAM, "cam_noti_init failed");
916                 CAM_TA_ACUM_ITEM_END("    cam_noti_init", 0);
917
918                 CAM_TA_ACUM_ITEM_BEGIN("    cam_key_grab_init", 0);
919                 if (!cam_key_grab_init(ad))
920                         DEBUG_TRACE("cam_key_grab_init fail");
921                 CAM_TA_ACUM_ITEM_END("    cam_key_grab_init", 0);
922
923                 cam_app_key_event_init(ad);
924                 cam_app_update_quickview_icon(ad);
925                 cam_toolbar_update(ad);
926         }
927
928         if (camapp->need_gps_on== TRUE) {
929                 camapp->need_gps_popup = FALSE;
930                 if (!cam_app_lbs_start(ad)) {
931                         if (!cam_app_lbs_stop(ad))
932                                 DEBUG_TRACE("The LBS failed to stop");
933                 }
934         }
935
936 #ifdef ENABLE_CHECK_CAM_STATUS
937         alarm(CAM_CHECK_STATUS_INTERVAL_TIME);  /* start alarm */
938 #endif
939
940         return TRUE;
941 }
942
943 gboolean cam_app_stop(void *data)
944 {
945         debug_fenter(LOG_CAM);
946         char *filename = NULL;
947
948         struct appdata *ad = (struct appdata *)data;
949         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
950         CamAppData *camapp = ad->camapp_handle;
951         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
952
953         CAM_TA_ACUM_ITEM_BEGIN("  cam_app_stop", 0);
954
955         /* return aul result path */
956         if (ad->launching_mode == CAM_LAUNCHING_MODE_EXTERNAL) {
957                 if (ad->exe_args == NULL) {
958                         DEBUG_TRACE("ad->exe_args is NULL");
959                         return FALSE;
960                 }
961                 if (ad->path_in_return) {
962                         if (((ad->exe_args->caller) && (strcmp(ad->exe_args->caller, "contacts") == 0))
963                                         || ((ad->exe_args->caller) && (strcmp(ad->exe_args->caller, "ug-setting-call-efl") == 0))) {
964                                 DEBUG_TRACE("contacts -not need sending result");
965                         } else {
966                                 if (ad->ug_state != CAM_UG_PAUSE_STATE) {
967                                         if (camapp->filename != NULL) {
968                                                 filename = strdup(camapp->filename);
969                                                 cam_app_return_ext_app(ad, filename);
970                                         }
971                                 }
972                         }
973                 } else {
974                         cam_app_return_ext_app(ad, filename);
975                 }
976         }
977
978         if (cam_mm_is_created()) {
979                 /*TODO: new logic will be add for save file while camera process is killed*/
980                 /*stop*/
981                 int state = 0;
982                 state = cam_mm_get_state();
983                 if (ad->camapp_handle) {
984                         if (ad->camapp_handle->camera_mode == CAM_CAMCORDER_MODE) {
985                                 switch (state) {
986                                 case RECORDER_STATE_NONE:
987                                 case RECORDER_STATE_CREATED:
988                                         break;
989                                 case RECORDER_STATE_READY:
990                                         break;
991                                 case RECORDER_STATE_RECORDING:
992                                 case RECORDER_STATE_PAUSED:
993                                         cam_video_record_stop(ad);
994                                         break;
995                                 default:
996                                         /*g_assert_not_reached();*/
997                                         break;
998                                 }
999                         }
1000                 }
1001
1002                 cam_mm_set_mdnie_mode(FALSE);
1003
1004                 if (camapp->outdoor_visibility)
1005                         cam_mm_set_outdoor_visibility(FALSE);
1006
1007                 CAM_TA_ACUM_ITEM_BEGIN("    cam_app_preview_stop", 0);
1008                 if (!cam_app_preview_stop()) {
1009                         cam_critical(LOG_MM, "cam_app_preview_stop failed");
1010                 }
1011                 CAM_TA_ACUM_ITEM_END("    cam_app_preview_stop", 0);
1012
1013                 CAM_TA_ACUM_ITEM_BEGIN("    cam_mm_destory", 0);
1014                 if (!cam_mm_destory()) {
1015                         cam_critical(LOG_MM, "cam_mm_destory failed");
1016                 }
1017                 CAM_TA_ACUM_ITEM_END("    cam_mm_destory", 0);
1018         }
1019
1020         if (ad->imageviewer_ug || ad->location_ug) {
1021                 cam_app_close_ug(ad);
1022         }
1023
1024         cam_popup_remove_all();
1025
1026         /* Idler of capture callback management. wh01.cho@samsung.com. 2010-12-15. */
1027         cam_utils_remove_idler_all(ad);
1028
1029         if (EXIT_FAILURE == cam_noti_deinit(ad))
1030                 cam_critical(LOG_UI, "cam_noti_deinit failed");
1031
1032         if(!cam_app_key_event_deinit(ad))
1033                 cam_critical(LOG_UI, "cam_app_key_event_deinit failed");
1034
1035         if(!cam_key_grab_deinit(ad))
1036                 cam_critical(LOG_UI, "cam_key_grab_deinit failed");
1037
1038         /* crear data & engine */
1039         CAM_TA_ACUM_ITEM_BEGIN("    cam_app_clear_engine_data", 0);
1040         cam_app_clear_engine_data(data, true);
1041         CAM_TA_ACUM_ITEM_END("    cam_app_clear_engine_data", 0);
1042
1043         CAM_TA_ACUM_ITEM_BEGIN("    cam_file_finalize", 0);
1044         cam_file_finalize();
1045         CAM_TA_ACUM_ITEM_END("    cam_file_finalize", 0);
1046
1047         CAM_TA_ACUM_ITEM_BEGIN("    cam_sound_finalize", 0);
1048         cam_sound_finalize();
1049         CAM_TA_ACUM_ITEM_END("    cam_sound_finalize", 0);
1050
1051         /*  clean config */
1052         CAM_TA_ACUM_ITEM_BEGIN("    cam_config_finalize", 0);
1053         cam_config_finalize();
1054         CAM_TA_ACUM_ITEM_END("    cam_config_finalize", 0);
1055
1056         /*  finialize gps */
1057         CAM_TA_ACUM_ITEM_BEGIN("    cam_gps_finialize", 0);
1058         cam_lbs_finialize();
1059         CAM_TA_ACUM_ITEM_END("    cam_gps_finialize", 0);
1060
1061         /*  cam_handle_free(ad); */
1062         cam_face_detection_focus_finish();
1063         cam_appdata_fini(ad);
1064
1065         if (filename != NULL) {
1066                 free(filename);
1067                 filename = NULL;
1068         }
1069
1070         CAM_TA_ACUM_ITEM_END("  cam_app_stop", 0);
1071
1072         return TRUE;
1073 }
1074
1075 gboolean cam_app_preview_start(void *data)
1076 {
1077         CAM_TA_ACUM_ITEM_BEGIN("----cam_app_preview_start", 0);
1078         DEBUG_TRACE
1079             ("------------------------------START---------------------------------");
1080
1081         struct appdata *ad = (struct appdata *)data;
1082         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
1083         CamAppData *camapp = ad->camapp_handle;
1084         cam_retvm_if(camapp == NULL, FALSE, "camapp is NULL");
1085
1086         int state = cam_mm_get_state();
1087         DEBUG_TRACE("state: %d ", state);
1088
1089         if (((camapp->camera_mode == CAM_CAMERA_MODE) && (state < CAMERA_STATE_NONE))
1090                         || ((camapp->camera_mode == CAM_CAMCORDER_MODE) && (state < RECORDER_STATE_NONE)))
1091                 return FALSE;
1092
1093         if (camapp->camera_mode == CAM_CAMERA_MODE) {
1094                 switch(state) {
1095                 case CAMERA_STATE_CREATED:
1096                 case CAMERA_STATE_CAPTURED:
1097                         {
1098                                 CAM_TA_ACUM_ITEM_BEGIN("          cam_mm_preview_start", 0);
1099                                 if (!cam_mm_preview_start(camapp->camera_mode)) {
1100                                         cam_critical(LOG_MM, "cam_mm_preview_start failed");
1101                                         return FALSE;
1102                                 }
1103                                 CAM_TA_ACUM_ITEM_END("          cam_mm_preview_start", 0);
1104                         }
1105                         break;
1106                 case CAMERA_STATE_CAPTURING:
1107                         {
1108                                 if (cam_mm_capture_stop(FALSE, camapp->camera_mode) == FALSE) {
1109                                         cam_critical(LOG_MM, "cam_mm_capture_stop failed");
1110                                         return FALSE;
1111                                 }
1112                         }
1113                         break;
1114                 default:
1115                         break;
1116                 }
1117         }else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
1118                 switch(state) {
1119                 case RECORDER_STATE_CREATED:
1120                 case RECORDER_STATE_PAUSED:
1121                         {
1122                                 if (!cam_mm_preview_start(camapp->camera_mode)) {
1123                                         cam_critical(LOG_MM, "cam_mm_preview_start failed");
1124                                         return FALSE;
1125                                 }
1126                         }
1127                         break;
1128                 default:
1129                         break;
1130
1131                 }
1132         }
1133
1134         CAM_TA_ACUM_ITEM_END("----cam_app_preview_start", 0);
1135         return TRUE;
1136 }
1137
1138 gboolean cam_app_preview_stop(void)
1139 {
1140         struct appdata *ad = (struct appdata *)cam_appdata_get();
1141         cam_retvm_if(ad == NULL, FALSE, "ad is NULL");
1142         CamAppData *camapp = ad->camapp_handle;
1143         cam_retvm_if(camapp == NULL, FALSE, "camapp is NULL");
1144
1145         if (camapp->touch_af_state == CAM_TOUCH_AF_STATE_DOING
1146                 || camapp->touch_af_state == CAM_TOUCH_AF_STATE_READY)
1147                 camapp->touch_af_state = CAM_TOUCH_AF_STATE_NONE;
1148
1149         if (!cam_mm_preview_stop(camapp->camera_mode)) {
1150                 cam_critical(LOG_MM, "cam_mm_preview_stop failed");
1151                 return FALSE;
1152         }
1153         return TRUE;
1154 }
1155
1156 static void cam_app_timer_icon_rotate(void *data)
1157 {
1158         struct appdata *ad = (struct appdata *)data;
1159         cam_retm_if(ad == NULL, "appdata is NULL");
1160
1161         DEL_EVAS_OBJECT(ad->timer_icon_edje);
1162         cam_app_timer_update_count(ad);
1163 }
1164
1165 static int cam_app_start_rotate(struct appdata *ad, bool bInitial)
1166 {
1167         cam_retvm_if(ad == NULL, -1, "appdata is NULL");
1168
1169         cam_debug(LOG_UI, "rotated : %d, window rotation angle=%d", ad->rot_current);   /*, elm_win_rotation_get(ad->win_main)); */
1170
1171
1172         int angle = 0;
1173
1174         switch (ad->rot_current) {
1175         case APP_DEVICE_ORIENTATION_0:
1176                 ad->camcorder_rotate = CAMERA_ROTATION_90;
1177                 ad->target_direction = CAM_TARGET_DIRECTION_PORTRAIT;
1178                 angle = 0;
1179                 break;
1180
1181         case APP_DEVICE_ORIENTATION_180:
1182                 ad->camcorder_rotate = CAMERA_ROTATION_270;
1183                 ad->target_direction = CAM_TARGET_DIRECTION_PORTRAIT_INVERSE;
1184                 angle = 180;
1185                 break;
1186
1187         case APP_DEVICE_ORIENTATION_270:
1188                 ad->camcorder_rotate = CAMERA_ROTATION_NONE;
1189                 ad->target_direction = CAM_TARGET_DIRECTION_LANDSCAPE;
1190                 angle = 270;
1191                 break;
1192
1193         case APP_DEVICE_ORIENTATION_90:
1194                 ad->camcorder_rotate = CAMERA_ROTATION_180;
1195                 ad->target_direction = CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE;
1196                 angle = 90;
1197                 break;
1198
1199         default:
1200                 break;
1201         }
1202         ad->angle = angle;
1203         ad->angle_pre = ad->angle;
1204
1205 ////////////////////////////////////////////////////////////////////////////
1206         if (ad->toolbar_edj_file) {
1207                 free(ad->toolbar_edj_file);
1208                 ad->toolbar_edj_file = NULL;
1209         }
1210
1211         switch (ad->angle) {
1212         case 270:
1213                 ad->toolbar_edj_file = strdup(CAM_TOOLBAR_LAYOUT_EDJ_NAME);
1214                 break;
1215         case 0:
1216                 ad->toolbar_edj_file = strdup(CAM_TOOLBAR_LAYOUT_VERTICAL_EDJ_NAME);
1217                 break;
1218         case 90:
1219                 ad->toolbar_edj_file = strdup(CAM_TOOLBAR_LAYOUT_INVERSE_EDJ_NAME);
1220                 break;
1221         case 180:
1222                 ad->toolbar_edj_file = strdup(CAM_TOOLBAR_LAYOUT_VERTICAL_INVERSE_EDJ_NAME);
1223                 break;
1224         default:
1225                 ad->toolbar_edj_file = strdup(CAM_TOOLBAR_LAYOUT_EDJ_NAME);
1226                 break;
1227
1228         }
1229
1230         if(elm_win_rotation_get(ad->win_main) != ad->angle)
1231                 elm_win_rotation_with_resize_set(ad->win_main, ad->angle);
1232
1233         cam_app_get_preview_offset_coordinate(ad);
1234
1235         if (!bInitial) {
1236                 if (ad->toolbar_edje)
1237                         cam_toolbar_rotate(ad);
1238
1239                 if (ad->indicator_edje)
1240                         cam_indicator_rotate(ad);
1241
1242                 if (ad->recording_edje)
1243                         cam_recording_rotate(ad);
1244
1245                 if (ad->timer_icon_edje)
1246                         cam_app_timer_icon_rotate(ad);
1247
1248                 if (ad->ev_edje) {
1249                         unload_ev_edje(ad);
1250                         load_ev_edje(ad);
1251                 }
1252
1253                 if (ad->zoom_edje) {
1254                         unload_zoom_edje(ad);
1255                         load_zoom_edje(ad);
1256                 }
1257                 /* guideline */
1258                 if (ad->guideline_edje)
1259                         settings_guideline_refresh(ad);
1260
1261         }
1262         return 0;
1263 }
1264
1265 gboolean cam_layout_init(void *data)
1266 {
1267         DEBUG_TRACE("START");
1268
1269         struct appdata *ad = (struct appdata *)data;
1270         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
1271
1272         if (ad->win_main == NULL) {
1273                 cam_critical(LOG_UI, "win_main is NULL");
1274                 return FALSE;
1275         }
1276         ad->pinch_edje = NULL;
1277
1278         cam_app_start_rotate(ad, TRUE);
1279         DEBUG_TRACE("ad->angle = %d", ad->angle);
1280
1281         elm_theme_extension_add(NULL, CAM_SETTING_POPUP_STYLE_EDJ_NAME);
1282         elm_theme_extension_add(NULL, CAM_SETTING_POPUP_STYLE_WITH_RADIO_EDJ_NAME);
1283         elm_theme_extension_add(NULL, CAM_SLIDER_STYLE_EDJ_NAME);
1284         elm_theme_extension_add(NULL, CAM_LABEL_STYLE_EDJ_NAME);
1285         elm_theme_extension_add(NULL, CAM_BUTTON_STYLE_EDJ_NAME);
1286
1287 #ifndef CAMERA_MACHINE_I686
1288         define_mouse_callback(ad);
1289 #endif
1290
1291         CAM_TA_ACUM_ITEM_BEGIN("      load_toolbar_edje", 0);
1292         if (cam_toolbar_create(ad)) {
1293                 CAM_TA_ACUM_ITEM_END("      load_toolbar_edje", 0);
1294                 cam_critical(LOG_UI, " load_toolbar_edje failed ");
1295                 return FALSE;
1296         }
1297         CAM_TA_ACUM_ITEM_END("      load_toolbar_edje", 0);
1298
1299         CAM_TA_ACUM_ITEM_BEGIN("      cam_indicator_create", 0);
1300         if (cam_indicator_create(ad)) {
1301                 CAM_TA_ACUM_ITEM_END("      cam_indicator_create", 0);
1302                 cam_critical(LOG_UI, "cam_indicator_create failed ");
1303                 return FALSE;
1304         }
1305         CAM_TA_ACUM_ITEM_END("      cam_indicator_create", 0);
1306
1307         cam_app_focus_guide_create(ad);
1308         cam_app_update_quickview_icon(ad);
1309         settings_guideline_refresh(ad);
1310
1311         /*note: */
1312         /*reading from ini: whether need show popup tip*/
1313         gboolean show_popup_tip = FALSE;
1314         show_popup_tip = cam_config_get_boolean_by_type(CAM_CONFIG_TYPE_SHORTCUTS, PROP_SHOW_POP_TIP, POP_TIP_DEFAULT);
1315         if (show_popup_tip) {
1316                 cam_tip_popup_create(ad, CAM_TIP_POPUP_BURSTSHOT_HELP);
1317         }
1318
1319         if (ad->battery_status == LOW_BATTERY_CRITICAL_STATUS
1320                 || ad->battery_status == LOW_BATTERY_WARNING_STATUS
1321                 || ad->is_calling == TRUE ){
1322                 ecore_idler_add(__cam_app_display_error_popup_idler, ad);
1323         }
1324
1325         DEBUG_TRACE("END");
1326
1327         return TRUE;
1328 }
1329
1330 gboolean cam_handle_create(void *data)
1331 {
1332         CAM_TA_ACUM_ITEM_BEGIN("------cam_handle_create", 0);
1333         struct appdata *ad = (struct appdata *)data;
1334         CamAppData *camapp = NULL;
1335
1336         debug_fenter(LOG_CAM);
1337         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
1338
1339         if (ad->camapp_handle && cam_handle) {
1340                 cam_handle_free(ad);
1341         }
1342
1343         camapp = (CamAppData *)malloc(sizeof(CamAppData));
1344         cam_retv_if(camapp == NULL, FALSE);
1345         memset(camapp, 0x00, sizeof(CamAppData));
1346
1347         cam_handle = camapp;
1348         ad->camapp_handle = camapp;
1349         CAM_TA_ACUM_ITEM_END("------cam_handle_create", 0);
1350
1351         return TRUE;
1352 }
1353
1354 gboolean cam_handle_free(void *data)
1355 {
1356         struct appdata *ad = (struct appdata *)data;
1357         CamAppData *camapp = NULL;
1358
1359         debug_fenter(LOG_CAM);
1360         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
1361         camapp = ad->camapp_handle;
1362         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
1363
1364         cam_config_save();
1365
1366         if (camapp && cam_handle) {
1367                 if (camapp->conti_image) {
1368                         evas_object_del(camapp->conti_image);
1369                         camapp->conti_image = NULL;
1370                 }
1371
1372                 if (camapp->filename) {
1373                         free(camapp->filename);
1374                         camapp->filename = NULL;
1375                 }
1376
1377                 if (camapp->thumbnail_name) {
1378                         free(camapp->thumbnail_name);
1379                         camapp->thumbnail_name = NULL;
1380                 }
1381                 cam_continuous_shot_data_free(ad);
1382                 if (camapp) {
1383                         free(camapp);
1384                         camapp = NULL;
1385                 }
1386
1387                 DEBUG_TRACE();
1388                 ad->camapp_handle = NULL;
1389                 cam_handle = NULL;
1390         }
1391
1392         return TRUE;
1393 }
1394
1395 gboolean cam_toolbar_menu_config_init(void *data, int mode) {
1396         struct appdata *ad = (struct appdata *)data;
1397         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
1398         int i = 0;
1399
1400 #ifdef CAMERA_MACHINE_I686
1401         for (i = CAM_MENU_BAR_LEFT_1; i < CAM_MENU_BAR_LEFT_MAX_NUM; i++) {
1402                 char buf[16+1] = { '\0', };
1403                 snprintf(buf, 16, "toolbar_%d", i);
1404                 ad->toolbar_menu_arrays[i].menu_type = CAM_MENU_EMPTY;
1405         }
1406 #else
1407         for (i = CAM_MENU_BAR_LEFT_1; i < CAM_MENU_BAR_LEFT_MAX_NUM; i++) {
1408                 char buf[16+1] = { '\0', };
1409                 snprintf(buf, 16, "toolbar_%d", i);
1410                 ad->toolbar_menu_arrays[i].menu_type = cam_config_get_int(buf, CAM_MENU_EMPTY);
1411
1412                 if (ad->toolbar_menu_arrays[i].menu_type == CAM_MENU_SELF_PORTRAIT) {
1413                         if (cam_mm_is_support_front_camera() == FALSE)
1414                                 ad->toolbar_menu_arrays[i].menu_type = CAM_MENU_EMPTY;
1415                 }
1416         }
1417 #endif
1418
1419         return TRUE;
1420 }
1421
1422 gboolean cam_toolbar_menu_config_update(void *data)
1423 {
1424         struct appdata *ad = (struct appdata *)data;
1425         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
1426         int i = 0;
1427         for (i = CAM_MENU_BAR_LEFT_1; i < CAM_MENU_BAR_LEFT_MAX_NUM; i++) {
1428                 char buf[16+1] = { '\0', };
1429                 snprintf(buf, 16, "toolbar_%d", i);
1430                 int tmp_type = cam_config_get_int(buf, CAM_MENU_EMPTY);
1431                 if (ad->toolbar_menu_arrays[i].menu_type != tmp_type) {
1432                         cam_config_set_int(buf, ad->toolbar_menu_arrays[i].menu_type);
1433                 }
1434         }
1435         return TRUE;
1436 }
1437
1438 gboolean cam_handle_init(void *data, int mode)
1439 {
1440         struct appdata *ad = data;
1441         CamAppData *camapp = NULL;
1442         int charging = 0;
1443
1444         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
1445         camapp = ad->camapp_handle;
1446         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
1447
1448         cam_info(LOG_UI, "mode : %d ", mode);
1449         camapp->camera_mode = mode;
1450         cam_config_set_int_by_type(CAM_CONFIG_TYPE_COMMON, PROP_MODE_NAME, mode);
1451
1452         cam_app_set_config_group(camapp->camera_mode);
1453         /* load init value from ini file */
1454         /*   camapp->camera_mode = cam_config_get_int(PROP_MODE_NAME, MODE_DEFAULT); */
1455
1456         vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_CAMERA_INT, &(camapp->storage));
1457
1458         camapp->anti_shake = cam_config_get_int(PROP_AHS_NAME, AHS_DEFAULT);
1459
1460         camapp->self_portrait = FALSE;
1461
1462         /* use shot mode as default value */
1463         camapp->recording_mode = RECMODE_DEFAULT;
1464         camapp->shooting_mode = SHOTMODE_DEFAULT;
1465
1466         camapp->scene_mode = cam_config_get_int(PROP_SCENE_MODE_NAME, PG_MODE_DEFAULT);
1467         camapp->iso = cam_config_get_int(PROP_ISO_NAME, ISO_DEFAULT);
1468         /*camapp->af_mode = cam_config_get_int(PROP_AF_NAME, AF_DEFAULT); */
1469         camapp->af_mode = AF_DEFAULT;
1470         /* camapp->white_balance = cam_config_get_int(PROP_WB_NAME, WB_DEFAULT); */
1471         camapp->white_balance = WB_DEFAULT;
1472
1473         camapp->flash = cam_config_get_int(PROP_FLASH_NAME, FLASH_DEFAULT);
1474
1475         /*batterylevel*/
1476         if (cam_utils_check_battery_warning_low()) {
1477                 camapp->flash = CAM_FLASH_OFF;
1478         }
1479         camapp->guideline = cam_config_get_boolean(PROP_GUIDELINE_NAME, GUIDE_LINE_DEFAULT);
1480         DEBUG_TRACE("camapp->guideline = %d" ,camapp->guideline);
1481         camapp->effect = EFFECT_DEFAULT;
1482
1483         camapp->wdr = cam_config_get_int(PROP_WDR_NAME, WDR_DEFAULT);
1484         camapp->auto_exposure = cam_config_get_int(PROP_METERING_NAME, AE_DEFAULT);
1485
1486         camapp->photo_resolution = cam_config_get_int(PROP_PHOTO_RESOLUTION_NAME, IMAGE_RESOLUTION_DEFAULT);
1487         camapp->video_resolution = cam_config_get_int(PROP_VIDEO_RESOLUTION_NAME, REC_RESOLUTION_DEFAULT);
1488
1489         camapp->auto_contrast = FALSE;
1490         camapp->image_quality = QUALITY_DEFAULT;
1491         camapp->video_quality = QUALITY_DEFAULT;
1492         camapp->audio_recording = AUDIOREC_DEFAULT;
1493         camapp->review = cam_config_get_boolean(PROP_REVIEW_NAME, FALSE);
1494
1495         camapp->battery_level = cam_utils_get_battery_level();
1496         charging = cam_utils_get_charging_status();
1497         if (charging == 1)
1498                 camapp->battery_charging = charging;
1499         else
1500                 camapp->battery_charging = 0;
1501
1502 #ifdef USE_CAMERA_APP_SHUTTER_SOUND
1503         camapp->shutter_sound = SHUTTER_SOUND_DEFAULT;
1504 #endif
1505         /*sound*/
1506
1507         cam_mm_set_shutter_sound(SOUND_DEFAULT);
1508         camapp->shutter_sound = SHUTTER_SOUND_DEFAULT;  /* on */
1509
1510         /* below item had been saved in ini file */
1511         camapp->zoom_mode = ZOOM_DEFAULT;
1512         camapp->image_count = IMAGE_COUNT_DEFAULT;
1513         camapp->size_limit_type = CAM_MM_SIZE_LIMIT_TYPE_BYTE;
1514         camapp->size_limit = REC_SIZE_LIMIT_DEFAULT;
1515         camapp->timer = TIMER_DEFAULT;
1516         camapp->fps = FPS_DEFAULT;
1517
1518         camapp->continuous_shot_data = NULL;
1519
1520         camapp->enable_touch_af = TRUE;
1521
1522         camapp->outdoor_visibility = FALSE;
1523
1524         camapp->burst_shot = cam_config_get_boolean(PROP_BURST_SHOT_NAME, BURST_SHOT_DEFAULT);
1525
1526         camapp->device_type = CAM_DEVICE_MEGA;
1527
1528         camapp->volume_key = cam_config_get_int(PROP_VOLUME_KEY_NAME, CAM_VOLUME_KEY_ZOOM);
1529
1530         camapp->save_as_flip = FALSE;
1531
1532         /*init toolbar menu config */
1533         cam_toolbar_menu_config_init((void*)ad, mode);
1534
1535         /* init reserved setting data */
1536         camapp->reserved_setting_data.front_photo_resolution = cam_config_get_int(PROP_SELF_PHOTO_RESOLUTION_NAME, SELF_IMAGE_RESOLUTION_DEFAULT);
1537         camapp->reserved_setting_data.front_video_resolution = cam_config_get_int(PROP_SELF_VIDEO_RESOLUTION_NAME, SELF_REC_RESOLUTION_DEFAULT);
1538         camapp->reserved_setting_data.rear_photo_resolution = cam_config_get_int(PROP_PHOTO_RESOLUTION_NAME, IMAGE_RESOLUTION_DEFAULT);
1539         camapp->reserved_setting_data.rear_video_resolution = cam_config_get_int(PROP_VIDEO_RESOLUTION_NAME, REC_RESOLUTION_DEFAULT);
1540         camapp->reserved_setting_data.front_shooting_mode = CAM_SELF_SINGLE_MODE;
1541         camapp->reserved_setting_data.front_recording_mode = CAM_RECORD_SELF;
1542         camapp->reserved_setting_data.rear_shooting_mode = SHOTMODE_DEFAULT;
1543         camapp->reserved_setting_data.rear_recording_mode = RECMODE_DEFAULT;
1544         camapp->reserved_setting_data.front_effect = EFFECT_DEFAULT;
1545         camapp->reserved_setting_data.rear_effect = EFFECT_DEFAULT;
1546         camapp->reserved_setting_data.front_wb = WB_DEFAULT;
1547         camapp->reserved_setting_data.rear_wb = WB_DEFAULT;
1548
1549         return TRUE;
1550 }
1551
1552 gboolean cam_handle_value_set(void *data, int type, const GValue *value)
1553 {
1554         struct appdata *ad = (struct appdata *)data;
1555         CamAppData *camapp = NULL;
1556
1557         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
1558         camapp = ad->camapp_handle;
1559         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
1560
1561         cam_debug(LOG_CAM, "type : %d", type);
1562
1563         switch (type) {
1564         case PROP_MODE:
1565                 {
1566                         gint current = 0;
1567                         gint tempval = g_value_get_int(value);
1568
1569                         current = camapp->camera_mode;
1570
1571                         //camapp->camera_mode = tempval;
1572                         if (!cam_mode_change(ad, tempval)) {
1573                                 cam_critical(LOG_CAM, "MODE CHANGE IS FAILED by MIDDLE WARE");
1574                                 camapp->camera_mode = current;
1575                                 cam_app_notice_popup(data, "MODE CHANGE FAILED !!", cam_app_timeout_notice_response_cb);
1576                         }
1577                 }
1578                 break;
1579
1580         case PROP_SELF_PORTRAIT:
1581                 {
1582                         GValue set_value = { 0 };
1583                         gboolean tempval = g_value_get_boolean(value);
1584
1585                         /* stop preview and destory mmfw handle */
1586                         if (!cam_app_preview_stop()) {
1587                                 cam_critical(LOG_MM, "cam_app_preview_stop faild");
1588                                 return FALSE;
1589                         }
1590
1591                         if (!cam_mm_destory()) {
1592                                 cam_critical(LOG_MM, "cam_mm_destory faild");
1593                                 return FALSE;
1594                         }
1595
1596                         if (camapp->self_portrait == TRUE) {
1597                                 camapp->device_type = CAM_DEVICE_VGA;
1598                         } else {
1599                                 camapp->device_type = CAM_DEVICE_MEGA;
1600                         }
1601
1602                         DEBUG_TRACE("device_type = %d", camapp->device_type);
1603
1604                         cam_config_set_boolean(PROP_SELF_PORTRAIT_NAME, tempval);
1605
1606                         if (!cam_mm_create(camapp->device_type, camapp->camera_mode)) {
1607                                 cam_critical(LOG_MM, "cam_mm_create failed");
1608                                 cam_app_notice_popup(ad, "cam_app_preview_start faild ", cam_app_timeout_notice_response_cb);
1609                                 return FALSE;
1610                         }
1611
1612                         ResetCaps();
1613                         define_mouse_callback(ad);
1614
1615                         /* get reserved setting value */
1616                         if (camapp->self_portrait == FALSE) {
1617                                 camapp->photo_resolution = camapp->reserved_setting_data.rear_photo_resolution;
1618                                 camapp->video_resolution = camapp->reserved_setting_data.rear_video_resolution;
1619                                 camapp->shooting_mode = camapp->reserved_setting_data.rear_shooting_mode;
1620                                 camapp->recording_mode = camapp->reserved_setting_data.rear_recording_mode;
1621                         } else {
1622                                 camapp->photo_resolution = camapp->reserved_setting_data.front_photo_resolution;
1623                                 camapp->video_resolution = camapp->reserved_setting_data.front_video_resolution;
1624                                 camapp->shooting_mode = camapp->reserved_setting_data.front_shooting_mode;
1625                                 camapp->recording_mode = camapp->reserved_setting_data.front_recording_mode;
1626                         }
1627
1628                         /* set shot, rec mode */
1629                         CAM_GVALUE_SET_INT(set_value, camapp->shooting_mode);
1630                         cam_handle_value_set(ad, PROP_SHOT_MODE, &set_value);
1631                         CAM_GVALUE_SET_INT(set_value, camapp->recording_mode);
1632                         cam_handle_value_set(ad, PROP_REC_MODE, &set_value);
1633
1634                         camapp->zoom_mode = ZOOM_DEFAULT;
1635
1636                         /* start preview */
1637                         if (!cam_app_init_attribute(ad, camapp->camera_mode)) {
1638                                 cam_critical(LOG_MM, "cam_app_init_attribute failed");
1639                         }
1640
1641                         cam_continuous_af_start(ad);
1642                         if (!cam_app_preview_start(ad)) {
1643                                 cam_critical(LOG_MM, "cam_app_preview_start failed");
1644                                 cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA"), cam_app_timeout_notice_response_cb);
1645                                 return FALSE;
1646                         }
1647
1648                         settings_guideline_refresh(ad);
1649
1650                         if(camapp->af_mode == CAM_FOCUS_FACE){
1651                                 /*start face detection*/
1652                                 if (cam_mm_is_supported_face_detection()) {
1653                                         cam_mm_start_camera_face_detection(camapp->face_detect_cb, (void *)ad);
1654                                         if (!cam_mm_set_preview_cb(cam_face_detection_focus_start_stream, (void*)ad)) {
1655                                                 DEBUG_TRACE("preview callback set error");
1656                                         }
1657                                         cam_app_run_video_stream();
1658                                 } else {
1659                                         DEBUG_TRACE("not support face detect mode");
1660                                 }
1661                         }
1662                 }
1663                 break;
1664
1665         case PROP_SHOT_MODE:
1666                 {
1667                         gint tempval = g_value_get_int(value);
1668                         gint cur_mode = camapp->shooting_mode;
1669
1670                         camapp->shooting_mode = tempval;
1671
1672                         if (!cam_shooting_mode_change(ad)) {
1673                                 cam_critical(LOG_UI, "shot mode set fail");
1674                                 camapp->shooting_mode = cur_mode;
1675                                 return FALSE;
1676                         }
1677
1678                         if (camapp->self_portrait == FALSE) {
1679                                 camapp->reserved_setting_data.rear_shooting_mode = tempval;
1680                         } else {
1681                                 camapp->reserved_setting_data.front_shooting_mode = tempval;
1682                         }
1683
1684                         cam_app_focus_guide_update(ad);
1685                 }
1686                 break;
1687         case PROP_REC_MODE:
1688                 {
1689                         gint tempval = g_value_get_int(value);
1690                         int video_resolution = 0;
1691                         GValue set_value = { 0, };
1692                         g_value_init(&set_value, G_TYPE_INT);
1693
1694                         camapp->recording_mode = tempval;
1695
1696                         if (camapp->self_portrait == FALSE) {
1697                                 camapp->reserved_setting_data.rear_recording_mode = tempval;
1698                         } else {
1699                                 camapp->reserved_setting_data.front_recording_mode = tempval;
1700                         }
1701
1702                         if (camapp->recording_mode == CAM_RECORD_NORMAL) {
1703                                 video_resolution = cam_config_get_int(PROP_VIDEO_RESOLUTION_NAME, REC_RESOLUTION_DEFAULT);
1704                                 g_value_set_int(&set_value, video_resolution);
1705                         } else if (camapp->recording_mode == CAM_RECORD_SLOW || camapp->recording_mode == CAM_RECORD_FAST) {
1706                                 g_value_set_int(&set_value, CAM_RESOLUTION_QVGA);
1707                         } else if (camapp->recording_mode == CAM_RECORD_SELF) {
1708                                 video_resolution = cam_config_get_int(PROP_SELF_VIDEO_RESOLUTION_NAME, SELF_REC_RESOLUTION_DEFAULT);
1709                                 g_value_set_int(&set_value, video_resolution);
1710                         } else if (camapp->recording_mode == CAM_RECORD_MMS || camapp->recording_mode == CAM_RECORD_SELF_MMS) {
1711                                 g_value_set_int(&set_value, CAM_RESOLUTION_QCIF);
1712                         }
1713
1714                         cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &set_value);
1715 /*
1716                         if (!cam_recording_mode_change(ad, tempval)) {
1717                                 cam_critical(LOG_UI, "rec mode change fail - mode[%d]", tempval);
1718                                 return FALSE;
1719                         }
1720 */
1721                 }
1722                 break;
1723         case PROP_SCENE_MODE:
1724                 {
1725                         gint tempval = g_value_get_int(value);
1726                         if (!cam_mm_set_program_mode(tempval)) {
1727                                 cam_warning(LOG_UI, "program mode set fail");
1728                                 return FALSE;
1729                         }
1730                         camapp->scene_mode = tempval;
1731
1732                         /* set flash */
1733                         int flash = CAM_FLASH_OFF;
1734                         if(camapp->scene_mode == CAM_SCENE_NONE){
1735                                 flash = cam_config_get_int(PROP_SCENE_MODE_NAME, PG_MODE_DEFAULT);
1736                         }else if(camapp->scene_mode == CAM_SCENE_CANDLELIGHT){
1737                                 flash = CAM_FLASH_ON;
1738                         }else {
1739                                 flash = CAM_FLASH_OFF;
1740                         }
1741                         GValue set_value = { 0, };
1742                         g_value_init(&set_value, G_TYPE_INT);
1743                         g_value_set_int(&set_value, flash);
1744                         cam_handle_value_set(ad, PROP_FLASH, &set_value);
1745
1746                 }
1747                 break;
1748         case PROP_PHOTO_RESOLUTION:
1749                 {
1750                         gint tempval = g_value_get_int(value);
1751
1752                         DEBUG_TRACE("*******************************************************");
1753                         DEBUG_TRACE("value set : PROP_RESOLUTION setting");
1754                         DEBUG_TRACE(" tempval = %d ", tempval);
1755                         DEBUG_TRACE("CAM_RESOLUTION_W = %d ,CAM_RESOLUTION_H=%d ", CAM_RESOLUTION_W(tempval), CAM_RESOLUTION_H(tempval));
1756                         DEBUG_TRACE("*******************************************************");
1757
1758                         if (!cam_app_reset_resolution(ad, CAM_RESOLUTION_W(tempval), CAM_RESOLUTION_H(tempval), FALSE)) {
1759                                 cam_warning(LOG_UI, "resolution set fail");
1760                                 return FALSE;
1761                         }
1762
1763                         settings_guideline_refresh(ad);
1764
1765                         camapp->photo_resolution = tempval;
1766
1767                         if (camapp->self_portrait == FALSE) {
1768                                 camapp->reserved_setting_data.rear_photo_resolution = tempval;
1769                                 if (camapp->camera_mode == CAM_CAMERA_MODE) {
1770                                         cam_config_set_int(PROP_PHOTO_RESOLUTION_NAME, tempval);
1771                                 }
1772                         } else {
1773                                 camapp->reserved_setting_data.front_photo_resolution = tempval;
1774                                 cam_config_set_int(PROP_SELF_PHOTO_RESOLUTION_NAME, tempval);
1775                         }
1776
1777                         cam_app_get_preview_offset_coordinate(ad);
1778                         ad->remained_count = cam_system_get_still_count_by_resolution(ad);
1779                         indicator_update_remain_count(ad);
1780                 }
1781                 break;
1782         case PROP_VIDEO_RESOLUTION:
1783                 {
1784                         gint tempval = g_value_get_int(value);
1785
1786                         camapp->video_resolution = tempval;
1787
1788                         if (camapp->self_portrait == FALSE) {
1789                                 camapp->reserved_setting_data.rear_video_resolution = tempval;
1790                                 if (camapp->recording_mode == CAM_RECORD_NORMAL) {
1791                                         cam_config_set_int(PROP_VIDEO_RESOLUTION_NAME, tempval);
1792                                 }
1793                         } else {
1794                                 camapp->reserved_setting_data.front_video_resolution = tempval;
1795                                 if (camapp->recording_mode == CAM_RECORD_SELF) {
1796                                         cam_config_set_int(PROP_SELF_VIDEO_RESOLUTION_NAME, tempval);
1797                                 }
1798                         }
1799                 }
1800                 break;
1801         case PROP_FPS:
1802                 {               /*  fps may not set it alone */
1803                         gint tempval = g_value_get_int(value);
1804                         if (!cam_mm_set_fps(tempval)) {
1805                                 cam_warning(LOG_UI, "fps set fail");
1806                                 return FALSE;
1807                         }
1808                         camapp->fps = tempval;
1809                 }
1810                 break;
1811         case PROP_BRIGHTNESS:
1812                 {
1813                         gint tempval = g_value_get_int(value);
1814                         if (!cam_mm_set_brightness(tempval)) {
1815                                 cam_warning(LOG_UI, "brightness set fail");
1816                                 return FALSE;
1817                         }
1818                         camapp->brightness = tempval;
1819                 }
1820                 break;
1821         case PROP_WB:
1822                 {
1823                         gint tempval = g_value_get_int(value);
1824                         if (!cam_mm_set_white_balance(tempval)) {
1825                                 cam_warning(LOG_UI,
1826                                             "white balance set fail: %d",
1827                                             tempval);
1828                                 return FALSE;
1829                         }
1830
1831                         camapp->white_balance = tempval;
1832
1833                         if (camapp->self_portrait)
1834                                 camapp->reserved_setting_data.front_wb = tempval;
1835                         else
1836                                 camapp->reserved_setting_data.rear_wb = tempval;
1837
1838                 }
1839                 break;
1840         case PROP_ISO:
1841                 {
1842                         gint tempval = g_value_get_int(value);
1843                         if (!cam_mm_set_iso(tempval)) {
1844                                 cam_warning(LOG_UI, "iso set fail");
1845                                 return FALSE;
1846                         }
1847                         camapp->iso = tempval;
1848                         cam_config_set_int(PROP_ISO_NAME, tempval);
1849                 }
1850                 break;
1851         case PROP_AUTO_CONTRAST:
1852                 {
1853                         gboolean tempval = g_value_get_boolean(value);
1854                         if (!cam_mm_enable_auto_contrast(tempval)) {
1855                                 cam_warning(LOG_UI, "contrast set fail");
1856                                 return FALSE;
1857                         }
1858                         camapp->auto_contrast = tempval;
1859                         cam_config_set_int(PROP_AUTO_CONTRAST_NAME, tempval);
1860                 }
1861                 break;
1862         case PROP_METERING:
1863                 {
1864                         gint tempval = g_value_get_int(value);
1865                         if (!cam_mm_set_auto_exposure(tempval)) {
1866                                 cam_warning(LOG_UI, "auto_exposure set fail");
1867                                 return FALSE;
1868                         }
1869                         camapp->auto_exposure = tempval;
1870                         cam_config_set_int(PROP_METERING_NAME, tempval);
1871                 }
1872                 break;
1873         case PROP_EFFECT:
1874                 {
1875                         gint tempval = g_value_get_int(value);
1876                         if (!cam_mm_set_effect(tempval)) {
1877                                 cam_warning(LOG_UI, "effect set fail : %d",
1878                                             tempval);
1879                                 return FALSE;
1880                         }
1881                         camapp->effect = tempval;
1882
1883                         if (camapp->self_portrait == FALSE) {
1884                                 camapp->reserved_setting_data.rear_effect = tempval;
1885                         } else {
1886                                 camapp->reserved_setting_data.front_effect = tempval;
1887                         }
1888                 }
1889                 break;
1890         case PROP_AF_MODE:
1891                 {
1892                         gint tempval = g_value_get_int(value);
1893                         gint oldval = cam_config_get_int(PROP_AF_NAME, CAM_FOCUS_AUTO);
1894                         if (oldval == CAM_FOCUS_FACE && tempval != CAM_FOCUS_FACE) {
1895                                 cam_mm_stop_camera_face_detection();
1896                                 cam_app_stop_video_stream();
1897                         }
1898
1899                         if (tempval == CAM_FOCUS_FACE) {
1900                                 if (!cam_mm_set_focus_mode(CAMERA_ATTR_AF_NORMAL)) {
1901                                         cam_warning(LOG_UI, "detect mode set fail");
1902                                         return FALSE;
1903                                 }
1904
1905                                 /*start face detection*/
1906                                 if (cam_mm_is_supported_face_detection()) {
1907                                         cam_mm_start_camera_face_detection(camapp->face_detect_cb, (void *)ad);
1908                                         if (!cam_mm_set_preview_cb(cam_face_detection_focus_start_stream, (void*)ad)) {
1909                                                 DEBUG_TRACE("preview callback set error");
1910                                         }
1911                                         cam_app_run_video_stream();
1912                                 } else {
1913                                         DEBUG_TRACE("not support face detect mode");
1914                                 }
1915
1916
1917                         } else if ((tempval == CAM_FOCUS_AUTO) || (tempval == CAM_FOCUS_MACRO)) {
1918                                 if (!cam_mm_set_focus_mode(tempval)) {
1919                                         cam_warning(LOG_UI, "af mode set fail");
1920                                         return FALSE;
1921                                 }
1922
1923                                 if (!cam_mm_set_preview_cb(camapp->preview_cb, (void*)ad)) {
1924                                         DEBUG_TRACE("preview callback set error");
1925                                 }
1926
1927                         } else {
1928                                 cam_warning(LOG_UI, "unknow af mode : %d", tempval);
1929                                 return FALSE;
1930                         }
1931                         camapp->af_mode = tempval;
1932                         cam_app_focus_guide_update(ad);
1933                         if (camapp->camera_mode == CAM_CAMERA_MODE && camapp->shooting_mode == CAM_SINGLE_MODE){
1934                                 cam_config_set_int(PROP_AF_NAME, tempval);
1935                         }
1936                 }
1937                 break;
1938         case PROP_AHS:
1939                 {
1940                         gboolean tempval = g_value_get_boolean(value);
1941
1942                         if (!cam_mm_set_anti_hand_shake(tempval)) {
1943                                 cam_warning(LOG_UI, "anti_shake set fail");
1944                                 return FALSE;
1945                         }
1946
1947                         camapp->anti_shake = tempval;
1948                         cam_config_set_int(PROP_AHS_NAME, tempval);
1949                 }
1950                 break;
1951         case PROP_WDR:/*auto contrast*/
1952                 {
1953                         gint tempval = g_value_get_int(value);
1954                         if (!cam_mm_set_wdr(tempval)) {
1955                                 cam_warning(LOG_UI, "wdr set fail");
1956                                 return FALSE;
1957                         }
1958                         camapp->wdr = tempval;
1959                         cam_config_set_int(PROP_WDR_NAME, tempval);
1960                 }
1961                 break;
1962         case PROP_FLASH:
1963                 {
1964                         gint tempval = g_value_get_int(value);
1965                         if (!cam_mm_set_flash(tempval)) {
1966                                 cam_warning(LOG_UI, "flash set fail");
1967                                 return FALSE;
1968                         }
1969                         camapp->flash = tempval;
1970                         /*fix me ,why only when in camera single mode ,
1971                                 save the FLASH setting value to config file*/
1972                         if ((camapp->camera_mode == CAM_CAMERA_MODE
1973                              && camapp->shooting_mode == CAM_SINGLE_MODE)
1974                             || camapp->camera_mode == CAM_CAMCORDER_MODE) {
1975                                 cam_config_set_int(PROP_FLASH_NAME, tempval);
1976                         }
1977                 }
1978                 break;
1979         case PROP_TIMER:
1980                 {
1981                         gint tempval = g_value_get_int(value);
1982                         camapp->timer = tempval;
1983                 }
1984                 break;
1985         case PROP_IMAGE_QUALITY:
1986                 {
1987                         gint tempval = g_value_get_int(value);
1988                         if (!cam_mm_set_image_enc_quality(tempval)) {
1989                                 cam_warning(LOG_UI,
1990                                             "image quality[%d] set fail",
1991                                             tempval);
1992                                 return FALSE;
1993                         }
1994                         camapp->image_quality = tempval;
1995                 }
1996                 break;
1997         case PROP_VIDEO_QUALITY:
1998                 {
1999                         gint tempval = g_value_get_int(value);
2000                         if (!cam_app_set_video_quality(ad, tempval)) {
2001                                 cam_warning(LOG_UI,
2002                                             "video quality[%d] set fail",
2003                                             tempval);
2004                                 return FALSE;
2005                         }
2006                         camapp->video_quality = tempval;
2007                 }
2008                 break;
2009         case PROP_AUDIO_REC:
2010                 {
2011                         gboolean tempval = g_value_get_boolean(value);
2012                         if (!cam_mm_set_audio_recording(tempval)) {
2013                                 cam_warning(LOG_UI, "audio_recording set fail");
2014                                 return FALSE;
2015                         }
2016                         camapp->audio_recording = tempval;
2017                 }
2018                 break;
2019         case PROP_AUDIO_QUALITY:
2020                 {
2021                         gint tempval = g_value_get_int(value);
2022                         camapp->audio_quality = tempval;
2023                 }
2024                 break;
2025         case PROP_BATTERY_CHARG:
2026                 {
2027                         gint tempval_charging = g_value_get_int(value);
2028
2029                         DEBUG_TRACE("charging = %d", tempval_charging);
2030                         camapp->battery_charging = tempval_charging;
2031                         camapp->battery_level = cam_utils_get_battery_level();
2032                         indicator_update_battery(ad, camapp->battery_level);
2033                 }
2034                 break;
2035         case PROP_BATTERY_LEVEL:
2036                 {
2037                         gint tempval = g_value_get_int(value);
2038                         camapp->battery_charging = cam_utils_get_charging_status();
2039                         camapp->battery_level = tempval;
2040                         indicator_update_battery(ad, camapp->battery_level);
2041
2042                 }
2043                 break;
2044         case PROP_ZOOM:
2045                 {
2046                         gint tempval = g_value_get_int(value);
2047                         DEBUG_TRACE("tempval:%d", tempval);
2048                         if (!cam_mm_set_zoom(tempval)) {
2049                                 cam_warning(LOG_UI, "zoom set fail");
2050                                 return FALSE;
2051                         }
2052                         /*camapp->zoom_mode = tempval;*/ /*note: zoom_mode is zoom level, is not same this value*/
2053                 }
2054                 break;
2055         case PROP_STORAGE:
2056                 {
2057                         gint tempval = g_value_get_int(value);
2058
2059                         camapp->storage = tempval;
2060
2061                         vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_CAMERA_INT, camapp->storage);
2062 //                      cam_config_set_int(PROP_STORAGE_NAME, tempval);
2063
2064                         indicator_update_storage(ad);
2065                 }
2066                 break;
2067         case PROP_GUIDELINE:
2068                 {
2069                         gboolean tempval = g_value_get_boolean(value);
2070
2071                         camapp->guideline = tempval;
2072                         cam_config_set_boolean(PROP_GUIDELINE_NAME, tempval);
2073                 }
2074                 break;
2075         case PROP_GPS:
2076                 {
2077                         gboolean tempval = g_value_get_boolean(value);
2078
2079                         if (tempval) {
2080                                 camapp->need_gps_popup = TRUE;
2081                                 if (!cam_app_lbs_start(ad))
2082                                         return FALSE;
2083
2084                                 return TRUE;
2085                         } else {
2086                                 if (ad->gps_animation_timer)
2087                                         REMOVE_TIMER(ad->gps_animation_timer);
2088                                 if (!cam_app_lbs_stop(ad))
2089                                         return FALSE;
2090
2091                                 return TRUE;
2092                         }
2093                 }
2094                 break;
2095         case PROP_GPS_LEVEL:
2096                 {
2097                         gint tempval = g_value_get_int(value);
2098
2099                         camapp->gps_level = tempval;
2100                         indicator_update_gps_level(ad);
2101                 }
2102                 break;
2103         case PROP_REVIEW:
2104                 {
2105                         gboolean tempval = g_value_get_boolean(value);
2106                         camapp->review = tempval;
2107                         cam_config_set_boolean(PROP_REVIEW_NAME, tempval);
2108                 }
2109                 break;
2110         case PROP_IMAGE_COUNT:
2111                 {
2112                         gint tempval = g_value_get_int(value);
2113                         if (!cam_mm_set_image_count(tempval)) {
2114                                 cam_warning(LOG_UI, "image_count set fail");
2115                                 return FALSE;
2116                         }
2117                         camapp->image_count = tempval;
2118                 }
2119                 break;
2120         case PROP_SHUTTER_SOUND:
2121                 {
2122                         gint tempval = g_value_get_int(value);
2123                         camapp->shutter_sound = tempval;
2124                 }
2125                 break;
2126         case PROP_SIZE_LIMIT:
2127                 {
2128                         gint tempval = g_value_get_int(value);
2129                         if (!cam_app_set_size_limit(tempval, camapp->size_limit_type)) {
2130                                 cam_warning(LOG_UI, "size_limit set fail");
2131                                 return FALSE;
2132                         }
2133                         camapp->size_limit = tempval;
2134                 }
2135                 break;
2136         case PROP_SIZE_LIMIT_TYPE:
2137                 {
2138                         gint tempval = g_value_get_int(value);
2139                         camapp->size_limit_type = tempval;
2140                 }
2141                 break;
2142         case PROP_REC_TIME:
2143                 {
2144                         guint tempval = g_value_get_uint(value);
2145                         camapp->rec_elapsed = tempval;
2146                 }
2147                 break;
2148         case PROP_REC_FILE_SIZE:
2149                 {
2150                         guint tempval = g_value_get_uint(value);
2151                         camapp->rec_filesize = tempval;
2152                 }
2153                 break;
2154         case PROP_OUTDOOR_VISIBILITY:
2155                 {
2156                         gboolean tempval = g_value_get_boolean(value);
2157                         cam_mm_set_outdoor_visibility(tempval);
2158                         camapp->outdoor_visibility = tempval;
2159                 }
2160                 break;
2161         case PROP_VOLUME_KEY:
2162                 {
2163                         gint tempval = g_value_get_int(value);
2164                         camapp->volume_key = tempval;
2165                         cam_config_set_int(PROP_VOLUME_KEY_NAME, tempval);
2166                 }
2167                 break;
2168         case PROP_SAVE_AS_FLIP:
2169                 {
2170                         gboolean tempval = g_value_get_boolean(value);
2171
2172                         if (camapp->camera_mode == CAM_CAMERA_MODE) {
2173                                 cam_app_preview_stop();
2174                                 cam_mm_set_image_flip(tempval);
2175                                 cam_app_preview_start(ad);
2176                         }
2177
2178                         camapp->save_as_flip= tempval;
2179                 }
2180                 break;
2181         case PROP_BURST_SHOT:
2182                 {
2183                         gboolean tempval = g_value_get_boolean(value);
2184
2185                         camapp->burst_shot = tempval;
2186                         cam_config_set_boolean(PROP_BURST_SHOT_NAME, tempval);
2187                 }
2188                 break;
2189         default:
2190                 cam_warning(LOG_UI, "unknow type :%d ", type);
2191                 return FALSE;
2192                 break;
2193         }
2194         /* indicator should be updated here!!! */
2195 /*      change_indicator_mode_icons(ad); */
2196         return TRUE;
2197 }
2198
2199 /*note: in this function ,just do data logic,please do not add any EFL code in it*/
2200 gboolean cam_app_mode_change(void *data, int to_mode)
2201 {
2202         struct appdata *ad = (struct appdata *)data;
2203         cam_retv_if(ad == NULL, FALSE);
2204         CamAppData *camapp = ad->camapp_handle;
2205         cam_retv_if(camapp == NULL, FALSE);
2206
2207         debug_fenter(LOG_UI);
2208
2209         ad->timer_activated = FALSE;
2210         ad->emit_continuous_shutter = FALSE;;
2211         /*camapp->guideline = FALSE;*/
2212         cam_app_timeout_checker_remove();
2213         /* draw to_mode icon in preview area */
2214 #ifdef USE_CAMERA_APP_SHUTTER_SOUND
2215         if (ad->play_rec_sound != 0)
2216                 return TRUE;
2217 #endif
2218
2219         if (cam_mm_get_state() == CAMERA_STATE_CAPTURING
2220                 && (camapp->camera_mode == CAM_CAMERA_MODE)) {
2221                 cam_mm_capture_stop(true, CAM_CAMERA_MODE);
2222         }
2223
2224         /*  stop preview and destory mmfw handle */
2225         if (!cam_app_preview_stop()) {
2226                 cam_critical(LOG_MM, "cam_app_preview_stop faild");
2227                 goto MODE_CHANGE_FAILED;
2228
2229         }
2230
2231         /* Idler of capture callback management. wh01.cho@samsung.com. 2010-12-15. */
2232         cam_utils_remove_idler_all(ad);
2233
2234         if (to_mode == CAM_CAMCORDER_MODE) {
2235
2236                 camapp->camera_mode = CAM_CAMCORDER_MODE;
2237
2238                 GValue value = { 0, };
2239                 g_value_init(&value, G_TYPE_INT);
2240
2241                 ad->last_camera_zoom_mode = camapp->zoom_mode;
2242
2243                 switch(camapp->recording_mode)
2244                 {
2245                 case CAM_RECORD_SLOW:
2246                 case CAM_RECORD_FAST:
2247                         {
2248                                 ad->camapp_handle->enable_touch_af = FALSE;
2249                                 camapp->video_resolution = CAM_RESOLUTION_QVGA;
2250                                 camapp->photo_resolution = cam_app_get_max_image_size_by_ratio(ad, camapp->video_resolution);
2251
2252                                 double rate = 0.0;
2253
2254                                 if (camapp->recording_mode == CAM_RECORD_SLOW) {
2255                                         g_value_set_int(&value, SLOW_MOTION_REC_FPS);
2256                                         rate = SLOW_MOTION_PLAY_FPS;
2257                                 } else {
2258                                         g_value_set_int(&value, FAST_MOTION_REC_FPS);
2259                                         rate = FAST_MOTION_PLAY_FPS;
2260                                 }
2261
2262                                 if (!cam_mm_set_recording_motion(rate)) {
2263                                         cam_critical(LOG_UI, "slow motion set fail");
2264                                         return FALSE;
2265                                 }
2266
2267                                 if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2268                                         cam_critical(LOG_UI, "fps set fail");
2269                                         return FALSE;
2270                                 }
2271
2272                                 #if 0
2273                                 g_value_set_int(&value, CAM_RESOLUTION_QVGA);
2274                                 if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2275                                         cam_critical(LOG_UI, "fps set fail");
2276                                         return FALSE;
2277                                 }
2278                                 #endif
2279
2280                                 g_value_set_int(&value, REC_SIZE_LIMIT_DEFAULT);
2281                                 if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2282                                         cam_critical(LOG_UI, "size limit set fail");
2283                                         return FALSE;
2284                                 }
2285
2286                                 if (camapp->zoom_mode != 1) {
2287                                         camapp->zoom_mode = 1;
2288
2289                                         CAM_GVALUE_SET_INT(value, 10);
2290                                         if (!cam_handle_value_set(ad, PROP_ZOOM, &value)) {
2291                                                 cam_critical(LOG_UI, "zoom set fail");
2292                                                 return FALSE;
2293                                         }
2294                                 }
2295                         }
2296                         break;
2297                 case CAM_RECORD_SELF:
2298                         {
2299                                 ad->camapp_handle->enable_touch_af = FALSE;
2300                                 camapp->video_resolution = cam_config_get_int(PROP_SELF_VIDEO_RESOLUTION_NAME, SELF_REC_RESOLUTION_DEFAULT);
2301                                 camapp->photo_resolution = cam_app_get_max_image_size_by_ratio(ad, camapp->video_resolution);
2302
2303                                 g_value_set_int(&value, FPS_DEFAULT);
2304
2305                                 if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2306                                         cam_critical(LOG_UI, "fps set fail");
2307                                         return FALSE;
2308                                 }
2309
2310                                 #if 0
2311                                 g_value_set_int(&value, CAM_RESOLUTION_VGA);
2312                                 if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2313                                         cam_critical(LOG_UI, "resolution set fail");
2314                                         return FALSE;
2315                                 }
2316                                 #endif
2317
2318                                 g_value_set_int(&value, REC_SIZE_LIMIT_DEFAULT);
2319                                 if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2320                                         cam_critical(LOG_UI, "size limit set fail");
2321                                         return FALSE;
2322                                 }
2323
2324                                 if (!cam_mm_reset_recording_motion_fps()) {
2325                                         cam_critical(LOG_UI,
2326                                                          "slow motion fps set fail");
2327                                         return FALSE;
2328                                 }
2329                         }
2330                         break;
2331                 case CAM_RECORD_MMS:
2332                 case CAM_RECORD_SELF_MMS:
2333                         {
2334                                 ad->camapp_handle->enable_touch_af = TRUE;
2335                                 camapp->video_resolution = CAM_RESOLUTION_QCIF;
2336                                 camapp->photo_resolution = cam_app_get_max_image_size_by_ratio(ad, camapp->video_resolution);
2337
2338                                 g_value_set_int(&value, FPS_SLOW);
2339                                 if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2340                                         cam_critical(LOG_UI, "fps set fail");
2341                                         return FALSE;
2342                                 }
2343
2344                                 #if 0
2345                                 g_value_set_int(&value, CAM_RESOLUTION_QCIF);
2346                                 if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2347                                         cam_critical(LOG_UI, "resolution set fail");
2348                                         return FALSE;
2349                                 }
2350                                 #endif
2351
2352                                 g_value_set_int(&value, CAM_REC_MMS_MAX_SIZE);
2353                                 if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2354                                         cam_critical(LOG_UI, "size limit set fail");
2355                                         return FALSE;
2356                                 }
2357
2358                                 if (!cam_mm_reset_recording_motion_fps()) {
2359                                         cam_critical(LOG_UI,
2360                                                          "slow motion fps set fail");
2361                                         return FALSE;
2362                                 }
2363                         }
2364                         break;
2365                 case CAM_RECORD_NORMAL:
2366                         {
2367                                 ad->camapp_handle->enable_touch_af = TRUE;
2368                                 camapp->video_resolution = cam_config_get_int(PROP_VIDEO_RESOLUTION_NAME, REC_RESOLUTION_DEFAULT);
2369                                 camapp->photo_resolution = cam_app_get_max_image_size_by_ratio(ad, camapp->video_resolution);
2370
2371                                 g_value_set_int(&value, FPS_DEFAULT);
2372                                 if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2373                                         cam_critical(LOG_UI, "fps set fail");
2374                                         return FALSE;
2375                                 }
2376
2377                                 #if 0
2378                                 g_value_set_int(&value, resolution_n);
2379                                 if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2380                                         cam_critical(LOG_UI, "resolution set fail");
2381                                         return FALSE;
2382                                 }
2383                                 #endif
2384
2385                                 g_value_set_int(&value, REC_SIZE_LIMIT_DEFAULT);
2386                                 if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2387                                         cam_critical(LOG_UI, "size limit set fail");
2388                                         return FALSE;
2389                                 }
2390
2391                                 if (!cam_mm_reset_recording_motion_fps()) {
2392                                         cam_critical(LOG_UI,
2393                                                          "slow motion fps set fail");
2394                                         return FALSE;
2395                                 }
2396                         }
2397                         break;
2398                 default:
2399                         break;
2400                 }
2401         } else {
2402                 camapp->camera_mode = CAM_CAMERA_MODE;
2403                 camapp->zoom_mode = ad->last_camera_zoom_mode;
2404
2405                 switch (camapp->shooting_mode) {
2406                 case CAM_SINGLE_MODE:
2407                         ad->camapp_handle->enable_touch_af = TRUE;
2408                         camapp->photo_resolution = cam_config_get_int(PROP_PHOTO_RESOLUTION_NAME, IMAGE_RESOLUTION_DEFAULT);
2409                         break;
2410                 case CAM_SELF_SINGLE_MODE:
2411                         ad->camapp_handle->enable_touch_af = FALSE;
2412                         camapp->photo_resolution = cam_config_get_int(PROP_SELF_PHOTO_RESOLUTION_NAME, SELF_IMAGE_RESOLUTION_DEFAULT);
2413                         break;
2414                 default:
2415                         break;
2416                 }
2417         }
2418
2419         if (!cam_callback_init(ad)) {
2420                 cam_critical(LOG_MM, "cam_init_mm_callback failed");
2421                 goto MODE_CHANGE_FAILED;
2422
2423         }
2424         DEBUG_TRACE("camera mode = %d", to_mode);
2425         if (!cam_app_init_attribute(ad, to_mode)) {
2426                 cam_critical(LOG_MM, "cam_app_init_attribute failed");
2427         }
2428
2429         if (!cam_app_preview_start(ad)) {
2430                 cam_critical(LOG_MM, "cam_app_preview_start failed");
2431                 goto MODE_CHANGE_FAILED;
2432
2433         }
2434         cam_app_timeout_checker_init(ad);
2435
2436         return TRUE;
2437
2438 MODE_CHANGE_FAILED:
2439         cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA"), cam_app_timeout_notice_response_cb);
2440         return FALSE;
2441
2442 }
2443
2444 gboolean cam_mode_change(void *data, int to_mode)
2445 {
2446         struct appdata *ad = (struct appdata *)data;
2447         cam_retv_if(ad == NULL, FALSE);
2448         CamAppData *camapp = ad->camapp_handle;
2449         cam_retv_if(camapp == NULL, FALSE);
2450
2451         debug_fenter(LOG_UI);
2452
2453         cam_elm_cache_flush();
2454
2455         evas_object_hide(ad->timer_icon_edje);
2456         REMOVE_TIMER(ad->timer_timer);
2457         ad->timer_activated = FALSE;
2458         ad->emit_continuous_shutter = FALSE;
2459         DEL_EVAS_OBJECT(ad->timer_icon_edje);
2460         DEL_EVAS_OBJECT(ad->guideline_edje);
2461         /*camapp->guideline = FALSE;*/
2462         cam_app_timeout_checker_remove();
2463         /* draw to_mode icon in preview area */
2464 #ifdef USE_CAMERA_APP_SHUTTER_SOUND
2465         if (ad->play_rec_sound != 0)
2466                 return TRUE;
2467 #endif
2468
2469         if (cam_mm_get_state() == CAMERA_STATE_CAPTURING
2470                 && (camapp->camera_mode == CAM_CAMERA_MODE)) {
2471                 cam_mm_capture_stop(true, CAM_CAMERA_MODE);
2472         }
2473
2474         cam_app_destroy_progressbar(ad);
2475         toolbar_shot_guide_popup_destory(ad);
2476
2477         /*  stop preview and destory mmfw handle */
2478         if (!cam_app_preview_stop()) {
2479                 cam_critical(LOG_MM, "cam_app_preview_stop faild");
2480                 goto MODE_CHANGE_FAILED;
2481
2482         }
2483
2484         /* Idler of capture callback management. wh01.cho@samsung.com. 2010-12-15. */
2485         cam_utils_remove_idler_all(ad);
2486
2487         if (to_mode == CAM_CAMCORDER_MODE) {
2488
2489                 camapp->camera_mode = CAM_CAMCORDER_MODE;
2490
2491                 GValue value = { 0, };
2492                 g_value_init(&value, G_TYPE_INT);
2493
2494                 ad->last_camera_zoom_mode = camapp->zoom_mode;
2495
2496                 switch(camapp->recording_mode)
2497                 {
2498                 case CAM_RECORD_SLOW:
2499                 case CAM_RECORD_FAST:
2500                         {
2501                                 ad->camapp_handle->enable_touch_af = FALSE;
2502                                 camapp->video_resolution = CAM_RESOLUTION_QVGA;
2503                                 camapp->photo_resolution = cam_app_get_max_image_size_by_ratio(ad, camapp->video_resolution);
2504
2505                                 double rate = 0.0;
2506
2507                                 if (camapp->recording_mode == CAM_RECORD_SLOW) {
2508                                         g_value_set_int(&value, SLOW_MOTION_REC_FPS);
2509                                         rate = SLOW_MOTION_PLAY_FPS;
2510                                 } else {
2511                                         g_value_set_int(&value, FAST_MOTION_REC_FPS);
2512                                         rate = FAST_MOTION_PLAY_FPS;
2513                                 }
2514
2515                                 if (!cam_mm_set_recording_motion(rate)) {
2516                                         cam_critical(LOG_UI, "slow motion set fail");
2517                                         return FALSE;
2518                                 }
2519
2520                                 if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2521                                         cam_critical(LOG_UI, "fps set fail");
2522                                         return FALSE;
2523                                 }
2524
2525                                 #if 0
2526                                 g_value_set_int(&value, CAM_RESOLUTION_QVGA);
2527                                 if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2528                                         cam_critical(LOG_UI, "fps set fail");
2529                                         return FALSE;
2530                                 }
2531                                 #endif
2532
2533                                 g_value_set_int(&value, REC_SIZE_LIMIT_DEFAULT);
2534                                 if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2535                                         cam_critical(LOG_UI, "size limit set fail");
2536                                         return FALSE;
2537                                 }
2538
2539                                 if (camapp->zoom_mode != 1) {
2540                                         camapp->zoom_mode = 1;
2541
2542                                         CAM_GVALUE_SET_INT(value, 10);
2543                                         if (!cam_handle_value_set(ad, PROP_ZOOM, &value)) {
2544                                                 cam_critical(LOG_UI, "zoom set fail");
2545                                                 return FALSE;
2546                                         }
2547                                 }
2548                         }
2549                         break;
2550                 case CAM_RECORD_SELF:
2551                         {
2552                                 ad->camapp_handle->enable_touch_af = FALSE;
2553                                 camapp->video_resolution = cam_config_get_int(PROP_SELF_VIDEO_RESOLUTION_NAME, SELF_REC_RESOLUTION_DEFAULT);
2554                                 camapp->photo_resolution = cam_app_get_max_image_size_by_ratio(ad, camapp->video_resolution);
2555
2556                                 g_value_set_int(&value, FPS_DEFAULT);
2557
2558                                 if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2559                                         cam_critical(LOG_UI, "fps set fail");
2560                                         return FALSE;
2561                                 }
2562
2563                                 #if 0
2564                                 g_value_set_int(&value, CAM_RESOLUTION_VGA);
2565                                 if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2566                                         cam_critical(LOG_UI, "resolution set fail");
2567                                         return FALSE;
2568                                 }
2569                                 #endif
2570
2571                                 g_value_set_int(&value, REC_SIZE_LIMIT_DEFAULT);
2572                                 if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2573                                         cam_critical(LOG_UI, "size limit set fail");
2574                                         return FALSE;
2575                                 }
2576
2577                                 if (!cam_mm_reset_recording_motion_fps()) {
2578                                         cam_critical(LOG_UI,
2579                                                          "slow motion fps set fail");
2580                                         return FALSE;
2581                                 }
2582                         }
2583                         break;
2584                 case CAM_RECORD_MMS:
2585                 case CAM_RECORD_SELF_MMS:
2586                         {
2587                                 ad->camapp_handle->enable_touch_af = TRUE;
2588                                 camapp->video_resolution = CAM_RESOLUTION_QCIF;
2589                                 camapp->photo_resolution = cam_app_get_max_image_size_by_ratio(ad, camapp->video_resolution);
2590
2591                                 g_value_set_int(&value, FPS_SLOW);
2592                                 if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2593                                         cam_critical(LOG_UI, "fps set fail");
2594                                         return FALSE;
2595                                 }
2596
2597                                 #if 0
2598                                 g_value_set_int(&value, CAM_RESOLUTION_QCIF);
2599                                 if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2600                                         cam_critical(LOG_UI, "resolution set fail");
2601                                         return FALSE;
2602                                 }
2603                                 #endif
2604
2605                                 g_value_set_int(&value, CAM_REC_MMS_MAX_SIZE);
2606                                 if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2607                                         cam_critical(LOG_UI, "size limit set fail");
2608                                         return FALSE;
2609                                 }
2610
2611                                 if (!cam_mm_reset_recording_motion_fps()) {
2612                                         cam_critical(LOG_UI,
2613                                                          "slow motion fps set fail");
2614                                         return FALSE;
2615                                 }
2616                         }
2617                         break;
2618                 case CAM_RECORD_NORMAL:
2619                         {
2620                                 ad->camapp_handle->enable_touch_af = TRUE;
2621                                 camapp->video_resolution = cam_config_get_int(PROP_VIDEO_RESOLUTION_NAME, REC_RESOLUTION_DEFAULT);
2622                                 camapp->photo_resolution = cam_app_get_max_image_size_by_ratio(ad, camapp->video_resolution);
2623
2624                                 g_value_set_int(&value, FPS_DEFAULT);
2625                                 if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2626                                         cam_critical(LOG_UI, "fps set fail");
2627                                         return FALSE;
2628                                 }
2629
2630                                 #if 0
2631                                 g_value_set_int(&value, resolution_n);
2632                                 if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2633                                         cam_critical(LOG_UI, "resolution set fail");
2634                                         return FALSE;
2635                                 }
2636                                 #endif
2637
2638                                 g_value_set_int(&value, REC_SIZE_LIMIT_DEFAULT);
2639                                 if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2640                                         cam_critical(LOG_UI, "size limit set fail");
2641                                         return FALSE;
2642                                 }
2643
2644                                 if (!cam_mm_reset_recording_motion_fps()) {
2645                                         cam_critical(LOG_UI,
2646                                                          "slow motion fps set fail");
2647                                         return FALSE;
2648                                 }
2649                         }
2650                         break;
2651                 default:
2652                         break;
2653                 }
2654         } else {
2655                 camapp->camera_mode = CAM_CAMERA_MODE;
2656                 camapp->zoom_mode = ad->last_camera_zoom_mode;
2657
2658                 switch (camapp->shooting_mode) {
2659                 case CAM_SINGLE_MODE:
2660                         ad->camapp_handle->enable_touch_af = TRUE;
2661                         camapp->photo_resolution = cam_config_get_int(PROP_PHOTO_RESOLUTION_NAME, IMAGE_RESOLUTION_DEFAULT);
2662                         break;
2663                 case CAM_SELF_SINGLE_MODE:
2664                         ad->camapp_handle->enable_touch_af = FALSE;
2665                         camapp->photo_resolution = cam_config_get_int(PROP_SELF_PHOTO_RESOLUTION_NAME, SELF_IMAGE_RESOLUTION_DEFAULT);
2666                         break;
2667                 default:
2668                         break;
2669                 }
2670         }
2671
2672         if (!cam_callback_init(ad)) {
2673                 cam_critical(LOG_MM, "cam_init_mm_callback failed");
2674                 goto MODE_CHANGE_FAILED;
2675
2676         }
2677         DEBUG_TRACE("camera mode = %d", to_mode);
2678         if (!cam_app_init_attribute(ad, to_mode)) {
2679                 cam_critical(LOG_MM, "cam_app_init_attribute failed");
2680         }
2681
2682         cam_app_get_preview_offset_coordinate(ad);
2683
2684         cam_reset_focus_mode(ad);
2685
2686         if (!cam_app_preview_start(ad)) {
2687                 cam_critical(LOG_MM, "cam_app_preview_start failed");
2688                 goto MODE_CHANGE_FAILED;
2689
2690         }
2691         cam_app_timeout_checker_init(ad);
2692
2693         return TRUE;
2694
2695 MODE_CHANGE_FAILED:
2696         cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA"), cam_app_timeout_notice_response_cb);
2697         return FALSE;
2698 }
2699
2700 gboolean cam_recording_mode_change(void *data, int rec_mode)
2701 {
2702         struct appdata *ad = (struct appdata *)data;
2703         CamAppData *camapp = NULL;
2704         //CamDeviceType device_type = CAM_DEVICE_MEGA;
2705         GValue value = { 0 };
2706         int video_dev = 0;
2707         gboolean cam_reset = FALSE;
2708
2709         debug_fenter(LOG_CAM);
2710
2711         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
2712         camapp = ad->camapp_handle;
2713         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
2714
2715         cam_app_timeout_checker_remove();
2716
2717         g_value_init(&value, G_TYPE_INT);
2718
2719         cam_mm_get_video_device(&video_dev);
2720         if (((camapp->recording_mode == CAM_RECORD_SELF || camapp->recording_mode == CAM_RECORD_SELF_MMS )&& video_dev == CAM_DEVICE_MEGA)
2721             || ((camapp->recording_mode != CAM_RECORD_SELF || camapp->recording_mode == CAM_RECORD_SELF_MMS) && video_dev == CAM_DEVICE_VGA)) {
2722
2723                 /*  stop preview and destory mmfw handle */
2724                 cam_reset = TRUE;
2725                 if (!cam_app_preview_stop()) {
2726                         cam_critical(LOG_MM, "cam_app_preview_stop faild");
2727                         return FALSE;
2728                 }
2729                 if (!cam_mm_destory()) {
2730                         cam_critical(LOG_MM, "cam_mm_destory faild");
2731                         return FALSE;
2732                 }
2733 #if 0
2734                 if (camapp->recording_mode == CAM_RECORD_SELF ||camapp->recording_mode == CAM_RECORD_SELF_MMS ) {
2735                         device_type = CAM_DEVICE_VGA;
2736                 } else {
2737                         device_type = CAM_DEVICE_MEGA;
2738                 }
2739 #endif
2740                 if (!cam_mm_create(camapp->device_type, camapp->camera_mode)) {
2741                         cam_critical(LOG_MM, "cam_mm_create failed");
2742                         cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA"), cam_app_timeout_notice_response_cb);
2743                         return FALSE;
2744                 }
2745                 cam_mm_get_video_size( &camapp->default_preview_width, &camapp->default_preview_height);
2746                 DEBUG_TRACE("default_width = %d,default_height = %d", camapp->default_preview_width, camapp->default_preview_height);
2747
2748         }else {
2749                 if (!cam_app_preview_stop()) {
2750                         cam_critical(LOG_MM, "cam_app_preview_stop faild");
2751                         return FALSE;
2752                 }
2753         }
2754         if (rec_mode == CAM_RECORD_SLOW || rec_mode == CAM_RECORD_FAST) {
2755                 ad->camapp_handle->enable_touch_af = FALSE;
2756
2757                 double rate = 0.0;
2758
2759                 if (rec_mode == CAM_RECORD_SLOW) {
2760                         g_value_set_int(&value, SLOW_MOTION_REC_FPS);
2761                         rate = SLOW_MOTION_PLAY_FPS;
2762                 } else {
2763                         g_value_set_int(&value, FAST_MOTION_REC_FPS);
2764                         rate = FAST_MOTION_PLAY_FPS;
2765                 }
2766
2767                 if (!cam_mm_set_recording_motion(rate)) {
2768                         cam_critical(LOG_UI, "slow motion set fail");
2769                         return FALSE;
2770                 }
2771
2772                 if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2773                         cam_critical(LOG_UI, "fps set fail");
2774                         return FALSE;
2775                 }
2776
2777                 g_value_set_int(&value, CAM_RESOLUTION_QVGA);
2778                 if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2779                         cam_critical(LOG_UI, "resolution set fail");
2780                         return FALSE;
2781                 }
2782                 g_value_set_int(&value, REC_SIZE_LIMIT_DEFAULT);
2783                 if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2784                         cam_critical(LOG_UI, "size limit set fail");
2785                         return FALSE;
2786                 }
2787
2788                 if (camapp->zoom_mode != 1) {
2789                         camapp->zoom_mode = 1;
2790
2791                         GValue value = { 0, };
2792
2793                         CAM_GVALUE_SET_INT(value, 10);
2794                         if (!cam_handle_value_set(ad, PROP_ZOOM, &value)) {
2795                                 cam_critical(LOG_UI, "zoom set fail");
2796                                 return FALSE;
2797                         }
2798                 }
2799
2800                 camapp->recording_mode = rec_mode;
2801
2802         } else {
2803                 ad->camapp_handle->enable_touch_af = TRUE;
2804
2805                 if(rec_mode == CAM_RECORD_SELF) {
2806
2807                         ad->camapp_handle->enable_touch_af = FALSE;
2808                         g_value_set_int(&value, FPS_SLOW);
2809                         if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2810                                 cam_critical(LOG_UI, "fps set fail");
2811                                 return FALSE;
2812                         }
2813
2814                         int resolution = cam_config_get_int(PROP_SELF_VIDEO_RESOLUTION_NAME, SELF_REC_RESOLUTION_DEFAULT);
2815
2816                         g_value_set_int(&value, resolution);
2817                         if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2818                                 cam_critical(LOG_UI, "resolution set fail");
2819                                 return FALSE;
2820                         }
2821
2822                         g_value_set_int(&value, REC_SIZE_LIMIT_DEFAULT);
2823                         if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2824                                 cam_critical(LOG_UI, "size limit set fail");
2825                                 return FALSE;
2826                         }
2827
2828                         if (!cam_mm_reset_recording_motion_fps()) {
2829                                 cam_critical(LOG_UI,
2830                                              "slow motion fps set fail");
2831                                 return FALSE;
2832                         }
2833                         camapp->recording_mode = CAM_RECORD_SELF;
2834                 } else if (rec_mode == CAM_RECORD_MMS ||rec_mode == CAM_RECORD_SELF_MMS ) {
2835                         g_value_set_int(&value, FPS_SLOW);
2836                         if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2837                                 cam_critical(LOG_UI, "fps set fail");
2838                                 return FALSE;
2839                         }
2840
2841                         g_value_set_int(&value, CAM_RESOLUTION_QCIF);
2842                         if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2843                                 cam_critical(LOG_UI, "resolution set fail");
2844                                 return FALSE;
2845                         }
2846
2847                         g_value_set_int(&value, CAM_REC_MMS_MAX_SIZE);
2848                         if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2849                                 cam_critical(LOG_UI, "size limit set fail");
2850                                 return FALSE;
2851                         }
2852
2853                         if (!cam_mm_reset_recording_motion_fps()) {
2854                                 cam_critical(LOG_UI,
2855                                              "slow motion fps set fail");
2856                                 return FALSE;
2857                         }
2858                         if (rec_mode == CAM_RECORD_MMS)
2859                                 camapp->recording_mode = CAM_RECORD_MMS;
2860                         else
2861                                 camapp->recording_mode = CAM_RECORD_SELF_MMS;
2862
2863                 } else {
2864                         int resolution_n =
2865                             cam_config_get_int(PROP_VIDEO_RESOLUTION_NAME,  REC_RESOLUTION_DEFAULT);
2866
2867                         g_value_set_int(&value, FPS_DEFAULT);
2868                         if (!cam_handle_value_set(ad, PROP_FPS, &value)) {
2869                                 cam_critical(LOG_UI, "fps set fail");
2870                                 return FALSE;
2871                         }
2872
2873                         g_value_set_int(&value, resolution_n);
2874                         if (!cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &value)) {
2875                                 cam_critical(LOG_UI, "resolution set fail");
2876                                 return FALSE;
2877                         }
2878
2879                         g_value_set_int(&value, REC_SIZE_LIMIT_DEFAULT);
2880                         if (!cam_handle_value_set(ad, PROP_SIZE_LIMIT, &value)) {
2881                                 cam_critical(LOG_UI, "size limit set fail");
2882                                 return FALSE;
2883                         }
2884
2885                         if (!cam_mm_reset_recording_motion_fps()) {
2886                                 cam_critical(LOG_UI,
2887                                              "slow motion fps set fail");
2888                                 return FALSE;
2889                         }
2890                         camapp->recording_mode = CAM_RECORD_NORMAL;
2891
2892                 }
2893                 if (cam_reset) {
2894                         if (!cam_app_init_attribute(ad, camapp->camera_mode)) {
2895                                 cam_critical(LOG_MM, "cam_app_init_attribute failed");
2896 //                              return FALSE;
2897                         }
2898                 } else {
2899                         if (!cam_app_set_recording_mode(ad, rec_mode)) {
2900                                 DEBUG_TRACE("cam_app_set_recording_mode failed");
2901 //                              return FALSE;
2902                         }
2903                 }
2904         }
2905         cam_app_get_preview_offset_coordinate(ad);
2906
2907         if (!cam_callback_init(ad)) {
2908                 cam_critical(LOG_MM, "cam_init_mm_callback failed");
2909                 cam_app_notice_popup(ad, "PREVIEW START FAILED !!", cam_app_timeout_notice_response_cb);
2910                 return FALSE;
2911         }
2912
2913         cam_continuous_af_start(ad);
2914         if (!cam_app_preview_start(ad)) {
2915                 cam_critical(LOG_MM, "cam_app_preview_start failed");
2916                 cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA"), cam_app_timeout_notice_response_cb);
2917                 return FALSE;
2918         }
2919
2920         cam_app_timeout_checker_init(ad);
2921
2922         return TRUE;
2923
2924 }
2925
2926 static gboolean cam_app_set_capture_format_shooting_mode(int mode)
2927 {
2928         switch (mode) {
2929         case CAM_SINGLE_MODE:
2930         case CAM_SELF_SINGLE_MODE:
2931                 if (!cam_mm_set_capture_format(CAMERA_PIXEL_FORMAT_JPEG))
2932                         return FALSE;
2933                 break;
2934         default:
2935                 break;
2936         }
2937
2938         cam_debug(LOG_UI,
2939                   "\n################# shooting mode set return success : %d\n",
2940                   mode);
2941
2942         return TRUE;
2943 }
2944
2945 static void cam_shooting_mode_reset(void *data)
2946 {
2947         struct appdata *ad = (struct appdata *)data;
2948         CamAppData *camapp = NULL;
2949
2950         debug_fenter(LOG_CAM);
2951         cam_retm_if(ad == NULL, "appdata is NULL");
2952         camapp = ad->camapp_handle;
2953         cam_retm_if(camapp == NULL, "camapp_handle is NULL");
2954
2955         cam_app_destroy_progressbar(ad);
2956
2957         return;
2958 }
2959
2960 gboolean cam_shooting_mode_change(void *data)
2961 {
2962         struct appdata *ad = (struct appdata *)data;
2963         CamAppData *camapp = NULL;
2964         GValue value = { 0 };
2965
2966         debug_fenter(LOG_CAM);
2967
2968         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
2969         camapp = ad->camapp_handle;
2970         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
2971
2972         cam_elm_cache_flush();
2973
2974         cam_app_stop_video_stream();
2975         cam_app_timeout_checker_remove();
2976         cam_shooting_mode_reset(ad);
2977
2978         g_value_init(&value, G_TYPE_INT);
2979
2980         cam_debug(LOG_CAM, "Shooting mode = %d ", camapp->shooting_mode);
2981
2982         cam_continuous_shot_data_free(ad);
2983
2984         if (ad->shot_mode_guide_popup)
2985                 toolbar_shot_guide_popup_destory(ad);
2986         ad->emit_continuous_shutter = FALSE;
2987         switch (camapp->shooting_mode) {
2988         case CAM_SINGLE_MODE:
2989                 {
2990                         int resolution = 0, flash = 0, auto_focus = 0, scene_mode = 0, wb = 0, effect = 0;
2991                         resolution = cam_config_get_int(PROP_PHOTO_RESOLUTION_NAME, IMAGE_RESOLUTION_DEFAULT);
2992                         flash = cam_config_get_int(PROP_FLASH_NAME, FLASH_DEFAULT);
2993                         auto_focus = cam_config_get_int(PROP_AF_NAME, AF_DEFAULT);
2994                         scene_mode = cam_config_get_int(PROP_SCENE_MODE_NAME, PG_MODE_DEFAULT);
2995                         wb = camapp->reserved_setting_data.rear_wb;
2996                         effect = camapp->reserved_setting_data.rear_effect;
2997
2998                         /* set resolution */
2999                         g_value_set_int(&value, resolution);
3000                         cam_handle_value_set(ad, PROP_PHOTO_RESOLUTION, &value);
3001
3002                         /* set flash  */
3003                         g_value_set_int(&value, flash);
3004                         cam_handle_value_set(ad, PROP_FLASH, &value);
3005
3006                         /* set auto focus */
3007                         g_value_set_int(&value, auto_focus);
3008                         cam_handle_value_set(ad, PROP_AF_MODE, &value);
3009
3010                         /* set scene */
3011                         g_value_set_int(&value, scene_mode);
3012                         cam_handle_value_set(ad, PROP_SCENE_MODE, &value);
3013
3014                         /* set wb */
3015                         g_value_set_int(&value, wb);
3016                         cam_handle_value_set(ad, PROP_WB, &value);
3017
3018                         /* set effect */
3019                         g_value_set_int(&value, effect);
3020                         cam_handle_value_set(ad, PROP_EFFECT, &value);
3021
3022                         /* set capture count */
3023                         g_value_set_int(&value, IMAGE_COUNT_DEFAULT);
3024                         cam_handle_value_set(ad, PROP_IMAGE_COUNT, &value);
3025                 }
3026                 break;
3027
3028         case CAM_SELF_SINGLE_MODE:
3029                 {
3030                         int resolution, effect, wb = 0;
3031
3032                         resolution = cam_config_get_int(PROP_SELF_PHOTO_RESOLUTION_NAME, SELF_IMAGE_RESOLUTION_DEFAULT);
3033                         effect = camapp->reserved_setting_data.front_effect;
3034                         wb = camapp->reserved_setting_data.front_wb;
3035
3036                         /* set resolution */
3037                         g_value_set_int(&value, resolution);
3038                         cam_handle_value_set(ad, PROP_PHOTO_RESOLUTION, &value);
3039
3040                         /* set flash off */
3041                         g_value_set_int(&value, CAM_FLASH_OFF);
3042                         cam_handle_value_set(ad, PROP_FLASH, &value);
3043
3044                         /* set auto focus */
3045                         g_value_set_int(&value, CAM_FOCUS_AUTO);
3046                         cam_handle_value_set(ad, PROP_AF_MODE, &value);
3047
3048                         /* set scene to NONE */
3049                         g_value_set_int(&value, CAM_SCENE_NONE);
3050                         cam_handle_value_set(ad, PROP_SCENE_MODE, &value);
3051
3052                         /* set effect */
3053                         g_value_set_int(&value, effect);
3054                         cam_handle_value_set(ad, PROP_EFFECT, &value);
3055
3056                         /* set capture count */
3057                         g_value_set_int(&value, IMAGE_COUNT_DEFAULT);
3058                         cam_handle_value_set(ad, PROP_IMAGE_COUNT, &value);
3059
3060                         // set wb
3061                         g_value_set_int(&value, wb);
3062                         cam_handle_value_set(ad, PROP_WB, &value);
3063                 }
3064                 break;
3065         default:
3066                 break;
3067         }
3068
3069         if (!cam_callback_init(ad)) {
3070                 cam_critical(LOG_MM, "cam_init_mm_callback failed");
3071                 cam_app_notice_popup(ad, "PREVIEW START FAILED !!", cam_app_timeout_notice_response_cb);
3072                 return FALSE;
3073         }
3074
3075         cam_app_timeout_checker_init(ad);
3076         return TRUE;
3077 }
3078
3079 gboolean __cam_single_shot_reg_file(char *file_path)
3080 {
3081         GError *error = NULL;
3082
3083         if (file_path) {
3084                 DEBUG_TRACE("register file : %s", file_path);
3085
3086                 if (!cam_file_register(file_path, &error)) {
3087                         cam_critical(LOG_FILE, "cam_file_register fail");
3088                         if (error != NULL) {
3089                                 if (error->message != NULL) {
3090                                         cam_critical(LOG_FILE,
3091                                                      "cam_file_register error [%s]",
3092                                                  error->message);
3093                                 } else {
3094                                         cam_critical(LOG_FILE,
3095                                                      "cam_file_register error but error message is NULL");
3096                                 }
3097                                 g_error_free(error);
3098                                 error = NULL;
3099                         }
3100                 }
3101         } else {
3102                 cam_warning(LOG_FILE, " file path is NULL...");
3103
3104                 return FALSE;
3105         }
3106
3107         return TRUE;
3108 }
3109
3110 static void cam_app_timer_update_count(void *data)
3111 {
3112         struct appdata *ad = (struct appdata *)data;
3113         cam_retm_if(ad == NULL, "appdata is NULL");
3114
3115         cam_debug(LOG_UI, "timer count ... [ %d ]", ad->timer_count);
3116
3117         char count_string[3] = "";
3118
3119         elm_object_part_content_unset(ad->ug_base, "timer_layout");
3120
3121         if (ad->timer_icon_edje == NULL) {
3122                 switch (ad->target_direction) {
3123                 case CAM_TARGET_DIRECTION_LANDSCAPE:
3124                 case CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE:
3125                         ad->timer_icon_edje = cam_app_load_edj(ad->ug_base, CAM_UTILS_EDJ_NAME, "timer_icon_landscape");
3126                         break;
3127                 case CAM_TARGET_DIRECTION_PORTRAIT:
3128                 case CAM_TARGET_DIRECTION_PORTRAIT_INVERSE:
3129                         ad->timer_icon_edje = cam_app_load_edj(ad->ug_base, CAM_UTILS_EDJ_NAME, "timer_icon_portrait");
3130                         break;
3131                 default:
3132                         DEBUG_TRACE("Invalid direction type!!!");
3133                 }
3134
3135                 cam_retm_if(ad->timer_icon_edje == NULL, "timer_icon_edje is NULL");
3136                 elm_object_part_content_set(ad->ug_base, "timer_layout", ad->timer_icon_edje);
3137         }
3138
3139         snprintf(count_string, sizeof(count_string), "%d", ad->timer_count);
3140
3141         edje_object_part_text_set(_EDJ(ad->timer_icon_edje), "text", count_string);
3142
3143         evas_object_show(ad->timer_icon_edje);
3144
3145         return;
3146 }
3147 static Eina_Bool cam_app_gps_timer_cb(void *data)
3148 {
3149         DEBUG_TRACE(" ");
3150         struct appdata *ad = (struct appdata *)data;
3151         cam_retv_if(ad == NULL, ECORE_CALLBACK_CANCEL);
3152         CamAppData *camapp = ad->camapp_handle;
3153         if (camapp == NULL) {
3154                 ad->gps_animation_timer = NULL;
3155                 return ECORE_CALLBACK_CANCEL;
3156         }
3157
3158         int gps_level = CAM_LBS_STATE_DISABLE;
3159         static int count =0;
3160
3161         gps_level = cam_lbs_get_state(); //real gps level
3162         if (gps_level >=CAM_LBS_STATE_SERVICE_ENABLE) {
3163                 camapp->gps = TRUE;
3164                 camapp->gps_level = cam_lbs_get_state();
3165
3166                 if (ad->gps_animation_timer)
3167                         ad->gps_animation_timer = NULL;
3168
3169                 return ECORE_CALLBACK_CANCEL;
3170         }
3171
3172         indicator_update_gps_level(ad);
3173         if (camapp->gps_level == CAM_LBS_STATE_ACCURANCY_DETAILED ) {
3174                 camapp->gps_level = CAM_LBS_STATE_SERVICE_START;
3175         }
3176
3177         if (count > GPS_TIME_OUT) {
3178                 count = 0;
3179                 camapp->gps = FALSE;
3180                 cam_lbs_stop();
3181                 camapp->gps_level = cam_lbs_get_state();
3182                 indicator_update_gps(ad);       /* update gps icon */
3183                 if(!cam_mm_remove_geo_tag())
3184                         DEBUG_TRACE("cam_mm_remove_geo_tag failed");
3185
3186                 if (ad->gps_animation_timer)
3187                         ad->gps_animation_timer = NULL;
3188
3189                 return ECORE_CALLBACK_CANCEL;
3190         }
3191         camapp->gps_level ++;
3192         count ++;
3193
3194         return ECORE_CALLBACK_RENEW;
3195 }
3196
3197 static Eina_Bool cam_app_timer_cb(void *data)
3198 {
3199         struct appdata *ad = (struct appdata *)data;
3200         cam_retv_if(ad == NULL, ECORE_CALLBACK_CANCEL);
3201
3202         CamAppData *camapp = NULL;
3203
3204         camapp = ad->camapp_handle;
3205         if (camapp == NULL) {
3206                 cam_critical(LOG_UI, "camapp_handle is NULL");
3207
3208                 if (ad->timer_timer)
3209                         ad->timer_timer = NULL;
3210                 return ECORE_CALLBACK_CANCEL;
3211         }
3212
3213         ad->timer_count = ad->timer_count - 1;
3214
3215         if (ad->timer_count > 0) {
3216                 cam_debug(LOG_UI, "timer continue ... ");
3217                 cam_app_timer_update_count(ad);
3218                 if (camapp->shutter_sound != CAM_SETTINGS_SOUND_OFF)
3219                         cam_sound_play(CAM_SOUND_EFFECT_TICK, ad);
3220                 return ECORE_CALLBACK_RENEW;
3221         } else {
3222                 cam_debug(LOG_UI, "timer terminated ...");
3223
3224                 ad->timer_activated = false;
3225
3226                 if (ad->timer_icon_edje != NULL) {
3227                         evas_object_del(ad->timer_icon_edje);
3228                         ad->timer_icon_edje = NULL;
3229                 }
3230
3231                 cam_toolbar_update(ad);
3232
3233                 if (camapp->camera_mode == CAM_CAMERA_MODE) {
3234                         cam_set_orient_value(ad);
3235                         if (!cam_image_capture_start(ad))
3236                                 cam_critical(LOG_UI, "cam_image_capture_start failed");
3237                 } else {
3238                         if (!cam_video_record_start(ad))
3239                                 cam_critical(LOG_UI, "cam_video_record_start failed");
3240                 }
3241
3242                 if (ad->timer_timer)
3243                         ad->timer_timer = NULL;
3244
3245                 return ECORE_CALLBACK_CANCEL;
3246         }
3247 }
3248
3249 static void cam_app_start_timer(void *data)
3250 {
3251         struct appdata *ad = (struct appdata *)data;
3252         cam_retm_if(ad == NULL, "appdata is NULL");
3253         CamAppData *camapp = ad->camapp_handle;
3254         cam_retm_if(camapp == NULL, "camapp_handle is NULL");
3255
3256         ad->timer_activated = true;
3257
3258         switch (camapp->timer) {
3259         case CAM_SETTINGS_TIMER_2SEC:
3260                 ad->timer_count = 2;
3261                 break;
3262         case CAM_SETTINGS_TIMER_5SEC:
3263                 ad->timer_count = 5;
3264                 break;
3265         case CAM_SETTINGS_TIMER_10SEC:
3266                 ad->timer_count = 10;
3267                 break;
3268
3269         case CAM_SETTINGS_TIMER_OFF:
3270         default:
3271                 CAM_UI_LOG("can not reach here");
3272                 return;
3273         }
3274
3275         if (camapp->default_capture_mode == CAM_CAPTURE_BURST)
3276                 return;
3277
3278         cam_toolbar_update(ad);
3279
3280         cam_app_timer_update_count(ad);
3281
3282         if (ad->timer_timer != NULL) {
3283                 ecore_timer_del(ad->timer_timer);
3284                 ad->timer_timer = NULL;
3285         }
3286
3287         ad->timer_timer = ecore_timer_add(1.0, cam_app_timer_cb, ad);
3288 }
3289
3290 void cam_app_cancel_timer(void *data)
3291 {
3292         struct appdata *ad = (struct appdata *)data;
3293
3294         ad->timer_activated = FALSE;
3295
3296         REMOVE_TIMER(ad->timer_timer);
3297         DEL_EVAS_OBJECT(ad->timer_icon_edje);
3298
3299         cam_toolbar_update(ad);
3300 }
3301
3302 static void _popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
3303 {
3304         /* cam_app_free_blocking_popup(); */
3305         Evas_Object *notify = (Evas_Object *)data;
3306         cam_popup_remove(notify);
3307         /* evas_object_del(notify); */
3308 }
3309
3310 gboolean cam_image_capture_start(void *data)
3311 {
3312         struct appdata *ad = (struct appdata *)data;
3313         CamAppData *camapp = NULL;
3314         gint64 remain = 0;
3315         gboolean ret = TRUE;
3316
3317         debug_fenter(LOG_UI);
3318
3319         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
3320         camapp = ad->camapp_handle;
3321         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
3322         CAM_TA_ACUM_ITEM_BEGIN("    cam_image_capture_start", 0);
3323         if (camapp->af_mode == CAM_FOCUS_FACE) {
3324                 cam_app_stop_video_stream();
3325         }
3326         DEBUG_TRACE("camapp->burst_shot %d", camapp->burst_shot);
3327         DEBUG_TRACE("camapp->shooting_mode %d", camapp->shooting_mode);
3328         DEBUG_TRACE("camapp->default_capture_mode %d", camapp->default_capture_mode);
3329         remain = cam_system_get_still_count_by_resolution(ad);
3330
3331         if(remain <= 0){
3332                 cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_BODY_UNABLE_TO_SAVE_NOT_ENOUGH_MEMORY"), cam_app_popup_response_cb);
3333                 CAM_TA_ACUM_ITEM_END("    cam_image_capture_start", 0);
3334                 return FALSE;
3335         }
3336
3337         if (camapp->gps) {
3338                 int gps_level = CAM_LBS_STATE_DISABLE;
3339                 gps_level = cam_lbs_get_state();
3340
3341                 if (gps_level >=CAM_LBS_STATE_SERVICE_ENABLE) {
3342                         double longitude = -1.0;
3343                         double latitude = -1.0;
3344                         double altitude = -1.0;
3345                         time_t time_stamp = -1.0;
3346                         if (cam_lbs_get_current_position(&longitude, &latitude, &altitude, &time_stamp)) {
3347                                 DEBUG_TRACE("GEO TAG [longitude = %d, latitude = %d, altitude = %d]", longitude, latitude, altitude);
3348                                 if (!cam_mm_set_gps_data(latitude, longitude, (double)altitude))
3349                                         DEBUG_TRACE("cam_mm_set_gps_data failed");
3350                         }
3351                 }
3352         }
3353         cam_set_orient_value(ad);
3354
3355         if (camapp->camera_mode == CAM_CAMERA_MODE) {
3356                 switch (camapp->shooting_mode) {
3357                 case CAM_SINGLE_MODE:
3358                 case CAM_SELF_SINGLE_MODE:
3359                         if (camapp->burst_shot == TRUE && camapp->default_capture_mode == CAM_CAPTURE_BURST) {
3360                                 camapp->capture_cb = (camera_capturing_cb)cam_continuous_shot_capture_callback;
3361                                 cam_continuous_shot_capture_start(ad);
3362                         } else {
3363                                 camapp->capture_cb = (camera_capturing_cb)__cam_capture_cb;
3364                                 ret = cam_mm_capture_start(camapp->capture_cb, camapp->capture_completed_cb, (void*)ad);
3365                         }
3366                         break;
3367                 default:
3368                         ret = cam_mm_capture_start(camapp->capture_cb, camapp->capture_completed_cb, (void*)ad); /*capture on recoring */
3369                         break;
3370                 }
3371         }else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
3372                 ret = cam_mm_capture_start(camapp->capture_cb, camapp->capture_completed_cb, (void*)ad);
3373         }
3374
3375         CAM_TA_ACUM_ITEM_END("    cam_image_capture_start", 0);
3376         CAM_TA_ACUM_ITEM_BEGIN("    capture_start to capturecallback", 0);
3377         return ret;
3378 }
3379
3380 static gboolean cam_image_capture_stop(void *data)
3381 {
3382         struct appdata *ad = (struct appdata *)data;
3383         CamAppData *camapp = NULL;
3384
3385         debug_fenter(LOG_UI);
3386         ad->stop_continuous_shot = FALSE;
3387         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
3388         camapp = ad->camapp_handle;
3389         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
3390
3391         if (camapp->shooting_mode == CAM_SINGLE_MODE && camapp->default_capture_mode == CAM_CAPTURE_BURST) {
3392                 ad->stop_continuous_shot = TRUE;
3393         }
3394
3395         return TRUE;
3396 }
3397
3398 Eina_Bool cam_image_capture_handle_idler(void *itm)
3399 {
3400         CamIdlerItem *item = (CamIdlerItem *) itm;
3401         struct appdata *ad = NULL;
3402         cam_retvm_if(!item, ECORE_CALLBACK_CANCEL, "CamIdlerItem is NULL");
3403
3404         ad = (struct appdata *)item->data;
3405         cam_retvm_if(!ad, ECORE_CALLBACK_CANCEL, "appdata is NULL");
3406
3407         cam_info(LOG_UI, "call idler[ %p] ", item->idler);
3408         ad->capture_cb_list = g_list_remove(ad->capture_cb_list, item->idler);
3409         if (item->idler) {
3410                 ecore_idler_del(item->idler);
3411                 item->idler = NULL;
3412         }
3413         free(item);
3414         item = NULL;
3415         return cam_image_capture_handle(ad);
3416 }
3417 static Eina_Bool __cam_app_hide_rect_image(void *data)
3418 {
3419         struct appdata *ad = (struct appdata *)data;
3420         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
3421         HIDE_EVAS_OBJECT(ad->rect_image);
3422         return ECORE_CALLBACK_CANCEL;
3423 }
3424
3425 Eina_Bool cam_capture_on_recording_handle(void *data)
3426 {
3427         struct appdata *ad = (struct appdata *)data;
3428         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
3429         CamAppData *camapp = NULL;
3430         camapp = ad->camapp_handle;
3431         cam_retvm_if(camapp == NULL, ECORE_CALLBACK_CANCEL,
3432                      "camapp_handle is NULL");
3433         gboolean preview_skip = FALSE;
3434
3435         if (camapp->filename) {
3436                 cam_debug(LOG_SYS, "#########camapp->filename=%s", camapp->filename);
3437                 CAM_TA_ACUM_ITEM_BEGIN("    send signal to register thread", 0);
3438                 g_queue_push_tail(ad->file_reg_queue, strdup(camapp->filename));
3439                 pthread_cond_signal(&ad->file_reg_cond);
3440                 CAM_TA_ACUM_ITEM_END("    send signal to register thread", 0);
3441         } else {
3442                 cam_app_notice_popup(ad, "Your storage have trouble ", cam_app_popup_response_cb);
3443         }
3444         if (!cam_mm_capture_stop (preview_skip, CAM_CAMERA_MODE)) {
3445                 cam_critical(LOG_MM, " cam_mm_capture_stop error ");
3446         }
3447         ecore_timer_add(0.50, __cam_app_hide_rect_image, ad);
3448
3449         return ECORE_CALLBACK_CANCEL;
3450 }
3451
3452 static Eina_Bool __cam_run_image_viewer_idler(void *data)
3453 {
3454         struct appdata *ad = (struct appdata *)data;
3455         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
3456         CamAppData *camapp = ad->camapp_handle;
3457         cam_retv_if(camapp == NULL, ECORE_CALLBACK_CANCEL);
3458
3459         gboolean launch_special_view = FALSE;
3460
3461         if (!cam_app_run_image_viewer_ug(ad, camapp->filename, launch_special_view)) {
3462                 cam_critical(LOG_UI, "cam_app_run_image_viewer_ug failed");
3463         }
3464
3465         return ECORE_CALLBACK_CANCEL;
3466 }
3467
3468 static void* __cam_run_image_viewer_thread_run(void *data)
3469 {
3470         struct appdata *ad = (struct appdata *)data;
3471
3472         if(ad == NULL){
3473                 pthread_exit(NULL);
3474                 return NULL;
3475         }
3476         CamAppData *camapp = ad->camapp_handle;
3477
3478         if(camapp == NULL){
3479                 pthread_exit(NULL);
3480                 return NULL;
3481         }
3482
3483         while (ad->is_capture_animation_processing) {
3484 //              DEBUG_TRACE("wait capture animation!");
3485         }
3486
3487         ecore_idler_add(__cam_run_image_viewer_idler, (void *)ad);
3488
3489         pthread_exit(NULL);
3490         return NULL;
3491 }
3492
3493 static Ecore_Timer *progress_timer = NULL;
3494
3495 Eina_Bool cam_image_capture_handle(void *data)
3496 {
3497         struct appdata *ad = (struct appdata *)data;
3498         CamAppData *camapp = NULL;
3499
3500         debug_fenter(LOG_UI);
3501
3502         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
3503         camapp = ad->camapp_handle;
3504         cam_retvm_if(camapp == NULL, ECORE_CALLBACK_CANCEL, "camapp_handle is NULL");
3505
3506         CAM_TA_ACUM_ITEM_END("    captured message to cam_image_capture_handle", 0);
3507         CAM_TA_ACUM_ITEM_BEGIN("    cam_image_capture_handle", 0);
3508
3509         pthread_t run_image_viewer_thread;
3510
3511         switch (camapp->shooting_mode) {
3512
3513         case CAM_SINGLE_MODE:
3514         case CAM_SELF_SINGLE_MODE:
3515                 DEBUG_TRACE("start single shot capture. capture mode %d", camapp->default_capture_mode);
3516
3517                 cam_critical(LOG_UI, "completed");
3518
3519                 if( camapp->default_capture_mode == CAM_CAPTURE_SINGLE ||camapp->burst_shot == FALSE) {
3520                         if (camapp->filename) {
3521                                 cam_debug(LOG_SYS, "#########camapp->filename=%s", camapp->filename);
3522                                 CAM_TA_ACUM_ITEM_BEGIN("        send signal to register thread", 0);
3523                                 g_queue_push_tail(ad->file_reg_queue, strdup(camapp->filename));
3524                                 pthread_cond_signal(&ad->file_reg_cond);
3525                                 CAM_TA_ACUM_ITEM_END("    send signal to register thread", 0);
3526                                 cam_app_update_thumbnail();
3527                         } else {
3528                                 cam_app_notice_popup(ad, "Your storage have trouble ", cam_app_popup_response_cb);
3529                         }
3530                 } else {
3531                         if (camapp->continuous_shot_data == NULL) {
3532                                 cam_critical(LOG_SYS, " continuous_shot_data is NULL");
3533                                 return ECORE_CALLBACK_CANCEL;
3534                         }
3535
3536                         int i = 0;
3537
3538                         camapp->continuous_shot_data->capture_status = CAM_CONTI_SHOT_STATUS_STOPPED;
3539
3540                         if (camapp->filename)
3541                                 free(camapp->filename);
3542
3543                         camapp->filename = strdup(camapp->continuous_shot_data->file_path[camapp->continuous_shot_data->shot_num - 1]);
3544
3545                         cam_app_destroy_progressbar(ad);
3546                         if (camapp->continuous_shot_data->error != NULL) {
3547                                 cam_debug(LOG_SYS, " Start to unlink captured files");
3548
3549                                 /*  unlink all captured files */
3550                                 for (i = 0; i < camapp->continuous_shot_data->shot_num; i++) {
3551                                         if (camapp->continuous_shot_data->file_path[i]
3552                                             && !access(camapp->continuous_shot_data->file_path[i], F_OK)) {
3553                                                 unlink(camapp->continuous_shot_data->file_path[i]);
3554                                         }
3555                                 }
3556
3557                                 cam_debug(LOG_SYS, " Unlink done");
3558                                 cam_app_notice_popup(ad, camapp->continuous_shot_data->error->message, cam_app_popup_response_cb);
3559                         } else {
3560                                 cam_critical(LOG_UI, "start to register continuous shot");
3561
3562                         }
3563
3564                         #if 1 /*TODO: need ui guide, for display popup*/
3565                         elm_progressbar_value_set(ad->progress_popup_bar, 1.0);
3566                         if (progress_timer) {
3567                                 ecore_timer_del(progress_timer);
3568                         }
3569                         ad->is_processing = FALSE;
3570                         cam_popup_delete(ad);
3571 #endif
3572
3573                         cam_continuous_shot_data_free(ad);
3574                         cam_toolbar_update(ad);
3575                         cam_app_update_thumbnail();
3576                         camapp->default_capture_mode = CAM_CAPTURE_SINGLE;
3577                         cam_reset_focus_mode(ad);
3578                 }
3579
3580
3581                 if (camapp->review) {
3582                         if (pthread_create(&run_image_viewer_thread, NULL, __cam_run_image_viewer_thread_run, (void *)ad) < 0) {
3583                                 cam_critical(LOG_CAM, "create run_image_viewer_thread failed");
3584                                 return ECORE_CALLBACK_CANCEL;
3585                         }
3586                 }
3587
3588                 break;
3589
3590         default:
3591                 cam_debug(LOG_UI, " Not matched shooting mode [%d]",
3592                           camapp->shooting_mode);
3593                 break;
3594         }
3595         ad->remained_count--;
3596         indicator_update_remain_count(ad);
3597
3598         if (camapp->af_mode == CAM_FOCUS_FACE) { /*note: face focus mode, if start capture,stop draw rect*/
3599                 cam_app_run_video_stream();
3600         }
3601
3602         CAM_TA_ACUM_ITEM_END("    cam_image_capture_handle", 0);
3603
3604         return ECORE_CALLBACK_CANCEL;
3605 }
3606
3607 gboolean cam_camera_touch_af_press(void *data)
3608 {
3609         struct appdata *ad = (struct appdata *)data;
3610         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
3611         CamAppData *camapp = ad->camapp_handle;
3612         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
3613
3614         debug_fenter(LOG_UI);
3615
3616         camapp->focus_mode = CAM_FOCUS_MODE_TOUCH_AUTO;
3617
3618         if (!ad->camapp_handle->key_lock) {
3619                 ad->camapp_handle->key_lock = TRUE;
3620                 if (!cam_camera_key_half_press(ad)) {
3621                         DEBUG_TRACE("cam_camera_key_half_press failed state");
3622                         ad->camapp_handle->key_lock = FALSE;
3623                         camapp->touch_af_state = CAM_TOUCH_AF_STATE_NONE;
3624                         return FALSE;
3625                 }
3626                 ad->camapp_handle->key_lock = FALSE;
3627         }
3628         else
3629                 camapp->touch_af_state = CAM_TOUCH_AF_STATE_NONE;
3630
3631         return TRUE;
3632 }
3633
3634 gboolean cam_camera_key_half_press(void *data)
3635 {
3636         struct appdata *ad = (struct appdata *)data;
3637         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
3638         CamAppData *camapp = ad->camapp_handle;
3639         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
3640
3641         debug_fenter(LOG_UI);
3642
3643         unsigned int capacity;
3644         GetCamDevFuncCaps(&capacity, (void*)ad);
3645
3646         if (!(capacity & CAM_CP_FUNC_FOCUS_MODE))
3647                 return FALSE;
3648
3649         if (camapp->af_mode != CAM_FOCUS_FACE) {
3650                 cam_mm_stop_focusing();
3651
3652                 if (!cam_mm_set_af_area(ad->af_x, ad->af_y, ad->camera_focus_w, ad->camera_focus_h)) {
3653                         DEBUG_TRACE("cam_mm_set_af_area failed");
3654                         return FALSE;
3655                 }
3656                 DEBUG_TRACE("focus mode = %d", camapp->focus_mode);
3657
3658                 if (!cam_mm_start_focusing(camapp->focus_mode)) {
3659                         cam_critical(LOG_MM, " cam_mm_start_focusing error " );
3660                         return FALSE;
3661                 }
3662         }
3663         return TRUE;
3664 }
3665
3666 gboolean cam_camera_key_half_release(void *data)
3667 {
3668         debug_fenter(LOG_UI);
3669         return TRUE;
3670 }
3671
3672 gboolean cam_do_capture(void* data)
3673 {
3674         struct appdata *ad = (struct appdata *)data;
3675         CamAppData *camapp = NULL;
3676         int state = 0;
3677
3678         debug_fenter(LOG_UI);
3679
3680         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
3681         if (ad->is_rotating)
3682                 return FALSE;/*note: now is rotating*/
3683         camapp = ad->camapp_handle;
3684         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
3685         CAM_TA_ACUM_ITEM_BEGIN("  cam_camera_key_press", 0);
3686
3687         if (ad->continuous_af_timer) {
3688                 REMOVE_TIMER(ad->continuous_af_timer);
3689                 ad->continuous_af_timer = ecore_timer_add(FOCUS_FOCUSED_TIME_OUT, __cam_continuous_af_timer_cb, ad);
3690         }
3691
3692         if (camapp->camera_mode == CAM_CAMERA_MODE) {
3693                 state = cam_mm_get_state();
3694                 cam_debug(LOG_UI, " state = %d", state);
3695                 switch (state) {
3696                 case CAMERA_STATE_PREVIEW:
3697                 case CAMERA_STATE_CAPTURED:
3698                         if (ad->timer_activated) {
3699                                 CAM_UI_LOG("timer activated!");
3700                                 cam_app_cancel_timer(ad);
3701                                 if (!cam_image_capture_start(ad)) {
3702                                         return FALSE;
3703                                 }
3704                         } else if (camapp->timer > CAM_SETTINGS_TIMER_OFF) {
3705                                 CAM_UI_LOG("timer start");
3706                                 cam_app_start_timer(ad);
3707                         } else if (!cam_image_capture_start(ad)) {
3708                                 return FALSE;
3709                         }
3710
3711                         break;
3712                 case CAMERA_STATE_CAPTURING:
3713                         cam_debug(LOG_UI, "capturing state");
3714                         return TRUE;
3715                         break;
3716                 case CAMERA_STATE_NONE:
3717                 case CAMERA_STATE_CREATED:
3718                         return FALSE;
3719                         break;
3720                 default:
3721                         return FALSE;
3722                         break;
3723
3724                 }
3725         } else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
3726
3727
3728                 state = cam_mm_get_state();
3729                 cam_debug(LOG_UI, " state = %d", state);
3730                 switch (state) {
3731                 case RECORDER_STATE_RECORDING:
3732                 case RECORDER_STATE_PAUSED:
3733                         if(!cam_image_capture_start(ad)) {
3734                                 HIDE_EVAS_OBJECT(ad->rect_image);
3735                                 return FALSE;
3736                         }
3737                         break;
3738                 case RECORDER_STATE_NONE:
3739                 case RECORDER_STATE_CREATED:
3740                 case RECORDER_STATE_READY:
3741                         return FALSE;
3742                 default:
3743                         return FALSE;
3744                         break;
3745
3746                 }
3747         }
3748
3749         return TRUE;
3750 }
3751
3752 gboolean cam_do_record(void* data)
3753 {
3754         struct appdata *ad = (struct appdata *)data;
3755         CamAppData *camapp = NULL;
3756         int state = 0;
3757
3758         debug_fenter(LOG_UI);
3759
3760         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
3761         if (ad->is_rotating)
3762                 return FALSE;/*note: now is rotating*/
3763         camapp = ad->camapp_handle;
3764         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
3765         CAM_TA_ACUM_ITEM_BEGIN("  cam_camera_key_press", 0);
3766
3767         if (ad->continuous_af_timer) {
3768                 REMOVE_TIMER(ad->continuous_af_timer);
3769                 ad->continuous_af_timer = ecore_timer_add(FOCUS_FOCUSED_TIME_OUT, __focus_guide_destroy, ad);
3770         }
3771
3772         if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
3773                 state = cam_mm_get_state();
3774                 cam_critical(LOG_UI, " state = %d", state);
3775                 switch (state) {
3776                 case RECORDER_STATE_READY:
3777                         {
3778                                 if (ad->timer_activated) {
3779                                         CAM_UI_LOG("timer activated!");
3780                                         cam_app_cancel_timer(ad);
3781                                         if (!cam_video_record_start(ad)) {
3782                                                 return FALSE;
3783                                         }
3784                                 } else if (camapp->timer > CAM_SETTINGS_TIMER_OFF) {
3785                                         CAM_UI_LOG("timer start");
3786                                         cam_app_start_timer(ad);
3787                                 } else if (!cam_video_record_start(ad)) {
3788                                         return FALSE;
3789                                 }
3790                         }
3791                         break;
3792                 case RECORDER_STATE_RECORDING:
3793                         cam_critical(LOG_UI, "RECORDER_STATE_NONE ");
3794                         return FALSE;
3795                         break;
3796                 case RECORDER_STATE_NONE:
3797                         cam_critical(LOG_UI, "RECORDER_STATE_NONE ");
3798                         return FALSE;
3799                         break;
3800                 case RECORDER_STATE_CREATED:
3801                         cam_critical(LOG_UI, "RECORDER_STATE_CREATED ");
3802                         return FALSE;
3803                         break;
3804                 case RECORDER_STATE_PAUSED:
3805                         cam_critical(LOG_UI, "RECORDER_STATE_PAUSED ");
3806                         return FALSE;
3807                         break;
3808                 default:
3809                         return FALSE;
3810                         break;
3811
3812                 }
3813         }
3814
3815         return TRUE;
3816 }
3817
3818 gboolean cam_camera_key_press(void *data)
3819 {
3820         struct appdata *ad = (struct appdata *)data;
3821         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
3822         CamAppData *camapp = ad->camapp_handle;
3823         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
3824
3825         debug_fenter(LOG_UI);
3826
3827         int state = 0;
3828
3829         if (ad->is_rotating)
3830                 return FALSE;/*note: now is rotating*/
3831
3832         CAM_TA_ACUM_ITEM_BEGIN("  cam_camera_key_press", 0);
3833
3834         if (ad->continuous_af_timer) {
3835                 REMOVE_TIMER(ad->continuous_af_timer);
3836
3837                 if (camapp->camera_mode == CAM_CAMCORDER_MODE)
3838                         ad->continuous_af_timer = ecore_timer_add(FOCUS_FOCUSED_TIME_OUT, __focus_guide_destroy, ad);
3839                 else
3840                         ad->continuous_af_timer = ecore_timer_add(FOCUS_FOCUSED_TIME_OUT, __cam_continuous_af_timer_cb, ad);
3841         }
3842
3843         if (camapp->camera_mode == CAM_CAMERA_MODE) {
3844                 state = cam_mm_get_state();
3845                 cam_debug(LOG_UI, " state = %d", state);
3846                 switch (state) {
3847                 case CAMERA_STATE_PREVIEW:
3848                 case CAMERA_STATE_CAPTURED:
3849                         if (ad->timer_activated) {
3850                                 CAM_UI_LOG("timer activated!");
3851                         } else if (camapp->timer >
3852                                    CAM_SETTINGS_TIMER_OFF) {
3853                                 CAM_UI_LOG("timer start");
3854                                 cam_app_start_timer(ad);
3855                         } else if (!cam_image_capture_start(ad)) {
3856                                 return FALSE;
3857                         }
3858                         break;
3859                 case CAMERA_STATE_CAPTURING:
3860                         cam_debug(LOG_UI, "capturing state");
3861                         return TRUE;
3862                         break;
3863                 case CAMERA_STATE_NONE:
3864                 case CAMERA_STATE_CREATED:
3865                         return FALSE;
3866                         break;
3867                 default:
3868                         return FALSE;
3869                         break;
3870
3871                 }
3872         } else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
3873                 state = cam_mm_get_state();
3874                 cam_debug(LOG_UI, " state = %d", state);
3875                 switch (state) {
3876                 case RECORDER_STATE_READY:
3877                         {
3878                                 if (ad->timer_activated) {
3879                                         CAM_UI_LOG("timer activated!");
3880                                 } else if (camapp->timer >
3881                                            CAM_SETTINGS_TIMER_OFF) {
3882                                         CAM_UI_LOG("timer start");
3883                                         cam_app_start_timer(ad);
3884                                 } else if (!cam_video_record_start(ad)) {
3885                                         return FALSE;
3886                                 }
3887                         }
3888                         break;
3889                 case RECORDER_STATE_RECORDING:
3890 #if 1
3891                         camapp->rec_stop_type = CAM_REC_STOP_NORMAL;
3892                         if (!cam_video_record_stop(ad)) {
3893                                 return FALSE;
3894                         }
3895                         return FALSE;
3896 #endif
3897                         break;
3898                 case RECORDER_STATE_NONE:
3899                 case RECORDER_STATE_CREATED:
3900                 case RECORDER_STATE_PAUSED:
3901                         return FALSE;
3902                         break;
3903                 default:
3904                         return FALSE;
3905                         break;
3906
3907                 }
3908         } else {
3909                 cam_critical(LOG_MM, "Unknow camera mode");
3910                 return FALSE;
3911         }
3912         CAM_TA_ACUM_ITEM_END("  cam_camera_key_press", 0);
3913         return TRUE;
3914 }
3915
3916 gboolean cam_camera_key_release(void *data)
3917 {
3918         struct appdata *ad = (struct appdata *)data;
3919         CamAppData *camapp = NULL;
3920         int state = 0;
3921
3922         debug_fenter(LOG_UI);
3923
3924         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
3925         camapp = ad->camapp_handle;
3926         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
3927
3928         if (camapp->camera_mode == CAM_CAMERA_MODE) {
3929
3930                 state = cam_mm_get_state();
3931                 cam_debug(LOG_UI, " state = %d", state);
3932                 switch (state) {
3933                 case CAMERA_STATE_CAPTURING:
3934                         if (!cam_image_capture_stop(ad)) {
3935                                 return FALSE;
3936                         }
3937                         return TRUE;
3938                         break;
3939                 case CAMERA_STATE_PREVIEW:
3940                 case CAMERA_STATE_CREATED:
3941                 case CAMERA_STATE_NONE:
3942                 case CAMERA_STATE_CAPTURED:
3943                         return FALSE;
3944                         break;
3945                 default:
3946                         return FALSE;
3947                         break;
3948
3949                 }
3950         } else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
3951 #if 0
3952                 state = cam_mm_get_state();
3953                 switch (state) {
3954                 case MM_CAMCORDER_STATE_PREPARE:
3955                         if (!cam_video_record_start(ad)) {
3956                                 return FALSE;
3957                         }
3958                         break;
3959                 case MM_CAMCORDER_STATE_RECORDING:
3960                         if (!cam_video_record_stop(ad)) {
3961                                 return FALSE;
3962                         }
3963                         return FALSE;
3964                         break;
3965                 case MM_CAMCORDER_STATE_NONE:
3966                 case MM_CAMCORDER_STATE_NULL:
3967                 case MM_CAMCORDER_STATE_READY:
3968                 case MM_CAMCORDER_STATE_CAPTURING:
3969                 case MM_CAMCORDER_STATE_PAUSED:
3970                         return FALSE;
3971                         break;
3972                 default:
3973                         return FALSE;
3974                         break;
3975
3976                 }
3977 #endif
3978         } else {
3979                 cam_critical(LOG_MM, "Unknow camera mode");
3980                 return FALSE;
3981         }
3982
3983         return TRUE;
3984 }
3985
3986 void cam_reset_focus_coordinate(void* data)
3987 {
3988         struct appdata *ad = (struct appdata *)data;
3989         cam_retm_if(ad == NULL, "appdata is NULL");
3990
3991         ad->af_x = (ad->win_width / 2) - ad->preview_offset_x;
3992         ad->af_y = (ad->win_height / 2) - ad->preview_offset_y;
3993
3994         ad->af_x = (ad->af_x * ad->camfw_video_width) / ad->preview_w;
3995         ad->af_y = (ad->af_y * ad->camfw_video_height) / ad->preview_h;
3996
3997         /* init */
3998         ad->touch_lcd_x = (ad->win_height / 2);
3999         ad->touch_lcd_y = (ad->win_width / 2);
4000
4001         ad->af_start_x = 0;
4002         ad->af_start_y = 0;
4003
4004         switch (ad->rot_current) {
4005         case APP_DEVICE_ORIENTATION_0:
4006                 {
4007                         ad->af_start_x = ad->touch_lcd_x;
4008                         ad->af_start_y = ad->touch_lcd_y;
4009                 }
4010                 break;
4011         case APP_DEVICE_ORIENTATION_180:
4012                 {
4013                         ad->af_start_x = ad->win_height - ad->touch_lcd_x;
4014                         ad->af_start_y = ad->win_width - ad->touch_lcd_y;
4015                 }
4016                 break;
4017         case APP_DEVICE_ORIENTATION_270:
4018                 {
4019                         ad->af_start_x = ad->touch_lcd_y;
4020                         ad->af_start_y = ad->win_height - ad->touch_lcd_x;
4021                 }
4022                 break;
4023         case APP_DEVICE_ORIENTATION_90:
4024                 {
4025                         ad->af_start_x = ad->win_width - ad->touch_lcd_y;
4026                         ad->af_start_y = ad->touch_lcd_x;
4027                 }
4028                 break;
4029         default:
4030                 break;
4031         }
4032
4033         /* adjust */
4034         DEBUG_TRACE("ad->af_start_x=%f, ad->af_start_y=%f", ad->af_start_x, ad->af_start_y);
4035
4036         ad->camera_focus_w = CAMERA_FOCUS_W * elm_config_scale_get();
4037         ad->camera_focus_h = CAMERA_FOCUS_H * elm_config_scale_get();
4038         DEBUG_TRACE("ad->camera_focus_w=%f, ad->camera_focus_h=%f", ad->camera_focus_w, ad->camera_focus_h);
4039
4040         ad->af_start_x = ad->af_start_x - (ad->camera_focus_w / 2);
4041         ad->af_start_y = ad->af_start_y - (ad->camera_focus_h / 2);
4042         DEBUG_TRACE("af area box start x,y =[%f,%f]\n", ad->af_start_x, ad->af_start_y);
4043
4044         if (ad->rot_current == APP_DEVICE_ORIENTATION_270
4045             || ad->rot_current == APP_DEVICE_ORIENTATION_90) {
4046                 if (ad->af_start_x < ad->preview_offset_x) {
4047                         ad->af_start_x = ad->preview_offset_x;
4048                 }
4049                 if (ad->af_start_y < ad->preview_offset_y) {
4050                         ad->af_start_y = ad->preview_offset_y;
4051                 }
4052                 if ((ad->af_start_x + ad->camera_focus_w) >
4053                     (ad->preview_w + ad->preview_offset_x)) {
4054                         ad->af_start_x =
4055                             (ad->preview_w + ad->preview_offset_x) -
4056                             ad->camera_focus_w;
4057                 }
4058                 if ((ad->af_start_y + ad->camera_focus_h) >
4059                     (ad->preview_h + ad->preview_offset_y)) {
4060                         ad->af_start_y =
4061                             (ad->preview_h + ad->preview_offset_y) -
4062                             ad->camera_focus_h;
4063                 }
4064
4065         } else {
4066                 if (ad->af_start_y < ad->preview_offset_x) {
4067                         ad->af_start_y = ad->preview_offset_x;
4068                 }
4069                 if (ad->af_start_x < ad->preview_offset_y) {
4070                         ad->af_start_x = ad->preview_offset_y;
4071                 }
4072                 if ((ad->af_start_y + ad->camera_focus_h) >
4073                     (ad->preview_w + ad->preview_offset_x)) {
4074                         ad->af_start_y =
4075                             (ad->preview_w + ad->preview_offset_x) -
4076                             ad->camera_focus_h;
4077                 }
4078                 if ((ad->af_start_x + ad->camera_focus_w) >
4079                     (ad->preview_h + ad->preview_offset_y)) {
4080                         ad->af_start_x =
4081                             (ad->preview_h + ad->preview_offset_y) -
4082                             ad->camera_focus_w;
4083                 }
4084         }
4085
4086
4087 }
4088
4089 Eina_Bool cam_continuous_af_start(void *data)
4090 {
4091         struct appdata *ad = (struct appdata *)data;
4092         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
4093
4094         CamAppData *camapp = NULL;
4095         camapp = ad->camapp_handle;
4096         cam_retvm_if(camapp == NULL, ECORE_CALLBACK_CANCEL, "camapp_handle is NULL");
4097
4098         /* cam_mm_set_af_area include init focusing */
4099         DEBUG_TRACE("start continuous AF");
4100         if (cam_mm_set_af_area(ad->af_x, ad->af_y, ad->camera_focus_w, ad->camera_focus_h)) {
4101                 DEBUG_TRACE("cam_mm_set_af_area success!");
4102                 /*focus guide update*/
4103         } else {
4104                 DEBUG_TRACE("cam_mm_set_af_area error!");
4105         }
4106
4107         camapp->focus_mode = CAM_FOCUS_MODE_CONTINUOUS;
4108
4109         if (!cam_mm_start_focusing(camapp->focus_mode)) {
4110                 cam_critical(LOG_MM, "cam_mm_start_focusing error");
4111         }
4112
4113         return ECORE_CALLBACK_CANCEL;
4114 }
4115
4116 Eina_Bool cam_volume_key_press(void *data)
4117 {
4118         struct appdata *ad = (struct appdata *)data;
4119         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
4120
4121         CamAppData *camapp = NULL;
4122         camapp = ad->camapp_handle;
4123         if (camapp == NULL) {
4124                 if (ad->longpress_timer)
4125                         ad->longpress_timer = NULL;
4126                 return ECORE_CALLBACK_CANCEL;
4127         }
4128
4129         if (ad->cancel_key_press == TRUE) {
4130                 if (ad->longpress_timer)
4131                         ad->longpress_timer = NULL;
4132                 return ECORE_CALLBACK_CANCEL;
4133         }
4134
4135         if(ad->is_rotating){
4136                 cam_critical(LOG_MM, "rotating...");
4137                 if (ad->longpress_timer)
4138                         ad->longpress_timer = NULL;
4139                 return ECORE_CALLBACK_CANCEL;
4140         }
4141
4142         if (camapp->touch_af_state == CAM_TOUCH_AF_STATE_DOING) {
4143                 cam_critical(LOG_UI, "touch_af_state is [%d], do not zoom", camapp->touch_af_state);
4144                 return ECORE_CALLBACK_CANCEL;
4145         }
4146
4147         DEL_EVAS_OBJECT(ad->focus_edje);
4148         cam_mm_stop_focusing();
4149
4150         int state = 0;
4151         gboolean up_key = ad->up_key;
4152         debug_fenter(LOG_UI);
4153
4154         state = cam_mm_get_state();
4155         cam_debug(LOG_UI, " state = %d", state);
4156         if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
4157                 switch (state) {
4158                 case RECORDER_STATE_RECORDING:
4159                 case RECORDER_STATE_PAUSED:
4160                 case RECORDER_STATE_READY:
4161                         {
4162                                 if (!camapp->zoom_lock
4163                                     && camapp->recording_mode != CAM_RECORD_SLOW) {
4164                                         zoom_in(ad, up_key, 1);
4165                                 }
4166                         }
4167                         break;
4168                 case RECORDER_STATE_NONE:
4169                 case RECORDER_STATE_CREATED:
4170                         break;
4171                 default:
4172                         break;
4173                 }
4174         } else if(camapp->camera_mode == CAM_CAMERA_MODE) {
4175                 switch (state) {
4176                 case CAMERA_STATE_PREVIEW:
4177                 case CAMERA_STATE_CAPTURED:
4178                         {
4179                                 if (!camapp->zoom_lock
4180                                     && camapp->recording_mode != CAM_RECORD_SLOW) {
4181                                         zoom_in(ad, up_key, 1);
4182                                 }
4183
4184                         }
4185                         break;
4186                 case CAMERA_STATE_NONE:
4187                 case CAMERA_STATE_CREATED:
4188                 case CAMERA_STATE_CAPTURING:
4189                         break;
4190                 default:
4191                         break;
4192                 }
4193
4194         }
4195
4196
4197         if (ad->longpress_timer)
4198                 ecore_timer_interval_set(ad->longpress_timer, ZOOM_LONG_PRESS_INTERVAL);
4199
4200         return ECORE_CALLBACK_RENEW;
4201 }
4202
4203 static gboolean cam_power_key_press(void *data)
4204 {
4205         struct appdata *ad = (struct appdata *)data;
4206         CamAppData *camapp = NULL;
4207
4208         power_lock_state(POWER_STATE_SCREEN_OFF, 0);
4209
4210         debug_fenter(LOG_UI);
4211
4212         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
4213         camapp = ad->camapp_handle;
4214         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
4215
4216         if (ad->mm_state < CAMERA_STATE_PREVIEW) {
4217                 goto lock_and_exit;
4218         } else if (ad->mm_state == CAMERA_STATE_PREVIEW) {
4219                 goto lock_and_exit;
4220         } else if (ad->mm_state > CAMERA_STATE_PREVIEW) {
4221                 if (camapp->camera_mode == CAM_CAMERA_MODE) {
4222                         DEBUG_TRACE("camera mode");
4223                 } else {
4224                         camapp->rec_stop_type = CAM_REC_STOP_POWER_KEY;
4225                         if (!cam_video_record_stop(ad)) {
4226                                 DEBUG_TRACE("record stop fail");
4227                         }
4228                 }
4229         }
4230         return TRUE;
4231
4232  lock_and_exit:
4233         power_unlock_state(POWER_STATE_SCREEN_OFF);
4234
4235         return TRUE;
4236 }
4237 #if 0
4238 static gboolean __cam_end_key_grab_init(void *data)
4239 {
4240         struct appdata *ad = (struct appdata *)data;
4241         Ecore_X_Display *disp = NULL;
4242
4243         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
4244         cam_retvm_if(ad->main_xid <= 0, FALSE, "main_xid <= 0");
4245
4246         disp = ecore_x_display_get();
4247         cam_retvm_if(disp == NULL, FALSE, "ecore_x_display_get fail");
4248
4249         if (utilx_grab_key(disp, ad->main_xid, KEY_END, SHARED_GRAB) == -1) {
4250                 cam_critical(LOG_SYS, "%s key grap fail", KEY_END);
4251         }
4252
4253         return TRUE;
4254 }
4255 #endif
4256 gboolean cam_key_grab_init(void *data)
4257 {
4258         struct appdata *ad = (struct appdata *)data;
4259         Ecore_X_Display *disp = NULL;
4260
4261         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
4262         cam_retvm_if(ad->main_xid <= 0, FALSE, "main_xid <= 0");
4263         int success = 0;
4264         int ret = TRUE;
4265
4266         if (ad->isGrabed)
4267                 return TRUE;
4268
4269         DEBUG_TRACE("key_grab_init############################");
4270
4271         ad->cancel_key_press = FALSE;
4272
4273         disp = ecore_x_display_get();
4274         cam_retvm_if(disp == NULL, FALSE, "ecore_x_display_get fail");
4275
4276         /* volume key */
4277         if (utilx_grab_key(disp, ad->main_xid, KEY_VOLUMEUP, TOP_POSITION_GRAB) != success) {
4278                 cam_critical(LOG_SYS, "%s key grap fail", KEY_VOLUMEUP);
4279                 ret = FALSE;
4280         }
4281         if (utilx_grab_key(disp, ad->main_xid, KEY_VOLUMEDOWN, TOP_POSITION_GRAB) != success) {
4282                 cam_critical(LOG_SYS, "%s key grap fail", KEY_VOLUMEDOWN);
4283                 ret = FALSE;
4284         }
4285
4286         #if 0
4287         if (vconf_set_int(VCONFKEY_STARTER_USE_VOLUME_KEY, 1))
4288                 cam_critical(LOG_SYS, "VCONFKEY_STARTER_USE_VOLUME_KEY set fail");
4289         #endif
4290
4291         /* camera key */
4292         if (utilx_grab_key(disp, ad->main_xid, KEY_CAMERA, TOP_POSITION_GRAB)  != success) {
4293                 cam_critical(LOG_SYS, "%s key grap fail", KEY_CAMERA);
4294                 ret = FALSE;
4295         }
4296         if (utilx_grab_key(disp, ad->main_xid, KEY_CONFIG, TOP_POSITION_GRAB)  != success) {
4297                 cam_critical(LOG_SYS, "%s key grap fail", KEY_CONFIG);
4298                 ret = FALSE;
4299         }
4300         /* power key */
4301         if (utilx_grab_key(disp, ad->main_xid, KEY_POWER, SHARED_GRAB) != success) {
4302                 cam_critical(LOG_SYS, "%s key grap fail", KEY_POWER);
4303                 ret = FALSE;
4304         }
4305
4306         /* etc */
4307         if (utilx_grab_key(disp, ad->main_xid, KEY_SEND, SHARED_GRAB) != success) {
4308                 cam_critical(LOG_SYS, "%s key grap fail", KEY_SEND);
4309                 ret = FALSE;
4310         }
4311         if (utilx_grab_key(disp, ad->main_xid, KEY_END, SHARED_GRAB) != success) {
4312                 cam_critical(LOG_SYS, "%s key grap fail", KEY_END);
4313                 ret = FALSE;
4314         }
4315
4316         ad->isGrabed = TRUE;
4317         return ret;
4318 }
4319
4320 gboolean cam_key_grab_deinit(void *data)
4321 {
4322         struct appdata *ad = (struct appdata *)data;
4323         Ecore_X_Display *disp = NULL;
4324         int success = 0;
4325         int ret = TRUE;
4326
4327         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
4328         cam_retvm_if(ad->main_xid <= 0, FALSE, "main_xid <= 0");
4329
4330         if (!ad->isGrabed)
4331                 return TRUE;
4332         DEBUG_TRACE("key_grab_deinit############################");
4333
4334         disp = ecore_x_display_get();
4335         cam_retvm_if(disp == NULL, FALSE, "ecore_x_display_get fail");
4336
4337         /* volume key */
4338         if (utilx_ungrab_key(disp, ad->main_xid, KEY_VOLUMEUP) != success){
4339                 cam_critical(LOG_SYS, "%s key ungrap fail", KEY_VOLUMEUP);
4340                 ret = FALSE;
4341         }
4342         if (utilx_ungrab_key(disp, ad->main_xid, KEY_VOLUMEDOWN) != success){
4343                 cam_critical(LOG_SYS, "%s key ungrap fail", KEY_VOLUMEDOWN);
4344                 ret = FALSE;
4345         }
4346
4347         /* camera key */
4348         if (utilx_ungrab_key(disp, ad->main_xid, KEY_CAMERA) != success){
4349                 cam_critical(LOG_SYS, "%s key ungrap fail", KEY_CAMERA);
4350                 ret = FALSE;
4351
4352         }
4353         if (utilx_ungrab_key(disp, ad->main_xid, KEY_CONFIG) != success){
4354                 cam_critical(LOG_SYS, "%s key ungrap fail", KEY_CONFIG);
4355                 ret = FALSE;
4356         }
4357
4358         /* power key */
4359         if (utilx_ungrab_key(disp, ad->main_xid, KEY_POWER) != success){
4360                 cam_critical(LOG_SYS, "%s key ungrap fail", KEY_POWER);
4361                 ret = FALSE;
4362         }
4363         if (utilx_ungrab_key(disp, ad->main_xid, KEY_PAUSE) != success){
4364                 cam_critical(LOG_SYS, "%s key ungrap fail", KEY_PAUSE);
4365                 ret = FALSE;
4366         }
4367
4368         /* etc */
4369         if (utilx_ungrab_key(disp, ad->main_xid, KEY_SEND) != success){
4370                 cam_critical(LOG_SYS, "%s key ungrap fail", KEY_SEND);
4371                 ret = FALSE;
4372         }
4373         if (utilx_ungrab_key(disp, ad->main_xid, KEY_SELECT) != success){
4374                 cam_critical(LOG_SYS, "%s key ungrap fail", KEY_SELECT);
4375                 ret = FALSE;
4376         }
4377         if (utilx_ungrab_key(disp, ad->main_xid, KEY_END) != success){
4378                 cam_critical(LOG_SYS, "%s key ungrap fail", KEY_END);
4379                 ret = FALSE;
4380         }
4381
4382         ad->isGrabed = FALSE;
4383         return ret;
4384 }
4385
4386 gboolean cam_app_key_event_init(void *data)
4387 {
4388         struct appdata *ad = (struct appdata *)data;
4389
4390         DEBUG_TRACE("cam_app_key_event_init");
4391
4392         if (ad == NULL) {
4393                 cam_critical(LOG_UI, "appdata is NULL, maybe not created");
4394                 return FALSE;
4395         }
4396         if (ad->key_down == NULL) {
4397                 ad->key_down =
4398                     ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, cam_hard_key_down, ad);
4399         }
4400         if (ad->key_up == NULL) {
4401                 ad->key_up =
4402                     ecore_event_handler_add(ECORE_EVENT_KEY_UP, cam_hard_key_up, ad);
4403         }
4404
4405         return TRUE;
4406 }
4407
4408 gboolean cam_app_key_event_deinit(void *data)
4409 {
4410         struct appdata *ad = (struct appdata *)data;
4411
4412         DEBUG_TRACE("cam_app_key_event_deinit");
4413
4414         if (ad == NULL) {
4415                 cam_critical(LOG_UI, "appdata is NULL, maybe not created");
4416                 return FALSE;
4417         }
4418         if (ad->key_down) {
4419                 ecore_event_handler_del(ad->key_down);
4420                 ad->key_down = NULL;
4421         }
4422         if (ad->key_up) {
4423                 ecore_event_handler_del(ad->key_up);
4424                 ad->key_up = NULL;
4425         }
4426
4427         return TRUE;
4428 }
4429
4430 Eina_Bool cam_hard_key_down(void *data, int type, void *event_info)
4431 {
4432         struct appdata *ad = (struct appdata *)data;
4433         cam_retvm_if(ad == NULL, ECORE_CALLBACK_DONE, "appdata is NULL");
4434         CamAppData *camapp = ad->camapp_handle;
4435         cam_retvm_if(camapp == NULL, ECORE_CALLBACK_DONE, "camapp_handle is NULL");
4436
4437         Ecore_Event_Key *kd = (Ecore_Event_Key *) event_info;
4438         cam_debug(LOG_UI, "Key name : %s", kd->keyname);
4439
4440         if (ad->confirm_popup) {
4441                 cam_debug(LOG_UI, "confirm popup exist. ignore key event");
4442                 return ECORE_CALLBACK_DONE;
4443         }
4444
4445         if (ad->zoom_edje)
4446                 unload_zoom_edje(ad);
4447
4448         if (ad->ev_edje)
4449                 unload_ev_edje(ad);
4450
4451         if (ad->setting_ctxpopup || ad->toolbar_setting_popup) {
4452                 ad->displayed_setting_popup = DISPLAY_NONE_POPUP;
4453                 cam_toolbar_setting_popup_destroy(ad);
4454         }
4455
4456         if (ad->edit_shortcuts_popup)
4457                 toolbar_destroy_shortcuts_popup(ad);
4458
4459         cam_app_timeout_checker_update();
4460
4461         /*  Camera key Press */
4462         if (0 == strcmp(kd->keyname, KEY_CANCEL)) {
4463                 ad->cancel_key_press = TRUE;
4464         }
4465         if (0 == strcmp(kd->keyname, KEY_CONFIG)) {     /* camera key - full */
4466                 if (!camapp->key_lock) {
4467                         camapp->key_lock = TRUE;
4468                         CAM_TA_ACUM_ITEM_BEGIN("Total capture time", 0);
4469                         CAM_TA_ACUM_ITEM_BEGIN
4470                             ("        camera key to capture start", 0);
4471                         if (!cam_camera_key_press(ad)) {
4472                                 cam_warning(LOG_UI, "cam_camera_key_press failed");
4473                         }
4474                         camapp->key_lock = FALSE;
4475                 }
4476         }
4477         /*  Camera key HALF press */
4478         else if (0 == strcmp(kd->keyname, KEY_CAMERA)) {        /* camera key - half */
4479                 if (!camapp->key_lock) {
4480                         camapp->key_lock = TRUE;
4481
4482                         if (!cam_camera_key_half_press(ad)) {
4483                                 cam_warning(LOG_UI, "cam_camera_key_half_press failed");
4484                         }
4485                         camapp->key_lock = FALSE;
4486                 }
4487         } else if (0 == strcmp(kd->keyname, KEY_VOLUMEUP)) {
4488                 if (camapp->volume_key == CAM_VOLUME_KEY_ZOOM) {
4489                         if (!camapp->key_lock) {
4490                                 camapp->key_lock = TRUE;
4491                                 ad->up_key = TRUE;
4492                                 cam_volume_key_press(ad);
4493                                 cam_add_longpress_key_timer(ad);
4494                                 camapp->key_lock = FALSE;
4495                         }
4496                 } else {
4497                         cam_toolbar_shutter_button_cb(ad, NULL, "press_shutter_sig", "hard_key");
4498                 }
4499         } else if (0 == strcmp(kd->keyname, KEY_VOLUMEDOWN)) {
4500                 if (camapp->volume_key == CAM_VOLUME_KEY_ZOOM) {
4501                         if (!camapp->key_lock) {
4502                                 camapp->key_lock = TRUE;
4503                                 ad->up_key = FALSE;
4504                                 cam_volume_key_press(ad);
4505                                 cam_add_longpress_key_timer(ad);
4506                                 camapp->key_lock = FALSE;
4507                         }
4508                 } else {
4509                         if (!ad->is_recording) {
4510                                 cam_toolbar_recording_button_cb(ad, NULL, "click_shutter_sig", "hard_key");
4511                         } else {
4512                                 cam_toolbar_recording_stop_button_cb(ad, NULL, "click_shutter_sig", "hard_key");
4513                         }
4514                 }
4515         } else if (0 == strcmp(kd->keyname, KEY_SELECT)) {
4516
4517         } else if ((0 == strcmp(kd->keyname, KEY_SELECT))
4518                    && ad->launching_mode == CAM_LAUNCHING_MODE_EXTERNAL) {
4519                 if (!camapp->key_lock) {
4520                         camapp->key_lock = TRUE;
4521                 }
4522         } else if (0 == strcmp(kd->keyname, KEY_POWER)) {
4523 #if 0
4524                 if (!camapp->key_lock) {
4525                         camapp->key_lock = TRUE;
4526                         power_unlock_state(POWER_STATE_NORMAL);
4527                         cam_power_key_press(ad);
4528                         camapp->key_lock = FALSE;
4529                 }
4530 #endif
4531         }
4532
4533         return ECORE_CALLBACK_DONE;
4534 }
4535
4536 Eina_Bool cam_hard_key_up(void *data, int type, void *event_info)
4537 {
4538         struct appdata *ad = (struct appdata *)data;
4539         cam_retvm_if(ad == NULL, ECORE_CALLBACK_DONE, "appdata is NULL");
4540         CamAppData *camapp = ad->camapp_handle;
4541         cam_retvm_if(camapp == NULL, ECORE_CALLBACK_DONE, "camapp_handle is NULL");
4542
4543         Ecore_Event_Key *kd = (Ecore_Event_Key *) event_info;
4544         cam_debug(LOG_UI, "Key name : %s", kd->keyname);
4545
4546         if (ad->confirm_popup) {
4547                 cam_debug(LOG_UI, "confirm popup exist. ignore key event");
4548                 return ECORE_CALLBACK_DONE;
4549         }
4550
4551         cam_app_timeout_checker_update();
4552
4553         if (0 == strcmp(kd->keyname, KEY_CANCEL)) {
4554                 ad->cancel_key_press = FALSE;
4555         }
4556
4557         if(ad->cancel_key_press == TRUE) {
4558                 if (ad->longpress_timer) { /*volume key long press */
4559                         cam_del_longpress_key_timer(ad);
4560                 }
4561                 return ECORE_CALLBACK_DONE;
4562         }
4563
4564         if (0 == strcmp(kd->keyname, KEY_CONFIG)) {     /* camera key - full  */
4565                 if (!camapp->key_lock) {
4566                         camapp->key_lock = TRUE;
4567                         if (!cam_camera_key_release(ad)) {
4568                                 cam_warning(LOG_UI, "cam_camera_key_release failed");
4569                         }
4570                         camapp->key_lock = FALSE;
4571                 }
4572         } else if (0 == strcmp(kd->keyname, KEY_CAMERA)) {      /* camera key - half */
4573                 if (!camapp->key_lock) {
4574                         camapp->key_lock = TRUE;
4575                         if (!cam_camera_key_half_release(ad)) {
4576                                 cam_warning(LOG_UI, "cam_camera_key_release failed");
4577                         }
4578                         camapp->key_lock = FALSE;
4579                 }
4580         } else if (0 == strcmp(kd->keyname, KEY_VOLUMEUP)
4581                    || 0 == strcmp(kd->keyname, KEY_VOLUMEDOWN)) {
4582                 if (camapp->volume_key == CAM_VOLUME_KEY_ZOOM) {
4583                         if (!camapp->key_lock) {
4584                                 camapp->key_lock = TRUE;
4585                                 cam_del_longpress_key_timer(ad);
4586                                 camapp->key_lock = FALSE;
4587                         }
4588                 } else {
4589                         cam_toolbar_shutter_button_cb(ad, NULL, "release_shutter_sig", "hard_key");
4590                 }
4591         }
4592         return ECORE_CALLBACK_DONE;
4593 }
4594
4595 Eina_Bool cam_mouse_button_down(void *data, void *event_info)
4596 {
4597         struct appdata *ad = (struct appdata *)data;
4598         cam_retvm_if(ad == NULL, EINA_FALSE, "appdata is NULL");
4599         CamAppData *camapp = ad->camapp_handle;
4600         cam_retvm_if(camapp == NULL, EINA_FALSE, "camapp_handle is NULL");
4601
4602         if (ad->pinch_edje) {
4603                 if (ad->focus_edje)
4604                         edje_object_signal_emit(_EDJ(ad->focus_edje), "focus,hide", "program");
4605                 return FALSE;
4606         }
4607
4608         Evas_Event_Mouse_Down *md = (Evas_Event_Mouse_Down *) event_info;
4609
4610         switch (ad->rot_current) {
4611         case APP_DEVICE_ORIENTATION_0:
4612                 {
4613                         ad->touch_lcd_x = md->canvas.x; /* LCD x */
4614                         ad->touch_lcd_y = md->canvas.y; /* LCD y */
4615                 }
4616                 break;
4617         case APP_DEVICE_ORIENTATION_180:
4618                 {
4619                         ad->touch_lcd_x = ad->win_height - md->canvas.x; /* LCD x */
4620                         ad->touch_lcd_y = ad->win_width - md->canvas.y; /* LCD y */
4621                 }
4622                 break;
4623         case APP_DEVICE_ORIENTATION_270:
4624                 {
4625                         ad->touch_lcd_x = ad->win_height - md->canvas.y; /* LCD x */
4626                         ad->touch_lcd_y = md->canvas.x; /* LCD y */
4627
4628                 }
4629                 break;
4630         case APP_DEVICE_ORIENTATION_90:
4631                 {
4632                         ad->touch_lcd_x = md->canvas.y; /* LCD x */
4633                         ad->touch_lcd_y = ad->win_width - md->canvas.x; /* LCD y */
4634                 }
4635                 break;
4636         default:
4637                 break;
4638         }
4639
4640         ad->af_x = ad->touch_lcd_y - ad->preview_offset_x;
4641         ad->af_y = ad->preview_h - ad->touch_lcd_x;
4642
4643         ad->af_x = (ad->af_x * ad->camfw_video_width) / ad->preview_w;
4644         ad->af_y = (ad->af_y * ad->camfw_video_height) / ad->preview_h;
4645
4646         DEBUG_TRACE("*************************************************************************************");
4647         DEBUG_TRACE("touched lcd x,y=[%d,%d] af x,y=[%d,%d]\n", ad->touch_lcd_x, ad->touch_lcd_y, ad->af_x, ad->af_y);
4648         DEBUG_TRACE("*************************************************************************************");
4649
4650         int state = cam_mm_get_state();
4651         if (!(camapp->camera_mode == CAM_CAMERA_MODE && state == CAMERA_STATE_CAPTURING) ){
4652                 if (camapp->enable_touch_af == TRUE
4653                         && camapp->touch_af_state == CAM_TOUCH_AF_STATE_NONE) {
4654                         REMOVE_TIMER(ad->continuous_af_timer);
4655                         cam_app_draw_af_box(ad);
4656
4657                         camapp->focus_state = CAM_FOCUS_STATUS_RELEASED;
4658                         cam_app_focus_guide_create(ad);
4659                         cam_app_focus_guide_update(ad);
4660                         cam_ui_effect_utils_set_zoom_effect(ad->focus_edje,
4661                                                                 CAM_FOCUS_EDJE_ZOOM_EFFECT_START_RATE,
4662                                                                 CAM_FOCUS_EDJE_ZOOM_EFFECT_END_RATE,
4663                                                                 CAM_FOCUS_EDJE_ZOOM_EFFECT_DURATION);
4664                         camapp->touch_af_state = CAM_TOUCH_AF_STATE_READY;
4665                 }
4666         } else
4667                 DEBUG_TRACE("camera mode[%d], camera state[%d] not available focus",camapp->camera_mode,state);
4668
4669         return EINA_TRUE;
4670 }
4671
4672 Eina_Bool cam_mouse_button_up(void *data, void *event_info)
4673 {
4674         struct appdata *ad = (struct appdata *)data;
4675         cam_retvm_if(ad == NULL, EINA_FALSE, "appdata is NULL");
4676         CamAppData *camapp = ad->camapp_handle;
4677         cam_retvm_if(camapp == NULL, EINA_FALSE, "camapp is NULL");
4678
4679         if (ad->pinch_edje) {
4680                 if (ad->focus_edje)
4681                         edje_object_signal_emit(_EDJ(ad->focus_edje), "focus,hide", "program");
4682                 return FALSE;
4683         }
4684
4685         if (camapp->touch_af_state == CAM_TOUCH_AF_STATE_READY) {
4686                 camapp->touch_af_state = CAM_TOUCH_AF_STATE_DOING;
4687                 cam_app_draw_af_box(ad);
4688                 evas_object_show(ad->focus_edje);
4689                 cam_ui_effect_utils_set_zoom_effect(ad->focus_edje,
4690                                                                 CAM_FOCUS_EDJE_ZOOM_EFFECT_END_RATE,
4691                                                                 CAM_FOCUS_EDJE_ZOOM_EFFECT_START_RATE,
4692                                                                 CAM_FOCUS_EDJE_ZOOM_EFFECT_DURATION);
4693
4694                 if (camapp->camera_mode == CAM_CAMCORDER_MODE && ad->is_recording) {
4695                         if (ad->caf_button)
4696                                 cam_toolbar_show_cafbutton(ad, TRUE);
4697                 }
4698
4699                 cam_camera_touch_af_press(ad);
4700         }
4701         return EINA_TRUE;
4702 }
4703
4704 void cam_app_set_config_group(gint mode)
4705 {
4706         cam_debug(LOG_UI, "mode : %d", mode);
4707
4708         if (mode == CAM_CAMERA_MODE) {
4709                 cam_config_set_group_name(CAM_CONFIG_TYPE_PREVIEW, "still");
4710         } else {
4711                 cam_config_set_group_name(CAM_CONFIG_TYPE_PREVIEW, "video");
4712         }
4713
4714         debug_fleave(LOG_UI);
4715
4716         return;
4717 }
4718
4719 int cam_app_get_latest_mode(void)
4720 {
4721         cam_config_set_group_name(CAM_CONFIG_TYPE_COMMON, "common");
4722         int last_mode =
4723             cam_config_get_int_by_type(CAM_CONFIG_TYPE_COMMON, "mode",
4724                                        CAM_CAMERA_MODE);
4725
4726         debug_msg(LOG_UI, "last mode:%d", last_mode);
4727         return last_mode;
4728 }
4729
4730 const gchar *cam_app_get_target_path(void)
4731 {
4732         CamAppData *camapp = NULL;
4733
4734         camapp = cam_handle_get();
4735
4736         if (camapp) {
4737
4738                 const gchar *default_path = NULL;
4739                 switch (camapp->storage) {
4740                 case CAM_STORAGE_INTERNAL:
4741                         default_path = cam_file_get_internal_image_path();
4742                         break;
4743                 case CAM_STORAGE_EXTERNAL:
4744                         default_path = cam_file_get_external_image_path();
4745                         break;
4746                 default:
4747                         cam_critical(LOG_UI, "Unknow storage type : %d", camapp->storage);
4748                         break;
4749                 }
4750
4751                 cam_debug(LOG_UI, "target path : [%s]", default_path);
4752                 return default_path;
4753         } else {
4754                 cam_critical(LOG_UI, "camapp handle is NULL");
4755                 return NULL;
4756         }
4757 }
4758
4759 gchar *cam_app_get_last_filename(void)
4760 {
4761         CamAppData *camapp = NULL;
4762         gchar *last_file_path = NULL;
4763         struct appdata *ad = (struct appdata *)cam_appdata_get();
4764         cam_retvm_if(ad == NULL, NULL, "appdata is NULL");
4765
4766         camapp = cam_handle_get();
4767         cam_retvm_if(camapp == NULL, NULL, "cam_handle is NULL");
4768
4769         last_file_path = cam_file_get_last_file_path(ad, cam_app_get_target_path());
4770
4771         if (last_file_path) {
4772                 cam_debug(LOG_UI, "last_file_path  : %s", last_file_path);
4773         } else {
4774                 cam_critical(LOG_UI, "last_file_path is NULL");
4775                 return NULL;
4776         }
4777         return last_file_path;
4778 }
4779
4780 gchar *cam_app_get_next_filename(CamFileExtention extension)
4781 {
4782
4783         CamAppData *camapp = NULL;
4784         gchar *new_filename = NULL;
4785         struct appdata *ad = (struct appdata *)cam_appdata_get();
4786         cam_retvm_if(ad == NULL, NULL, "appdata is NULL");
4787
4788         camapp = cam_handle_get();
4789         cam_retvm_if(camapp == NULL, NULL, "cam_handle is NULL");
4790         int mm_state = 0;
4791         mm_state = cam_mm_get_state();
4792
4793         if( extension == CAM_FILE_EXTENTION_IMAGE){
4794                 new_filename = cam_file_get_next_filename(cam_app_get_target_path(), INAGE_FILE_NAME, IMAGE_FILE_EXTENSION);
4795         } else {
4796                 if ((camapp->recording_mode == CAM_RECORD_MMS)
4797                                 || (camapp->recording_mode == CAM_RECORD_SELF_MMS))
4798                         new_filename = cam_file_get_next_filename(cam_app_get_target_path(), VIDEO_FILE_NAME, VIDEO_FILE_EXTENSION_3GP);
4799                 else
4800                         new_filename = cam_file_get_next_filename(cam_app_get_target_path(), VIDEO_FILE_NAME, VIDEO_FILE_EXTENSION_MP4);
4801         }
4802
4803         if (new_filename) {
4804                 cam_debug(LOG_UI, "next filename : %s", new_filename);
4805         } else {
4806                 cam_critical(LOG_UI, "new_filename is NULL");
4807         }
4808
4809         return new_filename;
4810 }
4811
4812 static void __cam_preview_cb(camera_preview_data_s *preview_frame, void *user_data)
4813 {
4814
4815         cam_retm_if(user_data == NULL, "data is null");
4816         struct appdata *ad = (struct appdata *)user_data;
4817
4818         CamAppData *camapp = ad->camapp_handle;
4819         cam_retm_if(camapp == NULL, "camapp is null");
4820 }
4821
4822 static void __cam_state_change_cb(camera_state_e previous, camera_state_e current,
4823         bool by_policy, void *user_data)
4824 {
4825         struct appdata *ad = NULL;
4826         CamAppData *camapp = NULL;
4827         ad = (struct appdata *)user_data;
4828         cam_retm_if(ad == NULL, "camapp is null");
4829         camapp = ad->camapp_handle;
4830         cam_retm_if(camapp == NULL, "camapp is null");
4831         DEBUG_TRACE("current= %d, previous = %d, ad->enable_mode_change = %d",  current, previous, ad->enable_mode_change);
4832
4833         if (current == CAMERA_STATE_PREVIEW) {
4834                 ad->enable_mode_change = TRUE;
4835         } else {
4836                 ad->enable_mode_change = FALSE;
4837         }
4838
4839         DEBUG_TRACE("current= %d, previous = %d, ad->enable_mode_change = %d", current, previous, ad->enable_mode_change);
4840         cam_app_camera_state_manager(previous, current, by_policy);
4841
4842 }
4843
4844 static void __cam_focus_cb(camera_focus_state_e state, void *user_data)
4845 {
4846         struct appdata *ad = (struct appdata *)user_data;
4847         cam_retm_if(ad == NULL, "appdata is NULL");
4848         CamAppData *camapp = ad->camapp_handle;
4849         cam_retm_if(camapp == NULL, "camapp is NULL");
4850
4851         cam_debug(LOG_MM, " Focus state changed to [%d]", state);
4852
4853         if (ad->ug_state == CAM_UG_PAUSE_STATE)
4854                 return;
4855
4856         camapp->focus_state = state ;
4857
4858         if (ad->is_rotating == FALSE) {
4859                 if (evas_object_visible_get(ad->focus_edje) == TRUE)
4860                         cam_app_focus_guide_update(ad);
4861         }
4862
4863         switch (state) {
4864         case CAMERA_FOCUS_STATE_RELEASED:
4865                 cam_debug(LOG_MM, "release");
4866                 break;
4867         case CAMERA_FOCUS_STATE_ONGOING:
4868                 cam_debug(LOG_MM, "ongoing");
4869                 break;
4870         case CAMERA_FOCUS_STATE_FOCUSED:
4871                 cam_debug(LOG_MM, "focused");
4872                 if (camapp->camera_mode == CAM_CAMERA_MODE && ad->mm_state < CAMERA_STATE_CAPTURING) {
4873                         if ((camapp->focus_mode == CAM_FOCUS_MODE_TOUCH_AUTO
4874                                         || camapp->focus_mode == CAM_FOCUS_MODE_HALFSHUTTER)
4875                                 && camapp->shutter_sound != CAM_SETTINGS_SOUND_OFF)
4876                                         cam_sound_play (CAM_SOUND_EFFECT_AF_OK, ad);
4877
4878                         if (camapp->focus_mode == CAM_FOCUS_MODE_TOUCH_AUTO) {
4879                                 if (camapp->touch_af_state == CAM_TOUCH_AF_STATE_READY
4880                                         ||camapp->touch_af_state == CAM_TOUCH_AF_STATE_DOING)
4881                                         camapp->touch_af_state = CAM_TOUCH_AF_STATE_NONE;
4882
4883                                 REMOVE_TIMER(ad->continuous_af_timer);
4884                                 ad->continuous_af_timer = ecore_timer_add(FOCUS_FOCUSED_TIME_OUT, __cam_continuous_af_timer_cb, ad);
4885                         }
4886
4887                 } else if (camapp->camera_mode == CAM_CAMCORDER_MODE && ad->mm_state <= RECORDER_STATE_RECORDING) {
4888                         if (camapp->focus_mode == CAM_FOCUS_MODE_TOUCH_AUTO
4889                                 && camapp->shutter_sound != CAM_SETTINGS_SOUND_OFF
4890                                 && ad->mm_state != RECORDER_STATE_RECORDING)
4891                                         cam_sound_play (CAM_SOUND_EFFECT_AF_OK, ad);
4892
4893                         if (camapp->focus_mode == CAM_FOCUS_MODE_TOUCH_AUTO) {
4894                                 if (camapp->touch_af_state == CAM_TOUCH_AF_STATE_READY
4895                                         ||camapp->touch_af_state == CAM_TOUCH_AF_STATE_DOING)
4896                                         camapp->touch_af_state = CAM_TOUCH_AF_STATE_NONE;
4897                         }
4898
4899                         REMOVE_TIMER(ad->continuous_af_timer);
4900
4901                         if (ad->is_recording)
4902                                 ad->continuous_af_timer = ecore_timer_add(FOCUS_FOCUSED_TIME_OUT, __focus_guide_destroy, ad);
4903                 } else {
4904                         camapp->touch_af_state = CAM_TOUCH_AF_STATE_NONE;
4905                 }
4906                 break;
4907         case CAMERA_FOCUS_STATE_FAILED:
4908                 cam_debug(LOG_MM, "failed");
4909                 if (camapp->camera_mode == CAM_CAMERA_MODE && ad->mm_state < CAMERA_STATE_CAPTURING) {
4910                         if ((camapp->focus_mode == CAM_FOCUS_MODE_TOUCH_AUTO
4911                                         || camapp->focus_mode == CAM_FOCUS_MODE_HALFSHUTTER)
4912                                 && camapp->shutter_sound != CAM_SETTINGS_SOUND_OFF)
4913                                         cam_sound_play (CAM_SOUND_EFFECT_AF_FAIL, ad);
4914
4915                         if (camapp->focus_mode == CAM_FOCUS_MODE_TOUCH_AUTO) {
4916                                 if (camapp->touch_af_state == CAM_TOUCH_AF_STATE_READY
4917                                         ||camapp->touch_af_state == CAM_TOUCH_AF_STATE_DOING)
4918                                         camapp->touch_af_state = CAM_TOUCH_AF_STATE_NONE;
4919
4920                                 REMOVE_TIMER(ad->continuous_af_timer);
4921                                 ad->continuous_af_timer = ecore_timer_add(FOCUS_FOCUSED_TIME_OUT, __cam_continuous_af_timer_cb, ad);
4922                         }
4923                 } else if (camapp->camera_mode == CAM_CAMCORDER_MODE && ad->mm_state <= RECORDER_STATE_RECORDING) {
4924                         if (camapp->focus_mode == CAM_FOCUS_MODE_TOUCH_AUTO
4925                                 && camapp->shutter_sound != CAM_SETTINGS_SOUND_OFF
4926                                 && ad->mm_state != RECORDER_STATE_RECORDING)
4927                                         cam_sound_play (CAM_SOUND_EFFECT_AF_FAIL, ad);
4928
4929                         if (camapp->focus_mode == CAM_FOCUS_MODE_TOUCH_AUTO) {
4930                                 if (camapp->touch_af_state == CAM_TOUCH_AF_STATE_READY
4931                                         ||camapp->touch_af_state == CAM_TOUCH_AF_STATE_DOING)
4932                                         camapp->touch_af_state = CAM_TOUCH_AF_STATE_NONE;
4933                         }
4934
4935                         REMOVE_TIMER(ad->continuous_af_timer);
4936
4937                         if (ad->is_recording)
4938                                 ad->continuous_af_timer = ecore_timer_add(FOCUS_FOCUSED_TIME_OUT, __focus_guide_destroy, ad);
4939                 } else {
4940                         camapp->touch_af_state = CAM_TOUCH_AF_STATE_NONE;
4941                 }
4942                 break;
4943         default:
4944                 break;
4945         }
4946 }
4947
4948 static void __cam_capture_cb(camera_image_data_s* image,
4949         camera_image_data_s* postview,
4950         camera_image_data_s* thumbnail,
4951         void *user_data)
4952 {
4953         struct appdata *ad = (struct appdata *)user_data;
4954         cam_retm_if(ad == NULL, "appdata is NULL");
4955         CamAppData *camapp = NULL;
4956         camapp = ad->camapp_handle;
4957         cam_retm_if(camapp == NULL, "camapp is NULL");
4958         if (camapp->af_mode == CAM_FOCUS_FACE) {
4959                 cam_app_stop_video_stream();
4960         }
4961         gchar *filename = NULL;
4962         FILE *fp = NULL;
4963         if ((image->format == CAMERA_PIXEL_FORMAT_YUYV)
4964             || (image->format == CAMERA_PIXEL_FORMAT_NV12)) {
4965                 cam_debug(LOG_UI,
4966                           "got raw data - format [%d] data [%p], length [%d], width [%d], height [%d]",
4967                           image->format, image->data, image->size, image->width,
4968                           image->height);
4969                 /* encode data */
4970                 /* MMImageJpegEncodeToFile(filename, src->data, src->width,src->height, src->format, 90); */
4971         } else if (image->format == CAMERA_PIXEL_FORMAT_JPEG) {
4972                 cam_debug(LOG_UI,
4973                           "got JPEG data - data [%p], length [%d], width [%d], height [%d]",
4974                           image->data, image->size, image->width, image->height);
4975                 if (camapp->camera_mode == CAM_CAMERA_MODE
4976                         && camapp->shooting_mode == CAM_SELF_SINGLE_MODE) {
4977                         ;
4978                 } else {
4979                         cam_app_create_screennail_and_start_animation(user_data);
4980                 }
4981
4982                 /* save file */
4983                 filename = cam_app_get_next_filename(CAM_FILE_EXTENTION_IMAGE);
4984                 if (filename == NULL) {
4985                         cam_critical(LOG_SYS, " Get next filename FAILED");
4986                         return;
4987                 }
4988
4989                 fp = fopen(filename, "w+");
4990                 if (fp == NULL) {
4991                         cam_critical(LOG_SYS, "FileOPEN error!!");
4992                         return;
4993                 } else {
4994                         cam_debug(LOG_SYS, "FileOPEN success");
4995                         if (fwrite(image->data, image->size, 1, fp) != 1) {
4996                                 cam_critical(LOG_SYS, "File write error!!");
4997                                 fclose(fp);
4998                                 return;
4999                         }
5000                         /*fsync(fp->_fileno);*/
5001                         /*block for increasing formance of shot-to-shot */
5002                         cam_debug(LOG_SYS, "File write success");
5003                         fclose(fp);
5004                 }
5005                 if (camapp->filename)
5006                         free(camapp->filename);
5007                 camapp->filename = strdup(filename);
5008                 free(filename);
5009                 filename = NULL;
5010         }
5011 }
5012
5013 void cam_app_create_capture_complete_ui_idlers(void *data)
5014 {
5015         struct appdata *ad = (struct appdata *)data;
5016         cam_ret_if(ad == NULL);
5017         CamIdlerItem *item = NULL;
5018         item = (CamIdlerItem *)g_malloc(sizeof(CamIdlerItem));
5019         cam_ret_if(item == NULL);
5020
5021         if (item) {
5022                 item->data = data;
5023                 item->idler = ecore_idler_add(cam_image_capture_handle_idler, item);
5024
5025                 if (item->idler)
5026                         ad->capture_cb_list = g_list_append(ad->capture_cb_list, item->idler);
5027
5028                 cam_info(LOG_UI, "image capture idler add : %p ", item->idler);
5029         }
5030 }
5031
5032 static Eina_Bool __cam_app_progressbar_timer(void *data)
5033 {
5034         double value=0.0;
5035
5036         Evas_Object *progressbar = (Evas_Object*) data;
5037         if (progressbar == NULL) {
5038                 progress_timer = NULL;
5039                 return ECORE_CALLBACK_CANCEL;
5040         }
5041
5042         value = elm_progressbar_value_get(progressbar);
5043         if (value == 1.0) value = 0.0;
5044         value = value + 0.025;
5045         elm_progressbar_value_set(progressbar, value);
5046
5047         return ECORE_CALLBACK_RENEW;
5048 }
5049
5050
5051 void cam_app_create_burst_popup(void *data)
5052 {
5053 #if 1/*TODO: need ui guide, for display popup*/
5054         struct appdata *ad = NULL;
5055         CamAppData *camapp = NULL;
5056
5057         ad = (struct appdata *)data;
5058         cam_ret_if(ad == NULL);
5059         camapp = ad->camapp_handle;
5060         cam_ret_if(camapp == NULL);
5061
5062         if (cam_is_enabled_menu((void*)ad, CAM_MENU_BURST_SHOT_MODE) &&
5063                         (camapp->burst_shot == TRUE) && camapp->continuous_shot_data) {
5064                 ad->is_processing = TRUE;
5065                 REMOVE_TIMER(ad->continuous_af_timer);
5066                 cam_mm_stop_focusing();
5067                 cam_toolbar_update_shutter_button(ad, TOOLBAR_ITEM_STATE_DIM);
5068
5069                 if (!cam_popup_for_burst_create(ad)) {/*TODO: need ui guide for this popup*/
5070                         cam_debug(LOG_UI, "cam_progress_popup_create() fail");
5071                         return;
5072                 }
5073
5074                 if (!cam_popup_add_progress_bar(ad))
5075                         cam_debug(LOG_UI, "cam_popup_add_progress_bar() fail");
5076
5077                 if (!cam_popup_set_text(ad, dgettext(PACKAGE, "IDS_CAM_BODY_PROCESSING_ING")))
5078                         cam_debug(LOG_UI, "cam_progress_popup_set_text() fail");
5079         }
5080         progress_timer = ecore_timer_add(0.01, __cam_app_progressbar_timer, ad->progress_popup_bar);
5081 #endif
5082
5083 }
5084
5085 static void __cam_capture_completed_cb(void *user_data)
5086 {
5087         DEBUG_TRACE();
5088         struct appdata *ad = (struct appdata *)user_data;
5089         cam_retm_if(ad == NULL, "appdata is NULL");
5090         CamAppData *camapp = ad->camapp_handle;
5091         cam_retm_if(camapp == NULL, "cam_handle is NULL");
5092
5093         if (camapp->af_mode == CAM_FOCUS_FACE) {
5094                 cam_app_run_video_stream();
5095         }
5096
5097         if (camapp->camera_mode == CAM_CAMERA_MODE) {
5098         if (cam_is_enabled_menu((void*)ad, CAM_MENU_BURST_SHOT_MODE) &&
5099                                 (camapp->burst_shot == TRUE) && camapp->continuous_shot_data) {
5100                         cam_utils_request_main_pipe_handler(ad, NULL, CAM_MAIN_PIPE_OP_TYPE_BURST_SHOT_DISPLAY_POPUP);
5101                         cam_continuous_shot_finish_save_image();
5102         } else {
5103                          cam_utils_request_main_pipe_handler(ad, NULL, CAM_MAIN_PIPE_OP_TYPE_BEST_SHOT_IMAGE_HANDLE);
5104            }
5105
5106                 DEBUG_TRACE("camapp->focus_mode %d ", camapp->focus_mode);
5107                 if (camapp->focus_mode == CAM_FOCUS_MODE_HALFSHUTTER) {
5108                         REMOVE_TIMER(ad->continuous_af_timer);
5109                         ad->continuous_af_timer = ecore_timer_add(FOCUS_FOCUSED_TIME_OUT, __cam_continuous_af_timer_cb, ad);
5110                 }
5111                 DEBUG_TRACE("camapp->burst_shot %d ", camapp->burst_shot);
5112                 DEBUG_TRACE("camapp->default_capture_mode %d ", camapp->default_capture_mode);
5113                 DEBUG_TRACE("ad->stop_continuous_shot %d ", ad->stop_continuous_shot);
5114
5115                 if (cam_is_enabled_menu((void*)ad, CAM_MENU_BURST_SHOT_MODE)
5116                                 && camapp->burst_shot == TRUE
5117                                 && camapp->default_capture_mode == CAM_CAPTURE_BURST) {
5118                         DEBUG_TRACE("TEST");
5119                 }
5120
5121                 if (ad->ug_state == CAM_UG_PAUSE_STATE){
5122                         cam_critical(LOG_MM, "CAM_UG_PAUSE_STATE");
5123                         return;
5124                 }
5125
5126                 if (!cam_app_preview_start(ad)) {
5127                         cam_critical(LOG_MM, "cam_app_preview_start failed");
5128                         cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA"), cam_app_timeout_notice_response_cb);
5129                         return;
5130                 }
5131         }else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
5132                 DEBUG_TRACE("MM_MESSAGE_CAMCORDER_VIDEO_SNAPSHOT_CAPTURED");
5133                 ecore_idler_add(cam_capture_on_recording_handle, ad);
5134         }
5135         DEBUG_TRACE();
5136 }
5137 static void __cam_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *data)
5138 {
5139         struct appdata *ad = (struct appdata *)data;
5140         cam_retm_if(ad == NULL, "appdata is NULL");
5141
5142         DEBUG_TRACE("policy is [%d]",policy);
5143
5144         switch (policy) {
5145         case CAMERA_POLICY_SOUND:
5146                 DEBUG_TRACE("occur incoming call");
5147                 break;
5148         case CAMERA_POLICY_SECURITY:
5149                 cam_app_mdm_syspopup(ad);
5150                 break;
5151         default:
5152                 break;
5153         }
5154 }
5155
5156 static void __rec_interrupted_cb(recorder_policy_e policy, recorder_state_e previous, recorder_state_e current, void *data)
5157 {
5158         struct appdata *ad = (struct appdata *)data;
5159         cam_retm_if(ad == NULL, "appdata is NULL");
5160
5161         DEBUG_TRACE("policy is [%d]",policy);
5162
5163         switch (policy) {
5164         case RECORDER_POLICY_SOUND:
5165                 DEBUG_TRACE("occur incoming call");
5166                 break;
5167         case RECORDER_POLICY_SECURITY:
5168                 cam_app_mdm_syspopup(ad);
5169                 break;
5170         default:
5171                 break;
5172         }
5173 }
5174
5175 static void __cam_error_cb(int error, camera_state_e current_state, void *user_data)
5176 {
5177         struct appdata *ad = NULL;
5178         CamAppData *camapp = NULL;
5179
5180         ad = (struct appdata *)user_data;
5181         cam_retm_if(ad == NULL, "appdata is NULL");
5182         camapp = ad->camapp_handle;
5183         cam_retm_if(camapp == NULL, "camapp is NULL");
5184
5185         int state = 0;
5186         state = current_state;
5187         cam_warning(LOG_MM,"MM ERROR occurs : code [%x], state [%d]",error, state);
5188
5189         char msg[1024] = { '\0', };
5190
5191         snprintf(msg, sizeof(msg), "Internal error %x", error);
5192         cam_app_notice_popup(ad, msg, cam_app_timeout_notice_response_cb);
5193
5194 }
5195
5196 static void __recorder_state_cb(recorder_state_e previous , recorder_state_e current , bool by_policy, void *user_data)
5197 {
5198         struct appdata *ad = NULL;
5199         CamAppData *camapp = NULL;
5200
5201         ad = (struct appdata *)user_data;
5202         cam_retm_if(ad == NULL, "appdata is NULL");
5203         camapp = ad->camapp_handle;
5204         cam_retm_if(camapp == NULL, "camapp is NULL");
5205         if (current == RECORDER_STATE_READY) {
5206                 ad->enable_mode_change = TRUE;
5207         } else {
5208                 ad->enable_mode_change = FALSE;
5209         }
5210         cam_app_recorder_state_manager(previous, current, by_policy);
5211 }
5212
5213 void __recording_status_cb(unsigned long long elapsed_time, unsigned long long file_size, void *user_data)
5214 {
5215         struct appdata *ad = NULL;
5216         CamAppData *camapp = NULL;
5217         ad = (struct appdata *)user_data;
5218         cam_retm_if(ad == NULL, "appdata is NULL");
5219         camapp = ad->camapp_handle;
5220         cam_retm_if(camapp == NULL, "camapp is NULL");
5221         /* update current time */
5222         DEBUG_TRACE();
5223         guint elapsed = 0;
5224         guint filesize = 0;
5225         elapsed = elapsed_time / 1000;
5226         filesize = file_size;
5227         if (camapp->rec_elapsed < elapsed) {
5228                 GValue value = { 0, };
5229
5230                 cam_debug(LOG_UI, "time updated: %u ", elapsed);
5231                 CAM_GVALUE_SET_UINT(value, elapsed);
5232                 cam_handle_value_set(ad, PROP_REC_TIME, &value);
5233         }
5234         if (camapp->rec_filesize < filesize) {
5235                 GValue value = { 0, };
5236
5237                 cam_debug(LOG_UI, "filesize updated: %u ", filesize);
5238                 CAM_GVALUE_SET_UINT(value, filesize);
5239                 cam_handle_value_set(ad, PROP_REC_FILE_SIZE, &value);
5240         }
5241 }
5242
5243 void __recording_limit_reached_cb(recorder_recording_limit_type_e type, void *user_data)
5244 {
5245         struct appdata *ad = NULL;
5246         CamAppData *camapp = NULL;
5247         ad = (struct appdata *)user_data;
5248         cam_retm_if(ad == NULL, "appdata is NULL");
5249         camapp = ad->camapp_handle;
5250         cam_retm_if(camapp == NULL, "camapp is NULL");
5251
5252         DEBUG_TRACE("");
5253         if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
5254                 if (type == RECORDER_RECORDING_LIMIT_FREE_SPACE)
5255                         camapp->rec_stop_type = CAM_REC_STOP_NO_SPACE;
5256                 else if (type == RECORDER_RECORDING_LIMIT_TIME
5257                                 || type == RECORDER_RECORDING_LIMIT_SIZE)
5258                         camapp->rec_stop_type = CAM_REC_STOP_TIME_LIMIT;
5259                 else {
5260                         DEBUG_TRACE("invalid type:%d", type);
5261                         camapp->rec_stop_type = CAM_REC_STOP_TIME_LIMIT;
5262                 }
5263                 ad->recording_commit = ecore_idler_add(cam_video_idler_record_stop, ad);
5264         }
5265 }
5266
5267 gboolean cam_callback_init(void *data)
5268 {
5269         struct appdata *ad = (struct appdata *)data;
5270         CamAppData *camapp = NULL;
5271
5272         debug_fenter(LOG_UI);
5273
5274         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5275         camapp = ad->camapp_handle;
5276         cam_retvm_if(camapp == NULL, FALSE, "cam_handle is NULL");
5277         camapp->error_cb = __cam_error_cb;
5278         camapp->focus_cb = __cam_focus_cb;
5279         camapp->state_cb = __cam_state_change_cb;
5280         camapp->preview_cb = __cam_preview_cb;
5281         camapp->capture_completed_cb = __cam_capture_completed_cb;
5282         camapp->cam_interrupted_cb = __cam_interrupted_cb;
5283
5284         camapp->recording_status_cb = __recording_status_cb;
5285         camapp->recording_state_changed_cb = __recorder_state_cb;
5286         camapp->recording_limit_reached_cb = __recording_limit_reached_cb;
5287         camapp->rec_interrupted_cb = __rec_interrupted_cb;
5288
5289         /*set face detect cb*/
5290         camapp->face_detect_cb = cam_face_detection_focus_face_detected_cb;
5291         camapp->capture_cb = __cam_capture_cb;
5292
5293         int ret = 1;
5294         if (camapp->camera_mode == CAM_CAMERA_MODE) {
5295                 /*ret &= cam_mm_recorder_unset_state_changed_cb();*/
5296                 ret &= cam_mm_set_preview_cb(camapp->preview_cb, (void*)ad);
5297                 ret &= cam_mm_set_focus_changed_cb(camapp->focus_cb, (void*)ad);
5298                 ret &= cam_mm_set_state_changed_cb(camapp->state_cb, (void*)ad);
5299                 ret &= cam_mm_set_error_cb(camapp->error_cb, (void*)ad);
5300                 ret &= cam_mm_set_camera_interrupted_cb(camapp->cam_interrupted_cb, (void*)ad);
5301         } else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
5302                 ret &= cam_mm_unset_state_changed_cb();
5303                 ret &= cam_mm_set_focus_changed_cb(camapp->focus_cb, (void*)ad);
5304                 ret &= cam_mm_recorder_set_state_changed_cb(camapp->recording_state_changed_cb, (void*)ad);
5305                 ret &= cam_mm_recorder_set_recording_status_cb(camapp->recording_status_cb, (void*)ad);
5306                 ret &= cam_mm_recorder_set_recording_limit_reached_cb(camapp->recording_limit_reached_cb, (void*)ad);
5307                 ret &= cam_mm_set_recorder_interrupted_cb(camapp->rec_interrupted_cb, (void*)ad);
5308         }
5309
5310
5311         return ret;
5312
5313 }
5314 gboolean cam_app_lbs_stop(void *data)
5315 {
5316         struct appdata *ad = (struct appdata *)data;
5317         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5318         CamAppData *camapp = ad->camapp_handle;
5319         cam_retvm_if(camapp == NULL, FALSE, "camapp is NULL");
5320
5321         int ret = FALSE;
5322
5323         ret = cam_lbs_stop();
5324         if(ret == FALSE) {
5325                 DEBUG_TRACE("cam_app_lbs_stop failed");
5326                 return FALSE;
5327         }
5328         camapp->gps = FALSE;
5329         camapp->gps_level = cam_lbs_get_state();
5330         indicator_update_gps(ad);       /* update gps icon */
5331         if (!cam_mm_remove_geo_tag())
5332                 DEBUG_TRACE("cam_mm_remove_geo_tag failed");
5333
5334         return TRUE;
5335
5336 }
5337 gboolean cam_app_lbs_start(void *data)
5338 {
5339         struct appdata *ad = (struct appdata *)data;
5340         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5341         CamAppData *camapp = ad->camapp_handle;
5342         cam_retvm_if(camapp == NULL, FALSE, "camapp is NULL");
5343
5344         int ret = FALSE;
5345
5346         ret = cam_lbs_start(cam_app_update_gps_level, ad);
5347         if (ret == FALSE) {
5348                 if(camapp->need_gps_popup == TRUE) {
5349                         cam_app_gps_enable_popup(ad,
5350                       dgettext(PACKAGE, "IDS_CAM_POP_ENABLE_LOCATION_SERVICE_IN_SETTINGS_TO_USE_GPS_TAG"), NULL);
5351                 }
5352                 return FALSE;
5353         }
5354         camapp->gps = TRUE;
5355
5356         REMOVE_TIMER(ad->gps_animation_timer);
5357         ad->gps_animation_timer = ecore_timer_add(0.5, cam_app_gps_timer_cb, ad);
5358
5359         return TRUE;
5360
5361 }
5362
5363 static void cam_app_close_ug(void *data)
5364 {
5365         cam_debug(LOG_UI, " ");
5366         struct appdata *ad = (struct appdata *)data;
5367         /* IDS problem */
5368
5369         cam_info(LOG_UI, "ad->imageviewer_ug : %p", ad->imageviewer_ug);
5370         if (ad->imageviewer_ug) {
5371                 ug_destroy(ad->imageviewer_ug);
5372                 ad->imageviewer_ug = NULL;
5373         }
5374         if (ad->location_ug) {
5375                 ug_destroy(ad->location_ug);
5376                 ad->location_ug = NULL;
5377         }
5378
5379         cam_file_init(NULL);
5380         return;
5381 }
5382
5383 static void __ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
5384 {
5385         cam_debug(LOG_UI, " ");
5386
5387         Evas_Object *base;
5388
5389         if (!ug || !priv)
5390                 return;
5391
5392         base = ug_get_layout(ug);
5393         if (!base)
5394                 return;
5395
5396         switch (mode) {
5397         case UG_MODE_FULLVIEW:
5398                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
5399                 ug_disable_effect(ug);/*note: disable Image viewer ug effect*/
5400                 evas_object_show(base);
5401                 break;
5402         default:
5403                 break;
5404         }
5405 }
5406
5407 void __ug_result_cb(ui_gadget_h ug, service_h result, void *priv)
5408 {
5409         cam_debug(LOG_UI, " ");
5410
5411         struct appdata *ad = (struct appdata *)priv;
5412         cam_retm_if(ad == NULL, "appdata is NULL");
5413         CamAppData *camapp = ad->camapp_handle;
5414         cam_retm_if(camapp == NULL, "cam_handle is NULL");
5415
5416         char *val = NULL;
5417         ad->path_in_return = false;
5418
5419         if (ad->imageviewer_ug) {
5420                 if (ad->launching_mode == CAM_LAUNCHING_MODE_EXTERNAL) {
5421                         if (result == NULL) {
5422                                 return;
5423                         }
5424
5425                         if ((ad->exe_args->caller) && (strcmp(ad->exe_args->caller, "contacts") == 0)) {
5426                                 service_h reply;
5427                                 service_create(&reply);
5428
5429                                 service_get_extra_data(result, "crop_image_path", &val);
5430                                 service_add_extra_data(reply, "crop_image_path", val);
5431                                 service_get_extra_data(result, "image_path", &val);
5432                                 service_add_extra_data(reply, "image_path", val);
5433
5434                                 service_reply_to_launch_request(reply, ad->service_handle, SERVICE_RESULT_SUCCEEDED);
5435                                 service_destroy(reply);
5436
5437                                 ad->path_in_return = true;
5438                         } else if ((ad->exe_args->caller) && (strcmp(ad->exe_args->caller, "ug-setting-call-efl") == 0)) {
5439                                 service_h reply;
5440                                 service_create(&reply);
5441
5442                                 service_get_extra_data(result, "crop_image_path", &val);
5443                                 service_add_extra_data(reply, SERVICE_DATA_SELECTED, val);
5444
5445                                 service_reply_to_launch_request(reply, ad->service_handle, SERVICE_RESULT_SUCCEEDED);
5446                                 service_destroy(reply);
5447
5448                                 ad->path_in_return = true;
5449                         } else {
5450                                 /* get result value. */
5451                                 service_get_extra_data(result, "Result", &val);
5452
5453                                 if (strcmp(val, "Ok") == 0) {
5454                                         ad->path_in_return = true;
5455                                 }
5456                                 else if (strcmp(val, "Cancel") == 0) {
5457                                         ad->path_in_return = false;
5458                                 }
5459                         }
5460                 }
5461         }
5462 }
5463
5464 void __ug_destroy_cb(ui_gadget_h ug, void *priv)
5465 {
5466         cam_debug(LOG_UI, " ");
5467
5468         if (!ug || !priv)
5469                 return;
5470
5471         struct appdata *ad = (struct appdata *)priv;
5472         cam_retm_if(ad == NULL, "appdata is NULL");
5473         CamAppData *camapp = ad->camapp_handle;
5474         cam_retm_if(camapp == NULL, "camapp is NULL");
5475
5476         if (ad->path_in_return) {
5477                 elm_win_lower(ad->win_main);
5478                 cam_app_exit(ad);
5479         } else {
5480                 ad->ug_is_deleting_process = TRUE;
5481
5482                 cam_app_timeout_checker_init(ad);
5483
5484                 if (ad->imageviewer_ug) {
5485                         ug_destroy(ad->imageviewer_ug);
5486                         ad->imageviewer_ug = NULL;
5487                 }
5488
5489                 if (ad->location_ug) {
5490                         ug_destroy(ad->location_ug);
5491                         ad->location_ug = NULL;
5492                         camapp->need_gps_popup = FALSE;
5493                         if (!cam_app_lbs_start(ad)) {
5494                                 if (!cam_app_lbs_stop(ad))
5495                                         DEBUG_TRACE("The LBS failed to stop");
5496                         }
5497                 }
5498
5499                 cam_app_start_rotate(ad, false);
5500
5501                 ecore_idler_add(__ug_destory_postprocessing, ad);
5502         }
5503
5504         return;
5505 }
5506
5507 Eina_Bool __ug_destory_postprocessing(void *data)
5508 {
5509         struct appdata *ad = data;
5510         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5511         ad->ug_is_deleting_process = TRUE;
5512         CamAppData *camapp = NULL;
5513         camapp = ad->camapp_handle;
5514         cam_retvm_if(camapp == NULL, FALSE,  "cam_handle is NULL");
5515
5516         cam_app_focus_guide_create(ad);
5517         show_toolbar_edje(ad);
5518
5519         if (!cam_file_check_exists(camapp->filename)) {
5520                 free(camapp->filename);
5521                 camapp->filename = NULL;
5522         }
5523
5524         if (!cam_app_preview_start(ad)) {
5525                 cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA"), cam_app_timeout_notice_response_cb);
5526         }
5527
5528         cam_mm_set_mdnie_mode(TRUE);
5529
5530         if (camapp->outdoor_visibility)
5531                 cam_mm_set_outdoor_visibility(TRUE);
5532
5533         power_lock_state(POWER_STATE_NORMAL, 0);
5534
5535         if (camapp->camera_mode == CAM_CAMERA_MODE) {
5536                 if(camapp->af_mode == CAM_FOCUS_FACE){
5537                 /*start face detection*/
5538                         if (cam_mm_is_supported_face_detection()) {
5539                                 cam_mm_start_camera_face_detection(camapp->face_detect_cb, (void *)ad);
5540                                 if (!cam_mm_set_preview_cb(cam_face_detection_focus_start_stream, (void*)ad)) {
5541                                         DEBUG_TRACE("preview callback set error");
5542                                 }
5543                                 cam_app_run_video_stream();
5544                         } else {
5545                                 DEBUG_TRACE("not support face detect mode");
5546                         }
5547                 }
5548         }
5549         if (!cam_key_grab_init(ad))
5550                 DEBUG_TRACE("cam_key_grab_init fail");
5551         cam_app_key_event_init(ad);
5552
5553         cam_app_update_quickview_icon(ad);
5554         cam_file_init(NULL);
5555         ad->ug_is_deleting_process = FALSE;
5556
5557         return ECORE_CALLBACK_CANCEL;
5558 }
5559
5560 gboolean cam_app_run_location_ug(void *data)
5561 {
5562         DEBUG_TRACE("START");
5563
5564         struct appdata *ad = (struct appdata *)data;
5565         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5566         CamAppData *camapp = NULL;
5567         camapp = ad->camapp_handle;
5568         cam_retvm_if(camapp == NULL, FALSE,  "cam_handle is NULL");
5569
5570         if (ad->ug_is_deleting_process) /*NOTE:before old ug is not deleted completely, should not create new ug*/
5571                 return FALSE;
5572
5573         if (ad->location_ug) {
5574                 ug_destroy(ad->location_ug);
5575                 ad->location_ug = NULL;
5576         }
5577
5578         DEL_EVAS_OBJECT(ad->focus_edje);
5579
5580         struct ug_cbs cbs = { 0, };
5581
5582         cbs.layout_cb = __ug_layout_cb;
5583         cbs.result_cb = __ug_result_cb;
5584         cbs.destroy_cb = __ug_destroy_cb;
5585         cbs.priv = (void *)data;
5586
5587         /* Create UI gadget */
5588         ad->location_ug = ug_create(NULL, LOCATION_UG_NAME, UG_MODE_FULLVIEW, NULL, &cbs);
5589
5590         if (!ad->location_ug) {
5591                 cam_critical(LOG_SYS, "location UI Gadget create fail...");
5592                 return FALSE;
5593         } else {
5594                 if (ad->location_ug) {
5595                         cam_mm_set_mdnie_mode(FALSE);
5596
5597                         if (camapp->outdoor_visibility)
5598                                 cam_mm_set_outdoor_visibility(FALSE);
5599
5600                         cam_app_preview_stop();
5601                         power_unlock_state(POWER_STATE_NORMAL);
5602                 } else {
5603                         cam_warning(LOG_UI, "Cannot create location_ug");
5604                         cam_file_init(NULL);
5605                         return FALSE;
5606                 }
5607         }
5608
5609         cam_app_timeout_checker_remove();
5610
5611         return TRUE;
5612 }
5613 gboolean cam_app_run_image_viewer_ug(void *data, char *file_path, gboolean launch_special_view)
5614 {
5615         DEBUG_TRACE("START");
5616
5617         struct appdata *ad = (struct appdata *)data;
5618         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5619         CamAppData *camapp = ad->camapp_handle;
5620         cam_retvm_if(camapp == NULL, FALSE,"camapp is NULL");
5621         cam_retvm_if(file_path == NULL, FALSE, "file_path is NULL");
5622
5623         if (ad->ug_is_deleting_process) /*NOTE:before old ug is not deleted completely, should not create new ug*/
5624                 return FALSE;
5625
5626         cam_debug(LOG_UI, "path :%s", file_path);
5627
5628         if (ad->imageviewer_ug) {
5629                 return FALSE;/*NOTE: ug is login, not create ug again.*/
5630         }
5631         if (ad->is_rotating == TRUE) {
5632                 return FALSE; /*note: while rotating, could not create image view ug*/
5633         }
5634
5635         DEL_EVAS_OBJECT(ad->focus_edje);
5636
5637         struct ug_cbs cbs = { 0, };
5638
5639         cbs.layout_cb = __ug_layout_cb;
5640         cbs.result_cb = __ug_result_cb;
5641         cbs.destroy_cb = __ug_destroy_cb;
5642         cbs.priv = (void *)data;
5643
5644         /* param */
5645         if (ad->imageviewer_service)
5646                 service_destroy(ad->imageviewer_service);
5647
5648         int ret = service_create(&ad->imageviewer_service);
5649         if (ret != SERVICE_ERROR_NONE) {
5650                 cam_critical(LOG_UI, "service_create error [%d]", ret);
5651                 return FALSE;
5652         }
5653
5654         if (ad->launching_mode == CAM_LAUNCHING_MODE_EXTERNAL) {
5655                 if ((ad->exe_args->caller) && (strcmp(ad->exe_args->caller, "contacts") == 0)) {
5656                         service_add_extra_data(ad->imageviewer_service, IMAGE_VIEWER_VIEW_MODE_KEY_NAME, "SETAS");
5657                         service_add_extra_data(ad->imageviewer_service, IMAGE_VIEWER_SET_AS_TYPE, "CallerID");
5658                 } else if ((ad->exe_args->caller) && (strcmp(ad->exe_args->caller, "ug-setting-call-efl") == 0)) {
5659                         service_add_extra_data(ad->imageviewer_service, IMAGE_VIEWER_VIEW_MODE_KEY_NAME, "SETAS");
5660                         service_add_extra_data(ad->imageviewer_service, IMAGE_VIEWER_SET_AS_TYPE, "VideoCallID");
5661                         service_add_extra_data(ad->imageviewer_service, IMAGE_VIEWER_RESOLUTION, "176x144");
5662                 } else {
5663                         service_add_extra_data(ad->imageviewer_service, IMAGE_VIEWER_VIEW_MODE_KEY_NAME, "DISPLAY");
5664                 }
5665         } else if (ad->launching_mode == CAM_LAUNCHING_MODE_NORMAL) {
5666                 service_add_extra_data(ad->imageviewer_service, IMAGE_VIEWER_VIEW_MODE_KEY_NAME, "CAMERA");
5667         }
5668
5669         service_add_extra_data(ad->imageviewer_service, IMAGE_VIEWER_FILE_PATH_KEY_NAME, file_path);
5670
5671         /* Create UI gadget */
5672         ad->imageviewer_ug = ug_create(NULL, IMAGE_VIEWER_UG_NAME, UG_MODE_FULLVIEW, ad->imageviewer_service, &cbs);
5673
5674         if (!ad->imageviewer_ug) {
5675                 cam_critical(LOG_SYS, "image viewer UI Gadget create fail...");
5676                 return FALSE;
5677         } else {
5678                 if (ad->imageviewer_ug) {
5679                         cam_app_key_event_deinit(ad);
5680                         if(!cam_key_grab_deinit(ad)){
5681                                 DEBUG_TRACE("cam_key_grab_deinit fail");
5682                         }
5683                         cam_mm_set_mdnie_mode(FALSE);
5684
5685                         if (camapp->outdoor_visibility)
5686                                 cam_mm_set_outdoor_visibility(FALSE);
5687
5688                         cam_app_preview_stop();
5689                         power_unlock_state(POWER_STATE_NORMAL);
5690                 } else {
5691                         cam_warning(LOG_UI, "Cannot create imageviewer ug");
5692                         cam_file_init(NULL);
5693                         return FALSE;
5694                 }
5695         }
5696
5697         if(camapp->af_mode == CAM_FOCUS_FACE){
5698                 cam_face_detection_reset();
5699         }
5700         DEBUG_TRACE("END");
5701
5702         cam_app_timeout_checker_remove();
5703
5704         return TRUE;
5705 }
5706
5707 gboolean cam_app_run_media_browser(void *data, gchar *filename)
5708 {
5709         cam_debug(LOG_UI, "filename = %s", filename);
5710         struct appdata *ad = (struct appdata *)data;
5711         CamAppData *camapp = NULL;
5712         int state = 0;
5713
5714         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5715         camapp = ad->camapp_handle;
5716         cam_retvm_if(camapp == NULL, FALSE, "cam_handle is NULL");
5717
5718         debug_fenter(LOG_UI);
5719
5720         state = cam_mm_get_state();
5721         if (state > CAMERA_STATE_PREVIEW) {
5722                 cam_warning(LOG_MM, "Invaild state : %d", state);
5723                 return FALSE;
5724         }
5725
5726         if (!cam_app_run_image_viewer_ug(ad, cam_app_get_last_filename(), FALSE)) {
5727                 DEBUG_TRACE("cam_app_run_image_viewer_ug failed");
5728                 return FALSE;
5729         }
5730
5731         if (camapp->thumbnail_name) {   /*  Some image is deleted from image viewer and galler -> BS  */
5732                 free(camapp->thumbnail_name);
5733                 camapp->thumbnail_name = NULL;
5734         }
5735
5736         return TRUE;
5737 }
5738
5739 gboolean cam_app_clear_engine_data(void *data, gboolean release)
5740 {
5741 #ifndef CAMERA_MACHINE_I686
5742
5743         /* release is not used */
5744         struct appdata *ad = (struct appdata *)data;
5745         CamAppData *camapp = NULL;
5746
5747         cam_debug(LOG_UI, "");
5748
5749         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5750         camapp = ad->camapp_handle;
5751         cam_retvm_if(camapp == NULL, FALSE, "cam_handle is NULL");
5752
5753 #endif
5754         return TRUE;
5755 }
5756
5757 gboolean cam_app_check_wide_resolution(int id)
5758 {
5759
5760         gfloat get_value = (HIWORD(id) * 3.0) / (LOWORD(id) * 4.0);
5761         if (ABS(get_value - 1.0) < CAM_EPSINON
5762             || ABS((gfloat)((HIWORD(id) * 25.0) / (LOWORD(id) * 36.0)) - 1.0) < CAM_EPSINON) {
5763                 return FALSE;
5764         }
5765
5766         return TRUE;
5767
5768 }
5769
5770 gboolean cam_app_is_skip_video_stream()
5771 {                               /*if true , must finish function in stream callback function */
5772         return video_stream_skip_flag;
5773 }
5774
5775 void cam_app_stop_video_stream()
5776 {
5777         video_stream_skip_flag = TRUE;
5778 }
5779
5780 void cam_app_run_video_stream()
5781 {
5782         video_stream_skip_flag = FALSE;
5783 }
5784
5785 Eina_Bool _auto_shot_idle_cb(void *data)
5786 {
5787         debug_fenter(LOG_CAM);
5788         struct appdata *ad = (struct appdata *)data;
5789         CamAppData *camapp = NULL;
5790         gboolean capture_result = false;
5791
5792         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5793         camapp = ad->camapp_handle;
5794         cam_retvm_if(camapp == NULL, FALSE, "cam_handle is NULL");
5795
5796         if (ad->auto_shot_idle) {
5797                 ecore_idler_del(ad->auto_shot_idle);
5798                 ad->auto_shot_idle = NULL;
5799         }
5800
5801         cam_warning(LOG_CAM, "position state not enough");
5802         debug_fleave(LOG_CAM);
5803
5804         return ECORE_CALLBACK_CANCEL;
5805 }
5806
5807 gboolean cam_app_create_progressbar(void *data)
5808 {
5809         struct appdata *ad = (struct appdata *)(data);
5810         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5811
5812         cam_debug(LOG_UI, "");
5813
5814         cam_app_destroy_progressbar(ad);
5815
5816         ad->progressbar = elm_progressbar_add(ad->ug_base);
5817         cam_retvm_if(ad->progressbar == NULL, FALSE, "Cannot create progressbar object\n");
5818
5819         elm_object_style_set(ad->progressbar, "list_progress");
5820         evas_object_size_hint_align_set(ad->progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
5821
5822         evas_object_show(ad->progressbar);
5823
5824         return TRUE;
5825 }
5826
5827 gboolean cam_app_set_progressbar_value(void *data, double value)
5828 {
5829         struct appdata *ad = (struct appdata *)(data);
5830         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5831
5832         if (ad->progressbar) {
5833                 cam_debug(LOG_UI, " value [%f]", value);
5834                 elm_progressbar_value_set(ad->progressbar, value);
5835         } else
5836                 UI_TEST_LOG("");
5837
5838         return TRUE;
5839 }
5840
5841 gboolean cam_app_set_progressbar_text(void *data, const char *text)
5842 {
5843         struct appdata *ad = (struct appdata *)(data);
5844         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5845
5846         cam_retv_if(text == NULL, FALSE);
5847
5848         if (ad->progressbar_edje)
5849                 edje_object_part_text_set(_EDJ(ad->progressbar_edje),
5850                                           "progressbar_text", text);
5851
5852         return TRUE;
5853 }
5854
5855 gboolean cam_app_destroy_progressbar(void *data)
5856 {
5857         struct appdata *ad = (struct appdata *)(data);
5858         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5859
5860         cam_debug(LOG_UI, " start");
5861         DEL_EVAS_OBJECT(ad->progressbar);
5862         DEL_EVAS_OBJECT(ad->progressbar_edje);
5863         cam_debug(LOG_UI, " done");
5864
5865         return TRUE;
5866 }
5867
5868 gboolean cam_app_hide_progressbar(void *data)
5869 {
5870         struct appdata *ad = (struct appdata *)(data);
5871         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5872
5873         cam_debug(LOG_UI, " start");
5874         HIDE_EVAS_OBJECT(ad->progressbar);
5875         HIDE_EVAS_OBJECT(ad->progressbar_edje);
5876         cam_debug(LOG_UI, " done");
5877
5878         return TRUE;
5879 }
5880
5881 gboolean cam_app_timeout_checker_update()
5882 {
5883         struct appdata *ad = NULL;
5884         CamAppData *camapp = NULL;
5885         gdouble c_time = 0.0;
5886         cam_debug(LOG_UI, "");
5887
5888         ad = (struct appdata *)cam_appdata_get();
5889         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
5890         camapp = ad->camapp_handle;
5891         cam_retvm_if(camapp == NULL, FALSE, "cam_handle is NULL");
5892
5893         if (ad->timeout_checker) {
5894                 c_time = _get_current_time();
5895                 ecore_timer_delay(ad->timeout_checker,
5896                                   (c_time - camapp->last_time));
5897                 camapp->last_time = c_time;
5898         }
5899
5900         return TRUE;
5901 }
5902
5903 void cam_app_mdm_syspopup(void *data)
5904 {
5905         struct appdata *ad = (struct appdata *)(data);
5906         cam_retm_if(ad == NULL, " appdata is NULL");
5907         bundle *b = NULL;
5908         b = bundle_create();
5909         if (b != NULL) {
5910                 bundle_add(b, "_SYSPOPUP_CONTENT_", dgettext(PACKAGE, "IDS_CAM_POP_SECURITY_POLICY_RESTRICTS_USE_OF_CAMERA"));
5911                 syspopup_launch("mdm-syspopup", b);
5912                 bundle_free(b);
5913         }
5914
5915         cam_app_exit(ad);
5916 }
5917
5918 void cam_app_notice_popup(void *data, const char *msg,
5919                           void (*func) (void *data,
5920                           Evas_Object *obj,
5921                           void *event_info)
5922                           )
5923 {
5924         struct appdata *ad = (struct appdata *)(data);
5925         cam_retm_if(ad == NULL, " appdata is NULL");
5926         cam_retm_if(ad->ug_base == NULL, " ad->ug_base is NULL");
5927         Evas_Object *popup = NULL;
5928
5929         popup = elm_popup_add(ad->ug_base);
5930         if (popup == NULL)
5931                 return;
5932
5933         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
5934         elm_object_text_set(popup, msg);
5935         /*elm_popup_mode_set(popup, ELM_POPUP_TYPE_ALERT);*/
5936         elm_popup_timeout_set(popup, 3.0);
5937         evas_object_smart_callback_add(popup, "timeout", func, data);
5938         ad->waring_popup = popup;
5939         evas_object_show(popup);
5940 }
5941
5942 static void cam_app_capture_error_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
5943 {
5944         struct appdata *ad = (struct appdata *)cam_appdata_get();
5945         cam_retm_if(ad == NULL, " appdata is NULL");
5946         CamAppData *camapp = ad->camapp_handle;
5947         cam_retm_if(camapp == NULL, " camapp is NULL");
5948         if (obj)
5949                 evas_object_del(obj);
5950         obj = NULL;
5951
5952         cam_app_stop_capture(ad);
5953         cam_app_exit(ad);
5954 }
5955
5956 void cam_app_gps_enable_popup(void *data, const char *msg,
5957                               Eina_Bool (*func) (void *data))
5958 {
5959         struct appdata *ad = (struct appdata *)(data);
5960         cam_retm_if(ad == NULL, " appdata is NULL");
5961         cam_retm_if(ad->ug_base == NULL, " ad->ug_base is NULL");
5962         Evas_Object * popup = NULL;
5963         popup = elm_popup_add(ad->ug_base);
5964         if (popup == NULL)
5965                 return;
5966         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
5967
5968         char popup_str[1024 + 1] = { '\0',};
5969         snprintf(popup_str, 1024, "%s%s%s", _("<font=SLP:style=Roman><color=#000000><align=center>"),
5970                 msg, _("</align></color></font>"));
5971
5972         elm_object_text_set(popup, popup_str);
5973         Evas_Object *btn1 = elm_button_add(popup);
5974         elm_object_text_set(btn1, dgettext(PACKAGE, "IDS_CAM_BODY_SETTINGS"));
5975         elm_object_part_content_set(popup, "button1", btn1);
5976         evas_object_smart_callback_add(btn1, "clicked", cam_app_gps_popup_response_ok_cb, (void*)ad);
5977         Evas_Object *btn2 = elm_button_add(popup);
5978         elm_object_text_set(btn2, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
5979         elm_object_part_content_set(popup, "button2", btn2);
5980         evas_object_smart_callback_add(btn2, "clicked", cam_app_gps_popup_response_cancel_cb, (void*)ad);
5981         ad->confirm_popup = popup;
5982
5983         evas_object_show(popup);
5984
5985 }
5986
5987 void cam_app_timeout_notice_response_cb(void *data, Evas_Object *obj,
5988                                         void *event_info)
5989 {
5990         struct appdata *ad = (struct appdata *)cam_appdata_get();
5991         cam_retm_if(ad == NULL, " appdata is NULL");
5992
5993         CamAppData *camapp = NULL;
5994         camapp = ad->camapp_handle;
5995         cam_retm_if(camapp == NULL, "camapp_handle is NULL");
5996
5997         if (obj){
5998                 evas_object_del(obj);
5999                 obj = NULL;
6000         }
6001
6002         cam_app_stop_capture(ad);
6003         cam_app_exit(ad);
6004 }
6005
6006 /*set flash close*/
6007 void cam_close_flash_feature(void *data)
6008 {
6009         struct appdata *ad = (struct appdata *)data;
6010         cam_retm_if(ad == NULL, " appdata is NULL");
6011         CamAppData *camapp = ad->camapp_handle;
6012         cam_retm_if(camapp == NULL, " appdata is NULL");
6013         if (camapp->flash > CAM_FLASH_OFF) {
6014                 GValue value = { 0 };
6015                 CAM_GVALUE_SET_INT(value, CAM_FLASH_OFF);
6016                 gint tempval = g_value_get_int(&value);
6017                 if (!cam_mm_set_flash(tempval)) {
6018                         cam_warning(LOG_UI, "flash set fail");
6019                         return;
6020                 }
6021                 camapp->flash = tempval;
6022         }
6023 }
6024 /*lowbattery callback*/
6025 void cam_app_lowbattery_close_flash_cb(void *data, Evas_Object *obj, void *event_info)
6026 {
6027         struct appdata *ad = (struct appdata *)cam_appdata_get();
6028         cam_retm_if(ad == NULL, " appdata is NULL");
6029         if (obj)
6030                 evas_object_del(obj);
6031         obj = NULL;
6032         cam_close_flash_feature(ad);
6033
6034         cam_toolbar_update(ad);
6035 }
6036
6037 static Eina_Bool cam_app_timeout_checker_cb(void *data)
6038 {
6039         struct appdata *ad = (struct appdata *)(data);
6040         CamAppData *camapp = NULL;
6041         gdouble diff = 0.0;
6042
6043         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
6044         camapp = ad->camapp_handle;
6045         if (camapp == NULL) {
6046                 ad->timeout_checker = NULL;
6047                 return ECORE_CALLBACK_CANCEL;
6048         }
6049         ad->timeout_checker = NULL;
6050
6051         diff = _get_current_time() - camapp->last_time;
6052
6053         if ((cam_mm_get_state() == CAMERA_STATE_PREVIEW)
6054             && (diff >= CAMERA_APP_TIMEOUT)) {
6055                 cam_debug(LOG_UI, "Close camera application!!! diff time:[%lf]", diff);
6056                 ad->timeout_checker = NULL;
6057                 camapp->last_time = 0;
6058                 elm_win_lower(ug_get_window());
6059         }
6060
6061         cam_debug(LOG_UI, "diff time : [%lf]", diff);
6062         return ECORE_CALLBACK_CANCEL;
6063 }
6064
6065 gboolean cam_app_timeout_checker_init(void *data)
6066 {
6067         struct appdata *ad = (struct appdata *)(data);
6068         CamAppData *camapp = NULL;
6069
6070         debug_fenter(LOG_CAM);
6071
6072         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
6073         camapp = ad->camapp_handle;
6074         cam_retvm_if(camapp == NULL, FALSE, "cam_handle is NULL");
6075
6076         if (ad->timeout_checker) {
6077                 ecore_timer_del(ad->timeout_checker);
6078                 ad->timeout_checker = NULL;
6079         }
6080         if (ad->timer_timer) {
6081                 ad->timer_activated = false;
6082                 DEL_EVAS_OBJECT(ad->timer_icon_edje);
6083                 REMOVE_TIMER(ad->timer_timer);
6084         }
6085         if (ad->continuous_shot_timer) {
6086                 REMOVE_TIMER(ad->continuous_shot_timer);
6087         }
6088         if (ad->check_af_timer) {
6089                 REMOVE_TIMER(ad->check_af_timer);
6090         }
6091         if (ad->gps_animation_timer) {
6092                 REMOVE_TIMER(ad->gps_animation_timer);
6093         }
6094
6095         ad->timeout_checker = ecore_timer_add(CAMERA_APP_TIMEOUT, cam_app_timeout_checker_cb, ad);
6096         camapp->last_time = _get_current_time();
6097
6098         return TRUE;
6099 }
6100
6101 gboolean cam_app_timeout_checker_remove(void)
6102 {
6103         struct appdata *ad = NULL;
6104         CamAppData *camapp = NULL;
6105
6106         debug_fenter(LOG_CAM);
6107
6108         ad = (struct appdata *)cam_appdata_get();
6109         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
6110         camapp = ad->camapp_handle;
6111         cam_retvm_if(camapp == NULL, FALSE, "cam_handle is NULL");
6112
6113         if (ad->timeout_checker) {
6114                 ecore_timer_del(ad->timeout_checker);
6115                 ad->timeout_checker = NULL;
6116         }
6117         camapp->last_time = 0;
6118
6119         return TRUE;
6120 }
6121
6122 #ifdef USE_FIFO_THREAD
6123 void *cam_app_FIFO_thread_run(void *data)
6124 {
6125         struct appdata *ad = (struct appdata *)data;
6126
6127         int fd = 0;
6128
6129         char buf[128] = { '\0', };
6130
6131         cam_retvm_if(ad == NULL, NULL, "appdata is NULL");
6132
6133         if (!access(CAM_FIFO_PATH, F_OK)) {
6134                 unlink(CAM_FIFO_PATH);
6135         }
6136
6137         if (-1 == mkfifo(CAM_FIFO_PATH, 0666)) {
6138                 cam_critical(LOG_SYS, " Make CamApp FIFO failed.");
6139                 cam_app_exit(ad);
6140                 return NULL;
6141         }
6142
6143         fd = open(CAM_FIFO_PATH, O_RDWR);
6144         if (fd < 0) {
6145                 cam_critical(LOG_SYS, " Open CamApp FIFO failed.");
6146                 cam_app_exit(ad);
6147                 return NULL;
6148         }
6149
6150         cam_debug(LOG_SYS, "Open CamApp FIFO [%s] success", CAM_FIFO_PATH);
6151
6152         while (1) {
6153                 memset(buf, 0x00, 128);
6154
6155                 cam_debug(LOG_SYS, " Wait CamApp FIFO write...");
6156
6157                 int count = read(fd, buf, 128);
6158                 if (count == -1)
6159                         cam_debug(LOG_SYS, " read error occur!");
6160
6161                 cam_debug(LOG_SYS, " Read from CamApp FIFO : [%s]", buf);
6162
6163                 if (!strcmp(buf, CAM_CAPTURE_AUTO_START)) {
6164                         cam_debug(LOG_SYS, " #### Start _auto_shot_idle_cb");
6165                         _auto_shot_idle_cb(data);
6166                 } else if (!strcmp(buf, CAM_FIFO_CMD_EXIT)) {
6167                         break;
6168                 } else {
6169                         /* Error */
6170                         cam_warning(LOG_SYS, " Skip this...");
6171                 }
6172         }
6173
6174         close(fd);
6175         unlink(CAM_FIFO_PATH);
6176
6177         cam_debug(LOG_SYS, " Exit CamApp FIFO thread...");
6178
6179         return NULL;
6180 }
6181
6182 void cam_app_FIFO_thread_exit()
6183 {
6184         int fd = open(CAM_FIFO_PATH, O_WRONLY);
6185         char *str_write = CAM_FIFO_CMD_EXIT;
6186
6187         if (fd < 0) {
6188                 cam_critical(LOG_SYS, " Open CammApp FIFO file[%s] failed",
6189                              CAM_FIFO_PATH);
6190         } else {
6191                 int count = write(fd, str_write, strlen(str_write));
6192                 if (count == -1)
6193                         cam_debug(LOG_SYS, " write error occur! ");
6194                 close(fd);
6195
6196                 cam_debug(LOG_SYS, " Write [%s] to FIFO Done.", str_write);
6197         }
6198 }
6199
6200 #endif
6201
6202 gboolean cam_app_create_file_register_thread(void *data)
6203 {
6204         struct appdata *ad = (struct appdata *)data;
6205
6206         int err = 0;
6207         cam_debug(LOG_SYS, "");
6208
6209         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
6210
6211         err = pthread_mutex_init(&(ad->file_reg_mutex), NULL);
6212         if (err != 0) {
6213                 cam_critical(LOG_CAM,
6214                              "Create Camera file register mutex failed");
6215                 return FALSE;
6216         }
6217
6218         err = pthread_cond_init(&(ad->file_reg_cond), NULL);
6219         if (err != 0) {
6220                 cam_critical(LOG_CAM,
6221                              "Create Camera file register cond failed");
6222                 return FALSE;
6223         }
6224
6225         ad->file_reg_queue = g_queue_new();
6226         if (ad->file_reg_queue == NULL) {
6227                 cam_critical(LOG_CAM,
6228                              "Create Camera file register queue failed");
6229                 return FALSE;
6230         }
6231
6232         err = pthread_create(&(ad->file_reg_thread), NULL, cam_app_file_register_thread_run, (void *)ad);
6233
6234         if (err != 0) {
6235                 cam_critical(LOG_CAM,
6236                              "Create Camera file register thread failed");
6237                 return FALSE;
6238         }
6239
6240         return TRUE;
6241 }
6242
6243 void *cam_app_file_register_thread_run(void *data)
6244 {
6245         struct appdata *ad = (struct appdata *)data;
6246         gboolean Exit_loop = FALSE;
6247         cam_debug(LOG_FILE, "");
6248
6249         pthread_mutex_lock(&ad->file_reg_mutex);
6250
6251         while (!Exit_loop) {
6252                 cam_debug(LOG_FILE, " wait signal...");
6253
6254                 pthread_cond_wait(&ad->file_reg_cond, &ad->file_reg_mutex);
6255
6256                 cam_debug(LOG_FILE, " signal received");
6257                 while (!g_queue_is_empty(ad->file_reg_queue)) {
6258                         char *filename = NULL;
6259                         filename = g_queue_pop_head(ad->file_reg_queue);
6260                         DEBUG_TRACE("filename is %s", filename);
6261                         if (strcmp(REG_THREAD_EXIT, filename) == 0) {
6262                                 free(filename);
6263                                 Exit_loop = TRUE;
6264                                 break;
6265                         } else if (strcmp(UPDATE_THUMBNAIL, filename) == 0) {
6266                                 /*TODO:*/
6267                         } else if (strcmp(UPDATE_THUMBNAIL_NO_ANI, filename) == 0) {
6268                                  /*TODO:*/
6269                         } else if (strcmp(REC_FILE_SAVE_REG, filename) == 0) {
6270                                 cam_rec_save_and_register_video_file(ad);
6271                                 free(filename);
6272                                 filename = NULL;
6273                         } else {
6274                                 __cam_single_shot_reg_file(filename);
6275                                 free(filename);
6276                                 cam_debug(LOG_FILE, " register done.");
6277                         }
6278                 }
6279                 /*TODO: update thumbnail*/
6280
6281         }
6282
6283         pthread_mutex_unlock(&ad->file_reg_mutex);
6284
6285         pthread_mutex_destroy(&ad->file_reg_mutex);
6286         pthread_cond_destroy(&ad->file_reg_cond);
6287
6288         cam_debug(LOG_SYS, " thread exit...");
6289
6290         return NULL;
6291 }
6292
6293 void cam_app_file_register_thread_exit(void *data)
6294 {
6295         struct appdata *ad = (struct appdata *)data;
6296         char *exit_cmd = NULL;
6297
6298         if (ad->file_reg_queue != NULL) {
6299                 exit_cmd = strdup(REG_THREAD_EXIT);
6300                 g_queue_push_tail(ad->file_reg_queue, exit_cmd);
6301                 pthread_cond_signal(&ad->file_reg_cond);
6302         }
6303         return;
6304 }
6305
6306 gboolean cam_app_init_with_args(void *data)
6307 {
6308         struct appdata *ad = (struct appdata *)data;
6309         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
6310         cam_retvm_if(ad->camapp_handle == NULL, FALSE, "camapp is NULL");
6311
6312         cam_debug(LOG_SYS, "");
6313         if (ad->launching_mode == CAM_LAUNCHING_MODE_EXTERNAL) {
6314                 ad->camapp_handle->camera_mode = ad->exe_args->cam_mode;
6315                 if (CAM_CAMCORDER_MODE == ad->camapp_handle->camera_mode) {
6316                         if (ad->exe_args->resolution == CAM_RESOLUTION_QCIF) {
6317                                 ad->camapp_handle->recording_mode = CAM_RECORD_MMS;
6318                                 ad->camapp_handle->video_resolution = CAM_RESOLUTION_QCIF;
6319                                 ad->camapp_handle->reserved_setting_data.rear_recording_mode = CAM_RECORD_MMS;
6320                                 ad->camapp_handle->reserved_setting_data.rear_video_resolution = CAM_RESOLUTION_QCIF;
6321                                 ad->camapp_handle->reserved_setting_data.front_recording_mode = CAM_RECORD_SELF_MMS;
6322                                 ad->camapp_handle->reserved_setting_data.front_video_resolution = CAM_RESOLUTION_QCIF;
6323                                 ad->camapp_handle->fps = FPS_SLOW;
6324                                 if (ad->exe_args->size_limit <= 0) {
6325                                         ad->camapp_handle->size_limit = CAM_REC_MMS_MAX_SIZE;
6326                                 } else {
6327                                         ad->camapp_handle->size_limit = ad->exe_args->size_limit;
6328                                 }
6329                                 ad->camapp_handle->size_limit_type = CAM_MM_SIZE_LIMIT_TYPE_BYTE;
6330                         } else {
6331                                 ad->camapp_handle->recording_mode = CAM_RECORD_NORMAL;
6332                                 ad->camapp_handle->video_resolution = ad->exe_args->resolution;
6333                                 ad->camapp_handle->fps = FPS_DEFAULT;
6334                                 if (ad->exe_args->size_limit <= 0) {
6335                                         ad->camapp_handle->size_limit = CAM_REC_NORMAL_MAX_SIZE;
6336                                 } else {
6337                                         ad->camapp_handle->size_limit = ad->exe_args->size_limit;
6338                                 }
6339                                 ad->camapp_handle->size_limit_type = CAM_MM_SIZE_LIMIT_TYPE_BYTE;
6340                         }
6341                 } else {
6342                         ad->camapp_handle->shooting_mode = CAM_SINGLE_MODE;
6343                         ad->camapp_handle->default_capture_mode = CAM_CAPTURE_SINGLE;
6344                         if (ad->exe_args->width <= 0
6345                             || ad->exe_args->height <= 0) {
6346                                 ad->camapp_handle->photo_resolution = CAM_RESOLUTION_VGA;
6347                         } else {
6348                                 ad->camapp_handle->photo_resolution = CAM_RESOLUTION(ad->exe_args->width, ad->exe_args->height);
6349                         }
6350                 }
6351                 ad->camapp_handle->review = ad->exe_args->review;
6352         } else {
6353                 cam_debug(LOG_SYS, " camera launch mode is normal.");
6354                 return FALSE;
6355         }
6356
6357         cam_debug(LOG_SYS, " done");
6358
6359         return TRUE;
6360 }
6361
6362 Eina_Bool cam_app_focus_guide_create(void *data)
6363 {
6364         struct appdata *ad = (struct appdata *)data;
6365         cam_retv_if(ad == NULL, EINA_FALSE);
6366
6367         /*NOTE: TODO, perhaps there is issue:
6368                 while focus is animating, now delete focus_edje, what will occur?
6369         */
6370         cam_ui_effect_utils_stop_zoom_effect();
6371         DEL_EVAS_OBJECT(ad->focus_edje);
6372
6373         ad->focus_edje = cam_app_load_edj(ad->ug_base, CAM_UTILS_EDJ_NAME, "focus_image");
6374
6375         if (ad->focus_edje == NULL) {
6376                 cam_critical(LOG_UI, "focus_edje load failed ");
6377                 return EINA_FALSE;
6378         }
6379         evas_object_show(ad->focus_edje);
6380
6381         return EINA_TRUE;
6382 }
6383
6384 static Eina_Bool __focus_guide_hide_timer_cb(void *data)
6385 {
6386         struct appdata *ad = (struct appdata *)data;
6387         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
6388
6389         if (ad->focus_guide_hide_timer)
6390                 ad->focus_guide_hide_timer = NULL;
6391
6392         if (ad->focus_edje)
6393                 edje_object_signal_emit(_EDJ(ad->focus_edje), "focus,hide", "program");
6394
6395         return ECORE_CALLBACK_CANCEL;
6396 }
6397
6398 Eina_Bool cam_app_focus_guide_update(void *data)
6399 {
6400         DEBUG_TRACE();
6401 #ifndef CAMERA_MACHINE_I686
6402         struct appdata *ad = (struct appdata *)data;
6403         cam_retvm_if(ad == NULL, EINA_FALSE, "appdata is NULL");
6404         CamAppData *camapp = ad->camapp_handle;
6405         cam_retvm_if(ad->camapp_handle == NULL, EINA_FALSE, "camapp is NULL");
6406
6407         if (ad->focus_edje == NULL) {
6408                 return EINA_FALSE;
6409         }
6410
6411         REMOVE_TIMER(ad->focus_guide_hide_timer);
6412
6413         /*note: relocation the focus edje*/
6414         evas_object_resize(ad->focus_edje, ad->camera_focus_w, ad->camera_focus_h);
6415         evas_object_move(ad->focus_edje, ad->af_start_x, ad->af_start_y);
6416         evas_object_show(ad->focus_edje);
6417
6418         if (ad->imageviewer_ug) {
6419                 edje_object_signal_emit(_EDJ(ad->focus_edje), "focus,hide", "program");
6420                 return EINA_FALSE;
6421         }
6422
6423         if (ad->confirm_popup) {
6424                 edje_object_signal_emit(_EDJ(ad->focus_edje), "focus,hide", "program");
6425                 return EINA_FALSE;
6426         }
6427
6428         if (ad->is_processing) {
6429                 edje_object_signal_emit(_EDJ(ad->focus_edje), "focus,hide", "program");
6430                 return EINA_FALSE;
6431         }
6432
6433         if (ad->setting_ctxpopup
6434                 || (ad->tip_popup)
6435                 || (ad->toolbar_setting_popup)
6436                 || (ad->edit_shortcuts_popup)) {
6437                 cam_debug(LOG_UI, "do not need to update focus");
6438                 edje_object_signal_emit(_EDJ(ad->focus_edje), "focus,hide", "program");
6439                 return EINA_FALSE;
6440         }
6441
6442         if (camapp->camera_mode == CAM_CAMERA_MODE
6443                 && ad->mm_state == CAMERA_STATE_CAPTURING) {
6444                 return EINA_FALSE;
6445         }
6446
6447         if (camapp->camera_mode == CAM_CAMERA_MODE
6448                 && (ad->mm_state < CAMERA_STATE_PREVIEW || camapp->af_mode == CAM_FOCUS_FACE)) {
6449                 edje_object_signal_emit(_EDJ(ad->focus_edje), "focus,hide", "program");
6450                 return EINA_FALSE;
6451         } else {
6452                 if ((camapp->camera_mode == CAM_CAMCORDER_MODE)
6453                         && (camapp->recording_mode == CAM_RECORD_SLOW
6454                         || camapp->recording_mode == CAM_RECORD_FAST
6455                         || camapp->recording_mode == CAM_RECORD_SELF
6456                         || camapp->recording_mode == CAM_RECORD_SELF_MMS)) {
6457                         edje_object_signal_emit(_EDJ(ad->focus_edje), "focus,hide", "program");
6458                 } else {
6459                         char signame[30] = { '\0', };
6460                         const char *focus_state_name[4] = {
6461                                 "hide",
6462                                 "notready",
6463                                 "focused",
6464                                 "failed",
6465                         };
6466
6467                         snprintf(signame, sizeof(signame), "%s,%s", "focus", focus_state_name[camapp->focus_state]);
6468                         edje_object_signal_emit(_EDJ(ad->focus_edje), signame, "program");
6469                 }
6470
6471                 if ((camapp->focus_state == CAMERA_FOCUS_STATE_FOCUSED) || (camapp->focus_state == CAMERA_FOCUS_STATE_FAILED))
6472                         ad->focus_guide_hide_timer = ecore_timer_add(1.0, __focus_guide_hide_timer_cb, ad);
6473         }
6474 #endif
6475         return EINA_TRUE;
6476 }
6477
6478 static int cam_app_camera_state_manager(int previous, int current, gboolean by_asm)
6479 {
6480         struct appdata *ad = NULL;
6481         CamAppData *camapp = NULL;
6482
6483         cam_info(LOG_UI, "STATE_CHANGED : %d -> %d ", previous, current);
6484
6485         ad = (struct appdata *)cam_appdata_get();
6486         cam_retv_if(ad == NULL, FALSE);
6487
6488         camapp = ad->camapp_handle;
6489         cam_retv_if(camapp == NULL, FALSE);
6490
6491         ad->mm_state = current;
6492
6493         if (current == CAMERA_STATE_PREVIEW) {
6494                 if (previous == CAMERA_STATE_CAPTURING) {
6495                         CAM_TA_ACUM_ITEM_END("    capture stop to preview", 0);
6496                         CAM_TA_ACUM_ITEM_END("Total capture time", 0);
6497                         cam_debug(LOG_MM, "capture end, preview start");
6498                 }
6499         }
6500
6501         if (current == CAMERA_STATE_CAPTURING) {
6502                 if (previous == CAMERA_STATE_PREVIEW) {
6503                         cam_debug(LOG_MM, "capture start, preview end");
6504                         if ((camapp->shooting_mode == CAM_SELF_SINGLE_MODE
6505                                         && camapp->default_capture_mode == CAM_CAPTURE_SINGLE)){
6506                                 cam_app_create_screennail_and_start_animation(ad);
6507                         }
6508                 }
6509         }
6510
6511         return 1;
6512 }
6513
6514 static int cam_app_recorder_state_manager(int previous, int current, gboolean by_asm)
6515 {
6516         struct appdata *ad = NULL;
6517         CamAppData *camapp = NULL;
6518
6519         cam_info(LOG_UI, "STATE_CHANGED : %d -> %d ", previous, current);
6520
6521         ad = (struct appdata *)cam_appdata_get();
6522         cam_retv_if(ad == NULL, FALSE);
6523
6524         camapp = ad->camapp_handle;
6525         cam_retv_if(camapp == NULL, FALSE);
6526
6527         ad->mm_state = current;
6528
6529         if (((previous == RECORDER_STATE_RECORDING)
6530             && (current != RECORDER_STATE_PAUSED))
6531             ||((previous == RECORDER_STATE_PAUSED)
6532             && (current != RECORDER_STATE_RECORDING))) {/*finished recording*/
6533
6534                 cam_info(LOG_UI, "Set gamma NORMAL");
6535
6536                 if (camapp->filename) {
6537                         free(camapp->filename);
6538                         camapp->filename = NULL;
6539                 }
6540
6541                 if (cam_mm_get_filename(&camapp->filename, 0) == FALSE) { /*file size not used,so set to 0*/
6542                         return FALSE;
6543                 }
6544                 cam_info(LOG_UI, "Recorded file name [%s] ", camapp->filename);
6545
6546 /*note: shooting mode change*/
6547 #if 1
6548                 /* change to camera mode*/
6549                 /*
6550                 *       TODO: if for any reason, not run here, there will be caused now now recording, but in record mode
6551                 *       So: I suggest while click capture button: judge now state and whether recording.
6552                 */
6553                 if(ad->launching_mode == CAM_LAUNCHING_MODE_NORMAL) {
6554                         if (ad->ug_state != CAM_UG_PAUSE_STATE) {/*if now is pause state, so do not set mode, just set while resume*/
6555                                 if (cam_app_mode_change(ad, CAM_CAMERA_MODE) == FALSE)
6556                                         return FALSE;;
6557
6558                         }
6559                 }
6560 #endif
6561         /*TODO: I think state manager callback is called in thread, so we could do data logic here,
6562                         and request ui operation to ecore_pipe*/
6563                 cam_utils_request_main_pipe_handler(ad, NULL, CAM_MAIN_PIPE_OP_TYPE_VIDEO_CAPTURE_HANDLE);
6564
6565         }
6566         return TRUE;
6567 }
6568
6569 static Eina_Bool __cam_ug_destroy(void *data)
6570 {
6571         struct appdata *ad = (struct appdata *)data;
6572         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
6573
6574         ug_destroy_me(ad->camera_ug);
6575
6576         return ECORE_CALLBACK_CANCEL;
6577 }
6578
6579 gboolean cam_app_exit(void *data)
6580 {
6581         struct appdata *ad = (struct appdata *)data;
6582         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
6583
6584         ecore_idler_add(__cam_ug_destroy, ad);
6585
6586         return TRUE;
6587 }
6588
6589 static void cam_mmc_state_change_cb(keynode_t *key, void *data)
6590 {
6591         struct appdata *ad = (struct appdata *)data;
6592         CamAppData *camapp = NULL;
6593         int mmc_state = vconf_keynode_get_int(key);
6594
6595         cam_retm_if(ad == NULL, "appdata is NULL");
6596         camapp = ad->camapp_handle;
6597         cam_retm_if(camapp == NULL, "camapp_handle is NULL");
6598
6599         cam_debug(LOG_SYS, " start");
6600
6601         if (mmc_state == VCONFKEY_SYSMAN_MMC_REMOVED
6602             && camapp->storage == CAM_STORAGE_EXTERNAL) {
6603
6604                 GValue value = { 0 };
6605                 int mm_state = cam_mm_get_state();
6606
6607                 if (mm_state == CAMERA_STATE_CAPTURING
6608                     && (camapp->shooting_mode == CAM_SINGLE_MODE
6609                         && camapp->default_capture_mode == CAM_CAPTURE_BURST)
6610                     &&camapp->camera_mode == CAM_CAMERA_MODE) {
6611                         if (camapp->continuous_shot_data) {
6612                                 if (camapp->continuous_shot_data->error != NULL) {
6613                                         cam_debug(LOG_SYS, " error [%s,%d]", camapp->continuous_shot_data->error->message, camapp->continuous_shot_data->error->code);
6614                                         g_error_free(camapp->continuous_shot_data->error);
6615                                         camapp->continuous_shot_data->error = NULL;
6616                                 }
6617
6618                                 camapp->continuous_shot_data->error = cam_error_new_literal(CAM_CONTI_SHOT_ERROR_MMC_REMOVED, dgettext(PACKAGE, "IDS_CAM_POP_MEMORY_CARD_REMOVED"));
6619                         } else {
6620                                 cam_debug(LOG_SYS, " continuous_shot_data is NULL");
6621                         }
6622                 } else {
6623                         if ((mm_state == RECORDER_STATE_RECORDING
6624                             || mm_state == RECORDER_STATE_PAUSED)
6625                             &&camapp->camera_mode == CAM_CAMCORDER_MODE) {
6626                                 cam_video_record_cancel(ad);
6627                                 cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_REMOVE_MMC_RECORDING"), cam_app_popup_response_cb);
6628                         }
6629 #ifndef CAMERA_MACHINE_I686
6630                         else if (mm_state != CAMERA_STATE_CAPTURING
6631                                  && camapp->camera_mode == CAM_CAMERA_MODE) {
6632                                 if (cam_app_check_blocking_popup()) {
6633                                         cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_MEMORY_CARD_REMOVED"), cam_app_popup_response_cb);
6634                                 }
6635                         }
6636 #endif
6637                 }
6638
6639                 CAM_GVALUE_SET_INT(value, CAM_STORAGE_INTERNAL);
6640                 cam_handle_value_set(ad, PROP_STORAGE, &value);
6641
6642                 cam_info(LOG_UI, "MMC card is removed");
6643         }
6644
6645         cam_toolbar_setting_popup_update(ad);
6646         indicator_update_storage(ad);
6647         return;
6648 }
6649
6650 #ifdef CAMAPP_SIG_HANDLING
6651 /**
6652 * This function registers a user space signal handler for the signal SIGSEGV (Signal #11)
6653 *
6654 * @return               nothing
6655 */
6656 static void cam_app_register_sigsegv(void)
6657 {
6658         debug_fenter(LOG_SYS);
6659
6660         /* cam_app_act.sa_flags = SA_SIGINFO | SA_NOCLDSTOP; */
6661         cam_app_act.sa_flags = SA_SIGINFO;
6662         cam_app_act.sa_handler = (void *)cam_app_sigsegv_handler;
6663         sigemptyset(&cam_app_act.sa_mask);
6664
6665 #ifdef ENABLE_CHECK_CAM_STATUS
6666         sigaction(SIGALRM, &cam_app_act, &cam_app_act_old);     /* register an action with a previous action */
6667 #endif
6668         sigaction(SIGABRT, &cam_app_act, &cam_app_act_old);
6669         sigaction(SIGSEGV, &cam_app_act, &cam_app_act_old);
6670         sigaction(SIGILL, &cam_app_act, &cam_app_act_old);
6671
6672         debug_fleave(LOG_SYS);
6673 }
6674
6675 static void
6676 cam_app_sigsegv_handler(int signal_no, siginfo_t *info, void *context)
6677 {
6678         debug_fenter(LOG_SYS);
6679
6680         cam_debug(LOG_SYS, "signal_no = %d", signal_no);
6681
6682         if (signal_no == SIGALRM) {     /* if alarm, check the camera status. */
6683 #ifdef ENABLE_CHECK_CAM_STATUS
6684                 cam_app_check_status();
6685                 alarm(CAM_CHECK_STATUS_INTERVAL_TIME);
6686 #endif
6687                 return;
6688         } else {
6689                 sigaction(signal_no, &cam_app_act_old, NULL);   /*  register the previous action */
6690                 raise(signal_no);
6691         }
6692
6693         debug_fleave(LOG_SYS);
6694 }
6695
6696 #endif
6697
6698 #ifdef ENABLE_CHECK_CAM_STATUS
6699
6700 static void cam_app_check_status()
6701 {
6702         cam_debug(LOG_SYS, "check status");
6703 }
6704 #endif                          /* ENABLE_CHECK_CAM_STATUS */
6705
6706 void cam_app_toggle_indicator(void *data, gboolean hide)
6707 {
6708         struct appdata *ad = (struct appdata *)data;
6709         cam_retm_if(ad == NULL, "appdata is NULL");
6710
6711         indicator_toggle(ad, hide);
6712
6713         return;
6714 }
6715
6716 void cam_app_toggle_toolbar(void *data, gboolean hide)
6717 {
6718         struct appdata *ad = (struct appdata *)data;
6719         cam_retm_if(ad == NULL, "appdata is NULL");
6720
6721         if (hide) {
6722                 hide_toolbar_edje(ad);
6723         } else {
6724                 show_toolbar_edje(ad);
6725         }
6726
6727         return;
6728 }
6729
6730 static void
6731 cam_app_reset_settings_launch_cb(void *data, Evas_Object *obj, void *event_info)
6732 {
6733         Evas_Object *notify = (Evas_Object *)data;
6734         GValue i_value = { 0, };
6735         GValue b_value = { 0, };
6736         struct appdata *ad = (struct appdata *)cam_appdata_get();
6737         CamAppData *camapp = NULL;
6738
6739         cam_debug(LOG_CAM, "!!!!!!!!!cam_app_reset_settings_launch_cb");
6740
6741         cam_retm_if(ad == NULL, " appdata is NULL");
6742         camapp = ad->camapp_handle;
6743         cam_retm_if(camapp == NULL, " cam_handle is NULL");
6744
6745         cam_popup_remove(notify);
6746         hide_toolbar_edje(ad);
6747
6748         cam_app_preview_stop();
6749
6750         g_value_init(&i_value, G_TYPE_INT);
6751         g_value_init(&b_value, G_TYPE_BOOLEAN);
6752
6753         /* auto focus */
6754
6755         g_value_set_int(&i_value, AF_DEFAULT);
6756         cam_handle_value_set(ad, PROP_AF_MODE, &i_value);
6757
6758         /* Timer */
6759         g_value_set_int(&i_value, TIMER_DEFAULT);
6760         cam_handle_value_set(ad, PROP_TIMER, &i_value);
6761
6762         /* white balance */
6763         g_value_set_int(&i_value, WB_DEFAULT);
6764         cam_handle_value_set(ad, PROP_WB, &i_value);
6765
6766         /* Effect */
6767         g_value_set_int(&i_value, EFFECT_DEFAULT);
6768         cam_handle_value_set(ad, PROP_EFFECT, &i_value);
6769
6770         /* ISO */
6771         g_value_set_int(&i_value, ISO_DEFAULT);
6772         cam_handle_value_set(ad, PROP_ISO, &i_value);
6773
6774         /* Metering */
6775         g_value_set_int(&i_value, AE_DEFAULT);
6776         cam_handle_value_set(ad, PROP_METERING, &i_value);
6777
6778         /* Anti-shake */
6779         g_value_set_int(&i_value, AHS_DEFAULT);
6780         cam_handle_value_set(ad, PROP_AHS, &i_value);
6781
6782         /* wild dynamic range */
6783         g_value_set_int(&i_value, WDR_DEFAULT);
6784         cam_handle_value_set(ad, PROP_WDR, &i_value);
6785
6786         /* Image quality */
6787         g_value_set_int(&i_value, QUALITY_DEFAULT);
6788         cam_handle_value_set(ad, PROP_IMAGE_QUALITY, &i_value);
6789
6790         /* Video quality */
6791         g_value_set_int(&i_value, QUALITY_DEFAULT);
6792         cam_handle_value_set(ad, PROP_VIDEO_QUALITY, &i_value);
6793
6794         /* Guide Line */
6795         g_value_set_boolean(&b_value, FALSE);
6796         cam_handle_value_set(ad, PROP_GUIDELINE, &b_value);
6797         settings_guideline_refresh(ad);
6798         /* Review */
6799         g_value_set_boolean(&b_value, FALSE);
6800         cam_handle_value_set(ad, PROP_REVIEW, &b_value);
6801
6802         /* GPS Connect */
6803         g_value_set_boolean(&b_value, FALSE);
6804         cam_handle_value_set(ad, PROP_GPS, &b_value);
6805
6806         /* shutter sound */
6807         g_value_set_int(&i_value, SHUTTER_SOUND_DEFAULT);
6808         cam_handle_value_set(ad, PROP_SHUTTER_SOUND, &i_value);
6809
6810         /* audio recording */
6811         g_value_set_boolean(&b_value, TRUE);
6812         cam_handle_value_set(ad, PROP_AUDIO_REC, &b_value);
6813
6814         /* storage */
6815         g_value_set_int(&i_value, STORAGE_DEFAULT);
6816         cam_handle_value_set(ad, PROP_STORAGE, &i_value);
6817
6818         /* brightness */
6819         g_value_set_int(&i_value, BRIGHTNESS_DEFAULT);
6820         cam_handle_value_set(ad, PROP_BRIGHTNESS, &i_value);
6821
6822         /* Resolution */
6823         g_value_set_int(&i_value, IMAGE_RESOLUTION_DEFAULT);
6824         cam_handle_value_set(ad, PROP_PHOTO_RESOLUTION, &i_value);
6825
6826         g_value_set_int(&i_value, REC_RESOLUTION_DEFAULT);
6827         cam_handle_value_set(ad, PROP_VIDEO_RESOLUTION, &i_value);
6828
6829         if (ad->indicator_edje) {
6830                 /* delete indicator */
6831                 evas_object_hide(ad->indicator_edje);
6832                 cam_indicator_destory(ad);
6833         }
6834         cam_indicator_create(ad);
6835
6836         show_toolbar_edje(ad);
6837
6838         if (!cam_app_preview_start(ad)) {
6839                 cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA"), cam_app_timeout_notice_response_cb);
6840         }
6841
6842 }
6843
6844 void cam_app_reset_settings(void *data)
6845 {
6846         struct appdata *ad = (struct appdata *)data;
6847         cam_retm_if(ad == NULL, "appdata is NULL");
6848         cam_popup_question_add(ad->ug_base,
6849                                dgettext(PACKAGE, "IDS_CAM_POP_RESET_CAMERA_SETTINGS"),
6850                                dgettext("sys_string", "IDS_COM_SK_YES"),
6851                                cam_app_reset_settings_launch_cb,
6852                                dgettext("sys_string", "IDS_COM_SK_NO"),
6853                                _popup_cancel_cb);
6854
6855 }
6856
6857 static gboolean __cam_toolbar_new_thumbnail_create(Evas_Object **obj,
6858                                                         struct appdata *ad,
6859                                                         Evas_Coord *thumbnail_x,
6860                                                         Evas_Coord *thumbnail_y,
6861                                                         Evas_Coord *thumbnail_w,
6862                                                         Evas_Coord *thumbnail_h)
6863 {
6864         cam_retv_if(ad == NULL, FALSE);
6865         CamAppData *camapp = ad->camapp_handle;
6866         cam_retv_if(camapp == NULL, FALSE);
6867         cam_retv_if(obj == NULL, FALSE);
6868         cam_retv_if(ad->evas == NULL, FALSE);
6869         cam_retv_if(ad->toolbar.quickview_item.edje == NULL, FALSE);
6870
6871         if(camapp->thumbnail_name == NULL) {
6872                 *obj = NULL;
6873                 return TRUE;
6874         }
6875         Evas_Object *new_thumbnail_img = elm_bg_add(ad->toolbar.quickview_item.edje);
6876         Evas_Coord x = 0, y = 0, w = 0, h = 0;
6877         Evas_Object *layout = NULL;
6878         Evas_Object *thumbnail_area = NULL;
6879
6880         cam_retv_if(new_thumbnail_img == NULL, FALSE);
6881         elm_bg_file_set(new_thumbnail_img, camapp->thumbnail_name, NULL);
6882
6883         layout = elm_layout_edje_get(ad->toolbar.quickview_item.edje);
6884         thumbnail_area = (Evas_Object *) edje_object_part_object_get(layout,"thumbnail_area");
6885         cam_retv_if(thumbnail_area == NULL, FALSE);
6886         evas_object_geometry_get(thumbnail_area, &x, &y, &w, &h);
6887         *thumbnail_x = x;
6888         *thumbnail_y = y;
6889         *thumbnail_w = w;
6890         *thumbnail_h = h;
6891
6892         evas_object_resize(new_thumbnail_img, 0, 0);
6893         evas_object_move(new_thumbnail_img, x, y);
6894         evas_object_show(new_thumbnail_img);
6895         *obj = new_thumbnail_img;
6896         return TRUE;
6897 }
6898
6899 static gboolean __filter_cam_app_pipe_handler(void *data, gint pipe_type)
6900 {
6901         struct appdata *ad = (struct appdata *)data;
6902         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
6903         if (ad->ug_state == CAM_UG_TERMINATE_STATE
6904                         || ad->ug_state == CAM_UG_PAUSE_STATE) {
6905                 switch (pipe_type) {
6906                 case CAM_MAIN_PIPE_OP_TYPE_BEST_SHOT_IMAGE_HANDLE:
6907                 case CAM_MAIN_PIPE_OP_TYPE_VIDEO_CAPTURE_HANDLE:
6908                         return FALSE;
6909                 default:
6910                         break;
6911                 }
6912                 return TRUE;
6913         }
6914         return FALSE;
6915 }
6916
6917 static void cam_app_pipe_handler(void *data, void *buffer, unsigned int nbyte)
6918 {
6919         struct appdata *ad = (struct appdata *)data;
6920         cam_retm_if(ad == NULL, "appdata is NULL");
6921
6922         /* Caution */
6923         /* DO NOT free buffer in here */
6924         /* buffer is freed by ecore */
6925
6926         if (buffer) {
6927                 Ecore_Pipe_Data_Info * pipe_info = (Ecore_Pipe_Data_Info *)buffer;
6928                 int main_pipe_type = pipe_info->cmd;
6929                 DEBUG_TRACE("main_pipe_type %d", main_pipe_type);
6930
6931                 if (__filter_cam_app_pipe_handler(ad, main_pipe_type) == TRUE) {
6932                         return;
6933                 }
6934
6935                 switch (main_pipe_type) {
6936                 case CAM_MAIN_PIPE_OP_TYPE_UPDATE_THUMBNAIL:
6937                         {
6938                                 Evas_Object *new_thumbnail_image = NULL;
6939                                 Evas_Coord x = 0, y = 0, w = 0, h = 0;
6940                                 gboolean ret = FALSE;
6941                                 ret = __cam_toolbar_new_thumbnail_create(&new_thumbnail_image, ad, &x, &y, &w, &h);
6942                                 if (ret == FALSE || !new_thumbnail_image) {
6943                                         if (!new_thumbnail_image && ret) {
6944                                                 DEL_EVAS_OBJECT(ad->toolbar.quickview_item.thumbnail_image);
6945                                         }
6946                                         return;
6947                                 }
6948                                 cam_ui_effect_utils_set_thumbnail_effect(new_thumbnail_image,
6949                                                                         x,
6950                                                                         y,
6951                                                                         w,
6952                                                                         h,
6953                                                                         CAM_THUMBNAIL_ANTIMATION_EFFECT_DURATION);
6954                         }
6955                         break;
6956                 case CAM_MAIN_PIPE_OP_TYPE_UPDATE_THUMBNAIL_NO_ANI:
6957                         {
6958                                 toolbar_update_quickview_thumbnail_no_animation(ad);
6959                         }
6960                         break;
6961                 case CAM_MAIN_PIPE_OP_TYPE_ROTATE_ANIMATOR:
6962                         {
6963                                 cam_ui_rotate_utils_rotate_start(ad, CAM_ROTATE_ICONS_ANTIMATION_DURATION);
6964                         }
6965                         break;
6966                 case CAM_MAIN_PIPE_OP_TYPE_SHUTTER_ANIMATION:
6967                         {
6968                                 cam_app_create_start_animation(ad);
6969                         }
6970                         break;
6971                 case CAM_MAIN_PIPE_OP_TYPE_BURST_SHOT_UPDATE_PROGRESS:
6972                         {
6973                                 cam_continuous_shot_update_progress_value(ad);
6974                         }
6975                         break;
6976                 case CAM_MAIN_PIPE_OP_TYPE_BURST_SHOT_DISPLAY_POPUP:
6977                         {
6978                                 cam_app_destroy_progressbar(ad);
6979                                 cam_app_create_burst_popup(ad);
6980                         }
6981                         break;
6982                 case CAM_MAIN_PIPE_OP_TYPE_BEST_SHOT_IMAGE_HANDLE:
6983                         {
6984                                 cam_image_capture_handle(ad);
6985                         }
6986                         break;
6987                 case CAM_MAIN_PIPE_OP_TYPE_UPDATE_VIEW:
6988                         {
6989                                 CamAppData *camapp = ad->camapp_handle;
6990                                 cam_retm_if(camapp == NULL, "camapp is NULL");
6991
6992                                 camapp->update_view_cb(ad);
6993                         }
6994                         break;
6995                 case CAM_MAIN_PIPE_OP_TYPE_ERROR_POPUP:
6996                         {
6997                                 cam_create_error_popup(ad);
6998                         }
6999                         break;
7000                 case CAM_MAIN_PIPE_OP_TYPE_VIDEO_CAPTURE_HANDLE:
7001                         {
7002                                 cam_video_capture_handle(ad);
7003                         }
7004                         break;
7005                 case CAM_MAIN_PIPE_OP_TYPE_RUN_IMAGE_VIEWER:
7006                         {
7007                                 CamAppData *camapp = ad->camapp_handle;
7008                                 cam_retm_if(camapp == NULL, "camapp is NULL");
7009                                 cam_retm_if(camapp->filename == NULL, "camapp is NULL");
7010                                 if (!cam_app_run_image_viewer_ug(ad, camapp->filename, FALSE)) {
7011                                         return;
7012                                 }
7013                         }
7014                         break;
7015                 default:
7016                         break;
7017                 }
7018                 /*note: free memory*/
7019                 if (pipe_info->data) {
7020                         free(pipe_info->data);
7021                         pipe_info = NULL;
7022                 }
7023         }
7024
7025         return;
7026 }
7027
7028 void cam_focus_edje_rotate(void *data)
7029 {
7030         struct appdata *ad = (struct appdata *)data;
7031         cam_retm_if(ad == NULL, "appdata is NULL");
7032
7033         DEL_EVAS_OBJECT(ad->focus_edje);
7034         ad->focus_edje = cam_app_load_edj(ad->ug_base, CAM_UTILS_EDJ_NAME, "focus_image");
7035
7036         cam_retm_if(ad->focus_edje == NULL, "focus_edje load failed");
7037
7038         evas_object_resize(ad->focus_edje, ad->camera_focus_w, ad->camera_focus_h);
7039         evas_object_move(ad->focus_edje, ad->af_start_x, ad->af_start_y);
7040         evas_object_show(ad->focus_edje);
7041
7042         cam_app_draw_af_box(ad);
7043         cam_app_focus_guide_update(ad);
7044 }
7045
7046 Eina_Bool cam_screen_rotate(void *data)
7047 {
7048         struct appdata *ad = (struct appdata *)data;
7049         cam_retvm_if(ad == NULL, -1, "appdata is NULL");
7050
7051     if (ad->imageviewer_ug) {
7052                 ad->is_rotating = FALSE;
7053                 return FALSE;
7054     }
7055
7056         elm_win_rotation_with_resize_set(ad->win_main, ad->angle);
7057
7058         if (ad->focus_edje)
7059                 cam_focus_edje_rotate(ad);
7060
7061         if (ad->timer_icon_edje)
7062                 cam_app_timer_icon_rotate(ad);
7063
7064         if (ad->toolbar_edje)
7065                 cam_toolbar_rotate(ad);
7066
7067         if (ad->recording_edje)
7068                 cam_recording_rotate(ad);
7069
7070         if (ad->indicator_edje)
7071                 cam_indicator_rotate(ad);
7072
7073         if (ad->tip_popup)
7074                 cam_tip_popup_rotate(ad);
7075
7076         if (ad->pinch_edje)
7077                 cam_zoom_create_pinch_edje(ad);
7078
7079         if (ad->progress_popup != NULL)
7080                 cam_popup_rotate(ad);
7081
7082         cam_retvm_if(ad->camapp_handle == NULL, -1, "camapp_handle is NULL");
7083
7084         toolbar_shot_guide_popup_create(ad, ad->camapp_handle->shooting_mode);
7085
7086         if (ad->ev_edje) {
7087                 unload_ev_edje(ad);
7088                 load_ev_edje(ad);
7089         }
7090
7091         if (ad->zoom_edje) {
7092                 unload_zoom_edje(ad);
7093                 load_zoom_edje(ad);
7094         }
7095
7096         if (ad->guideline_edje)
7097                 settings_guideline_refresh(ad);
7098
7099         /*update thumbnail*/
7100         toolbar_update_quickview_thumbnail_no_animation(ad);
7101         /* rotate menu */
7102         DEBUG_TRACE("ad->displayed_setting_popup = %d", ad->displayed_setting_popup);
7103         DEBUG_TRACE("ad->show_edit_shortcuts_popup_after_rotate = %d", ad->show_edit_shortcuts_popup_after_rotate);
7104         DEBUG_TRACE("ad->show_setting_popup_after_rotate = %d", ad->show_setting_popup_after_rotate);
7105         if ((ad->displayed_setting_popup != DISPLAY_NONE_POPUP)
7106                 || (ad->show_edit_shortcuts_popup_after_rotate == TRUE)
7107                 || (ad->show_setting_popup_after_rotate == TRUE)) {
7108                 /*ecore_idler_add(cam_show_setting_menu, ad);*/
7109                 /*note: use timer to delay creating the popup*/
7110                 ecore_timer_add(0.1, cam_show_setting_menu, ad);
7111         } else {
7112                 ad->is_rotating = FALSE;
7113         }
7114
7115         if (ad->confirm_popup)
7116                 evas_object_raise(ad->confirm_popup);
7117
7118         return ECORE_CALLBACK_CANCEL;
7119 }
7120
7121 static Ecore_Idler *rotate_delay_idler = NULL;
7122 Eina_Bool cam_app_screen_rotate_idler(void *data)
7123 {
7124         if (rotate_delay_idler) {
7125                 ecore_idler_del(rotate_delay_idler);
7126                 rotate_delay_idler = NULL;
7127         }
7128         struct appdata *ad = (struct appdata *)data;
7129         cam_retv_if(ad == NULL, ECORE_CALLBACK_CANCEL);
7130         if (ad->ug_state == CAM_UG_TERMINATE_STATE
7131                 || ad->ug_state == CAM_UG_PAUSE_STATE) {
7132                 ad->is_rotating = FALSE;
7133                 return ECORE_CALLBACK_CANCEL;
7134         }
7135         cam_screen_rotate(ad);
7136         return ECORE_CALLBACK_CANCEL;
7137 }
7138
7139 void cam_app_screen_rotate(void *data)
7140 {
7141         struct appdata *ad = (struct appdata *)data;
7142         cam_ret_if(ad == NULL);
7143         if (ad->ug_state == CAM_UG_TERMINATE_STATE
7144                 || ad->ug_state == CAM_UG_PAUSE_STATE) {
7145                 ad->is_rotating = FALSE;
7146                 return;
7147         }
7148         CamAppData *cam_handle = ad->camapp_handle;
7149         cam_ret_if(cam_handle == NULL);
7150         DEBUG_TRACE("");
7151
7152         if (ad->toolbar_edje) {
7153                 rotate_delay_idler = ecore_idler_add(cam_app_screen_rotate_idler, data);
7154         }
7155 }
7156
7157 gboolean cam_app_get_photo_resolution(int *width, int *height)
7158 {
7159         cam_retv_if(width == NULL || height == NULL, FALSE);
7160
7161         struct appdata *ad = (struct appdata *)cam_appdata_get();
7162         cam_retvm_if(ad == NULL, FALSE, "ad is NULL");
7163         CamAppData *camapp = ad->camapp_handle;
7164         cam_retvm_if(ad->camapp_handle == NULL, FALSE, "camapp_handle is NULL");
7165
7166         *width = CAM_RESOLUTION_W(camapp->photo_resolution);
7167         *height = CAM_RESOLUTION_H(camapp->photo_resolution);
7168
7169         return TRUE;
7170 }
7171
7172 gboolean cam_app_reset_resolution(void *data, int width, int height, gboolean force_set)
7173 {
7174         struct appdata *ad = (struct appdata *)data;
7175         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
7176         CamAppData *camapp = NULL;
7177         camapp = ad->camapp_handle;
7178         cam_retvm_if(camapp == NULL, FALSE, "camapp is NULL");
7179
7180         gboolean ret = TRUE;
7181         int state = 0;
7182
7183         cam_debug(LOG_MM, " reset resolution = [%d x %d], need_change_state = [%d]",
7184                                                   width, height, force_set);
7185
7186         if (camapp->camera_mode == CAM_CAMERA_MODE) {
7187                 int cur_img_w, cur_img_h = 0;
7188                 int recommanded_cur_w, recommanded_cur_h = 0;
7189                 int recommanded_new_w, recommanded_new_h = 0;
7190
7191                 ret &= cam_mm_get_image_size(&cur_img_w, &cur_img_h);
7192
7193                 if ((cur_img_w == 1392) && (cur_img_h == 1392)) {
7194                         recommanded_cur_w = 1392;
7195                         recommanded_cur_h = 1392;
7196                 } else
7197                         cam_mm_get_recommanded_preview_size(&recommanded_cur_w, &recommanded_cur_h);
7198
7199                 ret &= cam_mm_set_image_size(width, height);
7200
7201                 if ((width == 1392) && (height == 1392)) {
7202                         recommanded_new_w = 1392;
7203                         recommanded_new_h = 1392;
7204                 } else
7205                         cam_mm_get_recommanded_preview_size(&recommanded_new_w, &recommanded_new_h);
7206
7207                 DEBUG_TRACE("cam_mm_get_recommanded_preview_size CUR[%d %d] NEW[%d %d]",
7208                                                 recommanded_cur_w, recommanded_cur_h, recommanded_new_w, recommanded_new_h);
7209
7210                 if ((recommanded_cur_w != recommanded_new_w)
7211                         ||(recommanded_cur_h != recommanded_new_h)
7212                         ||(force_set)) {
7213
7214                         state = cam_mm_get_cam_state();
7215
7216                         if (state == CAMERA_STATE_PREVIEW) {
7217                                 ret &= cam_app_preview_stop();
7218                                 ret &= cam_mm_set_video_size(recommanded_new_w, recommanded_new_h);
7219                                 ret &= cam_app_preview_start(ad);
7220                         } else {
7221                                 ret &= cam_mm_set_video_size(recommanded_new_w, recommanded_new_h);
7222                         }
7223                 }
7224         } else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
7225                 int cur_video_w, cur_video_h = 0;
7226                 cam_mm_get_video_size(&cur_video_w, &cur_video_h);
7227
7228                 if (((cur_video_w != width) || (cur_video_h != height)) && (force_set)) {
7229                         state = cam_mm_get_rec_state();
7230
7231                         if (state == RECORDER_STATE_READY) {
7232                                 ret &= cam_app_preview_stop();
7233                                 ret &= cam_mm_set_video_size(width, height);
7234                                 ret &= cam_app_preview_start(ad);
7235                         } else {
7236                                 ret &= cam_mm_set_video_size(width, height);
7237                         }
7238                 } else {
7239                         ret &= cam_mm_set_video_size(width, height);
7240                 }
7241         } else {
7242                 return FALSE;
7243         }
7244         return ret;
7245 }
7246
7247 int cam_app_get_aenc_bitrate(void *data)
7248 {
7249         struct appdata *ad = (struct appdata *)data;
7250         CamAppData *camapp = NULL;
7251         int bitrate = 0;
7252
7253         cam_retvm_if(ad == NULL, 0, "appdata is NULL");
7254         camapp = ad->camapp_handle;
7255         cam_retvm_if(camapp == NULL, 0, "camapp is NULL");
7256
7257         if ((camapp->recording_mode == CAM_RECORD_MMS) ||(camapp->recording_mode == CAM_RECORD_SELF_MMS)) {
7258                 bitrate = CAM_AUDIO_BITRATE_MMS;
7259         } else {
7260                 bitrate = CAM_AUDIO_BITRATE_NORMAL;
7261         }
7262
7263         return bitrate;
7264 }
7265
7266 int cam_app_get_venc_bitrate(void *data, int quality)
7267 {
7268         struct appdata *ad = (struct appdata *)data;
7269         CamAppData *camapp = NULL;
7270         int return_val = 0;
7271
7272         cam_retvm_if(ad == NULL, 0, "appdata is NULL");
7273         camapp = ad->camapp_handle;
7274         cam_retvm_if(camapp == NULL, 0, "camapp is NULL");
7275
7276         if ((camapp->recording_mode == CAM_RECORD_MMS) ||(camapp->recording_mode == CAM_RECORD_SELF_MMS)) {
7277                 switch (quality) {
7278                 case CAM_QUALITY_HIGH:
7279                 case CAM_QUALITY_BEST:
7280                         return_val = 64000;
7281                         break;
7282
7283                 case CAM_QUALITY_MEDIUM:
7284                         return_val = 32000;
7285                         break;
7286
7287                 case CAM_QUALITY_LOW:
7288                         return_val = 16000;
7289                         break;
7290
7291                 default:
7292                         cam_critical(LOG_MM, "INVALID QUAILTY");
7293                         break;
7294                 }
7295         } else if ((camapp->recording_mode == CAM_RECORD_SLOW) ||(camapp->recording_mode == CAM_RECORD_FAST)) {
7296                 switch (quality) {
7297                 case CAM_QUALITY_HIGH:
7298                 case CAM_QUALITY_BEST:
7299                         return_val = 10000000;
7300                         break;
7301
7302                 case CAM_QUALITY_MEDIUM:
7303                         return_val = 4000000;
7304                         break;
7305
7306                 case CAM_QUALITY_LOW:
7307                         return_val = 2000000;
7308                         break;
7309
7310                 default:
7311                         cam_critical(LOG_MM, "INVALID QUAILTY");
7312                         break;
7313                 }
7314         } else {
7315                 switch (camapp->video_resolution) {
7316                 case CAM_RESOLUTION_FULLHD:
7317                         {
7318                                 switch (quality) {
7319                                 case CAM_QUALITY_HIGH:
7320                                 case CAM_QUALITY_BEST:
7321                                         return_val = 8000000;
7322                                         break;
7323
7324                                 case CAM_QUALITY_MEDIUM:
7325                                         return_val = 4000000;
7326                                         break;
7327
7328                                 case CAM_QUALITY_LOW:
7329                                         return_val = 2000000;
7330                                         break;
7331
7332                                 default:
7333                                         cam_critical(LOG_MM, "INVALID QUAILTY");
7334                                         break;
7335                                 }
7336                         }
7337                         break;
7338                 case CAM_RESOLUTION_HD:
7339                         {
7340                                 switch (quality) {
7341                                 case CAM_QUALITY_HIGH:
7342                                 case CAM_QUALITY_BEST:
7343                                         return_val = 10000000;
7344                                         break;
7345
7346                                 case CAM_QUALITY_MEDIUM:
7347                                         return_val = 4000000;
7348                                         break;
7349
7350                                 case CAM_QUALITY_LOW:
7351                                         return_val = 2000000;
7352                                         break;
7353
7354                                 default:
7355                                         cam_critical(LOG_MM, "INVALID QUAILTY");
7356                                         break;
7357                                 }
7358                         }
7359                         break;
7360
7361                 case CAM_RESOLUTION_WVGA:
7362                 case CAM_RESOLUTION_WVGA2:
7363                         {
7364                                 switch (quality) {
7365                                 case CAM_QUALITY_HIGH:
7366                                 case CAM_QUALITY_BEST:
7367                                         return_val = 4000000;
7368                                         break;
7369
7370                                 case CAM_QUALITY_MEDIUM:
7371                                         return_val = 2000000;
7372                                         break;
7373
7374                                 case CAM_QUALITY_LOW:
7375                                         return_val = 1000000;
7376                                         break;
7377
7378                                 default:
7379                                         cam_critical(LOG_MM, "INVALID QUAILTY");
7380                                         break;
7381                                 }
7382                         }
7383                         break;
7384
7385                 case CAM_RESOLUTION_VGA:
7386
7387                         {
7388                                 switch (quality) {
7389                                 case CAM_QUALITY_HIGH:
7390                                 case CAM_QUALITY_BEST:
7391                                         return_val = 3000000;
7392                                         break;
7393
7394                                 case CAM_QUALITY_MEDIUM:
7395                                         return_val = 1500000;
7396                                         break;
7397
7398                                 case CAM_QUALITY_LOW:
7399                                         return_val = 500000;
7400                                         break;
7401
7402                                 default:
7403                                         cam_critical(LOG_MM, "INVALID QUAILTY");
7404                                         break;
7405                                 }
7406                         }
7407                         break;
7408
7409                 case CAM_RESOLUTION_WQVGA:
7410                         {
7411                                 switch (quality) {
7412                                 case CAM_QUALITY_HIGH:
7413                                 case CAM_QUALITY_BEST:
7414                                         return_val = 2000000;
7415                                         break;
7416
7417                                 case CAM_QUALITY_MEDIUM:
7418                                         return_val = 1000000;
7419                                         break;
7420
7421                                 case CAM_QUALITY_LOW:
7422                                         return_val = 500000;
7423                                         break;
7424
7425                                 default:
7426                                         cam_critical(LOG_MM, "INVALID QUAILTY");
7427                                         break;
7428                                 }
7429                         }
7430                         break;
7431
7432                 case CAM_RESOLUTION_QVGA:
7433                         {
7434                                 switch (quality) {
7435                                 case CAM_QUALITY_HIGH:
7436                                 case CAM_QUALITY_BEST:
7437                                         return_val = 384000;
7438                                         break;
7439
7440                                 case CAM_QUALITY_MEDIUM:
7441                                         return_val = 192000;
7442                                         break;
7443
7444                                 case CAM_QUALITY_LOW:
7445                                         return_val = 64000;
7446                                         break;
7447
7448                                 default:
7449                                         cam_critical(LOG_MM, "INVALID QUAILTY");
7450                                         break;
7451                                 }
7452                         }
7453                         break;
7454
7455                 case CAM_RESOLUTION_QCIF:
7456                         {
7457                                 switch (quality) {
7458                                 case CAM_QUALITY_HIGH:
7459                                 case CAM_QUALITY_BEST:
7460                                         return_val = 384000;
7461                                         break;
7462
7463                                 case CAM_QUALITY_MEDIUM:
7464                                         return_val = 192000;
7465                                         break;
7466
7467                                 case CAM_QUALITY_LOW:
7468                                         return_val = 64000;
7469                                         break;
7470
7471                                 default:
7472                                         cam_critical(LOG_MM, "INVALID QUAILTY");
7473                                         break;
7474                                 }
7475                         }
7476                         break;
7477
7478                 default:
7479                         cam_critical(LOG_MM, "INVALID QUAILTY");
7480                         break;
7481                 }
7482         }
7483
7484         cam_debug(LOG_MM, "videoenc bit rate = %d, current quilty = %d",
7485                   return_val, quality);
7486         return return_val;
7487 }
7488
7489 gboolean cam_app_set_video_quality(void *data, int quality)
7490 {
7491         struct appdata *ad = (struct appdata *)data;
7492         CamAppData *camapp = NULL;
7493         int v_bitrate = 0;
7494
7495         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
7496         camapp = ad->camapp_handle;
7497         cam_retvm_if(camapp == NULL, FALSE, "camapp is NULL");
7498
7499         v_bitrate = cam_app_get_venc_bitrate(ad, quality);
7500         if (v_bitrate > 0) {
7501                 cam_mm_set_video_encoder_bitrate(v_bitrate);
7502         } else {
7503                 return FALSE;
7504         }
7505
7506         return TRUE;
7507 }
7508
7509 gboolean cam_app_set_recording_mode(void *data, int mode)
7510 {
7511         struct appdata *ad = (struct appdata *)data;
7512         CamAppData *camapp = NULL;
7513         int video_codec = 0, audio_codec = 0, sample_rate = 0;
7514         int file_format = RECORDER_FILE_FORMAT_MP4;
7515         int channel = 0;
7516         int a_bitrate = 0;
7517
7518         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
7519         camapp = ad->camapp_handle;
7520         cam_retvm_if(camapp == NULL, FALSE, "camapp is NULL");
7521         DEBUG_TRACE("mode = %d" , mode);
7522         if (mode == CAM_RECORD_MMS || mode == CAM_RECORD_SELF_MMS) {
7523                 DEBUG_TRACE("mode = %d" , mode);
7524                 video_codec = RECORDER_VIDEO_CODEC_H263;
7525                 audio_codec = RECORDER_AUDIO_CODEC_AMR;
7526                 sample_rate = 8000;
7527                 file_format = RECORDER_FILE_FORMAT_3GP;
7528                 channel = 1;
7529         } else {
7530                 DEBUG_TRACE("mode = %d" , mode);
7531                 video_codec = RECORDER_VIDEO_CODEC_MPEG4;
7532                 audio_codec = RECORDER_AUDIO_CODEC_AAC;
7533                 sample_rate = 44100;
7534                 file_format = RECORDER_FILE_FORMAT_MP4;
7535                 channel = 2;
7536         }
7537
7538         if (!cam_mm_set_codec(audio_codec, video_codec))
7539                 return FALSE;
7540
7541         if (!cam_mm_set_audio_source(sample_rate, channel))
7542                 return FALSE;
7543
7544         a_bitrate = cam_app_get_aenc_bitrate(ad);
7545         if (a_bitrate > 0) {
7546                 cam_mm_set_audio_encoder_bitrate(a_bitrate);
7547         } else {
7548                 return FALSE;
7549         }
7550
7551         if (!cam_app_set_video_quality(ad, camapp->video_quality))
7552                 return FALSE;
7553
7554         if (!cam_mm_set_file_format(file_format))
7555                 return FALSE;
7556
7557         return TRUE;
7558 }
7559
7560 gboolean cam_app_set_size_limit(int max_val, int size_limit_type)
7561 {
7562         int ret = 0;
7563
7564         switch (size_limit_type) {
7565         case CAM_MM_SIZE_LIMIT_TYPE_BYTE:
7566                 ret = cam_mm_set_max_size(max_val);
7567                 if (!ret)
7568                         return FALSE;
7569 /*
7570                 ret = cam_mm_set_max_time(REC_MAX_TIME_LIMITED);
7571                 if (!ret)
7572                         return FALSE;
7573 */
7574                 break;
7575         case CAM_MM_SIZE_LIMIT_TYPE_SECOND:
7576                 ret = cam_mm_set_max_size(0);
7577                 if (!ret)
7578                         return FALSE;
7579                 ret = cam_mm_set_max_time(max_val);
7580                 if (!ret)
7581                         return FALSE;
7582                 break;
7583         default:
7584                 g_assert_not_reached();
7585         }
7586
7587         return TRUE;
7588 }
7589
7590 gboolean cam_app_init_attribute(void *data, CamMode mode)
7591 {
7592         struct appdata *ad = (struct appdata *)data;
7593         CamAppData *camapp = NULL;
7594         gboolean ret = TRUE;
7595         int width = 0;
7596         int height = 0;
7597         int state = 0;
7598         int rotate = CAMERA_ROTATION_270;
7599         int camera_rotate = CAMERA_ROTATION_NONE;
7600         int video_dev = 0;
7601         int capture_video_format = -1;
7602         #ifdef TODO_SURRPORT
7603         int recording_video_format = -1;
7604         #endif
7605
7606         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
7607         camapp = ad->camapp_handle;
7608         cam_retvm_if(camapp == NULL, FALSE, "camapp is NULL");
7609
7610         state = cam_mm_get_state();
7611
7612 #if 0
7613         if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
7614                 if (state != RECORDER_STATE_CREATED) {
7615                         return FALSE;
7616                 }
7617         } else if(camapp->camera_mode == CAM_CAMERA_MODE) {
7618                 if (state != CAMERA_STATE_CREATED) {
7619                         return FALSE;
7620                 }
7621         }
7622 #endif
7623
7624         cam_mm_get_video_size( &camapp->default_preview_width, &camapp->default_preview_height);
7625         DEBUG_TRACE("default_width = %d,default_height = %d", camapp->default_preview_width, camapp->default_preview_height);
7626
7627         if (CAM_CAMERA_MODE == mode) {
7628                 width = CAM_RESOLUTION_W(camapp->photo_resolution);
7629                 height = CAM_RESOLUTION_H(camapp->photo_resolution);
7630
7631                 ret &= cam_mm_set_image_size(width, height);
7632                 ret &= cam_mm_set_image_count(camapp->image_count);
7633                 ret &= cam_mm_set_image_enc_quality(camapp->image_quality);
7634                 ret &= cam_mm_set_fps(CAMERA_ATTR_FPS_AUTO);
7635                 ret &= cam_mm_get_video_source_format(NULL, &capture_video_format);
7636                 ret &= cam_mm_set_video_source_format(capture_video_format);
7637                 ret &= cam_app_set_capture_format_shooting_mode(camapp->shooting_mode);
7638
7639                 if (cam_is_enabled_menu(ad, CAM_MENU_SAVE_AS_FLIP))
7640                         ret &= cam_mm_set_image_flip(camapp->save_as_flip);
7641                 else
7642                         ret &= cam_mm_set_image_flip(FALSE);
7643
7644                 ret &= cam_mm_set_anti_hand_shake(camapp->anti_shake);
7645         } else if (CAM_CAMCORDER_MODE == mode) {
7646                 width = CAM_RESOLUTION_W(camapp->video_resolution);
7647                 height = CAM_RESOLUTION_H(camapp->video_resolution);
7648
7649                 ret &= cam_mm_set_image_size(CAM_RESOLUTION_W(camapp->photo_resolution), CAM_RESOLUTION_H(camapp->photo_resolution));
7650                 ret &= cam_mm_set_image_enc_quality(camapp->image_quality);
7651                 ret &= cam_mm_set_video_profile();
7652                 DEBUG_TRACE("");
7653                 ret &= cam_mm_set_fps(camapp->fps);
7654                 if (camapp->anti_shake) {
7655                         ret &= cam_mm_set_video_source_format(CAMERA_PIXEL_FORMAT_NV12);
7656                 } else {
7657                         ret &= cam_mm_get_video_source_format(NULL, &recording_video_format);
7658                         DEBUG_TRACE("recording_video_format:%d", recording_video_format);
7659                         ret &= cam_mm_set_video_source_format(recording_video_format);
7660                 }
7661                 ret &= cam_mm_set_audio_recording(camapp->audio_recording);
7662                 ret &= cam_app_set_recording_mode(ad, camapp->recording_mode);
7663                 DEBUG_TRACE("camapp->size_limit = %d" , camapp->size_limit);
7664                 DEBUG_TRACE("camapp->size_limit_type = %d" , camapp->size_limit_type);
7665                 ret &= cam_app_set_size_limit(camapp->size_limit, camapp->size_limit_type);
7666         } else {
7667                 return FALSE;
7668         }
7669         cam_mm_get_video_device(&video_dev);
7670         DEBUG_TRACE("video_dev = %d",video_dev);
7671         if (video_dev == CAM_DEVICE_VGA) {
7672                 int value;
7673                 cam_mm_get_front_cam_display_rotate_value(&value, &rotate);
7674
7675                 DEBUG_TRACE("get front camera rotate %d value = %d", rotate, value);
7676                 /*rotate = value;*/
7677                 #ifdef TODO_SURRPORT
7678                 rotate = CAMERA_ROTATION_270;
7679                 #endif /*TODO:if new capi will released, this could be removed,but take care.*/
7680
7681         }
7682         cam_mm_get_zoom_valid_intrange(&camapp->zoom_min,&camapp->zoom_max);
7683         DEBUG_TRACE("Zoom range [%d - %d]",camapp->zoom_min, camapp->zoom_max);
7684
7685         cam_mm_get_brightless_valid_intrange(&camapp->brightness_min,&camapp->brightness_max);
7686         DEBUG_TRACE("brightness range [%d - %d]",camapp->brightness_min, camapp->brightness_max);
7687         camapp->brightness = (camapp->brightness_min + camapp->brightness_max) /2;
7688
7689         ret &= cam_mm_remove_geo_tag();
7690         DEBUG_TRACE("cam_mm_remove_geo_tag = %d", ret);
7691         ret &= cam_mm_set_display_device(CAMERA_DISPLAY_TYPE_X11, GET_DISPLAY(ad->main_xid));
7692         ret &= cam_mm_set_camera_rotate(camera_rotate);
7693         ret &= cam_mm_set_display_rotate(rotate);
7694         ret &= cam_mm_set_display_geometry_method(CAMERA_DISPLAY_MODE_LETTER_BOX);
7695 #ifndef USE_CAMERA_APP_SHUTTER_SOUND
7696         ret &= cam_mm_set_shutter_sound(TRUE);
7697 #endif
7698         ret &= cam_app_reset_resolution(ad, width, height, TRUE);
7699         ret &= cam_mm_set_zoom(camapp->zoom_mode);
7700         ret &= cam_mm_set_auto_exposure(camapp->auto_exposure);
7701         ret &= cam_mm_set_iso(camapp->iso);
7702         ret &= cam_mm_set_wdr(camapp->wdr);
7703         ret &= cam_mm_set_brightness(camapp->brightness);
7704         ret &= cam_mm_enable_auto_contrast(camapp->auto_contrast);
7705         ret &= cam_mm_set_white_balance(camapp->white_balance);
7706         ret &= cam_mm_set_effect(camapp->effect);
7707         ret &= cam_mm_set_program_mode(camapp->scene_mode);
7708
7709         if (ad->torchlight_on && camapp->flash != CAM_FLASH_OFF)
7710                 ret &= cam_mm_set_flash(CAM_FLASH_OFF);
7711         else
7712                 ret &= cam_mm_set_flash(camapp->flash);
7713
7714         if (camapp->af_mode == CAM_FOCUS_AUTO
7715             || camapp->af_mode == CAM_FOCUS_MACRO) {
7716                 ret &= cam_mm_set_focus_mode(camapp->af_mode);
7717         } else if (camapp->af_mode == CAM_FOCUS_FACE) {
7718                 ret &= cam_mm_set_focus_mode(CAMERA_ATTR_AF_NORMAL);
7719         }
7720
7721         ret &= cam_mm_set_tag_enable(TRUE);
7722         ret &= cam_mm_set_outdoor_visibility(camapp->outdoor_visibility);
7723         ad->enable_mode_change = TRUE;
7724         ad->is_recording = FALSE;
7725         return ret;
7726
7727 }
7728
7729 static void cam_app_update_gps_level(void *data, int lbs_state)
7730 {
7731         struct appdata *ad = (struct appdata *)data;
7732         GValue value = { 0, };
7733         cam_retm_if(ad == NULL, "appdata is NULL");
7734
7735         cam_debug(LOG_UI, "     cam_app_update_gps_level : %d", lbs_state);
7736
7737         CAM_GVALUE_SET_INT(value, lbs_state);
7738         cam_handle_value_set(ad, PROP_GPS_LEVEL, &value);
7739
7740         return;
7741 }
7742
7743 static gboolean cam_app_return_ext_app(void *data, const char *r_file_path)
7744 {
7745         struct appdata *ad = (struct appdata *)data;
7746         service_h reply;
7747         service_create(&reply);
7748
7749         if (ad->service_mime != NULL) {
7750                 if (r_file_path == NULL) {
7751                         service_add_extra_data(reply, SERVICE_DATA_SELECTED, "exit");
7752                         service_reply_to_launch_request(reply, ad->service_handle, SERVICE_RESULT_FAILED);
7753                 } else {
7754                         service_add_extra_data(reply, SERVICE_DATA_SELECTED, r_file_path);
7755                         service_reply_to_launch_request(reply, ad->service_handle, SERVICE_RESULT_SUCCEEDED);
7756                 }
7757         }
7758
7759         service_destroy(reply);
7760         return TRUE;
7761
7762 }
7763 static void cam_app_battery_status_cb(keynode_t *key, void *data)
7764 {
7765         struct appdata *ad = (struct appdata *)data;
7766
7767         debug_fenter(LOG_UI);
7768         cam_retm_if(ad == NULL, "appdata is NULL");
7769
7770         int low_status = -1;
7771
7772         if (!vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &low_status)) {
7773                 cam_debug(LOG_UI, "battery status low = %d", low_status);
7774                 if (low_status <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) {
7775                         ad->battery_status = LOW_BATTERY_CRITICAL_STATUS;
7776                         cam_app_notice_popup(ad, dgettext("sys_string", "IDS_COM_BODY_LOW_BATTERY"),
7777                         cam_app_timeout_notice_response_cb);
7778                 } else if (low_status == VCONFKEY_SYSMAN_BAT_WARNING_LOW) {
7779                         ad->battery_status = LOW_BATTERY_WARNING_STATUS;
7780                         cam_app_notice_popup((void *)ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_USE_FLASH_BATTERY_LOW"), cam_app_lowbattery_close_flash_cb);
7781                 } else {
7782                         ad->battery_status = NORMAL_BATTERY_STATUS;
7783                 }
7784         }
7785
7786         return;
7787 }
7788 /*if torch light vconf key value is changed, this cb is called*/
7789 static void cam_torchlight_update_cb(keynode_t *key, void *data)
7790 {
7791         struct appdata *ad = (struct appdata *)data;
7792         cam_retm_if(ad == NULL, "appdata is NULL");
7793         CamAppData *camapp = ad->camapp_handle;
7794         cam_retm_if(camapp == NULL, "camapp is NULL");
7795
7796         int key_value = vconf_keynode_get_bool(key); /* -1: error, 1:True, 0:False */
7797         if (key_value == -1) {
7798                 DEBUG_TRACE("vconf_keynode_get_bool failed");
7799                 return;
7800         }
7801         DEBUG_TRACE("VCONFKEY_SETAPPL_ACCESSIBILITY_TORCH_LIGHT is changed to %d", key_value);
7802         if (key_value) {
7803                 /* disable flash icon */
7804                 ad->torchlight_on = TRUE;
7805                 cam_mm_set_flash(CAM_FLASH_OFF);
7806
7807         } else {
7808                 /* enable flash icon */
7809                 ad->torchlight_on = FALSE;
7810                 cam_mm_set_flash(camapp->flash);
7811         }
7812         cam_toolbar_update(ad); /*update flash icon*/
7813         return;
7814 }
7815
7816 static void cam_app_battery_update_cb(keynode_t *key, void *data)
7817 {
7818         struct appdata *ad = (struct appdata *)data;
7819         CamAppData *camapp = NULL;
7820         char *keyname = NULL;
7821
7822         debug_fenter(LOG_UI);
7823
7824         cam_retm_if(ad == NULL, "appdata is NULL");
7825         camapp = ad->camapp_handle;
7826         cam_retm_if(camapp == NULL, "camapp_handle is NULL");
7827
7828         keyname = vconf_keynode_get_name(key);
7829
7830         if (!strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW)) {
7831                 GValue value = { 0 };
7832                 gint charging = vconf_keynode_get_int(key);
7833                 DEBUG_TRACE("charging = %d", charging);
7834                 CAM_GVALUE_SET_INT(value, charging);
7835                 cam_handle_value_set(ad, PROP_BATTERY_CHARG, &value);
7836
7837         } else if (!strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_CAPACITY)) {
7838                 GValue value = { 0 };
7839                 int battery_level = vconf_keynode_get_int(key);
7840                 CAM_GVALUE_SET_INT(value, battery_level);
7841                 cam_handle_value_set(ad, PROP_BATTERY_LEVEL, &value);
7842         }
7843         return;
7844 }
7845
7846 #if 0
7847 Evas_Object *cam_screen_load_edj(Evas_Object *parent, const char *file,
7848                                  const char *group)
7849 {
7850         Evas_Object *eo;
7851         int r;
7852
7853         eo = elm_layout_add(parent);
7854         if (eo) {
7855                 r = elm_layout_file_set(eo, file, group);
7856                 if (!r) {
7857                         evas_object_del(eo);
7858                         return NULL;
7859                 }
7860
7861                 evas_object_size_hint_weight_set(eo,
7862                                                  EVAS_HINT_EXPAND,
7863                                                  EVAS_HINT_EXPAND);
7864
7865                 /*      //if(!strcmp((const char *)elm_widget_type_get(parent), "win")) { */
7866                 elm_win_resize_object_add(parent, eo);
7867                 /*      //} */
7868         }
7869
7870         return eo;
7871 }
7872 #endif
7873 Evas_Object *cam_app_load_edj(Evas_Object *parent, const char *file,
7874                               const char *group)
7875 {
7876         Evas_Object *eo = NULL;
7877         int r = 0;
7878
7879         eo = elm_layout_add(parent);
7880         if (eo) {
7881                 r = elm_layout_file_set(eo, file, group);
7882                 if (!r) {
7883                         evas_object_del(eo);
7884                         return NULL;
7885                 }
7886
7887                 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
7888                 evas_object_show(eo);
7889         }
7890
7891         return eo;
7892 }
7893
7894 Eina_Bool __cam_app_update_thumbnail_idler(void *data)
7895 {
7896         struct appdata *ad = (struct appdata *)data;
7897         if (!ad) {
7898                 return ECORE_CALLBACK_CANCEL;
7899         }
7900         CamAppData *camapp = ad->camapp_handle;
7901
7902         if (!camapp) {
7903                 REMOVE_IDLER(ad->update_thumbnail_idler);
7904                 return ECORE_CALLBACK_CANCEL;
7905         }
7906
7907         DEBUG_TRACE(" ");
7908
7909         if (!g_file_test(camapp->filename,G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
7910                 DEBUG_TRACE( "The captured File is not existed");
7911                 REMOVE_IDLER(ad->update_thumbnail_idler);
7912                 return ECORE_CALLBACK_CANCEL;;
7913         }
7914
7915         gboolean ret = FALSE;
7916
7917         if (ad->imageviewer_ug) { /*review on */
7918                 DEBUG_TRACE("Image viewer was LAUNCHED. skip this...");
7919                 REMOVE_IDLER(ad->update_thumbnail_idler);
7920                 return ECORE_CALLBACK_CANCEL;;
7921         }
7922
7923         if (camapp->thumbnail_name != NULL) {
7924                 free (camapp->thumbnail_name);
7925                 camapp->thumbnail_name = NULL;
7926
7927         }
7928
7929         ret = cam_file_get_cam_file_thumbnail_path(camapp->filename, &camapp->thumbnail_name);
7930         DEBUG_TRACE("ret[0:success] = [%d] camapp->filename: [%s]",
7931                   ret, camapp->filename);
7932         DEBUG_TRACE("ret[0:success] = [%d] camapp->thumbnail_name: [%s]",
7933                   ret, camapp->thumbnail_name);
7934         if (!g_file_test(camapp->thumbnail_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
7935
7936                 if (g_thumbnail_image_check_count > 10) {
7937                         REMOVE_IDLER(ad->update_thumbnail_idler);
7938                         return ECORE_CALLBACK_CANCEL;
7939                 }
7940
7941                 DEBUG_TRACE("The thumbnail File is not existed,try the %d nums", g_thumbnail_image_check_count);
7942                 g_thumbnail_image_check_count++;
7943                 usleep(THUMBNAIL_UPDATE_WAIT_TIME);
7944                 /*REMOVE_IDLER(ad->update_thumbnail_idler);*//*note:renew, do not delete idler*/
7945                 return ECORE_CALLBACK_RENEW;
7946         }
7947         else if (camapp->camera_mode == CAM_CAMERA_MODE) {
7948                 DEBUG_TRACE("thumbnail image check count=[%d]", g_thumbnail_image_check_count);
7949                 toolbar_update_quickview_thumbnail(ad);
7950         }
7951         else if (camapp->camera_mode == CAM_CAMCORDER_MODE) {
7952                 toolbar_update_quickview_thumbnail(ad);
7953
7954         } else {
7955                 DEBUG_TRACE("NOT REACHED CODES REACHED!");
7956         }
7957         REMOVE_IDLER(ad->update_thumbnail_idler);
7958         return ECORE_CALLBACK_CANCEL;
7959 }
7960 /* update thumbnail to quickview after first launching or return from image viewer */
7961 void cam_app_update_quickview_icon(void *data) {
7962
7963         struct appdata *ad = (struct appdata *)data;
7964         cam_ret_if(ad == NULL);
7965         cam_ret_if(ad->camapp_handle == NULL);
7966         gchar *filename = NULL;
7967
7968         DEBUG_TRACE("");
7969
7970         /*To update quickview image, get last filename*/
7971         if (ad->camapp_handle->filename) {
7972                 free(ad->camapp_handle->filename);
7973                 ad->camapp_handle->filename = NULL;
7974         }
7975
7976         if (ad->camapp_handle->thumbnail_name) {
7977                 free(ad->camapp_handle->thumbnail_name);
7978                 ad->camapp_handle->thumbnail_name = NULL;
7979         }
7980
7981         filename = cam_app_get_last_filename();
7982
7983         if (filename != NULL) {
7984                 ad->camapp_handle->filename = strdup(filename);
7985                 free(filename);
7986                 filename = NULL;
7987
7988                 if (!cam_file_get_cam_file_thumbnail_path
7989                         (ad->camapp_handle->filename, &ad->camapp_handle->thumbnail_name))
7990                         DEBUG_TRACE("cam_file_get_cam_file_thumbnail_path() fail");
7991
7992         }
7993
7994         toolbar_update_quickview_thumbnail_no_animation(ad);
7995
7996         return;
7997 }
7998
7999 void cam_app_update_thumbnail()
8000 {
8001         struct appdata *ad = (struct appdata *)cam_appdata_get();
8002         cam_ret_if(ad == NULL);
8003         CamAppData *camapp = ad->camapp_handle;
8004         cam_ret_if(camapp == NULL);
8005
8006         DEBUG_TRACE("cam_app_update_thumbnail");
8007
8008         if (CAM_LAUNCHING_MODE_NORMAL == ad->launching_mode && camapp->filename) {
8009                 DEBUG_TRACE();
8010                 g_thumbnail_image_check_count = 0;
8011                 if (!ad->update_thumbnail_idler)
8012                         ad->update_thumbnail_idler = ecore_idler_add(__cam_app_update_thumbnail_idler, ad);
8013         }
8014         return;
8015 }
8016
8017 gboolean cam_app_parse_args(CamExeArgs *args, service_h service)
8018 {
8019         struct appdata *ad = (struct appdata *)cam_appdata_get();
8020         cam_retv_if(ad == NULL, FALSE);
8021
8022         ad->service_mime = NULL;
8023
8024         int ret = service_get_mime(service, &ad->service_mime);
8025         if (ret != SERVICE_ERROR_NONE) {
8026                 cam_debug(LOG_UI, "service_get_mime is error ");
8027                 return FALSE;
8028         }
8029
8030         if (ad->service_mime != NULL) {
8031                 /* get mode */
8032                 if ((strcmp(ad->service_mime, SERVICE_MIME_TYPE_IMAGE_1) == 0)
8033                         || (strcmp(ad->service_mime, SERVICE_MIME_TYPE_IMAGE_2) == 0)) {
8034                         cam_debug(LOG_UI, "CAM_CAMERA_MODE");
8035                         args->cam_mode = CAM_CAMERA_MODE;
8036                 } else if ((strcmp(ad->service_mime, SERVICE_MIME_TYPE_VIDEO_1) == 0)
8037                         || (strcmp(ad->service_mime, SERVICE_MIME_TYPE_VIDEO_2) == 0)) {
8038                         cam_debug(LOG_UI, "CAM_CAMCORDER_MODE");
8039                         args->cam_mode = CAM_CAMCORDER_MODE;
8040                 } else {
8041                         cam_critical(LOG_UI, "Invalid mime type");
8042                         args->cam_mode = CAM_CAMERA_MODE;
8043                 }
8044         }
8045
8046         const char *val = NULL;
8047         /* get caller appl. */
8048         service_get_extra_data(service, "CALLER", (char **)&val);
8049         if (val) {
8050                 cam_debug(LOG_UI, "CALLER %s", val);
8051                 args->caller = strdup(val);
8052         } else {
8053                 args->caller = NULL;
8054         }
8055
8056         /* resolution */
8057         val = NULL;
8058         int res = 0;
8059         service_get_extra_data(service, "RESOLUTION", (char **)&val);
8060         if (val) {
8061                 cam_debug(LOG_UI, "RESOLUTION %s", val);
8062
8063                 if (args->cam_mode == CAM_CAMERA_MODE) {
8064                         if (0 == strcmp(val, CAM_CAPTURE_RES_VGA))
8065                                 res = CAM_RESOLUTION_VGA;
8066                         else
8067                                 res = IMAGE_RESOLUTION_DEFAULT;
8068                 } else {
8069                         if (0 == strcmp(val, CAM_RECORDING_RES_QCIF))
8070                                 res = CAM_RESOLUTION_QCIF;
8071                         else
8072                                 res = REC_RESOLUTION_DEFAULT;
8073                 }
8074         } else {
8075                 if (args->cam_mode == CAM_CAMERA_MODE) {
8076                         res = IMAGE_RESOLUTION_DEFAULT;
8077                 } else {
8078                         res = REC_RESOLUTION_DEFAULT;
8079                 }
8080         }
8081         args->width = CAM_RESOLUTION_W(res);
8082         args->height = CAM_RESOLUTION_H(res);
8083         args->resolution = res;
8084
8085         /* size limit */
8086         val = NULL;
8087         service_get_extra_data(service, "LIMIT", (char **)&val);
8088         if (val) {
8089                 cam_debug(LOG_UI, "LIMIT %s", val);
8090                 args->size_limit = atoi(val);
8091         } else {
8092                 args->size_limit = 0;
8093         }
8094
8095         args->review = TRUE;
8096
8097         /*  print exe args */
8098         cam_debug(LOG_SYS, "############### exe args ###############");
8099         cam_debug(LOG_SYS, "mode =%d", args->cam_mode);
8100         cam_debug(LOG_SYS, "caller =%s", args->caller);
8101         cam_debug(LOG_SYS, "width =%d", args->width);
8102         cam_debug(LOG_SYS, "height =%d", args->height);
8103         cam_debug(LOG_SYS, "limit =%d", args->size_limit);
8104         cam_debug(LOG_SYS, "review =%d", args->review);
8105         cam_debug(LOG_SYS, "############### end ###############");
8106
8107         return TRUE;
8108 }
8109
8110
8111 void cam_app_draw_af_box(void *data)
8112 {
8113
8114         cam_retm_if(data == NULL, "data is null");
8115         struct appdata *ad = (struct appdata *)data;
8116         ad->af_start_x = 0;
8117         ad->af_start_y = 0;
8118
8119         switch (ad->rot_current) {
8120         case APP_DEVICE_ORIENTATION_0:
8121                 {
8122                         ad->af_start_x = ad->touch_lcd_x;
8123                         ad->af_start_y = ad->touch_lcd_y;
8124                 }
8125                 break;
8126         case APP_DEVICE_ORIENTATION_180:
8127                 {
8128                         ad->af_start_x = ad->win_height - ad->touch_lcd_x;
8129                         ad->af_start_y = ad->win_width - ad->touch_lcd_y;
8130                 }
8131                 break;
8132         case APP_DEVICE_ORIENTATION_270:
8133                 {
8134                         ad->af_start_x = ad->touch_lcd_y;
8135                         ad->af_start_y = ad->win_height - ad->touch_lcd_x;
8136                 }
8137                 break;
8138         case APP_DEVICE_ORIENTATION_90:
8139                 {
8140                         ad->af_start_x = ad->win_width - ad->touch_lcd_y;
8141                         ad->af_start_y = ad->touch_lcd_x;
8142                 }
8143                 break;
8144         default:
8145                 break;
8146         }
8147
8148         /* adjust */
8149         DEBUG_TRACE("ad->af_start_x=%f, ad->af_start_y=%f", ad->af_start_x, ad->af_start_y);
8150
8151         ad->camera_focus_w = CAMERA_FOCUS_W * elm_config_scale_get();
8152         ad->camera_focus_h = CAMERA_FOCUS_H * elm_config_scale_get();
8153         DEBUG_TRACE("ad->camera_focus_w=%f, ad->camera_focus_h=%f", ad->camera_focus_w, ad->camera_focus_h);
8154
8155         ad->af_start_x = ad->af_start_x - (ad->camera_focus_w / 2);
8156         ad->af_start_y = ad->af_start_y - (ad->camera_focus_h / 2);
8157         DEBUG_TRACE("af area box start x,y =[%f,%f]\n", ad->af_start_x, ad->af_start_y);
8158
8159         if (ad->rot_current == APP_DEVICE_ORIENTATION_270
8160             || ad->rot_current == APP_DEVICE_ORIENTATION_90) {
8161                 if (ad->af_start_x < ad->preview_offset_x) {
8162                         ad->af_start_x = ad->preview_offset_x;
8163                 }
8164                 if (ad->af_start_y < ad->preview_offset_y) {
8165                         ad->af_start_y = ad->preview_offset_y;
8166                 }
8167                 if ((ad->af_start_x + ad->camera_focus_w) >
8168                     (ad->preview_w + ad->preview_offset_x)) {
8169                         ad->af_start_x =
8170                             (ad->preview_w + ad->preview_offset_x) -
8171                             ad->camera_focus_w;
8172                 }
8173                 if ((ad->af_start_y + ad->camera_focus_h) >
8174                     (ad->preview_h + ad->preview_offset_y)) {
8175                         ad->af_start_y =
8176                             (ad->preview_h + ad->preview_offset_y) -
8177                             ad->camera_focus_h;
8178                 }
8179
8180         } else {
8181                 if (ad->af_start_y < ad->preview_offset_x) {
8182                         ad->af_start_y = ad->preview_offset_x;
8183                 }
8184                 if (ad->af_start_x < ad->preview_offset_y) {
8185                         ad->af_start_x = ad->preview_offset_y;
8186                 }
8187                 if ((ad->af_start_y + ad->camera_focus_h) >
8188                     (ad->preview_w + ad->preview_offset_x)) {
8189                         ad->af_start_y =
8190                             (ad->preview_w + ad->preview_offset_x) -
8191                             ad->camera_focus_h;
8192                 }
8193                 if ((ad->af_start_x + ad->camera_focus_w) >
8194                     (ad->preview_h + ad->preview_offset_y)) {
8195                         ad->af_start_x =
8196                             (ad->preview_h + ad->preview_offset_y) -
8197                             ad->camera_focus_w;
8198                 }
8199         }
8200
8201         if (ad->focus_edje) {
8202                 DEBUG_TRACE
8203                     ("####################################################");
8204                 DEBUG_TRACE("af area start ,ad->af_start_x,y =[%f,%f]\n",
8205                             ad->af_start_x, ad->af_start_y);
8206                 DEBUG_TRACE
8207                     ("####################################################");
8208                 evas_object_move(ad->focus_edje, ad->af_start_x,
8209                                  ad->af_start_y);
8210                 DEBUG_TRACE(" MOVE FOCUS_EDJE : %f,%f", ad->af_start_x,
8211                             ad->af_start_y);
8212         }
8213
8214 }
8215
8216
8217 /*  get preview start x,y coordinate */
8218 void cam_app_get_preview_offset_coordinate(void *data)
8219 {
8220
8221         cam_retm_if(data == NULL, "data is null");
8222         struct appdata *ad = (struct appdata *)data;
8223
8224         CamAppData *camapp = ad->camapp_handle;
8225         cam_retm_if(camapp == NULL, "camapp is null");
8226
8227         int width = 0;
8228         int height = 0;
8229         CamVideoRectangle result;       /* result ractangle */
8230         CamVideoRectangle window;       /* target window ractangle */
8231         CamVideoRectangle preview;      /* target preview rectangle */
8232         /*wow,now, the MMHandleType is not created*/
8233         cam_mm_get_video_size(&width, &height);
8234
8235         ad->camfw_video_width = width;
8236         ad->camfw_video_height = height;
8237
8238         preview.w = width;
8239         preview.h = height;
8240         DEBUG_TRACE("************************************************");
8241         DEBUG_TRACE("preview.w =%d, preview.h=%d", preview.w, preview.h);
8242
8243         window.h = ad->win_height;
8244         window.w = ad->win_width;
8245         DEBUG_TRACE("window.w =%d, window.h=%d\n", window.w, window.h);
8246         DEBUG_TRACE("************************************************");
8247         cam_app_preview_start_coordinate(preview, window, &result);
8248
8249         ad->preview_offset_x = result.x;
8250         ad->preview_offset_y = result.y;
8251         ad->preview_w = result.w;
8252         ad->preview_h = result.h;
8253
8254         DEBUG_TRACE("************************************************");
8255         DEBUG_TRACE("ad->preview_offset_x = %d, ad->preview_offset_y = %d",
8256                     ad->preview_offset_x, ad->preview_offset_y);
8257         DEBUG_TRACE("*************************************************");
8258
8259         camapp->focus_state = CAM_FOCUS_STATUS_RELEASED;
8260         cam_app_focus_guide_update(ad);
8261
8262         /* init */
8263         ad->af_x = (ad->win_width / 2) - ad->preview_offset_x;
8264         ad->af_y = (ad->win_height / 2) - ad->preview_offset_y;
8265
8266         ad->af_x = (ad->af_x * ad->camfw_video_width) / ad->preview_w;
8267         ad->af_y = (ad->af_y * ad->camfw_video_height) / ad->preview_h;
8268         /* init */
8269         ad->touch_lcd_x = (ad->win_height / 2);
8270         ad->touch_lcd_y = (ad->win_width / 2);
8271
8272         DEBUG_TRACE("*************************************************");
8273         DEBUG_TRACE(" ad->af_x=%d, ad->af_y=%d", ad->af_x, ad->af_y);
8274         DEBUG_TRACE(" ad->af_start_x=%d, ad->af_start_y=%d", ad->af_start_x, ad->af_start_y);
8275         DEBUG_TRACE(" ad->touch_lcd_x=%d, ad->touch_lcd_y=%d", ad->touch_lcd_x, ad->touch_lcd_y);
8276         DEBUG_TRACE("*************************************************");
8277
8278         cam_app_draw_af_box(ad);
8279
8280         if (ad->focus_edje)
8281                 evas_object_show(ad->focus_edje);
8282 }
8283
8284 void cam_app_preview_start_coordinate(CamVideoRectangle src,
8285                                       CamVideoRectangle dst,
8286                                       CamVideoRectangle *result)
8287 {
8288         /* src is target preview rectangle */
8289         /* dst is target window rectangle */
8290         g_return_if_fail(result != NULL);
8291         gdouble src_ratio, dst_ratio;
8292         src_ratio = (gdouble) src.w / src.h;
8293         dst_ratio = (gdouble) dst.w / dst.h;
8294         if (src_ratio > dst_ratio) {
8295                 DEBUG_TRACE("#### case 1\n");
8296                 result->w = dst.w;
8297                 result->h = dst.w / src_ratio;
8298                 result->x = 0;
8299                 result->y = (dst.h - result->h) / 2;
8300         } else if (src_ratio < dst_ratio) {
8301                 DEBUG_TRACE("#### case 2\n");
8302                 result->w = dst.h * src_ratio;
8303                 result->h = dst.h;
8304                 result->x = (dst.w - result->w) / 2;
8305                 result->y = 0;
8306         } else {
8307                 DEBUG_TRACE("#### case 3\n");
8308                 result->x = 0;
8309                 result->y = 0;
8310                 result->w = dst.w;
8311                 result->h = dst.h;
8312         }
8313         DEBUG_TRACE
8314             ("************************************************************");
8315         DEBUG_TRACE
8316             ("source is %dx%d dest is %dx%d, result window size is %dx%d result offset x= %dx y=%d",
8317              src.w, src.h, dst.w, dst.h, result->w, result->h, result->x,
8318              result->y);
8319         DEBUG_TRACE
8320             ("************************************************************");
8321 }
8322
8323
8324 void cam_remove_tmp_file()
8325 {
8326         const gchar *default_path = NULL;
8327         char tmpfile_name[256] = { 0 };
8328
8329         default_path = cam_file_get_internal_video_path();
8330         DEBUG_TRACE(" video = %s", default_path);
8331         snprintf(tmpfile_name, sizeof(tmpfile_name), "%s%s", default_path,
8332                  TMPFILE_PREFIX);
8333         if (g_file_test(tmpfile_name, G_FILE_TEST_EXISTS)) {
8334                 DEBUG_TRACE("REMOVE tmp file");
8335                 unlink(tmpfile_name);
8336         }
8337         default_path = cam_file_get_external_video_path();
8338         DEBUG_TRACE(" video = %s", default_path);
8339         snprintf(tmpfile_name, sizeof(tmpfile_name), "%s%s", default_path,
8340                  TMPFILE_PREFIX);
8341
8342         if (g_file_test(tmpfile_name, G_FILE_TEST_EXISTS)) {
8343                 DEBUG_TRACE("REMOVE tmp file");
8344                 unlink(tmpfile_name);
8345         }
8346
8347 }
8348
8349 Eina_Bool cam_app_launch_after_preview_began(void *data)
8350 {
8351         struct appdata *ad = (struct appdata *)data;
8352         cam_retv_if(ad == NULL, FALSE);
8353
8354         cam_debug(LOG_UI, "cam_app_launch_after_preview_began");
8355
8356         int state = cam_mm_get_state();
8357
8358         if (state != RECORDER_STATE_RECORDING) {
8359                 cam_debug(LOG_UI, "remove previous file");
8360                 cam_remove_tmp_file();
8361         }
8362
8363         cam_app_get_preview_offset_coordinate(data);
8364         cam_toolbar_setting_popup_create(data);
8365         return ECORE_CALLBACK_CANCEL;
8366 }
8367
8368 void cam_utils_remove_idler_all(void *data)
8369 {
8370         struct appdata *ad = (struct appdata *)data;
8371         GList *list = NULL;
8372         Ecore_Idler *idler = NULL;
8373
8374         debug_fenter(LOG_UI);
8375
8376         cam_retm_if(ad == NULL, "appdata is NULL");
8377
8378         /*LOCK
8379            In fact, a Lock is needed here. However, because all related functions are working main loop, practically it may not be needed. */
8380
8381         if (!ad->capture_cb_list) {
8382                 cam_debug(LOG_UI, "No idler is remained.");
8383         } else {
8384                 list = ad->capture_cb_list;
8385
8386                 while (list) {
8387                         idler = list->data;
8388
8389                         if (!idler) {
8390                                 cam_warning(LOG_UI,
8391                                             "Fail to remove idler. The idler is NULL");
8392                         } else {
8393                                 cam_debug(LOG_UI, "Remove idler[%p].", idler);
8394                                 ecore_idler_del(idler);
8395
8396                                 ad->capture_cb_list =
8397                                     g_list_remove(ad->capture_cb_list, idler);
8398                         }
8399
8400                         list = g_list_next(list);
8401                 }
8402
8403                 g_list_free(ad->capture_cb_list);
8404                 ad->capture_cb_list = NULL;
8405         }
8406
8407         /* UNLOCK */
8408         debug_fleave(LOG_UI);
8409         return;
8410 }
8411
8412 Eina_Bool cam_elm_cache_flush()
8413 {
8414 /*Make the canvas discard as much data as possible used by the engine at runtime.*/
8415         DEBUG_TRACE("start");
8416         struct appdata *ad = (struct appdata *)cam_appdata_get();
8417         if (ad) {
8418                 if (ad->evas) {
8419                         evas_render_idle_flush(ad->evas);
8420                 }
8421         }
8422         elm_cache_all_flush();
8423         DEBUG_TRACE("end");
8424         return EINA_TRUE;
8425 }
8426
8427 gboolean cam_condition_check_to_start_camera(void *data)
8428 {
8429         struct appdata *ad = (struct appdata *)data;
8430         cam_retvm_if(ad == NULL, EINA_FALSE, "appdata is NULL");
8431
8432         /* check battery */
8433         if (cam_utils_check_battery_critical_low()) {
8434                 ad->battery_status = LOW_BATTERY_CRITICAL_STATUS;
8435                 cam_app_notice_popup(ad, dgettext("sys_string", "IDS_COM_BODY_LOW_BATTERY"), cam_app_timeout_notice_response_cb);
8436                 return FALSE;
8437         } else if (cam_utils_check_battery_warning_low()) {
8438                 ad->battery_status = LOW_BATTERY_WARNING_STATUS;
8439                 cam_app_notice_popup((void *)ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_USE_FLASH_BATTERY_LOW"), cam_app_lowbattery_close_flash_cb);
8440         } else {
8441                 ad->battery_status = NORMAL_BATTERY_STATUS;
8442         }
8443
8444         if (cam_utils_check_call_running()) {
8445                 ad->is_calling = TRUE;
8446                 cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA_DURING_CALL"), cam_app_timeout_notice_response_cb);
8447                 return FALSE;
8448         } else
8449                 ad->is_calling = FALSE;
8450
8451         return TRUE;
8452 }
8453
8454 static Eina_Bool __cam_continuous_af_timer_cb(void *data)
8455 {
8456         DEBUG_TRACE("");
8457
8458         struct appdata *ad = (struct appdata *)data;
8459         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
8460
8461         if (ad->continuous_af_timer)
8462                 ad->continuous_af_timer = NULL;
8463
8464         cam_reset_focus_mode(ad);
8465
8466         return ECORE_CALLBACK_CANCEL;
8467 }
8468
8469 void cam_reset_focus_mode(void *data)
8470 {
8471         DEBUG_TRACE("");
8472
8473         struct appdata *ad = (struct appdata *)data;
8474         cam_retm_if(ad == NULL, "appdata is NULL");
8475         CamAppData *camapp = ad->camapp_handle;
8476         cam_retm_if(camapp == NULL, "camapp is NULL");
8477
8478         if (ad->caf_button)
8479                 cam_toolbar_show_cafbutton(ad, FALSE);
8480
8481         cam_reset_focus_coordinate(ad);
8482
8483         camapp->touch_af_state = CAM_TOUCH_AF_STATE_NONE;
8484         camapp->focus_state = CAM_FOCUS_STATUS_RELEASED;
8485
8486         cam_app_focus_guide_create(ad);
8487         cam_app_focus_guide_update(ad);
8488
8489         cam_continuous_af_start(ad);
8490 }
8491
8492 static Eina_Bool __focus_guide_destroy(void *data)
8493 {
8494         DEBUG_TRACE("");
8495
8496         struct appdata *ad = (struct appdata *)data;
8497         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
8498
8499         if (ad->continuous_af_timer)
8500                 ad->continuous_af_timer = NULL;
8501         DEL_EVAS_OBJECT(ad->focus_edje);
8502
8503         return ECORE_CALLBACK_CANCEL;
8504 }
8505
8506
8507 gboolean cam_set_default_capture_mode(void *data, CamCaptureMode type)
8508 {
8509         DEBUG_TRACE("");
8510
8511         struct appdata *ad = (struct appdata *)data;
8512         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
8513         CamAppData *camapp = ad->camapp_handle;
8514         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
8515
8516         if (camapp->camera_mode == CAM_CAMERA_MODE
8517                 && camapp->shooting_mode == CAM_SINGLE_MODE
8518                 && camapp->burst_shot == TRUE) {
8519
8520                 camapp->default_capture_mode = type;
8521                 if (camapp->default_capture_mode == CAM_CAPTURE_BURST)
8522                         camapp->capture_cb = (camera_capturing_cb)cam_continuous_shot_capture_callback;
8523                 else
8524                         camapp->capture_cb = (camera_capturing_cb)__cam_capture_cb;
8525
8526         } else
8527                 return FALSE;
8528
8529
8530         return TRUE;
8531 }
8532
8533 gint cam_app_get_max_image_size_by_ratio(void *data, int resolution)
8534 {
8535         struct appdata *ad = (struct appdata *)data;
8536         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
8537         CamAppData *camapp = ad->camapp_handle;
8538         cam_retvm_if(camapp == NULL, FALSE, "camapp_handle is NULL");
8539
8540         gint result = 0;
8541         unsigned int capacity = 0;
8542         gdouble ratio = (gdouble) CAM_RESOLUTION_W(resolution) / CAM_RESOLUTION_H(resolution);
8543
8544         GetCamDevCamResolutionCaps(&capacity, ad);
8545
8546         if (ratio == (gdouble)4.0/3.0) {
8547                 if (capacity & CAM_CP_SIZE_3264X2448)
8548                         result = CAM_RESOLUTION_3264x2448;
8549                 else if (capacity & CAM_CP_SIZE_2048X1536)
8550                         result = CAM_RESOLUTION_2048x1536;
8551                 else if (capacity & CAM_CP_SIZE_1280X960)
8552                         result = CAM_RESOLUTION_1280x960;
8553                 else
8554                         result = CAM_RESOLUTION_VGA;
8555         } else if (ratio == (gdouble)16.0/9.0) {
8556                 if (capacity & CAM_CP_SIZE_3264X1836)
8557                         result = CAM_RESOLUTION_3264x1836;
8558                 else if (capacity & CAM_CP_SIZE_2048X1152)
8559                         result = CAM_RESOLUTION_2048x1152;
8560                 else if (capacity & CAM_CP_SIZE_1280X720)
8561                         result = CAM_RESOLUTION_1280x720;
8562                 else
8563                         result = CAM_RESOLUTION_VGA;
8564         } else if (ratio == (gdouble)3.0/2.0) {
8565                 if (capacity & CAM_CP_SIZE_3264X2176)
8566                         result = CAM_RESOLUTION_3264x2176;
8567                 else
8568                         result = CAM_RESOLUTION_VGA;
8569         } else {
8570                 result = CAM_RESOLUTION_VGA;
8571         }
8572
8573         return result;
8574 }
8575
8576 void cam_app_stop_capture(void* data)
8577 {
8578         cam_retm_if(data == NULL, "data is null");
8579         struct appdata *ad = (struct appdata *)data;
8580
8581         CamAppData *camapp = ad->camapp_handle;
8582         cam_retm_if(camapp == NULL, "camapp is null");
8583
8584         if (camapp->camera_mode == CAM_CAMERA_MODE) {
8585                 if (camapp->shooting_mode == CAM_SINGLE_MODE) {
8586                         if (camapp->continuous_shot_data && camapp->continuous_shot_data->capture_status == CAM_CONTI_SHOT_STATUS_CAPTURING) {
8587                                 if (cam_is_enabled_menu((void*)ad, CAM_MENU_BURST_SHOT_MODE) && camapp->burst_shot == TRUE && camapp->default_capture_mode == CAM_CAPTURE_BURST) {
8588                                         DEBUG_TRACE("burst capture mode");
8589                                         cam_mm_set_conti_shot_break(TRUE);
8590                                         ad->emit_continuous_shutter = FALSE;
8591                                         cam_app_destroy_progressbar(ad);
8592                                         camapp->continuous_shot_data->capture_status = CAM_CONTI_SHOT_STATUS_STOPPED;
8593                                 }
8594                         }
8595                 }
8596         }
8597 }
8598 void cam_create_error_popup(void* data)
8599 {
8600         cam_retm_if(data == NULL, "data is null");
8601         struct appdata *ad = (struct appdata *)data;
8602
8603         if( ad->error_type == CAM_ERROR_TYPE_UNABLE_TO_LAUNCH){
8604                 if (ad->fw_error_type == CAMERA_ERROR_SOUND_POLICY ||ad->fw_error_type == RECORDER_ERROR_SOUND_POLICY) {
8605                         cam_app_notice_popup(data, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA_DURING_CALL"), cam_app_timeout_notice_response_cb);
8606                 }else{
8607                         cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA"), cam_app_timeout_notice_response_cb);
8608                 }
8609         }
8610 }
8611
8612 static Eina_Bool __cam_app_display_error_popup_idler(void *data)
8613 {
8614         debug_fenter(LOG_CAM);
8615         struct appdata *ad = (struct appdata *)data;
8616         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
8617
8618         if (ad->battery_status == LOW_BATTERY_CRITICAL_STATUS){
8619                 cam_app_notice_popup(ad, dgettext("sys_string", "IDS_COM_BODY_LOW_BATTERY"), cam_app_timeout_notice_response_cb);
8620         } else if (ad->is_calling == TRUE) {
8621                 cam_app_notice_popup(ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_START_CAMERA_DURING_CALL"), cam_app_timeout_notice_response_cb);
8622         } else if(ad->battery_status == LOW_BATTERY_WARNING_STATUS){
8623                 cam_app_notice_popup((void *)ad, dgettext(PACKAGE, "IDS_CAM_POP_UNABLE_TO_USE_FLASH_BATTERY_LOW"), cam_app_lowbattery_close_flash_cb);
8624         }
8625
8626         return ECORE_CALLBACK_CANCEL;
8627 }
8628
8629 //end file