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 "GlGalleryApp.h"
31 #include "GlThumbnailEvent.h"
32 #include "GlThumbnailEventArg.h"
33 #include "GlThumbnailProvider.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::Base::Utility;
40 using namespace Tizen::Content;
41 using namespace Tizen::Graphics;
42 using namespace Tizen::Io;
43 using namespace Tizen::Media;
44 using namespace Tizen::System;
45 using namespace Tizen::Ui::Controls;
47 static const int ICON_CAP = 3;
48 static const int FOLDER_CAP = 8;
49 static const int ICON_SIZE = 107;
50 static const int FOLDER_SIZE_WIDTH = 348;
51 static const int FOLDER_SIZE_HEIGHT = 348;
53 static const int CANVAS_HEIGHT = 71;
54 static const int CANVAS_WIDTH = 326;
56 static const int FONT_SIZE_FOLDER_NAME = 32;
57 static const int FONT_SIZE_FOLDER_DATE = 25;
58 static const int FONT_SIZE_FOLDER_COUNT = 45;
59 static const int FONT_SIZE_FOLDER_COUNT_SMALL = 35;
61 static const int CANVAS_IMAGE_FOLDER_HEIGHT = 48;
62 static const int CANVAS_IMAGE_FOLDER_WIDTH = 48;
63 static const int IMAGE_COUNT_WIDTH = 100;
64 static const int IMAGE_COUNT_HEIGHT = 60;
65 static const int CANVAS_MARGIN_LEFT = 10;
66 static const int GAP = 10;
67 static const int HEIGHT_OFFSET = 5;
68 static const int Y_POS_CANVAS = 260;
69 static const int FOLDER_NAME_WIDTH = 165;
70 static const int FOLDER_NAME_HEIGHT = 38 ;
73 static const int ALPHA_BG = 110;
75 static const Color COLOR_CANVAS_BG (Color::GetColor(COLOR_ID_BLACK));
77 static const String RESERVED_MEDIA_PATH = Environment::GetMediaPath();
78 static const String RESERVED_CAMERA_PATH = Environment::GetMediaPath() + L"Camera";
79 static const String RESERVED_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera";
80 static const String RESERVED_DOWNLOAD_PATH = Environment::GetMediaPath() + L"Downloads";
81 static const String CONTENT_INFO_ORDER = L"ContentFileName";
83 static const int FORMAT_BUFFER_SIZE = 256;
85 static const int DOUBLE_NUMBER = 2;
86 static const int TRIPLE_NUMBER = 3;
88 AlbumListPresentationModel* AlbumListPresentationModel::__pPresentationModelInstance = null;
89 ArrayList* AlbumListPresentationModel::__pPresentationModelListener = null;
90 ArrayList* AlbumListPresentationModel::__pContentEventListener = null;
91 ThumbnailProvider* AlbumListPresentationModel::__pThumbnailProvider = null;
92 ThumbnailEvent* AlbumListPresentationModel::__pThumbnailEvent = null;
93 IList* AlbumListPresentationModel::__pAlbumInfoList = null;
95 AlbumListPresentationModel::AlbumListPresentationModel(void)
96 : __pFolderBackgroundBitmap(null)
97 , __pContentManager(null)
98 , __pAlbumListener(null)
99 , __appControlMode(APPCONTROL_MODE_MAIN)
100 , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
101 , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
102 , __updateProgressStatus(false)
104 AppLogDebug("ENTER");
105 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
108 AlbumListPresentationModel::~AlbumListPresentationModel(void)
110 AppLogDebug("ENTER");
111 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
112 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
115 AlbumListPresentationModel*
116 AlbumListPresentationModel::GetInstance(void)
118 AppLogDebug("ENTER");
119 if (__pPresentationModelInstance == null)
123 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
125 return __pPresentationModelInstance;
129 AlbumListPresentationModel::Construct(void)
131 AppLogDebug("ENTER");
132 __pPresentationModelListener = new (std::nothrow) ArrayList();
133 __pPresentationModelListener->Construct();
135 ContentUpdateEventListener::GetInstance();
136 __pContentEventListener = new (std::nothrow) ArrayList();
137 __pContentEventListener->Construct();
139 IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
140 __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
141 __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
143 __pContentManager = new (std::nothrow) ContentManager();
144 __pContentManager->Construct();
146 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
148 __pThumbnailProvider = ThumbnailProvider::GetInstance();
149 AppLogDebug("ENTER1");
150 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
151 const IMap* pArguments = pApp->GetAppControlArguments();
152 String operationId = pApp->GetAppControlOperationId();
154 if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
156 __appControlMode = APPCONTROL_MODE_MAIN;
158 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
160 __appControlMode = APPCONTROL_MODE_PICK;
162 String mimeType = pApp->GetMimeType();
163 if (mimeType.IsEmpty() != true)
165 if (mimeType.StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
167 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
170 if (pArguments != null)
172 const String* selectionMode =
173 static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
174 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
176 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
180 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
182 __appControlMode = APPCONTROL_MODE_SETTING;
185 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
191 AlbumListPresentationModel::CreateInstance(void)
193 AppLogDebug("ENTER");
194 __pPresentationModelInstance = new (std::nothrow) AlbumListPresentationModel;
195 result r = __pPresentationModelInstance->Construct();
197 if (IsFailed(r) == true)
199 delete __pPresentationModelInstance;
200 __pPresentationModelInstance = null;
201 AppLogDebug("EXIT false");
204 std::atexit(DestroyInstance);
205 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
209 AlbumListPresentationModel::DestroyInstance(void)
211 AppLogDebug("ENTER");
213 delete __pThumbnailEvent;
214 __pThumbnailEvent = null;
216 if (__pAlbumInfoList != null)
218 delete __pAlbumInfoList;
219 __pAlbumInfoList = null;
222 if (__pPresentationModelListener != null)
224 delete __pPresentationModelListener;
225 __pPresentationModelListener = null;
228 if (__pContentEventListener != null)
230 delete __pContentEventListener;
231 __pContentEventListener = null;
234 delete __pPresentationModelInstance;
235 __pPresentationModelInstance = null;
237 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
241 AlbumListPresentationModel::AddPresentationModelListener(IAlbumEventListener* listener)
243 AppLogDebug("ENTER");
244 result r = __pPresentationModelListener->Add(listener);
245 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
251 AlbumListPresentationModel::RemovePresentationModelListener(IAlbumEventListener& listner)
253 AppLogDebug("ENTER");
254 result r = __pPresentationModelListener->Remove(listner);
255 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
261 AlbumListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
263 AppLogDebug("ENTER");
264 if (__pContentEventListener != null)
266 __pContentEventListener->RemoveAll();
267 __pContentEventListener->Add((Object*)listener);
268 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
273 AlbumListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener& listener)
275 AppLogDebug("ENTER");
276 __pContentEventListener->Remove(listener);
277 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
281 AlbumListPresentationModel::CallAlbumChangedEvent(void)
283 AppLogDebug("ENTER");
284 if (__pPresentationModelListener->GetCount() > 0)
286 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
288 while (pEnum->MoveNext() == E_SUCCESS)
290 IAlbumEventListener* pListener = null;
291 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
292 pListener->OnFileInfoChanged(CONTENT_TYPE_ALL);
297 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
301 AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& newPath,
302 IAlbumRenameEventListener* pAlbumListener)
304 AppLogDebug("ENTER");
305 result r = Directory::Rename(orgPath, newPath);
308 AppLogDebug("Album Rename failed(%s)", GetErrorMessage(r));
312 __pAlbumListener = pAlbumListener;
313 __renameNewPath = newPath;
\r
314 r = ContentManager::ScanDirectory(newPath, true, NULL, __reqId);
\r
315 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
316 r = ContentManager::ScanDirectory(orgPath, true, NULL, __reqId);
\r
317 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
323 void AlbumListPresentationModel::OnContentScanCompleted (const Tizen::Base::String &scanPath)
\r
325 AppLogDebug("ENTER");
\r
326 if (__pAlbumListener && ( scanPath == __renameNewPath))
\r
328 InitializeAlbumInfoList(CONTENT_TYPE_ALL);
329 __pAlbumListener->OnAlbumRenameComplete();
330 __renameNewPath = L"";
336 AlbumListPresentationModel::DrawPartialImage(Canvas& canvas, AlbumInfo* pAlbumInfo, const Rectangle& rectNew)
338 AppLogDebug("ENTER");
339 if (&canvas == null || __pFolderBackgroundBitmap == null || pAlbumInfo == null)
341 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
345 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
347 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
351 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
352 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
353 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
354 canvas.DrawBitmap(rectFirst, *pBitmap);
357 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
361 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
363 AppLogDebug("ENTER");
367 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
374 Bitmap* pBitmap = null;
375 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
377 EnrichedText enTextCount;
378 TextElement textElement;
379 TextElement textElementCount;
381 int allContentCount = pAlbumInfo->GetContentIdCount();
382 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
384 String strFolderName = pAlbumInfo->GetAlbumName();
386 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
387 Color bgColor(COLOR_CANVAS_BG);
388 bgColor.SetAlpha(ALPHA_BG);
389 canvas.FillRectangle(bgColor, rectCanvas);
391 if (strFolderName == ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"))
393 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
395 else if (strFolderName == ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"))
397 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
401 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
406 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
407 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
411 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
412 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
413 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
414 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
416 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
417 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
419 textElement.Construct(strFolderName);
420 textElement.SetFont(ftFolderName);
421 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
422 enText.SetTextAbbreviationEnabled(true);
423 enText.Add(textElement);
425 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
426 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
428 textElementCount.Construct(strCnt);
430 if (strCnt.GetLength() > 3)
432 textElementCount.SetFont(ftCntSmall);
436 textElementCount.SetFont(ftCnt);
438 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
439 enTextCount.SetTextAbbreviationEnabled(true);
440 enTextCount.Add(textElementCount);
442 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH , rectCanvas.y + HEIGHT_OFFSET);
443 canvas.SetFont(ftCnt);
444 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
445 canvas.DrawText(pointText, enTextCount);
447 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP , rectCanvas.y + GAP + HEIGHT_OFFSET);
448 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
449 canvas.DrawText(pointText, enText);
451 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
455 AlbumListPresentationModel::CreateMergeBitmapN(const int index)
457 AppLogDebug("ENTER index(%d)", index);
459 if (__pAlbumInfoList == null)
461 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
466 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
468 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
469 BufferInfo bufferinfo;
471 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
472 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
474 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
478 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
483 pBitmapNew->Lock(bufferinfo);
484 r = canvas.Construct(bufferinfo);
488 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
493 DrawPartialImage(canvas, pAlbumInfo, rectNew);
494 DrawFontImage(canvas, pAlbumInfo, index);
496 pBitmapNew->Unlock();
497 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
503 AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
504 const String* pUriData, const String* pMimeType, const HashMap* pDataList,
505 IAppControlResponseListener* pListener)
507 AppLogDebug("ENTER");
508 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
511 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
515 result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
519 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
520 pGalleryApp->SetFrameEnabled(false);
525 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
531 AlbumListPresentationModel::GetDirectoryName(String& directoryPath) const
533 AppLogDebug("ENTER");
534 String directoryName;
537 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
538 directoryPath.SubString(lastIndex + 1, directoryName);
539 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
541 return directoryName;
545 AlbumListPresentationModel::GetFolderCount(void) const
547 AppLogDebug("ENTER");
548 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
550 return __pAlbumInfoList->GetCount();
554 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
556 AppLogDebug("ENTER");
558 if (__pFolderBackgroundBitmap == null)
560 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
563 if (__pAlbumInfoList != null)
565 AlbumInfo* pInfo = null;
566 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
568 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
569 if (pInfo->GetAlbumName().IsEmpty() == false)
571 AppLog("Print AlbumName(%d)(%ls)", i, pInfo->GetAlbumName().GetPointer());
574 delete __pAlbumInfoList;
576 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
578 ContentDirectory directory;
580 if (contentType == CONTENT_TYPE_ALL)
582 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
583 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
584 pListT->Add(CONTENT_TYPE_IMAGE);
585 pListT->Add(CONTENT_TYPE_VIDEO);
587 result r = directory.Construct(*pListT);
592 delete __pAlbumInfoList;
593 __pAlbumInfoList = null;
594 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
600 result r = directory.Construct(contentType);
603 delete __pAlbumInfoList;
604 __pAlbumInfoList = null;
605 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
610 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
611 String* pDirPath = null;
612 AlbumInfo* pAlbumInfo = null;
614 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
615 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
616 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
617 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
619 result r = pAllAlbumInfo->Construct();
620 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
621 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
623 r = pCameraAlbumInfo->Construct();
624 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
625 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
627 r = pDownloadAlbumInfo->Construct();
628 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
629 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
631 r = pNoNameAlbumInfo->Construct();
632 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
633 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
635 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
637 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
638 while (pEnum->MoveNext() == E_SUCCESS)
640 pDirPath = static_cast<String*>(pEnum->GetCurrent());
641 String mediaPath = RESERVED_MEDIA_PATH;
642 int length = mediaPath.GetLength();
643 mediaPath.Remove(length-1,1);
645 if (pDirPath == null)
650 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
652 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
654 if (pContentIdList != null)
656 pCameraAlbumInfo->AppendDirectory(*pDirPath);
657 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
659 pAllAlbumInfo->AppendDirectory(*pDirPath);
660 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
661 delete pContentIdList;
664 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
666 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
668 if (pContentIdList != null)
670 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
671 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
673 pAllAlbumInfo->AppendDirectory(*pDirPath);
674 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
675 delete pContentIdList;
678 else if (*pDirPath == mediaPath)
680 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
682 if (pContentIdList != null)
684 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
685 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
687 pAllAlbumInfo->AppendDirectory(*pDirPath);
688 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
689 delete pContentIdList;
694 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
696 if (pContentIdList != null)
698 if (pContentIdList->GetCount() > 0)
700 pAlbumInfo = new (std::nothrow) AlbumInfo();
701 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
703 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
705 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
708 pAllAlbumInfo->AppendDirectory(*pDirPath);
709 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
712 delete pContentIdList;
714 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
716 __pAlbumInfoList->Add(pAlbumInfo);
727 if (pAllAlbumInfo->GetContentIdCount() > 0)
729 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
733 delete pAllAlbumInfo;
736 if (pCameraAlbumInfo->GetContentIdCount() > 0)
738 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
742 delete pCameraAlbumInfo;
745 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
747 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
751 delete pDownloadAlbumInfo;
754 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
756 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
760 delete pNoNameAlbumInfo;
767 delete pAllAlbumInfo;
768 delete pCameraAlbumInfo;
769 delete pDownloadAlbumInfo;
770 delete pNoNameAlbumInfo;
773 if (pContentDirectoryPathList != null)
775 delete pContentDirectoryPathList;
777 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
781 if (pContentDirectoryPathList != null)
783 delete pContentDirectoryPathList;
785 if (pAllAlbumInfo != null)
787 delete pAllAlbumInfo;
789 if (pCameraAlbumInfo != null)
791 delete pCameraAlbumInfo;
793 if (pDownloadAlbumInfo != null)
795 delete pDownloadAlbumInfo;
797 if (pNoNameAlbumInfo != null)
799 delete pNoNameAlbumInfo;
804 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
806 AppLogDebug("ENTER");
807 if (fullPath == null)
809 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
813 String delim(DIRECTORY_SEPARATOR);
814 StringTokenizer st(fullPath,delim);
816 while (st.HasMoreTokens())
818 st.GetNextToken(token);
820 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
826 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
828 AppLogDebug("ENTER");
830 if (&directoryPath == null)
832 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
836 ContentDirectory directory;
837 const String contentDirectoryPath = directoryPath;
838 if (contentType == CONTENT_TYPE_ALL)
840 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
841 pListT->Add(CONTENT_TYPE_IMAGE);
842 pListT->Add(CONTENT_TYPE_VIDEO);
843 result r = directory.Construct(*pListT);
847 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
853 result r = directory.Construct(contentType);
856 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
862 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
863 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
864 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
865 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
867 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
869 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
871 while (pEnum->MoveNext() == E_SUCCESS)
873 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
874 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
875 pContentIdList->Add(pItem);
879 delete pContentInfoList;
880 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
882 return pContentIdList;
886 AlbumListPresentationModel::DeleteContentFile(const ContentId& contentId)
888 AppLogDebug("ENTER");
889 result r = E_SUCCESS;
890 ContentManager contentManager;
891 r = contentManager.Construct();
894 r = contentManager.DeleteContent(contentId);
896 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
902 AlbumListPresentationModel::GetAppControlMode(void) const
904 AppLogDebug("Enter");
906 return __appControlMode;
910 AlbumListPresentationModel::GetAppControlMediaType(void) const
912 AppLogDebug("Enter");
914 return __appControlMediaType;
917 AppControlSelectionMode
918 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
920 AppLogDebug("Enter");
922 return __appControlSelectionMode;
926 AlbumListPresentationModel::GetAlbumInfoList(void) const
928 AppLogDebug("ENTER");
929 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
931 return __pAlbumInfoList;
934 IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
936 AppLogDebug("ENTER");
937 ContentDirectory directory;
938 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
940 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
941 TryReturn(pListT != null,null, "Unable to Create ArrayListT");
942 pListT->Add(CONTENT_TYPE_IMAGE);
943 pListT->Add(CONTENT_TYPE_VIDEO);
945 result r = directory.Construct(*pListT);
950 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
951 delete pContentIdList;
955 if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
957 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
958 String* pDirPath = null;
959 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
961 int loopCount = pContentDirectoryPathList->GetCount();
962 for (int i = 0; i < loopCount; ++i)
964 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
965 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
971 if(__pAlbumInfoList != null)
973 int loopCount = indexList.GetCount();
974 AlbumInfo* pInfo = null;
975 for (int i = 0; i < loopCount; ++i)
977 int index = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
978 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
982 IList* pList = pInfo->GetContentIdListN();
985 pContentIdList->AddItems(*pList);
991 return pContentIdList;
995 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
997 AppLogDebug("ENTER");
998 if (&eventArg != null)
1000 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
1001 if (pThumbnailEventArg == null)
1003 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1007 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
1008 if (pThumbnailInfo == null)
1010 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1015 ContentId contentId = pThumbnailInfo->GetContentId();
1016 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1018 if (__pAlbumInfoList != null)
1020 int outterLoopCount = __pAlbumInfoList->GetCount();
1021 for (int x = 0; x < outterLoopCount; ++x)
1023 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1024 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1025 for (int i = 0; i < innerLoopCount; ++i)
1027 if (i >= FOLDER_BITMAP_MAX)
1032 if (contentId == pAlbumInfo->GetContentId(i))
1034 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1036 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1037 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1044 if (__pPresentationModelListener->GetCount() > 0)
1046 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1047 while (pEnum->MoveNext() == E_SUCCESS)
1049 IAlbumEventListener* pListener = null;
1050 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1052 int loopCount = pUpdateFolderIndex->GetCount();
1053 for (int k = 0; k < loopCount; ++k)
1055 Integer *pIndex = (Integer*)pUpdateFolderIndex->GetAt(k);
1056 int folderIndex = pIndex->ToInt();
1057 pListener->OnThumbnailDecoded(folderIndex);
1063 delete pUpdateFolderIndex;
1065 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1069 AlbumListPresentationModel::OnContentCreated(void)
1071 AppLogDebug("ENTER");
1072 if (__updateProgressStatus == true)
1074 AppLogDebug("EXIT update in application");
1077 IFormContentUpdateEventListener* pInterface = null;
1078 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1079 while (pEventEnum->MoveNext() == E_SUCCESS)
1081 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1082 if (pInterface != null)
1084 pInterface->OnContentUpdated();
1088 AppLogDebug("EXIT");
1092 AlbumListPresentationModel::OnContentUpdated(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 pInterface->OnContentUpdated();
1108 AppLogDebug("EXIT");
1112 AlbumListPresentationModel::OnContentDeleted(void)
1114 AppLogDebug("ENTER");
1115 if (__updateProgressStatus == true)
1117 AppLogDebug("EXIT update in application");
1120 IFormContentUpdateEventListener* pInterface = null;
1121 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1122 while (pEventEnum->MoveNext() == E_SUCCESS)
1124 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1125 pInterface->OnContentUpdated();
1128 AppLogDebug("EXIT");
1132 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1134 AppLogDebug("ENTER");
1135 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1139 AlbumListPresentationModel::SetUpdateProgressStatus(const bool status)
1141 AppLogDebug("ENTER status = %d",status);
1142 __updateProgressStatus = status;
1143 AppLogDebug("EXIT");
1147 AlbumListPresentationModel::RotateImage(int index, RotateMode rotateMode)
1153 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, const int pathIndex)
1155 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1157 ContentId contentId;
1158 if (__pAlbumInfoList != null)
1160 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1161 contentId = pAlbumInfo->GetContentId(pathIndex);
1164 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1165 AppLogDebug("EXIT");
1169 AlbumListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
1171 AppLogDebug("ENTER");
1172 if (__pThumbnailProvider != null)
1174 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1176 AppLogDebug("EXIT");