Fixed issue 33526
[apps/osp/Gallery.git] / src / GlFileListPresentationModel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                GlFileListPresentationModel.cpp
19  * @brief               This is the implementation file for FileListPresentationModel class.
20  */
21
22 #include <cstdlib>
23 #include <FMedia.h>
24 #include <FSystem.h>
25 #include "GlCommonUtil.h"
26 #include "GlFileListPresentationModel.h"
27 #include "GlContentUpdateEventListener.h"
28 #include "GlGalleryApp.h"
29 #include "GlThumbnailEvent.h"
30 #include "GlThumbnailEventArg.h"
31 #include "GlThumbnailProvider.h"
32 #include "GlTypes.h"
33
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Base::Utility;
39 using namespace Tizen::Content;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Io;
42 using namespace Tizen::Media;
43 using namespace Tizen::System;
44
45 static const String CONTENT_INFO_ORDER = L"ContentFileName";
46
47 static const int SIZE_PAGE_NO = 1;
48 static const int SIZE_CONUNT_PER_PAGE = 3000;
49 static const int SIZE_ICON_LIST_CACHE = 50;
50 static const int W_DURATION_TEXT = 44;
51 static const int H_DURATION_TEXT = 4;
52 static const int W_DURATION = 171;
53 static const int H_DURATION = 32;
54 static const int W_DEFAULT_THUMBNAIL = 171;
55 static const int H_DEFAULT_THUMBNAIL = 127;
56 static const int W_WIDE_THUMBNAIL = 171;
57 static const int H_WIDE_THUMBNAIL = 127;
58 static const int W_PLAY_FG = 64;
59 static const int H_PLAY_FG = 64;
60 static const int GAP_W_PLAY_FG = (W_DEFAULT_THUMBNAIL -W_PLAY_FG)/2 ;
61 static const int GAP_H_PLAY_FG = (H_DEFAULT_THUMBNAIL - H_PLAY_FG)/2;
62 static const int GAP_H_DURATION = H_DEFAULT_THUMBNAIL - H_DURATION;
63 static const int ALPHA_DURATION = 70;
64 static const int FONT_SIZE_DURATION = 24;
65 static const Dimension DIMENSION_REAL_ICON (171,127);
66 static const Rectangle RECTANGLE_THUMBNAIL_OFFSET_POSION (1, 1, 171, 127);
67 static const Rectangle RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION (1, 1, 171, 127);
68 static const Color COLOR_DURATION_BG (Color::GetColor(COLOR_ID_BLACK));
69 static const Color COLOR_TEXT_OUTLINE (Color::GetColor(COLOR_ID_WHITE));
70
71 static const String RESERVED_CAMERA_PATH = Environment::GetMediaPath() + L"Camera";
72 static const String RESERVED_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera";
73 static const String RESERVED_DOWNLOAD_PATH = Environment::GetMediaPath() + L"Downloads";
74
75 FileListPresentationModel* FileListPresentationModel::__pPresentationModelInstance = null;
76 ThumbnailProvider* FileListPresentationModel::__pThumbnailProvider = null;
77 ThumbnailEvent* FileListPresentationModel::__pThumbnailEvent = null;
78 ArrayList* FileListPresentationModel::__pPresentationModelListener = null;
79 ArrayList* FileListPresentationModel::__pContentEventListener = null;
80 ArrayList* FileListPresentationModel::__pIconListViewCache = null;
81 IList* FileListPresentationModel::__pDirectoryList = null;
82 IList* FileListPresentationModel::__pContentInfoList = null;
83
84 FileListPresentationModel::FileListPresentationModel(void)
85         : __pContentManager(null)
86         , __albumContentType(CONTENT_TYPE_ALL)
87         , __appControlMode(APPCONTROL_MODE_MAIN)
88         , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
89         , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
90         , __pContentIdList(null)
91         , __updateProgressStatus(false)
92 {
93         AppLogDebug("ENTER");
94         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
95 }
96
97 FileListPresentationModel::~FileListPresentationModel(void)
98 {
99         AppLogDebug("ENTER");
100         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
101 }
102
103 FileListPresentationModel*
104 FileListPresentationModel::GetInstance(void)
105 {
106         AppLogDebug("ENTER");
107         if (__pPresentationModelInstance == null)
108         {
109                 CreateInstance();
110         }
111         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
112
113         return __pPresentationModelInstance;
114 }
115
116 result
117 FileListPresentationModel::Construct(void)
118 {
119         AppLogDebug("ENTER");
120
121         IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
122         __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
123         __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
124
125         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
126
127         ContentUpdateEventListener::GetInstance();
128         __pContentManager = new (std::nothrow) ContentManager();
129         __pContentManager->Construct();
130
131         if (__pIconListViewCache != null)
132         {
133                 delete __pIconListViewCache;
134         }
135         __pIconListViewCache = new (std::nothrow) ArrayList(SingleObjectDeleter);
136         __pIconListViewCache->Construct(SIZE_ICON_LIST_CACHE);
137
138         if (__pDirectoryList != null)
139         {
140                 delete __pDirectoryList;
141         }
142         __pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
143
144         if (__pContentInfoList != null)
145         {
146                 delete __pContentInfoList;
147         }
148         __pContentInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
149
150         __pPresentationModelListener = new (std::nothrow) ArrayList();
151         __pPresentationModelListener->Construct();
152
153         __pContentEventListener = new (std::nothrow) ArrayList();
154         __pContentEventListener->Construct();
155
156         __pThumbnailProvider = ThumbnailProvider::GetInstance();
157
158         GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
159         const IMap* pArguments = pApp->GetAppControlArguments();
160         String operationId = pApp->GetAppControlOperationId();
161
162         if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
163         {
164                 __appControlMode = APPCONTROL_MODE_MAIN;
165         }
166         else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
167         {
168                 __appControlMode = APPCONTROL_MODE_PICK;
169
170                 if (pArguments != null)
171                 {
172                         const String* selectionMode = static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
173
174                         if (pApp->GetMimeType().StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
175                         {
176                                 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
177                         }
178
179                         if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
180                         {
181                                 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
182                         }
183                 }
184         }
185         else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
186         {
187                 __appControlMode = APPCONTROL_MODE_SETTING;
188         }
189
190         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
191
192         return E_SUCCESS;
193 }
194
195 void
196 FileListPresentationModel::CreateInstance(void)
197 {
198         AppLogDebug("ENTER");
199         __pPresentationModelInstance = new (std::nothrow) FileListPresentationModel();
200         result r = __pPresentationModelInstance->Construct();
201         if (IsFailed(r) == true)
202         {
203                 delete __pPresentationModelInstance;
204                 __pPresentationModelInstance = null;
205                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
206
207                 return;
208         }
209
210         std::atexit(DestroyInstance);
211         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
212 }
213
214 void
215 FileListPresentationModel::DestroyInstance(void)
216 {
217         AppLogDebug("ENTER");
218
219         delete __pThumbnailEvent;
220         __pIconListViewCache = null;
221
222         if (__pIconListViewCache != null)
223         {
224                 delete __pIconListViewCache;
225                 __pIconListViewCache = null;
226         }
227
228         if (__pDirectoryList != null)
229         {
230                 delete __pDirectoryList;
231                 __pDirectoryList = null;
232         }
233
234         if (__pContentInfoList != null)
235         {
236                 delete __pContentInfoList;
237                 __pContentInfoList = null;
238         }
239
240         if (__pPresentationModelListener != null)
241         {
242                 delete __pPresentationModelListener;
243                 __pPresentationModelListener = null;
244         }
245
246         if (__pContentEventListener != null)
247         {
248                 delete __pContentEventListener;
249                 __pContentEventListener = null;
250         }
251
252         delete __pPresentationModelInstance;
253         __pPresentationModelInstance = null;
254
255         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
256 }
257
258 String
259 FileListPresentationModel::GetFileNameFromFullPath(const String& fullPath, const bool withExt) const
260 {
261         AppLogDebug("ENTER");
262         if (fullPath.CompareTo(EMPTY_SPACE) == 0)
263         {
264                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
265
266                 return EMPTY_SPACE;
267         }
268
269         String delim(DIRECTORY_SEPARATOR);
270         StringTokenizer st(fullPath,delim);
271         String token;
272         while (st.HasMoreTokens())
273         {
274                 st.GetNextToken(token);
275         }
276
277         if (withExt == true)
278         {
279                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
280
281                 return token;
282         }
283         else
284         {
285                 String subDelim(FILE_EXT_SEPARATOR);
286                 StringTokenizer subSt(token, subDelim);
287                 String subToken;
288                 subSt.GetNextToken(subToken);
289                 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
290
291                 return subToken;
292         }
293 }
294
295 String
296 FileListPresentationModel::GetDirecotyNameFromFullPath(const String& fullPath)const
297 {
298         AppLogDebug("ENTER");
299         if (fullPath == null)
300         {
301                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
302
303                 return null;
304         }
305         String delim(DIRECTORY_SEPARATOR);
306         StringTokenizer st(fullPath,delim);
307         String token;
308         while (st.HasMoreTokens())
309         {
310                 st.GetNextToken(token);
311         }
312         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
313
314         return token;
315 }
316
317 bool
318 FileListPresentationModel::IsContainContentInDirectory(const String& directoryPath, ContentType contentType) const
319 {
320         AppLogDebug("ENTER");
321         IListT<ContentType>* pContentTypeList = new (std::nothrow) ArrayListT<ContentType>();
322         if (&directoryPath == null || pContentTypeList == null)
323         {
324                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
325
326                 return false;
327         }
328
329         if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_ALL)
330         {
331                 pContentTypeList->Add(CONTENT_TYPE_IMAGE);
332         }
333         if (contentType == CONTENT_TYPE_VIDEO || contentType == CONTENT_TYPE_ALL)
334         {
335                 pContentTypeList->Add(CONTENT_TYPE_VIDEO);
336         }
337
338         ContentDirectory contentDirectory;
339         result r = contentDirectory.Construct(*pContentTypeList);
340         if (pContentTypeList != null)
341         {
342                 delete pContentTypeList;
343         }
344         TryReturn(r == E_SUCCESS, false, "[%s] Unable to construct ContentDirectory", GetErrorMessage(r));
345
346         bool returnValue = false;
347         int pageNo = SIZE_PAGE_NO;
348         int countPerPage = SIZE_CONUNT_PER_PAGE;
349
350         IList* pContentList = contentDirectory.GetContentDirectoryItemListN(directoryPath, pageNo, countPerPage,
351                         CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
352
353         if (pContentList == null || pContentList->GetCount() <= 0)
354         {
355                 returnValue = false;
356         }
357         else
358         {
359                 returnValue = true;
360         }
361
362         if (pContentList != null)
363         {
364                 delete pContentList;
365         }
366         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
367
368         return returnValue;
369 }
370
371 result
372 FileListPresentationModel::GetThumbnailInSyncCacheN(const int index, String*& pName, Bitmap*& pThumbnail)
373 {
374         AppLogDebug("ENTER : index(%d)", index);
375         Bitmap* pOriginalBitmap = null;
376         Bitmap* pDestinationBitmap = null;
377         ContentInfo* pContentInfo = null;
378
379         if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
380         {
381                 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
382                 if (pContentInfo == null)
383                 {
384                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
385
386                         return E_FAILURE;
387                 }
388         }
389         else
390         {
391                 AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
392                 return E_FAILURE;
393         }
394
395         ThumbnailInfo* pThumbnailInfo = GetThumbnailInfoFromInternalBufferN(pContentInfo->GetContentId());
396         if (pThumbnailInfo != null)
397         {
398                 pName = new (std::nothrow) String(pThumbnailInfo->GetFilePath());
399                 pOriginalBitmap = pThumbnailInfo->GetBitmapN();
400         }
401
402         if ((pThumbnailInfo != null)&&(pThumbnailInfo->GetContentType() == CONTENT_TYPE_VIDEO))
403         {
404                 if (pOriginalBitmap != null)
405                 {
406                         pDestinationBitmap = CoverVideoOverlayedImageOnThumbnailN(*pOriginalBitmap, *pThumbnailInfo);
407                         delete pOriginalBitmap;
408                 }
409         }
410         else
411         {
412                 pDestinationBitmap = pOriginalBitmap;
413         }
414
415         if (pDestinationBitmap != null)
416         {
417                 Bitmap* pThumbnailBgBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_BG);
418                 Rectangle thumbnailRect(RECTANGLE_THUMBNAIL_OFFSET_POSION);
419                 pDestinationBitmap->Scale(Dimension(RECTANGLE_THUMBNAIL_OFFSET_POSION.width - RECTANGLE_THUMBNAIL_OFFSET_POSION.x
420                                 , RECTANGLE_THUMBNAIL_OFFSET_POSION.height - RECTANGLE_THUMBNAIL_OFFSET_POSION.y));
421                 if (pThumbnailBgBitmap != null)
422                 {
423                         pThumbnailBgBitmap->Scale(DIMENSION_REAL_ICON);
424                         pThumbnail = GetShadedBackgroundBitmapN(*pThumbnailBgBitmap, *pDestinationBitmap, thumbnailRect);
425                         delete pThumbnailBgBitmap;
426                         delete pDestinationBitmap;
427                 }
428                 else
429                 {
430                         pThumbnail = pDestinationBitmap;
431                 }
432         }
433         else
434         {
435                 pThumbnail = null;
436         }
437
438         if (pThumbnailInfo != null)
439         {
440                 delete pThumbnailInfo;
441         }
442         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
443
444         return E_SUCCESS;
445 }
446
447 result
448 FileListPresentationModel::GetThumbnailVideoInSyncCacheN(const int index,
449                 String*& pName, Bitmap*& pThumbnail, String*& pDuration) const
450 {
451         AppLogDebug("ENTER : index(%d)", index);
452         ContentInfo* pContentInfo = null;
453         Bitmap* pOriginalBitmap = null;
454
455         if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
456         {
457                 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
458                 if (pContentInfo == null)
459                 {
460                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
461                         return E_FAILURE;
462                 }
463         }
464         else
465         {
466                 AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
467                 return E_FAILURE;
468         }
469
470         ThumbnailInfo* pThumbnailInfo = GetThumbnailInfoFromInternalBufferN(pContentInfo->GetContentId());
471         if (pThumbnailInfo != null)
472         {
473                 pName = new (std::nothrow) String(pThumbnailInfo->GetFilePath());
474                 pOriginalBitmap = pThumbnailInfo->GetBitmapN();
475                 pDuration = new (std::nothrow) String(CommonUtil::DurationToTimeString(pThumbnailInfo->GetDuration()));
476         }
477         else
478         {
479                 pName = new (std::nothrow) String(EMPTY_SPACE);
480                 pDuration = new (std::nothrow) String(CommonUtil::DurationToTimeString(0));
481         }
482
483         if (pOriginalBitmap != null)
484         {
485                 Bitmap* pThumbnailBgBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_BG);
486                 Rectangle thumbnailRect(RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION);
487                 pOriginalBitmap->Scale(Dimension(RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.width - RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.x
488                                 , RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.height - RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION.y));
489                 if (pThumbnailBgBitmap != null)
490                 {
491                         pThumbnailBgBitmap->Scale(Dimension(W_WIDE_THUMBNAIL, H_WIDE_THUMBNAIL));
492                         pThumbnail = GetShadedBackgroundBitmapN(*pThumbnailBgBitmap, *pOriginalBitmap, thumbnailRect);
493                         delete pThumbnailBgBitmap;
494                 }
495                 delete pOriginalBitmap;
496         }
497         else
498         {
499                 pThumbnail = null;
500         }
501
502         if (pThumbnail != null)
503         {
504                 pThumbnail->Scale(Dimension(W_WIDE_THUMBNAIL, H_WIDE_THUMBNAIL));
505         }
506
507         if (pThumbnailInfo != null)
508         {
509                 delete pThumbnailInfo;
510         }
511         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
512
513         return E_SUCCESS;
514 }
515
516 void
517 FileListPresentationModel::RequestThumbnail(const int index)
518 {
519         AppLogDebug("ENTER : index(%d)", index);
520         ContentInfo* pContentInfo = null;
521
522         if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
523         {
524                 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
525                 if (pContentInfo == null)
526                 {
527                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
528                         return;
529                 }
530         }
531         else
532         {
533                 AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
534
535                 return;
536         }
537
538         __pThumbnailProvider->RequestThumbnail(pContentInfo->GetContentId(), __pThumbnailEvent);
539         AppLogDebug("EXIT");
540 }
541
542 void
543 FileListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
544 {
545         AppLogDebug("ENTER");
546
547         if (__pThumbnailProvider != null)
548         {
549                 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
550         }
551
552         AppLogDebug("EXIT");
553 }
554
555 void
556 FileListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
557 {
558         AppLogDebug("ENTER");
559
560         if (&eventArg != null)
561         {
562                 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
563                 if (pThumbnailEventArg == null)
564                 {
565                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
566
567                         return;
568                 }               
569                 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
570                 if (pThumbnailInfo == null)
571                 {
572                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
573
574                         return;
575                 }
576
577                 bool isMatch = false;
578                 ContentId contentId = pThumbnailInfo->GetContentId();
579
580                 if (__pIconListViewCache != null)
581                 {
582                         IEnumerator* pEnum = __pIconListViewCache->GetEnumeratorN();
583                         Bitmap* pBitmap = null;
584                         while (pEnum->MoveNext() == E_SUCCESS)
585                         {
586                                 ThumbnailInfo* pTempThumbnailInfo = static_cast<ThumbnailInfo*>(pEnum->GetCurrent());
587
588                                 if (contentId == pTempThumbnailInfo->GetContentId())
589                                 {
590                                         AppLogDebug("[CHASEFIRE] PM receive (%ls)", pThumbnailInfo->GetFilePath().GetPointer());
591                                         pBitmap = pThumbnailInfo->GetBitmapN();
592                                         pTempThumbnailInfo->SetBitmap(*pBitmap);
593                                         delete pBitmap;
594
595                                         pTempThumbnailInfo->SetContentType(pThumbnailInfo->GetContentType());
596                                         pTempThumbnailInfo->SetDuration(pThumbnailInfo->GetDuration());
597                                         delete pThumbnailInfo;
598                                         isMatch = true;
599                                         break;
600                                 }
601                         }
602
603                         if (isMatch == false)
604                         {
605                                 if (SIZE_ICON_LIST_CACHE <= __pIconListViewCache->GetCount())
606                                 {
607                                         __pIconListViewCache->RemoveAt(0, true);
608                                 }
609                                 AppLogDebug("[CHASEFIRE] (all:%d) Add Thumbail(%ls)", __pIconListViewCache->GetCount(),
610                                                 pThumbnailInfo->GetFilePath().GetPointer());
611                                 __pIconListViewCache->Add(pThumbnailInfo);
612                         }
613                 }
614
615                 int index = -1;
616                 int loopCount = __pContentInfoList->GetCount();
617                 for (int i = 0; i < loopCount; ++i)
618                 {
619                         if (contentId == (static_cast<ContentInfo*>(__pContentInfoList->GetAt(i)))->GetContentId())
620                         {
621                                 index = i;
622                                 break;
623                         }
624                 }
625
626                 IAlbumEventListener* pInterface = null;
627                 IEnumerator* pEventEnum = __pPresentationModelListener->GetEnumeratorN();
628                 while (pEventEnum->MoveNext() == E_SUCCESS)
629                 {
630                         pInterface = static_cast<IAlbumEventListener*>(pEventEnum->GetCurrent());
631                         pInterface->OnThumbnailDecoded(index);
632                 }
633                 delete pEventEnum;
634         }
635         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
636 }
637
638 void
639 FileListPresentationModel::OnContentCreated(void)
640 {
641         AppLogDebug("ENTER");
642         if (__updateProgressStatus == true)
643         {
644                 AppLogDebug("EXIT update in application");
645                 return;
646         }
647         IFormContentUpdateEventListener* pInterface = null;
648         if (__pContentEventListener == null)
649         {
650                 AppLogDebug("EXIT");
651                 return;
652         }
653         IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
654         while (pEventEnum->MoveNext() == E_SUCCESS)
655         {
656                 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
657                 if (pInterface != null)
658                 {
659                         pInterface->OnContentUpdated();
660                 }
661         }
662         delete pEventEnum;
663         AppLogDebug("EXIT");
664 }
665
666 void
667 FileListPresentationModel::OnContentUpdated(void)
668 {
669         AppLogDebug("ENTER");
670         if (__updateProgressStatus == true)
671         {
672                 AppLogDebug("EXIT update in application");
673                 return;
674         }
675         IFormContentUpdateEventListener* pInterface = null;
676         if (__pContentEventListener == null)
677         {
678                 AppLogDebug("EXIT");
679                 return;
680         }
681         IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
682         while (pEventEnum->MoveNext() == E_SUCCESS)
683         {
684                 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
685                 pInterface->OnContentUpdated();
686         }
687         delete pEventEnum;
688         AppLogDebug("EXIT");
689 }
690
691 void
692 FileListPresentationModel::OnContentDeleted(void)
693 {
694         AppLogDebug("ENTER");
695         if (__updateProgressStatus == true)
696         {
697                 AppLogDebug("EXIT update in application");
698                 return;
699         }
700         IFormContentUpdateEventListener* pInterface = null;
701         if (__pContentEventListener == null)
702         {
703                 AppLogDebug("EXIT");
704                 return;
705         }
706         IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
707         while (pEventEnum->MoveNext() == E_SUCCESS)
708         {
709                 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
710                 pInterface->OnContentUpdated();
711         }
712         delete pEventEnum;
713         AppLogDebug("EXIT");
714 }
715
716 void
717 FileListPresentationModel::AddPresentationModelListener(const IAlbumEventListener* listener)
718 {
719         AppLogDebug("ENTER");
720         __pPresentationModelListener->Add((Object*)listener);
721         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
722 }
723
724 void
725 FileListPresentationModel::RemovePresentationModelListener(const IAlbumEventListener& listener)
726 {
727         AppLogDebug("ENTER");
728         __pPresentationModelListener->Remove(listener);
729         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
730 }
731
732 void
733 FileListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
734 {
735         AppLogDebug("ENTER");
736         if (__pContentEventListener != null)
737         {
738                 __pContentEventListener->RemoveAll();
739                 __pContentEventListener->Add((Object*)listener);
740                 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
741         }
742 }
743
744 void
745 FileListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener* listener)
746 {
747         AppLogDebug("ENTER");
748         __pContentEventListener->Remove(*listener);
749         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
750 }
751
752 ThumbnailInfo*
753 FileListPresentationModel::GetThumbnailInfoFromInternalBufferN(const ContentId& contentId) const
754 {
755         AppLogDebug("ENTER");
756         ThumbnailInfo* pThumbnailInfo = null;
757         ThumbnailInfo* pTempThumbnailInfo = null;
758         if (__pIconListViewCache != null)
759         {
760                 int loopCount = __pIconListViewCache->GetCount();
761                 for (int i = 0; i < loopCount; ++i)
762                 {
763                         pTempThumbnailInfo = static_cast<ThumbnailInfo*>(__pIconListViewCache->GetAt(i));
764                         if (contentId == pTempThumbnailInfo->GetContentId())
765                         {
766
767                                 pThumbnailInfo = new (std::nothrow) ThumbnailInfo();
768                                 Bitmap* pBitmap = pTempThumbnailInfo->GetBitmapN();
769                                 pThumbnailInfo->Construct(pTempThumbnailInfo->GetContentId(), pTempThumbnailInfo->GetFilePath(),
770                                                 *pBitmap, pTempThumbnailInfo->GetContentType(), pTempThumbnailInfo->GetDuration());
771                                 delete pBitmap;
772                                 break;
773                         }
774                 }
775         }
776         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
777
778         return pThumbnailInfo;
779 }
780
781 result
782 FileListPresentationModel::DeleteContentFileList(const IList& contentIndexList)
783 {
784         AppLogDebug("ENTER");
785         if (&contentIndexList == null || contentIndexList.GetCount() <= 0)
786         {
787                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
788
789                 return E_SUCCESS;
790         }
791
792         IList * pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
793         int loopCount = contentIndexList.GetCount();
794         for (int i = 0; i < loopCount; ++i)
795         {
796                 const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
797
798                 if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
799                 {
800                         pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>
801                                         (__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
802                 }
803         }
804
805         loopCount = pContentIdList->GetCount();
806         for (int i = 0; i < loopCount; ++i)
807         {
808                 ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(i));
809                 if (pContentId != null)
810                 {
811                         DeleteContentFile(*pContentId);
812                 }
813         }
814         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
815
816         return E_SUCCESS;
817 }
818
819 IList*
820 FileListPresentationModel::GetCollisionIndexListN(const IList& contentIndexList, const String& destDirectory)
821 {
822         AppLogDebug("ENTER");
823         if (&contentIndexList == null || contentIndexList.GetCount() <= 0 || &destDirectory == null
824                         || destDirectory.IsEmpty() == true)
825         {
826                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
827
828                 return null;
829         }
830
831         if (File::IsFileExist(destDirectory) == false)
832         {
833                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
834
835                 return null;
836         }
837
838         IList * pCollisionInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
839         ContentInfo* pContentInfo = null;
840         int loopCount = contentIndexList.GetCount();
841         for (int i = 0; i < loopCount; ++i)
842         {
843                 const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
844
845                 if ((pIndex != null) && (pIndex->ToInt()) >= 0 && __pContentInfoList->GetCount() > pIndex->ToInt())
846                 {
847                         pContentInfo = const_cast<ContentInfo*>(static_cast<const ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())));
848                         String filePath = pContentInfo->GetContentPath();
849                         String fileName = GetFileNameFromFullPath(filePath, true);
850
851                         String destPath;
852                         if (destDirectory.EndsWith(DIRECTORY_SEPARATOR) == true)
853                         {
854                                 destPath.Append(destDirectory);
855                                 destPath.Append(fileName);
856                         }
857                         else
858                         {
859                                 destPath.Append(destDirectory);
860                                 destPath.Append(DIRECTORY_SEPARATOR);
861                                 destPath.Append(fileName);
862                         }
863
864                         if (File::IsFileExist(destPath) == true)
865                         {
866                                 pCollisionInfoList->Add(*(new (std::nothrow) String(pIndex->ToString() + MULTI_ITEM_SEPARATOR + fileName)));
867                         }
868                 }
869         }
870         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
871
872         return pCollisionInfoList;
873 }
874
875 result
876 FileListPresentationModel::MoveToContentFileList(const IList& contentIndexList, const String& destDirectory)
877 {
878         AppLogDebug("ENTER");
879         result r = E_SUCCESS;
880         if (&contentIndexList == null || contentIndexList.GetCount() <= 0 || &destDirectory == null || destDirectory.IsEmpty() == true)
881         {
882                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
883
884                 return r;
885         }
886
887         if (File::IsFileExist(destDirectory) == false)
888         {
889                 Directory::Create(destDirectory, true);
890         }
891
892         delete __pContentIdList;
893         __pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
894         int loopCount = contentIndexList.GetCount();
895         for (int i = 0; i < loopCount; ++i)
896         {
897                 const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
898
899                 if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
900                 {
901                         __pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
902                 }
903         }
904
905
906         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
907
908         return E_SUCCESS;
909 }
910
911 result
912 FileListPresentationModel::DeleteContentFile(const ContentId& contentId)
913 {
914         AppLogDebug("ENTER");
915         if (&contentId == null)
916         {
917                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
918
919                 return E_SUCCESS;
920         }
921         result r = __pContentManager->DeleteContent(contentId);
922
923         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
924
925         return r;
926 }
927
928 result
929 FileListPresentationModel::MoveToContentFile(const ContentId& contentId, const String& destDirectory, const bool isCopyOperation)
930 {
931         AppLogDebug("ENTER");
932         if (contentId.ToString().IsEmpty() == true || destDirectory.IsEmpty() == true)
933         {
934                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
935                 return E_FAILURE;
936         }
937         result r = E_SUCCESS;
938         ContentInfo* pContentInfo = __pContentManager->GetContentInfoN(contentId);
939         if (pContentInfo == null)
940         {
941                 AppLogDebug("Santhosh %s", destDirectory.GetPointer());
942                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
943                 return E_FAILURE;
944         }
945
946         String filePath = pContentInfo->GetContentPath();
947         if (filePath.GetLength() < 4)
948         {
949                 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
950                 return E_SUCCESS;
951         }
952
953         String destPath;
954         if (destDirectory.EndsWith(DIRECTORY_SEPARATOR) == true)
955         {
956                 destPath.Append(destDirectory);
957                 destPath.Append(GetFileNameFromFullPath(filePath, true));
958         }
959         else
960         {
961                 destPath.Append(destDirectory);
962                 destPath.Append(DIRECTORY_SEPARATOR);
963                 destPath.Append(GetFileNameFromFullPath(filePath, true));
964         }
965
966         if (destPath.CompareTo(filePath) == 0)
967         {
968                 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
969                 return E_SUCCESS;
970         }
971
972         if (File::IsFileExist(destPath) == true)
973         {
974                 File::Remove(destPath);
975         }
976
977         if (pContentInfo->GetContentType() == CONTENT_TYPE_IMAGE)
978         {
979                 r = File::Copy(filePath, destPath, false);
980                 if (r == E_SUCCESS)
981                 {
982                         if (r == E_SUCCESS)
983                         {
984                                 ImageContentInfo contentInfo;
985                                 r = contentInfo.Construct(&destPath);
986                                 if (r == E_SUCCESS)
987                                 {
988                                         __pContentManager->CreateContent(contentInfo);
989                                         r = GetLastResult();
990                                         TryCatch(!IsFailed(r),,"CreateContent::the value is %s", GetErrorMessage(r));
991                                         if (!isCopyOperation)
992                                         {
993                                                 r = __pContentManager->DeleteContent(contentId);
994                                                 TryCatch(!IsFailed(r),,"DeleteContent::the value is %s", GetErrorMessage(r));
995                                         }
996                                 }
997                         }
998                 }
999         }
1000         else if (pContentInfo->GetContentType() == CONTENT_TYPE_VIDEO)
1001         {
1002                 r = File::Copy(filePath, destPath, false);
1003                 if (r == E_SUCCESS)
1004                 {
1005                         VideoContentInfo contentInfo;
1006                         r = contentInfo.Construct(&destPath);
1007                         {
1008                                 __pContentManager->CreateContent(contentInfo);
1009                                 r = GetLastResult();
1010                                 TryCatch(!IsFailed(r),,"CreateContent::the value is %s", GetErrorMessage(r));
1011                                 if (!isCopyOperation)
1012                                 {
1013                                         r = __pContentManager->DeleteContent(contentId);
1014                                         TryCatch(!IsFailed(r),,"DeleteContent::the value is %s", GetErrorMessage(r));
1015                                 }
1016                         }
1017                 }
1018         }
1019         CATCH:
1020         delete pContentInfo;
1021
1022         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1023
1024         return r;
1025 }
1026
1027 result
1028 FileListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
1029                 const String* pUriData, const Tizen::Base::String* pMimeType, const HashMap* pDataList,
1030                 IAppControlResponseListener* pListener)
1031 {
1032         AppLogDebug("ENTER");
1033         AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
1034         if (pAc == null)
1035         {
1036                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1037                 return E_FAILURE;
1038         }
1039         result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
1040
1041         if (r == E_SUCCESS)
1042         {
1043                 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
1044                 pGalleryApp->SetFrameEnabled(false);
1045         }
1046
1047         delete pAc;
1048
1049         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1050
1051         return r;
1052 }
1053
1054 result
1055 FileListPresentationModel::SetCurrentAlbumInfo(const String& albumName, const IList& directoryList)
1056 {
1057         AppLogDebug("ENTER");
1058
1059         if (&directoryList != null)
1060         {
1061                 if (__pDirectoryList != null && __pDirectoryList->GetCount() > 0)
1062                 {
1063                         bool isMatched = false;
1064                         int outterLoopCount = __pDirectoryList->GetCount();
1065                         int innerLoopCount = 0;
1066                         for (int i = 0; i < outterLoopCount ; ++i)
1067                         {
1068                                 isMatched = false;
1069                                 innerLoopCount = directoryList.GetCount();
1070                                 for (int j = 0; j < innerLoopCount; ++j)
1071                                 {
1072                                         if (static_cast<String*>(__pDirectoryList->GetAt(i))->CompareTo(
1073                                                         *(const_cast<String*>(static_cast<const String*>(directoryList.GetAt(j))))) == 0)
1074                                         {
1075                                                 isMatched = true;
1076                                                 break;
1077                                         }
1078                                 }
1079                         }
1080
1081                         outterLoopCount = directoryList.GetCount();
1082                         for (int i = 0; i < outterLoopCount; ++i)
1083                         {
1084                                 isMatched = false;
1085                                 innerLoopCount = __pDirectoryList->GetCount();
1086                                 for (int j = 0; j < innerLoopCount; ++j)
1087                                 {
1088                                         if (const_cast<String*>(static_cast<const String*>(directoryList.GetAt(i)))->CompareTo(
1089                                                         *(static_cast<String*>(__pDirectoryList->GetAt(j)))) == 0)
1090                                         {
1091                                                 isMatched = true;
1092                                                 break;
1093                                         }
1094                                 }
1095                         }
1096                 }
1097         }
1098
1099         __albumName = albumName;
1100
1101         if (__pDirectoryList != null)
1102         {
1103                 delete __pDirectoryList;
1104         }
1105         __pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1106
1107         int loopCount = directoryList.GetCount();
1108         for (int i = 0; i < loopCount; ++i)
1109         {
1110                 __pDirectoryList->Add(new (std::nothrow) String(*(const_cast<String*>
1111                         (static_cast<const String*>(directoryList.GetAt(i))))));
1112         }
1113
1114         if (__pContentInfoList != null)
1115         {
1116                 delete __pContentInfoList;
1117                 __pContentInfoList = null;
1118         }
1119
1120         if (GetAppControlMode() == APPCONTROL_MODE_PICK)
1121         {
1122                 AppControlMediaType appControlMediaType = GetAppControlMediaType();
1123                 if (appControlMediaType == APPCONTROL_MEDIA_TYPE_IMAGE)
1124                 {
1125                         __albumContentType = CONTENT_TYPE_IMAGE;
1126                 }
1127                 else if (appControlMediaType == APPCONTROL_MEDIA_TYPE_VIDEO)
1128                 {
1129                         __albumContentType = CONTENT_TYPE_VIDEO;
1130                 }
1131         }
1132         __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
1133         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1134
1135         return E_SUCCESS;
1136 }
1137
1138 result
1139 FileListPresentationModel::RefreshCurrentAlbumContentInfoList(const ContentType contentType)
1140 {
1141         AppLogDebug("ENTER");
1142         result r = RefreshContentInfoList(contentType);
1143         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1144
1145         return r;
1146 }
1147
1148 result
1149 FileListPresentationModel::RefreshContentInfoList(const ContentType contentType)
1150 {
1151         AppLogDebug("ENTER");
1152         if ((contentType != CONTENT_TYPE_ALL) && (contentType != CONTENT_TYPE_IMAGE) && (contentType != CONTENT_TYPE_VIDEO))
1153         {
1154                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1155
1156                 return E_FAILURE;
1157         }
1158
1159         if ((__pDirectoryList == null) || (__pDirectoryList->GetCount() <= 0))
1160         {
1161                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1162
1163                 return E_SUCCESS;
1164         }
1165
1166         __albumContentType = contentType;
1167
1168         if (__pContentInfoList != null)
1169         {
1170                 delete __pContentInfoList;
1171                 __pContentInfoList = null;
1172         }
1173         __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
1174         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1175
1176         return E_SUCCESS;
1177 }
1178
1179 String
1180 FileListPresentationModel::GetCurrentAlbumName(void) const
1181 {
1182         AppLogDebug("ENTER");
1183         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1184
1185         return __albumName;
1186 }
1187
1188 void
1189 FileListPresentationModel::SetCurrentAlbumName(const String& albumName)
1190 {
1191         AppLogDebug("ENTER");
1192         if (&albumName == null)
1193         {
1194                 __albumName = EMPTY_SPACE;
1195         }
1196         else
1197         {
1198                 __albumName = albumName;
1199         }
1200         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1201 }
1202
1203 ContentType
1204 FileListPresentationModel::GetCurrentAlbumContentType(void) const
1205 {
1206         AppLogDebug("ENTER");
1207         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1208
1209         return __albumContentType;
1210 }
1211
1212 void
1213 FileListPresentationModel::SetCurrentAlbumContentType(const ContentType contentType)
1214 {
1215         AppLogDebug("ENTER");
1216         __albumContentType = contentType;
1217         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1218 }
1219
1220 IList*
1221 FileListPresentationModel::GetAlbumDirectoryListN(void) const
1222 {
1223         AppLogDebug("ENTER");
1224         IList* pAlbumDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1225         if (__pDirectoryList == null)
1226         {
1227                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1228
1229                 return pAlbumDirectoryList;
1230         }
1231
1232         String* pDirectory = null;
1233         int loopCount = __pDirectoryList->GetCount();
1234         for (int i = 0; i < loopCount; ++i)
1235         {
1236                 pDirectory = static_cast<String*>(__pDirectoryList->GetAt(i));
1237                 pAlbumDirectoryList->Add(new (std::nothrow) String(*pDirectory));
1238         }
1239         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1240
1241         return pAlbumDirectoryList;
1242 }
1243
1244 IList*
1245 FileListPresentationModel::GetAlbumContentInfoList(void) const
1246 {
1247         AppLogDebug("ENTER");
1248         IList* pContentList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1249         if (__pContentInfoList == null)
1250         {
1251                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1252
1253                 return pContentList;
1254         }
1255
1256         ContentInfo* pContentInfo = null;
1257         int loopCount = __pContentInfoList->GetCount();
1258         for (int i = 0; i < loopCount; ++i)
1259         {
1260                 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(i));
1261                 pContentList->Add(pContentInfo);
1262         }
1263         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1264
1265         return pContentList;
1266 }
1267
1268 ContentInfo*
1269 FileListPresentationModel::GetContentInfo(const int index) const
1270 {
1271         AppLogDebug("ENTER");
1272         if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1273         {
1274                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1275
1276                 return null;
1277         }
1278
1279         if (index < 0 || index >= __pContentInfoList->GetCount())
1280         {
1281                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1282
1283                 return null;
1284         }
1285         ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1286         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1287
1288         return pContentInfo;
1289 }
1290
1291 IList* FileListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
1292 {
1293         IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1294         int loopCount = indexList.GetCount();
1295         for (int i = 0; i < loopCount; ++i)
1296         {
1297                 const Integer* pIndex = static_cast<const Integer*>(indexList.GetAt(i));
1298
1299                 if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
1300                 {
1301                         pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
1302                 }
1303         }
1304
1305         return pContentIdList;
1306 }
1307
1308 int
1309 FileListPresentationModel::GetCurrentAlbumContentInfoCount(void) const
1310 {
1311         AppLogDebug("ENTER");
1312         if (__pContentInfoList == null)
1313         {
1314                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1315
1316                 return 0;
1317         }
1318         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1319
1320         return __pContentInfoList->GetCount();
1321 }
1322
1323 ContentId
1324 FileListPresentationModel::GetContentInfoIndex(const int index) const
1325 {
1326         AppLogDebug("ENTER");
1327         if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1328         {
1329                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1330
1331                 return 0;
1332         }
1333
1334         if (index < 0 || index >= __pContentInfoList->GetCount())
1335         {
1336                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1337
1338                 return 0;
1339         }
1340         ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1341         ContentId contentId = pContentInfo->GetContentId();
1342         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1343
1344         return contentId;
1345 }
1346
1347 String
1348 FileListPresentationModel::GetContentFilePath(const int index) const
1349 {
1350         AppLogDebug("ENTER index(%d)", index);
1351         if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1352         {
1353                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1354
1355                 return EMPTY_SPACE;
1356         }
1357
1358         if (index < 0 || index >= __pContentInfoList->GetCount())
1359         {
1360                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1361
1362                 return EMPTY_SPACE;
1363         }
1364
1365         ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1366         String contentPath = pContentInfo->GetContentPath();
1367         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1368
1369         return contentPath;
1370 }
1371
1372 Bitmap*
1373 FileListPresentationModel::CoverVideoOverlayedImageOnThumbnailN(Bitmap& thumbnail,
1374                 const ThumbnailInfo& thumbmailInfo)
1375 {
1376         AppLogDebug("ENTER");
1377         Bitmap* pOverlayedImage = null;
1378
1379         if (&thumbmailInfo != null)
1380         {
1381                 long duration = thumbmailInfo.GetDuration();
1382
1383                 Canvas mainCanvas;
1384                 if (&thumbnail != null)
1385                 {
1386                         BufferInfo bufferInfo;
1387                         thumbnail.Lock(bufferInfo, INFINITE);
1388                         thumbnail.Unlock();
1389                         mainCanvas.Construct(bufferInfo);
1390                 }
1391                 else
1392                 {
1393                         Rectangle mainRect(0, 0, W_DEFAULT_THUMBNAIL, H_DEFAULT_THUMBNAIL);
1394                         mainCanvas.Construct(mainRect);
1395                         mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_BLACK), mainRect);
1396                 }
1397
1398                 Rectangle playRect(GAP_W_PLAY_FG, GAP_H_PLAY_FG, W_PLAY_FG, H_PLAY_FG);
1399                 Bitmap* playBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_PLAY);
1400                 if (playBitmap != null)
1401                 {
1402                         mainCanvas.DrawBitmap(playRect, *playBitmap);
1403                         delete playBitmap;
1404                 }
1405
1406                 Canvas durCanvas;
1407                 Rectangle durSize(0, 0, W_DURATION, H_DURATION);
1408                 Rectangle durRect(0, GAP_H_DURATION, W_DURATION, H_DURATION);
1409                 Color durColor(COLOR_DURATION_BG);
1410                 durColor.SetAlpha(ALPHA_DURATION);
1411                 durCanvas.Construct(durSize);
1412                 durCanvas.FillRectangle(durColor, durSize);
1413                 Font durFont;
1414                 durFont.Construct(FONT_STYLE_PLAIN, FONT_SIZE_DURATION);
1415                 durCanvas.SetFont(durFont);
1416                 durCanvas.DrawText(Point(W_DURATION_TEXT, H_DURATION_TEXT),
1417                                 CommonUtil::DurationToTimeString(duration), COLOR_TEXT_OUTLINE);
1418                 Bitmap durBitmap;
1419                 durBitmap.Construct(durCanvas, durCanvas.GetBounds());
1420                 mainCanvas.DrawBitmap(durRect, durBitmap);
1421
1422                 pOverlayedImage = new (std::nothrow) Bitmap();
1423                 pOverlayedImage->Construct(mainCanvas, mainCanvas.GetBounds());
1424         }
1425         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1426
1427         return pOverlayedImage;
1428 }
1429
1430 Bitmap*
1431 FileListPresentationModel::GetShadedBackgroundBitmapN(Bitmap& bgBitmap,
1432                 const Bitmap& originalBitmap, const Rectangle& originalBitmapPosition) const
1433 {
1434         AppLogDebug("ENTER");
1435         if (&originalBitmap == null || &originalBitmap == null)
1436         {
1437                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1438
1439                 return null;
1440         }
1441
1442         BufferInfo bufferInfo;
1443         bgBitmap.Lock(bufferInfo, INFINITE);
1444         bgBitmap.Unlock();
1445         Canvas mainCanvas;
1446         mainCanvas.Construct(bufferInfo);
1447         mainCanvas.Clear();
1448         mainCanvas.DrawBitmap(originalBitmapPosition, originalBitmap);
1449
1450         Bitmap* pMainImage = new (std::nothrow) Bitmap();
1451         pMainImage->Construct(mainCanvas,mainCanvas.GetBounds());
1452         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1453
1454         return pMainImage;
1455 }
1456
1457 IList*
1458 FileListPresentationModel::GetContentInfoListInDirectoryListN(const IList& contentDirectoryList,
1459                 ContentType contentType)const
1460 {
1461         AppLogDebug("ENTER");
1462         IList* pContentList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1463
1464         if ((&contentDirectoryList == null) || (contentDirectoryList.GetCount() == 0)
1465                         || ((contentType != CONTENT_TYPE_IMAGE) && (contentType != CONTENT_TYPE_VIDEO) && (contentType != CONTENT_TYPE_ALL)))
1466         {
1467                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1468                 return pContentList;
1469         }
1470
1471         ContentDirectory contentDirectory;
1472         IListT<ContentType>* pContentTypeList = new (std::nothrow) ArrayListT<ContentType>();
1473         if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_ALL)
1474         {
1475                 pContentTypeList->Add(CONTENT_TYPE_IMAGE);
1476         }
1477         if (contentType == CONTENT_TYPE_VIDEO || contentType == CONTENT_TYPE_ALL)
1478         {
1479                 pContentTypeList->Add(CONTENT_TYPE_VIDEO);
1480         }
1481         result r = contentDirectory.Construct(*pContentTypeList);
1482         delete pContentTypeList;
1483
1484         if (r == E_SUCCESS)
1485         {
1486                 int pageNo = SIZE_PAGE_NO;
1487                 int countPerPage = SIZE_CONUNT_PER_PAGE;
1488                 String* pContentDirectory = null;
1489
1490                 int loopCount = contentDirectoryList.GetCount();
1491                 for (int i = 0; i < loopCount; ++i)
1492                 {
1493                         IList* pIList = null;
1494                         pContentDirectory = const_cast<String*>(static_cast<const String*>(contentDirectoryList.GetAt(i)));
1495                         if (pContentDirectory != null)
1496                         {
1497                                 pIList = contentDirectory.GetContentDirectoryItemListN(*pContentDirectory, pageNo, countPerPage,
1498                                                 CONTENT_INFO_ORDER, SORT_ORDER_NONE);
1499
1500                                 if (pIList != null)
1501                                 {
1502                                         pContentList->AddItems(*pIList);
1503                                 }
1504                         }
1505                 }
1506         }
1507         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1508
1509         return pContentList;
1510 }
1511
1512 String
1513 FileListPresentationModel::ConvertToAlbumName(const String& targetPath)const
1514 {
1515         AppLogDebug("ENTER");
1516         String albumName;
1517         if (&targetPath == null || targetPath.GetLength() == 0)
1518         {
1519                 return albumName;
1520         }
1521
1522         if (targetPath == RESERVED_CAMERA_PATH || targetPath == RESERVED_CAMERA_PATH_EXT)
1523         {
1524                 albumName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB");
1525         }
1526         else if (targetPath == RESERVED_DOWNLOAD_PATH)
1527         {
1528                 albumName = ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS");
1529         }
1530         else
1531         {
1532                 String directoryName = GetDirecotyNameFromFullPath(targetPath);
1533                 albumName = directoryName;
1534         }
1535
1536         return albumName;
1537 }
1538
1539 AppControlMode
1540 FileListPresentationModel::GetAppControlMode(void) const
1541 {
1542         AppLogDebug("Enter");
1543         AppLogDebug("Exit");
1544
1545         return __appControlMode;
1546 }
1547
1548 AppControlMediaType
1549 FileListPresentationModel::GetAppControlMediaType(void) const
1550 {
1551         AppLogDebug("Enter");
1552         AppLogDebug("Exit");
1553
1554         return __appControlMediaType;
1555 }
1556
1557 AppControlSelectionMode
1558 FileListPresentationModel::GetAppControlSelectionMode(void) const
1559 {
1560         AppLogDebug("Enter");
1561         AppLogDebug("Exit");
1562
1563         return __appControlSelectionMode;
1564 }
1565
1566 void
1567 FileListPresentationModel::SetUpdateProgressStatus(const bool status)
1568 {
1569         AppLogDebug("ENTER status = %d",status);
1570         __updateProgressStatus = status;
1571         AppLogDebug("EXIT");
1572 }
1573
1574 result
1575 FileListPresentationModel::RotateImage(int index, RotateMode rotateMode)
1576 {
1577         result r = E_SUCCESS;
1578         ImageBuffer rotateBuffer;
1579         ImageBuffer* pRotatedBuffer = null;
1580         ImageFormat imageFormat;
1581         Image img;
1582         String filePath = GetContentFilePath(index);
1583         r = img.Construct();
1584
1585
1586         if (r == E_SUCCESS)
1587         {
1588                 imageFormat = img.GetImageFormat(filePath);
1589         }
1590
1591         r = rotateBuffer.Construct(filePath);
1592         if (r == E_SUCCESS)
1593         {
1594                 if (rotateMode == ROTATE_MODE_RIGHT)
1595                 {
1596                         pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_90);
1597                 }
1598                 else
1599                 {
1600                         pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_270);
1601                 }
1602         }
1603
1604         if (pRotatedBuffer != null)
1605         {
1606                 r = pRotatedBuffer->EncodeToFile(filePath, imageFormat, true, 100);
1607                 delete pRotatedBuffer;
1608         }
1609
1610         ContentManager::ScanFile(filePath);
1611         return r;
1612 }
1613
1614 void
1615 FileListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1616 {
1617         AppLogDebug("ENTER");
1618         if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
1619         {
1620                 IFormContentUpdateEventListener* pInterface = null;
1621                 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1622                 while (pEventEnum->MoveNext() == E_SUCCESS)
1623                 {
1624                         pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1625                         pInterface->OnContentUpdated();
1626                 }
1627                 delete pEventEnum;
1628         }
1629         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1630 }