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