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";
84 static const int FORMAT_BUFFER_SIZE = 256;
86 static const int DOUBLE_NUMBER = 2;
87 static const int TRIPLE_NUMBER = 3;
89 AlbumListPresentationModel* AlbumListPresentationModel::__pPresentationModelInstance = null;
90 ArrayList* AlbumListPresentationModel::__pPresentationModelListener = null;
91 ArrayList* AlbumListPresentationModel::__pContentEventListener = null;
92 ThumbnailProvider* AlbumListPresentationModel::__pThumbnailProvider = null;
93 ThumbnailEvent* AlbumListPresentationModel::__pThumbnailEvent = null;
94 IList* AlbumListPresentationModel::__pAlbumInfoList = null;
96 AlbumListPresentationModel::AlbumListPresentationModel(void)
97 : __pFolderBackgroundBitmap(null)
98 , __pContentManager(null)
99 , __pAlbumListener(null)
100 , __appControlMode(APPCONTROL_MODE_MAIN)
101 , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
102 , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
103 , __updateProgressStatus(false)
105 AppLogDebug("ENTER");
106 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
109 AlbumListPresentationModel::~AlbumListPresentationModel(void)
111 AppLogDebug("ENTER");
112 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
113 delete __pFolderBackgroundBitmap;
114 delete __pContentManager;
115 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
118 AlbumListPresentationModel*
119 AlbumListPresentationModel::GetInstance(void)
121 AppLogDebug("ENTER");
122 if (__pPresentationModelInstance == null)
126 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
128 return __pPresentationModelInstance;
132 AlbumListPresentationModel::Construct(void)
134 AppLogDebug("ENTER");
135 __pPresentationModelListener = new (std::nothrow) ArrayList();
136 __pPresentationModelListener->Construct();
138 ContentUpdateEventListener::GetInstance();
139 __pContentEventListener = new (std::nothrow) ArrayList();
140 __pContentEventListener->Construct();
142 IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
143 __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
144 __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
146 __pContentManager = new (std::nothrow) ContentManager();
147 __pContentManager->Construct();
149 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
151 __pThumbnailProvider = ThumbnailProvider::GetInstance();
152 AppLogDebug("ENTER1");
153 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
154 const IMap* pArguments = pApp->GetAppControlArguments();
155 String operationId = pApp->GetAppControlOperationId();
157 if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
159 __appControlMode = APPCONTROL_MODE_MAIN;
161 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
163 __appControlMode = APPCONTROL_MODE_PICK;
165 String mimeType = pApp->GetMimeType();
166 if (mimeType.IsEmpty() != true)
168 if (mimeType.StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
170 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
173 if (pArguments != null)
175 const String* selectionMode =
176 static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
177 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
179 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
183 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
185 __appControlMode = APPCONTROL_MODE_SETTING;
188 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
194 AlbumListPresentationModel::CreateInstance(void)
196 AppLogDebug("ENTER");
197 __pPresentationModelInstance = new (std::nothrow) AlbumListPresentationModel;
198 result r = __pPresentationModelInstance->Construct();
200 if (IsFailed(r) == true)
202 delete __pPresentationModelInstance;
203 __pPresentationModelInstance = null;
204 AppLogDebug("EXIT false");
207 std::atexit(DestroyInstance);
208 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
212 AlbumListPresentationModel::DestroyInstance(void)
214 AppLogDebug("ENTER");
216 delete __pThumbnailEvent;
217 __pThumbnailEvent = null;
219 if (__pAlbumInfoList != null)
221 delete __pAlbumInfoList;
222 __pAlbumInfoList = null;
225 if (__pPresentationModelListener != null)
227 delete __pPresentationModelListener;
228 __pPresentationModelListener = null;
231 if (__pContentEventListener != null)
233 delete __pContentEventListener;
234 __pContentEventListener = null;
237 delete __pPresentationModelInstance;
238 __pPresentationModelInstance = null;
240 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
244 AlbumListPresentationModel::AddPresentationModelListener(IAlbumEventListener* listener)
246 AppLogDebug("ENTER");
247 result r = __pPresentationModelListener->Add(listener);
248 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
254 AlbumListPresentationModel::RemovePresentationModelListener(IAlbumEventListener& listner)
256 AppLogDebug("ENTER");
257 result r = __pPresentationModelListener->Remove(listner);
258 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
264 AlbumListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
266 AppLogDebug("ENTER");
267 if (__pContentEventListener != null)
269 __pContentEventListener->RemoveAll();
270 __pContentEventListener->Add((Object*)listener);
271 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
276 AlbumListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener& listener)
278 AppLogDebug("ENTER");
279 __pContentEventListener->Remove(listener);
280 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
284 AlbumListPresentationModel::CallAlbumChangedEvent(void)
286 AppLogDebug("ENTER");
287 if (__pPresentationModelListener->GetCount() > 0)
289 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
291 while (pEnum->MoveNext() == E_SUCCESS)
293 IAlbumEventListener* pListener = null;
294 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
295 pListener->OnFileInfoChanged(CONTENT_TYPE_ALL);
300 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
304 AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& newPath,
305 IAlbumRenameEventListener* pAlbumListener)
307 AppLogDebug("ENTER");
308 result r = Directory::Rename(orgPath, newPath);
311 AppLogDebug("Album Rename failed(%s)", GetErrorMessage(r));
315 __pAlbumListener = pAlbumListener;
316 __renameNewPath = newPath;
\r
317 r = ContentManager::ScanDirectory(newPath, true, NULL, __reqId);
\r
318 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
319 r = ContentManager::ScanDirectory(orgPath, true, NULL, __reqId);
\r
320 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
326 bool AlbumListPresentationModel::OnContentScanCompleted (const Tizen::Base::String &scanPath)
\r
328 AppLogDebug("ENTER");
\r
329 if (__pAlbumListener && (scanPath == __renameNewPath))
\r
331 InitializeAlbumInfoList(CONTENT_TYPE_ALL);
332 __pAlbumListener->OnAlbumRenameComplete();
333 __renameNewPath = L"";
342 AlbumListPresentationModel::DrawPartialImage(Canvas& canvas, AlbumInfo* pAlbumInfo, const Rectangle& rectNew)
344 AppLogDebug("ENTER");
345 if (&canvas == null || __pFolderBackgroundBitmap == null || pAlbumInfo == null)
347 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
351 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
353 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
357 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
358 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
359 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
360 canvas.DrawBitmap(rectFirst, *pBitmap);
363 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
367 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
369 AppLogDebug("ENTER");
373 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
380 Bitmap* pBitmap = null;
381 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
383 EnrichedText enTextCount;
384 TextElement textElement;
385 TextElement textElementCount;
387 int allContentCount = pAlbumInfo->GetContentIdCount();
388 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
390 String strFolderName = pAlbumInfo->GetAlbumName();
391 String strDirectory = pAlbumInfo->GetDirectory(0);
392 AppLog("The directory path is %ls" , strDirectory.GetPointer());
394 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
395 Color bgColor(COLOR_CANVAS_BG);
396 bgColor.SetAlpha(ALPHA_BG);
397 canvas.FillRectangle(bgColor, rectCanvas);
400 if (strDirectory == RESERVED_DOWNLOAD_PATH)
402 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
404 else if (strDirectory == RESERVED_CAMERA_PATH || strDirectory == RESERVED_CAMERA_PATH_EXT)
406 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
410 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
415 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
416 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
420 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
421 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
422 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
423 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
425 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
426 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
428 textElement.Construct(strFolderName);
429 textElement.SetFont(ftFolderName);
430 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
431 enText.SetTextAbbreviationEnabled(true);
432 enText.Add(textElement);
434 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
435 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
437 textElementCount.Construct(strCnt);
439 if (strCnt.GetLength() > 3)
441 textElementCount.SetFont(ftCntSmall);
445 textElementCount.SetFont(ftCnt);
447 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
448 enTextCount.SetTextAbbreviationEnabled(true);
449 enTextCount.Add(textElementCount);
451 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH,
452 rectCanvas.y + HEIGHT_OFFSET);
453 canvas.SetFont(ftCnt);
454 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
455 canvas.DrawText(pointText, enTextCount);
457 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP,
458 rectCanvas.y + GAP + HEIGHT_OFFSET);
459 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
460 canvas.DrawText(pointText, enText);
462 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
466 AlbumListPresentationModel::CreateMergeBitmapN(const int index)
468 AppLogDebug("ENTER index(%d)", index);
470 if (__pAlbumInfoList == null)
472 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
477 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
479 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
480 BufferInfo bufferinfo;
482 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
483 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
485 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
489 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
494 pBitmapNew->Lock(bufferinfo);
495 r = canvas.Construct(bufferinfo);
499 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
504 DrawPartialImage(canvas, pAlbumInfo, rectNew);
505 DrawFontImage(canvas, pAlbumInfo, index);
507 pBitmapNew->Unlock();
508 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
514 AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
515 const String* pUriData, const String* pMimeType, const HashMap* pDataList,
516 IAppControlResponseListener* pListener)
518 AppLogDebug("ENTER");
519 FileListPresentationModel::GetInstance()->ClearProviderId();
520 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
523 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
527 result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
531 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
532 pGalleryApp->SetFrameEnabled(false);
537 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
543 AlbumListPresentationModel::GetDirectoryName(String& directoryPath) const
545 AppLogDebug("ENTER");
546 String directoryName;
549 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
550 directoryPath.SubString(lastIndex + 1, directoryName);
551 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
553 return directoryName;
557 AlbumListPresentationModel::GetFolderCount(void) const
559 AppLogDebug("ENTER");
560 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
562 return __pAlbumInfoList->GetCount();
566 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
568 AppLogDebug("ENTER");
570 if (__pFolderBackgroundBitmap == null)
572 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
575 if (__pAlbumInfoList != null)
577 AlbumInfo* pInfo = null;
578 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
580 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
581 if (pInfo->GetAlbumName().IsEmpty() == false)
583 AppLog("Print AlbumName(%d)(%ls)", i, pInfo->GetAlbumName().GetPointer());
586 delete __pAlbumInfoList;
588 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
590 ContentDirectory directory;
592 if (contentType == CONTENT_TYPE_ALL)
594 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
595 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
596 pListT->Add(CONTENT_TYPE_IMAGE);
597 pListT->Add(CONTENT_TYPE_VIDEO);
599 result r = directory.Construct(*pListT);
604 delete __pAlbumInfoList;
605 __pAlbumInfoList = null;
606 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
612 result r = directory.Construct(contentType);
615 delete __pAlbumInfoList;
616 __pAlbumInfoList = null;
617 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
622 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
623 String* pDirPath = null;
624 AlbumInfo* pAlbumInfo = null;
626 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
627 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
628 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
629 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
631 result r = pAllAlbumInfo->Construct();
632 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
633 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
635 r = pCameraAlbumInfo->Construct();
636 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
637 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
639 r = pDownloadAlbumInfo->Construct();
640 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
641 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
643 r = pNoNameAlbumInfo->Construct();
644 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
645 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
647 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
649 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
650 while (pEnum->MoveNext() == E_SUCCESS)
652 pDirPath = static_cast<String*>(pEnum->GetCurrent());
653 String mediaPath = RESERVED_MEDIA_PATH;
654 int length = mediaPath.GetLength();
655 mediaPath.Remove(length-1,1);
657 if (pDirPath == null)
662 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
664 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
666 if (pContentIdList != null)
668 pCameraAlbumInfo->AppendDirectory(*pDirPath);
669 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
671 pAllAlbumInfo->AppendDirectory(*pDirPath);
672 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
673 delete pContentIdList;
676 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
678 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
680 if (pContentIdList != null)
682 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
683 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
685 pAllAlbumInfo->AppendDirectory(*pDirPath);
686 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
688 pContentIdList->RemoveAll(true);
689 delete pContentIdList;
692 else if (*pDirPath == mediaPath)
694 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
696 if (pContentIdList != null)
698 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
699 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
701 pAllAlbumInfo->AppendDirectory(*pDirPath);
702 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
704 pContentIdList->RemoveAll(true);
705 delete pContentIdList;
710 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
712 if (pContentIdList != null)
714 if (pContentIdList->GetCount() > 0)
716 pAlbumInfo = new (std::nothrow) AlbumInfo();
717 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
719 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
721 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
724 pAllAlbumInfo->AppendDirectory(*pDirPath);
725 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
727 pSubDirList->RemoveAll(true);
731 if (pContentIdList != NULL)
733 pContentIdList->RemoveAll(true);
734 delete pContentIdList;
737 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
739 __pAlbumInfoList->Add(pAlbumInfo);
740 AppLog("Adding album");
751 if (pAllAlbumInfo->GetContentIdCount() > 0)
753 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
757 delete pAllAlbumInfo;
760 if (pCameraAlbumInfo->GetContentIdCount() > 0)
762 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
766 delete pCameraAlbumInfo;
769 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
771 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
775 delete pDownloadAlbumInfo;
778 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
780 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
784 delete pNoNameAlbumInfo;
791 delete pAllAlbumInfo;
792 delete pCameraAlbumInfo;
793 delete pDownloadAlbumInfo;
794 delete pNoNameAlbumInfo;
797 if (pContentDirectoryPathList != null)
799 pContentDirectoryPathList->RemoveAll(true);
800 delete pContentDirectoryPathList;
802 ClearThumbnailRequests(false);
803 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
807 if (pContentDirectoryPathList != null)
809 pContentDirectoryPathList->RemoveAll(true);
810 delete pContentDirectoryPathList;
812 delete pAllAlbumInfo;
813 delete pCameraAlbumInfo;
814 delete pDownloadAlbumInfo;
815 delete pNoNameAlbumInfo;
819 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
821 AppLogDebug("ENTER");
822 if (fullPath == null)
824 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
828 String delim(DIRECTORY_SEPARATOR);
829 StringTokenizer st(fullPath,delim);
831 while (st.HasMoreTokens())
833 st.GetNextToken(token);
835 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
841 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
843 AppLogDebug("ENTER");
845 if (&directoryPath == null)
847 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
851 ContentDirectory directory;
852 const String contentDirectoryPath = directoryPath;
853 if (contentType == CONTENT_TYPE_ALL)
855 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
856 pListT->Add(CONTENT_TYPE_IMAGE);
857 pListT->Add(CONTENT_TYPE_VIDEO);
858 result r = directory.Construct(*pListT);
862 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
868 result r = directory.Construct(contentType);
871 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
877 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
878 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
879 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
880 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
882 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
884 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
886 while (pEnum->MoveNext() == E_SUCCESS)
888 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
889 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
890 pContentIdList->Add(pItem);
895 if (pContentInfoList != NULL)
897 pContentInfoList->RemoveAll(true);
898 delete pContentInfoList;
901 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
903 return pContentIdList;
907 AlbumListPresentationModel::DeleteContentFile(const ContentId& contentId)
909 AppLogDebug("ENTER");
910 result r = E_SUCCESS;
911 ContentManager contentManager;
912 r = contentManager.Construct();
915 r = contentManager.DeleteContent(contentId);
917 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
923 AlbumListPresentationModel::GetAppControlMode(void) const
925 AppLogDebug("Enter");
927 return __appControlMode;
931 AlbumListPresentationModel::GetAppControlMediaType(void) const
933 AppLogDebug("Enter");
935 return __appControlMediaType;
938 AppControlSelectionMode
939 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
941 AppLogDebug("Enter");
943 return __appControlSelectionMode;
947 AlbumListPresentationModel::GetAlbumInfoList(void) const
949 AppLogDebug("ENTER");
950 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
952 return __pAlbumInfoList;
955 IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
957 AppLogDebug("ENTER");
958 ContentDirectory directory;
959 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
961 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
962 TryReturn(pListT != null,null, "Unable to Create ArrayListT");
963 pListT->Add(CONTENT_TYPE_IMAGE);
964 pListT->Add(CONTENT_TYPE_VIDEO);
966 result r = directory.Construct(*pListT);
971 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
972 delete pContentIdList;
976 if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
978 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
979 String* pDirPath = null;
980 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
982 int loopCount = pContentDirectoryPathList->GetCount();
983 for (int i = 0; i < loopCount; ++i)
985 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
986 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
992 if(__pAlbumInfoList != null)
994 int loopCount = indexList.GetCount();
995 AlbumInfo* pInfo = null;
996 for (int i = 0; i < loopCount; ++i)
998 int index = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
999 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
1003 IList* pList = pInfo->GetContentIdListN();
1006 pContentIdList->AddItems(*pList);
1012 return pContentIdList;
1016 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
1018 AppLogDebug("ENTER");
1019 if (&eventArg != null)
1021 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
1022 if (pThumbnailEventArg == null)
1024 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1028 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
1029 if (pThumbnailInfo == null)
1031 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1036 ContentId contentId = pThumbnailInfo->GetContentId();
1037 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1039 if (__pAlbumInfoList != null)
1041 int outterLoopCount = __pAlbumInfoList->GetCount();
1042 for (int x = 0; x < outterLoopCount; ++x)
1044 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1045 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1046 for (int i = 0; i < innerLoopCount; ++i)
1048 if (i >= FOLDER_BITMAP_MAX)
1053 if (contentId == pAlbumInfo->GetContentId(i))
1055 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1057 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1058 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1065 delete pThumbnailInfo;
1067 if (__pPresentationModelListener->GetCount() > 0)
1069 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1070 while (pEnum->MoveNext() == E_SUCCESS)
1072 IAlbumEventListener* pListener = null;
1073 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1075 int loopCount = pUpdateFolderIndex->GetCount();
1076 for (int k = 0; k < loopCount; ++k)
1078 Integer *pIndex = (Integer*)pUpdateFolderIndex->GetAt(k);
1079 int folderIndex = pIndex->ToInt();
1080 pListener->OnThumbnailDecoded(folderIndex);
1086 delete pUpdateFolderIndex;
1088 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1092 AlbumListPresentationModel::OnContentCreated(void)
1094 AppLogDebug("ENTER");
1095 if (__updateProgressStatus == true)
1097 AppLogDebug("EXIT update in application");
1100 IFormContentUpdateEventListener* pInterface = null;
1101 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1102 while (pEventEnum->MoveNext() == E_SUCCESS)
1104 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1105 if (pInterface != null)
1107 pInterface->OnContentUpdated();
1111 AppLogDebug("EXIT");
1115 AlbumListPresentationModel::OnContentUpdated(void)
1117 AppLogDebug("ENTER");
1118 if (__updateProgressStatus == true)
1120 AppLogDebug("EXIT update in application");
1123 IFormContentUpdateEventListener* pInterface = null;
1124 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1125 while (pEventEnum->MoveNext() == E_SUCCESS)
1127 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1128 pInterface->OnContentUpdated();
1131 AppLogDebug("EXIT");
1135 AlbumListPresentationModel::OnContentDeleted(void)
1137 AppLogDebug("ENTER");
1138 if (__updateProgressStatus == true)
1140 AppLogDebug("EXIT update in application");
1143 IFormContentUpdateEventListener* pInterface = null;
1144 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1145 while (pEventEnum->MoveNext() == E_SUCCESS)
1147 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1148 pInterface->OnContentUpdated();
1151 AppLogDebug("EXIT");
1155 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1157 AppLogDebug("ENTER");
1158 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1162 AlbumListPresentationModel::SetUpdateProgressStatus(const bool status)
1164 AppLogDebug("ENTER status = %d",status);
1165 __updateProgressStatus = status;
1166 AppLogDebug("EXIT");
1170 AlbumListPresentationModel::RotateImage(int index, RotateMode rotateMode)
1176 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, const int pathIndex)
1178 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1180 ContentId contentId;
1181 if (__pAlbumInfoList != null)
1183 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1184 contentId = pAlbumInfo->GetContentId(pathIndex);
1187 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1188 AppLogDebug("EXIT");
1192 AlbumListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
1194 AppLogDebug("ENTER");
1195 if (__pThumbnailProvider != null)
1197 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1199 AppLogDebug("EXIT");