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