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* pUriData, const String* pMimeType, const IMap* pDataList,
503 IAppControlResponseListener* pListener)
505 AppLogDebug("ENTER");
506 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
509 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
513 result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
517 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
518 pGalleryApp->SetFrameEnabled(false);
523 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
529 AlbumListPresentationModel::GetDirectoryName(String& directoryPath)
531 AppLogDebug("ENTER");
532 String directoryName;
535 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
536 directoryPath.SubString(lastIndex + 1, directoryName);
537 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
539 return directoryName;
543 AlbumListPresentationModel::GetFolderCount(void)
545 AppLogDebug("ENTER");
546 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
548 return __pAlbumInfoList->GetCount();
552 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
554 AppLogDebug("ENTER");
556 if (__pFolderBackgroundBitmap == null)
558 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
561 if (__pAlbumInfoList != null)
563 AlbumInfo* info = null;
564 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
566 info = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
567 if (info->GetAlbumName().IsEmpty() == false)
569 AppLog("Print AlbumName(%d)(%ls)", i, info->GetAlbumName().GetPointer());
572 delete __pAlbumInfoList;
574 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
576 ContentDirectory directory;
578 if (contentType == CONTENT_TYPE_ALL)
580 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
581 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
582 pListT->Add(CONTENT_TYPE_IMAGE);
583 pListT->Add(CONTENT_TYPE_VIDEO);
585 result r = directory.Construct(*pListT);
590 delete __pAlbumInfoList;
591 __pAlbumInfoList = null;
592 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
598 result r = directory.Construct(contentType);
601 delete __pAlbumInfoList;
602 __pAlbumInfoList = null;
603 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
608 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
609 String* pDirPath = null;
610 AlbumInfo* pAlbumInfo = null;
612 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
613 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
614 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
615 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
617 result r = pAllAlbumInfo->Construct();
618 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
619 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
621 r = pCameraAlbumInfo->Construct();
622 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
623 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
625 r = pDownloadAlbumInfo->Construct();
626 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
627 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
629 r = pNoNameAlbumInfo->Construct();
630 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
631 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
633 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
635 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
636 while (pEnum->MoveNext() == E_SUCCESS)
638 pDirPath = static_cast<String*>(pEnum->GetCurrent());
639 if (pDirPath == null)
644 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
646 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
648 if (pContentIdList != null)
650 pCameraAlbumInfo->AppendDirectory(*pDirPath);
651 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
653 pAllAlbumInfo->AppendDirectory(*pDirPath);
654 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
655 delete pContentIdList;
658 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
660 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
662 if (pContentIdList != null)
664 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
665 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
667 pAllAlbumInfo->AppendDirectory(*pDirPath);
668 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
669 delete pContentIdList;
672 else if (*pDirPath == RESERVED_MEDIA_PATH)
674 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
676 if (pContentIdList != null)
678 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
679 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
681 pAllAlbumInfo->AppendDirectory(*pDirPath);
682 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
683 delete pContentIdList;
688 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
690 if (pContentIdList != null)
692 if (pContentIdList->GetCount() > 0)
694 pAlbumInfo = new (std::nothrow) AlbumInfo();
695 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
697 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
699 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
702 pAllAlbumInfo->AppendDirectory(*pDirPath);
703 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
706 delete pContentIdList;
708 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
710 __pAlbumInfoList->Add(pAlbumInfo);
720 if (pAllAlbumInfo->GetContentIdCount() > 0)
722 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
726 delete pAllAlbumInfo;
729 if (pCameraAlbumInfo->GetContentIdCount() > 0)
731 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
735 delete pCameraAlbumInfo;
738 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
740 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
744 delete pDownloadAlbumInfo;
747 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
749 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
753 delete pNoNameAlbumInfo;
760 delete pAllAlbumInfo;
761 delete pCameraAlbumInfo;
762 delete pDownloadAlbumInfo;
763 delete pNoNameAlbumInfo;
766 if (pContentDirectoryPathList != null)
768 delete pContentDirectoryPathList;
770 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
774 if (pContentDirectoryPathList != null)
776 delete pContentDirectoryPathList;
778 if (pAllAlbumInfo != null)
780 delete pAllAlbumInfo;
782 if (pCameraAlbumInfo != null)
784 delete pCameraAlbumInfo;
786 if (pDownloadAlbumInfo != null)
788 delete pDownloadAlbumInfo;
790 if (pNoNameAlbumInfo != null)
792 delete pNoNameAlbumInfo;
797 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
799 AppLogDebug("ENTER");
800 if (fullPath == null)
802 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
806 String delim(DIRECTORY_SEPARATOR);
807 StringTokenizer st(fullPath,delim);
809 while (st.HasMoreTokens())
811 st.GetNextToken(token);
813 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
819 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
821 AppLogDebug("ENTER");
823 if (&directoryPath == null)
825 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
829 ContentDirectory directory;
830 const String contentDirectoryPath = directoryPath;
831 if (contentType == CONTENT_TYPE_ALL)
833 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
834 pListT->Add(CONTENT_TYPE_IMAGE);
835 pListT->Add(CONTENT_TYPE_VIDEO);
836 result r = directory.Construct(*pListT);
840 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
846 result r = directory.Construct(contentType);
849 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
855 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
856 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
857 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
858 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
860 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
862 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
864 while (pEnum->MoveNext() == E_SUCCESS)
866 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
867 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
868 pContentIdList->Add(pItem);
872 delete pContentInfoList;
873 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
875 return pContentIdList;
879 AlbumListPresentationModel::DeleteContentInfoInDirectory(int index, ContentType contentType)
881 AppLogDebug("ENTER");
882 result r = E_SUCCESS;
883 if (__pAlbumInfoList == null)
885 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
890 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
892 int loopCount = pAlbumInfo->GetDirectoryCount();
893 for (int i = 0; i < loopCount; ++i)
895 ContentDirectory directory;
896 const String contentDirectoryPath = pAlbumInfo->GetDirectory(i);
898 if (contentType == CONTENT_TYPE_ALL)
900 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
901 pListT->Add(CONTENT_TYPE_IMAGE);
902 pListT->Add(CONTENT_TYPE_VIDEO);
903 r = directory.Construct(*pListT);
908 r = directory.Construct(contentType);
916 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
917 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo,
918 countPerPage, CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
919 ContentManager contentManager;
920 r = contentManager.Construct();
923 delete pContentInfoList;
927 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
929 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
930 while (pEnum->MoveNext() == E_SUCCESS || r == E_SUCCESS)
932 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
933 ContentId contentId = pContentInfo->GetContentId();
934 r = contentManager.DeleteContent(contentId);
939 delete pContentInfoList;
941 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
947 AlbumListPresentationModel::GetAppControlMode(void) const
949 AppLogDebug("Enter");
951 return __appControlMode;
955 AlbumListPresentationModel::GetAppControlMediaType(void) const
957 AppLogDebug("Enter");
959 return __appControlMediaType;
962 AppControlSelectionMode
963 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
965 AppLogDebug("Enter");
967 return __appControlSelectionMode;
971 AlbumListPresentationModel::GetAlbumInfoList(void)
973 AppLogDebug("ENTER");
974 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
976 return __pAlbumInfoList;
980 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
982 AppLogDebug("ENTER");
983 if (&eventArg != null)
985 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
986 if (pThumbnailEventArg == null)
988 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
992 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
993 if (pThumbnailInfo == null)
995 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1000 ContentId contentId = pThumbnailInfo->GetContentId();
1001 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1003 if (__pAlbumInfoList != null)
1005 int outterLoopCount = __pAlbumInfoList->GetCount();
1006 for (int x = 0; x < outterLoopCount; ++x)
1008 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1009 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1010 for (int i = 0; i < innerLoopCount; ++i)
1012 if (i >= FOLDER_BITMAP_MAX)
1017 if (contentId == pAlbumInfo->GetContentId(i))
1019 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1021 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1022 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1029 if (__pPresentationModelListener->GetCount() > 0)
1031 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1032 while (pEnum->MoveNext() == E_SUCCESS)
1034 IAlbumEventListener* pListener = null;
1035 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1037 int loopCount = pUpdateFolderIndex->GetCount();
1038 for (int k = 0; k < loopCount; ++k)
1040 Integer *index = (Integer*)pUpdateFolderIndex->GetAt(k);
1041 int folderIndex = index->ToInt();
1042 pListener->OnThumbnailDecoded(folderIndex);
1048 delete pUpdateFolderIndex;
1050 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1054 AlbumListPresentationModel::OnContentCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1056 AppLogDebug("ENTER");
1057 IFormContentUpdateEventListener* pInterface = null;
1058 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1059 while (pEventEnum->MoveNext() == E_SUCCESS)
1061 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1062 pInterface->OnContentUpdated();
1065 AppLogDebug("EXIT");
1069 AlbumListPresentationModel::OnContentUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1071 AppLogDebug("ENTER");
1072 IFormContentUpdateEventListener* pInterface = null;
1073 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1074 while (pEventEnum->MoveNext() == E_SUCCESS)
1076 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1077 pInterface->OnContentUpdated();
1080 AppLogDebug("EXIT");
1084 AlbumListPresentationModel::OnContentDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1086 AppLogDebug("ENTER");
1087 IFormContentUpdateEventListener* pInterface = null;
1088 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1089 while (pEventEnum->MoveNext() == E_SUCCESS)
1091 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1092 pInterface->OnContentUpdated();
1095 AppLogDebug("EXIT");
1099 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1101 AppLogDebug("ENTER");
1102 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
1104 IFormContentUpdateEventListener* pInterface = null;
1105 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1106 while (pEventEnum->MoveNext() == E_SUCCESS)
1108 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1109 pInterface->OnContentUpdated();
1113 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1117 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, int pathIndex)
1119 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1121 ContentId contentId;
1122 if (__pAlbumInfoList != null)
1124 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1125 contentId = pAlbumInfo->GetContentId(pathIndex);
1128 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1129 AppLogDebug("EXIT");
1133 AlbumListPresentationModel::CancelThumbnailRequest(const int folderIndex)
1135 AppLogDebug("ENTER : folderIndex(%d)", folderIndex);
1136 if (__pAlbumInfoList != null)
1138 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1139 if (pAlbumInfo != null)
1142 for (int i = 0; i < loopCount ; ++i)
1144 contentId = pAlbumInfo->GetContentId(i);
1145 __pThumbnailProvider->CancelThumbnailRequest(contentId, __pThumbnailEvent);
1150 AppLogDebug("EXIT");
1154 AlbumListPresentationModel::ClearThumbnailRequests(bool appTerminating)
1156 AppLogDebug("ENTER");
1157 if (__pThumbnailProvider != null)
1159 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1161 AppLogDebug("EXIT");