2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file 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 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
114 AlbumListPresentationModel*
115 AlbumListPresentationModel::GetInstance(void)
117 AppLogDebug("ENTER");
118 if (__pPresentationModelInstance == null)
122 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
124 return __pPresentationModelInstance;
128 AlbumListPresentationModel::Construct(void)
130 AppLogDebug("ENTER");
131 __pPresentationModelListener = new (std::nothrow) ArrayList();
132 __pPresentationModelListener->Construct();
134 ContentUpdateEventListener::GetInstance();
135 __pContentEventListener = new (std::nothrow) ArrayList();
136 __pContentEventListener->Construct();
138 IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
139 __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
140 __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
142 __pContentManager = new (std::nothrow) ContentManager();
143 __pContentManager->Construct();
145 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
147 __pThumbnailProvider = ThumbnailProvider::GetInstance();
148 AppLogDebug("ENTER1");
149 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
150 const IMap* pArguments = pApp->GetAppControlArguments();
151 String operationId = pApp->GetAppControlOperationId();
153 if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
155 __appControlMode = APPCONTROL_MODE_MAIN;
157 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
159 __appControlMode = APPCONTROL_MODE_PICK;
161 String mimeType = pApp->GetMimeType();
162 if (mimeType.IsEmpty() != true)
164 if (mimeType.StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
166 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
169 if (pArguments != null)
171 const String* selectionMode =
172 static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
173 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
175 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
179 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
181 __appControlMode = APPCONTROL_MODE_SETTING;
184 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
190 AlbumListPresentationModel::CreateInstance(void)
192 AppLogDebug("ENTER");
193 __pPresentationModelInstance = new (std::nothrow) AlbumListPresentationModel;
194 result r = __pPresentationModelInstance->Construct();
196 if (IsFailed(r) == true)
198 delete __pPresentationModelInstance;
199 __pPresentationModelInstance = null;
200 AppLogDebug("EXIT false");
203 std::atexit(DestroyInstance);
204 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
208 AlbumListPresentationModel::DestroyInstance(void)
210 AppLogDebug("ENTER");
212 delete __pThumbnailEvent;
213 __pThumbnailEvent = null;
215 if (__pAlbumInfoList != null)
217 delete __pAlbumInfoList;
218 __pAlbumInfoList = null;
221 if (__pPresentationModelListener != null)
223 delete __pPresentationModelListener;
224 __pPresentationModelListener = null;
227 if (__pContentEventListener != null)
229 delete __pContentEventListener;
230 __pContentEventListener = null;
233 delete __pPresentationModelInstance;
234 __pPresentationModelInstance = null;
236 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
240 AlbumListPresentationModel::AddPresentationModelListener(IAlbumEventListener* listener)
242 AppLogDebug("ENTER");
243 result r = __pPresentationModelListener->Add(listener);
244 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
250 AlbumListPresentationModel::RemovePresentationModelListener(IAlbumEventListener& listner)
252 AppLogDebug("ENTER");
253 result r = __pPresentationModelListener->Remove(listner);
254 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
260 AlbumListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
262 AppLogDebug("ENTER");
263 if (__pContentEventListener != null)
265 __pContentEventListener->RemoveAll();
266 __pContentEventListener->Add((Object*)listener);
267 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
272 AlbumListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener& listener)
274 AppLogDebug("ENTER");
275 __pContentEventListener->Remove(listener);
276 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
280 AlbumListPresentationModel::CallAlbumChangedEvent(void)
282 AppLogDebug("ENTER");
283 if (__pPresentationModelListener->GetCount() > 0)
285 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
287 while (pEnum->MoveNext() == E_SUCCESS)
289 IAlbumEventListener* pListener = null;
290 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
291 pListener->OnFileInfoChanged(CONTENT_TYPE_ALL);
296 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
300 AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& newPath,
301 IAlbumRenameEventListener* pAlbumListener)
303 AppLogDebug("ENTER");
304 result r = Directory::Rename(orgPath, newPath);
307 AppLogDebug("Album Rename failed(%s)", GetErrorMessage(r));
311 __pAlbumListener = pAlbumListener;
312 if (orgPath.Contains(Tizen::System::Environment::GetMediaPath()))
314 r = ContentManager::ScanDirectory(Tizen::System::Environment::GetMediaPath(), true, this, __reqId);
316 else if (orgPath.Contains(Tizen::System::Environment::GetExternalStoragePath()))
318 r = ContentManager::ScanDirectory(Tizen::System::Environment::GetExternalStoragePath(), true, this, __reqId);
320 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
326 void AlbumListPresentationModel::OnContentScanCompleted (RequestId reqId, const Tizen::Base::String &scanPath, result r)
328 AppLogDebug("ENTER");
329 if (__pAlbumListener && __reqId == reqId)
331 InitializeAlbumInfoList(CONTENT_TYPE_ALL);
332 __pAlbumListener->OnAlbumRenameComplete();
338 AlbumListPresentationModel::DrawPartialImage(Canvas& canvas, AlbumInfo* pAlbumInfo, const Rectangle& rectNew)
340 AppLogDebug("ENTER");
341 if (&canvas == null || __pFolderBackgroundBitmap == null || pAlbumInfo == null)
343 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
347 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
349 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
353 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
354 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
355 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
356 canvas.DrawBitmap(rectFirst, *pBitmap);
359 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
363 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
365 AppLogDebug("ENTER");
369 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
376 Bitmap* pBitmap = null;
377 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
379 EnrichedText enTextCount;
380 TextElement textElement;
381 TextElement textElementCount;
383 int allContentCount = pAlbumInfo->GetContentIdCount();
384 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
386 String strFolderName = pAlbumInfo->GetAlbumName();
388 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
389 Color bgColor(COLOR_CANVAS_BG);
390 bgColor.SetAlpha(ALPHA_BG);
391 canvas.FillRectangle(bgColor, rectCanvas);
393 if (strFolderName == ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"))
395 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
397 else if (strFolderName == ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"))
399 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
403 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
408 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
409 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
413 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
414 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
415 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
416 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
418 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
419 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
421 textElement.Construct(strFolderName);
422 textElement.SetFont(ftFolderName);
423 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
424 enText.SetTextAbbreviationEnabled(true);
425 enText.Add(textElement);
427 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
428 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
430 textElementCount.Construct(strCnt);
432 if (strCnt.GetLength() > 3)
434 textElementCount.SetFont(ftCntSmall);
438 textElementCount.SetFont(ftCnt);
440 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
441 enTextCount.SetTextAbbreviationEnabled(true);
442 enTextCount.Add(textElementCount);
444 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH , rectCanvas.y + HEIGHT_OFFSET);
445 canvas.SetFont(ftCnt);
446 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
447 canvas.DrawText(pointText, enTextCount);
449 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP , rectCanvas.y + GAP + HEIGHT_OFFSET);
450 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
451 canvas.DrawText(pointText, enText);
453 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
457 AlbumListPresentationModel::CreateMergeBitmapN(const int index)
459 AppLogDebug("ENTER index(%d)", index);
461 if (__pAlbumInfoList == null)
463 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
468 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
470 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
471 BufferInfo bufferinfo;
473 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
474 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
476 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
480 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
485 pBitmapNew->Lock(bufferinfo);
486 r = canvas.Construct(bufferinfo);
490 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
495 DrawPartialImage(canvas, pAlbumInfo, rectNew);
496 DrawFontImage(canvas, pAlbumInfo, index);
498 pBitmapNew->Unlock();
499 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
505 AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
506 const String* pUriData, const String* pMimeType, const HashMap* pDataList,
507 IAppControlResponseListener* pListener)
509 AppLogDebug("ENTER");
510 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
513 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
517 result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
521 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
522 pGalleryApp->SetFrameEnabled(false);
527 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
533 AlbumListPresentationModel::GetDirectoryName(String& directoryPath) const
535 AppLogDebug("ENTER");
536 String directoryName;
539 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
540 directoryPath.SubString(lastIndex + 1, directoryName);
541 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
543 return directoryName;
547 AlbumListPresentationModel::GetFolderCount(void) const
549 AppLogDebug("ENTER");
550 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
552 return __pAlbumInfoList->GetCount();
556 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
558 AppLogDebug("ENTER");
560 if (__pFolderBackgroundBitmap == null)
562 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
565 if (__pAlbumInfoList != null)
567 AlbumInfo* pInfo = null;
568 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
570 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
571 if (pInfo->GetAlbumName().IsEmpty() == false)
573 AppLog("Print AlbumName(%d)(%ls)", i, pInfo->GetAlbumName().GetPointer());
576 delete __pAlbumInfoList;
578 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
580 ContentDirectory directory;
582 if (contentType == CONTENT_TYPE_ALL)
584 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
585 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
586 pListT->Add(CONTENT_TYPE_IMAGE);
587 pListT->Add(CONTENT_TYPE_VIDEO);
589 result r = directory.Construct(*pListT);
594 delete __pAlbumInfoList;
595 __pAlbumInfoList = null;
596 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
602 result r = directory.Construct(contentType);
605 delete __pAlbumInfoList;
606 __pAlbumInfoList = null;
607 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
612 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
613 String* pDirPath = null;
614 AlbumInfo* pAlbumInfo = null;
616 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
617 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
618 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
619 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
621 result r = pAllAlbumInfo->Construct();
622 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
623 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
625 r = pCameraAlbumInfo->Construct();
626 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
627 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
629 r = pDownloadAlbumInfo->Construct();
630 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
631 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
633 r = pNoNameAlbumInfo->Construct();
634 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
635 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
637 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
639 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
640 while (pEnum->MoveNext() == E_SUCCESS)
642 pDirPath = static_cast<String*>(pEnum->GetCurrent());
643 if (pDirPath == null)
648 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
650 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
652 if (pContentIdList != null)
654 pCameraAlbumInfo->AppendDirectory(*pDirPath);
655 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
657 pAllAlbumInfo->AppendDirectory(*pDirPath);
658 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
659 delete pContentIdList;
662 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
664 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
666 if (pContentIdList != null)
668 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
669 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
671 pAllAlbumInfo->AppendDirectory(*pDirPath);
672 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
673 delete pContentIdList;
676 else if (*pDirPath == RESERVED_MEDIA_PATH)
678 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
680 if (pContentIdList != null)
682 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
683 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
685 pAllAlbumInfo->AppendDirectory(*pDirPath);
686 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
687 delete pContentIdList;
692 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
694 if (pContentIdList != null)
696 if (pContentIdList->GetCount() > 0)
698 pAlbumInfo = new (std::nothrow) AlbumInfo();
699 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
701 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
703 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
706 pAllAlbumInfo->AppendDirectory(*pDirPath);
707 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
710 delete pContentIdList;
712 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
714 __pAlbumInfoList->Add(pAlbumInfo);
725 if (pAllAlbumInfo->GetContentIdCount() > 0)
727 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
731 delete pAllAlbumInfo;
734 if (pCameraAlbumInfo->GetContentIdCount() > 0)
736 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
740 delete pCameraAlbumInfo;
743 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
745 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
749 delete pDownloadAlbumInfo;
752 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
754 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
758 delete pNoNameAlbumInfo;
765 delete pAllAlbumInfo;
766 delete pCameraAlbumInfo;
767 delete pDownloadAlbumInfo;
768 delete pNoNameAlbumInfo;
771 if (pContentDirectoryPathList != null)
773 delete pContentDirectoryPathList;
775 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
779 if (pContentDirectoryPathList != null)
781 delete pContentDirectoryPathList;
783 if (pAllAlbumInfo != null)
785 delete pAllAlbumInfo;
787 if (pCameraAlbumInfo != null)
789 delete pCameraAlbumInfo;
791 if (pDownloadAlbumInfo != null)
793 delete pDownloadAlbumInfo;
795 if (pNoNameAlbumInfo != null)
797 delete pNoNameAlbumInfo;
802 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
804 AppLogDebug("ENTER");
805 if (fullPath == null)
807 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
811 String delim(DIRECTORY_SEPARATOR);
812 StringTokenizer st(fullPath,delim);
814 while (st.HasMoreTokens())
816 st.GetNextToken(token);
818 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
824 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
826 AppLogDebug("ENTER");
828 if (&directoryPath == null)
830 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
834 ContentDirectory directory;
835 const String contentDirectoryPath = directoryPath;
836 if (contentType == CONTENT_TYPE_ALL)
838 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
839 pListT->Add(CONTENT_TYPE_IMAGE);
840 pListT->Add(CONTENT_TYPE_VIDEO);
841 result r = directory.Construct(*pListT);
845 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
851 result r = directory.Construct(contentType);
854 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
860 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
861 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
862 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
863 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
865 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
867 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
869 while (pEnum->MoveNext() == E_SUCCESS)
871 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
872 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
873 pContentIdList->Add(pItem);
877 delete pContentInfoList;
878 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
880 return pContentIdList;
884 AlbumListPresentationModel::DeleteContentFile(const ContentId& contentId)
886 AppLogDebug("ENTER");
887 result r = E_SUCCESS;
888 ContentManager contentManager;
889 r = contentManager.Construct();
892 r = contentManager.DeleteContent(contentId);
894 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
900 AlbumListPresentationModel::GetAppControlMode(void) const
902 AppLogDebug("Enter");
904 return __appControlMode;
908 AlbumListPresentationModel::GetAppControlMediaType(void) const
910 AppLogDebug("Enter");
912 return __appControlMediaType;
915 AppControlSelectionMode
916 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
918 AppLogDebug("Enter");
920 return __appControlSelectionMode;
924 AlbumListPresentationModel::GetAlbumInfoList(void) const
926 AppLogDebug("ENTER");
927 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
929 return __pAlbumInfoList;
932 IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
934 AppLogDebug("ENTER");
935 ContentDirectory directory;
936 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
938 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
939 TryReturn(pListT != null,null, "Unable to Create ArrayListT");
940 pListT->Add(CONTENT_TYPE_IMAGE);
941 pListT->Add(CONTENT_TYPE_VIDEO);
943 result r = directory.Construct(*pListT);
948 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
949 delete pContentIdList;
953 if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
955 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
956 String* pDirPath = null;
957 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
959 int loopCount = pContentDirectoryPathList->GetCount();
960 for (int i = 0; i < loopCount; ++i)
962 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
963 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
969 if(__pAlbumInfoList != null)
971 int loopCount = indexList.GetCount();
972 AlbumInfo* pInfo = null;
973 for (int i = 0; i < loopCount; ++i)
975 int index = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
976 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
980 IList* pList = pInfo->GetContentIdListN();
983 pContentIdList->AddItems(*pList);
989 return pContentIdList;
993 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
995 AppLogDebug("ENTER");
996 if (&eventArg != null)
998 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
999 if (pThumbnailEventArg == null)
1001 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1005 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
1006 if (pThumbnailInfo == null)
1008 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1013 ContentId contentId = pThumbnailInfo->GetContentId();
1014 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1016 if (__pAlbumInfoList != null)
1018 int outterLoopCount = __pAlbumInfoList->GetCount();
1019 for (int x = 0; x < outterLoopCount; ++x)
1021 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1022 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1023 for (int i = 0; i < innerLoopCount; ++i)
1025 if (i >= FOLDER_BITMAP_MAX)
1030 if (contentId == pAlbumInfo->GetContentId(i))
1032 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1034 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1035 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1042 if (__pPresentationModelListener->GetCount() > 0)
1044 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1045 while (pEnum->MoveNext() == E_SUCCESS)
1047 IAlbumEventListener* pListener = null;
1048 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1050 int loopCount = pUpdateFolderIndex->GetCount();
1051 for (int k = 0; k < loopCount; ++k)
1053 Integer *pIndex = (Integer*)pUpdateFolderIndex->GetAt(k);
1054 int folderIndex = pIndex->ToInt();
1055 pListener->OnThumbnailDecoded(folderIndex);
1061 delete pUpdateFolderIndex;
1063 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1067 AlbumListPresentationModel::OnContentCreated(void)
1069 AppLogDebug("ENTER");
1070 if (__updateProgressStatus == true)
1072 AppLogDebug("EXIT update in application");
1075 IFormContentUpdateEventListener* pInterface = null;
1076 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1077 while (pEventEnum->MoveNext() == E_SUCCESS)
1079 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1080 if (pInterface != null)
1082 pInterface->OnContentUpdated();
1086 AppLogDebug("EXIT");
1090 AlbumListPresentationModel::OnContentUpdated(void)
1092 AppLogDebug("ENTER");
1093 if (__updateProgressStatus == true)
1095 AppLogDebug("EXIT update in application");
1098 IFormContentUpdateEventListener* pInterface = null;
1099 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1100 while (pEventEnum->MoveNext() == E_SUCCESS)
1102 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1103 pInterface->OnContentUpdated();
1106 AppLogDebug("EXIT");
1110 AlbumListPresentationModel::OnContentDeleted(void)
1112 AppLogDebug("ENTER");
1113 if (__updateProgressStatus == true)
1115 AppLogDebug("EXIT update in application");
1118 IFormContentUpdateEventListener* pInterface = null;
1119 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1120 while (pEventEnum->MoveNext() == E_SUCCESS)
1122 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1123 pInterface->OnContentUpdated();
1126 AppLogDebug("EXIT");
1130 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1132 AppLogDebug("ENTER");
1133 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
1135 IFormContentUpdateEventListener* pInterface = null;
1136 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1137 while (pEventEnum->MoveNext() == E_SUCCESS)
1139 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1140 pInterface->OnContentUpdated();
1144 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1148 AlbumListPresentationModel::SetUpdateProgressStatus(const bool status)
1150 AppLogDebug("ENTER status = %d",status);
1151 __updateProgressStatus = status;
1152 AppLogDebug("EXIT");
1156 AlbumListPresentationModel::RotateImage(int index, RotateMode rotateMode)
1162 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, const int pathIndex)
1164 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1166 ContentId contentId;
1167 if (__pAlbumInfoList != null)
1169 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1170 contentId = pAlbumInfo->GetContentId(pathIndex);
1173 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1174 AppLogDebug("EXIT");
1178 AlbumListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
1180 AppLogDebug("ENTER");
1181 if (__pThumbnailProvider != null)
1183 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1185 AppLogDebug("EXIT");