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