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"
36 using namespace Tizen::App;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Base::Runtime;
40 using namespace Tizen::Base::Utility;
41 using namespace Tizen::Content;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Io;
44 using namespace Tizen::Media;
45 using namespace Tizen::System;
46 using namespace Tizen::Ui::Controls;
48 static const int ICON_CAP = 3;
49 static const int FOLDER_CAP = 8;
50 static const int ICON_SIZE = 107;
51 static const int FOLDER_SIZE_WIDTH = 348;
52 static const int FOLDER_SIZE_HEIGHT = 348;
54 static const int CANVAS_HEIGHT = 71;
55 static const int CANVAS_WIDTH = 326;
57 static const int FONT_SIZE_FOLDER_NAME = 32;
58 static const int FONT_SIZE_FOLDER_DATE = 25;
59 static const int FONT_SIZE_FOLDER_COUNT = 45;
60 static const int FONT_SIZE_FOLDER_COUNT_SMALL = 35;
62 static const int CANVAS_IMAGE_FOLDER_HEIGHT = 48;
63 static const int CANVAS_IMAGE_FOLDER_WIDTH = 48;
64 static const int IMAGE_COUNT_WIDTH = 100;
65 static const int IMAGE_COUNT_HEIGHT = 60;
66 static const int CANVAS_MARGIN_LEFT = 10;
67 static const int GAP = 10;
68 static const int HEIGHT_OFFSET = 5;
69 static const int Y_POS_CANVAS = 260;
70 static const int FOLDER_NAME_WIDTH = 165;
71 static const int FOLDER_NAME_HEIGHT = 38;
74 static const int ALPHA_BG = 110;
76 static const Color COLOR_CANVAS_BG (Color::GetColor(COLOR_ID_BLACK));
78 static const String RESERVED_MEDIA_PATH = Environment::GetMediaPath();
79 static const String RESERVED_CAMERA_PATH = Environment::GetMediaPath() + L"Camera";
80 static const String RESERVED_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera";
81 static const String RESERVED_DOWNLOAD_PATH = Environment::GetMediaPath() + L"Downloads";
82 static const String CONTENT_INFO_ORDER = L"ContentFileName";
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 , __pContentManager(null)
100 , __pAlbumListener(null)
101 , __appControlMode(APPCONTROL_MODE_MAIN)
102 , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
103 , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
104 , __updateProgressStatus(false)
106 AppLogDebug("ENTER");
107 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
110 AlbumListPresentationModel::~AlbumListPresentationModel(void)
112 AppLogDebug("ENTER");
113 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
114 delete __pFolderBackgroundBitmap;
115 delete __pContentManager;
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 __pContentManager = new (std::nothrow) ContentManager();
148 __pContentManager->Construct();
150 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
152 __pThumbnailProvider = ThumbnailProvider::GetInstance();
153 AppLogDebug("ENTER1");
154 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
155 const IMap* pArguments = pApp->GetAppControlArguments();
156 String operationId = pApp->GetAppControlOperationId();
158 if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
160 __appControlMode = APPCONTROL_MODE_MAIN;
162 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
164 __appControlMode = APPCONTROL_MODE_PICK;
166 String mimeType = pApp->GetMimeType();
167 if (mimeType.IsEmpty() != true)
169 if (mimeType.StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
171 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
174 if (pArguments != null)
176 const String* selectionMode =
177 static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
178 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
180 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
184 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
186 __appControlMode = APPCONTROL_MODE_SETTING;
189 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
195 AlbumListPresentationModel::CreateInstance(void)
197 AppLogDebug("ENTER");
198 __pPresentationModelInstance = new (std::nothrow) AlbumListPresentationModel;
199 result r = __pPresentationModelInstance->Construct();
201 if (IsFailed(r) == true)
203 delete __pPresentationModelInstance;
204 __pPresentationModelInstance = null;
205 AppLogDebug("EXIT false");
208 std::atexit(DestroyInstance);
209 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
213 AlbumListPresentationModel::DestroyInstance(void)
215 AppLogDebug("ENTER");
217 delete __pThumbnailEvent;
218 __pThumbnailEvent = null;
220 if (__pAlbumInfoList != null)
222 delete __pAlbumInfoList;
223 __pAlbumInfoList = null;
226 if (__pPresentationModelListener != null)
228 delete __pPresentationModelListener;
229 __pPresentationModelListener = null;
232 if (__pContentEventListener != null)
234 delete __pContentEventListener;
235 __pContentEventListener = null;
238 delete __pPresentationModelInstance;
239 __pPresentationModelInstance = null;
241 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
245 AlbumListPresentationModel::AddPresentationModelListener(IAlbumEventListener* listener)
247 AppLogDebug("ENTER");
248 result r = __pPresentationModelListener->Add(listener);
249 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
255 AlbumListPresentationModel::RemovePresentationModelListener(IAlbumEventListener& listner)
257 AppLogDebug("ENTER");
258 result r = __pPresentationModelListener->Remove(listner);
259 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
265 AlbumListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
267 AppLogDebug("ENTER");
268 if (__pContentEventListener != null)
270 __pContentEventListener->RemoveAll();
271 __pContentEventListener->Add((Object*)listener);
272 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
277 AlbumListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener& listener)
279 AppLogDebug("ENTER");
280 __pContentEventListener->Remove(listener);
281 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
285 AlbumListPresentationModel::CallAlbumChangedEvent(void)
287 AppLogDebug("ENTER");
288 if (__pPresentationModelListener->GetCount() > 0)
290 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
292 while (pEnum->MoveNext() == E_SUCCESS)
294 IAlbumEventListener* pListener = null;
295 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
296 pListener->OnFileInfoChanged(CONTENT_TYPE_ALL);
301 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
305 AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& newPath,
306 IAlbumRenameEventListener* pAlbumListener)
308 AppLogDebug("ENTER");
309 result r = Directory::Rename(orgPath, newPath);
312 AppLogDebug("Album Rename failed(%s)", GetErrorMessage(r));
316 __pAlbumListener = pAlbumListener;
317 __renameNewPath = newPath;
\r
318 r = ContentManager::ScanDirectory(newPath, true, NULL, __reqId);
\r
319 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
320 r = ContentManager::ScanDirectory(orgPath, true, NULL, __reqId);
\r
321 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
327 bool AlbumListPresentationModel::OnContentScanCompleted (const Tizen::Base::String &scanPath)
\r
329 AppLogDebug("ENTER");
\r
330 if (__pAlbumListener && (scanPath == __renameNewPath))
\r
332 InitializeAlbumInfoList(CONTENT_TYPE_ALL);
333 __pAlbumListener->OnAlbumRenameComplete();
334 __renameNewPath = L"";
343 AlbumListPresentationModel::DrawPartialImage(Canvas& canvas, AlbumInfo* pAlbumInfo, const Rectangle& rectNew)
345 AppLogDebug("ENTER");
346 if (&canvas == null || __pFolderBackgroundBitmap == null || pAlbumInfo == null)
348 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
352 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
354 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
358 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
359 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
360 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
361 canvas.DrawBitmap(rectFirst, *pBitmap);
364 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
368 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
370 AppLogDebug("ENTER");
374 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
381 Bitmap* pBitmap = null;
382 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
384 EnrichedText enTextCount;
385 TextElement textElement;
386 TextElement textElementCount;
388 int allContentCount = pAlbumInfo->GetContentIdCount();
389 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
391 String strFolderName = pAlbumInfo->GetAlbumName();
392 String strDirectory = pAlbumInfo->GetDirectory(0);
393 AppLog("The directory path is %ls" , strDirectory.GetPointer());
395 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
396 Color bgColor(COLOR_CANVAS_BG);
397 bgColor.SetAlpha(ALPHA_BG);
398 canvas.FillRectangle(bgColor, rectCanvas);
401 if (strDirectory == RESERVED_DOWNLOAD_PATH)
403 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
405 else if (strDirectory == RESERVED_CAMERA_PATH || strDirectory == RESERVED_CAMERA_PATH_EXT)
407 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
411 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
416 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
417 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
421 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
422 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
423 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
424 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
426 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
427 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
429 textElement.Construct(strFolderName);
430 textElement.SetFont(ftFolderName);
431 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
432 enText.SetTextAbbreviationEnabled(true);
433 enText.Add(textElement);
435 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
436 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
438 textElementCount.Construct(strCnt);
440 if (strCnt.GetLength() > 3)
442 textElementCount.SetFont(ftCntSmall);
446 textElementCount.SetFont(ftCnt);
448 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
449 enTextCount.SetTextAbbreviationEnabled(true);
450 enTextCount.Add(textElementCount);
452 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH,
453 rectCanvas.y + HEIGHT_OFFSET);
454 canvas.SetFont(ftCnt);
455 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
456 canvas.DrawText(pointText, enTextCount);
458 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP,
459 rectCanvas.y + GAP + HEIGHT_OFFSET);
460 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
461 canvas.DrawText(pointText, enText);
463 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
467 AlbumListPresentationModel::CreateMergeBitmapN(const int index)
469 AppLogDebug("ENTER index(%d)", index);
471 if (__pAlbumInfoList == null)
473 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
478 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
480 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
481 BufferInfo bufferinfo;
483 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
484 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
486 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
490 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
495 pBitmapNew->Lock(bufferinfo);
496 r = canvas.Construct(bufferinfo);
500 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
505 DrawPartialImage(canvas, pAlbumInfo, rectNew);
506 DrawFontImage(canvas, pAlbumInfo, index);
508 pBitmapNew->Unlock();
509 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
515 AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
516 const String* pUriData, const String* pMimeType, const HashMap* pDataList,
517 IAppControlResponseListener* pListener)
519 AppLogDebug("ENTER");
520 FileListPresentationModel::GetInstance()->ClearProviderId();
521 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
524 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
528 result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
532 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
533 pGalleryApp->SetFrameEnabled(false);
538 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
544 AlbumListPresentationModel::GetDirectoryName(String& directoryPath) const
546 AppLogDebug("ENTER");
547 String directoryName;
550 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
551 directoryPath.SubString(lastIndex + 1, directoryName);
552 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
554 return directoryName;
558 AlbumListPresentationModel::GetFolderCount(void) const
560 AppLogDebug("ENTER");
561 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
563 return __pAlbumInfoList->GetCount();
567 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
569 AppLogDebug("ENTER");
571 if (__pFolderBackgroundBitmap == null)
573 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
576 if (__pAlbumInfoList != null)
578 AlbumInfo* pInfo = null;
579 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
581 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
582 if (pInfo->GetAlbumName().IsEmpty() == false)
584 AppLog("Print AlbumName(%d)(%ls)", i, pInfo->GetAlbumName().GetPointer());
587 delete __pAlbumInfoList;
589 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
591 ContentDirectory directory;
593 if (contentType == CONTENT_TYPE_ALL)
595 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
596 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
597 pListT->Add(CONTENT_TYPE_IMAGE);
598 pListT->Add(CONTENT_TYPE_VIDEO);
600 result r = directory.Construct(*pListT);
605 delete __pAlbumInfoList;
606 __pAlbumInfoList = null;
607 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
613 result r = directory.Construct(contentType);
616 delete __pAlbumInfoList;
617 __pAlbumInfoList = null;
618 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
623 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
624 String* pDirPath = null;
625 AlbumInfo* pAlbumInfo = null;
627 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
628 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
629 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
630 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
632 result r = pAllAlbumInfo->Construct();
633 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
634 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
636 r = pCameraAlbumInfo->Construct();
637 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
638 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
640 r = pDownloadAlbumInfo->Construct();
641 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
642 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
644 r = pNoNameAlbumInfo->Construct();
645 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
646 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
648 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
650 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
651 while (pEnum->MoveNext() == E_SUCCESS)
653 pDirPath = static_cast<String*>(pEnum->GetCurrent());
654 String mediaPath = RESERVED_MEDIA_PATH;
655 int length = mediaPath.GetLength();
656 mediaPath.Remove(length-1,1);
658 if (pDirPath == null)
663 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
665 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
667 if (pContentIdList != null)
669 pCameraAlbumInfo->AppendDirectory(*pDirPath);
670 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
672 pAllAlbumInfo->AppendDirectory(*pDirPath);
673 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
674 delete pContentIdList;
677 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
679 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
681 if (pContentIdList != null)
683 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
684 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
686 pAllAlbumInfo->AppendDirectory(*pDirPath);
687 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
689 pContentIdList->RemoveAll(true);
690 delete pContentIdList;
693 else if (*pDirPath == mediaPath)
695 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
697 if (pContentIdList != null)
699 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
700 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
702 pAllAlbumInfo->AppendDirectory(*pDirPath);
703 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
705 pContentIdList->RemoveAll(true);
706 delete pContentIdList;
711 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
713 if (pContentIdList != null)
715 if (pContentIdList->GetCount() > 0)
717 pAlbumInfo = new (std::nothrow) AlbumInfo();
718 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
720 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
722 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
725 pAllAlbumInfo->AppendDirectory(*pDirPath);
726 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
728 pSubDirList->RemoveAll(true);
732 if (pContentIdList != NULL)
734 pContentIdList->RemoveAll(true);
735 delete pContentIdList;
738 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
740 __pAlbumInfoList->Add(pAlbumInfo);
741 AppLog("Adding album");
752 if (pAllAlbumInfo->GetContentIdCount() > 0)
754 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
758 delete pAllAlbumInfo;
761 if (pCameraAlbumInfo->GetContentIdCount() > 0)
763 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
767 delete pCameraAlbumInfo;
770 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
772 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
776 delete pDownloadAlbumInfo;
779 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
781 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
785 delete pNoNameAlbumInfo;
792 delete pAllAlbumInfo;
793 delete pCameraAlbumInfo;
794 delete pDownloadAlbumInfo;
795 delete pNoNameAlbumInfo;
798 if (pContentDirectoryPathList != null)
800 pContentDirectoryPathList->RemoveAll(true);
801 delete pContentDirectoryPathList;
803 ClearThumbnailRequests(false);
804 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
808 if (pContentDirectoryPathList != null)
810 pContentDirectoryPathList->RemoveAll(true);
811 delete pContentDirectoryPathList;
813 delete pAllAlbumInfo;
814 delete pCameraAlbumInfo;
815 delete pDownloadAlbumInfo;
816 delete pNoNameAlbumInfo;
820 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
822 AppLogDebug("ENTER");
823 if (fullPath == null)
825 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
829 String delim(DIRECTORY_SEPARATOR);
830 StringTokenizer st(fullPath,delim);
832 while (st.HasMoreTokens())
834 st.GetNextToken(token);
836 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
842 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
844 AppLogDebug("ENTER");
846 if (&directoryPath == null)
848 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
852 ContentDirectory directory;
853 const String contentDirectoryPath = directoryPath;
854 if (contentType == CONTENT_TYPE_ALL)
856 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
857 pListT->Add(CONTENT_TYPE_IMAGE);
858 pListT->Add(CONTENT_TYPE_VIDEO);
859 result r = directory.Construct(*pListT);
863 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
869 result r = directory.Construct(contentType);
872 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
878 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
880 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
881 DATE_TIME, SORT_ORDER_DESCENDING);
883 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
885 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
887 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
889 while (pEnum->MoveNext() == E_SUCCESS)
891 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
892 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
893 pContentIdList->Add(pItem);
898 if (pContentInfoList != NULL)
900 pContentInfoList->RemoveAll(true);
901 delete pContentInfoList;
904 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
906 return pContentIdList;
910 AlbumListPresentationModel::DeleteContentFile(const ContentId& contentId)
912 AppLogDebug("ENTER");
913 result r = E_SUCCESS;
914 ContentManager contentManager;
915 r = contentManager.Construct();
918 r = contentManager.DeleteContent(contentId);
920 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
926 AlbumListPresentationModel::GetAppControlMode(void) const
928 AppLogDebug("Enter");
930 return __appControlMode;
934 AlbumListPresentationModel::GetAppControlMediaType(void) const
936 AppLogDebug("Enter");
938 return __appControlMediaType;
941 AppControlSelectionMode
942 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
944 AppLogDebug("Enter");
946 return __appControlSelectionMode;
950 AlbumListPresentationModel::GetAlbumInfoList(void) const
952 AppLogDebug("ENTER");
953 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
955 return __pAlbumInfoList;
958 IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
960 AppLogDebug("ENTER");
961 ContentDirectory directory;
962 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
964 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
965 TryReturn(pListT != null,null, "Unable to Create ArrayListT");
966 pListT->Add(CONTENT_TYPE_IMAGE);
967 pListT->Add(CONTENT_TYPE_VIDEO);
969 result r = directory.Construct(*pListT);
974 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
975 delete pContentIdList;
979 if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
981 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
982 String* pDirPath = null;
983 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
985 int loopCount = pContentDirectoryPathList->GetCount();
986 for (int i = 0; i < loopCount; ++i)
988 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
989 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
995 if(__pAlbumInfoList != null)
997 int loopCount = indexList.GetCount();
998 AlbumInfo* pInfo = null;
999 for (int i = 0; i < loopCount; ++i)
1001 int index = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
1002 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
1006 IList* pList = pInfo->GetContentIdListN();
1009 pContentIdList->AddItems(*pList);
1015 return pContentIdList;
1019 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
1021 AppLogDebug("ENTER");
1022 if (&eventArg != null)
1024 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
1025 if (pThumbnailEventArg == null)
1027 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1031 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
1032 if (pThumbnailInfo == null)
1034 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1039 ContentId contentId = pThumbnailInfo->GetContentId();
1040 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1042 if (__pAlbumInfoList != null)
1044 int outterLoopCount = __pAlbumInfoList->GetCount();
1045 for (int x = 0; x < outterLoopCount; ++x)
1047 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1048 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1049 for (int i = 0; i < innerLoopCount; ++i)
1051 if (i >= FOLDER_BITMAP_MAX)
1056 if (contentId == pAlbumInfo->GetContentId(i))
1058 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1060 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1061 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1068 delete pThumbnailInfo;
1070 if (__pPresentationModelListener->GetCount() > 0)
1072 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1073 while (pEnum->MoveNext() == E_SUCCESS)
1075 IAlbumEventListener* pListener = null;
1076 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1078 int loopCount = pUpdateFolderIndex->GetCount();
1079 for (int k = 0; k < loopCount; ++k)
1081 Integer *pIndex = (Integer*)pUpdateFolderIndex->GetAt(k);
1082 int folderIndex = pIndex->ToInt();
1083 pListener->OnThumbnailDecoded(folderIndex);
1089 delete pUpdateFolderIndex;
1091 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1095 AlbumListPresentationModel::OnContentCreated(void)
1097 AppLogDebug("ENTER");
1098 if (__updateProgressStatus == true)
1100 AppLogDebug("EXIT update in application");
1103 IFormContentUpdateEventListener* pInterface = null;
1104 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1105 while (pEventEnum->MoveNext() == E_SUCCESS)
1107 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1108 if (pInterface != null)
1110 pInterface->OnContentUpdated();
1114 AppLogDebug("EXIT");
1118 AlbumListPresentationModel::OnContentUpdated(void)
1120 AppLogDebug("ENTER");
1121 if (__updateProgressStatus == true)
1123 AppLogDebug("EXIT update in application");
1126 IFormContentUpdateEventListener* pInterface = null;
1127 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1128 while (pEventEnum->MoveNext() == E_SUCCESS)
1130 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1131 pInterface->OnContentUpdated();
1134 AppLogDebug("EXIT");
1138 AlbumListPresentationModel::OnContentDeleted(void)
1140 AppLogDebug("ENTER");
1141 if (__updateProgressStatus == true)
1143 AppLogDebug("EXIT update in application");
1146 IFormContentUpdateEventListener* pInterface = null;
1147 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1148 while (pEventEnum->MoveNext() == E_SUCCESS)
1150 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1151 pInterface->OnContentUpdated();
1154 AppLogDebug("EXIT");
1158 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1160 AppLogDebug("ENTER");
1161 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1165 AlbumListPresentationModel::SetUpdateProgressStatus(const bool status)
1167 AppLogDebug("ENTER status = %d",status);
1168 __updateProgressStatus = status;
1169 AppLogDebug("EXIT");
1173 AlbumListPresentationModel::RotateImage(int index, RotateMode rotateMode)
1179 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, const int pathIndex)
1181 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1183 ContentId contentId;
1184 if (__pAlbumInfoList != null)
1186 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1187 contentId = pAlbumInfo->GetContentId(pathIndex);
1190 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1191 AppLogDebug("EXIT");
1195 AlbumListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
1197 AppLogDebug("ENTER");
1198 if (__pThumbnailProvider != null)
1200 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1202 AppLogDebug("EXIT");