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