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