Fix 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_IMAGE)
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 String* pUriData, const Tizen::Base::String* pMimeType, const HashMap* pDataList,
1020                 IAppControlResponseListener* pListener)
1021 {
1022         AppLogDebug("ENTER");
1023         AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
1024         if (pAc == null)
1025         {
1026                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1027                 return E_FAILURE;
1028         }
1029         result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
1030
1031         if (r == E_SUCCESS)
1032         {
1033                 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
1034                 pGalleryApp->SetFrameEnabled(false);
1035         }
1036
1037         delete pAc;
1038
1039         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1040
1041         return r;
1042 }
1043
1044 result
1045 FileListPresentationModel::SetCurrentAlbumInfo(const String& albumName, const IList& directoryList)
1046 {
1047         AppLogDebug("ENTER");
1048
1049         if (&directoryList != null)
1050         {
1051                 if (__pDirectoryList != null && __pDirectoryList->GetCount() > 0)
1052                 {
1053                         bool isMatched = false;
1054                         int outterLoopCount = __pDirectoryList->GetCount();
1055                         int innerLoopCount = 0;
1056                         for (int i = 0; i < outterLoopCount ; ++i)
1057                         {
1058                                 isMatched = false;
1059                                 innerLoopCount = directoryList.GetCount();
1060                                 for (int j = 0; j < innerLoopCount; ++j)
1061                                 {
1062                                         if (static_cast<String*>(__pDirectoryList->GetAt(i))->CompareTo(
1063                                                         *(const_cast<String*>(static_cast<const String*>(directoryList.GetAt(j))))) == 0)
1064                                         {
1065                                                 isMatched = true;
1066                                                 break;
1067                                         }
1068                                 }
1069                         }
1070
1071                         outterLoopCount = directoryList.GetCount();
1072                         for (int i = 0; i < outterLoopCount; ++i)
1073                         {
1074                                 isMatched = false;
1075                                 innerLoopCount = __pDirectoryList->GetCount();
1076                                 for (int j = 0; j < innerLoopCount; ++j)
1077                                 {
1078                                         if (const_cast<String*>(static_cast<const String*>(directoryList.GetAt(i)))->CompareTo(
1079                                                         *(static_cast<String*>(__pDirectoryList->GetAt(j)))) == 0)
1080                                         {
1081                                                 isMatched = true;
1082                                                 break;
1083                                         }
1084                                 }
1085                         }
1086                 }
1087         }
1088
1089         __albumName = albumName;
1090
1091         if (__pDirectoryList != null)
1092         {
1093                 delete __pDirectoryList;
1094         }
1095         __pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1096
1097         int loopCount = directoryList.GetCount();
1098         for (int i = 0; i < loopCount; ++i)
1099         {
1100                 __pDirectoryList->Add(new (std::nothrow) String(*(const_cast<String*>
1101                         (static_cast<const String*>(directoryList.GetAt(i))))));
1102         }
1103
1104         if (__pContentInfoList != null)
1105         {
1106                 delete __pContentInfoList;
1107                 __pContentInfoList = null;
1108         }
1109
1110         if (GetAppControlMode() == APP_CONTROL_MODE_PICK)
1111         {
1112                 AppControlMediaType appControlMediaType = GetAppControlMediaType();
1113                 if (appControlMediaType == APPCONTROL_MEDIA_TYPE_IMAGE)
1114                 {
1115                         __albumContentType = CONTENT_TYPE_IMAGE;
1116                 }
1117                 else if (appControlMediaType == APPCONTROL_MEDIA_TYPE_VIDEO)
1118                 {
1119                         __albumContentType = CONTENT_TYPE_VIDEO;
1120                 }
1121         }
1122         __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
1123         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1124
1125         return E_SUCCESS;
1126 }
1127
1128 result
1129 FileListPresentationModel::RefreshCurrentAlbumContentInfoList(ContentType contentType)
1130 {
1131         AppLogDebug("ENTER");
1132         result r = RefreshContentInfoList(contentType);
1133         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1134
1135         return r;
1136 }
1137
1138 result
1139 FileListPresentationModel::RefreshContentInfoList(ContentType contentType)
1140 {
1141         AppLogDebug("ENTER");
1142         if ((contentType != CONTENT_TYPE_ALL) && (contentType != CONTENT_TYPE_IMAGE) && (contentType != CONTENT_TYPE_VIDEO))
1143         {
1144                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1145
1146                 return E_FAILURE;
1147         }
1148
1149         if ((__pDirectoryList == null) || (__pDirectoryList->GetCount() <= 0))
1150         {
1151                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1152
1153                 return E_SUCCESS;
1154         }
1155
1156         __albumContentType = contentType;
1157
1158         if (__pContentInfoList != null)
1159         {
1160                 delete __pContentInfoList;
1161                 __pContentInfoList = null;
1162         }
1163         __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
1164         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1165
1166         return E_SUCCESS;
1167 }
1168
1169 String
1170 FileListPresentationModel::GetCurrentAlbumName(void)
1171 {
1172         AppLogDebug("ENTER");
1173         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1174
1175         return __albumName;
1176 }
1177
1178 void
1179 FileListPresentationModel::SetCurrentAlbumName(String& albumName)
1180 {
1181         AppLogDebug("ENTER");
1182         if (&albumName == null)
1183         {
1184                 __albumName = EMPTY_SPACE;
1185         }
1186         else
1187         {
1188                 __albumName = albumName;
1189         }
1190         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1191 }
1192
1193 ContentType
1194 FileListPresentationModel::GetCurrentAlbumContentType(void)
1195 {
1196         AppLogDebug("ENTER");
1197         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1198
1199         return __albumContentType;
1200 }
1201
1202 void
1203 FileListPresentationModel::SetCurrentAlbumContentType(ContentType contentType)
1204 {
1205         AppLogDebug("ENTER");
1206         __albumContentType = contentType;
1207         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1208 }
1209
1210 IList*
1211 FileListPresentationModel::GetAlbumDirectoryListN(void)
1212 {
1213         AppLogDebug("ENTER");
1214         IList* pAlbumDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1215         if (__pDirectoryList == null)
1216         {
1217                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1218
1219                 return pAlbumDirectoryList;
1220         }
1221
1222         String* pDirectory = null;
1223         int loopCount = __pDirectoryList->GetCount();
1224         for (int i = 0; i < loopCount; ++i)
1225         {
1226                 pDirectory = static_cast<String*>(__pDirectoryList->GetAt(i));
1227                 pAlbumDirectoryList->Add(new (std::nothrow) String(*pDirectory));
1228         }
1229         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1230
1231         return pAlbumDirectoryList;
1232 }
1233
1234 IList*
1235 FileListPresentationModel::GetAlbumContentInfoList(void)
1236 {
1237         AppLogDebug("ENTER");
1238         IList* pContentList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1239         if (__pContentInfoList == null)
1240         {
1241                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1242
1243                 return pContentList;
1244         }
1245
1246         ContentInfo* pContentInfo = null;
1247         int loopCount = __pContentInfoList->GetCount();
1248         for (int i = 0; i < loopCount; ++i)
1249         {
1250                 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(i));
1251                 pContentList->Add(pContentInfo);
1252         }
1253         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1254
1255         return pContentList;
1256 }
1257
1258 ContentInfo*
1259 FileListPresentationModel::GetContentInfo(int index)
1260 {
1261         AppLogDebug("ENTER");
1262         if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1263         {
1264                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1265
1266                 return null;
1267         }
1268
1269         if (index < 0 || index >= __pContentInfoList->GetCount())
1270         {
1271                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1272
1273                 return null;
1274         }
1275         ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1276         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1277
1278         return pContentInfo;
1279 }
1280
1281
1282 IList* FileListPresentationModel::GetContentIdListN(const IList& contentInfoList)
1283 {
1284         IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1285         int loopCount = contentInfoList.GetCount();
1286         for (int i = 0; i < loopCount; ++i)
1287         {
1288                 const Integer* pIndex = static_cast<const Integer*>(contentInfoList.GetAt(i));
1289
1290                 if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
1291                 {
1292                         pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
1293                 }
1294         }
1295
1296         return pContentIdList;
1297 }
1298
1299 int
1300 FileListPresentationModel::GetCurrentAlbumContentInfoCount(void)
1301 {
1302         AppLogDebug("ENTER");
1303         if (__pContentInfoList == null)
1304         {
1305                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1306
1307                 return 0;
1308         }
1309         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1310
1311         return __pContentInfoList->GetCount();
1312 }
1313
1314 ContentId
1315 FileListPresentationModel::GetContentInfoIndex(int index)
1316 {
1317         AppLogDebug("ENTER");
1318         if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1319         {
1320                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1321
1322                 return 0;
1323         }
1324
1325         if (index < 0 || index >= __pContentInfoList->GetCount())
1326         {
1327                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1328
1329                 return 0;
1330         }
1331         ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1332         ContentId contentId = pContentInfo->GetContentId();
1333         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1334
1335         return contentId;
1336 }
1337
1338 String
1339 FileListPresentationModel::GetContentFilePath(int index)
1340 {
1341         AppLogDebug("ENTER index(%d)", index);
1342         if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1343         {
1344                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1345
1346                 return EMPTY_SPACE;
1347         }
1348
1349         if (index < 0 || index >= __pContentInfoList->GetCount())
1350         {
1351                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1352
1353                 return EMPTY_SPACE;
1354         }
1355
1356         ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1357         String contentPath = pContentInfo->GetContentPath();
1358         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1359
1360         return contentPath;
1361 }
1362
1363 Bitmap*
1364 FileListPresentationModel::CoverVideoOverlayedImageOnThumbnailN(Bitmap& thumbnail,
1365                 const ThumbnailInfo& thumbmailInfo)
1366 {
1367         AppLogDebug("ENTER");
1368         Bitmap* overlayedImage = null;
1369
1370         if (&thumbmailInfo != null)
1371         {
1372                 long duration = thumbmailInfo.GetDuration();
1373
1374                 Canvas mainCanvas;
1375                 if (&thumbnail != null)
1376                 {
1377                         BufferInfo bufferInfo;
1378                         thumbnail.Lock(bufferInfo, INFINITE);
1379                         thumbnail.Unlock();
1380                         mainCanvas.Construct(bufferInfo);
1381                 }
1382                 else
1383                 {
1384                         Rectangle mainRect(0, 0, W_DEFAULT_THUMBNAIL, H_DEFAULT_THUMBNAIL);
1385                         mainCanvas.Construct(mainRect);
1386                         mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_BLACK), mainRect);
1387                 }
1388
1389                 Rectangle playRect(GAP_W_PLAY_FG, GAP_H_PLAY_FG, W_PLAY_FG, H_PLAY_FG);
1390                 Bitmap* playBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_PLAY);
1391                 if (playBitmap != null)
1392                 {
1393                         mainCanvas.DrawBitmap(playRect, *playBitmap);
1394                         delete playBitmap;
1395                 }
1396
1397                 Canvas durCanvas;
1398                 Rectangle durSize(0, 0, W_DURATION, H_DURATION);
1399                 Rectangle durRect(0, GAP_H_DURATION, W_DURATION, H_DURATION);
1400                 Color durColor(COLOR_DURATION_BG);
1401                 durColor.SetAlpha(ALPHA_DURATION);
1402                 durCanvas.Construct(durSize);
1403                 durCanvas.FillRectangle(durColor, durSize);
1404                 Font durFont;
1405                 durFont.Construct(FONT_STYLE_PLAIN, FONT_SIZE_DURATION);
1406                 durCanvas.SetFont(durFont);
1407                 durCanvas.DrawText(Point(W_DURATION_TEXT, H_DURATION_TEXT), CommonUtil::DurationToTimeString(duration), COLOR_TEXT_OUTLINE);
1408                 Bitmap durBitmap;
1409                 durBitmap.Construct(durCanvas,durCanvas.GetBounds());
1410                 mainCanvas.DrawBitmap(durRect,durBitmap);
1411
1412                 overlayedImage = new (std::nothrow) Bitmap();
1413                 overlayedImage->Construct(mainCanvas,mainCanvas.GetBounds());
1414         }
1415         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1416
1417         return overlayedImage;
1418 }
1419
1420 Bitmap*
1421 FileListPresentationModel::GetShadedBackgroundBitmapN(Bitmap& bgBitmap,
1422                 const Bitmap& orgBitmap,
1423                 const Rectangle& orgBitmapPosition)
1424 {
1425         AppLogDebug("ENTER");
1426         if (&orgBitmap == null || &orgBitmap == null)
1427         {
1428                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1429
1430                 return null;
1431         }
1432
1433         BufferInfo bufferInfo;
1434         bgBitmap.Lock(bufferInfo, INFINITE);
1435         bgBitmap.Unlock();
1436         Canvas mainCanvas;
1437         mainCanvas.Construct(bufferInfo);
1438         mainCanvas.Clear();
1439         mainCanvas.DrawBitmap(orgBitmapPosition, orgBitmap);
1440
1441         Bitmap* pMainImage = new (std::nothrow) Bitmap();
1442         pMainImage->Construct(mainCanvas,mainCanvas.GetBounds());
1443         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1444
1445         return pMainImage;
1446 }
1447
1448 IList*
1449 FileListPresentationModel::GetContentInfoListInDirectoryListN(const IList& contentDirectoryList,
1450                 ContentType contentType)const
1451 {
1452         AppLogDebug("ENTER");
1453         IList* pContentList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1454
1455         if ((&contentDirectoryList == null) || (contentDirectoryList.GetCount() == 0)
1456                         || ((contentType != CONTENT_TYPE_IMAGE) && (contentType != CONTENT_TYPE_VIDEO) && (contentType != CONTENT_TYPE_ALL)))
1457         {
1458                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1459                 return pContentList;
1460         }
1461
1462         ContentDirectory contentDirectory;
1463         IListT<ContentType>* pContentTypeList = new (std::nothrow) ArrayListT<ContentType>();
1464         if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_ALL)
1465         {
1466                 pContentTypeList->Add(CONTENT_TYPE_IMAGE);
1467         }
1468         if (contentType == CONTENT_TYPE_VIDEO || contentType == CONTENT_TYPE_ALL)
1469         {
1470                 pContentTypeList->Add(CONTENT_TYPE_VIDEO);
1471         }
1472         result r = contentDirectory.Construct(*pContentTypeList);
1473         delete pContentTypeList;
1474
1475         if (r == E_SUCCESS)
1476         {
1477                 int pageNo = SIZE_PAGE_NO;
1478                 int countPerPage = SIZE_CONUNT_PER_PAGE;
1479                 String* pContentDirectory = null;
1480
1481                 int loopCount = contentDirectoryList.GetCount();
1482                 for (int i = 0; i < loopCount; ++i)
1483                 {
1484                         IList* pIList = null;
1485                         pContentDirectory = const_cast<String*>(static_cast<const String*>(contentDirectoryList.GetAt(i)));
1486                         if (pContentDirectory != null)
1487                         {
1488                                 pIList = contentDirectory.GetContentDirectoryItemListN(*pContentDirectory, pageNo, countPerPage,
1489                                                 CONTENT_INFO_ORDER, SORT_ORDER_NONE);
1490
1491                                 if (pIList != null)
1492                                 {
1493                                         pContentList->AddItems(*pIList);
1494                                 }
1495                                 else
1496                                 {
1497                                         delete pIList;
1498                                 }
1499                         }
1500                 }
1501         }
1502         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1503
1504         return pContentList;
1505 }
1506
1507 String
1508 FileListPresentationModel::ConvertToAlbumName(const String& targetPath)const
1509 {
1510         AppLogDebug("ENTER");
1511         String albumName;
1512         if (&targetPath == null || targetPath.GetLength() == 0)
1513         {
1514                 return albumName;
1515         }
1516
1517         if (targetPath == RESERVED_CAMERA_PATH || targetPath == RESERVED_CAMERA_PATH_EXT)
1518         {
1519                 albumName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB");
1520         }
1521         else if (targetPath == RESERVED_DOWNLOAD_PATH)
1522         {
1523                 albumName = ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS");
1524         }
1525         else
1526         {
1527                 String directoryName = GetDirecotyNameFromFullPath(targetPath);
1528                 albumName = directoryName;
1529         }
1530
1531         return albumName;
1532 }
1533
1534 AppControlMode
1535 FileListPresentationModel::GetAppControlMode(void) const
1536 {
1537         AppLogDebug("Enter");
1538         AppLogDebug("Exit");
1539
1540         return __appControlMode;
1541 }
1542
1543 AppControlMediaType
1544 FileListPresentationModel::GetAppControlMediaType(void) const
1545 {
1546         AppLogDebug("Enter");
1547         AppLogDebug("Exit");
1548
1549         return __appControlMediaType;
1550 }
1551
1552 AppControlSelectionMode
1553 FileListPresentationModel::GetAppControlSelectionMode(void) const
1554 {
1555         AppLogDebug("Enter");
1556         AppLogDebug("Exit");
1557
1558         return __appControlSelectionMode;
1559 }