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 const String* mediaType =
172 static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_MEDIA_TYPE)));
174 if (mediaType != null && mediaType->CompareTo(APPCONTROL_DATA_VIDEO) == 0)
176 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
179 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
181 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
185 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
187 __appControlMode = APP_CONTROL_MODE_SETTING;
190 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
196 AlbumListPresentationModel::CreateInstance(void)
198 AppLogDebug("ENTER");
199 __pPresentationModelInstance = new (std::nothrow) AlbumListPresentationModel;
200 result r = __pPresentationModelInstance->Construct();
202 if (IsFailed(r) == true)
204 delete __pPresentationModelInstance;
205 __pPresentationModelInstance = null;
206 AppLogDebug("EXIT false");
209 std::atexit(DestroyInstance);
210 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
214 AlbumListPresentationModel::DestroyInstance(void)
216 AppLogDebug("ENTER");
218 delete __pThumbnailEvent;
219 __pThumbnailEvent = null;
221 if (__pAlbumInfoList != null)
223 delete __pAlbumInfoList;
224 __pAlbumInfoList = null;
227 if (__pPresentationModelListener != null)
229 delete __pPresentationModelListener;
230 __pPresentationModelListener = null;
233 if (__pContentEventListener != null)
235 delete __pContentEventListener;
236 __pContentEventListener = null;
239 delete __pPresentationModelInstance;
240 __pPresentationModelInstance = null;
242 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
246 AlbumListPresentationModel::AddPresentationModelListener(IAlbumEventListener* listener)
248 AppLogDebug("ENTER");
249 result r = __pPresentationModelListener->Add(listener);
250 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
256 AlbumListPresentationModel::RemovePresentationModelListener(IAlbumEventListener& listner)
258 AppLogDebug("ENTER");
259 result r = __pPresentationModelListener->Remove(listner);
260 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
266 AlbumListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
268 AppLogDebug("ENTER");
269 if (__pContentEventListener != null)
271 __pContentEventListener->RemoveAll();
272 __pContentEventListener->Add((Object*)listener);
273 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
278 AlbumListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener& listener)
280 AppLogDebug("ENTER");
281 __pContentEventListener->Remove(listener);
282 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
286 AlbumListPresentationModel::CallAlbumChangedEvent(void)
288 AppLogDebug("ENTER");
289 if (__pPresentationModelListener->GetCount() > 0)
291 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
293 while (pEnum->MoveNext() == E_SUCCESS)
295 IAlbumEventListener* pListener = null;
296 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
297 pListener->OnFileInfoChanged(CONTENT_TYPE_ALL);
303 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
307 AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& newPath,
308 IAlbumRenameEventListener* pAlbumListener)
310 AppLogDebug("ENTER");
311 result r = Directory::Rename(orgPath, newPath);
314 AppLogDebug("Album Rename failed(%s)", GetErrorMessage(r));
318 __pAlbumListener = pAlbumListener;
319 r = ContentManager::ScanDirectory(Tizen::System::Environment::GetMediaPath(), 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();
339 AlbumListPresentationModel::DrawPartialImage(Canvas& canvas, AlbumInfo* pAlbumInfo, const Rectangle& rectNew)
341 AppLogDebug("ENTER");
342 if (&canvas == null || __pFolderBackgroundBitmap == null || pAlbumInfo == null)
344 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
349 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
351 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
355 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
356 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
357 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
358 canvas.DrawBitmap(rectFirst, *pBitmap);
361 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
365 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
367 AppLogDebug("ENTER");
371 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
378 Bitmap* pBitmap = null;
379 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
381 EnrichedText enTextCount;
382 TextElement textElement;
383 TextElement textElementCount;
385 int allContentCount = pAlbumInfo->GetContentIdCount();
386 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
388 String strFolderName = pAlbumInfo->GetAlbumName();
390 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
391 Color bgColor(COLOR_CANVAS_BG);
392 bgColor.SetAlpha(ALPHA_BG);
393 canvas.FillRectangle(bgColor, rectCanvas);
395 if ( strFolderName == ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"))
397 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
399 else if ( strFolderName == ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB") )
401 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
405 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
408 if ( pBitmap != null)
410 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
411 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
415 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
416 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
417 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
418 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
420 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
421 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
423 textElement.Construct(strFolderName);
424 textElement.SetFont(ftFolderName);
425 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
426 enText.SetTextAbbreviationEnabled(true);
427 enText.Add(textElement);
429 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
430 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
432 textElementCount.Construct(strCnt);
434 if (strCnt.GetLength() > 3) // if the count in Album is greater than 3 digit number, use small font
436 textElementCount.SetFont(ftCntSmall);
440 textElementCount.SetFont(ftCnt);
442 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
443 enTextCount.SetTextAbbreviationEnabled(true);
444 enTextCount.Add(textElementCount);
446 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH , rectCanvas.y + HEIGHT_OFFSET);
447 canvas.SetFont(ftCnt);
448 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
449 canvas.DrawText(pointText, enTextCount);
451 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP , rectCanvas.y + GAP + HEIGHT_OFFSET);
452 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
453 canvas.DrawText(pointText, enText);
455 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
459 AlbumListPresentationModel::CreateMergeBitmapN(int index)
461 AppLogDebug("ENTER index(%d)", index);
463 if (__pAlbumInfoList == null)
465 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
470 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
472 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
473 BufferInfo bufferinfo;
475 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
476 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
478 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
482 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
487 pBitmapNew->Lock(bufferinfo);
488 r = canvas.Construct(bufferinfo);
492 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
497 DrawPartialImage(canvas, pAlbumInfo, rectNew);
498 DrawFontImage(canvas, pAlbumInfo, index);
500 pBitmapNew->Unlock();
501 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
507 AlbumListPresentationModel::StartAppControl( const String& providerId, const String& operationId,
508 const IMap* pDataList, IAppControlResponseListener* pListener)
510 AppLogDebug("ENTER");
511 AppLogDebug("FindAppControlN(%ls, %ls)", providerId.GetPointer(), operationId.GetPointer());
512 if (pDataList != null)
514 IList* pKeyList = pDataList->GetKeysN();
515 if (pKeyList != null)
517 int keyCount = pKeyList->GetCount();
518 for (int i = 0; i < keyCount; ++i)
520 String* pKey = const_cast<String*>(static_cast<const String*>(pKeyList->GetAt(i)));
521 String* pValue = const_cast<String*>(static_cast<const String*>(pDataList->GetValue(*pKey)));
523 AppLogDebug("(%ls:%ls)", pKey == null ? L"(null)" : pKey->GetPointer(), pValue == null ? L"(null)" : pValue->GetPointer());
528 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
531 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
535 result r = pAc->Start(null, null, pDataList, pListener);
539 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
540 pGalleryApp->SetFrameEnabled(false);
545 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
551 AlbumListPresentationModel::GetDirectoryName(String& directoryPath)
553 AppLogDebug("ENTER");
554 String directoryName;
557 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
558 directoryPath.SubString(lastIndex + 1, directoryName);
559 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
561 return directoryName;
565 AlbumListPresentationModel::GetFolderCount(void)
567 AppLogDebug("ENTER");
568 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
570 return __pAlbumInfoList->GetCount();
574 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
576 AppLogDebug("ENTER");
578 if (__pFolderBackgroundBitmap == null)
580 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
583 if (__pAlbumInfoList != null)
585 AlbumInfo* info = null;
586 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
588 info = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
589 if (info->GetAlbumName().IsEmpty() == false)
591 AppLog("Print AlbumName(%d)(%ls)", i, info->GetAlbumName().GetPointer());
594 delete __pAlbumInfoList;
596 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
598 ContentDirectory directory;
600 if (contentType == CONTENT_TYPE_ALL)
602 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
603 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
604 pListT->Add(CONTENT_TYPE_IMAGE);
605 pListT->Add(CONTENT_TYPE_VIDEO);
607 result r = directory.Construct(*pListT);
612 delete __pAlbumInfoList;
613 __pAlbumInfoList = null;
614 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
620 result r = directory.Construct(contentType);
623 delete __pAlbumInfoList;
624 __pAlbumInfoList = null;
625 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
630 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
631 String* pDirPath = null;
632 AlbumInfo* pAlbumInfo = null;
634 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
635 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
636 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
637 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
639 result r = pAllAlbumInfo->Construct();
640 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
641 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
643 r = pCameraAlbumInfo->Construct();
644 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
645 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
647 r = pDownloadAlbumInfo->Construct();
648 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
649 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
651 r = pNoNameAlbumInfo->Construct();
652 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
653 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
655 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
657 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
658 while (pEnum->MoveNext() == E_SUCCESS)
660 pDirPath = static_cast<String*>(pEnum->GetCurrent());
661 if (pDirPath == null)
666 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
668 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
670 if (pContentIdList != null)
672 pCameraAlbumInfo->AppendDirectory(*pDirPath);
673 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
675 pAllAlbumInfo->AppendDirectory(*pDirPath);
676 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
677 delete pContentIdList;
680 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
682 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
684 if (pContentIdList != null)
686 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
687 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
689 pAllAlbumInfo->AppendDirectory(*pDirPath);
690 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
691 delete pContentIdList;
694 else if (*pDirPath == RESERVED_MEDIA_PATH)
696 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
698 if (pContentIdList != null)
700 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
701 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
703 pAllAlbumInfo->AppendDirectory(*pDirPath);
704 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
705 delete pContentIdList;
710 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
712 if (pContentIdList != null)
714 if (pContentIdList->GetCount() > 0)
716 pAlbumInfo = new (std::nothrow) AlbumInfo();
717 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
719 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
721 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
724 pAllAlbumInfo->AppendDirectory(*pDirPath);
725 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
728 delete pContentIdList;
730 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
732 __pAlbumInfoList->Add(pAlbumInfo);
742 if (pAllAlbumInfo->GetContentIdCount() > 0)
744 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
748 delete pAllAlbumInfo;
751 if (pCameraAlbumInfo->GetContentIdCount() > 0)
753 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
757 delete pCameraAlbumInfo;
760 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
762 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
766 delete pDownloadAlbumInfo;
769 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
771 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
775 delete pNoNameAlbumInfo;
782 delete pAllAlbumInfo;
783 delete pCameraAlbumInfo;
784 delete pDownloadAlbumInfo;
785 delete pNoNameAlbumInfo;
788 if (pContentDirectoryPathList != null)
790 delete pContentDirectoryPathList;
792 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
796 if (pContentDirectoryPathList != null)
798 delete pContentDirectoryPathList;
800 if (pAllAlbumInfo != null)
802 delete pAllAlbumInfo;
804 if (pCameraAlbumInfo != null)
806 delete pCameraAlbumInfo;
808 if (pDownloadAlbumInfo != null)
810 delete pDownloadAlbumInfo;
812 if (pNoNameAlbumInfo != null)
814 delete pNoNameAlbumInfo;
819 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
821 AppLogDebug("ENTER");
822 if (fullPath == null)
824 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
828 String delim(DIRECTORY_SEPARATOR);
829 StringTokenizer st(fullPath,delim);
831 while (st.HasMoreTokens())
833 st.GetNextToken(token);
835 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
841 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
843 AppLogDebug("ENTER");
845 if (&directoryPath == null)
847 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
851 ContentDirectory directory;
852 const String contentDirectoryPath = directoryPath;
853 if (contentType == CONTENT_TYPE_ALL)
855 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
856 pListT->Add(CONTENT_TYPE_IMAGE);
857 pListT->Add(CONTENT_TYPE_VIDEO);
858 result r = directory.Construct(*pListT);
862 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
868 result r = directory.Construct(contentType);
871 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
877 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
878 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
879 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
880 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
882 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
884 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
886 while (pEnum->MoveNext() == E_SUCCESS)
888 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
889 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
890 pContentIdList->Add(pItem);
894 delete pContentInfoList;
895 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
897 return pContentIdList;
901 AlbumListPresentationModel::DeleteContentInfoInDirectory(int index, ContentType contentType)
903 AppLogDebug("ENTER");
904 result r = E_SUCCESS;
905 if (__pAlbumInfoList == null)
907 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
912 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
914 int loopCount = pAlbumInfo->GetDirectoryCount();
915 for (int i = 0; i < loopCount; ++i)
917 ContentDirectory directory;
918 const String contentDirectoryPath = pAlbumInfo->GetDirectory(i);
920 if (contentType == CONTENT_TYPE_ALL)
922 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
923 pListT->Add(CONTENT_TYPE_IMAGE);
924 pListT->Add(CONTENT_TYPE_VIDEO);
925 r = directory.Construct(*pListT);
931 r = directory.Construct(contentType);
939 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
940 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo,
941 countPerPage, CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
942 ContentManager contentManager;
943 r = contentManager.Construct();
946 delete pContentInfoList;
950 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
952 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
953 while (pEnum->MoveNext() == E_SUCCESS || r == E_SUCCESS)
955 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
956 ContentId contentId = pContentInfo->GetContentId();
957 r = contentManager.DeleteContent(contentId);
963 delete pContentInfoList;
965 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
971 AlbumListPresentationModel::GetAppControlMode(void) const
973 AppLogDebug("Enter");
975 return __appControlMode;
979 AlbumListPresentationModel::GetAppControlMediaType(void) const
981 AppLogDebug("Enter");
983 return __appControlMediaType;
986 AppControlSelectionMode
987 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
989 AppLogDebug("Enter");
991 return __appControlSelectionMode;
995 AlbumListPresentationModel::GetAlbumInfoList(void)
997 AppLogDebug("ENTER");
998 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1000 return __pAlbumInfoList;
1004 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
1006 AppLogDebug("ENTER");
1007 if (&eventArg != null)
1009 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
1010 if (pThumbnailEventArg == null)
1012 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1016 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
1017 if (pThumbnailInfo == null)
1019 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1024 ContentId contentId = pThumbnailInfo->GetContentId();
1025 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1027 if (__pAlbumInfoList != null)
1029 int outterLoopCount = __pAlbumInfoList->GetCount();
1030 for (int x = 0; x < outterLoopCount; ++x)
1032 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1033 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1034 for (int i = 0; i < innerLoopCount; ++i)
1036 if (i >= FOLDER_BITMAP_MAX)
1041 if (contentId == pAlbumInfo->GetContentId(i))
1043 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1045 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1046 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1053 if (__pPresentationModelListener->GetCount() > 0)
1055 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1056 while (pEnum->MoveNext() == E_SUCCESS)
1058 IAlbumEventListener* pListener = null;
1059 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1061 int loopCount = pUpdateFolderIndex->GetCount();
1062 for (int k = 0; k < loopCount; ++k)
1064 Integer *index = (Integer*)pUpdateFolderIndex->GetAt(k);
1065 int folderIndex = index->ToInt();
1066 pListener->OnThumbnailDecoded(folderIndex);
1072 delete pUpdateFolderIndex;
1074 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1078 AlbumListPresentationModel::OnContentCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1080 AppLogDebug("ENTER");
1081 IFormContentUpdateEventListener* pInterface = null;
1082 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1083 while (pEventEnum->MoveNext() == E_SUCCESS)
1085 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1086 pInterface->OnContentUpdated();
1090 AppLogDebug("EXIT");
1094 AlbumListPresentationModel::OnContentUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1096 AppLogDebug("ENTER");
1097 IFormContentUpdateEventListener* pInterface = null;
1098 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1099 while (pEventEnum->MoveNext() == E_SUCCESS)
1101 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1102 pInterface->OnContentUpdated();
1106 AppLogDebug("EXIT");
1110 AlbumListPresentationModel::OnContentDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1112 AppLogDebug("ENTER");
1113 IFormContentUpdateEventListener* pInterface = null;
1114 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1115 while (pEventEnum->MoveNext() == E_SUCCESS)
1117 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1118 pInterface->OnContentUpdated();
1122 AppLogDebug("EXIT");
1126 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1128 AppLogDebug("ENTER");
1129 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
1131 IFormContentUpdateEventListener* pInterface = null;
1132 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1133 while (pEventEnum->MoveNext() == E_SUCCESS)
1135 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1136 pInterface->OnContentUpdated();
1141 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1145 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, int pathIndex)
1147 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1149 ContentId contentId;
1150 if (__pAlbumInfoList != null)
1152 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1153 contentId = pAlbumInfo->GetContentId(pathIndex);
1156 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1157 AppLogDebug("EXIT");
1161 AlbumListPresentationModel::CancelThumbnailRequest(const int folderIndex)
1163 AppLogDebug("ENTER : folderIndex(%d)", folderIndex);
1164 if (__pAlbumInfoList != null)
1166 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1167 if (pAlbumInfo != null)
1170 for (int i = 0; i < loopCount ; ++i)
1172 contentId = pAlbumInfo->GetContentId(i);
1173 __pThumbnailProvider->CancelThumbnailRequest(contentId, __pThumbnailEvent);
1178 AppLogDebug("EXIT");
1182 AlbumListPresentationModel::ClearThumbnailRequests(bool appTerminating)
1184 AppLogDebug("ENTER");
1185 if (__pThumbnailProvider != null)
1187 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1189 AppLogDebug("EXIT");