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