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