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