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