Nabi issue (N_SE-46583) fix
[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         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_INITIALIZE_FAILED);
1111         AppLogDebug("EXIT - CATCH");
1112         return r;
1113 }
1114
1115 result
1116 CameraPresentationModel::ToggleCameraDirection(int mode, int direction)
1117 {
1118         AppLogDebug("ENTER");
1119         result r = E_SUCCESS;
1120         int captureResolutionCount = 0;
1121         Dimension* pCaptureResolution = null;
1122
1123         Terminate(mode);
1124
1125         __pCamera = new (std::nothrow) Camera();
1126         TryCatch(__pCamera != null, , "[FAILURE] new (std::nothrow) Camera()");
1127
1128         if (direction == CAMERA_DIRECTION_BACK)
1129         {
1130                 AppLogDebug("BACK");
1131
1132                 r = __pCamera->Construct(*this, CAMERA_PRIMARY);
1133                 TryCatch(r == E_SUCCESS, , "__pCamera->Construct() [%s]", GetErrorMessage(r));
1134         }
1135         else if (direction == CAMERA_DIRECTION_FRONT)
1136         {
1137                 AppLogDebug("FRONT");
1138
1139                 r = __pCamera->Construct(*this, CAMERA_SECONDARY);
1140                 TryCatch(r == E_SUCCESS, , "__pCamera->Construct() [%s]", GetErrorMessage(r));
1141         }
1142
1143         r = __pCamera->PowerOn();
1144         TryCatch(r == E_SUCCESS, , "__pCamera->PowerOn() [%s]", GetErrorMessage(r));
1145
1146         if (mode == CAMERA_MODE_RECORD)
1147         {
1148                 if (__pVideoRecorder == null)
1149                 {
1150                         __pVideoRecorder = new (std::nothrow) VideoRecorder();
1151                         __pVideoRecorder->Construct(*this, *__pCamera);
1152                 }
1153         }
1154
1155         if (mode == CAMERA_MODE_SNAPSHOT && direction == CAMERA_DIRECTION_FRONT)
1156         {
1157                 __pCaptureResolutionList = __pCamera->GetSupportedCaptureResolutionListN();
1158                 TryCatch(__pCaptureResolutionList != null, , "pCaptureResolutionList is null");
1159
1160                 captureResolutionCount = __pCaptureResolutionList->GetCount();
1161
1162                 pCaptureResolution = static_cast< Dimension*>(__pCaptureResolutionList->GetAt(captureResolutionCount - 1));
1163                 TryCatch(pCaptureResolution != null, , " pCaptureResolution->GetAt()");
1164
1165                 r = __pCamera->SetCaptureResolution(*pCaptureResolution);
1166                 TryCatch(r == E_SUCCESS, , "Camera::SetCaptureResolution fail[%s]", GetErrorMessage(r));
1167         }
1168
1169         if (direction == CAMERA_DIRECTION_FRONT)
1170         {
1171                 SetFlip(CAMERA_FLIP_HORIZONTAL);
1172         }
1173
1174         AppLogDebug("EXIT");
1175         return r;
1176
1177 CATCH:
1178         AppLogDebug("EXIT - CATCH");
1179         if (__pCaptureResolutionList)
1180         {
1181                 __pCaptureResolutionList->RemoveAll(true);
1182         }
1183
1184         delete __pCaptureResolutionList;
1185         __pCaptureResolutionList = null;
1186
1187         __isInitCamera = false;
1188         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_INITIALIZE_FAILED);
1189
1190         return r;
1191 }
1192
1193 bool
1194 CameraPresentationModel::GetInitCameraStatus(void) const
1195 {
1196         AppLogDebug("ENTER");
1197         AppLogDebug("EXIT - __isInitCamera = %d", __isInitCamera);
1198         return __isInitCamera;
1199 }
1200
1201 result
1202 CameraPresentationModel::SetMode(int mode)
1203 {
1204         AppLogDebug("ENTER");
1205         result r = E_SUCCESS;
1206         String contentSubDirectory = STRING_CAMERA_FOLDER_NAME;
1207         Directory contentDirectory;
1208         int cameraSelfPortraitEnable = CAM_SELF_PORTRAIT_MODE_PRIMARY;
1209         int camcorderSelfPortraitEnable = CAM_SELF_PORTRAIT_MODE_PRIMARY;
1210         int direction = CAMERA_DIRECTION_BACK;
1211         int selfPortraitEnable = 0;
1212
1213         AppLogDebug("SetMode __SetMode = %d && mode = %d", __cameraMode, mode);
1214
1215         if (__pCamera != null)
1216         {
1217                 if (__pCamera->IsPoweredOn() == true)
1218                 {
1219                         AppLogDebug("StopCamera or Terminate");
1220
1221                         __pCameraSettingsPresentationModel->GetValue(SECTION_CAMERA, SELF_PORTRAIT_ENABLE, cameraSelfPortraitEnable);
1222
1223                         __pCameraSettingsPresentationModel->GetValue(SECTION_CAMCORDER, SELF_PORTRAIT_ENABLE, camcorderSelfPortraitEnable);
1224
1225                         AppLogDebug("SECTION_CAMERA mode = %d && SECTION_CAMCORDER mode = %d", cameraSelfPortraitEnable, camcorderSelfPortraitEnable);
1226
1227                         GetMediaCapability(CAMERA_SECONDARY_DIRECTION, direction);
1228
1229                         if ((cameraSelfPortraitEnable == CAM_SELF_PORTRAIT_MODE_SECONDARY && camcorderSelfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
1230                                 || (cameraSelfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY && camcorderSelfPortraitEnable == CAM_SELF_PORTRAIT_MODE_SECONDARY)
1231                         )
1232                         {
1233                                 if (__cameraMode == mode && direction == CAMERA_DIRECTION_FRONT)
1234                                 {
1235                                         AppLogDebug("StopCamera");
1236                                         StopCamera();
1237                                 }
1238                                 else
1239                                 {
1240                                         AppLogDebug("Terminate");
1241                                         Terminate(mode);
1242                                 }
1243                         }
1244                         else
1245                         {
1246                                 AppLogDebug("StopCamera");
1247                                 StopCamera();
1248                         }
1249                 }
1250         }
1251
1252         if (mode == CAMERA_MODE_SNAPSHOT)
1253         {
1254                 if (__pCamera == null)
1255                 {
1256                         AppLogDebug("CAMERA_MODE_SNAPSHOT::NOT_INITIALIZED");
1257
1258 #if 0                   //Not in use
1259                         if (__pContentManager == null)
1260                         {
1261                                 __pContentManager = new (std::nothrow) ContentManager();
1262
1263                                 r = __pContentManager->Construct();
1264                                 TryCatch(r == E_SUCCESS, , "__pContentManager->Construct [%s]", GetErrorMessage(r));
1265                         }
1266                         if (__pImageContentInfo == null)
1267                         {
1268                                 __pImageContentInfo = new (std::nothrow) ImageContentInfo();
1269                                 r = __pImageContentInfo->Construct(null);
1270                                 TryCatch(r == E_SUCCESS, , "__pImageContentInfo->Construct [%s]", GetErrorMessage(r));
1271                         }
1272 #endif
1273
1274                         r = CreateThumbnail(CAMERA_MODE_SNAPSHOT);
1275                         AppLogDebug("CreateThumbnail [%s]", GetErrorMessage(r));
1276
1277                         r = InitializeCamera();
1278                         TryCatch(r == E_SUCCESS, , "InitializeCamera [%s]", GetErrorMessage(r));
1279
1280                         r = InitializeFlashMode();
1281                         AppLogDebug("InitFlashMode fail [%s]", GetErrorMessage(r));
1282
1283                         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1284                         if (r != E_SUCCESS)
1285                         {
1286                                 selfPortraitEnable = CAM_SELF_PORTRAIT_MODE_PRIMARY;
1287                         }
1288
1289                         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_SECONDARY)
1290                         {
1291                                 SetFlip(CAMERA_FLIP_HORIZONTAL);
1292                         }
1293                 }
1294                 else if (__pCamera != null)
1295                 {
1296                         AppLogDebug("CAMERA_MODE_SNAPSHOT::INITIALIZED");
1297
1298                         r = CreateThumbnail(CAMERA_MODE_SNAPSHOT);
1299                         AppLogDebug("CreateThumbnail [%s]", GetErrorMessage(r));
1300
1301                         r = ToggleCameraCamcorder(CAMERA_MODE_SNAPSHOT);
1302                         TryCatch(r == E_SUCCESS, , "ToggleCameraCamcorder [%s]", GetErrorMessage(r));
1303                 }
1304         }
1305         else if (mode == CAMERA_MODE_RECORD)
1306         {
1307                 if (__pCamera == null)
1308                 {
1309                         AppLogDebug("CAMERA_MODE_RECORD::NOT_INITIALIZED");
1310 #if 0                   //varialbe not in use
1311                         if (__pContentManager == null)
1312                         {
1313                                 __pContentManager = new (std::nothrow) ContentManager();
1314
1315                                 r =  __pContentManager->Construct();
1316                                 TryCatch(r == E_SUCCESS, , "__pContentManager->Construct [%s]", GetErrorMessage(r));
1317                         }
1318                         if (__pVideoContentInfo == null)
1319                         {
1320                                 __pVideoContentInfo = new (std::nothrow) VideoContentInfo();
1321
1322                                 r = __pVideoContentInfo->Construct(null);
1323                                 TryCatch(r == E_SUCCESS, , "__pVideoContentInfo->Construct [%s]", GetErrorMessage(r));
1324                         }
1325 #endif
1326
1327                         r = CreateThumbnail(CAMERA_MODE_RECORD);
1328                         AppLogDebug("CreateThumbnail [%s]", GetErrorMessage(r));
1329
1330                         r = InitializeCamcorder();
1331                         TryCatch(r == E_SUCCESS, , "InitializeCamcorder [%s]", GetErrorMessage(r));
1332
1333                         r = InitializeFlashMode();
1334                         AppLogDebug("InitFlashMode fail [%s]", GetErrorMessage(r));
1335
1336                         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1337                         if (r != E_SUCCESS)
1338                         {
1339                                 selfPortraitEnable = CAM_SELF_PORTRAIT_MODE_PRIMARY;
1340                         }
1341
1342                         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_SECONDARY)
1343                         {
1344                                 SetFlip(CAMERA_FLIP_HORIZONTAL);
1345                         }
1346                 }
1347                 else if (__pCamera != null)
1348                 {
1349                         AppLogDebug("CAMERA_MODE_RECORD::INITIALIZED");
1350
1351                         if (__pVideoRecorder == null)
1352                         {
1353                                 __pVideoRecorder = new (std::nothrow) VideoRecorder();
1354                                 __pVideoRecorder->Construct(*this, *__pCamera);
1355                         }
1356
1357                         r = CreateThumbnail(CAMERA_MODE_RECORD);
1358                         AppLogDebug("CreateThumbnail [%s]", GetErrorMessage(r));
1359
1360                         r = ToggleCameraCamcorder(CAMERA_MODE_RECORD);                  
1361                         TryCatch(r == E_SUCCESS, , "ToggleCameraCamcorder [%s]", GetErrorMessage(r));
1362                         InitializeFlashMode();
1363                 }
1364         }
1365         __cameraMode = mode;
1366
1367         __isInitCamera = true;
1368
1369         AppLogDebug("EXIT");
1370         return r;
1371
1372 CATCH:
1373         AppLogDebug("EXIT - CATCH");
1374         __isInitCamera = false;
1375         return r;
1376 }
1377
1378 Tizen::Graphics::Bitmap*
1379 CameraPresentationModel::GetLatestThumbnail(void)
1380 {
1381         AppLogDebug("ENTER");
1382         if (__pBitmap)
1383         {
1384                 AppLogDebug("__pBitmap NOT null");
1385                 AppLogDebug("EXIT");
1386                 return __pBitmap;
1387         }
1388         else
1389         {
1390                 AppLogDebug("__pBitmap null");
1391                 AppLogDebug("EXIT");
1392                 return null;
1393         }
1394 }
1395
1396 int
1397 CameraPresentationModel::GetContentCount(void)
1398 {
1399         AppLogDebug("ENTER");
1400         AppLogDebug("EXIT");
1401         return __contentCount;
1402 }
1403
1404 Tizen::Base::Collection::ArrayList*
1405 CameraPresentationModel::GetContentPathListN(int mode)
1406 {
1407         AppLogDebug("ENTER");
1408         result r = E_SUCCESS;
1409         ContentDirectory contentDirectory;
1410         IList* pContentList = null;
1411         String contentFullPath = L"";
1412         String filePath = L"";
1413         String combineText = L"";
1414         int storageType = 0;
1415         int countPerPage = 0;
1416         ArrayList* pContentPath = null;
1417
1418         r = GetValue(STORAGE_TYPE, storageType);
1419         if (r != E_SUCCESS)
1420         {
1421                 storageType = STORAGE_TYPE_PHONE;
1422         }
1423
1424         if (storageType == STORAGE_TYPE_MEMORYCARD)
1425         {
1426                 filePath = STRING_CONTENT_CAMERA_PATH_EXT;
1427         }
1428         else if (storageType == STORAGE_TYPE_PHONE)
1429         {
1430                 filePath = STRING_CONTENT_CAMERA_PATH;
1431         }
1432         AppLogDebug("SearchContentFilePath :: pFilePath = %ls", filePath.GetPointer());
1433
1434         if (mode == CAMERA_MODE_SNAPSHOT)
1435         {
1436                 r = contentDirectory.Construct(CONTENT_TYPE_IMAGE);
1437         }
1438         else
1439         {
1440                 r = contentDirectory.Construct(CONTENT_TYPE_VIDEO);
1441         }
1442         TryCatch(r == E_SUCCESS, , "contentDirectory.Construct[%s]", GetErrorMessage(r));
1443
1444         countPerPage = contentDirectory.GetContentDirectoryItemCount(filePath);
1445         AppLogDebug("SearchContentFilePath :: countPerPage = %d", countPerPage);
1446
1447         pContentList = contentDirectory.GetContentDirectoryItemListN(filePath,
1448                                                                                                                 SEARCH_PAGE_NO,
1449                                                                                                                 countPerPage,
1450                                                                                                                 CONTENT_INFO_ORDER,
1451                                                                                                                 SORT_ORDER_ASCENDING);
1452         TryCatch(pContentList != null, , "pContentList is null");
1453
1454         __contentCount = pContentList->GetCount();
1455         AppLogDebug("SearchContentFilePath :: __contentCount = %d", __contentCount);
1456
1457         pContentPath = new (std::nothrow) ArrayList();
1458         pContentPath->Construct();
1459
1460         if ((pContentList != null) && (pContentList->GetCount() > 0))
1461         {
1462                 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1463                 while (pEnum->MoveNext() == E_SUCCESS)
1464                 {
1465                         ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
1466                         contentFullPath = pContentInfo->GetContentPath();
1467
1468                         AppLogDebug("SearchContentFilePath :: contentFullPath = %ls", contentFullPath.GetPointer());
1469
1470                         pContentPath->Add(*(new (std::nothrow) String(contentFullPath)));
1471                 }
1472
1473                 delete pEnum;
1474                 pEnum = null;
1475         }
1476
1477         if (pContentList != null)
1478         {
1479                 pContentList->RemoveAll(true);
1480                 delete pContentList;
1481         }
1482
1483         AppLogDebug("EXIT");
1484         return pContentPath;
1485
1486 CATCH:
1487         AppLogDebug("EXIT - CATCH");
1488         return pContentPath;
1489 }
1490
1491 Tizen::Base::String
1492 CameraPresentationModel::SearchContentFilePath(int mode)
1493 {
1494         AppLogDebug("ENTER");
1495         result r = E_SUCCESS;
1496         ContentDirectory contentDirectory;
1497         IList* pContentList = null;
1498         String contentFullPath = L"";
1499         String filePath = L"";
1500         String combineText = L"";
1501         int storageType = 0;
1502         int countPerPage = 0;
1503
1504         r = GetValue(STORAGE_TYPE, storageType);
1505         if (r != E_SUCCESS)
1506         {
1507                 storageType = STORAGE_TYPE_PHONE;
1508         }
1509
1510         if (storageType == STORAGE_TYPE_MEMORYCARD)
1511         {
1512                 filePath = STRING_CONTENT_CAMERA_PATH_EXT;
1513         }
1514         else if (storageType == STORAGE_TYPE_PHONE)
1515         {
1516                 filePath = STRING_CONTENT_CAMERA_PATH;
1517         }
1518         AppLogDebug("SearchContentFilePath :: pFilePath = %ls", filePath.GetPointer());
1519
1520         if (mode == CAMERA_MODE_SNAPSHOT)
1521         {
1522                 r = contentDirectory.Construct(CONTENT_TYPE_IMAGE);
1523         }
1524         else
1525         {
1526                 r = contentDirectory.Construct(CONTENT_TYPE_VIDEO);
1527         }
1528         TryCatch(r == E_SUCCESS, , "contentDirectory.Construct[%s]", GetErrorMessage(r));
1529
1530         countPerPage = contentDirectory.GetContentDirectoryItemCount(filePath);
1531         AppLogDebug("SearchContentFilePath :: countPerPage = %d", countPerPage);
1532
1533         pContentList = contentDirectory.GetContentDirectoryItemListN(filePath,
1534                                                                                                                         SEARCH_PAGE_NO,
1535                                                                                                                         countPerPage,
1536                                                                                                                         CONTENT_INFO_ORDER,
1537                                                                                                                         SORT_ORDER_ASCENDING);
1538         TryCatch(pContentList != null, , "pContentList is null");
1539
1540         __contentCount = pContentList->GetCount();
1541         AppLogDebug("SearchContentFilePath :: __contentCount = %d", __contentCount);
1542
1543         if ((pContentList != null) && (pContentList->GetCount() > 0))
1544         {
1545                 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1546                 while (pEnum->MoveNext() == E_SUCCESS)
1547                 {
1548                         ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
1549                         contentFullPath = pContentInfo->GetContentPath();
1550
1551                         if (combineText.CompareTo(EMPTY_SPACE) != 0)
1552                         {
1553                                 combineText.Append(L";");
1554                         }
1555
1556                         combineText.Append(contentFullPath);
1557                 }
1558
1559                 delete pEnum;
1560                 pEnum = null;
1561         }
1562
1563         AppLogDebug("SearchContentFilePath :: combineText = %ls", combineText.GetPointer());
1564
1565         if (pContentList != null)
1566         {
1567                 pContentList->RemoveAll(true);
1568                 delete pContentList;
1569         }
1570
1571         AppLogDebug("EXIT");
1572         return combineText;
1573
1574 CATCH:
1575         AppLogDebug("EXIT - CATCH");
1576         return combineText;
1577 }
1578
1579 Tizen::Base::String
1580 CameraPresentationModel::GetContentFilePath(int currentCameraMode)
1581 {
1582         AppLogDebug("ENTER");
1583         String contentFullName = L"";
1584
1585         contentFullName = SearchContentFilePath(currentCameraMode);
1586
1587         AppLogDebug("EXIT");
1588         return contentFullName;
1589 }
1590
1591 result
1592 CameraPresentationModel::GetLatestContentName(int currentCameraMode, Tizen::Base::String& latestContentName)
1593 {
1594         AppLogDebug("ENTER");
1595         String contentSubDirectory = STRING_CAMERA_FOLDER_NAME;
1596         String fileExtension = L"";
1597         String directoryEntryName = L"";
1598         String temporaryEntryName = L"";
1599         Directory contentDirectory;
1600         result r = E_SUCCESS;
1601         DirEnumerator* pDirEnum = null;
1602         DateTime directoryEntryDateTime;
1603         DateTime temporaryEntryDateTime = DateTime::GetMinValue();
1604         int storageType = STORAGE_TYPE_PHONE;
1605
1606         AppLogDebug("__lastestContentName content name is %ls",__latestContentName.GetPointer());
1607
1608         r = GetValue(STORAGE_TYPE, storageType);
1609         TryCatch(r == E_SUCCESS, , "Err catch [%s]", GetErrorMessage(r));
1610
1611         if (storageType == STORAGE_TYPE_PHONE)
1612         {
1613                 r = contentDirectory.Construct(Environment::GetMediaPath().GetPointer() + contentSubDirectory);
1614
1615                 AppLogDebug("GetLatestContentName::contentDirectory.Construct r = %s", GetErrorMessage(r));
1616                 if (r == E_FILE_NOT_FOUND)
1617                 {
1618                         r = contentDirectory.Create((Environment::GetMediaPath().GetPointer() + contentSubDirectory), true);
1619                         TryCatch(r == E_SUCCESS, , "contentDirectory Create Fail");
1620
1621                         contentDirectory.Construct(Environment::GetMediaPath().GetPointer() + contentSubDirectory);
1622                 }
1623         }
1624         else if (storageType == STORAGE_TYPE_MEMORYCARD)
1625         {
1626                 r = contentDirectory.Construct(Environment::GetExternalStoragePath().GetPointer() + contentSubDirectory);
1627
1628                 if (r == E_FILE_NOT_FOUND)
1629                 {
1630                         r = contentDirectory.Create((Environment::GetExternalStoragePath().GetPointer() + contentSubDirectory), true);
1631                         TryCatch(r == E_SUCCESS, , "contentDirectory Create Fail");
1632
1633                         contentDirectory.Construct(Environment::GetExternalStoragePath().GetPointer() + contentSubDirectory);
1634                 }
1635         }
1636
1637         pDirEnum = contentDirectory.ReadN();
1638         AppLogDebug("contentDirectory.ReadN()r = %s", GetErrorMessage(GetLastResult()));
1639         TryCatch(pDirEnum != null, r = E_SYSTEM, "pDirEnum is null");
1640
1641         if (currentCameraMode == CAMERA_MODE_SNAPSHOT)
1642         {
1643                 r = fileExtension.Append(STRING_EXTENSION_JPG);
1644                 TryCatch(r == E_SUCCESS, , "String::Append() fail[%s]", GetErrorMessage(r));
1645         }
1646         else
1647         {
1648                 r = fileExtension.Append(STRING_EXTENSION_MP4);
1649                 TryCatch(r == E_SUCCESS, , "String::Append() fail[%s]", GetErrorMessage(r));
1650         }
1651
1652         while (pDirEnum->MoveNext() == E_SUCCESS)
1653         {
1654                  DirEntry directoryEntry = pDirEnum->GetCurrentDirEntry();
1655                  directoryEntryName = directoryEntry.GetName();
1656                  if (directoryEntryName.Contains(fileExtension))
1657                  {
1658                          directoryEntryDateTime = directoryEntry.GetDateTime();
1659                          AppLogDebug("DirEntry::GetDateTime() name %ls Time %ls", directoryEntryName.GetPointer(), directoryEntryDateTime.ToString().GetPointer());
1660
1661                          if (directoryEntryDateTime > temporaryEntryDateTime)
1662                          {
1663                                  temporaryEntryDateTime = directoryEntryDateTime;
1664                                  temporaryEntryName = directoryEntryName;
1665                                  AppLogDebug("dt_temp change Str %ls Time %ls", temporaryEntryName.GetPointer(), temporaryEntryDateTime.ToString().GetPointer());
1666                          }
1667                  }
1668                  else
1669                  {
1670                          AppLogDebug("Dont Contains(fileExtension)");
1671                  }
1672         }
1673
1674         if (!(temporaryEntryName.IsEmpty()))
1675         {
1676                 latestContentName.Clear();
1677                 r = latestContentName.Append(temporaryEntryName);
1678                 TryCatch(r == E_SUCCESS, , "String::Append() fail[%s]", GetErrorMessage(r));
1679
1680                 AppLogDebug("latestContentName = %ls", latestContentName.GetPointer());
1681         }
1682
1683         delete pDirEnum;
1684         pDirEnum = null;
1685
1686         AppLogDebug("EXIT");
1687         return r;
1688
1689 CATCH:
1690         AppLogDebug("EXIT - CATCH");
1691         delete pDirEnum;
1692         pDirEnum = null;
1693
1694         return r;
1695 }
1696
1697 Tizen::Graphics::Dimension
1698 CameraPresentationModel::GetPreviewResolution(void) const
1699 {
1700         AppLogDebug("ENTER");
1701         Dimension dimension(INIT, INIT);
1702
1703         if (__pCamera != null)
1704         {
1705                 dimension = __pCamera->GetPreviewResolution();
1706         }
1707
1708         AppLogDebug("CameraPresentationModel::GetPreviewResolution(%d, %d)", dimension.width, dimension.height);
1709
1710         AppLogDebug("EXIT");
1711         return dimension;
1712 }
1713
1714 result
1715 CameraPresentationModel::SetPreviewResolution(Tizen::Graphics::Dimension previewResolution)
1716 {
1717         AppLogDebug("ENTER");
1718         result r = E_SUCCESS;
1719
1720         r = __pCamera->SetPreviewResolution(previewResolution);
1721         TryCatch(r == E_SUCCESS, , "Camera::SetPreviewResolution fail[%s]", GetErrorMessage(r));
1722
1723         AppLogDebug("EXIT");
1724         return r;
1725
1726 CATCH:
1727         AppLogDebug("EXIT - CATCH");
1728         return r;
1729 }
1730
1731 Tizen::Graphics::Dimension
1732 CameraPresentationModel::GetCaptureResolution(void) const
1733 {
1734         AppLogDebug("ENTER");
1735         Dimension dimension(INIT, INIT);
1736
1737         if (__pCamera != null)
1738         {
1739                 dimension = __pCamera->GetCaptureResolution();
1740         }
1741
1742         AppLogDebug("CameraPresentationModel::GetCaptureResolution(%d, %d)", dimension.width, dimension.height);
1743
1744         AppLogDebug("EXIT");
1745         return dimension;
1746 }
1747
1748 result
1749 CameraPresentationModel::SetCaptureResolution(Tizen::Graphics::Dimension captureResolution)
1750 {
1751         AppLogDebug("ENTER");
1752         result r = E_SUCCESS;
1753
1754         if (__pCamera != null)
1755         {
1756                 r = __pCamera->SetCaptureResolution(captureResolution);
1757                 TryCatch(r == E_SUCCESS, , "Camera::SetCaptureResolution fail[%s]", GetErrorMessage(r));
1758         }
1759         AppLogDebug("EXIT");
1760         return r;
1761
1762 CATCH:
1763         AppLogDebug("EXIT - CATCH");
1764         return r;
1765 }
1766
1767 Tizen::Graphics::Dimension
1768 CameraPresentationModel::GetRecordingResolution(void) const
1769 {
1770         AppLogDebug("ENTER");
1771         Dimension dimension(INIT, INIT);
1772
1773         if (__pVideoRecorder != null)
1774         {
1775                 dimension = __pVideoRecorder->GetRecordingResolution();
1776         }
1777         AppLogDebug("CameraPresentationModel::GetRecordingResolution(%d, %d)", dimension.width, dimension.height);
1778
1779         AppLogDebug("EXIT");
1780         return dimension;
1781 }
1782
1783 result
1784 CameraPresentationModel::SetRecordingResolution(Tizen::Graphics::Dimension previewResolution)
1785 {
1786         AppLogDebug("ENTER");
1787         result r = E_SUCCESS;
1788
1789         r = __pVideoRecorder->SetRecordingResolution(previewResolution);
1790         TryCatch(r == E_SUCCESS, , "Camera::SetRecordingResolution fail[%s]", GetErrorMessage(r));
1791
1792         AppLogDebug("EXIT");
1793         return r;
1794
1795 CATCH:
1796         AppLogDebug("EXIT - CATCH");
1797         return r;
1798 }
1799
1800 Tizen::Base::Collection::IList*
1801 CameraPresentationModel::GetCaptureResolutionList(void)
1802 {
1803         AppLogDebug("ENTER");
1804         result r = E_SUCCESS;
1805         int selfPortraitEnable = 0;
1806
1807         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1808
1809         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
1810         {
1811                 AppLogDebug("CAM_SELF_PORTRAIT_MODE_PRIMARY");
1812                 __pCaptureResolutionList = MediaCapability::GetValueN(CAMERA_PRIMARY_CAPTURE_RESOLUTION);
1813                 TryCatch(__pCaptureResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1814         }
1815         else
1816         {
1817                 AppLogDebug("CAM_SELF_PORTRAIT_MODE_SECONDARY");
1818                 __pCaptureResolutionList = MediaCapability::GetValueN(CAMERA_SECONDARY_CAPTURE_RESOLUTION);
1819                 TryCatch(__pCaptureResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1820         }
1821
1822         AppLogDebug("EXIT");
1823         return __pCaptureResolutionList;
1824
1825 CATCH:
1826         AppLogDebug("EXIT - CATCH");
1827         if (__pCaptureResolutionList)
1828         {
1829                 __pCaptureResolutionList->RemoveAll(true);
1830         }
1831
1832         delete __pCaptureResolutionList;
1833
1834         __pCaptureResolutionList = null;
1835
1836         return __pCaptureResolutionList;
1837 }
1838
1839 Tizen::Base::Collection::IList*
1840 CameraPresentationModel::GetPreviewResolutionList(void)
1841 {
1842         AppLogDebug("ENTER");
1843         result r = E_SUCCESS;
1844         int selfPortraitEnable = 0;
1845
1846         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1847
1848         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
1849         {
1850                 if (__pPreviewResolutionList != null)
1851                 {
1852                         __pPreviewResolutionList->RemoveAll(true);
1853                         delete __pPreviewResolutionList;
1854                         __pPreviewResolutionList = null;
1855                 }
1856                 __pPreviewResolutionList = MediaCapability::GetValueN(CAMERA_PRIMARY_PREVIEW_RESOLUTION);
1857                 TryCatch(__pPreviewResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1858         }
1859         else
1860         {
1861                 __pPreviewResolutionList = MediaCapability::GetValueN(CAMERA_SECONDARY_PREVIEW_RESOLUTION);
1862                 TryCatch(__pPreviewResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1863         }
1864
1865         AppLogDebug("EXIT");
1866         return __pPreviewResolutionList;
1867
1868 CATCH:
1869         AppLogDebug("EXIT - CATCH");
1870         if (__pPreviewResolutionList)
1871         {
1872                 __pPreviewResolutionList->RemoveAll(true);
1873         }
1874
1875         delete __pPreviewResolutionList;
1876
1877         __pPreviewResolutionList = null;
1878
1879         return __pPreviewResolutionList;
1880 }
1881
1882 Tizen::Base::Collection::IList*
1883 CameraPresentationModel::GetRecordingResolutionList(void)
1884 {
1885         AppLogDebug("ENTER");
1886         result r = E_SUCCESS;
1887         int selfPortraitEnable = 0;
1888
1889         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
1890
1891         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
1892         {
1893                 __pRecordingResolutionList = MediaCapability::GetValueN(CAMERA_PRIMARY_RECORDING_RESOLUTION);
1894                 TryCatch(__pRecordingResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1895         }
1896         else
1897         {
1898                 __pRecordingResolutionList = MediaCapability::GetValueN(CAMERA_PRIMARY_RECORDING_RESOLUTION);
1899                 TryCatch(__pRecordingResolutionList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
1900         }
1901
1902         AppLogDebug("EXIT");
1903         return __pRecordingResolutionList;
1904
1905 CATCH:
1906         AppLogDebug("EXIT - CATCH");
1907         if (__pRecordingResolutionList)
1908         {
1909                 __pRecordingResolutionList->RemoveAll(true);
1910         }
1911
1912         delete __pRecordingResolutionList;
1913
1914         __pRecordingResolutionList = null;
1915
1916         return __pRecordingResolutionList;
1917 }
1918
1919 bool
1920 CameraPresentationModel::IsPreviewState(void)
1921 {
1922         AppLogDebug("ENTER");
1923         if (GetCameraState() == CAMERA_STATE_PREVIEW)
1924         {
1925                 AppLogDebug("IsPreviewState YES");
1926                 AppLogDebug("EXIT");
1927                 return true;
1928         }
1929         else
1930         {
1931                 AppLogDebug("IsPreviewState NOT");
1932                 AppLogDebug("EXIT");
1933                 return false;
1934         }
1935
1936         AppLogDebug("EXIT");
1937         return false;
1938 }
1939
1940 bool
1941 CameraPresentationModel::IsCameraInstance(void)
1942 {
1943         AppLogDebug("ENTER");
1944         if (__pCamera == null)
1945         {
1946                 AppLogDebug("EXIT - __pCamera is null");
1947                 return false;
1948         }
1949
1950         AppLogDebug("EXIT");
1951         return true;
1952 }
1953
1954 bool
1955 CameraPresentationModel::IsCameraPoweredOn(void)
1956 {
1957         AppLogDebug("ENTER");
1958         AppLogDebug("IsPoweredOn State[%d]", __pCamera->IsPoweredOn());
1959         AppLogDebug("EXIT");
1960         return __pCamera->IsPoweredOn();
1961 }
1962
1963 bool
1964 CameraPresentationModel::IsStorageCardMounted(void) const
1965 {
1966         AppLogDebug("ENTER");
1967         String strState = L"";
1968
1969         DeviceManager::GetState(StorageCard, strState);
1970
1971         if (strState == STRING_SDCARD_MOUNTED_STATE)
1972         {
1973                 AppLogDebug("EXIT");
1974                 return true;
1975         }
1976         else
1977         {
1978                 AppLogDebug("EXIT");
1979                 return false;
1980         }
1981 }
1982
1983 bool
1984 CameraPresentationModel::IsCharging(void)
1985 {
1986         AppLogDebug("ENTER");
1987         bool isCharging = false;
1988         isCharging = PowerManager::IsCharging();
1989         AppLogDebug("charging status is %d",isCharging);
1990         AppLogDebug("EXIT");
1991         return isCharging;
1992 }
1993
1994 bool
1995 CameraPresentationModel::GetStartPreviewException(void)
1996 {
1997         AppLogDebug("ENTER");
1998         AppLogDebug("EXIT - Error %d", __startPreviewException);
1999         return __startPreviewException;
2000 }
2001
2002 bool
2003 CameraPresentationModel::GetIntervalTimerRun(void) const
2004 {
2005         AppLogDebug("ENTER");
2006         AppLogDebug("EXIT - __isIntervalTimerRun = %d", __isIntervalTimerRun);
2007         return __isIntervalTimerRun;
2008 }
2009
2010 void
2011 CameraPresentationModel::SetIntervalTimerRun(bool intervalTimerRun)
2012 {
2013         AppLogDebug("ENTER");
2014         __isIntervalTimerRun = intervalTimerRun;
2015         AppLogDebug("EXIT");
2016 }
2017
2018 bool
2019 CameraPresentationModel::GetPreviewState(void) const
2020 {
2021         AppLogDebug("ENTER");
2022         AppLogDebug("EXIT - __isPreviewExit = %d", __isPreviewExit);
2023         return __isPreviewExit;
2024 }
2025
2026 void
2027 CameraPresentationModel::StartPreview(const Tizen::Graphics::BufferInfo* pBufferInfo)
2028 {
2029         AppLogDebug("ENTER");
2030         result r = E_SUCCESS;
2031
2032         AppLogDebug("GetCameraState = %d", __pCamera->GetState());
2033         if (GetCameraState() == CAMERA_STATE_INITIALIZED || GetCameraState() == CAMERA_STATE_CAPTURED)
2034         {
2035                 r = __pCamera->StartPreview(pBufferInfo, false);
2036                 if (r == E_DEVICE_BUSY || r == E_DEVICE_UNAVAILABLE || r == E_SYSTEM)
2037                 {
2038                         __startPreviewException = true;
2039                 }
2040                 else
2041                 {
2042                         __startPreviewException = false;
2043                 }
2044                  __isPreviewExit = true;
2045                 TryReturnVoid(r == E_SUCCESS, "Camera::StartPreview() fail[%s]", GetErrorMessage(r));
2046         }
2047         else
2048         {
2049                 AppLogDebug("Before the StartPreview() method is called, camera state should be CAMERA_STATE_INITIALIZED or CAMERA_STATE_CAPTURED");
2050         }
2051
2052         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_BACK_BUTTON_ACTIVATED);
2053         AppLogDebug("EXIT");
2054 }
2055
2056 void
2057 CameraPresentationModel::StopPreview(void)
2058 {
2059         AppLogDebug("ENTER");
2060         result r = E_SUCCESS;
2061
2062         if (__pCamera != null)
2063         {
2064                 if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
2065                 {
2066                         r = __pCamera->StopPreview();
2067                         TryReturnVoid(r == E_SUCCESS, "Camera::StopPreview() [%s]", GetErrorMessage(r));
2068                 }
2069         }
2070         AppLogDebug("EXIT");
2071 }
2072
2073 void
2074 CameraPresentationModel::StopCamera(void)
2075 {
2076         AppLogDebug("ENTER");
2077         result r = E_SUCCESS;
2078
2079         if (__isInitCamera == false)
2080         {
2081                 AppLogDebug("Camera Construct fail or Memory allocation Fail");
2082                 return;
2083         }
2084
2085         if (__pVideoRecorder != null)
2086         {
2087                 AppLogDebug("VideoRecorder State[%d]", __pVideoRecorder->GetState());
2088
2089                 if (__pVideoRecorder->GetState()== RECORDER_STATE_RECORDING
2090                         || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSED
2091                 )
2092                 {
2093                         r = __pVideoRecorder->Stop();
2094                         TryReturnVoid(r == E_SUCCESS, "__pVideoRecorder::Stop() [%s]", GetErrorMessage(r));
2095                 }
2096         }
2097
2098         if (__pCamera != null)
2099         {
2100                 AppLogDebug("Camera State[%d]", __pCamera->GetState());
2101
2102                 if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
2103                 {
2104                         r = __pCamera->StopPreview();
2105                         TryReturnVoid(r == E_SUCCESS, "Camera::StopPreview() [%s]", GetErrorMessage(r));
2106                 }
2107
2108                 if (__pCamera->IsPoweredOn() == true)
2109                 {
2110                         r = __pCamera->PowerOff();
2111                         TryReturnVoid(r == E_SUCCESS, "Camera::PowerOff() [%s]", GetErrorMessage(r));
2112                 }
2113         }
2114         AppLogDebug("EXIT");
2115 }
2116
2117 void
2118 CameraPresentationModel::Capture(void)
2119 {
2120         AppLogDebug("ENTER");
2121         result r = E_SUCCESS;
2122
2123         if (GetCameraState() == CAMERA_STATE_PREVIEW)
2124         {
2125                 r = __pCamera->Capture();
2126                 TryReturnVoid( r == E_SUCCESS, "Camera::Capture() fail[%s]", GetErrorMessage(r));
2127         }
2128         else
2129         {
2130                 AppLogDebug("Before the Capture() method is called, camera state should be CAMERA_STATE_PREVIEW");
2131         }
2132         AppLogDebug("EXIT");
2133 }
2134
2135 long
2136 CameraPresentationModel::GetMaxRecordingTime(void)
2137 {
2138         AppLogDebug("ENTER");
2139         long getMaxRecordingTime = 0;
2140
2141         getMaxRecordingTime = __pVideoRecorder->GetMaxRecordingTime();
2142
2143         AppLogDebug("GetMaxRecordingTime = %d EXIT", getMaxRecordingTime);
2144         return getMaxRecordingTime;
2145 }
2146
2147 long
2148 CameraPresentationModel::GetRecordingSize(void)
2149 {
2150         AppLogDebug("ENTER");
2151         long getRecordingSize = 0;
2152
2153         getRecordingSize = __pVideoRecorder->GetRecordingSize();
2154
2155         AppLogDebug("EXIT - GetRecordingSize = %d", getRecordingSize);
2156         return getRecordingSize;
2157 }
2158
2159 void
2160 CameraPresentationModel::StartRecord(void)
2161 {
2162         AppLogDebug("ENTER");
2163         String* pFullFileName = null;
2164         result r = E_SUCCESS;
2165         long maxRecordDefaultTime = 0;
2166         String camcorderTemporaryFilePath;
2167         RecordingRotation rotate = RECORDING_ROTATION_NONE;
2168         int storageType = STORAGE_TYPE_PHONE;
2169
2170         __onVideoRecorderStarted = true;
2171
2172         AppLogDebug("Record GetRecorderState = %d", GetRecorderState());
2173         if (GetRecorderState() == RECORDER_STATE_PAUSED || GetRecorderState() == RECORDER_STATE_PAUSING)
2174         {
2175                 AppLogDebug("RECORDER_STATE_PAUSED or RECORDER_STATE_PAUSING ==> RECORDER_STATE_RECORDING");
2176
2177                 r = __pVideoRecorder->Record();
2178                 TryCatch(r == E_SUCCESS, , "VideoRecorder::Record() fail[%s]", GetErrorMessage(r));
2179
2180                 r = SetFlashModeOnRecord(true);
2181                 AppLogDebug("SetFlashModeOnRecord fail[%s]", GetErrorMessage(r));
2182
2183                 AppLogDebug("EXIT");
2184                 return;
2185         }
2186
2187         r = GetValue(STORAGE_TYPE, storageType);
2188         if (r != E_SUCCESS)
2189         {
2190                 storageType = STORAGE_TYPE_PHONE;
2191         }
2192
2193         if (storageType == STORAGE_TYPE_PHONE)
2194         {
2195                 camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", App::GetInstance()->GetAppRootPath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE);
2196         }
2197         else
2198         {
2199                 camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", Environment::GetExternalStoragePath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE_EXT);
2200         }
2201
2202         pFullFileName = new (std::nothrow) String();
2203         r = CreateFileName(*pFullFileName);
2204         TryCatch(r == E_SUCCESS, , "pFullFileName is null");
2205
2206         __latestContentName.Clear();
2207         r = __latestContentName.Append(pFullFileName->GetPointer());
2208         TryCatch(r == E_SUCCESS, , "String::Append() fail[%s]", GetErrorMessage(r));
2209
2210         AppLogDebug("Record pFullFileName = %ls", pFullFileName->GetPointer());
2211         if (__pVideoRecorder == null)
2212         {
2213                 __pVideoRecorder = new (std::nothrow) VideoRecorder();
2214                 __pVideoRecorder->Construct(*this, *__pCamera);
2215         }
2216
2217         r = __pVideoRecorder->SetQuality(RECORDING_QUALITY_HIGH);
2218         TryCatch(r == E_SUCCESS, , "VideoRecorder::SetQuality() fail[%s]", GetErrorMessage(r));
2219
2220         maxRecordDefaultTime = RECORD_DEFAULT_SEC * SECONDS_PER_MINUTE;
2221
2222         r = __pVideoRecorder->SetMaxRecordingTime(maxRecordDefaultTime);
2223         TryCatch(r == E_SUCCESS, , "VideoRecorder::SetMaxRecordingTime() fail[%s]", GetErrorMessage(r));
2224
2225         r = __pVideoRecorder->SetFormat(CODEC_AAC, CODEC_MPEG4, MEDIA_CONTAINER_MP4);
2226         TryCatch(r == E_SUCCESS, , "VideoRecorder::SetFormat() fail[%s]", GetErrorMessage(r));
2227
2228         rotate = GetRecordingRotation();
2229         AppLogDebug("StartRecord rotate = %d",rotate);
2230
2231         r = __pVideoRecorder->SetRecordingRotation(rotate);
2232         TryCatch(r == E_SUCCESS, , "VideoRecorder::SetRecordingRotation() fail[%s]", GetErrorMessage(r));
2233
2234         AppLogDebug("latest file name is %ls",__latestContentName.GetPointer());
2235         r = __pVideoRecorder->CreateVideoFile(__latestContentName, true);
2236         AppLogDebug("create video file result is %s",GetErrorMessage(r));
2237         TryCatch(r == E_SUCCESS, , "VideoRecorder::CreateVideoFile() fail[%s]", GetErrorMessage(r));
2238
2239         r = __pVideoRecorder->Record();
2240         TryCatch(r == E_SUCCESS, , "VideoRecorder::Record() fail[%s]", GetErrorMessage(r));
2241
2242         delete pFullFileName;
2243         pFullFileName = null;
2244
2245         r = SetFlashModeOnRecord(true);
2246         AppLogDebug("SetFlashModeOnRecord fail[%s]", GetErrorMessage(r));
2247
2248         AppLogDebug("EXIT");
2249         return;
2250
2251 CATCH:
2252         AppLogDebug("EXIT - CATCH");
2253         __onVideoRecorderStarted = false;
2254         delete pFullFileName;
2255         pFullFileName = null;
2256 }
2257
2258 void
2259 CameraPresentationModel::SetCancelRecord(bool isCancel)
2260 {
2261         AppLogDebug("ENTER");
2262         __isCancelRecord = isCancel;    
2263         AppLogDebug("EXIT");
2264 }
2265
2266 result
2267 CameraPresentationModel::StopRecord(void)
2268 {
2269         AppLogDebug("ENTER");
2270         result r = E_SUCCESS;
2271
2272         if (__pVideoRecorder != null)
2273         {
2274                 r = __pVideoRecorder->Stop();
2275                 AppLogDebug("stop record result is %s",GetErrorMessage(r));
2276                 //TryReturnVoid(r == E_SUCCESS, "VideoRecorder::Stop() fail[%s]", GetErrorMessage(r));
2277         }
2278         AppLogDebug("EXIT");
2279         return r;
2280 }
2281
2282 void
2283 CameraPresentationModel::CloseRecord(void)
2284 {
2285         AppLogDebug("ENTER");
2286         result r = E_SUCCESS;
2287
2288         if (__pVideoRecorder != null)
2289         {
2290                 r = __pVideoRecorder->Close();
2291                 TryReturnVoid(r == E_SUCCESS, "VideoRecorder::Close() fail[%s]", GetErrorMessage(r));
2292         }
2293         AppLogDebug("EXIT");
2294 }
2295
2296 void
2297 CameraPresentationModel::CancelRecord(void)
2298 {
2299         AppLogDebug("ENTER");
2300         result r = E_SUCCESS;
2301
2302         if (__pVideoRecorder != null)
2303         {
2304                 r = __pVideoRecorder->Cancel();
2305                 TryReturnVoid(r == E_SUCCESS, "VideoRecorder::Cancel() fail[%s]", GetErrorMessage(r));
2306         }
2307         AppLogDebug("EXIT");
2308 }
2309
2310 void
2311 CameraPresentationModel::PauseRecord(void)
2312 {
2313         AppLogDebug("ENTER");
2314         result r = E_SUCCESS;
2315
2316         if (__pVideoRecorder != null)
2317         {
2318                 r = __pVideoRecorder->Pause();
2319                 TryReturnVoid(r == E_SUCCESS, "VideoRecorder::Pause() fail[%s]", GetErrorMessage(r));
2320         }
2321         AppLogDebug("EXIT");
2322 }
2323
2324 void
2325 CameraPresentationModel::SetFlip(CameraFlipType type)
2326 {
2327         AppLogDebug("ENTER");
2328         result r = E_SUCCESS;
2329         int selfPortraitEnable = 0;
2330
2331         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
2332
2333         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
2334         {
2335                 r = GetMediaCapability(CAMERA_PRIMARY_FLIP);
2336         }
2337         else
2338         {
2339                 r = GetMediaCapability(CAMERA_SECONDARY_FLIP);
2340         }
2341
2342         if (r == E_SUCCESS)
2343         {
2344                 r = __pCamera->SetFlip(type);
2345                 TryReturnVoid(r == E_SUCCESS, "Camera::SetFlip() [%s]", GetErrorMessage(r));
2346         }
2347         else
2348         {
2349                 AppLogDebug("SetFlip is not support");
2350         }
2351         AppLogDebug("EXIT");
2352 }
2353
2354 CameraFlipType
2355 CameraPresentationModel::GetFlip(void) const
2356 {
2357         AppLogDebug("ENTER");
2358         AppLogDebug("EXIT");
2359         return __pCamera->GetFlip();
2360 }
2361
2362 void
2363 CameraPresentationModel::SetFocusMode(CameraFocusMode mode)
2364 {
2365         AppLogDebug("ENTER");
2366         result r = E_SUCCESS;
2367
2368         r = __pCamera->SetFocusMode(mode);
2369         TryReturnVoid(r == E_SUCCESS, "Camera::SetFocusMode() [%s]", GetErrorMessage(r));
2370         AppLogDebug("EXIT");
2371 }
2372
2373 void
2374 CameraPresentationModel::SetContinuousAutoFocus(void)
2375 {
2376         AppLogDebug("ENTER");
2377         result r = E_SUCCESS;
2378
2379         if (__pCamera != null)
2380         {
2381                 r = __pCamera->SetFocusMode(CAMERA_FOCUS_MODE_CONTINUOUS_AUTO);
2382                 TryReturnVoid(r == E_SUCCESS, "Camera::SetFocusMode() [%s]", GetErrorMessage(r));
2383
2384                 r = __pCamera->SetAutoFocus(true);
2385                 TryReturnVoid(r == E_SUCCESS, "Camera::SetAutoFocus() [%s]", GetErrorMessage(r));
2386         }
2387         AppLogDebug("EXIT");
2388 }
2389
2390 void
2391 CameraPresentationModel::SetAutoFocusPoint(const Tizen::Graphics::Point& currentPosition)
2392 {
2393         AppLogDebug("ENTER");
2394         result r = E_SUCCESS;
2395         ArrayList currentPositionList;
2396         currentPositionList.Construct();
2397         currentPositionList.Add(currentPosition);
2398
2399         r = __pCamera->SetFocusMode(CAMERA_FOCUS_MODE_NORMAL);
2400         TryReturnVoid(r == E_SUCCESS, "Camera::SetFocusMode() [%s]", GetErrorMessage(r));
2401
2402         r = __pCamera->SetAutoFocusPoint(currentPositionList);
2403         TryReturnVoid(r == E_SUCCESS, "Camera::SetAutoFocusPoint() [%s]", GetErrorMessage(r));
2404
2405         r = __pCamera->SetAutoFocus(true);
2406         TryReturnVoid(r == E_SUCCESS, "Camera::SetAutoFocus() [%s]", GetErrorMessage(r));
2407         AppLogDebug("EXIT");
2408 }
2409
2410 int
2411 CameraPresentationModel::GetExposure(void) const
2412 {
2413         AppLogDebug("ENTER");
2414         int exposureValue = 0;
2415
2416         exposureValue = __pCamera->GetExposure();
2417
2418         AppLogDebug("EXIT");
2419         return exposureValue;
2420 }
2421
2422 void
2423 CameraPresentationModel::SetExposure(int exposureValue)
2424 {
2425         AppLogDebug("ENTER");
2426         result r = E_SUCCESS;
2427
2428         exposureValue = MAX_CAMERA_EXPOSURE_VALUE - exposureValue;
2429
2430         r = __pCamera->SetExposure(exposureValue);
2431         TryReturnVoid(r == E_SUCCESS, "SetExposure() fail[%s]", GetErrorMessage(r));
2432         AppLogDebug("EXIT");
2433 }
2434
2435 int
2436 CameraPresentationModel::GetBrightness(void) const
2437 {
2438         AppLogDebug("ENTER");
2439         int brightnessValue = 0;
2440
2441         brightnessValue = __pCamera->GetBrightness();
2442
2443         AppLogDebug("EXIT");
2444         return brightnessValue;
2445 }
2446
2447 void
2448 CameraPresentationModel::SetBrightness(int brightnessValue)
2449 {
2450         AppLogDebug("ENTER");
2451         result r = E_SUCCESS;
2452
2453         brightnessValue = MAX_CAMERA_EXPOSURE_VALUE - brightnessValue;
2454
2455         r = __pCamera->SetBrightness(brightnessValue);
2456         TryReturnVoid(r == E_SUCCESS, "Camera::SetBrightness() fail[%s]", GetErrorMessage(r));
2457         AppLogDebug("EXIT");
2458 }
2459
2460 CameraWhiteBalance
2461 CameraPresentationModel::GetWhiteBalance(void) const
2462 {
2463         AppLogDebug("ENTER");
2464         CameraWhiteBalance whiteBalanceValue = CAMERA_WHITE_BALANCE_AUTO;
2465
2466         whiteBalanceValue = __pCamera->GetWhiteBalance();
2467
2468         AppLogDebug("EXIT");
2469         return whiteBalanceValue;
2470 }
2471
2472 result
2473 CameraPresentationModel::SetWhiteBalance(CameraWhiteBalance whitebalanceValue)
2474 {
2475         AppLogDebug("ENTER");
2476         result r = E_SUCCESS;
2477
2478         r = __pCamera->SetWhiteBalance(whitebalanceValue);
2479
2480         AppLogDebug("EXIT");
2481         return r;
2482 }
2483
2484 Tizen::Base::Collection::IList*
2485 CameraPresentationModel::GetIsoList(void)
2486 {
2487         AppLogDebug("ENTER");
2488         result r = E_SUCCESS;
2489         int selfPortraitEnable = 0;
2490
2491         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
2492
2493         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
2494         {
2495                 __pIsoList = MediaCapability::GetValueN(CAMERA_PRIMARY_ISO_LEVEL);
2496                 TryCatch(__pIsoList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
2497         }
2498         else
2499         {
2500                 __pIsoList = MediaCapability::GetValueN(CAMERA_SECONDARY_ISO_LEVEL);
2501                 TryCatch(__pIsoList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(GetLastResult()));
2502         }
2503
2504         AppLogDebug("EXIT");
2505         return __pIsoList;
2506
2507 CATCH:
2508         AppLogDebug("EXIT - CATCH");
2509         if (__pIsoList)
2510         {
2511                 __pIsoList->RemoveAll(true);
2512         }
2513
2514         delete __pIsoList;
2515
2516         __pIsoList = null;
2517
2518         return __pIsoList;
2519 }
2520
2521 CameraIsoLevel
2522 CameraPresentationModel::GetIsoLevel(void) const
2523 {
2524         AppLogDebug("ENTER");
2525         CameraIsoLevel isoValue = CAMERA_ISO_DEFAULT;
2526
2527         isoValue = __pCamera->GetIsoLevel();
2528
2529         AppLogDebug("EXIT");
2530         return isoValue;
2531 }
2532
2533 void
2534 CameraPresentationModel::SetIsoLevel(CameraIsoLevel isoValue)
2535 {
2536         AppLogDebug("ENTER");
2537         result r = E_SUCCESS;
2538
2539         r = __pCamera->SetIsoLevel(isoValue);
2540         TryReturnVoid(r == E_SUCCESS, "SetIsoLevel() fail[%s]", GetErrorMessage(r));
2541         AppLogDebug("EXIT");
2542 }
2543
2544 int
2545 CameraPresentationModel::GetMaxZoomLevel(void) const
2546 {
2547         AppLogDebug("ENTER");
2548         int zoomLevel = 0;
2549
2550         zoomLevel = __pCamera->GetMaxZoomLevel();
2551
2552         AppLogDebug("EXIT");
2553         return zoomLevel;
2554 }
2555
2556 int
2557 CameraPresentationModel::GetZoomLevel(void) const
2558 {
2559         AppLogDebug("ENTER");
2560         int zoomLevel = 0;
2561
2562         zoomLevel = __pCamera->GetZoomLevel();
2563
2564         AppLogDebug("EXIT");
2565         return zoomLevel;
2566 }
2567
2568 void
2569 CameraPresentationModel::SetZoomValue(int zoomValue)
2570 {
2571         AppLogDebug("ENTER");
2572         result r = E_SUCCESS;
2573
2574         int currentZoomValue = __pCamera->GetZoomLevel();
2575
2576         if (currentZoomValue < zoomValue)
2577         {
2578                 for (int i = currentZoomValue; i < zoomValue; i++)
2579                 {
2580                         r = __pCamera->ZoomIn();
2581                         TryReturnVoid(r == E_SUCCESS, "ZoomIn() fail[%s]", GetErrorMessage(r));
2582                 }
2583         }
2584         else
2585         {
2586                 for (int i = currentZoomValue; i > zoomValue; i--)
2587                 {
2588                         r = __pCamera->ZoomOut();
2589                         TryReturnVoid(r == E_SUCCESS, "ZoomOut() fail[%s]", GetErrorMessage(r));
2590                 }
2591         }
2592         AppLogDebug("EXIT");
2593 }
2594
2595 CameraFlashMode
2596 CameraPresentationModel::GetFlashMode(void) const
2597 {
2598         AppLogDebug("ENTER");
2599         CameraFlashMode cameraFlashMode = CAMERA_FLASH_MODE_OFF;
2600
2601         cameraFlashMode = __pCamera->GetFlashMode();
2602
2603         AppLogDebug("Get flashMode = %d", cameraFlashMode);
2604
2605         AppLogDebug("EXIT");
2606         return cameraFlashMode;
2607 }
2608
2609 result
2610 CameraPresentationModel::SetFlashModeOnRecord(bool flashOn)
2611 {
2612         AppLogDebug("ENTER");
2613         result ret = E_SUCCESS;
2614         int selfPortraitEnable = 0;
2615         int flashMode = 0;
2616
2617         ret = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
2618         if (ret != E_SUCCESS)
2619         {
2620                 selfPortraitEnable = CAM_SELF_PORTRAIT_MODE_PRIMARY;
2621         }
2622
2623         if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
2624         {
2625                 ret = GetMediaCapability(CAMERA_PRIMARY_FLASH_MODE);
2626         }
2627         else
2628         {
2629                 ret = GetMediaCapability(CAMERA_SECONDARY_FLASH_MODE);
2630         }
2631
2632         if (ret == E_SUCCESS)
2633         {
2634                 if (selfPortraitEnable == CAM_SELF_PORTRAIT_MODE_PRIMARY)
2635                 {
2636                         ret = __pCameraSettingsPresentationModel->GetValue(SECTION_CAMCORDER, FLASH_MODE_PRIMARY, flashMode);
2637                 }
2638                 else
2639                 {
2640                         ret = __pCameraSettingsPresentationModel->GetValue(SECTION_CAMCORDER, FLASH_MODE_SECONDARY, flashMode);
2641                 }
2642                 TryCatch(ret == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(ret));
2643
2644                 AppLogDebug("flashMode = %d", flashMode);
2645
2646                 if (__pCamera->IsPoweredOn() == true && flashMode == FLASH_TYPE_ON)
2647                 {
2648                         AppLogDebug("SetFlashModeOnRecord flashOn = %d", flashOn);
2649
2650                         if (flashOn)
2651                         {
2652                                 ret = __pCamera->SetFlashMode(CAMERA_FLASH_MODE_CONTINUOUS);
2653                                 TryCatch(ret == E_SUCCESS, , "SetFlashMode() fail[%s]", GetErrorMessage(ret));
2654                         }
2655                         else
2656                         {
2657                                 ret = __pCamera->SetFlashMode(CAMERA_FLASH_MODE_ON); //CAMERA_FLASH_MODE_OFF >>is TAF don't flash on
2658                                 TryCatch(ret == E_SUCCESS, , "SetFlashMode() fail[%s]", GetErrorMessage(ret));
2659                         }
2660                 }
2661                 else
2662                 {
2663                         AppLogDebug("Camera PoweredOff status");
2664                 }
2665         }
2666
2667         AppLogDebug("EXIT");
2668         return ret;
2669
2670 CATCH:
2671         AppLogDebug("EXIT - CATCH");
2672         return ret;
2673 }
2674
2675 result
2676 CameraPresentationModel::SetFlashMode(CameraFlashMode mode)
2677 {
2678         AppLogDebug("ENTER");
2679         result r = E_SUCCESS;
2680
2681         AppLogDebug("Set flashMode = %d", mode);
2682
2683         if (__pCamera != null)
2684         {
2685                 if (mode == CAMERA_FLASH_MODE_OFF)
2686                 {
2687                         if (__pCamera->IsFlashOn())
2688                         {
2689                                 r = __pCamera->SetFlashMode(CAMERA_FLASH_MODE_OFF);
2690                                 AppLogDebug("Set SetFlashMode = %s", GetErrorMessage(r));
2691                         }
2692                 }
2693                 else
2694                 {
2695                         r = __pCamera->SetFlashMode(mode);
2696                         AppLogDebug("Set SetFlashMode = %s", GetErrorMessage(r));
2697                 }
2698         }
2699         else
2700         {
2701                 AppLogDebug("__pCamera is null");
2702                 r = E_FAILURE;
2703         }
2704         AppLogDebug("EXIT");
2705         return r;
2706 }
2707
2708 Tizen::Ui::OrientationStatus
2709 CameraPresentationModel::GetOrientation(void) const
2710 {
2711         AppLogDebug("ENTER");
2712         AppLogDebug("EXIT");
2713         return __dir;
2714 }
2715
2716 void
2717 CameraPresentationModel::SetOrientation(Tizen::Ui::OrientationStatus dir)
2718 {
2719         AppLogDebug("ENTER");
2720         AppLogDebug("EXIT");
2721         __dir = dir;
2722 }
2723
2724 int
2725 CameraPresentationModel::GetAppControlRequestType(void) const
2726 {
2727         AppLogDebug("ENTER");
2728         AppLogDebug("EXIT");
2729         return __appControlRequestType;
2730 }
2731
2732 void
2733 CameraPresentationModel::SetAppControlRequestType(int requestType)
2734 {
2735         AppLogDebug("ENTER");
2736         __appControlRequestType = requestType;
2737         AppLogDebug("EXIT");
2738 }
2739
2740 Tizen::Base::String
2741 CameraPresentationModel::GetErrorResult(void) const
2742 {
2743         AppLogDebug("ENTER");
2744         AppLogDebug("EXIT");
2745         return __errorResult;
2746 }
2747
2748 void
2749 CameraPresentationModel::SetErrorResult(const Tizen::Base::String& string)
2750 {
2751         AppLogDebug("ENTER");
2752         __errorResult = string;
2753         AppLogDebug("EXIT");
2754 }
2755
2756 Tizen::System::BatteryLevel
2757 CameraPresentationModel::GetBatteryLevel(void) const
2758 {
2759         AppLogDebug("ENTER");
2760         BatteryLevel batteryLevel;
2761
2762         batteryLevel = PowerManager::GetCurrentBatteryLevel();
2763
2764         AppLogDebug("EXIT");
2765         return batteryLevel;
2766 }
2767
2768 Tizen::Media::CameraState
2769 CameraPresentationModel::GetCameraState(void) const
2770 {
2771         AppLogDebug("ENTER");
2772         TryCatch(__pCamera != null, , "__pCamera is null");
2773
2774         AppLogDebug("EXIT");
2775         return __pCamera->GetState();
2776
2777 CATCH:
2778         AppLogDebug("EXIT - CATCH");
2779         return CAMERA_STATE_ERROR;
2780 }
2781
2782 Tizen::Media::RecorderState
2783 CameraPresentationModel::GetRecorderState(void) const
2784 {
2785         AppLogDebug("ENTER");
2786         TryCatch(__pVideoRecorder != null, , "__pVideoRecorder is null");
2787
2788         AppLogDebug("EXIT");
2789         return __pVideoRecorder->GetState();
2790
2791 CATCH:
2792         AppLogDebug("EXIT - CATCH");
2793         return RECORDER_STATE_ERROR;
2794 }
2795
2796 long long
2797 CameraPresentationModel::GetAvailableStorageSpace(void) const
2798 {
2799         AppLogDebug("ENTER");
2800         result r = E_SUCCESS;
2801         int storageType = STORAGE_TYPE_PHONE;
2802         long long availableStorageSpace = 0;
2803
2804         r = GetValue(STORAGE_TYPE, storageType);
2805         if (r != E_SUCCESS)
2806         {
2807                 storageType = STORAGE_TYPE_PHONE;       
2808         }
2809
2810         if (storageType == STORAGE_TYPE_PHONE)
2811         {
2812                 String key(STRING_KEY_STORAGE_PHONE);
2813                 r = RuntimeInfo::GetValue(key, availableStorageSpace);
2814                 TryCatch(r == E_SUCCESS, , "To get a value is fail");
2815         }
2816         else if (storageType == STORAGE_TYPE_MEMORYCARD)
2817         {
2818                 if (IsStorageCardMounted() == true)
2819                 {
2820                         String key(STRING_KEY_STORAGE_SDCARD);
2821
2822                         r = RuntimeInfo::GetValue(key, availableStorageSpace);
2823                         TryCatch(r == E_SUCCESS, , "To get a value is fail");
2824                 }
2825                 else
2826                 {
2827                         availableStorageSpace = 0;
2828                 }
2829         }
2830
2831         AppLogDebug("EXIT - availableStorageSpace = %ld", availableStorageSpace);
2832         return availableStorageSpace;
2833
2834 CATCH:
2835         AppLogDebug("EXIT - CATCH");
2836         availableStorageSpace = 0;
2837         return availableStorageSpace;
2838 }
2839
2840 void
2841 CameraPresentationModel::ZoomIn(void)
2842 {
2843         AppLogDebug("ENTER");
2844         result r = E_SUCCESS;
2845
2846         r = __pCamera->ZoomIn();
2847         TryReturnVoid(r == E_SUCCESS, "ZoomIn() fail[%s]", GetErrorMessage(r));
2848         AppLogDebug("EXIT");
2849 }
2850
2851 void
2852 CameraPresentationModel::ZoomOut(void)
2853 {
2854         AppLogDebug("ENTER");
2855         result r = E_SUCCESS;
2856
2857         r = __pCamera->ZoomOut();
2858         TryReturnVoid(r == E_SUCCESS, "ZoomOut() fail[%s]", GetErrorMessage(r));
2859         AppLogDebug("EXIT");
2860 }
2861
2862 result
2863 CameraPresentationModel::SetExifOrientation(int orientation)
2864 {
2865         AppLogDebug("ENTER");
2866         result r = E_SUCCESS;
2867
2868         switch (orientation)
2869         {
2870         case CAM_SET_EXIF_ORIENTATION_MODE_PORTRAIT:
2871                 {
2872                         r = __pCamera->SetExifOrientation(CAMERA_EXIF_ORIENTATION_RIGHT_TOP);
2873                 }
2874                 break;
2875
2876         case CAM_SET_EXIF_ORIENTATION_MODE_PORTRAIT_REVERSE:
2877                 {
2878                         r = __pCamera->SetExifOrientation(CAMERA_EXIF_ORIENTATION_LEFT_BOTTOM);
2879                 }
2880                 break;
2881
2882         case CAM_SET_EXIF_ORIENTATION_MODE_LANDSCAPE:
2883                 {
2884                         r = __pCamera->SetExifOrientation(CAMERA_EXIF_ORIENTATION_TOP_LEFT);
2885                 }
2886                 break;
2887
2888         case CAM_SET_EXIF_ORIENTATION_MODE_LANDSCAPE_REVERSE:
2889                 {
2890                         r = __pCamera->SetExifOrientation(CAMERA_EXIF_ORIENTATION_BOTTOM_RIGHT);
2891                 }
2892                 break;
2893
2894         default:
2895                 break;
2896         }
2897         AppLogDebug("__pCamera->SetExifOrientation() fail[%s]", GetErrorMessage(r));
2898
2899         AppLogDebug("EXIT");
2900         return r;
2901 }
2902
2903 void
2904 CameraPresentationModel::KeepScreenOnState(bool keepOn, bool dimming)
2905 {
2906         result r = E_FAILURE;
2907         AppLogDebug("ENTER");
2908
2909         AppLogDebug("PowerManager keepOn : %d  dimming : %d", keepOn, dimming);
2910
2911         r = PowerManager::KeepScreenOnState(keepOn, dimming);
2912         TryReturnVoid(r == E_SUCCESS, "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
2913         AppLogDebug("EXIT");
2914 }
2915
2916 void
2917 CameraPresentationModel::AddPresentationChangedEventListener(ICameraEventListner& pObserverListener)
2918 {
2919         AppLogDebug("ENTER");
2920         __pCameraListener = &pObserverListener;
2921         AppLogDebug("EXIT");
2922 }
2923
2924 void
2925 CameraPresentationModel::RemovePresentationChangedEventListener(ICameraEventListner* pObserverListener)
2926 {
2927         AppLogDebug("ENTER");
2928         __pCameraListener = pObserverListener;
2929         AppLogDebug("EXIT");
2930 }
2931
2932 void
2933 CameraPresentationModel::CallOnPresentationModeChanged(CameraActionEvent event)
2934 {
2935         AppLogDebug("ENTER");
2936         AppLogDebug("CallOnPresentationModeChanged - event = %d", event);
2937         if (__pCameraListener != null)
2938         {
2939                 __pCameraListener->OnCameraActionPerformed(event);
2940         }
2941         AppLogDebug("EXIT");
2942 }
2943
2944 result
2945 CameraPresentationModel::ResetCameraSettingsRegistry(void)
2946 {
2947         AppLogDebug("ENTER");
2948         result r = E_SUCCESS;
2949
2950         r = __pCameraSettingsPresentationModel->ResetCameraSettingsRegistry();
2951         TryCatch(r == E_SUCCESS, , "Registry::SetValue() failed[%s]", GetErrorMessage(r));
2952
2953         AppLogDebug("EXIT");
2954         return r;
2955
2956 CATCH:
2957         AppLogDebug("EXIT - CATCH");
2958         return r;
2959 }
2960
2961 result
2962 CameraPresentationModel::ResetCameraSettings(void)
2963 {
2964         AppLogDebug("ENTER");
2965         result r = E_SUCCESS;
2966
2967         TryCatch(__pCameraSettingsPresentationModel!=null, r = E_FAILURE,"Camera Settings Presentation Model is NULL");
2968
2969         r = __pCameraSettingsPresentationModel->SetValue(SECTION_CAMERA, EXPOSURE_VALUE, EXPOSURE_DEFAULT_VALUE);
2970         TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
2971
2972         r = __pCameraSettingsPresentationModel->SetValue(SECTION_CAMCORDER, EXPOSURE_VALUE, EXPOSURE_DEFAULT_VALUE);
2973         TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
2974
2975         r = __pCameraSettingsPresentationModel->SetValue(SECTION_CAMERA, BRIGHTNESS_VALUE, BRIGHTNESS_DEFAULT_VALUE);
2976         TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
2977
2978         r = __pCameraSettingsPresentationModel->SetValue(SECTION_CAMCORDER, BRIGHTNESS_VALUE, BRIGHTNESS_DEFAULT_VALUE);
2979         TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
2980
2981         AppLogDebug("EXIT");
2982         return r;
2983
2984 CATCH:  
2985         AppLogDebug("EXIT - CATCH %s", GetErrorMessage(r));
2986         return r;
2987 }
2988
2989 result
2990 CameraPresentationModel::GetValue(const Tizen::Base::String& entryName, int& value) const
2991 {
2992         AppLogDebug("ENTER");
2993         AppLogDebug("entry name is %ls",entryName.GetPointer());
2994         AppLogDebug("entry value is %d",value);
2995         result r = E_SUCCESS;
2996         int mode = 0;
2997         String strSectionName = SECTION_CAMERA;
2998
2999         if (entryName.Equals(String(CURRENT_MODE)))
3000         {
3001                 strSectionName = SECTION_CAMERA;
3002         }
3003         else
3004         {
3005                 r = __pCameraSettingsPresentationModel->GetValue(SECTION_CAMERA, CURRENT_MODE, mode);
3006                 TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
3007
3008                 if (mode == CAMERA_MODE_SNAPSHOT)
3009                 {
3010                         strSectionName = SECTION_CAMERA;
3011                 }
3012                 else
3013                 {
3014                         strSectionName = SECTION_CAMCORDER;
3015                 }
3016         }
3017
3018         r = __pCameraSettingsPresentationModel->GetValue(strSectionName, entryName, value);
3019         TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
3020
3021         AppLogDebug("EXIT");
3022         return r;
3023
3024 CATCH:
3025         AppLogDebug("EXIT - CATCH");
3026         return r;
3027 }
3028
3029 result
3030 CameraPresentationModel::SetValue(const Tizen::Base::String& entryName, const int value)
3031 {
3032         AppLogDebug("ENTER");
3033         result r = E_SUCCESS;
3034         int mode = 0;
3035         String strSectionName = SECTION_CAMERA;
3036
3037         AppLogDebug("entry name is %ls",entryName.GetPointer());
3038         AppLogDebug("entry value is %d",value);
3039
3040         if (entryName.Equals(String(CURRENT_MODE)))
3041         {
3042                 strSectionName = SECTION_CAMERA;
3043         }
3044         else
3045         {
3046                 r = __pCameraSettingsPresentationModel->GetValue(SECTION_CAMERA, CURRENT_MODE, mode);
3047                 TryCatch(r == E_SUCCESS, , "Registry::GetValue() failed[%s]", GetErrorMessage(r));
3048
3049                 if (mode == CAMERA_MODE_SNAPSHOT)
3050                 {
3051                         strSectionName = SECTION_CAMERA;
3052                 }
3053                 else
3054                 {
3055                         strSectionName = SECTION_CAMCORDER;
3056                 }
3057         }
3058
3059         r = __pCameraSettingsPresentationModel->SetValue(strSectionName, entryName, value);
3060
3061         /*if ( entryName.CompareTo(L"PRIMARY_FLASH_MODE") == 0)
3062         {
3063                 AppLogDebug("flash mode is set to value %d",value);
3064                 SetFlashMode(CameraFlashMode(value));
3065         }
3066         TryCatch(r == E_SUCCESS, , "Registry::SetValue() failed[%s]", GetErrorMessage(r));
3067 */
3068         AppLogDebug("EXIT");
3069         return r;
3070
3071 CATCH:
3072         AppLogDebug("EXIT - CATCH");
3073         return r;
3074 }
3075
3076 result
3077 CameraPresentationModel::GetMediaCapability(Tizen::Base::String key, bool& value) const
3078 {
3079         AppLogDebug("ENTER");
3080         result r = E_SUCCESS;
3081         r = MediaCapability::GetValue(key, value);
3082
3083         AppLogDebug("GetMediaCapability for %ls value = %d return = %s", key.GetPointer(), value, GetErrorMessage(r));
3084         TryCatch(r == E_SUCCESS, , "MediaCapability::GetValue() fail[%s]", GetErrorMessage(r));
3085
3086         AppLogDebug("EXIT");
3087         return r;
3088
3089 CATCH:
3090         AppLogDebug("EXIT - CATCH");
3091         return E_FAILURE;
3092 }
3093
3094 result
3095 CameraPresentationModel::GetMediaCapability(Tizen::Base::String key, int& value) const
3096 {
3097         AppLogDebug("ENTER");
3098         result r = E_SUCCESS;
3099         r = MediaCapability::GetValue(key, value);
3100
3101         AppLogDebug("GetMediaCapability for %ls value = %d return = %s", key.GetPointer(), value, GetErrorMessage(r));
3102         TryCatch(r == E_SUCCESS, , "MediaCapability::GetValue() fail[%s]", GetErrorMessage(r));
3103
3104         AppLogDebug("EXIT");
3105         return r;
3106
3107 CATCH:
3108         AppLogDebug("EXIT - CATCH");
3109         return E_FAILURE;
3110 }
3111
3112 result
3113 CameraPresentationModel::GetMediaCapability(Tizen::Base::String key) const
3114 {
3115         AppLogDebug("ENTER");
3116         result r = E_SUCCESS;
3117         IList* pList = null;
3118         pList = MediaCapability::GetValueN(key);
3119         r = GetLastResult();
3120         AppLogDebug("GetMediaCapability for %ls return = %s", key.GetPointer(), GetErrorMessage(r));
3121         TryCatch(pList != null, , "MediaCapability::GetValueN() fail[%s]", GetErrorMessage(r));
3122
3123         pList->RemoveAll(true);
3124         delete pList;
3125         pList = null;
3126
3127         AppLogDebug("EXIT");
3128         return r;
3129
3130 CATCH:
3131         AppLogDebug("EXIT - CATCH");
3132         return E_FAILURE;
3133 }
3134
3135 void
3136 CameraPresentationModel::OnCameraAutoFocused(bool completeCondition)
3137 {
3138         AppLogDebug("ENTER");
3139         CameraFocusMode focusMode = CAMERA_FOCUS_MODE_NONE;
3140
3141         if (__isIntervalTimerRun == true)
3142         {
3143                 AppLogDebug("__isIntervalTimerRun: true");
3144                 return;
3145         }
3146
3147         if (completeCondition == true)
3148         {
3149                 focusMode = __pCamera->GetFocusMode();
3150
3151                 if (focusMode == CAMERA_FOCUS_MODE_CONTINUOUS_AUTO)
3152                 {
3153                         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_AUTO_FOCUSED);
3154                 }
3155                 else if (focusMode == CAMERA_FOCUS_MODE_NORMAL)
3156                 {
3157                         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_TOUCH_AUTO_FOCUSED);
3158                 }
3159         }
3160         else
3161         {
3162                 AppLogDebug("completeCondition:false");
3163                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_AUTO_FOCUS_FAILED);
3164         }
3165         AppLogDebug("EXIT");
3166 }
3167
3168 void
3169 CameraPresentationModel::OnCameraPreviewed(Tizen::Base::ByteBuffer& previewedData, result r)
3170 {
3171         AppLogDebug("ENTER");
3172         AppLogDebug("EXIT");
3173 }
3174
3175 void
3176 CameraPresentationModel::OnCameraCaptured(Tizen::Base::ByteBuffer& capturedData, result r)
3177 {
3178         AppLogDebug("ENTER");
3179         int shootingMode = 0;
3180         String* pFullFileName = null;
3181         ContentManager* pContentManager = null;
3182         ImageContentInfo* pImageContentInfo = null;
3183         result ret = E_SUCCESS;
3184         int storageType = 0;
3185         String  FilePath= null;
3186         bool    bDoScanDir= false;
3187
3188         AppLogDebug("OnCameraCaptured :: StopCaptured = %d", __isStopCaptured);
3189
3190         if (__isStopCaptured == true)
3191         {
3192                 AppLogDebug("OnCameraCaptured :: StopCaptured");
3193                 __isStopCaptured = false;
3194
3195                 SetErrorResult(STRING_CAMERA_CAPTURED_ERROR);
3196
3197                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3198
3199                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_ERROR_OCCURRED);
3200         }
3201         else
3202         {
3203                 ret = GetValue(SHOOTING_MODE, shootingMode);
3204                 TryCatch(ret == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(ret));
3205
3206                 if (shootingMode == CAPTURE_NORMAL_MODE)
3207                 {
3208                         if (r == E_SUCCESS)
3209                         {
3210                                 ContentId contentId;
3211
3212                                 pFullFileName = new (std::nothrow) String();
3213                                 ret = CreateFileName(*pFullFileName);
3214                                 TryCatch(ret == E_SUCCESS, , "pFullFileName is null");
3215
3216                                 __latestContentName.Clear();
3217                                 ret = __latestContentName.Append(pFullFileName->GetPointer());
3218                                 TryCatch(ret == E_SUCCESS, , "String::Append() fail[%s]", GetErrorMessage(ret));
3219
3220                                 AppLogDebug("OnCameraCaptured pFullFileName = %ls", pFullFileName->GetPointer());
3221                                 pContentManager = new (std::nothrow) ContentManager();
3222
3223                                 ret = pContentManager->Construct();
3224                                 TryCatch(ret == E_SUCCESS, , "ContentManager->Construct() failed(%s)", GetErrorMessage(r));
3225
3226
3227                                 //Code for doing ScanDirectory!!!
3228                                 r = GetValue(STORAGE_TYPE, storageType);
3229                                 TryCatch(r == E_SUCCESS, , "GetValue() fail[%s]", GetErrorMessage(r));
3230
3231                                 r = CmUtility::GetDirectoryPath(storageType, FilePath);
3232                                 TryCatch(r == E_SUCCESS, , "GetDirectoryPath() fail[%s]", GetErrorMessage(r));
3233
3234                                 if( File::IsFileExist(FilePath) != true)
3235                                 {
3236                                         bDoScanDir = true;
3237                                 }
3238                                 //Ends
3239
3240                                 contentId = pContentManager->CreateContent(capturedData, pFullFileName->GetPointer());
3241                                 TryCatch(Tizen::Base::UuId::GetInvalidUuId() != contentId, GetLastResult(), "CreateContent failed.");
3242
3243                                 pImageContentInfo = static_cast<ImageContentInfo*>(pContentManager->GetContentInfoN(contentId));
3244                                 TryCatch(pImageContentInfo != null, , "pImageContentInfo is null");
3245
3246                                 if( bDoScanDir )
3247                                 {
3248                                         RequestId reqId;
3249                                         pContentManager->ScanDirectory(FilePath, true, null , reqId);
3250                                 }
3251
3252                                 delete __pBitmap;
3253                                 __pBitmap = null;
3254
3255                                 __pBitmap = pImageContentInfo->GetThumbnailN();
3256                                 TryCatch(__pBitmap != null, , "__pBitmap is null");
3257
3258                                 delete pContentManager;
3259                                 pContentManager = null;
3260
3261                                 delete pImageContentInfo;
3262                                 pImageContentInfo = null;
3263
3264                                 delete pFullFileName;
3265                                 pFullFileName = null;
3266
3267                                 AppLogDebug("ENTER:E_SUCCESS");
3268
3269                                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_SUCCEEDED);
3270
3271                                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_CAPTURED);
3272                         }
3273                         else
3274                         {
3275                                 AppLogDebug("ENTER:E_FAILED");
3276                                 SetErrorResult(STRING_CAMERA_CAPTURED_ERROR);
3277
3278                                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3279
3280                                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_ERROR_OCCURRED);
3281                         }
3282                 }
3283                 else if (shootingMode == CAPTURE_BURST_MODE)
3284                 {
3285                         // Empty statement
3286                 }
3287         }
3288
3289         AppLogDebug("EXIT");
3290         return;
3291
3292 CATCH:
3293         AppLogDebug("EXIT - CATCH");
3294         if (__pBitmap != null)
3295         {
3296                 delete __pBitmap;
3297                 __pBitmap = null;
3298         }
3299
3300         if (pContentManager != null)
3301         {
3302                 delete pContentManager;
3303                 pContentManager = null;
3304         }
3305
3306         if (pImageContentInfo)
3307         {
3308                 delete pImageContentInfo;
3309                 pImageContentInfo = null;
3310         }
3311
3312         if (pFullFileName)
3313         {
3314                 delete pFullFileName;
3315                 pFullFileName = null;
3316         }
3317
3318         SetErrorResult(STRING_CAMERA_CAPTURED_ERROR);
3319
3320         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3321
3322         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_ERROR_OCCURRED);
3323 }
3324
3325 void
3326 CameraPresentationModel::OnCameraErrorOccurred(Tizen::Media::CameraErrorReason r)
3327 {
3328         AppLogDebug("ENTER");
3329         result res = E_FAILURE;
3330         int currentCameraMode = 0;
3331
3332         switch (r)
3333         {
3334         case CAMERA_ERROR_OUT_OF_MEMORY:
3335                 {
3336                         AppLogDebug("camera error occurred - CAMERA_ERROR_OUT_OF_MEMORY");
3337                         res = E_OUT_OF_MEMORY;
3338                 }
3339                 break;
3340
3341         case CAMERA_ERROR_DEVICE_FAILED:
3342                 {
3343                         AppLogDebug("camera error occurred - CAMERA_ERROR_DEVICE_FAILED");
3344                         res = E_DEVICE_FAILED;
3345                 }
3346                 break;
3347
3348         case CAMERA_ERROR_DEVICE_INTERRUPTED:
3349                 {
3350                         AppLogDebug("camera error occurred - CAMERA_ERROR_DEVICE_INTERRUPTED");
3351                         res = E_DEVICE_BUSY;
3352                 }
3353                 break;
3354
3355         default:
3356                 {
3357                         res = E_SUCCESS;
3358                 }
3359                 break;
3360         }
3361
3362         result ret = GetValue(CURRENT_MODE, currentCameraMode);
3363         TryReturnVoid(ret == E_SUCCESS, "Faled to set value to registry[%s]", GetErrorMessage(ret));
3364
3365         if (currentCameraMode == CAMERA_MODE_RECORD)
3366         {
3367                 AppLogDebug("RECORD error occurred");
3368                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_ERROR_OCCURRED);
3369         }
3370         else
3371         {
3372                 AppLogDebug("SNAPSHOT error occurred");
3373                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_ERROR_OCCURRED);
3374         }
3375         AppLogDebug("EXIT");
3376 }
3377
3378 void
3379 CameraPresentationModel::OnVideoRecorderCanceled(result r)
3380 {
3381         AppLogDebug("ENTER");
3382         if (__pVideoRecorder != null)
3383         {
3384                 __pVideoRecorder->Close();
3385         }
3386
3387         if (__recorderStopException)
3388         {
3389                 r = __pCamera->StopPreview();
3390                 TryReturnVoid(r == E_SUCCESS, "Camera::StopPreview() [%s]", GetErrorMessage(r));
3391
3392                 if (__pCamera->IsPoweredOn() == true)
3393                 {
3394                         r = __pCamera->PowerOff();
3395                         TryReturnVoid(r == E_SUCCESS, "Camera::PowerOff() [%s]", GetErrorMessage(r));
3396                 }
3397         }
3398         AppLogDebug("EXIT");
3399 }
3400
3401 void
3402 CameraPresentationModel::OnVideoRecorderClosed(result r)
3403 {
3404         AppLogDebug("ENTER");
3405 # if 0                          //Unused code
3406         ContentManager* pContentManager = null;
3407 #endif
3408         ContentId contentId;
3409         String replaceFilePath;
3410         String camcorderTemporaryFilePath;
3411         int storageType = STORAGE_TYPE_PHONE;
3412         result ret = E_SUCCESS;
3413
3414         ret = SetFlashModeOnRecord(false);
3415         AppLogDebug("SetFlashModeOnRecord fail[%s]", GetErrorMessage(ret));
3416
3417         AppLogDebug("isCancelRecord", __isCancelRecord);
3418
3419         if (__isCancelRecord)
3420         {
3421                 __onVideoRecorderStarted = false;
3422                 AppLogDebug("isCancelRecord %d", __isCancelRecord);
3423
3424                 ret = RemoveVideoFile();
3425                 AppLogDebug("RemoveVideoFile fail[%s]", GetErrorMessage(ret));
3426
3427                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_CANCELED);
3428                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_CANCELED);
3429
3430                 AppLogDebug("CANCELRECORD - EXIT");
3431                 return;
3432         }
3433
3434         if (r == E_SUCCESS)
3435         {
3436                 AppLogDebug("ENTER: E_SUCCESS");
3437
3438                 ret = GetValue(STORAGE_TYPE, storageType);
3439                 if (ret != E_SUCCESS)
3440                 {
3441                         storageType = STORAGE_TYPE_PHONE;
3442                 }
3443
3444                 if (storageType == STORAGE_TYPE_PHONE)
3445                 {
3446                         camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", App::GetInstance()->GetAppRootPath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE);
3447                 }
3448                 else
3449                 {
3450                         camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", Environment::GetExternalStoragePath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE_EXT);
3451                 }
3452
3453 # if 0                          //Contnet Manager is nto used
3454                 pContentManager = new (std::nothrow) ContentManager();
3455                 ret = pContentManager->Construct();
3456                 TryCatch(ret == E_SUCCESS, , "ContentManager->Construct() failed(%s)", GetErrorMessage(r));
3457 #endif
3458
3459                 AppLogDebug("latest content name is %ls",__latestContentName.GetPointer());
3460                 r = ContentManager::ScanFile(__latestContentName);
3461                 __CurrentVideoFileName = __latestContentName;
3462
3463                 if (storageType == STORAGE_TYPE_PHONE)
3464                 {
3465                         replaceFilePath =  Environment::GetMediaPath();
3466                 }
3467                 else
3468                 {
3469                         replaceFilePath = Environment::GetExternalStoragePath();
3470                 }
3471
3472                 replaceFilePath.Append(STRING_CAMERA_FOLDER_NAME);
3473                 replaceFilePath.Append("/");
3474                 AppLogDebug("Replace filepath is %ls",replaceFilePath.GetPointer());
3475                 __CurrentVideoFileName.Replace(replaceFilePath,"");
3476                 AppLogDebug("__CurrentVideoFileName path is %ls",__CurrentVideoFileName.GetPointer());
3477
3478                 __pBitmap = CmUtility::CreateThumbnailN(__CurrentVideoFileName,CONTENT_TYPE_VIDEO);
3479
3480                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_SUCCEEDED);
3481
3482                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_CLOSED);
3483         }
3484         else
3485         {
3486                 AppLogDebug("ENTER: E_FAILED");
3487
3488                 SetErrorResult(STRING_VIDEO_RECORDER_CLOSED_ERROR);
3489
3490                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3491                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_ERROR_OCCURRED);
3492         }
3493
3494         __onVideoRecorderStarted = false;
3495
3496         AppLogDebug("EXIT");
3497         return;
3498 }
3499
3500 void
3501 CameraPresentationModel::OnVideoRecorderEndReached(RecordingEndCondition endCondition)
3502 {
3503         AppLogDebug("ENTER");
3504         ContentManager* pContentManager = null;
3505         VideoContentInfo* videoContentInfo = null;
3506         ContentId contentId;
3507         String camcorderTemporaryFilePath;
3508         int storageType = STORAGE_TYPE_PHONE;
3509         result ret = E_SUCCESS;
3510
3511         ret = SetFlashModeOnRecord(false);
3512         AppLogDebug("SetFlashModeOnRecord fail[%s]", GetErrorMessage(ret));
3513
3514         StopRecord();
3515
3516         ret = GetValue(STORAGE_TYPE, storageType);
3517         if (ret != E_SUCCESS)
3518         {
3519                 storageType = STORAGE_TYPE_PHONE;
3520         }
3521
3522         if (storageType == STORAGE_TYPE_PHONE)
3523         {
3524                 camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", App::GetInstance()->GetAppRootPath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE);
3525         }
3526         else
3527         {
3528                 camcorderTemporaryFilePath.Format(MAX_DIRECTORY_PATH_LENGTH, L"%ls%ls", Environment::GetExternalStoragePath().GetPointer(), STRING_CAMCORDER_TEMPORARY_FILE_EXT);
3529         }
3530
3531         pContentManager = new (std::nothrow) ContentManager();
3532
3533         ret = pContentManager->Construct();
3534         TryCatch(ret == E_SUCCESS, , "ContentManager->Construct() failed(%s)", GetErrorMessage(ret));
3535
3536         contentId = pContentManager->CreateContent(camcorderTemporaryFilePath, __latestContentName, true);
3537         TryCatch(Tizen::Base::UuId::GetInvalidUuId() != contentId, GetLastResult(), "CreateContent failed.");
3538
3539         videoContentInfo = static_cast<VideoContentInfo*>(pContentManager->GetContentInfoN(contentId));
3540         TryCatch(videoContentInfo != null, , "videoContentInfo is null");
3541
3542         delete __pBitmap;
3543         __pBitmap = null;
3544
3545         __pBitmap = videoContentInfo->GetThumbnailN();
3546         TryCatch(__pBitmap != null, , "__pBitmap is null");
3547
3548         delete videoContentInfo;
3549         videoContentInfo = null;
3550
3551         delete pContentManager;
3552         pContentManager = null;
3553
3554         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_SUCCEEDED);
3555
3556         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_END_REACHED);
3557
3558         __onVideoRecorderStarted = false;
3559         AppLogDebug("EXIT");
3560         return;
3561
3562 CATCH:
3563         AppLogDebug("EXIT - CATCH");
3564         delete pContentManager;
3565         pContentManager = null;
3566
3567         delete videoContentInfo;
3568         videoContentInfo = null;
3569
3570         delete __pBitmap;
3571         __pBitmap = null;
3572
3573         SetErrorResult(STRING_VIDEO_RECORDER_END_REACHED_ERROR);
3574         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3575         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_ERROR_OCCURRED);
3576 }
3577
3578 void
3579 CameraPresentationModel::OnVideoRecorderErrorOccurred(RecorderErrorReason r)
3580 {
3581         AppLogDebug("ENTER OnVideoRecorderErrorOccurred (%ld)", r);
3582
3583         __recorderError = r;
3584         __pVideoRecorder->Close();
3585
3586         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3587
3588         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_ERROR_OCCURRED);
3589
3590         __onVideoRecorderStarted = false;
3591         AppLogDebug("EXIT");
3592 }
3593
3594 void
3595 CameraPresentationModel::OnVideoRecorderPaused(result r)
3596 {
3597         AppLogDebug("ENTER");
3598         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_PAUSED);
3599         AppLogDebug("EXIT");
3600 }
3601
3602 void
3603 CameraPresentationModel::OnVideoRecorderStarted(result r)
3604 {
3605         AppLogDebug("ENTER");
3606         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_STARTED);
3607         AppLogDebug("EXIT");
3608 }
3609
3610 bool
3611 CameraPresentationModel::GetOnVideoRecorderStopped(void)
3612 {
3613         AppLogDebug("ENTER");
3614         AppLogDebug("EXIT");
3615         return __onVideoRecorderStarted;
3616 }
3617
3618 void
3619 CameraPresentationModel::SetOnVideoRecorderStopped(bool isCompleted)
3620 {
3621         AppLogDebug("ENTER");
3622         __onVideoRecorderStarted = isCompleted;
3623         AppLogDebug("EXIT");
3624 }
3625
3626 void
3627 CameraPresentationModel::OnVideoRecorderStopped(result r)
3628 {
3629         AppLogDebug("ENTER");
3630         result localResult = E_SUCCESS;
3631
3632         if (__pVideoRecorder != null)
3633         {
3634                 localResult = __pVideoRecorder->Close();
3635                 TryCatch(localResult == E_SUCCESS, , "__pVideoRecorder::Close() fail[%s]", GetErrorMessage(localResult));
3636         }
3637         __onVideoRecorderStarted = true;
3638
3639         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_STOPPED);
3640
3641         AppLogDebug("EXIT");
3642         return;
3643
3644 CATCH:
3645         AppLogDebug("EXIT - CATCH");
3646         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3647         CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_VIDEO_RECORDER_ERROR_OCCURRED);
3648 }
3649
3650 void
3651 CameraPresentationModel::DestroyPresentationModelInstance(void)
3652 {
3653         AppLogDebug("ENTER");
3654         CameraPresentationModel* pCameraPresentationModel = CameraPresentationModel::GetInstance();
3655
3656         delete pCameraPresentationModel;
3657         AppLogDebug("EXIT");
3658 }
3659
3660 void
3661 CameraPresentationModel::UpdateThumbnail(int currentCameraMode)
3662 {
3663         AppLogDebug("ENTER");
3664         result r = E_SUCCESS;
3665
3666         r = CreateThumbnail(currentCameraMode);
3667         TryReturnVoid(r == E_SUCCESS, "CreateThumbnail() fail[%s]", GetErrorMessage(r));
3668         AppLogDebug("EXIT");
3669 }
3670
3671 int
3672 CameraPresentationModel::GetStorageCardState(void) const
3673 {
3674         AppLogDebug("ENTER");
3675         AppLogDebug("EXIT");
3676         return __storageCardState;
3677 }
3678
3679 void
3680 CameraPresentationModel::SetStorageCardState(int storageCardState)
3681 {
3682         AppLogDebug("ENTER");
3683         __storageCardState = storageCardState;
3684         AppLogDebug("EXIT");
3685 }
3686
3687 int
3688 CameraPresentationModel::GetStorageCardChageState(void) const
3689 {
3690         AppLogDebug("ENTER");
3691         AppLogDebug("EXIT");
3692         return __storageCardChageState;
3693 }
3694
3695 void
3696 CameraPresentationModel::SetStorageCardChageState(int storageCardChageState)
3697 {
3698         AppLogDebug("ENTER");
3699         __storageCardChageState = storageCardChageState;
3700         AppLogDebug("EXIT");
3701 }
3702
3703 void
3704 CameraPresentationModel::StorageCardStateChaged(bool isMounted)
3705 {
3706         AppLogDebug("ENTER");
3707         if (isMounted)
3708         {
3709                 __storageCardState = STORAGE_CARD_STATE_MOUNT;
3710         }
3711         else
3712         {
3713                 __storageCardState = STORAGE_CARD_STATE_UNMOUNT;
3714
3715                 __pCameraSettingsPresentationModel->SetValue(SECTION_CAMERA, STORAGE_TYPE, STORAGE_TYPE_PHONE);
3716
3717                 __pCameraSettingsPresentationModel->SetValue(SECTION_CAMCORDER, STORAGE_TYPE, STORAGE_TYPE_PHONE);
3718         }
3719         AppLogDebug("EXIT");
3720 }
3721
3722 void
3723 CameraPresentationModel::SetDeviceManagerEventListner(void)
3724 {
3725         AppLogDebug("ENTER");
3726         result r = E_SUCCESS;
3727
3728         r = DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
3729         AppLogDebug("AddDeviceEventListener [%s] fail", GetErrorMessage(r));
3730         AppLogDebug("EXIT");
3731 }
3732
3733 void
3734 CameraPresentationModel::RemoveDeviceManagerEventListner(void)
3735 {
3736         AppLogDebug("ENTER");
3737         result r = E_SUCCESS;
3738
3739         r = DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
3740         AppLogDebug("RemoveDeviceManagerEventListner [%s] fail", GetErrorMessage(r));
3741         AppLogDebug("EXIT");
3742 }
3743
3744 void
3745 CameraPresentationModel::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
3746 {
3747         AppLogDebug("ENTER");
3748         int currentCameraMode = 0;
3749         int storageType = STORAGE_TYPE_PHONE;
3750
3751         result r = E_SUCCESS;
3752         r = GetValue(CURRENT_MODE, currentCameraMode);
3753         TryReturnVoid(r == E_SUCCESS, "GetValue returns not E_SUCCESS", GetErrorMessage(r));
3754
3755         if (deviceType == DEVICE_TYPE_STORAGE_CARD)
3756         {
3757                 switch (currentCameraMode)
3758                 {
3759                 case CAMERA_MODE_RECORD:
3760                         {
3761                                 __pCameraSettingsPresentationModel->GetValue(SECTION_CAMCORDER, STORAGE_TYPE, storageType);
3762
3763                                 if (storageType == STORAGE_TYPE_MEMORYCARD)
3764                                 {
3765                                         if (IsStorageCardMounted()== false)
3766                                         {
3767                                                 AppLogDebug("RemoveVideoFile::GetRecorderState() = %d", __pVideoRecorder->GetState());
3768
3769                                                 if (__pVideoRecorder->GetState() == RECORDER_STATE_RECORDING
3770                                                         || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSED
3771                                                         || __pVideoRecorder->GetState() == RECORDER_STATE_STARTING
3772                                                         || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSING
3773                                                 )
3774                                                 {
3775                                                         r = RemoveVideoFile();
3776                                                         AppLogDebug("RemoveVideoFile fail[%s]", GetErrorMessage(r));
3777                                                 }
3778
3779                                                 StorageCardStateChaged(false);
3780
3781                                                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3782
3783                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_MOUNT_TO_UNMOUNT);
3784                                                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_STORAGE_CARD_UNMOUNT);
3785                                         }
3786                                         else
3787                                         {
3788                                                 StorageCardStateChaged(true);
3789                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3790                                         }
3791                                 }
3792                                 else
3793                                 {
3794                                         if ( IsStorageCardMounted()== false)
3795                                         {
3796                                                 StorageCardStateChaged(false);
3797                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3798                                         }
3799                                         else
3800                                         {
3801                                                 StorageCardStateChaged(true);
3802                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3803                                         }
3804                                 }
3805                         }
3806                         break;
3807
3808                 case CAMERA_MODE_SNAPSHOT:
3809                         {
3810                                 __pCameraSettingsPresentationModel->GetValue(SECTION_CAMERA, STORAGE_TYPE, storageType);
3811
3812                                 if (storageType == STORAGE_TYPE_MEMORYCARD)
3813                                 {
3814                                         if ( IsStorageCardMounted()== false)
3815                                         {
3816                                                 AppLogDebug("OnDeviceStateChanged state=%d", __pCamera->GetState());
3817
3818                                                 if (GetCameraState() == CAMERA_STATE_CAPTURED || GetCameraState() == CAMERA_STATE_CAPTURING)
3819                                                 {
3820                                                         __isStopCaptured = true;
3821                                                 }
3822                                                 else
3823                                                 {
3824                                                         __isStopCaptured = false;
3825                                                 }
3826
3827                                                 StorageCardStateChaged(false);
3828
3829                                                 SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_FAILED);
3830                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_MOUNT_TO_UNMOUNT);
3831                                                 CallOnPresentationModeChanged(CAMERA_ACTION_EVENT_STORAGE_CARD_UNMOUNT);
3832                                         }
3833                                         else
3834                                         {
3835                                                 StorageCardStateChaged(true);
3836                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3837                                         }
3838                                 }
3839                                 else
3840                                 {
3841                                         __isStopCaptured = false;
3842
3843                                         if ( IsStorageCardMounted()== false)
3844                                         {
3845                                                 StorageCardStateChaged(false);
3846                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3847                                         }
3848                                         else
3849                                         {
3850                                                 StorageCardStateChaged(true);
3851                                                 SetStorageCardChageState(STORAGE_CARD_CHAGE_STATE_UNKNOWN);
3852                                         }
3853                                 }
3854                         }
3855                         break;
3856
3857                 default:
3858                         break;
3859                 }
3860         }
3861         AppLogDebug("EXIT");
3862 }
3863
3864 result
3865 CameraPresentationModel::RemoveVideoFile(void)
3866 {
3867         AppLogDebug("ENTER");
3868         String removeFileName;
3869         File file;
3870         result r = E_SUCCESS;
3871         int storageType = STORAGE_TYPE_PHONE;
3872
3873         r = GetValue(STORAGE_TYPE, storageType);
3874         if (r != E_SUCCESS)
3875         {
3876                 storageType = STORAGE_TYPE_PHONE;
3877         }
3878
3879         removeFileName = __latestContentName;
3880
3881         AppLogDebug("removeFileName is %ls",removeFileName.GetPointer());
3882         AppLogDebug("RemoveVideoFile::GetRecorderState() = %d", __pVideoRecorder->GetState());
3883         if (__pVideoRecorder->GetState()== RECORDER_STATE_RECORDING
3884                 || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSED
3885                 || __pVideoRecorder->GetState() == RECORDER_STATE_STARTING
3886                 || __pVideoRecorder->GetState() == RECORDER_STATE_PAUSING
3887         )
3888         {
3889                 StopRecord();
3890         }
3891
3892         r = file.Construct(removeFileName, "w+");
3893         TryCatch(r == E_SUCCESS, , "file::Construct() fail[%s]", GetErrorMessage(r));
3894
3895         r = file.Remove(removeFileName);
3896         TryCatch(r == E_SUCCESS, , "file::Remove() fail[%s]", GetErrorMessage(r));
3897
3898         AppLogDebug("EXIT");
3899         return r;
3900
3901 CATCH:
3902         AppLogDebug("EXIT - CATCH");
3903         return r;
3904 }
3905
3906 void
3907 CameraPresentationModel::SetDisplayResolutionType(int type)
3908 {
3909         AppLogDebug("ENTER");
3910         __displayResolution = type;
3911         AppLogDebug("EXIT");
3912 }
3913
3914 int
3915 CameraPresentationModel::GetDisplayResolutionType(void)
3916 {
3917         AppLogDebug("ENTER");
3918         AppLogDebug("EXIT");
3919         return __displayResolution;
3920 }
3921
3922 Tizen::Media::RecordingRotation
3923 CameraPresentationModel::GetRecordingRotation(void)
3924 {
3925         AppLogDebug("ENTER");
3926         RecordingRotation rotate = RECORDING_ROTATION_NONE;
3927         int selfPortraitEnable = 0;
3928         result r = E_SUCCESS;
3929         int count = sizeof(_RecordRotate) / sizeof(_RecordRotate[0]);
3930
3931         r = GetValue(SELF_PORTRAIT_ENABLE, selfPortraitEnable);
3932
3933         for (int i=0; i < count; i++)
3934         {
3935                 if ((_RecordRotate[i].camType == selfPortraitEnable) && _RecordRotate[i].orientation == GetOrientation())
3936                 {
3937                         return _RecordRotate[i].rotate;
3938                 }
3939         }
3940         AppLogDebug("EXIT");
3941         return rotate;
3942 }
3943
3944 void
3945 CameraPresentationModel::OnContentScanCompleted (RequestId reqId, const Tizen::Base::String &scanPath, result r)
3946 {
3947         AppLogDebug("Enter");
3948         AppLogDebug("Exit");
3949 }
3950
3951 void
3952 CameraPresentationModel::SetStartPreviewException(bool status)
3953 {
3954         __startPreviewException = status;
3955 }
3956
3957 void
3958 CameraPresentationModel::UpdateContentFile(void)
3959 {
3960         AppLogDebug("latest content name is %ls",__latestContentName.GetPointer());
3961         ContentManager::ScanFile(__latestContentName);
3962         SetAppControlRequestType(APP_CONTROL_REQUEST_TYPE_SUCCEEDED);
3963 }
3964
3965 void
3966 CameraPresentationModel::SetRecordStopException(bool currentStatus)
3967 {
3968         __recorderStopException = currentStatus;
3969 }
3970
3971 RecorderErrorReason
3972 CameraPresentationModel::GetRecorderErrorStatus(void)
3973 {
3974         return __recorderError;
3975 }
3976
3977 void
3978 CameraPresentationModel::GetUpdatedContentName(Tizen::Base::String& latestContentName)
3979 {
3980         latestContentName = __latestContentName;
3981 }
3982
3983 void
3984 CameraPresentationModel::SetMemoryFullException(bool status)
3985 {
3986         __memoryFullException = status;
3987 }
3988
3989 bool
3990 CameraPresentationModel::GetMemoryFullExceptionStatus(void)
3991 {
3992         long long allocatedMemory = 0;
3993         bool memoryStatus = false;
3994
3995         allocatedMemory = CmUtility::GetAvailableMemory();
3996
3997         if (__memoryFullException && allocatedMemory < MIN_MEMORY_NEEDED)
3998         {
3999                 memoryStatus = true;
4000         }
4001
4002         return memoryStatus;
4003 }
4004
4005 void
4006 CameraPresentationModel::SetCurrentSourceForm(SourceForm source)
4007 {
4008         __pCurrentSource = source;
4009 }
4010
4011 SourceForm
4012 CameraPresentationModel::GetCurrentSourceForm(void)
4013 {
4014         return __pCurrentSource;
4015 }
4016
4017 bool
4018 CameraPresentationModel::GetCancelRecord(void)
4019 {
4020         return __isCancelRecord;
4021 }