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