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 , __pAlbumListener(null)
98 , __appControlMode(APP_CONTROL_MODE_MAIN)
99 , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
100 , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
102 AppLogDebug("ENTER");
103 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
106 AlbumListPresentationModel::~AlbumListPresentationModel(void)
108 AppLogDebug("ENTER");
109 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
112 AlbumListPresentationModel*
113 AlbumListPresentationModel::GetInstance(void)
115 AppLogDebug("ENTER");
116 if (__pPresentationModelInstance == null)
120 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
122 return __pPresentationModelInstance;
126 AlbumListPresentationModel::Construct(void)
128 AppLogDebug("ENTER");
129 __pPresentationModelListener = new (std::nothrow) ArrayList();
130 __pPresentationModelListener->Construct();
132 ContentUpdateEventListener::GetInstance();
133 __pContentEventListener = new (std::nothrow) ArrayList();
134 __pContentEventListener->Construct();
136 IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
137 __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
138 __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
140 __pContentManager = new (std::nothrow) ContentManager();
141 __pContentManager->Construct();
143 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
145 __pThumbnailProvider = ThumbnailProvider::GetInstance();
146 AppLogDebug("ENTER1");
147 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
148 const IMap* pArguments = pApp->GetAppControlArguments();
149 String operationId = pApp->GetAppControlOperationId();
151 if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
153 __appControlMode = APP_CONTROL_MODE_MAIN;
155 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
157 __appControlMode = APP_CONTROL_MODE_PICK;
159 String mimeType = pApp->GetMimeType();
160 if (mimeType.IsEmpty() != true)
162 if (mimeType.StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
164 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
167 if (pArguments != null)
169 const String* selectionMode =
170 static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
171 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
173 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
176 if (pApp->GetMimeType().StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
178 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
182 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
184 __appControlMode = APP_CONTROL_MODE_SETTING;
187 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
193 AlbumListPresentationModel::CreateInstance(void)
195 AppLogDebug("ENTER");
196 __pPresentationModelInstance = new (std::nothrow) AlbumListPresentationModel;
197 result r = __pPresentationModelInstance->Construct();
199 if (IsFailed(r) == true)
201 delete __pPresentationModelInstance;
202 __pPresentationModelInstance = null;
203 AppLogDebug("EXIT false");
206 std::atexit(DestroyInstance);
207 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
211 AlbumListPresentationModel::DestroyInstance(void)
213 AppLogDebug("ENTER");
215 delete __pThumbnailEvent;
216 __pThumbnailEvent = null;
218 if (__pAlbumInfoList != null)
220 delete __pAlbumInfoList;
221 __pAlbumInfoList = null;
224 if (__pPresentationModelListener != null)
226 delete __pPresentationModelListener;
227 __pPresentationModelListener = null;
230 if (__pContentEventListener != null)
232 delete __pContentEventListener;
233 __pContentEventListener = null;
236 delete __pPresentationModelInstance;
237 __pPresentationModelInstance = null;
239 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
243 AlbumListPresentationModel::AddPresentationModelListener(IAlbumEventListener* listener)
245 AppLogDebug("ENTER");
246 result r = __pPresentationModelListener->Add(listener);
247 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
253 AlbumListPresentationModel::RemovePresentationModelListener(IAlbumEventListener& listner)
255 AppLogDebug("ENTER");
256 result r = __pPresentationModelListener->Remove(listner);
257 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
263 AlbumListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
265 AppLogDebug("ENTER");
266 if (__pContentEventListener != null)
268 __pContentEventListener->RemoveAll();
269 __pContentEventListener->Add((Object*)listener);
270 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
275 AlbumListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener& listener)
277 AppLogDebug("ENTER");
278 __pContentEventListener->Remove(listener);
279 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
283 AlbumListPresentationModel::CallAlbumChangedEvent(void)
285 AppLogDebug("ENTER");
286 if (__pPresentationModelListener->GetCount() > 0)
288 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
290 while (pEnum->MoveNext() == E_SUCCESS)
292 IAlbumEventListener* pListener = null;
293 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
294 pListener->OnFileInfoChanged(CONTENT_TYPE_ALL);
299 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
303 AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& newPath,
304 IAlbumRenameEventListener* pAlbumListener)
306 AppLogDebug("ENTER");
307 result r = Directory::Rename(orgPath, newPath);
310 AppLogDebug("Album Rename failed(%s)", GetErrorMessage(r));
314 __pAlbumListener = pAlbumListener;
315 r = ContentManager::ScanDirectory(Tizen::System::Environment::GetMediaPath(), true, this, __reqId);
316 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
322 void AlbumListPresentationModel::OnContentScanCompleted (RequestId reqId, const Tizen::Base::String &scanPath, result r)
324 AppLogDebug("ENTER");
325 if (__pAlbumListener && __reqId == reqId)
327 InitializeAlbumInfoList(CONTENT_TYPE_ALL);
328 __pAlbumListener->OnAlbumRenameComplete();
334 AlbumListPresentationModel::DrawPartialImage(Canvas& canvas, AlbumInfo* pAlbumInfo, const Rectangle& rectNew)
336 AppLogDebug("ENTER");
337 if (&canvas == null || __pFolderBackgroundBitmap == null || pAlbumInfo == null)
339 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
343 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
345 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
349 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
350 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
351 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
352 canvas.DrawBitmap(rectFirst, *pBitmap);
355 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
359 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
361 AppLogDebug("ENTER");
365 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
372 Bitmap* pBitmap = null;
373 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
375 EnrichedText enTextCount;
376 TextElement textElement;
377 TextElement textElementCount;
379 int allContentCount = pAlbumInfo->GetContentIdCount();
380 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
382 String strFolderName = pAlbumInfo->GetAlbumName();
384 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
385 Color bgColor(COLOR_CANVAS_BG);
386 bgColor.SetAlpha(ALPHA_BG);
387 canvas.FillRectangle(bgColor, rectCanvas);
389 if (strFolderName == ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"))
391 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
393 else if (strFolderName == ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"))
395 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
399 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
404 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
405 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
409 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
410 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
411 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
412 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
414 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
415 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
417 textElement.Construct(strFolderName);
418 textElement.SetFont(ftFolderName);
419 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
420 enText.SetTextAbbreviationEnabled(true);
421 enText.Add(textElement);
423 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
424 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
426 textElementCount.Construct(strCnt);
428 if (strCnt.GetLength() > 3) // if the count in Album is greater than 3 digit number, use small font
430 textElementCount.SetFont(ftCntSmall);
434 textElementCount.SetFont(ftCnt);
436 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
437 enTextCount.SetTextAbbreviationEnabled(true);
438 enTextCount.Add(textElementCount);
440 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH , rectCanvas.y + HEIGHT_OFFSET);
441 canvas.SetFont(ftCnt);
442 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
443 canvas.DrawText(pointText, enTextCount);
445 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP , rectCanvas.y + GAP + HEIGHT_OFFSET);
446 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
447 canvas.DrawText(pointText, enText);
449 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
453 AlbumListPresentationModel::CreateMergeBitmapN(int index)
455 AppLogDebug("ENTER index(%d)", index);
457 if (__pAlbumInfoList == null)
459 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
464 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
466 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
467 BufferInfo bufferinfo;
469 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
470 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
472 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
476 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
481 pBitmapNew->Lock(bufferinfo);
482 r = canvas.Construct(bufferinfo);
486 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
491 DrawPartialImage(canvas, pAlbumInfo, rectNew);
492 DrawFontImage(canvas, pAlbumInfo, index);
494 pBitmapNew->Unlock();
495 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
501 AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
502 const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
504 AppLogDebug("ENTER");
505 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
508 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
512 result r = pAc->Start(null, pMimeType, pDataList, pListener);
516 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
517 pGalleryApp->SetFrameEnabled(false);
522 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
528 AlbumListPresentationModel::GetDirectoryName(String& directoryPath)
530 AppLogDebug("ENTER");
531 String directoryName;
534 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
535 directoryPath.SubString(lastIndex + 1, directoryName);
536 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
538 return directoryName;
542 AlbumListPresentationModel::GetFolderCount(void)
544 AppLogDebug("ENTER");
545 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
547 return __pAlbumInfoList->GetCount();
551 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
553 AppLogDebug("ENTER");
555 if (__pFolderBackgroundBitmap == null)
557 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
560 if (__pAlbumInfoList != null)
562 AlbumInfo* info = null;
563 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
565 info = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
566 if (info->GetAlbumName().IsEmpty() == false)
568 AppLog("Print AlbumName(%d)(%ls)", i, info->GetAlbumName().GetPointer());
571 delete __pAlbumInfoList;
573 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
575 ContentDirectory directory;
577 if (contentType == CONTENT_TYPE_ALL)
579 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
580 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
581 pListT->Add(CONTENT_TYPE_IMAGE);
582 pListT->Add(CONTENT_TYPE_VIDEO);
584 result r = directory.Construct(*pListT);
589 delete __pAlbumInfoList;
590 __pAlbumInfoList = null;
591 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
597 result r = directory.Construct(contentType);
600 delete __pAlbumInfoList;
601 __pAlbumInfoList = null;
602 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
607 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
608 String* pDirPath = null;
609 AlbumInfo* pAlbumInfo = null;
611 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
612 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
613 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
614 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
616 result r = pAllAlbumInfo->Construct();
617 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
618 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
620 r = pCameraAlbumInfo->Construct();
621 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
622 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
624 r = pDownloadAlbumInfo->Construct();
625 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
626 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
628 r = pNoNameAlbumInfo->Construct();
629 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
630 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
632 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
634 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
635 while (pEnum->MoveNext() == E_SUCCESS)
637 pDirPath = static_cast<String*>(pEnum->GetCurrent());
638 if (pDirPath == null)
643 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
645 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
647 if (pContentIdList != null)
649 pCameraAlbumInfo->AppendDirectory(*pDirPath);
650 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
652 pAllAlbumInfo->AppendDirectory(*pDirPath);
653 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
654 delete pContentIdList;
657 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
659 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
661 if (pContentIdList != null)
663 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
664 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
666 pAllAlbumInfo->AppendDirectory(*pDirPath);
667 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
668 delete pContentIdList;
671 else if (*pDirPath == RESERVED_MEDIA_PATH)
673 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
675 if (pContentIdList != null)
677 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
678 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
680 pAllAlbumInfo->AppendDirectory(*pDirPath);
681 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
682 delete pContentIdList;
687 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
689 if (pContentIdList != null)
691 if (pContentIdList->GetCount() > 0)
693 pAlbumInfo = new (std::nothrow) AlbumInfo();
694 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
696 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
698 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
701 pAllAlbumInfo->AppendDirectory(*pDirPath);
702 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
705 delete pContentIdList;
707 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
709 __pAlbumInfoList->Add(pAlbumInfo);
719 if (pAllAlbumInfo->GetContentIdCount() > 0)
721 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
725 delete pAllAlbumInfo;
728 if (pCameraAlbumInfo->GetContentIdCount() > 0)
730 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
734 delete pCameraAlbumInfo;
737 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
739 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
743 delete pDownloadAlbumInfo;
746 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
748 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
752 delete pNoNameAlbumInfo;
759 delete pAllAlbumInfo;
760 delete pCameraAlbumInfo;
761 delete pDownloadAlbumInfo;
762 delete pNoNameAlbumInfo;
765 if (pContentDirectoryPathList != null)
767 delete pContentDirectoryPathList;
769 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
773 if (pContentDirectoryPathList != null)
775 delete pContentDirectoryPathList;
777 if (pAllAlbumInfo != null)
779 delete pAllAlbumInfo;
781 if (pCameraAlbumInfo != null)
783 delete pCameraAlbumInfo;
785 if (pDownloadAlbumInfo != null)
787 delete pDownloadAlbumInfo;
789 if (pNoNameAlbumInfo != null)
791 delete pNoNameAlbumInfo;
796 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
798 AppLogDebug("ENTER");
799 if (fullPath == null)
801 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
805 String delim(DIRECTORY_SEPARATOR);
806 StringTokenizer st(fullPath,delim);
808 while (st.HasMoreTokens())
810 st.GetNextToken(token);
812 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
818 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
820 AppLogDebug("ENTER");
822 if (&directoryPath == null)
824 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
828 ContentDirectory directory;
829 const String contentDirectoryPath = directoryPath;
830 if (contentType == CONTENT_TYPE_ALL)
832 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
833 pListT->Add(CONTENT_TYPE_IMAGE);
834 pListT->Add(CONTENT_TYPE_VIDEO);
835 result r = directory.Construct(*pListT);
839 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
845 result r = directory.Construct(contentType);
848 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
854 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
855 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
856 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
857 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
859 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
861 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
863 while (pEnum->MoveNext() == E_SUCCESS)
865 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
866 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
867 pContentIdList->Add(pItem);
871 delete pContentInfoList;
872 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
874 return pContentIdList;
878 AlbumListPresentationModel::DeleteContentInfoInDirectory(int index, ContentType contentType)
880 AppLogDebug("ENTER");
881 result r = E_SUCCESS;
882 if (__pAlbumInfoList == null)
884 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
889 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
891 int loopCount = pAlbumInfo->GetDirectoryCount();
892 for (int i = 0; i < loopCount; ++i)
894 ContentDirectory directory;
895 const String contentDirectoryPath = pAlbumInfo->GetDirectory(i);
897 if (contentType == CONTENT_TYPE_ALL)
899 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
900 pListT->Add(CONTENT_TYPE_IMAGE);
901 pListT->Add(CONTENT_TYPE_VIDEO);
902 r = directory.Construct(*pListT);
907 r = directory.Construct(contentType);
915 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
916 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo,
917 countPerPage, CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
918 ContentManager contentManager;
919 r = contentManager.Construct();
922 delete pContentInfoList;
926 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
928 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
929 while (pEnum->MoveNext() == E_SUCCESS || r == E_SUCCESS)
931 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
932 ContentId contentId = pContentInfo->GetContentId();
933 r = contentManager.DeleteContent(contentId);
938 delete pContentInfoList;
940 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
946 AlbumListPresentationModel::GetAppControlMode(void) const
948 AppLogDebug("Enter");
950 return __appControlMode;
954 AlbumListPresentationModel::GetAppControlMediaType(void) const
956 AppLogDebug("Enter");
958 return __appControlMediaType;
961 AppControlSelectionMode
962 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
964 AppLogDebug("Enter");
966 return __appControlSelectionMode;
970 AlbumListPresentationModel::GetAlbumInfoList(void)
972 AppLogDebug("ENTER");
973 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
975 return __pAlbumInfoList;
979 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
981 AppLogDebug("ENTER");
982 if (&eventArg != null)
984 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
985 if (pThumbnailEventArg == null)
987 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
991 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
992 if (pThumbnailInfo == null)
994 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
999 ContentId contentId = pThumbnailInfo->GetContentId();
1000 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1002 if (__pAlbumInfoList != null)
1004 int outterLoopCount = __pAlbumInfoList->GetCount();
1005 for (int x = 0; x < outterLoopCount; ++x)
1007 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1008 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1009 for (int i = 0; i < innerLoopCount; ++i)
1011 if (i >= FOLDER_BITMAP_MAX)
1016 if (contentId == pAlbumInfo->GetContentId(i))
1018 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1020 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1021 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1028 if (__pPresentationModelListener->GetCount() > 0)
1030 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1031 while (pEnum->MoveNext() == E_SUCCESS)
1033 IAlbumEventListener* pListener = null;
1034 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1036 int loopCount = pUpdateFolderIndex->GetCount();
1037 for (int k = 0; k < loopCount; ++k)
1039 Integer *index = (Integer*)pUpdateFolderIndex->GetAt(k);
1040 int folderIndex = index->ToInt();
1041 pListener->OnThumbnailDecoded(folderIndex);
1047 delete pUpdateFolderIndex;
1049 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1053 AlbumListPresentationModel::OnContentCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1055 AppLogDebug("ENTER");
1056 IFormContentUpdateEventListener* pInterface = null;
1057 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1058 while (pEventEnum->MoveNext() == E_SUCCESS)
1060 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1061 pInterface->OnContentUpdated();
1064 AppLogDebug("EXIT");
1068 AlbumListPresentationModel::OnContentUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1070 AppLogDebug("ENTER");
1071 IFormContentUpdateEventListener* pInterface = null;
1072 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1073 while (pEventEnum->MoveNext() == E_SUCCESS)
1075 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1076 pInterface->OnContentUpdated();
1079 AppLogDebug("EXIT");
1083 AlbumListPresentationModel::OnContentDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1085 AppLogDebug("ENTER");
1086 IFormContentUpdateEventListener* pInterface = null;
1087 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1088 while (pEventEnum->MoveNext() == E_SUCCESS)
1090 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1091 pInterface->OnContentUpdated();
1094 AppLogDebug("EXIT");
1098 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1100 AppLogDebug("ENTER");
1101 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
1103 IFormContentUpdateEventListener* pInterface = null;
1104 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1105 while (pEventEnum->MoveNext() == E_SUCCESS)
1107 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1108 pInterface->OnContentUpdated();
1112 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1116 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, int pathIndex)
1118 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1120 ContentId contentId;
1121 if (__pAlbumInfoList != null)
1123 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1124 contentId = pAlbumInfo->GetContentId(pathIndex);
1127 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1128 AppLogDebug("EXIT");
1132 AlbumListPresentationModel::CancelThumbnailRequest(const int folderIndex)
1134 AppLogDebug("ENTER : folderIndex(%d)", folderIndex);
1135 if (__pAlbumInfoList != null)
1137 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1138 if (pAlbumInfo != null)
1141 for (int i = 0; i < loopCount ; ++i)
1143 contentId = pAlbumInfo->GetContentId(i);
1144 __pThumbnailProvider->CancelThumbnailRequest(contentId, __pThumbnailEvent);
1149 AppLogDebug("EXIT");
1153 AlbumListPresentationModel::ClearThumbnailRequests(bool appTerminating)
1155 AppLogDebug("ENTER");
1156 if (__pThumbnailProvider != null)
1158 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1160 AppLogDebug("EXIT");