7a9224a5b6f5ea4b91f02f03c74b75f907406225
[apps/osp/Camera.git] / src / CmCameraPresentationModel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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  * @file                CmCameraPresentationModel.cpp
19  * @brief               This is the implementation file for CameraPresentationModel class.
20  */
21
22 #include <cstdlib>
23 #include "CmCameraPresentationModel.h"
24 #include "CmCameraSettingsPresentationModel.h"
25
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Content;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Io;
32 using namespace Tizen::Locales;
33 using namespace Tizen::Media;
34 using namespace Tizen::System;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37
38 static const long RECORD_DEFAULT_SEC = 60000;
39 static const long SECONDS_PER_MINUTE = 60;
40 static const int MAX_FULL_FILE_PATH = 100;
41 static const bool CAPTURE_NORMAL_MODE = 0;
42 static const bool CAPTURE_BURST_MODE = 1;
43 static const int MAX_CAMERA_EXPOSURE_VALUE = 8;
44 static const int PREVIEW_RESOLOTION_WIDTH = 640;
45 static const int PREVIEW_RESOLOTION_HEIGHT = 480;
46 static const int PREVIEW_RESOLOTION_WVGA_WIDTH = 320;
47 static const int PREVIEW_RESOLOTION_WVGA_HEIGHT = 240;
48 static const int SEARCH_PAGE_NO = 1;
49 static const long INIT = -1;
50
51 static const wchar_t* STRING_SDCARD_MOUNTED_STATE = L"Mounted";
52 static const wchar_t* STRING_KEY_STORAGE_PHONE = L"http://tizen.org/runtime/storage.available.internal.media";
53 static const wchar_t* STRING_KEY_STORAGE_SDCARD = L"http://tizen.org/runtime/storage.available.external";
54 static const wchar_t* STRING_CAMCORDER_TEMPORARY_FILE = L"data/temp.mp4";
55 static const wchar_t* STRING_CAMCORDER_TEMPORARY_FILE_EXT = L"Camera/temp.mp4";
56 static const wchar_t* STRING_CAMERA_CAPTURED_ERROR = L"Captured Error";
57 static const wchar_t* STRING_VIDEO_RECORDER_CLOSED_ERROR = L"Video Recorder Closed Error";
58 static const wchar_t* STRING_VIDEO_RECORDER_END_REACHED_ERROR = L"Video Recorder End Reached Error";
59 static const String STRING_CONTENT_CAMERA_PATH = Environment::GetMediaPath() + L"Camera";
60 static const String STRING_CONTENT_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera";
61 static const String CONTENT_INFO_ORDER = L"ContentName";
62 static const wchar_t* EMPTY_SPACE = L"";
63
64 CameraPresentationModel* CameraPresentationModel::__pPresentationModel = null;
65
66 typedef struct
67 {
68         Tizen::Ui::OrientationStatus orientation;
69         CameraSelection camType;
70         RecordingRotation rotate;
71 }_RecordingRotationTable;
72
73 static const _RecordingRotationTable _RecordRotate[] =
74 {
75         {ORIENTATION_STATUS_PORTRAIT, CAMERA_PRIMARY, RECORDING_ROTATION_90},
76         {ORIENTATION_STATUS_LANDSCAPE, CAMERA_PRIMARY, RECORDING_ROTATION_NONE},
77         {ORIENTATION_STATUS_PORTRAIT_REVERSE, CAMERA_PRIMARY, RECORDING_ROTATION_180},
78         {ORIENTATION_STATUS_LANDSCAPE_REVERSE, CAMERA_PRIMARY, RECORDING_ROTATION_270},
79
80         {ORIENTATION_STATUS_PORTRAIT, CAMERA_SECONDARY, RECORDING_ROTATION_90},
81         {ORIENTATION_STATUS_LANDSCAPE, CAMERA_SECONDARY, RECORDING_ROTATION_NONE},
82         {ORIENTATION_STATUS_PORTRAIT_REVERSE, CAMERA_SECONDARY, RECORDING_ROTATION_180},
83         {ORIENTATION_STATUS_LANDSCAPE_REVERSE, CAMERA_SECONDARY, RECORDING_ROTATION_270},
84 };
85
86 enum CamSetExifOrientationMode
87 {
88         CAM_SET_EXIF_ORIENTATION_MODE_NONE = 0,
89         CAM_SET_EXIF_ORIENTATION_MODE_PORTRAIT,
90         CAM_SET_EXIF_ORIENTATION_MODE_LANDSCAPE,
91         CAM_SET_EXIF_ORIENTATION_MODE_PORTRAIT_REVERSE,
92         CAM_SET_EXIF_ORIENTATION_MODE_LANDSCAPE_REVERSE,
93 };
94
95 CameraPresentationModel::CameraPresentationModel(void)
96         : __pCamera(null)
97         , __pPreviewResolutionList(null)
98         , __pCaptureResolutionList(null)
99         , __pRecordingResolutionList(null)
100         , __pIsoList(null)
101         , __pVideoRecorder(null)
102         , __pCameraListener(null)
103 #if 0
104         , __pContentManager(null)
105         , __pImageContentInfo(null)
106         , __pVideoContentInfo(null)
107 #endif
108         , __pCameraSettingsPresentationModel(null)
109         , __pBitmap(null)
110         , __latestContentName(L"")
111         , __errorResult(L"")
112         , __appControlRequestType(APP_CONTROL_REQUEST_TYPE_CANCELED)
113         , __dir(ORIENTATION_STATUS_NONE)
114         , __cameraMode(CAMERA_MODE_SNAPSHOT)
115         , __storageCardState(STORAGE_CARD_STATE_UNMOUNT)
116         , __storageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN)
117         , __isStopCaptured(false)
118         , __contentCount(0)
119         , __onVideoRecorderStarted(false)
120         , __displayResolution(DISPLAY_RESOLUTION_HD)
121         , __startPreviewException(false)
122         , __isCancelRecord(false)
123         , __isInitCamera(false)
124         , __isPreviewExit(false)
125         , __isIntervalTimerRun(false)
126         ,__recorderStopException(false)
127         ,__memoryFullException(false)
128 ,__pCurrentSource(SOURCE_FORM_CAMERA)
129         ,__recorderError(RECORDER_ERROR_OUT_OF_STORAGE)
130 {
131         AppLogDebug("ENTER");
132         AppLogDebug("EXIT");
133 }
134
135 CameraPresentationModel::~CameraPresentationModel(void)
136 {
137         AppLogDebug("ENTER");
138         result r = E_SUCCESS;
139
140         if (__isInitCamera == true)
141         {
142                 if (__pVideoRecorder != null)
143                 {
144                         AppLogDebug("VideoRecorder State[%d]", __pVideoRecorder->GetState());
145
146                         if (__pVideoRecorder->GetState()== RECORDER_STATE_RECORDING
147                                 || __pVideoRecorder->GetState() == RECORDER_STATE_STARTING
148                                 || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSING
149                                 || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSED
150                         )
151                         {
152                                 r = __pVideoRecorder->Stop();
153                                 TryReturnVoid(r == E_SUCCESS, "__pVideoRecorder::Stop() [%s]", GetErrorMessage(r));
154                         }
155
156                         if (__pVideoRecorder->GetState()== RECORDER_STATE_STOPPING
157                                 || __pVideoRecorder->GetState() == RECORDER_STATE_STOPPED
158                         )
159                         {
160                                 r = __pVideoRecorder->Close();
161                                 TryReturnVoid(r == E_SUCCESS, "__pVideoRecorder::Close() [%s]", GetErrorMessage(r));
162                         }
163
164                         delete __pVideoRecorder;
165                         __pVideoRecorder = null;
166                 }
167
168                 if (__pCamera != null)
169                 {
170                         AppLogDebug("Camera State[%d]", __pCamera->GetState());
171
172                         if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
173                         {
174                                 r = __pCamera->StopPreview();
175                                 TryReturnVoid(r == E_SUCCESS, "Camera::StopPreview() [%s]", GetErrorMessage(r));
176                         }
177
178                         if (__pCamera->IsPoweredOn() == true)
179                         {
180                                 r = __pCamera->PowerOff();
181                                 TryReturnVoid(r == E_SUCCESS, "Camera::PowerOff() [%s]", GetErrorMessage(r));
182                         }
183
184                         delete __pCamera;
185                         __pCamera = null;
186                 }
187         }
188         else
189         {
190                 if (__pCamera != null)
191                 {
192                         delete __pCamera;
193                         __pCamera = null;
194                 }
195         }
196
197         if (__pPreviewResolutionList)
198         {
199                 __pPreviewResolutionList->RemoveAll(true);
200                 delete __pPreviewResolutionList;
201                 __pPreviewResolutionList = null;
202         }
203
204         if (__pCaptureResolutionList)
205         {
206                 __pCaptureResolutionList->RemoveAll(true);
207                 delete __pCaptureResolutionList;
208                 __pCaptureResolutionList = null;
209         }
210
211         if (__pRecordingResolutionList)
212         {
213                 __pRecordingResolutionList->RemoveAll(true);
214                 delete __pRecordingResolutionList;
215                 __pRecordingResolutionList = null;
216         }
217
218         if (__pIsoList)
219         {
220                 __pIsoList->RemoveAll(true);
221                 delete __pIsoList;
222                 __pIsoList = null;
223         }
224
225 #if 0
226         if (__pContentManager)
227         {
228                 delete __pContentManager;
229         }
230         if (__pImageContentInfo)
231         {
232                 delete __pImageContentInfo;
233         }
234         if (__pVideoContentInfo)
235         {
236                 delete __pVideoContentInfo;
237         }
238 #endif
239
240         if (__pBitmap)
241         {
242                 delete __pBitmap;
243         }
244
245         __isInitCamera = false;
246
247         __isStopCaptured = false;
248
249         __contentCount = 0;
250
251         __onVideoRecorderStarted = false;
252
253         __isPreviewExit = false;
254
255         __isIntervalTimerRun = false;
256
257         __displayResolution = DISPLAY_RESOLUTION_HD;
258
259         RemoveDeviceManagerEventListner();
260
261         __pCameraSettingsPresentationModel = null;
262         AppLogDebug("EXIT");
263 }
264
265 result
266 CameraPresentationModel::CreateThumbnail(int currentCameraMode)
267 {
268         AppLogDebug("ENTER");
269         String latestContentName = L"";
270         result r = E_SUCCESS;
271         String filePath;
272         int storageType = 0;
273
274         delete __pBitmap;
275         __pBitmap = null;
276
277         r = GetLatestContentName(currentCameraMode, latestContentName);
278         AppLogDebug("latestContentName : %ls",latestContentName.GetPointer());
279         TryCatch(r == E_SUCCESS, , "GetLatestContentName() fail[%s]", GetErrorMessage(r));
280
281         if (currentCameraMode == CAMERA_MODE_SNAPSHOT)
282         {
283                 __pBitmap = CmUtility::CreateThumbnailN(latestContentName, CONTENT_TYPE_IMAGE);
284
285                 if (latestContentName == L"")
286                 {
287                         __pBitmap = null;
288                 }
289         }
290         else
291         {
292                 r = GetValue(STORAGE_TYPE, storageType);
293
294                 if (storageType == STORAGE_TYPE_PHONE)
295                 {
296                         filePath = Environment::GetMediaPath();
297                 }
298                 else
299                 {
300                         filePath = Environment::GetExternalStoragePath();
301                 }
302
303                 filePath.Append(STRING_CAMERA_FOLDER_NAME);
304                 filePath.Append("/");
305                 filePath.Append(__CurrentVideoFileName);
306                 if (!File::IsFileExist(filePath) || __CurrentVideoFileName.IsEmpty())
307                 {
308                         AppLogDebug("Latest content name is %ls",latestContentName.GetPointer());
309                         __pBitmap = CmUtility::CreateThumbnailN(latestContentName,CONTENT_TYPE_VIDEO);
310                 }
311
312                 else
313                 {
314                         AppLogDebug("Current content name is %ls",__CurrentVideoFileName.GetPointer());
315                         __pBitmap = CmUtility::CreateThumbnailN(__CurrentVideoFileName,CONTENT_TYPE_VIDEO);
316                 }
317
318                 if (latestContentName == L"")
319                 {
320                         __pBitmap = null;
321                 }
322         }
323
324         if (__pBitmap == null)
325         {
326                 AppLogDebug("__pBitmap : null");
327         }
328
329         AppLogDebug("EXIT");
330         return r;
331
332 CATCH:
333         AppLogDebug("EXIT - CATCH");
334         return r;
335 }
336
337 bool
338 CameraPresentationModel::IsExistThumbnail(int currentCameraMode)
339 {
340         AppLogDebug("ENTER");
341         String latestContentName = L"";
342         result r = E_SUCCESS;
343         Bitmap* pThumbnailBitmap = null;
344
345         r = GetLatestContentName(currentCameraMode, latestContentName);
346         if (r != E_SUCCESS)
347         {
348                 AppLogDebug("GetLatestContentName() fail[%s]", GetErrorMessage(r));
349                 return false;
350         }
351
352         if (currentCameraMode == CAMERA_MODE_SNAPSHOT)
353         {
354                 pThumbnailBitmap = CmUtility::CreateThumbnailN(latestContentName, CONTENT_TYPE_IMAGE);
355
356                 if (pThumbnailBitmap != null)
357                 {
358                         delete pThumbnailBitmap;
359                         pThumbnailBitmap = null;
360                 }
361
362                 if (latestContentName == L"")
363                 {
364                         AppLogDebug("EXIT - FILE NOT FOUND");
365                         return false;
366                 }
367                 else
368                 {
369                         AppLogDebug("EXIT");
370                         return true;
371                 }
372         }
373         else
374         {
375                 pThumbnailBitmap = CmUtility::CreateThumbnailN(latestContentName, CONTENT_TYPE_VIDEO);
376
377                 if (pThumbnailBitmap != null)
378                 {
379                         delete pThumbnailBitmap;
380                         pThumbnailBitmap = null;
381                 }
382
383                 if (latestContentName == L"")
384                 {
385                         AppLogDebug("EXIT - FILE NOT FOUND");
386                         return false;
387                 }
388                 else
389                 {
390                         AppLogDebug("EXIT");
391                         return true;
392                 }
393         }
394 }
395
396 Tizen::Base::String
397 CameraPresentationModel::GetfilePath(int storageType)
398 {
399         AppLogDebug("ENTER");
400         result r = E_SUCCESS;
401         String filePath = L"";
402
403         if (storageType == STORAGE_TYPE_MEMORYCARD)
404         {
405                 r = filePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", Environment::GetExternalStoragePath().GetPointer(), STRING_CAMERA_FOLDER);
406                 TryCatch(r == E_SUCCESS, , "String::Format() fail[%s]", GetErrorMessage(r));
407         }
408         else if (storageType == STORAGE_TYPE_PHONE)
409         {
410                 r = filePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", Environment::GetMediaPath().GetPointer(), STRING_CAMERA_FOLDER);
411                 TryCatch(r == E_SUCCESS, , "String::Format() fail[%s]", GetErrorMessage(r));
412         }
413         else
414         {
415                 r = filePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", Environment::GetMediaPath().GetPointer(), STRING_CAMERA_FOLDER);
416                 TryCatch(r == E_SUCCESS, , "String::Format() fail[%s]", GetErrorMessage(r));
417         }
418
419         AppLogDebug("EXIT - filePath : %ls", filePath.GetPointer());
420         return filePath;
421
422 CATCH:
423         AppLogDebug("EXIT - CATCH");
424         return filePath;
425 }
426
427 result
428 CameraPresentationModel::CreateFileName(Tizen::Base::String& fullFileName)
429 {
430         AppLogDebug("ENTER");
431         String* pFilePath = null;
432         String* pFileName = null;
433         int storageType = 0;
434         int currentCameraMode = 0;
435         result r = E_SUCCESS;
436         bool checkFileAvailability = false;
437         String updatedFileName;
438         int currentNameCount = 0;
439         String currentFileName;
440         String fileExtension;
441         int fileExtensionLength = 0;
442         int generatedFileLength = 0;
443
444         r = GetValue(STORAGE_TYPE, storageType);
445         TryCatch(r == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(r));
446
447         r = GetValue(CURRENT_MODE, currentCameraMode);
448         TryCatch(r == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(r));
449
450         pFilePath = new (std::nothrow) String();
451         pFileName = new (std::nothrow) String();
452
453         r = CmUtility::GetDirectoryPath(storageType, *pFilePath);
454         TryCatch(r == E_SUCCESS, , "GetDirectoryPath() fail[%s]", GetErrorMessage(r));
455
456         r = CmUtility::GetFileName(currentCameraMode, *pFileName);
457         TryCatch(r == E_SUCCESS, , "GetFileName() fail[%s]", GetErrorMessage(r));
458
459         updatedFileName.Clear();
460         updatedFileName.Format(MAX_FULL_FILE_PATH, L"%ls%ls", pFilePath->GetPointer(), pFileName->GetPointer());
461         currentFileName = *pFileName;
462         checkFileAvailability = File::IsFileExist(updatedFileName);
463
464         generatedFileLength = pFileName->GetLength();
465         if (checkFileAvailability)
466         {
467                 if (currentCameraMode == CameraPresentationModel::CAMERA_MODE_SNAPSHOT)
468                 {
469                         r = fileExtension.Append(STRING_EXTENSION_JPG);
470                         TryCatch(r == E_SUCCESS, , "fileName::Append() fail[%s]", GetErrorMessage(r));
471                 }
472                 else
473                 {
474                         r = fileExtension.Append(STRING_EXTENSION_MP4);
475                         TryCatch(r == E_SUCCESS, , "fileName::Append() fail[%s]", GetErrorMessage(r));
476                 }
477                 fileExtensionLength = fileExtension.GetLength();
478         }
479
480         while (checkFileAvailability)
481         {
482                 currentNameCount++;
483                 currentFileName.Clear();
484                 currentFileName = *pFileName;
485                 currentFileName.Remove(generatedFileLength -fileExtensionLength,fileExtensionLength);
486                 AppLogDebug("filename after remove is %ls",currentFileName.GetPointer());
487                 currentFileName.Append("_");
488                 currentFileName.Append(currentNameCount);
489                 if (currentCameraMode == CameraPresentationModel::CAMERA_MODE_SNAPSHOT)
490                 {
491                         currentFileName.Append(STRING_EXTENSION_JPG);
492                 }
493                 else
494                 {
495                         currentFileName.Append(STRING_EXTENSION_MP4);
496                 }
497                 updatedFileName.Clear();
498                 updatedFileName.Format(MAX_FULL_FILE_PATH, L"%ls%ls", pFilePath->GetPointer(), currentFileName.GetPointer());
499                 checkFileAvailability = File::IsFileExist(updatedFileName);
500         }
501
502         if (currentNameCount != 0)
503         {
504                 pFileName->Clear();
505                 pFileName->Append(currentFileName);
506                 AppLogDebug("updated file name is %ls",pFileName->GetPointer());
507         }
508
509         fullFileName.Clear();
510         r = fullFileName.Format(MAX_FULL_FILE_PATH, L"%ls%ls", pFilePath->GetPointer(), pFileName->GetPointer());
511         TryCatch(r == E_SUCCESS, , "String::Format() fail[%s]", GetErrorMessage(r));
512
513         delete pFilePath;
514         pFilePath = null;
515
516         delete pFileName;
517         pFileName = null;
518
519         AppLogDebug("EXIT - pFullFileName %ls", fullFileName.GetPointer());
520         return r;
521
522 CATCH:
523         AppLogDebug("EXIT - CATCH");
524         delete pFilePath;
525         pFilePath = null;
526
527         delete pFileName;
528         pFileName = null;
529
530         return r;
531 }
532
533 void
534 CameraPresentationModel::CreateInstance(void)
535 {
536         AppLogDebug("ENTER");
537         __pPresentationModel = new (std::nothrow) CameraPresentationModel();
538
539         result r = __pPresentationModel->Construct();
540
541         if (IsFailed(r))
542         {
543                 delete __pPresentationModel;
544                 __pPresentationModel = null;
545                 return;
546         }
547
548 //      std::atexit(DestroyInstance);
549         AppLogDebug("EXIT");
550 }
551
552 void
553 CameraPresentationModel::DestroyInstance(void)
554 {
555         AppLogDebug("ENTER");
556         delete __pPresentationModel;
557         __pPresentationModel = null;
558         AppLogDebug("EXIT");
559 }
560
561 CameraPresentationModel*
562 CameraPresentationModel::GetInstance(void)
563 {
564         AppLogDebug("ENTER");
565         if (__pPresentationModel == null)
566         {
567                 CreateInstance();
568         }
569
570         AppLogDebug("EXIT");
571         return __pPresentationModel;
572 }
573
574 result
575 CameraPresentationModel::Construct(void)
576 {
577         AppLogDebug("ENTER");
578         result r = E_SUCCESS;
579
580         __pCameraSettingsPresentationModel = CameraSettingsPresentationModel::GetInstance();
581         TryCatch(__pCameraSettingsPresentationModel != null, r = E_SYSTEM, "__pCameraSettingsPresentationModel is null");
582
583         SetDeviceManagerEventListner();
584
585         AppLogDebug("EXIT");
586         return r;
587
588 CATCH:
589         AppLogDebug("EXIT - CATCH");
590         return r;
591 }
592
593 void
594 CameraPresentationModel::Terminate(int mode)
595 {
596         AppLogDebug("ENTER Terminate :: mode = %d", mode);
597         result r = E_SUCCESS;
598
599         if (mode == CAMERA_MODE_SNAPSHOT)
600         {
601                 if (__pVideoRecorder != null)
602                 {
603                         AppLogDebug("VideoRecorder State[%d]", __pVideoRecorder->GetState());
604
605                         if (__pVideoRecorder->GetState()== RECORDER_STATE_RECORDING
606                                 || __pVideoRecorder->GetState() == RECORDER_STATE_STARTING
607                                 || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSING
608                                 || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSED
609                         )
610                         {
611                                 r = __pVideoRecorder->Stop();
612                                 TryReturnVoid(r == E_SUCCESS, "__pVideoRecorder::Stop() [%s]", GetErrorMessage(r));
613                         }
614
615                         if (__pVideoRecorder->GetState()== RECORDER_STATE_STOPPING
616                                 || __pVideoRecorder->GetState() == RECORDER_STATE_STOPPED
617                         )
618                         {
619                                 r = __pVideoRecorder->Close();
620                                 TryReturnVoid(r == E_SUCCESS, "__pVideoRecorder::Close() [%s]", GetErrorMessage(r));
621                         }
622
623                         delete __pVideoRecorder;
624                         __pVideoRecorder = null;
625                 }
626
627                 if (__pCamera != null)
628                 {
629                         AppLogDebug("Camera State[%d]", __pCamera->GetState());
630
631                         if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
632                         {
633                                 r = __pCamera->StopPreview();
634                                 TryReturnVoid(r == E_SUCCESS, "Camera::StopPreview() [%s]", GetErrorMessage(r));
635                         }
636
637                         if (__pCamera->IsPoweredOn() == true)
638                         {
639                                 r = __pCamera->PowerOff();
640
641                                 AppLogDebug("Camera::PowerOff() [%s]", GetErrorMessage(r));
642
643                                 if (r == E_DEVICE_BUSY)
644                                 {
645                                         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_PREVIEW_START_FAILED);
646                                 }
647                         }
648
649                         delete __pCamera;
650                         __pCamera = null;
651                 }
652         }
653         else if (mode == CAMERA_MODE_RECORD)
654         {
655                 if (__pCamera != null)
656                 {
657                         AppLogDebug("Camera State[%d]", __pCamera->GetState());
658
659                         if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
660                         {
661                                 r = __pCamera->StopPreview();
662                                 TryReturnVoid(r == E_SUCCESS, "Camera::StopPreview() [%s]", GetErrorMessage(r));
663                         }
664
665                         if (__pCamera->IsPoweredOn() == true)
666                         {
667                                 r = __pCamera->PowerOff();
668
669                                 AppLogDebug("Camera::PowerOff() [%s]", GetErrorMessage(r));
670
671                                 if (r == E_DEVICE_BUSY)
672                                 {
673                                         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_PREVIEW_START_FAILED);
674                                 }
675                         }
676
677                         delete __pCamera;
678                         __pCamera = null;
679                 }
680
681                 if (__pVideoRecorder != null)
682                 {
683                         AppLogDebug("VideoRecorder State[%d]", __pVideoRecorder->GetState());
684
685                         if (__pVideoRecorder->GetState()== RECORDER_STATE_RECORDING
686                                 || __pVideoRecorder->GetState() == RECORDER_STATE_STARTING
687                                 || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSING
688                                 || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSED
689                         )
690                         {
691                                 r = __pVideoRecorder->Stop();
692                                 TryReturnVoid(r == E_SUCCESS, "__pVideoRecorder::Stop() [%s]", GetErrorMessage(r));
693                         }
694
695                         if (__pVideoRecorder->GetState()== RECORDER_STATE_STOPPING
696                                 || __pVideoRecorder->GetState() == RECORDER_STATE_STOPPED
697                         )
698                         {
699                                 r = __pVideoRecorder->Close();
700                                 TryReturnVoid(r == E_SUCCESS, "__pVideoRecorder::Close() [%s]", GetErrorMessage(r));
701                         }
702
703                         delete __pVideoRecorder;
704                         __pVideoRecorder = null;
705                 }
706         }
707         AppLogDebug("EXIT");
708 }
709
710 result
711 CameraPresentationModel::InitializeFlashMode(void)
712 {
713         AppLogDebug("ENTER");
714         result r = E_SUCCESS;
715         int flashMode = 0;
716         int selfPortraitEnable = 0;
717
718         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
719         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
720         {
721                 r = GetMediaCapability(CAMERA_PRIMARY_FLASH_MODE);
722         }
723         else
724         {
725                 r = GetMediaCapability(CAMERA_SECONDARY_FLASH_MODE);
726         }
727
728         if (r == E_SUCCESS)
729         {
730                 if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
731                 {
732                         r = GetValue(FLASH_MODE_PRIMARY, flashMode);
733                 }
734                 else
735                 {
736                         r = GetValue(FLASH_MODE_SECONDARY, flashMode);
737                 }
738                 TryCatch(r == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(r));
739
740                 AppLogDebug("flashMode = %d", flashMode);
741                 SetFlashMode(CameraFlashMode(flashMode));
742         }
743
744         AppLogDebug("EXIT");
745         return r;
746
747 CATCH:
748         AppLogDebug("EXIT - CATCH");
749         return r;
750 }
751
752 result
753 CameraPresentationModel::InitializeCamera(void)
754 {
755         AppLogDebug("ENTER");
756         Dimension* pCaptureResolution = null;
757         int selfPortraitEnable = 0;
758         int captureResolutionCount = 0;
759         result r = E_SUCCESS;
760         int resolutionIndex = 0;
761
762         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
763         TryCatch(r == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(r));
764         
765         if (selfPortraitEnable == CameraPresentationModel::CAM_SELF_PORTRAIT_MODE_PRIMARY)
766         {
767                 r = GetValue(PRIMARY_RESOLUTION_INDEX, resolutionIndex);
768                 TryCatch(r == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(r));
769         }
770         else
771         {
772                 r = GetValue(SECONDARY_RESOLUTION_INDEX, resolutionIndex);
773                 TryCatch(r == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(r));
774         }
775
776         if (__pCamera == null)
777         {
778                 __pCamera = new (std::nothrow) Camera();
779                 TryCatch(__pCamera != null, , "[FAILURE] new (std::nothrow) Camera()");
780
781                 if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
782                 {
783                         AppLogDebug("CAMERA_PRIMARY_MODE !!!");
784                         r = __pCamera->Construct(*this, CAMERA_PRIMARY);
785                 }
786                 else
787                 {
788                         AppLogDebug("CAMERA_SECONDARY_MODE !!!");
789                         r = __pCamera->Construct(*this, CAMERA_SECONDARY);
790                 }
791                 TryCatch(r == E_SUCCESS, , "__pCamera->Construct() [%s]", GetErrorMessage(r));
792         }
793
794         r = __pCamera->PowerOn();
795         TryCatch(r == E_SUCCESS, , "Camera::PowerOn fail[%s]", GetErrorMessage(r));
796
797         r = SetCameraPreviewResolution();
798         TryCatch(r == E_SUCCESS, , "Camera::SetCameraPreviewResolution fail[%s]", GetErrorMessage(r));
799
800         __pCaptureResolutionList = __pCamera->GetSupportedCaptureResolutionListN();
801         TryCatch(__pCaptureResolutionList != null, , "pCaptureResolutionList is null");
802
803         captureResolutionCount = __pCaptureResolutionList->GetCount();
804         AppLogDebug("__pCaptureResolutionList Count : %d", captureResolutionCount);
805
806
807         pCaptureResolution = static_cast< Dimension*>(__pCaptureResolutionList->GetAt(captureResolutionCount -1 - resolutionIndex));
808         TryCatch(pCaptureResolution != null, , "pCaptureResolution is null");
809
810         r = __pCamera->SetCaptureResolution(*pCaptureResolution);
811         TryCatch(r == E_SUCCESS, , "Camera::SetCaptureResolution fail[%s]", GetErrorMessage(r));
812
813         AppLogDebug("EXIT");
814         return r;
815
816 CATCH:
817         AppLogDebug("EXIT - CATCH");
818
819         if ( __pCamera != null )                        //Deleting Camera if something goes wrong.
820         {
821                 delete __pCamera;
822                 __pCamera = null;
823         }
824         if (__pPreviewResolutionList)
825         {
826                 __pPreviewResolutionList->RemoveAll(true);
827         }
828
829         delete __pPreviewResolutionList;
830         __pPreviewResolutionList = null;
831
832         if (__pCaptureResolutionList)
833         {
834                 __pCaptureResolutionList->RemoveAll(true);
835         }
836
837         delete __pCaptureResolutionList;
838         __pCaptureResolutionList = null;
839
840         __isInitCamera = false;
841         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_INITIALIZE_FAILED);
842
843         return r;
844 }
845
846 result
847 CameraPresentationModel::SetCameraPreviewResolution(void)
848 {
849         AppLogDebug("ENTER");
850         Dimension* pPreviewResolution = null;
851         Dimension PreviewResolutionDim;
852         Dimension tempDimention(PREVIEW_RESOLOTION_WIDTH, PREVIEW_RESOLOTION_HEIGHT);
853         Dimension tempDimentionWvga(PREVIEW_RESOLOTION_WVGA_WIDTH, PREVIEW_RESOLOTION_WVGA_HEIGHT);
854         int previewResolutionCount = 0;
855         int previewResolutionIdx = 0;
856         int idx = 0;
857         result r = E_SUCCESS;
858
859         if (__pPreviewResolutionList == null)
860         {
861                 __pPreviewResolutionList = __pCamera->GetSupportedPreviewResolutionListN();
862                 TryCatch(__pPreviewResolutionList != null, , "__pPreviewResolutionList is null");
863
864                 previewResolutionCount = __pPreviewResolutionList->GetCount();
865                 AppLogDebug("pPreviewResolutionList Count : %d", previewResolutionCount);
866
867                 if (previewResolutionCount > 0)
868                 {
869                         for (idx = 0; idx < previewResolutionCount; idx++)
870                         {
871                                 pPreviewResolution = static_cast<Dimension*>(__pPreviewResolutionList->GetAt(idx));
872
873                                 AppLogDebug("InitializeCamcorder pPreviewResolution w:%d,h:%d", pPreviewResolution->width, pPreviewResolution->height);
874
875                                 if (GetDisplayResolutionType() == DISPLAY_RESOLUTION_WVGA)
876                                 {
877                                         AppLogDebug("DISPLAY_RESOLUTION_WVGA");
878                                         if (*pPreviewResolution == tempDimentionWvga)
879                                         {
880                                                 previewResolutionIdx = idx;
881                                                 break;
882                                         }
883                                 }
884                                 else
885                                 {
886                                         if (*pPreviewResolution == tempDimention)
887                                         {
888                                                 previewResolutionIdx = idx;
889                                                 break;
890                                         }
891                                 }
892                         }
893                 }
894
895                 pPreviewResolution = static_cast<Dimension*>(__pPreviewResolutionList->GetAt(previewResolutionIdx));
896                 TryCatch(pPreviewResolution != null, , "pPreviewResolution is null");
897
898                 AppLogDebug("InitializeCamcorder::pPreviewResolution w:%d,h:%d", pPreviewResolution->width, pPreviewResolution->height);
899
900                 r = __pCamera->SetPreviewResolution(*pPreviewResolution);
901                 TryCatch(r == E_SUCCESS, , "Camera::SetPreviewResolution fail[%s]", GetErrorMessage(r));
902         }
903         else
904         {
905                 PreviewResolutionDim = __pCamera->GetPreviewResolution();
906
907                 AppLogDebug("InitializeCamcorder::pPreviewResolution w:%d,h:%d", PreviewResolutionDim.width, PreviewResolutionDim.height);
908
909                 r = __pCamera->SetPreviewResolution(PreviewResolutionDim);
910                 TryCatch(r == E_SUCCESS, , "Camera::SetPreviewResolution fail[%s]", GetErrorMessage(r));
911         }
912
913         AppLogDebug("EXIT");
914         return r;
915
916 CATCH:
917         AppLogDebug("EXIT - CATCH");
918         if (__pPreviewResolutionList)
919         {
920                 __pPreviewResolutionList->RemoveAll(true);
921                 delete __pPreviewResolutionList;
922                 __pPreviewResolutionList = null;
923         }
924         return r;
925 }
926
927 result
928 CameraPresentationModel::SetCamcorderRecordingResolution(void)
929 {
930         AppLogDebug("ENTER");
931         Dimension* pRecordingResolution = null;
932         Dimension RecordingResolutionDim;
933         Dimension tempDimention(PREVIEW_RESOLOTION_WIDTH, PREVIEW_RESOLOTION_HEIGHT);
934         Dimension tempDimentionWvga(PREVIEW_RESOLOTION_WVGA_WIDTH, PREVIEW_RESOLOTION_WVGA_HEIGHT);
935         int recordingResolutionCount = 0;
936         int recordingResolutionIdx = 0;
937         int idx = 0;
938         result r = E_SUCCESS;
939
940         if (__pRecordingResolutionList == null)
941         {
942                 __pRecordingResolutionList = __pVideoRecorder->GetSupportedRecordingResolutionListN();
943                 TryCatch(__pRecordingResolutionList != null, , "__pRecordingResolutionList is null");
944
945                 recordingResolutionCount = __pRecordingResolutionList->GetCount();
946                 AppLogDebug("__pRecordingResolutionList Count : %d", recordingResolutionCount);
947
948                 if (recordingResolutionCount > 0)
949                 {
950                         for (idx = 0; idx < recordingResolutionCount; idx++)
951                         {
952                                 pRecordingResolution = static_cast<Dimension*>(__pRecordingResolutionList->GetAt(idx));
953
954                                 AppLogDebug("pRecordingResolution w:%d,h:%d", pRecordingResolution->width, pRecordingResolution->height);
955
956                                 if (GetDisplayResolutionType() == DISPLAY_RESOLUTION_WVGA)
957                                 {
958                                         AppLogDebug("DISPLAY_RESOLUTION_WVGA");
959                                         if (*pRecordingResolution == tempDimentionWvga)
960                                         {
961                                                 recordingResolutionIdx = idx;
962                                                 __pCamera->SetPreviewResolution(tempDimentionWvga);
963                                                 break;
964                                         }
965                                 }
966                                 else
967                                 {
968                                         if (*pRecordingResolution == tempDimention)
969                                         {
970                                                 __pCamera->SetPreviewResolution(tempDimention);
971                                                 recordingResolutionIdx = idx;
972                                                 break;
973                                         }
974                                 }
975                         }
976                 }
977
978                 pRecordingResolution = static_cast<Dimension*>(__pRecordingResolutionList->GetAt(recordingResolutionIdx));
979                 TryCatch(pRecordingResolution != null, , "pRecordingResolution is null");
980
981                 AppLogDebug("pRecordingResolution w:%d,h:%d", pRecordingResolution->width, pRecordingResolution->height);
982
983                 r = __pVideoRecorder->SetRecordingResolution(*pRecordingResolution);
984                 TryCatch(r == E_SUCCESS, , "VideoRecorder::SetRecordingResolution() fail[%s]", GetErrorMessage(r));
985         }
986         else
987         {
988                 RecordingResolutionDim = __pVideoRecorder->GetRecordingResolution();
989
990                 AppLogDebug("pPreviewResolution w:%d,h:%d", RecordingResolutionDim.width, RecordingResolutionDim.height);
991
992                 if (__pVideoRecorder->GetState() != RECORDER_STATE_STOPPING)
993                 {
994                         __pVideoRecorder->SetRecordingResolution(RecordingResolutionDim);
995                         TryCatch(r == E_SUCCESS, , "VideoRecorder::SetRecordingResolution() fail[%s]", GetErrorMessage(r));
996                 }
997         }
998
999         AppLogDebug("EXIT");
1000         return r;
1001
1002 CATCH:
1003         AppLogDebug("EXIT - CATCH");
1004         if (__pRecordingResolutionList)
1005         {
1006                 __pRecordingResolutionList->RemoveAll(true);
1007         }
1008
1009         delete __pRecordingResolutionList;
1010         __pRecordingResolutionList = null;
1011         return r;
1012 }
1013
1014 result
1015 CameraPresentationModel::InitializeCamcorder(void)
1016 {
1017         AppLogDebug("ENTER");
1018         int selfPortraitEnable = 0;
1019         result r = E_SUCCESS;
1020
1021         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1022         TryCatch(r == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(r));
1023
1024         if (__pCamera == null)
1025         {
1026                 __pCamera = new (std::nothrow) Camera();
1027                 TryCatch(__pCamera != null, , "[FAILURE] new (std::nothrow) Camera()");
1028
1029                 if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
1030                 {
1031                         AppLogDebug("CAMERA_PRIMARY_MODE !!!");
1032                         r = __pCamera->Construct(*this, CAMERA_PRIMARY);
1033                 }
1034                 else
1035                 {
1036                         AppLogDebug("CAMERA_SECONDARY_MODE !!!");
1037                         r = __pCamera->Construct(*this, CAMERA_SECONDARY);
1038                 }
1039                 TryCatch(r == E_SUCCESS, , "__pCamera->Construct() [%s]", GetErrorMessage(r));
1040         }
1041
1042         if( __pCamera->IsPoweredOn() == false)
1043         {
1044                 r = __pCamera->PowerOn();
1045                 TryCatch(r == E_SUCCESS, , "Camera::PowerOn fail[%s]", GetErrorMessage(r));
1046         }
1047         else
1048         {
1049                 AppLogDebug("Camera was already powered on");
1050         }
1051
1052         if (__pVideoRecorder == null)
1053         {
1054                 __pVideoRecorder = new (std::nothrow) VideoRecorder();
1055                 __pVideoRecorder->Construct(*this, *__pCamera);
1056         }
1057
1058         r = SetCameraPreviewResolution();
1059         TryCatch(r == E_SUCCESS, , "SetCameraPreviewResolution fail[%s]", GetErrorMessage(r));
1060
1061         r = SetCamcorderRecordingResolution();
1062         TryCatch(r == E_SUCCESS, , "SetCamcorderRecordingResolution fail[%s]", GetErrorMessage(r));
1063
1064         AppLogDebug("EXIT");
1065         return r;
1066
1067 CATCH:
1068         AppLogDebug("EXIT - CATCH");
1069         if (__pPreviewResolutionList)
1070         {
1071                 __pPreviewResolutionList->RemoveAll(true);
1072                 delete __pPreviewResolutionList;
1073                 __pPreviewResolutionList = null;
1074         }
1075
1076         __isInitCamera = false;
1077         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_INITIALIZE_FAILED);
1078
1079         return r;
1080 }
1081
1082 result
1083 CameraPresentationModel::ToggleCameraCamcorder(int mode)
1084 {
1085         AppLogDebug("ENTER");
1086         Dimension PreviewResolutionDim;
1087         result r = E_SUCCESS;
1088
1089         if (mode == CAMERA_MODE_SNAPSHOT)
1090         {
1091                 r = __pCamera->PowerOn();
1092                 TryCatch(r == E_SUCCESS, , "Camera::PowerOn fail[%s]", GetErrorMessage(r));
1093         }
1094         else if (mode == CAMERA_MODE_RECORD)
1095         {
1096                 r = __pCamera->PowerOn();
1097                 TryCatch(r == E_SUCCESS, , "Camera::PowerOn fail[%s]", GetErrorMessage(r));
1098
1099                 r = SetCameraPreviewResolution();
1100                 TryCatch(r == E_SUCCESS, , "ToggleCameraCamcorder::SetCameraPreviewResolution fail[%s]", GetErrorMessage(r));
1101
1102                 r = SetCamcorderRecordingResolution();
1103                 TryCatch(r == E_SUCCESS, , "ToggleCameraCamcorder::SetCamcorderRecordingResolution fail[%s]", GetErrorMessage(r));
1104         }
1105
1106         AppLogDebug("EXIT");
1107         return r;
1108
1109 CATCH:
1110         AppLogDebug("EXIT - CATCH");
1111         return r;
1112 }
1113
1114 result
1115 CameraPresentationModel::ToggleCameraDirection(int mode, int direction)
1116 {
1117         AppLogDebug("ENTER");
1118         result r = E_SUCCESS;
1119         int captureResolutionCount = 0;
1120         Dimension* pCaptureResolution = null;
1121
1122         Terminate(mode);
1123
1124         __pCamera = new (std::nothrow) Camera();
1125         TryCatch(__pCamera != null, , "[FAILURE] new (std::nothrow) Camera()");
1126
1127         if (direction == CAMERA_DIRECTION_BACK)
1128         {
1129                 AppLogDebug("BACK");
1130
1131                 r = __pCamera->Construct(*this, CAMERA_PRIMARY);
1132                 TryCatch(r == E_SUCCESS, , "__pCamera->Construct() [%s]", GetErrorMessage(r));
1133         }
1134         else if (direction == CAMERA_DIRECTION_FRONT)
1135         {
1136                 AppLogDebug("FRONT");
1137
1138                 r = __pCamera->Construct(*this, CAMERA_SECONDARY);
1139                 TryCatch(r == E_SUCCESS, , "__pCamera->Construct() [%s]", GetErrorMessage(r));
1140         }
1141
1142         r = __pCamera->PowerOn();
1143         TryCatch(r == E_SUCCESS, , "__pCamera->PowerOn() [%s]", GetErrorMessage(r));
1144
1145         if (mode == CAMERA_MODE_RECORD)
1146         {
1147                 if (__pVideoRecorder == null)
1148                 {
1149                         __pVideoRecorder = new (std::nothrow) VideoRecorder();
1150                         __pVideoRecorder->Construct(*this, *__pCamera);
1151                 }
1152         }
1153
1154         if (mode == CAMERA_MODE_SNAPSHOT && direction == CAMERA_DIRECTION_FRONT)
1155         {
1156                 __pCaptureResolutionList = __pCamera->GetSupportedCaptureResolutionListN();
1157                 TryCatch(__pCaptureResolutionList != null, , "pCaptureResolutionList is null");
1158
1159                 captureResolutionCount = __pCaptureResolutionList->GetCount();
1160
1161                 pCaptureResolution = static_cast< Dimension*>(__pCaptureResolutionList->GetAt(captureResolutionCount - 1));
1162                 TryCatch(pCaptureResolution != null, , " pCaptureResolution->GetAt()");
1163
1164                 r = __pCamera->SetCaptureResolution(*pCaptureResolution);
1165                 TryCatch(r == E_SUCCESS, , "Camera::SetCaptureResolution fail[%s]", GetErrorMessage(r));
1166         }
1167
1168         if (direction == CAMERA_DIRECTION_FRONT)
1169         {
1170                 SetFlip(CAMERA_FLIP_HORIZONTAL);
1171         }
1172
1173         AppLogDebug("EXIT");
1174         return r;
1175
1176 CATCH:
1177         AppLogDebug("EXIT - CATCH");
1178         if (__pCaptureResolutionList)
1179         {
1180                 __pCaptureResolutionList->RemoveAll(true);
1181         }
1182
1183         delete __pCaptureResolutionList;
1184         __pCaptureResolutionList = null;
1185
1186         __isInitCamera = false;
1187         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_INITIALIZE_FAILED);
1188
1189         return r;
1190 }
1191
1192 bool
1193 CameraPresentationModel::GetInitCameraStatus(void) const
1194 {
1195         AppLogDebug("ENTER");
1196         AppLogDebug("EXIT - __isInitCamera = %d", __isInitCamera);
1197         return __isInitCamera;
1198 }
1199
1200 result
1201 CameraPresentationModel::SetMode(int mode)
1202 {
1203         AppLogDebug("ENTER");
1204         result r = E_SUCCESS;
1205         String contentSubDirectory = STRING_CAMERA_FOLDER_NAME;
1206         Directory contentDirectory;
1207         int cameraSelfPortraitEnable = CAM_SELF_PORTRAIT_MODE_PRIMARY;
1208         int camcorderSelfPortraitEnable = CAM_SELF_PORTRAIT_MODE_PRIMARY;
1209         int direction = CAMERA_DIRECTION_BACK;
1210         int selfPortraitEnable = 0;
1211
1212         AppLogDebug("SetMode __SetMode = %d && mode = %d", __cameraMode, mode);
1213
1214         if (__pCamera != null)
1215         {
1216                 if (__pCamera->IsPoweredOn() == true)
1217                 {
1218                         AppLogDebug("StopCamera or Terminate");
1219
1220                         __pCameraSettingsPresentationModel->GetValue(SECTION_CAMERA, SELF_PORTRAIT_ENABLE, cameraSelfPortraitEnable);
1221
1222                         __pCameraSettingsPresentationModel->GetValue(SECTION_CAMCORDER, SELF_PORTRAIT_ENABLE, camcorderSelfPortraitEnable);
1223
1224                         AppLogDebug("SECTION_CAMERA mode = %d && SECTION_CAMCORDER mode = %d", cameraSelfPortraitEnable, camcorderSelfPortraitEnable);
1225
1226                         GetMediaCapability(CAMERA_SECONDARY_DIRECTION, direction);
1227
1228                         if ((cameraSelfPortraitEnable == CAM_SELF_PORTRAIT_MODE_SECONDARY && camcorderSelfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
1229                                 || (cameraSelfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY && camcorderSelfPortraitEnable == CAM_SELF_PORTRAIT_MODE_SECONDARY)
1230                         )
1231                         {
1232                                 if (__cameraMode == mode && direction == CAMERA_DIRECTION_FRONT)
1233                                 {
1234                                         AppLogDebug("StopCamera");
1235                                         StopCamera();
1236                                 }
1237                                 else
1238                                 {
1239                                         AppLogDebug("Terminate");
1240                                         Terminate(mode);
1241                                 }
1242                         }
1243                         else
1244                         {
1245                                 AppLogDebug("StopCamera");
1246                                 StopCamera();
1247                         }
1248                 }
1249         }
1250
1251         if (mode == CAMERA_MODE_SNAPSHOT)
1252         {
1253                 if (__pCamera == null)
1254                 {
1255                         AppLogDebug("CAMERA_MODE_SNAPSHOT::NOT_INITIALIZED");
1256
1257 #if 0                   //Not in use
1258                         if (__pContentManager == null)
1259                         {
1260                                 __pContentManager = new (std::nothrow) ContentManager();
1261
1262                                 r = __pContentManager->Construct();
1263                                 TryCatch(r == E_SUCCESS, , "__pContentManager->Construct [%s]", GetErrorMessage(r));
1264                         }
1265                         if (__pImageContentInfo == null)
1266                         {
1267                                 __pImageContentInfo = new (std::nothrow) ImageContentInfo();
1268                                 r = __pImageContentInfo->Construct(null);
1269                                 TryCatch(r == E_SUCCESS, , "__pImageContentInfo->Construct [%s]", GetErrorMessage(r));
1270                         }
1271 #endif
1272
1273                         r = CreateThumbnail(CAMERA_MODE_SNAPSHOT);
1274                         AppLogDebug("CreateThumbnail [%s]", GetErrorMessage(r));
1275
1276                         r = InitializeCamera();
1277                         TryCatch(r == E_SUCCESS, , "InitializeCamera [%s]", GetErrorMessage(r));
1278
1279                         r = InitializeFlashMode();
1280                         AppLogDebug("InitFlashMode fail [%s]", GetErrorMessage(r));
1281
1282                         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1283                         if (r != E_SUCCESS)
1284                         {
1285                                 selfPortraitEnable = CAM_SELF_PORTRAIT_MODE_PRIMARY;
1286                         }
1287
1288                         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_SECONDARY)
1289                         {
1290                                 SetFlip(CAMERA_FLIP_HORIZONTAL);
1291                         }
1292                 }
1293                 else if (__pCamera != null)
1294                 {
1295                         AppLogDebug("CAMERA_MODE_SNAPSHOT::INITIALIZED");
1296
1297                         r = CreateThumbnail(CAMERA_MODE_SNAPSHOT);
1298                         AppLogDebug("CreateThumbnail [%s]", GetErrorMessage(r));
1299
1300                         r = ToggleCameraCamcorder(CAMERA_MODE_SNAPSHOT);
1301                         TryCatch(r == E_SUCCESS, , "ToggleCameraCamcorder [%s]", GetErrorMessage(r));
1302                 }
1303         }
1304         else if (mode == CAMERA_MODE_RECORD)
1305         {
1306                 if (__pCamera == null)
1307                 {
1308                         AppLogDebug("CAMERA_MODE_RECORD::NOT_INITIALIZED");
1309 #if 0                   //varialbe not in use
1310                         if (__pContentManager == null)
1311                         {
1312                                 __pContentManager = new (std::nothrow) ContentManager();
1313
1314                                 r =  __pContentManager->Construct();
1315                                 TryCatch(r == E_SUCCESS, , "__pContentManager->Construct [%s]", GetErrorMessage(r));
1316                         }
1317                         if (__pVideoContentInfo == null)
1318                         {
1319                                 __pVideoContentInfo = new (std::nothrow) VideoContentInfo();
1320
1321                                 r = __pVideoContentInfo->Construct(null);
1322                                 TryCatch(r == E_SUCCESS, , "__pVideoContentInfo->Construct [%s]", GetErrorMessage(r));
1323                         }
1324 #endif
1325
1326                         r = CreateThumbnail(CAMERA_MODE_RECORD);
1327                         AppLogDebug("CreateThumbnail [%s]", GetErrorMessage(r));
1328
1329                         r = InitializeCamcorder();
1330                         TryCatch(r == E_SUCCESS, , "InitializeCamcorder [%s]", GetErrorMessage(r));
1331
1332                         r = InitializeFlashMode();
1333                         AppLogDebug("InitFlashMode fail [%s]", GetErrorMessage(r));
1334
1335                         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1336                         if (r != E_SUCCESS)
1337                         {
1338                                 selfPortraitEnable = CAM_SELF_PORTRAIT_MODE_PRIMARY;
1339                         }
1340
1341                         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_SECONDARY)
1342                         {
1343                                 SetFlip(CAMERA_FLIP_HORIZONTAL);
1344                         }
1345                 }
1346                 else if (__pCamera != null)
1347                 {
1348                         AppLogDebug("CAMERA_MODE_RECORD::INITIALIZED");
1349
1350                         if (__pVideoRecorder == null)
1351                         {
1352                                 __pVideoRecorder = new (std::nothrow) VideoRecorder();
1353                                 __pVideoRecorder->Construct(*this, *__pCamera);
1354                         }
1355
1356                         r = CreateThumbnail(CAMERA_MODE_RECORD);
1357                         AppLogDebug("CreateThumbnail [%s]", GetErrorMessage(r));
1358
1359                         r = ToggleCameraCamcorder(CAMERA_MODE_RECORD);                  
1360                         TryCatch(r == E_SUCCESS, , "ToggleCameraCamcorder [%s]", GetErrorMessage(r));
1361                         InitializeFlashMode();
1362                 }
1363         }
1364         __cameraMode = mode;
1365
1366         __isInitCamera = true;
1367
1368         AppLogDebug("EXIT");
1369         return r;
1370
1371 CATCH:
1372         AppLogDebug("EXIT - CATCH");
1373         __isInitCamera = false;
1374         return r;
1375 }
1376
1377 Tizen::Graphics::Bitmap*
1378 CameraPresentationModel::GetLatestThumbnail(void)
1379 {
1380         AppLogDebug("ENTER");
1381         if (__pBitmap)
1382         {
1383                 AppLogDebug("__pBitmap NOT null");
1384                 AppLogDebug("EXIT");
1385                 return __pBitmap;
1386         }
1387         else
1388         {
1389                 AppLogDebug("__pBitmap null");
1390                 AppLogDebug("EXIT");
1391                 return null;
1392         }
1393 }
1394
1395 int
1396 CameraPresentationModel::GetContentCount(void)
1397 {
1398         AppLogDebug("ENTER");
1399         AppLogDebug("EXIT");
1400         return __contentCount;
1401 }
1402
1403 Tizen::Base::Collection::ArrayList*
1404 CameraPresentationModel::GetContentPathListN(int mode)
1405 {
1406         AppLogDebug("ENTER");
1407         result r = E_SUCCESS;
1408         ContentDirectory contentDirectory;
1409         IList* pContentList = null;
1410         String contentFullPath = L"";
1411         String filePath = L"";
1412         String combineText = L"";
1413         int storageType = 0;
1414         int countPerPage = 0;
1415         ArrayList* pContentPath = null;
1416
1417         r = GetValue(STORAGE_TYPE, storageType);
1418         if (r != E_SUCCESS)
1419         {
1420                 storageType = STORAGE_TYPE_PHONE;
1421         }
1422
1423         if (storageType == STORAGE_TYPE_MEMORYCARD)
1424         {
1425                 filePath = STRING_CONTENT_CAMERA_PATH_EXT;
1426         }
1427         else if (storageType == STORAGE_TYPE_PHONE)
1428         {
1429                 filePath = STRING_CONTENT_CAMERA_PATH;
1430         }
1431         AppLogDebug("SearchContentFilePath :: pFilePath = %ls", filePath.GetPointer());
1432
1433         if (mode == CAMERA_MODE_SNAPSHOT)
1434         {
1435                 r = contentDirectory.Construct(CONTENT_TYPE_IMAGE);
1436         }
1437         else
1438         {
1439                 r = contentDirectory.Construct(CONTENT_TYPE_VIDEO);
1440         }
1441         TryCatch(r == E_SUCCESS, , "contentDirectory.Construct[%s]", GetErrorMessage(r));
1442
1443         countPerPage = contentDirectory.GetContentDirectoryItemCount(filePath);
1444         AppLogDebug("SearchContentFilePath :: countPerPage = %d", countPerPage);
1445
1446         pContentList = contentDirectory.GetContentDirectoryItemListN(filePath,
1447                                                                                                                 SEARCH_PAGE_NO,
1448                                                                                                                 countPerPage,
1449                                                                                                                 CONTENT_INFO_ORDER,
1450                                                                                                                 SORT_ORDER_ASCENDING);
1451         TryCatch(pContentList != null, , "pContentList is null");
1452
1453         __contentCount = pContentList->GetCount();
1454         AppLogDebug("SearchContentFilePath :: __contentCount = %d", __contentCount);
1455
1456         pContentPath = new (std::nothrow) ArrayList();
1457         pContentPath->Construct();
1458
1459         if ((pContentList != null) && (pContentList->GetCount() > 0))
1460         {
1461                 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1462                 while (pEnum->MoveNext() == E_SUCCESS)
1463                 {
1464                         ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
1465                         contentFullPath = pContentInfo->GetContentPath();
1466
1467                         AppLogDebug("SearchContentFilePath :: contentFullPath = %ls", contentFullPath.GetPointer());
1468
1469                         pContentPath->Add(*(new (std::nothrow) String(contentFullPath)));
1470                 }
1471
1472                 delete pEnum;
1473                 pEnum = null;
1474         }
1475
1476         if (pContentList != null)
1477         {
1478                 pContentList->RemoveAll(true);
1479                 delete pContentList;
1480         }
1481
1482         AppLogDebug("EXIT");
1483         return pContentPath;
1484
1485 CATCH:
1486         AppLogDebug("EXIT - CATCH");
1487         return pContentPath;
1488 }
1489
1490 Tizen::Base::String
1491 CameraPresentationModel::SearchContentFilePath(int mode)
1492 {
1493         AppLogDebug("ENTER");
1494         result r = E_SUCCESS;
1495         ContentDirectory contentDirectory;
1496         IList* pContentList = null;
1497         String contentFullPath = L"";
1498         String filePath = L"";
1499         String combineText = L"";
1500         int storageType = 0;
1501         int countPerPage = 0;
1502
1503         r = GetValue(STORAGE_TYPE, storageType);
1504         if (r != E_SUCCESS)
1505         {
1506                 storageType = STORAGE_TYPE_PHONE;
1507         }
1508
1509         if (storageType == STORAGE_TYPE_MEMORYCARD)
1510         {
1511                 filePath = STRING_CONTENT_CAMERA_PATH_EXT;
1512         }
1513         else if (storageType == STORAGE_TYPE_PHONE)
1514         {
1515                 filePath = STRING_CONTENT_CAMERA_PATH;
1516         }
1517         AppLogDebug("SearchContentFilePath :: pFilePath = %ls", filePath.GetPointer());
1518
1519         if (mode == CAMERA_MODE_SNAPSHOT)
1520         {
1521                 r = contentDirectory.Construct(CONTENT_TYPE_IMAGE);
1522         }
1523         else
1524         {
1525                 r = contentDirectory.Construct(CONTENT_TYPE_VIDEO);
1526         }
1527         TryCatch(r == E_SUCCESS, , "contentDirectory.Construct[%s]", GetErrorMessage(r));
1528
1529         countPerPage = contentDirectory.GetContentDirectoryItemCount(filePath);
1530         AppLogDebug("SearchContentFilePath :: countPerPage = %d", countPerPage);
1531
1532         pContentList = contentDirectory.GetContentDirectoryItemListN(filePath,
1533                                                                                                                         SEARCH_PAGE_NO,
1534                                                                                                                         countPerPage,
1535                                                                                                                         CONTENT_INFO_ORDER,
1536                                                                                                                         SORT_ORDER_ASCENDING);
1537         TryCatch(pContentList != null, , "pContentList is null");
1538
1539         __contentCount = pContentList->GetCount();
1540         AppLogDebug("SearchContentFilePath :: __contentCount = %d", __contentCount);
1541
1542         if ((pContentList != null) && (pContentList->GetCount() > 0))
1543         {
1544                 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1545                 while (pEnum->MoveNext() == E_SUCCESS)
1546                 {
1547                         ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
1548                         contentFullPath = pContentInfo->GetContentPath();
1549
1550                         if (combineText.CompareTo(EMPTY_SPACE) != 0)
1551                         {
1552                                 combineText.Append(L";");
1553                         }
1554
1555                         combineText.Append(contentFullPath);
1556                 }
1557
1558                 delete pEnum;
1559                 pEnum = null;
1560         }
1561
1562         AppLogDebug("SearchContentFilePath :: combineText = %ls", combineText.GetPointer());
1563
1564         if (pContentList != null)
1565         {
1566                 pContentList->RemoveAll(true);
1567                 delete pContentList;
1568         }
1569
1570         AppLogDebug("EXIT");
1571         return combineText;
1572
1573 CATCH:
1574         AppLogDebug("EXIT - CATCH");
1575         return combineText;
1576 }
1577
1578 Tizen::Base::String
1579 CameraPresentationModel::GetContentFilePath(int currentCameraMode)
1580 {
1581         AppLogDebug("ENTER");
1582         String contentFullName = L"";
1583
1584         contentFullName = SearchContentFilePath(currentCameraMode);
1585
1586         AppLogDebug("EXIT");
1587         return contentFullName;
1588 }
1589
1590 result
1591 CameraPresentationModel::GetLatestContentName(int currentCameraMode, Tizen::Base::String& latestContentName)
1592 {
1593         AppLogDebug("ENTER");
1594         String contentSubDirectory = STRING_CAMERA_FOLDER_NAME;
1595         String fileExtension = L"";
1596         String directoryEntryName = L"";
1597         String temporaryEntryName = L"";
1598         Directory contentDirectory;
1599         result r = E_SUCCESS;
1600         DirEnumerator* pDirEnum = null;
1601         DateTime directoryEntryDateTime;
1602         DateTime temporaryEntryDateTime = DateTime::GetMinValue();
1603         int storageType = STORAGE_TYPE_PHONE;
1604
1605         AppLogDebug("__lastestContentName content name is %ls",__latestContentName.GetPointer());
1606
1607         r = GetValue(STORAGE_TYPE, storageType);
1608         TryCatch(r == E_SUCCESS, , "Err catch [%s]", GetErrorMessage(r));
1609
1610         if (storageType == STORAGE_TYPE_PHONE)
1611         {
1612                 r = contentDirectory.Construct(Environment::GetMediaPath().GetPointer() + contentSubDirectory);
1613
1614                 AppLogDebug("GetLatestContentName::contentDirectory.Construct r = %s", GetErrorMessage(r));
1615                 if (r == E_FILE_NOT_FOUND)
1616                 {
1617                         r = contentDirectory.Create((Environment::GetMediaPath().GetPointer() + contentSubDirectory), true);
1618                         TryCatch(r == E_SUCCESS, , "contentDirectory Create Fail");
1619
1620                         contentDirectory.Construct(Environment::GetMediaPath().GetPointer() + contentSubDirectory);
1621                 }
1622         }
1623         else if (storageType == STORAGE_TYPE_MEMORYCARD)
1624         {
1625                 r = contentDirectory.Construct(Environment::GetExternalStoragePath().GetPointer() + contentSubDirectory);
1626
1627                 if (r == E_FILE_NOT_FOUND)
1628                 {
1629                         r = contentDirectory.Create((Environment::GetExternalStoragePath().GetPointer() + contentSubDirectory), true);
1630                         TryCatch(r == E_SUCCESS, , "contentDirectory Create Fail");
1631
1632                         contentDirectory.Construct(Environment::GetExternalStoragePath().GetPointer() + contentSubDirectory);
1633                 }
1634         }
1635
1636         pDirEnum = contentDirectory.ReadN();
1637         AppLogDebug("contentDirectory.ReadN()r = %s", GetErrorMessage(GetLastResult()));
1638         TryCatch(pDirEnum != null, r = E_SYSTEM, "pDirEnum is null");
1639
1640         if (currentCameraMode == CAMERA_MODE_SNAPSHOT)
1641         {
1642                 r = fileExtension.Append(STRING_EXTENSION_JPG);
1643                 TryCatch(r == E_SUCCESS, , "String::Append() fail[%s]", GetErrorMessage(r));
1644         }
1645         else
1646         {
1647                 r = fileExtension.Append(STRING_EXTENSION_MP4);
1648                 TryCatch(r == E_SUCCESS, , "String::Append() fail[%s]", GetErrorMessage(r));
1649         }
1650
1651         while (pDirEnum->MoveNext() == E_SUCCESS)
1652         {
1653                  DirEntry directoryEntry = pDirEnum->GetCurrentDirEntry();
1654                  directoryEntryName = directoryEntry.GetName();
1655                  if (directoryEntryName.Contains(fileExtension))
1656                  {
1657                          directoryEntryDateTime = directoryEntry.GetDateTime();
1658                          AppLogDebug("DirEntry::GetDateTime() name %ls Time %ls", directoryEntryName.GetPointer(), directoryEntryDateTime.ToString().GetPointer());
1659
1660                          if (directoryEntryDateTime > temporaryEntryDateTime)
1661                          {
1662                                  temporaryEntryDateTime = directoryEntryDateTime;
1663                                  temporaryEntryName = directoryEntryName;
1664                                  AppLogDebug("dt_temp change Str %ls Time %ls", temporaryEntryName.GetPointer(), temporaryEntryDateTime.ToString().GetPointer());
1665                          }
1666                  }
1667                  else
1668                  {
1669                          AppLogDebug("Dont Contains(fileExtension)");
1670                  }
1671         }
1672
1673         if (!(temporaryEntryName.IsEmpty()))
1674         {
1675                 latestContentName.Clear();
1676                 r = latestContentName.Append(temporaryEntryName);
1677                 TryCatch(r == E_SUCCESS, , "String::Append() fail[%s]", GetErrorMessage(r));
1678
1679                 AppLogDebug("latestContentName = %ls", latestContentName.GetPointer());
1680         }
1681
1682         delete pDirEnum;
1683         pDirEnum = null;
1684
1685         AppLogDebug("EXIT");
1686         return r;
1687
1688 CATCH:
1689         AppLogDebug("EXIT - CATCH");
1690         delete pDirEnum;
1691         pDirEnum = null;
1692
1693         return r;
1694 }
1695
1696 Tizen::Graphics::Dimension
1697 CameraPresentationModel::GetPreviewResolution(void) const
1698 {
1699         AppLogDebug("ENTER");
1700         Dimension dimension(INIT, INIT);
1701
1702         if (__pCamera != null)
1703         {
1704                 dimension = __pCamera->GetPreviewResolution();
1705         }
1706
1707         AppLogDebug("CameraPresentationModel::GetPreviewResolution(%d, %d)", dimension.width, dimension.height);
1708
1709         AppLogDebug("EXIT");
1710         return dimension;
1711 }
1712
1713 result
1714 CameraPresentationModel::SetPreviewResolution(Tizen::Graphics::Dimension previewResolution)
1715 {
1716         AppLogDebug("ENTER");
1717         result r = E_SUCCESS;
1718
1719         r = __pCamera->SetPreviewResolution(previewResolution);
1720         TryCatch(r == E_SUCCESS, , "Camera::SetPreviewResolution fail[%s]", GetErrorMessage(r));
1721
1722         AppLogDebug("EXIT");
1723         return r;
1724
1725 CATCH:
1726         AppLogDebug("EXIT - CATCH");
1727         return r;
1728 }
1729
1730 Tizen::Graphics::Dimension
1731 CameraPresentationModel::GetCaptureResolution(void) const
1732 {
1733         AppLogDebug("ENTER");
1734         Dimension dimension(INIT, INIT);
1735
1736         if (__pCamera != null)
1737         {
1738                 dimension = __pCamera->GetCaptureResolution();
1739         }
1740
1741         AppLogDebug("CameraPresentationModel::GetCaptureResolution(%d, %d)", dimension.width, dimension.height);
1742
1743         AppLogDebug("EXIT");
1744         return dimension;
1745 }
1746
1747 result
1748 CameraPresentationModel::SetCaptureResolution(Tizen::Graphics::Dimension captureResolution)
1749 {
1750         AppLogDebug("ENTER");
1751         result r = E_SUCCESS;
1752
1753         if (__pCamera != null)
1754         {
1755                 r = __pCamera->SetCaptureResolution(captureResolution);
1756                 TryCatch(r == E_SUCCESS, , "Camera::SetCaptureResolution fail[%s]", GetErrorMessage(r));
1757         }
1758         AppLogDebug("EXIT");
1759         return r;
1760
1761 CATCH:
1762         AppLogDebug("EXIT - CATCH");
1763         return r;
1764 }
1765
1766 Tizen::Graphics::Dimension
1767 CameraPresentationModel::GetRecordingResolution(void) const
1768 {
1769         AppLogDebug("ENTER");
1770         Dimension dimension(INIT, INIT);
1771
1772         if (__pVideoRecorder != null)
1773         {
1774                 dimension = __pVideoRecorder->GetRecordingResolution();
1775         }
1776         AppLogDebug("CameraPresentationModel::GetRecordingResolution(%d, %d)", dimension.width, dimension.height);
1777
1778         AppLogDebug("EXIT");
1779         return dimension;
1780 }
1781
1782 result
1783 CameraPresentationModel::SetRecordingResolution(Tizen::Graphics::Dimension previewResolution)
1784 {
1785         AppLogDebug("ENTER");
1786         result r = E_SUCCESS;
1787
1788         r = __pVideoRecorder->SetRecordingResolution(previewResolution);
1789         TryCatch(r == E_SUCCESS, , "Camera::SetRecordingResolution fail[%s]", GetErrorMessage(r));
1790
1791         AppLogDebug("EXIT");
1792         return r;
1793
1794 CATCH:
1795         AppLogDebug("EXIT - CATCH");
1796         return r;
1797 }
1798
1799 Tizen::Base::Collection::IList*
1800 CameraPresentationModel::GetCaptureResolutionList(void)
1801 {
1802         AppLogDebug("ENTER");
1803         result r = E_SUCCESS;
1804         int selfPortraitEnable = 0;
1805
1806         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1807
1808         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
1809         {
1810                 AppLogDebug("CAM_SELF_PORTRAIT_MODE_PRIMARY");
1811                 __pCaptureResolutionList = MediaCapability::GetValueN(CAMERA_PRIMARY_CAPTURE_RESOLUTION);
1812                 TryCatch(__pCaptureResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1813         }
1814         else
1815         {
1816                 AppLogDebug("CAM_SELF_PORTRAIT_MODE_SECONDARY");
1817                 __pCaptureResolutionList = MediaCapability::GetValueN(CAMERA_SECONDARY_CAPTURE_RESOLUTION);
1818                 TryCatch(__pCaptureResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1819         }
1820
1821         AppLogDebug("EXIT");
1822         return __pCaptureResolutionList;
1823
1824 CATCH:
1825         AppLogDebug("EXIT - CATCH");
1826         if (__pCaptureResolutionList)
1827         {
1828                 __pCaptureResolutionList->RemoveAll(true);
1829         }
1830
1831         delete __pCaptureResolutionList;
1832
1833         __pCaptureResolutionList = null;
1834
1835         return __pCaptureResolutionList;
1836 }
1837
1838 Tizen::Base::Collection::IList*
1839 CameraPresentationModel::GetPreviewResolutionList(void)
1840 {
1841         AppLogDebug("ENTER");
1842         result r = E_SUCCESS;
1843         int selfPortraitEnable = 0;
1844
1845         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1846
1847         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
1848         {
1849                 if (__pPreviewResolutionList != null)
1850                 {
1851                         __pPreviewResolutionList->RemoveAll(true);
1852                         delete __pPreviewResolutionList;
1853                         __pPreviewResolutionList = null;
1854                 }
1855                 __pPreviewResolutionList = MediaCapability::GetValueN(CAMERA_PRIMARY_PREVIEW_RESOLUTION);
1856                 TryCatch(__pPreviewResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1857         }
1858         else
1859         {
1860                 __pPreviewResolutionList = MediaCapability::GetValueN(CAMERA_SECONDARY_PREVIEW_RESOLUTION);
1861                 TryCatch(__pPreviewResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1862         }
1863
1864         AppLogDebug("EXIT");
1865         return __pPreviewResolutionList;
1866
1867 CATCH:
1868         AppLogDebug("EXIT - CATCH");
1869         if (__pPreviewResolutionList)
1870         {
1871                 __pPreviewResolutionList->RemoveAll(true);
1872         }
1873
1874         delete __pPreviewResolutionList;
1875
1876         __pPreviewResolutionList = null;
1877
1878         return __pPreviewResolutionList;
1879 }
1880
1881 Tizen::Base::Collection::IList*
1882 CameraPresentationModel::GetRecordingResolutionList(void)
1883 {
1884         AppLogDebug("ENTER");
1885         result r = E_SUCCESS;
1886         int selfPortraitEnable = 0;
1887
1888         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1889
1890         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
1891         {
1892                 __pRecordingResolutionList = MediaCapability::GetValueN(CAMERA_PRIMARY_RECORDING_RESOLUTION);
1893                 TryCatch(__pRecordingResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1894         }
1895         else
1896         {
1897                 __pRecordingResolutionList = MediaCapability::GetValueN(CAMERA_PRIMARY_RECORDING_RESOLUTION);
1898                 TryCatch(__pRecordingResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1899         }
1900
1901         AppLogDebug("EXIT");
1902         return __pRecordingResolutionList;
1903
1904 CATCH:
1905         AppLogDebug("EXIT - CATCH");
1906         if (__pRecordingResolutionList)
1907         {
1908                 __pRecordingResolutionList->RemoveAll(true);
1909         }
1910
1911         delete __pRecordingResolutionList;
1912
1913         __pRecordingResolutionList = null;
1914
1915         return __pRecordingResolutionList;
1916 }
1917
1918 bool
1919 CameraPresentationModel::IsPreviewState(void)
1920 {
1921         AppLogDebug("ENTER");
1922         if (GetCameraState() == CAMERA_STATE_PREVIEW)
1923         {
1924                 AppLogDebug("IsPreviewState YES");
1925                 AppLogDebug("EXIT");
1926                 return true;
1927         }
1928         else
1929         {
1930                 AppLogDebug("IsPreviewState NOT");
1931                 AppLogDebug("EXIT");
1932                 return false;
1933         }
1934
1935         AppLogDebug("EXIT");
1936         return false;
1937 }
1938
1939 bool
1940 CameraPresentationModel::IsCameraInstance(void)
1941 {
1942         AppLogDebug("ENTER");
1943         if (__pCamera == null)
1944         {
1945                 AppLogDebug("EXIT - __pCamera is null");
1946                 return false;
1947         }
1948
1949         AppLogDebug("EXIT");
1950         return true;
1951 }
1952
1953 bool
1954 CameraPresentationModel::IsCameraPoweredOn(void)
1955 {
1956         AppLogDebug("ENTER");
1957         AppLogDebug("IsPoweredOn State[%d]", __pCamera->IsPoweredOn());
1958         AppLogDebug("EXIT");
1959         return __pCamera->IsPoweredOn();
1960 }
1961
1962 bool
1963 CameraPresentationModel::IsStorageCardMounted(void) const
1964 {
1965         AppLogDebug("ENTER");
1966         String strState = L"";
1967
1968         DeviceManager::GetState(StorageCard, strState);
1969
1970         if (strState == STRING_SDCARD_MOUNTED_STATE)
1971         {
1972                 AppLogDebug("EXIT");
1973                 return true;
1974         }
1975         else
1976         {
1977                 AppLogDebug("EXIT");
1978                 return false;
1979         }
1980 }
1981
1982 bool
1983 CameraPresentationModel::IsCharging(void)
1984 {
1985         AppLogDebug("ENTER");
1986         bool isCharging = false;
1987         isCharging = PowerManager::IsCharging();
1988         AppLogDebug("charging status is %d",isCharging);
1989         AppLogDebug("EXIT");
1990         return isCharging;
1991 }
1992
1993 bool
1994 CameraPresentationModel::GetStartPreviewException(void)
1995 {
1996         AppLogDebug("ENTER");
1997         AppLogDebug("EXIT - Error %d", __startPreviewException);
1998         return __startPreviewException;
1999 }
2000
2001 bool
2002 CameraPresentationModel::GetIntervalTimerRun(void) const
2003 {
2004         AppLogDebug("ENTER");
2005         AppLogDebug("EXIT - __isIntervalTimerRun = %d", __isIntervalTimerRun);
2006         return __isIntervalTimerRun;
2007 }
2008
2009 void
2010 CameraPresentationModel::SetIntervalTimerRun(bool intervalTimerRun)
2011 {
2012         AppLogDebug("ENTER");
2013         __isIntervalTimerRun = intervalTimerRun;
2014         AppLogDebug("EXIT");
2015 }
2016
2017 bool
2018 CameraPresentationModel::GetPreviewState(void) const
2019 {
2020         AppLogDebug("ENTER");
2021         AppLogDebug("EXIT - __isPreviewExit = %d", __isPreviewExit);
2022         return __isPreviewExit;
2023 }
2024
2025 void
2026 CameraPresentationModel::StartPreview(const Tizen::Graphics::BufferInfo* pBufferInfo)
2027 {
2028         AppLogDebug("ENTER");
2029         result r = E_SUCCESS;
2030
2031         AppLogDebug("GetCameraState = %d", __pCamera->GetState());
2032         if (GetCameraState() == CAMERA_STATE_INITIALIZED || GetCameraState() == CAMERA_STATE_CAPTURED)
2033         {
2034                 r = __pCamera->StartPreview(pBufferInfo, false);
2035                 if (r == E_DEVICE_BUSY || r == E_DEVICE_UNAVAILABLE || r == E_SYSTEM)
2036                 {
2037                         __startPreviewException = true;
2038                 }
2039                 else
2040                 {
2041                         __startPreviewException = false;
2042                 }
2043                  __isPreviewExit = true;
2044                 TryReturnVoid(r == E_SUCCESS, "Camera::StartPreview() fail[%s]", GetErrorMessage(r));
2045         }
2046         else
2047         {
2048                 AppLogDebug("Before the StartPreview() method is called, camera state should be CAMERA_STATE_INITIALIZED or CAMERA_STATE_CAPTURED");
2049         }
2050
2051         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_BACK_BUTTON_ACTIVATED);
2052         AppLogDebug("EXIT");
2053 }
2054
2055 void
2056 CameraPresentationModel::StopPreview(void)
2057 {
2058         AppLogDebug("ENTER");
2059         result r = E_SUCCESS;
2060
2061         if (__pCamera != null)
2062         {
2063                 if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
2064                 {
2065                         r = __pCamera->StopPreview();
2066                         TryReturnVoid(r == E_SUCCESS, "Camera::StopPreview() [%s]", GetErrorMessage(r));
2067                 }
2068         }
2069         AppLogDebug("EXIT");
2070 }
2071
2072 void
2073 CameraPresentationModel::StopCamera(void)
2074 {
2075         AppLogDebug("ENTER");
2076         result r = E_SUCCESS;
2077
2078         if (__isInitCamera == false)
2079         {
2080                 AppLogDebug("Camera Construct fail or Memory allocation Fail");
2081                 return;
2082         }
2083
2084         if (__pVideoRecorder != null)
2085         {
2086                 AppLogDebug("VideoRecorder State[%d]", __pVideoRecorder->GetState());
2087
2088                 if (__pVideoRecorder->GetState()== RECORDER_STATE_RECORDING
2089                         || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSED
2090                 )
2091                 {
2092                         r = __pVideoRecorder->Stop();
2093                         TryReturnVoid(r == E_SUCCESS, "__pVideoRecorder::Stop() [%s]", GetErrorMessage(r));
2094                 }
2095         }
2096
2097         if (__pCamera != null)
2098         {
2099                 AppLogDebug("Camera State[%d]", __pCamera->GetState());
2100
2101                 if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
2102                 {
2103                         r = __pCamera->StopPreview();
2104                         TryReturnVoid(r == E_SUCCESS, "Camera::StopPreview() [%s]", GetErrorMessage(r));
2105                 }
2106
2107                 if (__pCamera->IsPoweredOn() == true)
2108                 {
2109                         r = __pCamera->PowerOff();
2110                         TryReturnVoid(r == E_SUCCESS, "Camera::PowerOff() [%s]", GetErrorMessage(r));
2111                 }
2112         }
2113         AppLogDebug("EXIT");
2114 }
2115
2116 void
2117 CameraPresentationModel::Capture(void)
2118 {
2119         AppLogDebug("ENTER");
2120         result r = E_SUCCESS;
2121
2122         if (GetCameraState() == CAMERA_STATE_PREVIEW)
2123         {
2124                 r = __pCamera->Capture();
2125                 TryReturnVoid( r == E_SUCCESS, "Camera::Capture() fail[%s]", GetErrorMessage(r));
2126         }
2127         else
2128         {
2129                 AppLogDebug("Before the Capture() method is called, camera state should be CAMERA_STATE_PREVIEW");
2130         }
2131         AppLogDebug("EXIT");
2132 }
2133
2134 long
2135 CameraPresentationModel::GetMaxRecordingTime(void)
2136 {
2137         AppLogDebug("ENTER");
2138         long getMaxRecordingTime = 0;
2139
2140         getMaxRecordingTime = __pVideoRecorder->GetMaxRecordingTime();
2141
2142         AppLogDebug("GetMaxRecordingTime = %d EXIT", getMaxRecordingTime);
2143         return getMaxRecordingTime;
2144 }
2145
2146 long
2147 CameraPresentationModel::GetRecordingSize(void)
2148 {
2149         AppLogDebug("ENTER");
2150         long getRecordingSize = 0;
2151
2152         getRecordingSize = __pVideoRecorder->GetRecordingSize();
2153
2154         AppLogDebug("EXIT - GetRecordingSize = %d", getRecordingSize);
2155         return getRecordingSize;
2156 }
2157
2158 void
2159 CameraPresentationModel::StartRecord(void)
2160 {
2161         AppLogDebug("ENTER");
2162         String* pFullFileName = null;
2163         result r = E_SUCCESS;
2164         long maxRecordDefaultTime = 0;
2165         String camcorderTemporaryFilePath;
2166         RecordingRotation rotate = RECORDING_ROTATION_NONE;
2167         int storageType = STORAGE_TYPE_PHONE;
2168
2169         __onVideoRecorderStarted = true;
2170
2171         AppLogDebug("Record GetRecorderState = %d", GetRecorderState());
2172         if (GetRecorderState() == RECORDER_STATE_PAUSED || GetRecorderState() == RECORDER_STATE_PAUSING)
2173         {
2174                 AppLogDebug("RECORDER_STATE_PAUSED or RECORDER_STATE_PAUSING ==> RECORDER_STATE_RECORDING");
2175
2176                 r = __pVideoRecorder->Record();
2177                 TryCatch(r == E_SUCCESS, , "VideoRecorder::Record() fail[%s]", GetErrorMessage(r));
2178
2179                 r = SetFlashModeOnRecord(true);
2180                 AppLogDebug("SetFlashModeOnRecord fail[%s]", GetErrorMessage(r));
2181
2182                 AppLogDebug("EXIT");
2183                 return;
2184         }
2185
2186         r = GetValue(STORAGE_TYPE, storageType);
2187         if (r != E_SUCCESS)
2188         {
2189                 storageType = STORAGE_TYPE_PHONE;
2190         }
2191
2192         if (storageType == STORAGE_TYPE_PHONE)
2193         {
2194                 camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", App::GetInstance()->GetAppRootPath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE);
2195         }
2196         else
2197         {
2198                 camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", Environment::GetExternalStoragePath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE_EXT);
2199         }
2200
2201         pFullFileName = new (std::nothrow) String();
2202         r = CreateFileName(*pFullFileName);
2203         TryCatch(r == E_SUCCESS, , "pFullFileName is null");
2204
2205         __latestContentName.Clear();
2206         r = __latestContentName.Append(pFullFileName->GetPointer());
2207         TryCatch(r == E_SUCCESS, , "String::Append() fail[%s]", GetErrorMessage(r));
2208
2209         AppLogDebug("Record pFullFileName = %ls", pFullFileName->GetPointer());
2210         if (__pVideoRecorder == null)
2211         {
2212                 __pVideoRecorder = new (std::nothrow) VideoRecorder();
2213                 __pVideoRecorder->Construct(*this, *__pCamera);
2214         }
2215
2216         r = __pVideoRecorder->SetQuality(RECORDING_QUALITY_HIGH);
2217         TryCatch(r == E_SUCCESS, , "VideoRecorder::SetQuality() fail[%s]", GetErrorMessage(r));
2218
2219         maxRecordDefaultTime = RECORD_DEFAULT_SEC * SECONDS_PER_MINUTE;
2220
2221         r = __pVideoRecorder->SetMaxRecordingTime(maxRecordDefaultTime);
2222         TryCatch(r == E_SUCCESS, , "VideoRecorder::SetMaxRecordingTime() fail[%s]", GetErrorMessage(r));
2223
2224         r = __pVideoRecorder->SetFormat(CODEC_AAC, CODEC_MPEG4, MEDIA_CONTAINER_MP4);
2225         TryCatch(r == E_SUCCESS, , "VideoRecorder::SetFormat() fail[%s]", GetErrorMessage(r));
2226
2227         rotate = GetRecordingRotation();
2228         AppLogDebug("StartRecord rotate = %d",rotate);
2229
2230         r = __pVideoRecorder->SetRecordingRotation(rotate);
2231         TryCatch(r == E_SUCCESS, , "VideoRecorder::SetRecordingRotation() fail[%s]", GetErrorMessage(r));
2232
2233         AppLogDebug("latest file name is %ls",__latestContentName.GetPointer());
2234         r = __pVideoRecorder->CreateVideoFile(__latestContentName, true);
2235         AppLogDebug("create video file result is %s",GetErrorMessage(r));
2236         TryCatch(r == E_SUCCESS, , "VideoRecorder::CreateVideoFile() fail[%s]", GetErrorMessage(r));
2237
2238         r = __pVideoRecorder->Record();
2239         TryCatch(r == E_SUCCESS, , "VideoRecorder::Record() fail[%s]", GetErrorMessage(r));
2240
2241         delete pFullFileName;
2242         pFullFileName = null;
2243
2244         r = SetFlashModeOnRecord(true);
2245         AppLogDebug("SetFlashModeOnRecord fail[%s]", GetErrorMessage(r));
2246
2247         AppLogDebug("EXIT");
2248         return;
2249
2250 CATCH:
2251         AppLogDebug("EXIT - CATCH");
2252         __onVideoRecorderStarted = false;
2253         delete pFullFileName;
2254         pFullFileName = null;
2255 }
2256
2257 void
2258 CameraPresentationModel::SetCancelRecord(bool isCancel)
2259 {
2260         AppLogDebug("ENTER");
2261         __isCancelRecord = isCancel;    
2262         AppLogDebug("EXIT");
2263 }
2264
2265 result
2266 CameraPresentationModel::StopRecord(void)
2267 {
2268         AppLogDebug("ENTER");
2269         result r = E_SUCCESS;
2270
2271         if (__pVideoRecorder != null)
2272         {
2273                 r = __pVideoRecorder->Stop();
2274                 AppLogDebug("stop record result is %s",GetErrorMessage(r));
2275                 //TryReturnVoid(r == E_SUCCESS, "VideoRecorder::Stop() fail[%s]", GetErrorMessage(r));
2276         }
2277         AppLogDebug("EXIT");
2278         return r;
2279 }
2280
2281 void
2282 CameraPresentationModel::CloseRecord(void)
2283 {
2284         AppLogDebug("ENTER");
2285         result r = E_SUCCESS;
2286
2287         if (__pVideoRecorder != null)
2288         {
2289                 r = __pVideoRecorder->Close();
2290                 TryReturnVoid(r == E_SUCCESS, "VideoRecorder::Close() fail[%s]", GetErrorMessage(r));
2291         }
2292         AppLogDebug("EXIT");
2293 }
2294
2295 void
2296 CameraPresentationModel::CancelRecord(void)
2297 {
2298         AppLogDebug("ENTER");
2299         result r = E_SUCCESS;
2300
2301         if (__pVideoRecorder != null)
2302         {
2303                 r = __pVideoRecorder->Cancel();
2304                 TryReturnVoid(r == E_SUCCESS, "VideoRecorder::Cancel() fail[%s]", GetErrorMessage(r));
2305         }
2306         AppLogDebug("EXIT");
2307 }
2308
2309 void
2310 CameraPresentationModel::PauseRecord(void)
2311 {
2312         AppLogDebug("ENTER");
2313         result r = E_SUCCESS;
2314
2315         if (__pVideoRecorder != null)
2316         {
2317                 r = __pVideoRecorder->Pause();
2318                 TryReturnVoid(r == E_SUCCESS, "VideoRecorder::Pause() fail[%s]", GetErrorMessage(r));
2319         }
2320         AppLogDebug("EXIT");
2321 }
2322
2323 void
2324 CameraPresentationModel::SetFlip(CameraFlipType type)
2325 {
2326         AppLogDebug("ENTER");
2327         result r = E_SUCCESS;
2328         int selfPortraitEnable = 0;
2329
2330         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
2331
2332         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
2333         {
2334                 r = GetMediaCapability(CAMERA_PRIMARY_FLIP);
2335         }
2336         else
2337         {
2338                 r = GetMediaCapability(CAMERA_SECONDARY_FLIP);
2339         }
2340
2341         if (r == E_SUCCESS)
2342         {
2343                 r = __pCamera->SetFlip(type);
2344                 TryReturnVoid(r == E_SUCCESS, "Camera::SetFlip() [%s]", GetErrorMessage(r));
2345         }
2346         else
2347         {
2348                 AppLogDebug("SetFlip is not support");
2349         }
2350         AppLogDebug("EXIT");
2351 }
2352
2353 CameraFlipType
2354 CameraPresentationModel::GetFlip(void) const
2355 {
2356         AppLogDebug("ENTER");
2357         AppLogDebug("EXIT");
2358         return __pCamera->GetFlip();
2359 }
2360
2361 void
2362 CameraPresentationModel::SetFocusMode(CameraFocusMode mode)
2363 {
2364         AppLogDebug("ENTER");
2365         result r = E_SUCCESS;
2366
2367         r = __pCamera->SetFocusMode(mode);
2368         TryReturnVoid(r == E_SUCCESS, "Camera::SetFocusMode() [%s]", GetErrorMessage(r));
2369         AppLogDebug("EXIT");
2370 }
2371
2372 void
2373 CameraPresentationModel::SetContinuousAutoFocus(void)
2374 {
2375         AppLogDebug("ENTER");
2376         result r = E_SUCCESS;
2377
2378         if (__pCamera != null)
2379         {
2380                 r = __pCamera->SetFocusMode(CAMERA_FOCUS_MODE_CONTINUOUS_AUTO);
2381                 TryReturnVoid(r == E_SUCCESS, "Camera::SetFocusMode() [%s]", GetErrorMessage(r));
2382
2383                 r = __pCamera->SetAutoFocus(true);
2384                 TryReturnVoid(r == E_SUCCESS, "Camera::SetAutoFocus() [%s]", GetErrorMessage(r));
2385         }
2386         AppLogDebug("EXIT");
2387 }
2388
2389 void
2390 CameraPresentationModel::SetAutoFocusPoint(const Tizen::Graphics::Point& currentPosition)
2391 {
2392         AppLogDebug("ENTER");
2393         result r = E_SUCCESS;
2394         ArrayList currentPositionList;
2395         currentPositionList.Construct();
2396         currentPositionList.Add(currentPosition);
2397
2398         r = __pCamera->SetFocusMode(CAMERA_FOCUS_MODE_NORMAL);
2399         TryReturnVoid(r == E_SUCCESS, "Camera::SetFocusMode() [%s]", GetErrorMessage(r));
2400
2401         r = __pCamera->SetAutoFocusPoint(currentPositionList);
2402         TryReturnVoid(r == E_SUCCESS, "Camera::SetAutoFocusPoint() [%s]", GetErrorMessage(r));
2403
2404         r = __pCamera->SetAutoFocus(true);
2405         TryReturnVoid(r == E_SUCCESS, "Camera::SetAutoFocus() [%s]", GetErrorMessage(r));
2406         AppLogDebug("EXIT");
2407 }
2408
2409 int
2410 CameraPresentationModel::GetExposure(void) const
2411 {
2412         AppLogDebug("ENTER");
2413         int exposureValue = 0;
2414
2415         exposureValue = __pCamera->GetExposure();
2416
2417         AppLogDebug("EXIT");
2418         return exposureValue;
2419 }
2420
2421 void
2422 CameraPresentationModel::SetExposure(int exposureValue)
2423 {
2424         AppLogDebug("ENTER");
2425         result r = E_SUCCESS;
2426
2427         exposureValue = MAX_CAMERA_EXPOSURE_VALUE - exposureValue;
2428
2429         r = __pCamera->SetExposure(exposureValue);
2430         TryReturnVoid(r == E_SUCCESS, "SetExposure() fail[%s]", GetErrorMessage(r));
2431         AppLogDebug("EXIT");
2432 }
2433
2434 int
2435 CameraPresentationModel::GetBrightness(void) const
2436 {
2437         AppLogDebug("ENTER");
2438         int brightnessValue = 0;
2439
2440         brightnessValue = __pCamera->GetBrightness();
2441
2442         AppLogDebug("EXIT");
2443         return brightnessValue;
2444 }
2445
2446 void
2447 CameraPresentationModel::SetBrightness(int brightnessValue)
2448 {
2449         AppLogDebug("ENTER");
2450         result r = E_SUCCESS;
2451
2452         brightnessValue = MAX_CAMERA_EXPOSURE_VALUE - brightnessValue;
2453
2454         r = __pCamera->SetBrightness(brightnessValue);
2455         TryReturnVoid(r == E_SUCCESS, "Camera::SetBrightness() fail[%s]", GetErrorMessage(r));
2456         AppLogDebug("EXIT");
2457 }
2458
2459 CameraWhiteBalance
2460 CameraPresentationModel::GetWhiteBalance(void) const
2461 {
2462         AppLogDebug("ENTER");
2463         CameraWhiteBalance whiteBalanceValue = CAMERA_WHITE_BALANCE_AUTO;
2464
2465         whiteBalanceValue = __pCamera->GetWhiteBalance();
2466
2467         AppLogDebug("EXIT");
2468         return whiteBalanceValue;
2469 }
2470
2471 result
2472 CameraPresentationModel::SetWhiteBalance(CameraWhiteBalance whitebalanceValue)
2473 {
2474         AppLogDebug("ENTER");
2475         result r = E_SUCCESS;
2476
2477         r = __pCamera->SetWhiteBalance(whitebalanceValue);
2478
2479         AppLogDebug("EXIT");
2480         return r;
2481 }
2482
2483 Tizen::Base::Collection::IList*
2484 CameraPresentationModel::GetIsoList(void)
2485 {
2486         AppLogDebug("ENTER");
2487         result r = E_SUCCESS;
2488         int selfPortraitEnable = 0;
2489
2490         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
2491
2492         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
2493         {
2494                 __pIsoList = MediaCapability::GetValueN(CAMERA_PRIMARY_ISO_LEVEL);
2495                 TryCatch(__pIsoList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
2496         }
2497         else
2498         {
2499                 __pIsoList = MediaCapability::GetValueN(CAMERA_SECONDARY_ISO_LEVEL);
2500                 TryCatch(__pIsoList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
2501         }
2502
2503         AppLogDebug("EXIT");
2504         return __pIsoList;
2505
2506 CATCH:
2507         AppLogDebug("EXIT - CATCH");
2508         if (__pIsoList)
2509         {
2510                 __pIsoList->RemoveAll(true);
2511         }
2512
2513         delete __pIsoList;
2514
2515         __pIsoList = null;
2516
2517         return __pIsoList;
2518 }
2519
2520 CameraIsoLevel
2521 CameraPresentationModel::GetIsoLevel(void) const
2522 {
2523         AppLogDebug("ENTER");
2524         CameraIsoLevel isoValue = CAMERA_ISO_DEFAULT;
2525
2526         isoValue = __pCamera->GetIsoLevel();
2527
2528         AppLogDebug("EXIT");
2529         return isoValue;
2530 }
2531
2532 void
2533 CameraPresentationModel::SetIsoLevel(CameraIsoLevel isoValue)
2534 {
2535         AppLogDebug("ENTER");
2536         result r = E_SUCCESS;
2537
2538         r = __pCamera->SetIsoLevel(isoValue);
2539         TryReturnVoid(r == E_SUCCESS, "SetIsoLevel() fail[%s]", GetErrorMessage(r));
2540         AppLogDebug("EXIT");
2541 }
2542
2543 int
2544 CameraPresentationModel::GetMaxZoomLevel(void) const
2545 {
2546         AppLogDebug("ENTER");
2547         int zoomLevel = 0;
2548
2549         zoomLevel = __pCamera->GetMaxZoomLevel();
2550
2551         AppLogDebug("EXIT");
2552         return zoomLevel;
2553 }
2554
2555 int
2556 CameraPresentationModel::GetZoomLevel(void) const
2557 {
2558         AppLogDebug("ENTER");
2559         int zoomLevel = 0;
2560
2561         zoomLevel = __pCamera->GetZoomLevel();
2562
2563         AppLogDebug("EXIT");
2564         return zoomLevel;
2565 }
2566
2567 void
2568 CameraPresentationModel::SetZoomValue(int zoomValue)
2569 {
2570         AppLogDebug("ENTER");
2571         result r = E_SUCCESS;
2572
2573         int currentZoomValue = __pCamera->GetZoomLevel();
2574
2575         if (currentZoomValue < zoomValue)
2576         {
2577                 for (int i = currentZoomValue; i < zoomValue; i++)
2578                 {
2579                         r = __pCamera->ZoomIn();
2580                         TryReturnVoid(r == E_SUCCESS, "ZoomIn() fail[%s]", GetErrorMessage(r));
2581                 }
2582         }
2583         else
2584         {
2585                 for (int i = currentZoomValue; i > zoomValue; i--)
2586                 {
2587                         r = __pCamera->ZoomOut();
2588                         TryReturnVoid(r == E_SUCCESS, "ZoomOut() fail[%s]", GetErrorMessage(r));
2589                 }
2590         }
2591         AppLogDebug("EXIT");
2592 }
2593
2594 CameraFlashMode
2595 CameraPresentationModel::GetFlashMode(void) const
2596 {
2597         AppLogDebug("ENTER");
2598         CameraFlashMode cameraFlashMode = CAMERA_FLASH_MODE_OFF;
2599
2600         cameraFlashMode = __pCamera->GetFlashMode();
2601
2602         AppLogDebug("Get flashMode = %d", cameraFlashMode);
2603
2604         AppLogDebug("EXIT");
2605         return cameraFlashMode;
2606 }
2607
2608 result
2609 CameraPresentationModel::SetFlashModeOnRecord(bool flashOn)
2610 {
2611         AppLogDebug("ENTER");
2612         result ret = E_SUCCESS;
2613         int selfPortraitEnable = 0;
2614         int flashMode = 0;
2615
2616         ret = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
2617         if (ret != E_SUCCESS)
2618         {
2619                 selfPortraitEnable = CAM_SELF_PORTRAIT_MODE_PRIMARY;
2620         }
2621
2622         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
2623         {
2624                 ret = GetMediaCapability(CAMERA_PRIMARY_FLASH_MODE);
2625         }
2626         else
2627         {
2628                 ret = GetMediaCapability(CAMERA_SECONDARY_FLASH_MODE);
2629         }
2630
2631         if (ret == E_SUCCESS)
2632         {
2633                 if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
2634                 {
2635                         ret = __pCameraSettingsPresentationModel->GetValue(SECTION_CAMCORDER, FLASH_MODE_PRIMARY, flashMode);
2636                 }
2637                 else
2638                 {
2639                         ret = __pCameraSettingsPresentationModel->GetValue(SECTION_CAMCORDER, FLASH_MODE_SECONDARY, flashMode);
2640                 }
2641                 TryCatch(ret == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(ret));
2642
2643                 AppLogDebug("flashMode = %d", flashMode);
2644
2645                 if (__pCamera->IsPoweredOn() == true && flashMode == FLASH_TYPE_ON)
2646                 {
2647                         AppLogDebug("SetFlashModeOnRecord flashOn = %d", flashOn);
2648
2649                         if (flashOn)
2650                         {
2651                                 ret = __pCamera->SetFlashMode(CAMERA_FLASH_MODE_CONTINUOUS);
2652                                 TryCatch(ret == E_SUCCESS, , "SetFlashMode() fail[%s]", GetErrorMessage(ret));
2653                         }
2654                         else
2655                         {
2656                                 ret = __pCamera->SetFlashMode(CAMERA_FLASH_MODE_ON); //CAMERA_FLASH_MODE_OFF >>is TAF don't flash on
2657                                 TryCatch(ret == E_SUCCESS, , "SetFlashMode() fail[%s]", GetErrorMessage(ret));
2658                         }
2659                 }
2660                 else
2661                 {
2662                         AppLogDebug("Camera PoweredOff status");
2663                 }
2664         }
2665
2666         AppLogDebug("EXIT");
2667         return ret;
2668
2669 CATCH:
2670         AppLogDebug("EXIT - CATCH");
2671         return ret;
2672 }
2673
2674 result
2675 CameraPresentationModel::SetFlashMode(CameraFlashMode mode)
2676 {
2677         AppLogDebug("ENTER");
2678         result r = E_SUCCESS;
2679
2680         AppLogDebug("Set flashMode = %d", mode);
2681
2682         if (__pCamera != null)
2683         {
2684                 if (mode == CAMERA_FLASH_MODE_OFF)
2685                 {
2686                         if (__pCamera->IsFlashOn())
2687                         {
2688                                 r = __pCamera->SetFlashMode(CAMERA_FLASH_MODE_OFF);
2689                                 AppLogDebug("Set SetFlashMode = %s", GetErrorMessage(r));
2690                         }
2691                 }
2692                 else
2693                 {
2694                         r = __pCamera->SetFlashMode(mode);
2695                         AppLogDebug("Set SetFlashMode = %s", GetErrorMessage(r));
2696                 }
2697         }
2698         else
2699         {
2700                 AppLogDebug("__pCamera is null");
2701                 r = E_FAILURE;
2702         }
2703         AppLogDebug("EXIT");
2704         return r;
2705 }
2706
2707 Tizen::Ui::OrientationStatus
2708 CameraPresentationModel::GetOrientation(void) const
2709 {
2710         AppLogDebug("ENTER");
2711         AppLogDebug("EXIT");
2712         return __dir;
2713 }
2714
2715 void
2716 CameraPresentationModel::SetOrientation(Tizen::Ui::OrientationStatus dir)
2717 {
2718         AppLogDebug("ENTER");
2719         AppLogDebug("EXIT");
2720         __dir = dir;
2721 }
2722
2723 int
2724 CameraPresentationModel::GetAppControlRequestType(void) const
2725 {
2726         AppLogDebug("ENTER");
2727         AppLogDebug("EXIT");
2728         return __appControlRequestType;
2729 }
2730
2731 void
2732 CameraPresentationModel::SetAppControlRequestType(int requestType)
2733 {
2734         AppLogDebug("ENTER");
2735         __appControlRequestType = requestType;
2736         AppLogDebug("EXIT");
2737 }
2738
2739 Tizen::Base::String
2740 CameraPresentationModel::GetErrorResult(void) const
2741 {
2742         AppLogDebug("ENTER");
2743         AppLogDebug("EXIT");
2744         return __errorResult;
2745 }
2746
2747 void
2748 CameraPresentationModel::SetErrorResult(const Tizen::Base::String& string)
2749 {
2750         AppLogDebug("ENTER");
2751         __errorResult = string;
2752         AppLogDebug("EXIT");
2753 }
2754
2755 Tizen::System::BatteryLevel
2756 CameraPresentationModel::GetBatteryLevel(void) const
2757 {
2758         AppLogDebug("ENTER");
2759         BatteryLevel batteryLevel;
2760
2761         batteryLevel = PowerManager::GetCurrentBatteryLevel();
2762
2763         AppLogDebug("EXIT");
2764         return batteryLevel;
2765 }
2766
2767 Tizen::Media::CameraState
2768 CameraPresentationModel::GetCameraState(void) const
2769 {
2770         AppLogDebug("ENTER");
2771         TryCatch(__pCamera != null, , "__pCamera is null");
2772
2773         AppLogDebug("EXIT");
2774         return __pCamera->GetState();
2775
2776 CATCH:
2777         AppLogDebug("EXIT - CATCH");
2778         return CAMERA_STATE_ERROR;
2779 }
2780
2781 Tizen::Media::RecorderState
2782 CameraPresentationModel::GetRecorderState(void) const
2783 {
2784         AppLogDebug("ENTER");
2785         TryCatch(__pVideoRecorder != null, , "__pVideoRecorder is null");
2786
2787         AppLogDebug("EXIT");
2788         return __pVideoRecorder->GetState();
2789
2790 CATCH:
2791         AppLogDebug("EXIT - CATCH");
2792         return RECORDER_STATE_ERROR;
2793 }
2794
2795 long long
2796 CameraPresentationModel::GetAvailableStorageSpace(void) const
2797 {
2798         AppLogDebug("ENTER");
2799         result r = E_SUCCESS;
2800         int storageType = STORAGE_TYPE_PHONE;
2801         long long availableStorageSpace = 0;
2802
2803         r = GetValue(STORAGE_TYPE, storageType);
2804         if (r != E_SUCCESS)
2805         {
2806                 storageType = STORAGE_TYPE_PHONE;       
2807         }
2808
2809         if (storageType == STORAGE_TYPE_PHONE)
2810         {
2811                 String key(STRING_KEY_STORAGE_PHONE);
2812                 r = RuntimeInfo::GetValue(key, availableStorageSpace);
2813                 TryCatch(r == E_SUCCESS, , "To get a value is fail");
2814         }
2815         else if (storageType == STORAGE_TYPE_MEMORYCARD)
2816         {
2817                 if (IsStorageCardMounted() == true)
2818                 {
2819                         String key(STRING_KEY_STORAGE_SDCARD);
2820
2821                         r = RuntimeInfo::GetValue(key, availableStorageSpace);
2822                         TryCatch(r == E_SUCCESS, , "To get a value is fail");
2823                 }
2824                 else
2825                 {
2826                         availableStorageSpace = 0;
2827                 }
2828         }
2829
2830         AppLogDebug("EXIT - availableStorageSpace = %ld", availableStorageSpace);
2831         return availableStorageSpace;
2832
2833 CATCH:
2834         AppLogDebug("EXIT - CATCH");
2835         availableStorageSpace = 0;
2836         return availableStorageSpace;
2837 }
2838
2839 void
2840 CameraPresentationModel::ZoomIn(void)
2841 {
2842         AppLogDebug("ENTER");
2843         result r = E_SUCCESS;
2844
2845         r = __pCamera->ZoomIn();
2846         TryReturnVoid(r == E_SUCCESS, "ZoomIn() fail[%s]", GetErrorMessage(r));
2847         AppLogDebug("EXIT");
2848 }
2849
2850 void
2851 CameraPresentationModel::ZoomOut(void)
2852 {
2853         AppLogDebug("ENTER");
2854         result r = E_SUCCESS;
2855
2856         r = __pCamera->ZoomOut();
2857         TryReturnVoid(r == E_SUCCESS, "ZoomOut() fail[%s]", GetErrorMessage(r));
2858         AppLogDebug("EXIT");
2859 }
2860
2861 result
2862 CameraPresentationModel::SetExifOrientation(int orientation)
2863 {
2864         AppLogDebug("ENTER");
2865         result r = E_SUCCESS;
2866
2867         switch (orientation)
2868         {
2869         case CAM_SET_EXIF_ORIENTATION_MODE_PORTRAIT:
2870                 {
2871                         r = __pCamera->SetExifOrientation(CAMERA_EXIF_ORIENTATION_RIGHT_TOP);
2872                 }
2873                 break;
2874
2875         case CAM_SET_EXIF_ORIENTATION_MODE_PORTRAIT_REVERSE:
2876                 {
2877                         r = __pCamera->SetExifOrientation(CAMERA_EXIF_ORIENTATION_LEFT_BOTTOM);
2878                 }
2879                 break;
2880
2881         case CAM_SET_EXIF_ORIENTATION_MODE_LANDSCAPE:
2882                 {
2883                         r = __pCamera->SetExifOrientation(CAMERA_EXIF_ORIENTATION_TOP_LEFT);
2884                 }
2885                 break;
2886
2887         case CAM_SET_EXIF_ORIENTATION_MODE_LANDSCAPE_REVERSE:
2888                 {
2889                         r = __pCamera->SetExifOrientation(CAMERA_EXIF_ORIENTATION_BOTTOM_RIGHT);
2890                 }
2891                 break;
2892
2893         default:
2894                 break;
2895         }
2896         AppLogDebug("__pCamera->SetExifOrientation() fail[%s]", GetErrorMessage(r));
2897
2898         AppLogDebug("EXIT");
2899         return r;
2900 }
2901
2902 void
2903 CameraPresentationModel::KeepScreenOnState(bool keepOn, bool dimming)
2904 {
2905         result r = E_FAILURE;
2906         AppLogDebug("ENTER");
2907
2908         AppLogDebug("PowerManager keepOn : %d  dimming : %d", keepOn, dimming);
2909
2910         r = PowerManager::KeepScreenOnState(keepOn, dimming);
2911         TryReturnVoid(r == E_SUCCESS, "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
2912         AppLogDebug("EXIT");
2913 }
2914
2915 void
2916 CameraPresentationModel::AddPresentationChangedEventListener(ICameraEventListner& pObserverListener)
2917 {
2918         AppLogDebug("ENTER");
2919         __pCameraListener = &pObserverListener;
2920         AppLogDebug("EXIT");
2921 }
2922
2923 void
2924 CameraPresentationModel::RemovePresentationChangedEventListener(ICameraEventListner* pObserverListener)
2925 {
2926         AppLogDebug("ENTER");
2927         __pCameraListener = pObserverListener;
2928         AppLogDebug("EXIT");
2929 }
2930
2931 void
2932 CameraPresentationModel::CallOnPresentationModeChanged(CameraActionEvent event)
2933 {
2934         AppLogDebug("ENTER");
2935         AppLogDebug("CallOnPresentationModeChanged - event = %d", event);
2936         if (__pCameraListener != null)
2937         {
2938                 __pCameraListener->OnCameraActionPerformed(event);
2939         }
2940         AppLogDebug("EXIT");
2941 }
2942
2943 result
2944 CameraPresentationModel::ResetCameraSettingsRegistry(void)
2945 {
2946         AppLogDebug("ENTER");
2947         result r = E_SUCCESS;
2948
2949         r = __pCameraSettingsPresentationModel->ResetCameraSettingsRegistry();
2950         TryCatch(r == E_SUCCESS, , "Registry::SetValue() failed[%s]", GetErrorMessage(r));
2951
2952         AppLogDebug("EXIT");
2953         return r;
2954
2955 CATCH:
2956         AppLogDebug("EXIT - CATCH");
2957         return r;
2958 }
2959
2960 result
2961 CameraPresentationModel::ResetCameraSettings(void)
2962 {
2963         AppLogDebug("ENTER");
2964         result r = E_SUCCESS;
2965
2966         TryCatch(__pCameraSettingsPresentationModel!=null, r = E_FAILURE,"Camera Settings Presentation Model is NULL");
2967
2968         r = __pCameraSettingsPresentationModel->SetValue(SECTION_CAMERA, EXPOSURE_VALUE, EXPOSURE_DEFAULT_VALUE);
2969         TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
2970
2971         r = __pCameraSettingsPresentationModel->SetValue(SECTION_CAMCORDER, EXPOSURE_VALUE, EXPOSURE_DEFAULT_VALUE);
2972         TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
2973
2974         r = __pCameraSettingsPresentationModel->SetValue(SECTION_CAMERA, BRIGHTNESS_VALUE, BRIGHTNESS_DEFAULT_VALUE);
2975         TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
2976
2977         r = __pCameraSettingsPresentationModel->SetValue(SECTION_CAMCORDER, BRIGHTNESS_VALUE, BRIGHTNESS_DEFAULT_VALUE);
2978         TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
2979
2980         AppLogDebug("EXIT");
2981         return r;
2982
2983 CATCH:  
2984         AppLogDebug("EXIT - CATCH %s", GetErrorMessage(r));
2985         return r;
2986 }
2987
2988 result
2989 CameraPresentationModel::GetValue(const Tizen::Base::String& entryName, int& value) const
2990 {
2991         AppLogDebug("ENTER");
2992         AppLogDebug("entry name is %ls",entryName.GetPointer());
2993         AppLogDebug("entry value is %d",value);
2994         result r = E_SUCCESS;
2995         int mode = 0;
2996         String strSectionName = SECTION_CAMERA;
2997
2998         if (entryName.Equals(String(CURRENT_MODE)))
2999         {
3000                 strSectionName = SECTION_CAMERA;
3001         }
3002         else
3003         {
3004                 r = __pCameraSettingsPresentationModel->GetValue(SECTION_CAMERA, CURRENT_MODE, mode);
3005                 TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
3006
3007                 if (mode == CAMERA_MODE_SNAPSHOT)
3008                 {
3009                         strSectionName = SECTION_CAMERA;
3010                 }
3011                 else
3012                 {
3013                         strSectionName = SECTION_CAMCORDER;
3014                 }
3015         }
3016
3017         r = __pCameraSettingsPresentationModel->GetValue(strSectionName, entryName, value);
3018         TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
3019
3020         AppLogDebug("EXIT");
3021         return r;
3022
3023 CATCH:
3024         AppLogDebug("EXIT - CATCH");
3025         return r;
3026 }
3027
3028 result
3029 CameraPresentationModel::SetValue(const Tizen::Base::String& entryName, const int value)
3030 {
3031         AppLogDebug("ENTER");
3032         result r = E_SUCCESS;
3033         int mode = 0;
3034         String strSectionName = SECTION_CAMERA;
3035
3036         AppLogDebug("entry name is %ls",entryName.GetPointer());
3037         AppLogDebug("entry value is %d",value);
3038
3039         if (entryName.Equals(String(CURRENT_MODE)))
3040         {
3041                 strSectionName = SECTION_CAMERA;
3042         }
3043         else
3044         {
3045                 r = __pCameraSettingsPresentationModel->GetValue(SECTION_CAMERA, CURRENT_MODE, mode);
3046                 TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
3047
3048                 if (mode == CAMERA_MODE_SNAPSHOT)
3049                 {
3050                         strSectionName = SECTION_CAMERA;
3051                 }
3052                 else
3053                 {
3054                         strSectionName = SECTION_CAMCORDER;
3055                 }
3056         }
3057
3058         r = __pCameraSettingsPresentationModel->SetValue(strSectionName, entryName, value);
3059
3060         /*if ( entryName.CompareTo(L"PRIMARY_FLASH_MODE") == 0)
3061         {
3062                 AppLogDebug("flash mode is set to value %d",value);
3063                 SetFlashMode(CameraFlashMode(value));
3064         }
3065         TryCatch(r == E_SUCCESS, , "Registry::SetValue() failed[%s]", GetErrorMessage(r));
3066 */
3067         AppLogDebug("EXIT");
3068         return r;
3069
3070 CATCH:
3071         AppLogDebug("EXIT - CATCH");
3072         return r;
3073 }
3074
3075 result
3076 CameraPresentationModel::GetMediaCapability(Tizen::Base::String key, bool& value) const
3077 {
3078         AppLogDebug("ENTER");
3079         result r = E_SUCCESS;
3080         r = MediaCapability::GetValue(key, value);
3081
3082         AppLogDebug("GetMediaCapability for %ls value = %d return = %s", key.GetPointer(), value, GetErrorMessage(r));
3083         TryCatch(r == E_SUCCESS, , "MediaCapability::GetValue() fail[%s]", GetErrorMessage(r));
3084
3085         AppLogDebug("EXIT");
3086         return r;
3087
3088 CATCH:
3089         AppLogDebug("EXIT - CATCH");
3090         return E_FAILURE;
3091 }
3092
3093 result
3094 CameraPresentationModel::GetMediaCapability(Tizen::Base::String key, int& value) const
3095 {
3096         AppLogDebug("ENTER");
3097         result r = E_SUCCESS;
3098         r = MediaCapability::GetValue(key, value);
3099
3100         AppLogDebug("GetMediaCapability for %ls value = %d return = %s", key.GetPointer(), value, GetErrorMessage(r));
3101         TryCatch(r == E_SUCCESS, , "MediaCapability::GetValue() fail[%s]", GetErrorMessage(r));
3102
3103         AppLogDebug("EXIT");
3104         return r;
3105
3106 CATCH:
3107         AppLogDebug("EXIT - CATCH");
3108         return E_FAILURE;
3109 }
3110
3111 result
3112 CameraPresentationModel::GetMediaCapability(Tizen::Base::String key) const
3113 {
3114         AppLogDebug("ENTER");
3115         result r = E_SUCCESS;
3116         IList* pList = null;
3117         pList = MediaCapability::GetValueN(key);
3118         r = GetLastResult();
3119         AppLogDebug("GetMediaCapability for %ls return = %s", key.GetPointer(), GetErrorMessage(r));
3120         TryCatch(pList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(r));
3121
3122         pList->RemoveAll(true);
3123         delete pList;
3124         pList = null;
3125
3126         AppLogDebug("EXIT");
3127         return r;
3128
3129 CATCH:
3130         AppLogDebug("EXIT - CATCH");
3131         return E_FAILURE;
3132 }
3133
3134 void
3135 CameraPresentationModel::OnCameraAutoFocused(bool completeCondition)
3136 {
3137         AppLogDebug("ENTER");
3138         CameraFocusMode focusMode = CAMERA_FOCUS_MODE_NONE;
3139
3140         if (__isIntervalTimerRun == true)
3141         {
3142                 AppLogDebug("__isIntervalTimerRun: true");
3143                 return;
3144         }
3145
3146         if (completeCondition == true)
3147         {
3148                 focusMode = __pCamera->GetFocusMode();
3149
3150                 if (focusMode == CAMERA_FOCUS_MODE_CONTINUOUS_AUTO)
3151                 {
3152                         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_AUTO_FOCUSED);
3153                 }
3154                 else if (focusMode == CAMERA_FOCUS_MODE_NORMAL)
3155                 {
3156                         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_TOUCH_AUTO_FOCUSED);
3157                 }
3158         }
3159         else
3160         {
3161                 AppLogDebug("completeCondition:false");
3162                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_AUTO_FOCUS_FAILED);
3163         }
3164         AppLogDebug("EXIT");
3165 }
3166
3167 void
3168 CameraPresentationModel::OnCameraPreviewed(Tizen::Base::ByteBuffer& previewedData, result r)
3169 {
3170         AppLogDebug("ENTER");
3171         AppLogDebug("EXIT");
3172 }
3173
3174 void
3175 CameraPresentationModel::OnCameraCaptured(Tizen::Base::ByteBuffer& capturedData, result r)
3176 {
3177         AppLogDebug("ENTER");
3178         int shootingMode = 0;
3179         String* pFullFileName = null;
3180         ContentManager* pContentManager = null;
3181         ImageContentInfo* pImageContentInfo = null;
3182         result ret = E_SUCCESS;
3183         int storageType = 0;
3184         String  FilePath= null;
3185         bool    bDoScanDir= false;
3186
3187         AppLogDebug("OnCameraCaptured :: StopCaptured = %d", __isStopCaptured);
3188
3189         if (__isStopCaptured == true)
3190         {
3191                 AppLogDebug("OnCameraCaptured :: StopCaptured");
3192                 __isStopCaptured = false;
3193
3194                 SetErrorResult(STRING_CAMERA_CAPTURED_ERROR);
3195
3196                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3197
3198                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_ERROR_OCCURRED);
3199         }
3200         else
3201         {
3202                 ret = GetValue(SHOOTING_MODE, shootingMode);
3203                 TryCatch(ret == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(ret));
3204
3205                 if (shootingMode == CAPTURE_NORMAL_MODE)
3206                 {
3207                         if (r == E_SUCCESS)
3208                         {
3209                                 ContentId contentId;
3210
3211                                 pFullFileName = new (std::nothrow) String();
3212                                 ret = CreateFileName(*pFullFileName);
3213                                 TryCatch(ret == E_SUCCESS, , "pFullFileName is null");
3214
3215                                 __latestContentName.Clear();
3216                                 ret = __latestContentName.Append(pFullFileName->GetPointer());
3217                                 TryCatch(ret == E_SUCCESS, , "String::Append() fail[%s]", GetErrorMessage(ret));
3218
3219                                 AppLogDebug("OnCameraCaptured pFullFileName = %ls", pFullFileName->GetPointer());
3220                                 pContentManager = new (std::nothrow) ContentManager();
3221
3222                                 ret = pContentManager->Construct();
3223                                 TryCatch(ret == E_SUCCESS, , "ContentManager->Construct() failed(%s)", GetErrorMessage(r));
3224
3225
3226                                 //Code for doing ScanDirectory!!!
3227                                 r = GetValue(STORAGE_TYPE, storageType);
3228                                 TryCatch(r == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(r));
3229
3230                                 r = CmUtility::GetDirectoryPath(storageType, FilePath);
3231                                 TryCatch(r == E_SUCCESS, , "GetDirectoryPath() fail[%s]", GetErrorMessage(r));
3232
3233                                 if( File::IsFileExist(FilePath) != true)
3234                                 {
3235                                         bDoScanDir = true;
3236                                 }
3237                                 //Ends
3238
3239                                 contentId = pContentManager->CreateContent(capturedData, pFullFileName->GetPointer());
3240                                 TryCatch(Tizen::Base::UuId::GetInvalidUuId() != contentId, GetLastResult(), "CreateContent failed.");
3241
3242                                 pImageContentInfo = static_cast<ImageContentInfo*>(pContentManager->GetContentInfoN(contentId));
3243                                 TryCatch(pImageContentInfo != null, , "pImageContentInfo is null");
3244
3245                                 if( bDoScanDir )
3246                                 {
3247                                         RequestId reqId;
3248                                         pContentManager->ScanDirectory(FilePath, true, null , reqId);
3249                                 }
3250
3251                                 delete __pBitmap;
3252                                 __pBitmap = null;
3253
3254                                 __pBitmap = pImageContentInfo->GetThumbnailN();
3255                                 TryCatch(__pBitmap != null, , "__pBitmap is null");
3256
3257                                 delete pContentManager;
3258                                 pContentManager = null;
3259
3260                                 delete pImageContentInfo;
3261                                 pImageContentInfo = null;
3262
3263                                 delete pFullFileName;
3264                                 pFullFileName = null;
3265
3266                                 AppLogDebug("ENTER:E_SUCCESS");
3267
3268                                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_SUCCEEDED);
3269
3270                                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_CAPTURED);
3271                         }
3272                         else
3273                         {
3274                                 AppLogDebug("ENTER:E_FAILED");
3275                                 SetErrorResult(STRING_CAMERA_CAPTURED_ERROR);
3276
3277                                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3278
3279                                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_ERROR_OCCURRED);
3280                         }
3281                 }
3282                 else if (shootingMode == CAPTURE_BURST_MODE)
3283                 {
3284                         // Empty statement
3285                 }
3286         }
3287
3288         AppLogDebug("EXIT");
3289         return;
3290
3291 CATCH:
3292         AppLogDebug("EXIT - CATCH");
3293         if (__pBitmap != null)
3294         {
3295                 delete __pBitmap;
3296                 __pBitmap = null;
3297         }
3298
3299         if (pContentManager != null)
3300         {
3301                 delete pContentManager;
3302                 pContentManager = null;
3303         }
3304
3305         if (pImageContentInfo)
3306         {
3307                 delete pImageContentInfo;
3308                 pImageContentInfo = null;
3309         }
3310
3311         if (pFullFileName)
3312         {
3313                 delete pFullFileName;
3314                 pFullFileName = null;
3315         }
3316
3317         SetErrorResult(STRING_CAMERA_CAPTURED_ERROR);
3318
3319         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3320
3321         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_ERROR_OCCURRED);
3322 }
3323
3324 void
3325 CameraPresentationModel::OnCameraErrorOccurred(Tizen::Media::CameraErrorReason r)
3326 {
3327         AppLogDebug("ENTER");
3328         result res = E_FAILURE;
3329         int currentCameraMode = 0;
3330
3331         switch (r)
3332         {
3333         case CAMERA_ERROR_OUT_OF_MEMORY:
3334                 {
3335                         AppLogDebug("camera error occurred - CAMERA_ERROR_OUT_OF_MEMORY");
3336                         res = E_OUT_OF_MEMORY;
3337                 }
3338                 break;
3339
3340         case CAMERA_ERROR_DEVICE_FAILED:
3341                 {
3342                         AppLogDebug("camera error occurred - CAMERA_ERROR_DEVICE_FAILED");
3343                         res = E_DEVICE_FAILED;
3344                 }
3345                 break;
3346
3347         case CAMERA_ERROR_DEVICE_INTERRUPTED:
3348                 {
3349                         AppLogDebug("camera error occurred - CAMERA_ERROR_DEVICE_INTERRUPTED");
3350                         res = E_DEVICE_BUSY;
3351                 }
3352                 break;
3353
3354         default:
3355                 {
3356                         res = E_SUCCESS;
3357                 }
3358                 break;
3359         }
3360
3361         result ret = GetValue(CURRENT_MODE, currentCameraMode);
3362         TryReturnVoid(ret == E_SUCCESS, "Faled to set value to registry[%s]", GetErrorMessage(ret));
3363
3364         if (currentCameraMode == CAMERA_MODE_RECORD)
3365         {
3366                 AppLogDebug("RECORD error occurred");
3367                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_ERROR_OCCURRED);
3368         }
3369         else
3370         {
3371                 AppLogDebug("SNAPSHOT error occurred");
3372                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_ERROR_OCCURRED);
3373         }
3374         AppLogDebug("EXIT");
3375 }
3376
3377 void
3378 CameraPresentationModel::OnVideoRecorderCanceled(result r)
3379 {
3380         AppLogDebug("ENTER");
3381         if (__pVideoRecorder != null)
3382         {
3383                 __pVideoRecorder->Close();
3384         }
3385
3386         if (__recorderStopException)
3387         {
3388                 r = __pCamera->StopPreview();
3389                 TryReturnVoid(r == E_SUCCESS, "Camera::StopPreview() [%s]", GetErrorMessage(r));
3390
3391                 if (__pCamera->IsPoweredOn() == true)
3392                 {
3393                         r = __pCamera->PowerOff();
3394                         TryReturnVoid(r == E_SUCCESS, "Camera::PowerOff() [%s]", GetErrorMessage(r));
3395                 }
3396         }
3397         AppLogDebug("EXIT");
3398 }
3399
3400 void
3401 CameraPresentationModel::OnVideoRecorderClosed(result r)
3402 {
3403         AppLogDebug("ENTER");
3404 # if 0                          //Unused code
3405         ContentManager* pContentManager = null;
3406 #endif
3407         ContentId contentId;
3408         String replaceFilePath;
3409         String camcorderTemporaryFilePath;
3410         int storageType = STORAGE_TYPE_PHONE;
3411         result ret = E_SUCCESS;
3412
3413         ret = SetFlashModeOnRecord(false);
3414         AppLogDebug("SetFlashModeOnRecord fail[%s]", GetErrorMessage(ret));
3415
3416         AppLogDebug("isCancelRecord", __isCancelRecord);
3417
3418         if (__isCancelRecord)
3419         {
3420                 __onVideoRecorderStarted = false;
3421                 AppLogDebug("isCancelRecord %d", __isCancelRecord);
3422
3423                 ret = RemoveVideoFile();
3424                 AppLogDebug("RemoveVideoFile fail[%s]", GetErrorMessage(ret));
3425
3426                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_CANCELED);
3427                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_CANCELED);
3428
3429                 AppLogDebug("CANCELRECORD - EXIT");
3430                 return;
3431         }
3432
3433         if (r == E_SUCCESS)
3434         {
3435                 AppLogDebug("ENTER: E_SUCCESS");
3436
3437                 ret = GetValue(STORAGE_TYPE, storageType);
3438                 if (ret != E_SUCCESS)
3439                 {
3440                         storageType = STORAGE_TYPE_PHONE;
3441                 }
3442
3443                 if (storageType == STORAGE_TYPE_PHONE)
3444                 {
3445                         camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", App::GetInstance()->GetAppRootPath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE);
3446                 }
3447                 else
3448                 {
3449                         camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", Environment::GetExternalStoragePath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE_EXT);
3450                 }
3451
3452 # if 0                          //Contnet Manager is nto used
3453                 pContentManager = new (std::nothrow) ContentManager();
3454                 ret = pContentManager->Construct();
3455                 TryCatch(ret == E_SUCCESS, , "ContentManager->Construct() failed(%s)", GetErrorMessage(r));
3456 #endif
3457
3458                 AppLogDebug("latest content name is %ls",__latestContentName.GetPointer());
3459                 r = ContentManager::ScanFile(__latestContentName);
3460                 __CurrentVideoFileName = __latestContentName;
3461
3462                 if (storageType == STORAGE_TYPE_PHONE)
3463                 {
3464                         replaceFilePath =  Environment::GetMediaPath();
3465                 }
3466                 else
3467                 {
3468                         replaceFilePath = Environment::GetExternalStoragePath();
3469                 }
3470
3471                 replaceFilePath.Append(STRING_CAMERA_FOLDER_NAME);
3472                 replaceFilePath.Append("/");
3473                 AppLogDebug("Replace filepath is %ls",replaceFilePath.GetPointer());
3474                 __CurrentVideoFileName.Replace(replaceFilePath,"");
3475                 AppLogDebug("__CurrentVideoFileName path is %ls",__CurrentVideoFileName.GetPointer());
3476
3477                 __pBitmap = CmUtility::CreateThumbnailN(__CurrentVideoFileName,CONTENT_TYPE_VIDEO);
3478
3479                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_SUCCEEDED);
3480
3481                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_CLOSED);
3482         }
3483         else
3484         {
3485                 AppLogDebug("ENTER: E_FAILED");
3486
3487                 SetErrorResult(STRING_VIDEO_RECORDER_CLOSED_ERROR);
3488
3489                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3490                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_ERROR_OCCURRED);
3491         }
3492
3493         __onVideoRecorderStarted = false;
3494
3495         AppLogDebug("EXIT");
3496         return;
3497 }
3498
3499 void
3500 CameraPresentationModel::OnVideoRecorderEndReached(RecordingEndCondition endCondition)
3501 {
3502         AppLogDebug("ENTER");
3503         ContentManager* pContentManager = null;
3504         VideoContentInfo* videoContentInfo = null;
3505         ContentId contentId;
3506         String camcorderTemporaryFilePath;
3507         int storageType = STORAGE_TYPE_PHONE;
3508         result ret = E_SUCCESS;
3509
3510         ret = SetFlashModeOnRecord(false);
3511         AppLogDebug("SetFlashModeOnRecord fail[%s]", GetErrorMessage(ret));
3512
3513         StopRecord();
3514
3515         ret = GetValue(STORAGE_TYPE, storageType);
3516         if (ret != E_SUCCESS)
3517         {
3518                 storageType = STORAGE_TYPE_PHONE;
3519         }
3520
3521         if (storageType == STORAGE_TYPE_PHONE)
3522         {
3523                 camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", App::GetInstance()->GetAppRootPath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE);
3524         }
3525         else
3526         {
3527                 camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", Environment::GetExternalStoragePath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE_EXT);
3528         }
3529
3530         pContentManager = new (std::nothrow) ContentManager();
3531
3532         ret = pContentManager->Construct();
3533         TryCatch(ret == E_SUCCESS, , "ContentManager->Construct() failed(%s)", GetErrorMessage(ret));
3534
3535         contentId = pContentManager->CreateContent(camcorderTemporaryFilePath, __latestContentName, true);
3536         TryCatch(Tizen::Base::UuId::GetInvalidUuId() != contentId, GetLastResult(), "CreateContent failed.");
3537
3538         videoContentInfo = static_cast<VideoContentInfo*>(pContentManager->GetContentInfoN(contentId));
3539         TryCatch(videoContentInfo != null, , "videoContentInfo is null");
3540
3541         delete __pBitmap;
3542         __pBitmap = null;
3543
3544         __pBitmap = videoContentInfo->GetThumbnailN();
3545         TryCatch(__pBitmap != null, , "__pBitmap is null");
3546
3547         delete videoContentInfo;
3548         videoContentInfo = null;
3549
3550         delete pContentManager;
3551         pContentManager = null;
3552
3553         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_SUCCEEDED);
3554
3555         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_END_REACHED);
3556
3557         __onVideoRecorderStarted = false;
3558         AppLogDebug("EXIT");
3559         return;
3560
3561 CATCH:
3562         AppLogDebug("EXIT - CATCH");
3563         delete pContentManager;
3564         pContentManager = null;
3565
3566         delete videoContentInfo;
3567         videoContentInfo = null;
3568
3569         delete __pBitmap;
3570         __pBitmap = null;
3571
3572         SetErrorResult(STRING_VIDEO_RECORDER_END_REACHED_ERROR);
3573         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3574         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_ERROR_OCCURRED);
3575 }
3576
3577 void
3578 CameraPresentationModel::OnVideoRecorderErrorOccurred(RecorderErrorReason r)
3579 {
3580         AppLogDebug("ENTER OnVideoRecorderErrorOccurred (%ld)", r);
3581
3582         __recorderError = r;
3583         __pVideoRecorder->Close();
3584
3585         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3586
3587         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_ERROR_OCCURRED);
3588
3589         __onVideoRecorderStarted = false;
3590         AppLogDebug("EXIT");
3591 }
3592
3593 void
3594 CameraPresentationModel::OnVideoRecorderPaused(result r)
3595 {
3596         AppLogDebug("ENTER");
3597         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_PAUSED);
3598         AppLogDebug("EXIT");
3599 }
3600
3601 void
3602 CameraPresentationModel::OnVideoRecorderStarted(result r)
3603 {
3604         AppLogDebug("ENTER");
3605         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_STARTED);
3606         AppLogDebug("EXIT");
3607 }
3608
3609 bool
3610 CameraPresentationModel::GetOnVideoRecorderStopped(void)
3611 {
3612         AppLogDebug("ENTER");
3613         AppLogDebug("EXIT");
3614         return __onVideoRecorderStarted;
3615 }
3616
3617 void
3618 CameraPresentationModel::SetOnVideoRecorderStopped(bool isCompleted)
3619 {
3620         AppLogDebug("ENTER");
3621         __onVideoRecorderStarted = isCompleted;
3622         AppLogDebug("EXIT");
3623 }
3624
3625 void
3626 CameraPresentationModel::OnVideoRecorderStopped(result r)
3627 {
3628         AppLogDebug("ENTER");
3629         result localResult = E_SUCCESS;
3630
3631         if (__pVideoRecorder != null)
3632         {
3633                 localResult = __pVideoRecorder->Close();
3634                 TryCatch(localResult == E_SUCCESS, , "__pVideoRecorder::Close() fail[%s]", GetErrorMessage(localResult));
3635         }
3636         __onVideoRecorderStarted = true;
3637
3638         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_STOPPED);
3639
3640         AppLogDebug("EXIT");
3641         return;
3642
3643 CATCH:
3644         AppLogDebug("EXIT - CATCH");
3645         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3646         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_ERROR_OCCURRED);
3647 }
3648
3649 void
3650 CameraPresentationModel::DestroyPresentationModelInstance(void)
3651 {
3652         AppLogDebug("ENTER");
3653         CameraPresentationModel* pCameraPresentationModel = CameraPresentationModel::GetInstance();
3654
3655         delete pCameraPresentationModel;
3656         AppLogDebug("EXIT");
3657 }
3658
3659 void
3660 CameraPresentationModel::UpdateThumbnail(int currentCameraMode)
3661 {
3662         AppLogDebug("ENTER");
3663         result r = E_SUCCESS;
3664
3665         r = CreateThumbnail(currentCameraMode);
3666         TryReturnVoid(r == E_SUCCESS, "CreateThumbnail() fail[%s]", GetErrorMessage(r));
3667         AppLogDebug("EXIT");
3668 }
3669
3670 int
3671 CameraPresentationModel::GetStorageCardState(void) const
3672 {
3673         AppLogDebug("ENTER");
3674         AppLogDebug("EXIT");
3675         return __storageCardState;
3676 }
3677
3678 void
3679 CameraPresentationModel::SetStorageCardState(int storageCardState)
3680 {
3681         AppLogDebug("ENTER");
3682         __storageCardState = storageCardState;
3683         AppLogDebug("EXIT");
3684 }
3685
3686 int
3687 CameraPresentationModel::GetStorageCardChageState(void) const
3688 {
3689         AppLogDebug("ENTER");
3690         AppLogDebug("EXIT");
3691         return __storageCardChageState;
3692 }
3693
3694 void
3695 CameraPresentationModel::SetStorageCardChageState(int storageCardChageState)
3696 {
3697         AppLogDebug("ENTER");
3698         __storageCardChageState = storageCardChageState;
3699         AppLogDebug("EXIT");
3700 }
3701
3702 void
3703 CameraPresentationModel::StorageCardStateChaged(bool isMounted)
3704 {
3705         AppLogDebug("ENTER");
3706         if (isMounted)
3707         {
3708                 __storageCardState = STORAGE_CARD_STATE_MOUNT;
3709         }
3710         else
3711         {
3712                 __storageCardState = STORAGE_CARD_STATE_UNMOUNT;
3713
3714                 __pCameraSettingsPresentationModel->SetValue(SECTION_CAMERA, STORAGE_TYPE, STORAGE_TYPE_PHONE);
3715
3716                 __pCameraSettingsPresentationModel->SetValue(SECTION_CAMCORDER, STORAGE_TYPE, STORAGE_TYPE_PHONE);
3717         }
3718         AppLogDebug("EXIT");
3719 }
3720
3721 void
3722 CameraPresentationModel::SetDeviceManagerEventListner(void)
3723 {
3724         AppLogDebug("ENTER");
3725         result r = E_SUCCESS;
3726
3727         r = DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
3728         AppLogDebug("AddDeviceEventListener [%s] fail", GetErrorMessage(r));
3729         AppLogDebug("EXIT");
3730 }
3731
3732 void
3733 CameraPresentationModel::RemoveDeviceManagerEventListner(void)
3734 {
3735         AppLogDebug("ENTER");
3736         result r = E_SUCCESS;
3737
3738         r = DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
3739         AppLogDebug("RemoveDeviceManagerEventListner [%s] fail", GetErrorMessage(r));
3740         AppLogDebug("EXIT");
3741 }
3742
3743 void
3744 CameraPresentationModel::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
3745 {
3746         AppLogDebug("ENTER");
3747         int currentCameraMode = 0;
3748         int storageType = STORAGE_TYPE_PHONE;
3749
3750         result r = E_SUCCESS;
3751         r = GetValue(CURRENT_MODE, currentCameraMode);
3752         TryReturnVoid(r == E_SUCCESS, "GetValue returns not E_SUCCESS", GetErrorMessage(r));
3753
3754         if (deviceType == DEVICE_TYPE_STORAGE_CARD)
3755         {
3756                 switch (currentCameraMode)
3757                 {
3758                 case CAMERA_MODE_RECORD:
3759                         {
3760                                 __pCameraSettingsPresentationModel->GetValue(SECTION_CAMCORDER, STORAGE_TYPE, storageType);
3761
3762                                 if (storageType == STORAGE_TYPE_MEMORYCARD)
3763                                 {
3764                                         if (IsStorageCardMounted()== false)
3765                                         {
3766                                                 AppLogDebug("RemoveVideoFile::GetRecorderState() = %d", __pVideoRecorder->GetState());
3767
3768                                                 if (__pVideoRecorder->GetState() == RECORDER_STATE_RECORDING
3769                                                         || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSED
3770                                                         || __pVideoRecorder->GetState() == RECORDER_STATE_STARTING
3771                                                         || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSING
3772                                                 )
3773                                                 {
3774                                                         r = RemoveVideoFile();
3775                                                         AppLogDebug("RemoveVideoFile fail[%s]", GetErrorMessage(r));
3776                                                 }
3777
3778                                                 StorageCardStateChaged(false);
3779
3780                                                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3781
3782                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_MOUNT_TO_UNMOUNT);
3783                                                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_STORAGE_CARD_UNMOUNT);
3784                                         }
3785                                         else
3786                                         {
3787                                                 StorageCardStateChaged(true);
3788                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3789                                         }
3790                                 }
3791                                 else
3792                                 {
3793                                         if ( IsStorageCardMounted()== false)
3794                                         {
3795                                                 StorageCardStateChaged(false);
3796                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3797                                         }
3798                                         else
3799                                         {
3800                                                 StorageCardStateChaged(true);
3801                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3802                                         }
3803                                 }
3804                         }
3805                         break;
3806
3807                 case CAMERA_MODE_SNAPSHOT:
3808                         {
3809                                 __pCameraSettingsPresentationModel->GetValue(SECTION_CAMERA, STORAGE_TYPE, storageType);
3810
3811                                 if (storageType == STORAGE_TYPE_MEMORYCARD)
3812                                 {
3813                                         if ( IsStorageCardMounted()== false)
3814                                         {
3815                                                 AppLogDebug("OnDeviceStateChanged state=%d", __pCamera->GetState());
3816
3817                                                 if (GetCameraState() == CAMERA_STATE_CAPTURED || GetCameraState() == CAMERA_STATE_CAPTURING)
3818                                                 {
3819                                                         __isStopCaptured = true;
3820                                                 }
3821                                                 else
3822                                                 {
3823                                                         __isStopCaptured = false;
3824                                                 }
3825
3826                                                 StorageCardStateChaged(false);
3827
3828                                                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3829                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_MOUNT_TO_UNMOUNT);
3830                                                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_STORAGE_CARD_UNMOUNT);
3831                                         }
3832                                         else
3833                                         {
3834                                                 StorageCardStateChaged(true);
3835                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3836                                         }
3837                                 }
3838                                 else
3839                                 {
3840                                         __isStopCaptured = false;
3841
3842                                         if ( IsStorageCardMounted()== false)
3843                                         {
3844                                                 StorageCardStateChaged(false);
3845                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3846                                         }
3847                                         else
3848                                         {
3849                                                 StorageCardStateChaged(true);
3850                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3851                                         }
3852                                 }
3853                         }
3854                         break;
3855
3856                 default:
3857                         break;
3858                 }
3859         }
3860         AppLogDebug("EXIT");
3861 }
3862
3863 result
3864 CameraPresentationModel::RemoveVideoFile(void)
3865 {
3866         AppLogDebug("ENTER");
3867         String removeFileName;
3868         File file;
3869         result r = E_SUCCESS;
3870         int storageType = STORAGE_TYPE_PHONE;
3871
3872         r = GetValue(STORAGE_TYPE, storageType);
3873         if (r != E_SUCCESS)
3874         {
3875                 storageType = STORAGE_TYPE_PHONE;
3876         }
3877
3878         removeFileName = __latestContentName;
3879
3880         AppLogDebug("removeFileName is %ls",removeFileName.GetPointer());
3881         AppLogDebug("RemoveVideoFile::GetRecorderState() = %d", __pVideoRecorder->GetState());
3882         if (__pVideoRecorder->GetState()== RECORDER_STATE_RECORDING
3883                 || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSED
3884                 || __pVideoRecorder->GetState() == RECORDER_STATE_STARTING
3885                 || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSING
3886         )
3887         {
3888                 StopRecord();
3889         }
3890
3891         r = file.Construct(removeFileName, "w+");
3892         TryCatch(r == E_SUCCESS, , "file::Construct() fail[%s]", GetErrorMessage(r));
3893
3894         r = file.Remove(removeFileName);
3895         TryCatch(r == E_SUCCESS, , "file::Remove() fail[%s]", GetErrorMessage(r));
3896
3897         AppLogDebug("EXIT");
3898         return r;
3899
3900 CATCH:
3901         AppLogDebug("EXIT - CATCH");
3902         return r;
3903 }
3904
3905 void
3906 CameraPresentationModel::SetDisplayResolutionType(int type)
3907 {
3908         AppLogDebug("ENTER");
3909         __displayResolution = type;
3910         AppLogDebug("EXIT");
3911 }
3912
3913 int
3914 CameraPresentationModel::GetDisplayResolutionType(void)
3915 {
3916         AppLogDebug("ENTER");
3917         AppLogDebug("EXIT");
3918         return __displayResolution;
3919 }
3920
3921 Tizen::Media::RecordingRotation
3922 CameraPresentationModel::GetRecordingRotation(void)
3923 {
3924         AppLogDebug("ENTER");
3925         RecordingRotation rotate = RECORDING_ROTATION_NONE;
3926         int selfPortraitEnable = 0;
3927         result r = E_SUCCESS;
3928         int count = sizeof(_RecordRotate) / sizeof(_RecordRotate[0]);
3929
3930         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
3931
3932         for (int i=0; i < count; i++)
3933         {
3934                 if ((_RecordRotate[i].camType == selfPortraitEnable) && _RecordRotate[i].orientation == GetOrientation())
3935                 {
3936                         return _RecordRotate[i].rotate;
3937                 }
3938         }
3939         AppLogDebug("EXIT");
3940         return rotate;
3941 }
3942
3943 void
3944 CameraPresentationModel::OnContentScanCompleted (RequestId reqId, const Tizen::Base::String &scanPath, result r)
3945 {
3946         AppLogDebug("Enter");
3947         AppLogDebug("Exit");
3948 }
3949
3950 void
3951 CameraPresentationModel::SetStartPreviewException(bool status)
3952 {
3953         __startPreviewException = status;
3954 }
3955
3956 void
3957 CameraPresentationModel::UpdateContentFile(void)
3958 {
3959         AppLogDebug("latest content name is %ls",__latestContentName.GetPointer());
3960         ContentManager::ScanFile(__latestContentName);
3961         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_SUCCEEDED);
3962 }
3963
3964 void
3965 CameraPresentationModel::SetRecordStopException(bool currentStatus)
3966 {
3967         __recorderStopException = currentStatus;
3968 }
3969
3970 RecorderErrorReason
3971 CameraPresentationModel::GetRecorderErrorStatus(void)
3972 {
3973         return __recorderError;
3974 }
3975
3976 void
3977 CameraPresentationModel::GetUpdatedContentName(Tizen::Base::String& latestContentName)
3978 {
3979         latestContentName = __latestContentName;
3980 }
3981
3982 void
3983 CameraPresentationModel::SetMemoryFullException(bool status)
3984 {
3985         __memoryFullException = status;
3986 }
3987
3988 bool
3989 CameraPresentationModel::GetMemoryFullExceptionStatus(void)
3990 {
3991         long long allocatedMemory = 0;
3992         bool memoryStatus = false;
3993
3994         allocatedMemory = CmUtility::GetAvailableMemory();
3995
3996         if (__memoryFullException && allocatedMemory < MIN_MEMORY_NEEDED)
3997         {
3998                 memoryStatus = true;
3999         }
4000
4001         return memoryStatus;
4002 }
4003
4004 void
4005 CameraPresentationModel::SetCurrentSourceForm(SourceForm source)
4006 {
4007         __pCurrentSource = source;
4008 }
4009
4010 SourceForm
4011 CameraPresentationModel::GetCurrentSourceForm(void)
4012 {
4013         return __pCurrentSource;
4014 }
4015
4016 bool
4017 CameraPresentationModel::GetCancelRecord(void)
4018 {
4019         return __isCancelRecord;
4020 }