2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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 GlAlbumListPresentationModel.cpp
19 * @brief This is the implementation file for AlbumListPresentationModel class.
26 #include "GlAlbumInfo.h"
27 #include "GlAlbumListPresentationModel.h"
28 #include "GlAlbumRenameEventListener.h"
29 #include "GlContentUpdateEventListener.h"
30 #include "GlFileListPresentationModel.h"
31 #include "GlGalleryApp.h"
32 #include "GlThumbnailEvent.h"
33 #include "GlThumbnailEventArg.h"
34 #include "GlThumbnailProvider.h"
35 #include "GlTimerScanDirListener.h"
37 using namespace Tizen::App;
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Base::Runtime;
41 using namespace Tizen::Base::Utility;
42 using namespace Tizen::Content;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Io;
45 using namespace Tizen::Media;
46 using namespace Tizen::System;
47 using namespace Tizen::Ui::Controls;
49 static const int ICON_CAP = 3;
50 static const int FOLDER_CAP = 8;
51 static const int ICON_SIZE = 107;
52 static const int FOLDER_SIZE_WIDTH = 348;
53 static const int FOLDER_SIZE_HEIGHT = 348;
55 static const int CANVAS_HEIGHT = 71;
56 static const int CANVAS_WIDTH = 326;
58 static const int FONT_SIZE_FOLDER_NAME = 32;
59 static const int FONT_SIZE_FOLDER_DATE = 25;
60 static const int FONT_SIZE_FOLDER_COUNT = 45;
61 static const int FONT_SIZE_FOLDER_COUNT_SMALL = 35;
63 static const int CANVAS_IMAGE_FOLDER_HEIGHT = 48;
64 static const int CANVAS_IMAGE_FOLDER_WIDTH = 48;
65 static const int IMAGE_COUNT_WIDTH = 100;
66 static const int IMAGE_COUNT_HEIGHT = 60;
67 static const int CANVAS_MARGIN_LEFT = 10;
68 static const int GAP = 10;
69 static const int HEIGHT_OFFSET = 5;
70 static const int Y_POS_CANVAS = 260;
71 static const int FOLDER_NAME_WIDTH = 165;
72 static const int FOLDER_NAME_HEIGHT = 38;
75 static const int ALPHA_BG = 110;
77 static const Color COLOR_CANVAS_BG (Color::GetColor(COLOR_ID_BLACK));
79 static const String RESERVED_MEDIA_PATH = Environment::GetMediaPath();
80 static const String RESERVED_CAMERA_PATH = Environment::GetMediaPath() + L"Camera";
81 static const String RESERVED_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera";
82 static const String RESERVED_DOWNLOAD_PATH = Environment::GetMediaPath() + L"Downloads";
83 static const String DATE_TIME = L"DateTime";
85 static const int FORMAT_BUFFER_SIZE = 256;
87 static const int DOUBLE_NUMBER = 2;
88 static const int TRIPLE_NUMBER = 3;
90 AlbumListPresentationModel* AlbumListPresentationModel::__pPresentationModelInstance = null;
91 ArrayList* AlbumListPresentationModel::__pPresentationModelListener = null;
92 ArrayList* AlbumListPresentationModel::__pContentEventListener = null;
93 ThumbnailProvider* AlbumListPresentationModel::__pThumbnailProvider = null;
94 ThumbnailEvent* AlbumListPresentationModel::__pThumbnailEvent = null;
95 IList* AlbumListPresentationModel::__pAlbumInfoList = null;
97 AlbumListPresentationModel::AlbumListPresentationModel(void)
98 : __pFolderBackgroundBitmap(null)
99 , __pAlbumListener(null)
100 , __appControlMode(APPCONTROL_MODE_MAIN)
101 , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
102 , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
103 , __updateProgressStatus(false)
104 , __pTimerScanListener(null)
107 AppLogDebug("ENTER");
108 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
111 AlbumListPresentationModel::~AlbumListPresentationModel(void)
113 AppLogDebug("ENTER");
114 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
115 delete __pFolderBackgroundBitmap;
116 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
119 AlbumListPresentationModel*
120 AlbumListPresentationModel::GetInstance(void)
122 AppLogDebug("ENTER");
123 if (__pPresentationModelInstance == null)
127 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
129 return __pPresentationModelInstance;
133 AlbumListPresentationModel::Construct(void)
135 AppLogDebug("ENTER");
136 __pPresentationModelListener = new (std::nothrow) ArrayList();
137 __pPresentationModelListener->Construct();
139 ContentUpdateEventListener::GetInstance();
140 __pContentEventListener = new (std::nothrow) ArrayList();
141 __pContentEventListener->Construct();
143 IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
144 __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
145 __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
147 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
149 __pThumbnailProvider = ThumbnailProvider::GetInstance();
150 AppLogDebug("ENTER1");
151 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
152 const IMap* pArguments = pApp->GetAppControlArguments();
153 String operationId = pApp->GetAppControlOperationId();
155 if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
157 __appControlMode = APPCONTROL_MODE_MAIN;
159 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
161 __appControlMode = APPCONTROL_MODE_PICK;
163 String mimeType = pApp->GetMimeType();
164 if (mimeType.IsEmpty() != true)
166 if (mimeType.StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
168 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
171 if (pArguments != null)
173 const String* selectionMode =
174 static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
175 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
177 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
181 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
183 __appControlMode = APPCONTROL_MODE_SETTING;
186 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
192 AlbumListPresentationModel::CreateInstance(void)
194 AppLogDebug("ENTER");
195 __pPresentationModelInstance = new (std::nothrow) AlbumListPresentationModel;
196 result r = __pPresentationModelInstance->Construct();
198 if (IsFailed(r) == true)
200 delete __pPresentationModelInstance;
201 __pPresentationModelInstance = null;
202 AppLogDebug("EXIT false");
205 std::atexit(DestroyInstance);
206 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
210 AlbumListPresentationModel::DestroyInstance(void)
212 AppLogDebug("ENTER");
214 delete __pThumbnailEvent;
215 __pThumbnailEvent = null;
217 if (__pAlbumInfoList != null)
219 delete __pAlbumInfoList;
220 __pAlbumInfoList = null;
223 if (__pPresentationModelListener != null)
225 delete __pPresentationModelListener;
226 __pPresentationModelListener = null;
229 if (__pContentEventListener != null)
231 delete __pContentEventListener;
232 __pContentEventListener = null;
235 delete __pPresentationModelInstance;
236 __pPresentationModelInstance = null;
238 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
242 AlbumListPresentationModel::AddPresentationModelListener(IAlbumEventListener* listener)
244 AppLogDebug("ENTER");
245 result r = __pPresentationModelListener->Add(listener);
246 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
252 AlbumListPresentationModel::RemovePresentationModelListener(IAlbumEventListener& listner)
254 AppLogDebug("ENTER");
255 result r = __pPresentationModelListener->Remove(listner);
256 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
262 AlbumListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
264 AppLogDebug("ENTER");
265 if (__pContentEventListener != null)
267 __pContentEventListener->RemoveAll();
268 __pContentEventListener->Add((Object*)listener);
269 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
274 AlbumListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener& listener)
276 AppLogDebug("ENTER");
277 __pContentEventListener->Remove(listener);
278 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
282 AlbumListPresentationModel::CallAlbumChangedEvent(void)
284 AppLogDebug("ENTER");
285 if (__pPresentationModelListener->GetCount() > 0)
287 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
289 while (pEnum->MoveNext() == E_SUCCESS)
291 IAlbumEventListener* pListener = null;
292 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
293 pListener->OnFileInfoChanged(CONTENT_TYPE_ALL);
298 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
302 AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& newPath,
303 IAlbumRenameEventListener* pAlbumListener)
305 AppLogDebug("ENTER");
306 result r = Directory::Rename(orgPath, newPath);
309 AppLogDebug("Album Rename failed(%s)", GetErrorMessage(r));
313 __pAlbumListener = pAlbumListener;
314 __renameNewPath = newPath;
\r
315 r = ContentManager::ScanDirectory(newPath, true, NULL, __reqId);
\r
316 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
317 r = ContentManager::ScanDirectory(orgPath, true, NULL, __reqId);
\r
318 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
325 AlbumListPresentationModel::ShowAnimation(void)
327 IFormContentUpdateEventListener* pInterface = null;
328 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
329 while (pEventEnum->MoveNext() == E_SUCCESS)
331 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
332 pInterface->ShowAnimation();
338 AlbumListPresentationModel::StopAnimation(void)
340 IFormContentUpdateEventListener* pInterface = null;
341 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
342 while (pEventEnum->MoveNext() == E_SUCCESS)
344 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
345 pInterface->StopAnimation();
351 AlbumListPresentationModel::AddTimerScanListener(ITimerScanDirListener* pListener, int scanCount)
353 __pTimerScanListener = pListener;
354 __scanCount = scanCount;
358 AlbumListPresentationModel::RemoveTimerScanListener(void)
360 __pTimerScanListener = null;
365 AlbumListPresentationModel::OnContentScanCompleted (const Tizen::Base::String &scanPath)
\r
367 AppLogDebug("ENTER");
\r
368 if (__pTimerScanListener)
371 if ( __scanCount == 0 )
373 __pTimerScanListener->OnTimerScanDirComplete();
377 if (__pAlbumListener && ( scanPath == __renameNewPath))
\r
379 InitializeAlbumInfoList(CONTENT_TYPE_ALL);
380 __pAlbumListener->OnAlbumRenameComplete();
381 __renameNewPath = L"";
390 AlbumListPresentationModel::DrawPartialImage(Canvas& canvas, AlbumInfo* pAlbumInfo, const Rectangle& rectNew)
392 AppLogDebug("ENTER");
393 if (&canvas == null || __pFolderBackgroundBitmap == null || pAlbumInfo == null)
395 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
399 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
401 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
405 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
406 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
407 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
408 canvas.DrawBitmap(rectFirst, *pBitmap);
411 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
415 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
417 AppLogDebug("ENTER");
421 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
428 Bitmap* pBitmap = null;
429 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
431 EnrichedText enTextCount;
432 TextElement textElement;
433 TextElement textElementCount;
435 int allContentCount = pAlbumInfo->GetContentIdCount();
436 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
438 String strFolderName = pAlbumInfo->GetAlbumName();
440 if (strFolderName == ALL_ALBUMS_REAL_NAME)
442 strFolderName = ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS");
445 String strDirectory = pAlbumInfo->GetDirectory(0);
446 AppLog("The directory path is %ls" , strDirectory.GetPointer());
448 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
449 Color bgColor(COLOR_CANVAS_BG);
450 bgColor.SetAlpha(ALPHA_BG);
451 canvas.FillRectangle(bgColor, rectCanvas);
454 if (strDirectory == RESERVED_DOWNLOAD_PATH)
456 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
458 else if (strDirectory == RESERVED_CAMERA_PATH || strDirectory == RESERVED_CAMERA_PATH_EXT)
460 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
464 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
469 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
470 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
474 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
475 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
476 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
477 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
479 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
480 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
482 textElement.Construct(strFolderName);
483 textElement.SetFont(ftFolderName);
484 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
485 enText.SetTextAbbreviationEnabled(true);
486 enText.Add(textElement);
488 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
489 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
491 textElementCount.Construct(strCnt);
493 if (strCnt.GetLength() > 3)
495 textElementCount.SetFont(ftCntSmall);
499 textElementCount.SetFont(ftCnt);
501 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
502 enTextCount.SetTextAbbreviationEnabled(true);
503 enTextCount.Add(textElementCount);
505 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH,
506 rectCanvas.y + HEIGHT_OFFSET);
507 canvas.SetFont(ftCnt);
508 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
509 canvas.DrawText(pointText, enTextCount);
511 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP,
512 rectCanvas.y + GAP + HEIGHT_OFFSET);
513 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
514 canvas.DrawText(pointText, enText);
516 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
520 AlbumListPresentationModel::CreateMergeBitmapN(const int index)
522 AppLogDebug("ENTER index(%d)", index);
524 if (__pAlbumInfoList == null)
526 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
531 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
533 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
534 BufferInfo bufferinfo;
536 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
537 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
539 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
543 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
548 pBitmapNew->Lock(bufferinfo);
549 r = canvas.Construct(bufferinfo);
553 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
558 DrawPartialImage(canvas, pAlbumInfo, rectNew);
559 DrawFontImage(canvas, pAlbumInfo, index);
561 pBitmapNew->Unlock();
562 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
568 AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
569 const String* pUriData, const String* pMimeType, const HashMap* pDataList,
570 IAppControlResponseListener* pListener)
572 AppLogDebug("ENTER");
573 FileListPresentationModel::GetInstance()->ClearProviderId();
574 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
577 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
581 result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
585 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
586 pGalleryApp->SetFrameEnabled(false);
591 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
597 AlbumListPresentationModel::GetDirectoryName(String& directoryPath) const
599 AppLogDebug("ENTER");
600 String directoryName;
603 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
604 directoryPath.SubString(lastIndex + 1, directoryName);
605 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
607 return directoryName;
611 AlbumListPresentationModel::GetFolderCount(void) const
613 AppLogDebug("ENTER");
614 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
616 return __pAlbumInfoList->GetCount();
620 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
622 AppLogDebug("ENTER");
624 if (__pFolderBackgroundBitmap == null)
626 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
629 if (__pAlbumInfoList != null)
631 delete __pAlbumInfoList;
633 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
635 ContentDirectory directory;
637 if (contentType == CONTENT_TYPE_ALL)
639 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
640 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
641 pListT->Add(CONTENT_TYPE_IMAGE);
642 pListT->Add(CONTENT_TYPE_VIDEO);
644 result r = directory.Construct(*pListT);
649 delete __pAlbumInfoList;
650 __pAlbumInfoList = null;
651 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
657 result r = directory.Construct(contentType);
660 delete __pAlbumInfoList;
661 __pAlbumInfoList = null;
662 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
667 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
668 String* pDirPath = null;
669 AlbumInfo* pAlbumInfo = null;
671 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
672 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
673 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
674 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
676 result r = pAllAlbumInfo->Construct();
677 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
678 pAllAlbumInfo->SetAlbumName(ALL_ALBUMS_REAL_NAME);
680 r = pCameraAlbumInfo->Construct();
681 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
682 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
684 r = pDownloadAlbumInfo->Construct();
685 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
686 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
688 r = pNoNameAlbumInfo->Construct();
689 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
690 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
692 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
694 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
695 while (pEnum->MoveNext() == E_SUCCESS)
697 pDirPath = static_cast<String*>(pEnum->GetCurrent());
698 String mediaPath = RESERVED_MEDIA_PATH;
699 int length = mediaPath.GetLength();
700 mediaPath.Remove(length-1,1);
702 if (pDirPath == null)
706 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
708 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
710 if (pContentIdList != null)
712 pCameraAlbumInfo->AppendDirectory(*pDirPath);
713 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
715 pAllAlbumInfo->AppendDirectory(*pDirPath);
716 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
717 delete pContentIdList;
720 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
722 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
724 if (pContentIdList != null)
726 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
727 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
729 pAllAlbumInfo->AppendDirectory(*pDirPath);
730 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
732 pContentIdList->RemoveAll(true);
733 delete pContentIdList;
736 else if (*pDirPath == mediaPath)
738 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
740 if (pContentIdList != null)
742 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
743 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
745 pAllAlbumInfo->AppendDirectory(*pDirPath);
746 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
748 pContentIdList->RemoveAll(true);
749 delete pContentIdList;
754 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
756 if (pContentIdList != null)
758 if (pContentIdList->GetCount() > 0)
760 pAlbumInfo = new (std::nothrow) AlbumInfo();
761 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
763 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
765 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
768 pAllAlbumInfo->AppendDirectory(*pDirPath);
769 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
771 pSubDirList->RemoveAll(true);
775 if (pContentIdList != NULL)
777 pContentIdList->RemoveAll(true);
778 delete pContentIdList;
781 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
783 __pAlbumInfoList->Add(pAlbumInfo);
784 AppLog("Adding album");
795 if (pAllAlbumInfo->GetContentIdCount() > 0)
797 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
801 delete pAllAlbumInfo;
804 if (pCameraAlbumInfo->GetContentIdCount() > 0)
806 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
810 delete pCameraAlbumInfo;
813 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
815 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
819 delete pDownloadAlbumInfo;
822 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
824 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
828 delete pNoNameAlbumInfo;
835 delete pAllAlbumInfo;
836 delete pCameraAlbumInfo;
837 delete pDownloadAlbumInfo;
838 delete pNoNameAlbumInfo;
841 if (pContentDirectoryPathList != null)
843 pContentDirectoryPathList->RemoveAll(true);
844 delete pContentDirectoryPathList;
846 ClearThumbnailRequests(false);
847 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
851 if (pContentDirectoryPathList != null)
853 pContentDirectoryPathList->RemoveAll(true);
854 delete pContentDirectoryPathList;
856 delete pAllAlbumInfo;
857 delete pCameraAlbumInfo;
858 delete pDownloadAlbumInfo;
859 delete pNoNameAlbumInfo;
863 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
865 AppLogDebug("ENTER");
866 if (fullPath == null)
868 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
872 String delim(DIRECTORY_SEPARATOR);
873 StringTokenizer st(fullPath,delim);
875 while (st.HasMoreTokens())
877 st.GetNextToken(token);
879 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
885 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
887 AppLogDebug("ENTER");
889 if (&directoryPath == null)
891 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
895 ContentDirectory directory;
896 const String contentDirectoryPath = directoryPath;
897 if (contentType == CONTENT_TYPE_ALL)
899 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
900 pListT->Add(CONTENT_TYPE_IMAGE);
901 pListT->Add(CONTENT_TYPE_VIDEO);
902 result r = directory.Construct(*pListT);
906 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
912 result r = directory.Construct(contentType);
915 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
921 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
923 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
924 DATE_TIME, SORT_ORDER_DESCENDING);
926 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
928 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
930 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
932 while (pEnum->MoveNext() == E_SUCCESS)
934 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
935 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
936 pContentIdList->Add(pItem);
941 if (pContentInfoList != NULL)
943 pContentInfoList->RemoveAll(true);
944 delete pContentInfoList;
947 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
949 return pContentIdList;
953 AlbumListPresentationModel::DeleteContentFile(const String& filePath)
955 AppLogDebug("ENTER");
956 result r = E_SUCCESS;
957 r = File::Remove(filePath);
963 AlbumListPresentationModel::GetAppControlMode(void) const
965 AppLogDebug("Enter");
967 return __appControlMode;
971 AlbumListPresentationModel::GetAppControlMediaType(void) const
973 AppLogDebug("Enter");
975 return __appControlMediaType;
978 AppControlSelectionMode
979 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
981 AppLogDebug("Enter");
983 return __appControlSelectionMode;
987 AlbumListPresentationModel::GetAlbumInfoList(void) const
989 AppLogDebug("ENTER");
990 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
992 return __pAlbumInfoList;
995 IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
997 AppLogDebug("ENTER");
998 ContentDirectory directory;
999 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1001 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
1002 TryReturn(pListT != null,null, "Unable to Create ArrayListT");
1003 pListT->Add(CONTENT_TYPE_IMAGE);
1004 pListT->Add(CONTENT_TYPE_VIDEO);
1006 result r = directory.Construct(*pListT);
1011 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
1012 delete pContentIdList;
1016 if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
1018 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
1019 String* pDirPath = null;
1020 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
1022 int loopCount = pContentDirectoryPathList->GetCount();
1023 for (int i = 0; i < loopCount; ++i)
1025 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
1026 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
1032 if(__pAlbumInfoList != null)
1034 int loopCount = indexList.GetCount();
1035 AlbumInfo* pInfo = null;
1036 for (int i = 0; i < loopCount; ++i)
1038 int index = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
1039 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
1043 IList* pList = pInfo->GetContentIdListN();
1046 pContentIdList->AddItems(*pList);
1052 return pContentIdList;
1056 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
1058 AppLogDebug("ENTER");
1059 if (&eventArg != null)
1061 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
1062 if (pThumbnailEventArg == null)
1064 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1068 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
1069 if (pThumbnailInfo == null)
1071 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1076 ContentId contentId = pThumbnailInfo->GetContentId();
1077 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1079 if (__pAlbumInfoList != null)
1081 int outterLoopCount = __pAlbumInfoList->GetCount();
1082 for (int x = 0; x < outterLoopCount; ++x)
1084 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1085 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1086 for (int i = 0; i < innerLoopCount; ++i)
1088 if (i >= FOLDER_BITMAP_MAX)
1093 if (contentId == pAlbumInfo->GetContentId(i))
1095 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1097 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1098 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1105 delete pThumbnailInfo;
1107 if (__pPresentationModelListener->GetCount() > 0)
1109 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1110 while (pEnum->MoveNext() == E_SUCCESS)
1112 IAlbumEventListener* pListener = null;
1113 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1115 int loopCount = pUpdateFolderIndex->GetCount();
1116 for (int k = 0; k < loopCount; ++k)
1118 Integer *pIndex = (Integer*)pUpdateFolderIndex->GetAt(k);
1119 int folderIndex = pIndex->ToInt();
1120 pListener->OnThumbnailDecoded(folderIndex);
1126 delete pUpdateFolderIndex;
1128 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1132 AlbumListPresentationModel::OnContentCreated(void)
1134 AppLogDebug("ENTER");
1135 if (__updateProgressStatus == true)
1137 AppLogDebug("EXIT update in application");
1140 IFormContentUpdateEventListener* pInterface = null;
1141 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1142 while (pEventEnum->MoveNext() == E_SUCCESS)
1144 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1145 if (pInterface != null)
1147 pInterface->OnContentUpdated();
1151 AppLogDebug("EXIT");
1155 AlbumListPresentationModel::OnContentUpdated(void)
1157 AppLogDebug("ENTER");
1158 if (__updateProgressStatus == true)
1160 AppLogDebug("EXIT update in application");
1163 IFormContentUpdateEventListener* pInterface = null;
1164 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1165 while (pEventEnum->MoveNext() == E_SUCCESS)
1167 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1168 pInterface->OnContentUpdated();
1171 AppLogDebug("EXIT");
1175 AlbumListPresentationModel::OnContentDeleted(void)
1177 AppLogDebug("ENTER");
1178 if (__updateProgressStatus == true)
1180 AppLogDebug("EXIT update in application");
1183 IFormContentUpdateEventListener* pInterface = null;
1184 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1185 while (pEventEnum->MoveNext() == E_SUCCESS)
1187 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1188 pInterface->OnContentUpdated();
1191 AppLogDebug("EXIT");
1195 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1197 AppLogDebug("ENTER");
1198 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
1200 IFormContentUpdateEventListener* pInterface = null;
1201 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1202 while (pEventEnum->MoveNext() == E_SUCCESS)
1204 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1205 pInterface->OnContentUpdated();
1209 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1213 AlbumListPresentationModel::SetUpdateProgressStatus(const bool status)
1215 AppLogDebug("ENTER status = %d",status);
1216 __updateProgressStatus = status;
1217 AppLogDebug("EXIT");
1221 AlbumListPresentationModel::RotateImage(const ContentId&, RotateMode rotateMode)
1227 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, const int pathIndex)
1229 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1231 ContentId contentId;
1232 if (__pAlbumInfoList != null)
1234 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1235 contentId = pAlbumInfo->GetContentId(pathIndex);
1238 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1239 AppLogDebug("EXIT");
1243 AlbumListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
1245 AppLogDebug("ENTER");
1246 if (__pThumbnailProvider != null)
1248 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1250 AppLogDebug("EXIT");