2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file GlFileListPresentationModel.cpp
19 * @brief This is the implementation file for FileListPresentationModel class.
25 #include "GlCommonUtil.h"
26 #include "GlFileListPresentationModel.h"
27 #include "GlGalleryApp.h"
28 #include "GlThumbnailEvent.h"
29 #include "GlThumbnailEventArg.h"
30 #include "GlThumbnailProvider.h"
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Base::Runtime;
37 using namespace Tizen::Base::Utility;
38 using namespace Tizen::Content;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Io;
41 using namespace Tizen::Media;
42 using namespace Tizen::System;
44 static const String CONTENT_INFO_ORDER = L"ContentFileName";
46 static const int SIZE_PAGE_NO = 1;
47 static const int SIZE_CONUNT_PER_PAGE = 3000;
48 static const int SIZE_ICON_LIST_CACHE = 50;
49 static const int W_DURATION_TEXT = 44;
50 static const int H_DURATION_TEXT = 4;
51 static const int W_DURATION = 171;
52 static const int H_DURATION = 32;
53 static const int W_DEFAULT_THUMBNAIL = 171;
54 static const int H_DEFAULT_THUMBNAIL = 127;
55 static const int W_WIDE_THUMBNAIL = 171;
56 static const int H_WIDE_THUMBNAIL = 127;
57 static const int W_PLAY_FG = 64;
58 static const int H_PLAY_FG = 64;
59 static const int GAP_W_PLAY_FG = (W_DEFAULT_THUMBNAIL -W_PLAY_FG)/2 ;
60 static const int GAP_H_PLAY_FG = (H_DEFAULT_THUMBNAIL - H_PLAY_FG)/2;
61 static const int GAP_H_DURATION = H_DEFAULT_THUMBNAIL - H_DURATION;
62 static const int ALPHA_DURATION = 70;
63 static const int FONT_SIZE_DURATION = 24;
64 static const Dimension DIMENSION_REAL_ICON (171,127);
65 static const Rectangle RECTANGLE_THUMBNAIL_OFFSET_POSION (1, 1, 171, 127);
66 static const Rectangle RECTANGLE_VIDEO_THUMBNAIL_OFFSET_POSION (1, 1, 171, 127);
67 static const Color COLOR_DURATION_BG (Color::GetColor(COLOR_ID_BLACK));
68 static const Color COLOR_TEXT_OUTLINE (Color::GetColor(COLOR_ID_WHITE));
70 static const String RESERVED_CAMERA_PATH = Environment::GetMediaPath() + L"Camera";
71 static const String RESERVED_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera";
72 static const String RESERVED_DOWNLOAD_PATH = Environment::GetMediaPath() + L"Downloads";
74 FileListPresentationModel* FileListPresentationModel::__pPresentationModelInstance = null;
75 ThumbnailProvider* FileListPresentationModel::__pThumbnailProvider = null;
76 ThumbnailEvent* FileListPresentationModel::__pThumbnailEvent = null;
77 ArrayList* FileListPresentationModel::__pPresentationModelListener = null;
78 ArrayList* FileListPresentationModel::__pIconListViewCache = null;
79 IList* FileListPresentationModel::__pDirectoryList = null;
80 IList* FileListPresentationModel::__pContentInfoList = null;
82 FileListPresentationModel::FileListPresentationModel(void)
83 : __albumContentType(CONTENT_TYPE_ALL)
84 , __appControlMode(APP_CONTROL_MODE_MAIN)
85 , __appControlMediaType(APPCONTROL_MEDIA_TYPE_UNKNOWN)
86 , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
89 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
92 FileListPresentationModel::~FileListPresentationModel(void)
95 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
98 FileListPresentationModel*
99 FileListPresentationModel::GetInstance(void)
101 AppLogDebug("ENTER");
102 if (__pPresentationModelInstance == null)
106 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
108 return __pPresentationModelInstance;
112 FileListPresentationModel::Construct(void)
114 AppLogDebug("ENTER");
116 IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
117 __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
118 __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
120 if (__pIconListViewCache != null)
122 delete __pIconListViewCache;
124 __pIconListViewCache = new (std::nothrow) ArrayList(SingleObjectDeleter);
125 __pIconListViewCache->Construct(SIZE_ICON_LIST_CACHE);
127 if (__pDirectoryList != null)
129 delete __pDirectoryList;
131 __pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
133 if (__pContentInfoList != null)
135 delete __pContentInfoList;
137 __pContentInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
139 __pPresentationModelListener = new (std::nothrow) ArrayList();
140 __pPresentationModelListener->Construct();
142 __pThumbnailProvider = ThumbnailProvider::GetInstance();
144 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
145 const IMap* pArguments = pApp->GetAppControlArguments();
146 String operationId = pApp->GetAppControlOperationId();
148 if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
150 __appControlMode = APP_CONTROL_MODE_MAIN;
152 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
154 __appControlMode = APP_CONTROL_MODE_PICK;
156 if (pArguments != null)
158 const String* selectionMode = static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
159 const String* mediaType = static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_MEDIA_TYPE)));
161 if (mediaType != null && mediaType->CompareTo(APPCONTROL_DATA_VIDEO) == 0)
163 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
167 __appControlMediaType = APPCONTROL_MEDIA_TYPE_IMAGE;
170 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
172 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
176 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_SINGLE;
180 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
182 __appControlMode = APP_CONTROL_MODE_SETTING;
185 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
191 FileListPresentationModel::CreateInstance(void)
193 AppLogDebug("ENTER");
194 __pPresentationModelInstance = new (std::nothrow) FileListPresentationModel();
195 result r = __pPresentationModelInstance->Construct();
196 if (IsFailed(r) == true)
198 delete __pPresentationModelInstance;
199 __pPresentationModelInstance = null;
200 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
205 std::atexit(DestroyInstance);
206 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
210 FileListPresentationModel::DestroyInstance(void)
212 AppLogDebug("ENTER");
214 delete __pThumbnailEvent;
215 __pIconListViewCache = null;
217 if (__pIconListViewCache != null)
219 delete __pIconListViewCache;
220 __pIconListViewCache = null;
223 if (__pDirectoryList != null)
225 delete __pDirectoryList;
226 __pDirectoryList = null;
229 if (__pContentInfoList != null)
231 delete __pContentInfoList;
232 __pContentInfoList = null;
235 if (__pPresentationModelListener != null)
237 delete __pPresentationModelListener;
238 __pPresentationModelListener = null;
241 delete __pPresentationModelInstance;
242 __pPresentationModelInstance = null;
244 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
248 FileListPresentationModel::GetFileNameFromFullPath(const String& fullPath, bool withExt) const
250 AppLogDebug("ENTER");
251 if (fullPath.CompareTo(EMPTY_SPACE) == 0)
253 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
258 String delim(DIRECTORY_SEPARATOR);
259 StringTokenizer st(fullPath,delim);
261 while (st.HasMoreTokens())
263 st.GetNextToken(token);
268 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
274 String subDelim(FILE_EXT_SEPARATOR);
275 StringTokenizer subSt(token, subDelim);
277 subSt.GetNextToken(subToken);
278 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
285 FileListPresentationModel::GetDirecotyNameFromFullPath(const String& fullPath)const
287 AppLogDebug("ENTER");
288 if (fullPath == null)
290 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
294 String delim(DIRECTORY_SEPARATOR);
295 StringTokenizer st(fullPath,delim);
297 while (st.HasMoreTokens())
299 st.GetNextToken(token);
301 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
307 FileListPresentationModel::IsContainContentInDirectory(const String& directoryPath, ContentType contentType) const
309 AppLogDebug("ENTER");
310 IListT<ContentType>* pContentTypeList = new (std::nothrow) ArrayListT<ContentType>();
311 if (&directoryPath == null || pContentTypeList == null)
313 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
318 if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_ALL)
320 pContentTypeList->Add(CONTENT_TYPE_IMAGE);
322 if (contentType == CONTENT_TYPE_VIDEO || contentType == CONTENT_TYPE_ALL)
324 pContentTypeList->Add(CONTENT_TYPE_VIDEO);
327 ContentDirectory contentDirectory;
328 result r = contentDirectory.Construct(*pContentTypeList);
329 if (pContentTypeList != null)
331 delete pContentTypeList;
332 pContentTypeList = null;
334 TryReturn(r == E_SUCCESS, false, "[%s] Unable to construct ContentDirectory", GetErrorMessage(r));
336 bool returnValue = false;
337 int pageNo = SIZE_PAGE_NO;
338 int countPerPage = SIZE_CONUNT_PER_PAGE;
340 IList* pContentList = contentDirectory.GetContentDirectoryItemListN(directoryPath, pageNo, countPerPage,
341 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
343 if (pContentList == null || pContentList->GetCount() <= 0)
352 if (pContentList != null)
357 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
363 FileListPresentationModel::GetThumbnailInSyncCacheN(const int index, String*& pName, Bitmap*& pThumbnail)
365 AppLogDebug("ENTER : index(%d)", index);
366 Bitmap* pOrgBitmap = null;
367 Bitmap* pDstBitmap = null;
368 ContentInfo* pContentInfo = null;
370 if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
372 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
373 if (pContentInfo == null)
375 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
382 AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
386 ThumbnailInfo* pThumbnailInfo = GetThumbnailInfoFromInternalBufferN(pContentInfo->GetContentId());
387 if (pThumbnailInfo != null)
389 pName = new (std::nothrow) String(pThumbnailInfo->GetFilePath());
390 pOrgBitmap = pThumbnailInfo->GetBitmapN();
393 if ((pThumbnailInfo != null)&&(pThumbnailInfo->GetContentType() == CONTENT_TYPE_VIDEO))
395 if (pOrgBitmap != null)
397 pDstBitmap = CoverVideoOverlayedImageOnThumbnailN(*pOrgBitmap, *pThumbnailInfo);
404 pDstBitmap = pOrgBitmap;
407 if (pDstBitmap != null)
409 Bitmap* pThumbnailBgBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_BG);
410 Rectangle thumbnailRect(RECTANGLE_THUMBNAIL_OFFSET_POSION);
411 pDstBitmap->Scale(Dimension(RECTANGLE_THUMBNAIL_OFFSET_POSION.width - RECTANGLE_THUMBNAIL_OFFSET_POSION.x
412 , RECTANGLE_THUMBNAIL_OFFSET_POSION.height - RECTANGLE_THUMBNAIL_OFFSET_POSION.y));
413 if (pThumbnailBgBitmap != null)
415 pThumbnailBgBitmap->Scale(DIMENSION_REAL_ICON);
416 pThumbnail = GetShadedBackgroundBitmapN(*pThumbnailBgBitmap, *pDstBitmap, thumbnailRect);
417 delete pThumbnailBgBitmap;
418 pThumbnailBgBitmap = null;
424 pThumbnail = pDstBitmap;
432 if (pThumbnailInfo != null)
434 delete pThumbnailInfo;
435 pThumbnailInfo = null;
437 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
443 FileListPresentationModel::GetThumbnailVideoInSyncCacheN(const int index, String*& pName, Bitmap*& pThumbnail, String*& pDuration)
445 AppLogDebug("ENTER : index(%d)", index);
446 ContentInfo* pContentInfo = null;
447 Bitmap* pOrgBitmap = null;
449 if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
451 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
452 if (pContentInfo == null)
454 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
460 AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
464 ThumbnailInfo* pThumbnailInfo = GetThumbnailInfoFromInternalBufferN(pContentInfo->GetContentId());
465 if (pThumbnailInfo != null)
467 pName = new (std::nothrow) String(pThumbnailInfo->GetFilePath());
468 pOrgBitmap = pThumbnailInfo->GetBitmapN();
469 pDuration = new (std::nothrow) String(CommonUtil::DurationToTimeString(pThumbnailInfo->GetDuration()));
473 pName = new (std::nothrow) String(EMPTY_SPACE);
474 pDuration = new (std::nothrow) String(CommonUtil::DurationToTimeString(0));
477 if (pOrgBitmap != null)
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)
485 pThumbnailBgBitmap->Scale(Dimension(W_WIDE_THUMBNAIL, H_WIDE_THUMBNAIL));
486 pThumbnail = GetShadedBackgroundBitmapN(*pThumbnailBgBitmap, *pOrgBitmap, thumbnailRect);
487 delete pThumbnailBgBitmap;
488 pThumbnailBgBitmap = null;
498 if (pThumbnail != null)
500 pThumbnail->Scale(Dimension(W_WIDE_THUMBNAIL, H_WIDE_THUMBNAIL));
503 if (pThumbnailInfo != null)
505 delete pThumbnailInfo;
506 pThumbnailInfo = null;
508 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
514 FileListPresentationModel::RequestThumbnail(const int index)
516 AppLogDebug("ENTER : index(%d)", index);
517 ContentInfo* pContentInfo = null;
519 if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
521 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
522 if (pContentInfo == null)
524 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
530 AppLogDebug("EXIT 2 __pContentInfoList(%x) index(%d)", __pContentInfoList, index);
535 __pThumbnailProvider->RequestThumbnail(pContentInfo->GetContentId(), __pThumbnailEvent);
540 FileListPresentationModel::CancelThumbnailRequest(const int index)
542 AppLogDebug("ENTER : index(%d)", index);
543 /*ContentInfo* pContentInfo = null;
545 if (__pContentInfoList != null && index < __pContentInfoList->GetCount())
547 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
548 if (pContentInfo == null)
550 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
553 __pThumbnailProvider->CancelThumbnailRequest(pContentInfo->GetContentId(), __pThumbnailEvent);
559 FileListPresentationModel::ClearThumbnailRequests(bool appTerminating)
561 AppLogDebug("ENTER");
563 if (__pThumbnailProvider != null)
565 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
572 FileListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
574 AppLogDebug("ENTER");
576 if (&eventArg != null)
578 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
579 if (pThumbnailEventArg == null)
581 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
585 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
586 if (pThumbnailInfo == null)
588 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
593 bool isMatch = false;
594 ContentId contentId = pThumbnailInfo->GetContentId();
596 if (__pIconListViewCache != null)
598 IEnumerator* pEnum = __pIconListViewCache->GetEnumeratorN();
599 Bitmap* pBitmap = null;
600 while (pEnum->MoveNext() == E_SUCCESS)
602 ThumbnailInfo* pTempThumbnailInfo = static_cast<ThumbnailInfo*>(pEnum->GetCurrent());
604 if (contentId == pTempThumbnailInfo->GetContentId())
606 AppLogDebug("[CHASEFIRE] PM receive (%ls)", pThumbnailInfo->GetFilePath().GetPointer());
607 pBitmap = pThumbnailInfo->GetBitmapN();
608 pTempThumbnailInfo->SetBitmap(*pBitmap);
611 pTempThumbnailInfo->SetContentType(pThumbnailInfo->GetContentType());
612 pTempThumbnailInfo->SetDuration(pThumbnailInfo->GetDuration());
613 delete pThumbnailInfo;
614 pThumbnailInfo = null;
620 if (isMatch == false)
622 if (SIZE_ICON_LIST_CACHE <= __pIconListViewCache->GetCount())
624 __pIconListViewCache->RemoveAt(0, true);
626 AppLogDebug("[CHASEFIRE] (all:%d) Add Thumbail(%ls)",__pIconListViewCache->GetCount(),
627 pThumbnailInfo->GetFilePath().GetPointer());
628 __pIconListViewCache->Add(pThumbnailInfo);
633 int loopCount = __pContentInfoList->GetCount();
634 for (int i = 0; i < loopCount; ++i)
636 if (contentId == (static_cast<ContentInfo*>(__pContentInfoList->GetAt(i)))->GetContentId())
643 IAlbumEventListener* pInterface = null;
644 IEnumerator* pEventEnum = __pPresentationModelListener->GetEnumeratorN();
645 while (pEventEnum->MoveNext() == E_SUCCESS)
647 pInterface = static_cast<IAlbumEventListener*>(pEventEnum->GetCurrent());
648 pInterface->OnThumbnailDecoded(index);
653 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
657 FileListPresentationModel::AddPresentationModelListener(const IAlbumEventListener* listener)
659 AppLogDebug("ENTER");
660 __pPresentationModelListener->Add((Object*)listener);
661 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
665 FileListPresentationModel::RemovePresentationModelListener(const IAlbumEventListener& listener)
667 AppLogDebug("ENTER");
668 __pPresentationModelListener->Remove(listener);
669 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
673 FileListPresentationModel::GetThumbnailInfoFromInternalBufferN(const ContentId& contentId) const
675 AppLogDebug("ENTER");
676 ThumbnailInfo* pThumbnailInfo = null;
677 ThumbnailInfo* pTempThumbnailInfo = null;
678 if (__pIconListViewCache != null)
680 int loopCount = __pIconListViewCache->GetCount();
681 for (int i = 0 ; i < loopCount; ++i)
683 pTempThumbnailInfo = static_cast<ThumbnailInfo*>(__pIconListViewCache->GetAt(i));
684 if (contentId == pTempThumbnailInfo->GetContentId())
687 pThumbnailInfo = new (std::nothrow) ThumbnailInfo();
688 Bitmap* pBitmap = pTempThumbnailInfo->GetBitmapN();
689 pThumbnailInfo->Construct(pTempThumbnailInfo->GetContentId(),
690 pTempThumbnailInfo->GetFilePath(), *pBitmap,
691 pTempThumbnailInfo->GetContentType(), pTempThumbnailInfo->GetDuration());
697 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
699 return pThumbnailInfo;
703 FileListPresentationModel::DeleteContentFileList(const IList& contentIndexList)
705 AppLogDebug("ENTER");
706 if (&contentIndexList == null || contentIndexList.GetCount() <= 0)
708 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
713 IList * pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
714 int loopCount = contentIndexList.GetCount();
715 for (int i = 0; i < loopCount; ++i)
717 const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
719 if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
721 pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>
722 (__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
726 loopCount = pContentIdList->GetCount();
727 for (int i = 0; i < loopCount; ++i)
729 ContentId* pContentId = static_cast<ContentId*>(pContentIdList->GetAt(i));
730 if (pContentId != null)
732 DeleteContentFile(*pContentId);
735 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
741 FileListPresentationModel::GetCollisionIndexListN(const IList& contentIndexList, const String& destDirectory)
743 AppLogDebug("ENTER");
744 if (&contentIndexList == null || contentIndexList.GetCount() <= 0 || &destDirectory == null
745 || destDirectory.IsEmpty() == true)
747 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
752 if (File::IsFileExist(destDirectory) == false)
754 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
759 IList * pCollisionInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
760 ContentInfo* pContentInfo = null;
761 int loopCount = contentIndexList.GetCount();
762 for (int i = 0; i < loopCount; ++i)
764 const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
766 if ((pIndex != null) && (pIndex->ToInt()) >= 0 && __pContentInfoList->GetCount() > pIndex->ToInt())
768 pContentInfo = const_cast<ContentInfo*>(static_cast<const ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())));
769 String filePath = pContentInfo->GetContentPath();
770 String fileName = GetFileNameFromFullPath(filePath, true);
773 if (destDirectory.EndsWith(DIRECTORY_SEPARATOR) == true)
775 destPath.Append(destDirectory);
776 destPath.Append(fileName);
780 destPath.Append(destDirectory);
781 destPath.Append(DIRECTORY_SEPARATOR);
782 destPath.Append(fileName);
785 if (File::IsFileExist(destPath) == true)
787 pCollisionInfoList->Add(*(new (std::nothrow) String(pIndex->ToString() + MULTI_ITEM_SEPARATOR + fileName)));
791 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
793 return pCollisionInfoList;
797 FileListPresentationModel::MoveToContentFileList(const IList& contentIndexList, const String& destDirectory)
799 AppLogDebug("ENTER");
800 result r = E_SUCCESS;
801 if (&contentIndexList == null || contentIndexList.GetCount() <= 0 || &destDirectory == null || destDirectory.IsEmpty() == true)
803 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
808 if (File::IsFileExist(destDirectory) == false)
810 Directory::Create(destDirectory, true);
813 delete __pContentIdList;
814 __pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
815 int loopCount = contentIndexList.GetCount();
816 for (int i = 0; i < loopCount; ++i)
818 const Integer* pIndex = static_cast<const Integer*>(contentIndexList.GetAt(i));
820 if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
822 __pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
827 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
833 FileListPresentationModel::DeleteContentFile(const ContentId& contentId)
835 AppLogDebug("ENTER");
836 if (&contentId == null)
838 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
842 ContentManager contentManager;
843 result r = contentManager.Construct();
846 r = contentManager.DeleteContent(contentId);
848 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
854 FileListPresentationModel::MoveToContentFile(const ContentId& contentId, const String& destDirectory)
856 AppLogDebug("ENTER");
857 if (contentId.ToString().IsEmpty() == true || destDirectory.IsEmpty() == true)
859 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
863 ContentManager contentManager;
864 result r = contentManager.Construct();
867 ContentInfo* pContentInfo = contentManager.GetContentInfoN(contentId);
868 if (pContentInfo == null)
870 AppLogDebug("Santhosh %s", destDirectory.GetPointer());
871 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
875 String filePath = pContentInfo->GetContentPath();
876 if (filePath.GetLength() < 4)
878 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
884 if (destDirectory.EndsWith(DIRECTORY_SEPARATOR) == true)
886 destPath.Append(destDirectory);
887 destPath.Append(GetFileNameFromFullPath(filePath, true));
891 destPath.Append(destDirectory);
892 destPath.Append(DIRECTORY_SEPARATOR);
893 destPath.Append(GetFileNameFromFullPath(filePath, true));
896 if (destPath.CompareTo(filePath) == 0)
898 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
903 if (File::IsFileExist(destPath) == true)
905 File::Remove(destPath);
908 if (pContentInfo->GetContentType() == CONTENT_TYPE_IMAGE)
911 r = File::Copy(filePath, destPath, false);
914 ContentManager cntManager;
915 r = cntManager.Construct();
918 ImageContentInfo contentInfo;
919 r = contentInfo.Construct(&destPath);
922 cntManager.CreateContent(contentInfo);
924 TryCatch(!IsFailed(r),,"CreateContent::the value is %s",GetErrorMessage(r));
925 r = cntManager.DeleteContent(contentId);
926 TryCatch(!IsFailed(r),,"DeleteContent::the value is %s",GetErrorMessage(r));
931 else if (pContentInfo->GetContentType() == CONTENT_TYPE_VIDEO)
933 r = File::Copy(filePath, destPath, false);
937 ContentManager cntManager;
938 r = cntManager.Construct();
941 VideoContentInfo contentInfo;
942 r = contentInfo.Construct(&destPath);
944 cntManager.CreateContent(contentInfo);
946 TryCatch(!IsFailed(r),,"CreateContent::the value is %s",GetErrorMessage(r));
947 r = cntManager.DeleteContent(contentId);
948 TryCatch(!IsFailed(r),,"DeleteContent::the value is %s",GetErrorMessage(r));
957 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
963 FileListPresentationModel::StartAppControl( const String& providerId, const String& operationId,
964 const IMap* pDataList, IAppControlResponseListener* pListener)
966 AppLogDebug("ENTER");
967 AppLogDebug("FindAppControlN(%ls, %ls)", providerId.GetPointer(), operationId.GetPointer());
968 if (pDataList != null)
970 IList* pKeyList = pDataList->GetKeysN();
971 if (pKeyList != null)
973 int keyCount = pKeyList->GetCount();
974 for (int i = 0 ; i < keyCount ; ++i)
976 String* pKey = const_cast<String*>(static_cast<const String*>(pKeyList->GetAt(i)));
977 String* pValue = const_cast<String*>(static_cast<const String*>(pDataList->GetValue(*pKey)));
979 AppLogDebug("(%ls:%ls)", pKey == null ? L"(null)" : pKey->GetPointer(),
980 pValue == null ? L"(null)" : pValue->GetPointer());
984 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
987 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
991 result r = pAc->Start(null, null, pDataList, pListener);
995 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
996 pGalleryApp->SetFrameEnabled(false);
1001 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1007 FileListPresentationModel::SetCurrentAlbumInfo(const String& albumName, const IList& directoryList)
1009 AppLogDebug("ENTER");
1011 if (&directoryList != null)
1013 if (__pDirectoryList != null && __pDirectoryList->GetCount() > 0)
1015 bool isMatched = false;
1016 int outterLoopCount = __pDirectoryList->GetCount();
1017 int innerLoopCount = 0;
1018 for (int i = 0; i < outterLoopCount ; ++i)
1021 innerLoopCount = directoryList.GetCount();
1022 for (int j = 0; j < innerLoopCount; ++j)
1024 if (static_cast<String*>(__pDirectoryList->GetAt(i))->CompareTo(
1025 *(const_cast<String*>(static_cast<const String*>(directoryList.GetAt(j))))) == 0)
1033 outterLoopCount = directoryList.GetCount();
1034 for (int i = 0; i < outterLoopCount; ++i)
1037 innerLoopCount = __pDirectoryList->GetCount();
1038 for (int j = 0; j < innerLoopCount; ++j)
1040 if (const_cast<String*>(static_cast<const String*>(directoryList.GetAt(i)))->CompareTo(
1041 *(static_cast<String*>(__pDirectoryList->GetAt(j)))) == 0)
1051 __albumName = albumName;
1053 if (__pDirectoryList != null)
1055 delete __pDirectoryList;
1057 __pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1059 int loopCount = directoryList.GetCount();
1060 for (int i = 0; i < loopCount; ++i)
1062 __pDirectoryList->Add(new (std::nothrow) String(*(const_cast<String*>
1063 (static_cast<const String*>(directoryList.GetAt(i))))));
1066 if (__pContentInfoList != null)
1068 delete __pContentInfoList;
1069 __pContentInfoList = null;
1072 if (GetAppControlMode() == APP_CONTROL_MODE_PICK)
1074 AppControlMediaType appControlMediaType = GetAppControlMediaType();
1075 if (appControlMediaType == APPCONTROL_MEDIA_TYPE_IMAGE)
1077 __albumContentType = CONTENT_TYPE_IMAGE;
1079 else if (appControlMediaType == APPCONTROL_MEDIA_TYPE_VIDEO)
1081 __albumContentType = CONTENT_TYPE_VIDEO;
1084 __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
1085 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1091 FileListPresentationModel::RefreshCurrentAlbumContentInfoList(ContentType contentType)
1093 AppLogDebug("ENTER");
1094 result r = RefreshContentInfoList(contentType);
1095 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1101 FileListPresentationModel::RefreshContentInfoList(ContentType contentType)
1103 AppLogDebug("ENTER");
1104 if ((contentType != CONTENT_TYPE_ALL) && (contentType != CONTENT_TYPE_IMAGE) && (contentType != CONTENT_TYPE_VIDEO))
1106 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1111 if ((__pDirectoryList == null) || (__pDirectoryList->GetCount() <= 0))
1113 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1118 __albumContentType = contentType;
1120 if (__pContentInfoList != null)
1122 delete __pContentInfoList;
1123 __pContentInfoList = null;
1125 __pContentInfoList = GetContentInfoListInDirectoryListN(*__pDirectoryList, __albumContentType);
1126 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1132 FileListPresentationModel::GetCurrentAlbumName(void)
1134 AppLogDebug("ENTER");
1135 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1141 FileListPresentationModel::SetCurrentAlbumName(String& albumName)
1143 AppLogDebug("ENTER");
1144 if (&albumName == null)
1146 __albumName = EMPTY_SPACE;
1150 __albumName = albumName;
1152 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1156 FileListPresentationModel::GetCurrentAlbumContentType(void)
1158 AppLogDebug("ENTER");
1159 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1161 return __albumContentType;
1165 FileListPresentationModel::SetCurrentAlbumContentType(ContentType contentType)
1167 AppLogDebug("ENTER");
1168 __albumContentType = contentType;
1169 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1173 FileListPresentationModel::GetAlbumDirectoryListN(void)
1175 AppLogDebug("ENTER");
1176 IList* pAlbumDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1177 if (__pDirectoryList == null)
1179 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1181 return pAlbumDirectoryList;
1184 String* pDirectory = null;
1185 int loopCount = __pDirectoryList->GetCount();
1186 for (int i = 0; i < loopCount; ++i)
1188 pDirectory = static_cast<String*>(__pDirectoryList->GetAt(i));
1189 pAlbumDirectoryList->Add(new (std::nothrow) String(*pDirectory));
1191 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1193 return pAlbumDirectoryList;
1197 FileListPresentationModel::GetAlbumContentInfoList(void)
1199 AppLogDebug("ENTER");
1200 IList* pContentList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1201 if (__pContentInfoList == null)
1203 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1205 return pContentList;
1208 ContentInfo* pContentInfo = null;
1209 int loopCount = __pContentInfoList->GetCount();
1210 for (int i = 0; i < loopCount; ++i)
1212 pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(i));
1213 pContentList->Add(pContentInfo);
1215 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1217 return pContentList;
1221 FileListPresentationModel::GetContentInfo(int index)
1223 AppLogDebug("ENTER");
1224 if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1226 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1231 if (index < 0 || index >= __pContentInfoList->GetCount())
1233 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1237 ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1238 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1240 return pContentInfo;
1244 IList* FileListPresentationModel::GetContentIdListN(const IList& contentInfoList)
1246 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1247 int loopCount = contentInfoList.GetCount();
1248 for (int i = 0; i < loopCount; ++i)
1250 const Integer* pIndex = static_cast<const Integer*>(contentInfoList.GetAt(i));
1252 if ((pIndex != null) && (pIndex->ToInt())>=0 && __pContentInfoList->GetCount() > pIndex->ToInt())
1254 pContentIdList->Add(new (std::nothrow) ContentId((static_cast<ContentInfo*>(__pContentInfoList->GetAt(pIndex->ToInt())))->GetContentId()));
1258 return pContentIdList;
1262 FileListPresentationModel::GetCurrentAlbumContentInfoCount(void)
1264 AppLogDebug("ENTER");
1265 if (__pContentInfoList == null)
1267 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1271 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1273 return __pContentInfoList->GetCount();
1277 FileListPresentationModel::GetContentInfoIndex(int index)
1279 AppLogDebug("ENTER");
1280 if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1282 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1287 if (index < 0 || index >= __pContentInfoList->GetCount())
1289 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1293 ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1294 ContentId contentId = pContentInfo->GetContentId();
1295 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1301 FileListPresentationModel::GetContentFilePath(int index)
1303 AppLogDebug("ENTER index(%d)", index);
1304 if (__pContentInfoList == null || __pContentInfoList->GetCount() == 0)
1306 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1311 if (index < 0 || index >= __pContentInfoList->GetCount())
1313 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1318 ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentInfoList->GetAt(index));
1319 String contentPath = pContentInfo->GetContentPath();
1320 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1326 FileListPresentationModel::CoverVideoOverlayedImageOnThumbnailN(Bitmap& thumbnail,
1327 const ThumbnailInfo& thumbmailInfo)
1329 AppLogDebug("ENTER");
1330 Bitmap* overlayedImage = null;
1332 if (&thumbmailInfo != null)
1334 long duration = thumbmailInfo.GetDuration();
1337 if (&thumbnail != null)
1339 BufferInfo bufferInfo;
1340 thumbnail.Lock(bufferInfo, INFINITE);
1342 mainCanvas.Construct(bufferInfo);
1346 Rectangle mainRect(0, 0, W_DEFAULT_THUMBNAIL, H_DEFAULT_THUMBNAIL);
1347 mainCanvas.Construct(mainRect);
1348 mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_BLACK), mainRect);
1351 Rectangle playRect(GAP_W_PLAY_FG, GAP_H_PLAY_FG, W_PLAY_FG, H_PLAY_FG);
1352 Bitmap* playBitmap = ResourceManager::GetBitmapN(IDB_VIDEOTHUMBNAIL_PLAY);
1353 if (playBitmap != null)
1355 mainCanvas.DrawBitmap(playRect, *playBitmap);
1361 Rectangle durSize(0, 0, W_DURATION, H_DURATION);
1362 Rectangle durRect(0, GAP_H_DURATION, W_DURATION, H_DURATION);
1363 Color durColor(COLOR_DURATION_BG);
1364 durColor.SetAlpha(ALPHA_DURATION);
1365 durCanvas.Construct(durSize);
1366 durCanvas.FillRectangle(durColor, durSize);
1368 durFont.Construct(FONT_STYLE_PLAIN, FONT_SIZE_DURATION);
1369 durCanvas.SetFont(durFont);
1370 durCanvas.DrawText(Point(W_DURATION_TEXT, H_DURATION_TEXT), CommonUtil::DurationToTimeString(duration), COLOR_TEXT_OUTLINE);
1372 durBitmap.Construct(durCanvas,durCanvas.GetBounds());
1373 mainCanvas.DrawBitmap(durRect,durBitmap);
1375 overlayedImage = new (std::nothrow) Bitmap();
1376 overlayedImage->Construct(mainCanvas,mainCanvas.GetBounds());
1378 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1380 return overlayedImage;
1384 FileListPresentationModel::GetShadedBackgroundBitmapN(Bitmap& bgBitmap,
1385 const Bitmap& orgBitmap,
1386 const Rectangle& orgBitmapPosition)
1388 AppLogDebug("ENTER");
1389 if (&orgBitmap == null || &orgBitmap == null)
1391 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1396 BufferInfo bufferInfo;
1397 bgBitmap.Lock(bufferInfo, INFINITE);
1400 mainCanvas.Construct(bufferInfo);
1402 mainCanvas.DrawBitmap(orgBitmapPosition, orgBitmap);
1404 Bitmap* pMainImage = new (std::nothrow) Bitmap();
1405 pMainImage->Construct(mainCanvas,mainCanvas.GetBounds());
1406 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1412 FileListPresentationModel::GetContentInfoListInDirectoryListN(const IList& contentDirectoryList,
1413 ContentType contentType)const
1415 AppLogDebug("ENTER");
1416 IList* pContentList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1418 if ((&contentDirectoryList == null) || (contentDirectoryList.GetCount() == 0)
1419 || ((contentType != CONTENT_TYPE_IMAGE) && (contentType != CONTENT_TYPE_VIDEO) && (contentType != CONTENT_TYPE_ALL)))
1421 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1422 return pContentList;
1425 ContentDirectory contentDirectory;
1426 IListT<ContentType>* pContentTypeList = new (std::nothrow) ArrayListT<ContentType>();
1427 if (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_ALL)
1429 pContentTypeList->Add(CONTENT_TYPE_IMAGE);
1431 if (contentType == CONTENT_TYPE_VIDEO || contentType == CONTENT_TYPE_ALL)
1433 pContentTypeList->Add(CONTENT_TYPE_VIDEO);
1435 result r = contentDirectory.Construct(*pContentTypeList);
1436 delete pContentTypeList;
1440 int pageNo = SIZE_PAGE_NO;
1441 int countPerPage = SIZE_CONUNT_PER_PAGE;
1442 String* pContentDirectory = null;
1444 int loopCount = contentDirectoryList.GetCount();
1445 for (int i = 0; i < loopCount; ++i)
1447 IList* pIList = null;
1448 pContentDirectory = const_cast<String*>(static_cast<const String*>(contentDirectoryList.GetAt(i)));
1449 if (pContentDirectory != null)
1451 pIList = contentDirectory.GetContentDirectoryItemListN(*pContentDirectory, pageNo, countPerPage,
1452 CONTENT_INFO_ORDER, SORT_ORDER_NONE);
1456 pContentList->AddItems(*pIList);
1465 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1467 return pContentList;
1471 FileListPresentationModel::ConvertToAlbumName(const String& targetPath)const
1473 AppLogDebug("ENTER");
1475 if (&targetPath == null || targetPath.GetLength() == 0)
1480 if (targetPath == RESERVED_CAMERA_PATH || targetPath == RESERVED_CAMERA_PATH_EXT)
1482 albumName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB");
1484 else if (targetPath == RESERVED_DOWNLOAD_PATH)
1486 albumName = ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS");
1490 String directoryName = GetDirecotyNameFromFullPath(targetPath);
1491 albumName = directoryName;
1498 FileListPresentationModel::GetAppControlMode(void) const
1500 AppLogDebug("Enter");
1501 AppLogDebug("Exit");
1503 return __appControlMode;
1507 FileListPresentationModel::GetAppControlMediaType(void) const
1509 AppLogDebug("Enter");
1510 AppLogDebug("Exit");
1512 return __appControlMediaType;
1515 AppControlSelectionMode
1516 FileListPresentationModel::GetAppControlSelectionMode(void) const
1518 AppLogDebug("Enter");
1519 AppLogDebug("Exit");
1521 return __appControlSelectionMode;