2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file GlAlbumListPresentationModel.cpp
19 * @brief This is the implementation file for AlbumListPresentationModel class.
26 #include "GlAlbumInfo.h"
27 #include "GlAlbumListPresentationModel.h"
28 #include "GlAlbumRenameEventListener.h"
29 #include "GlContentUpdateEventListener.h"
30 #include "GlFileListPresentationModel.h"
31 #include "GlGalleryApp.h"
32 #include "GlThumbnailEvent.h"
33 #include "GlThumbnailEventArg.h"
34 #include "GlThumbnailProvider.h"
36 using namespace Tizen::App;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Base::Runtime;
40 using namespace Tizen::Base::Utility;
41 using namespace Tizen::Content;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Io;
44 using namespace Tizen::Media;
45 using namespace Tizen::System;
46 using namespace Tizen::Ui::Controls;
48 static const int ICON_CAP = 3;
49 static const int FOLDER_CAP = 8;
50 static const int ICON_SIZE = 107;
51 static const int FOLDER_SIZE_WIDTH = 348;
52 static const int FOLDER_SIZE_HEIGHT = 348;
54 static const int CANVAS_HEIGHT = 71;
55 static const int CANVAS_WIDTH = 326;
57 static const int FONT_SIZE_FOLDER_NAME = 32;
58 static const int FONT_SIZE_FOLDER_DATE = 25;
59 static const int FONT_SIZE_FOLDER_COUNT = 45;
60 static const int FONT_SIZE_FOLDER_COUNT_SMALL = 35;
62 static const int CANVAS_IMAGE_FOLDER_HEIGHT = 48;
63 static const int CANVAS_IMAGE_FOLDER_WIDTH = 48;
64 static const int IMAGE_COUNT_WIDTH = 100;
65 static const int IMAGE_COUNT_HEIGHT = 60;
66 static const int CANVAS_MARGIN_LEFT = 10;
67 static const int GAP = 10;
68 static const int HEIGHT_OFFSET = 5;
69 static const int Y_POS_CANVAS = 260;
70 static const int FOLDER_NAME_WIDTH = 165;
71 static const int FOLDER_NAME_HEIGHT = 38;
74 static const int ALPHA_BG = 110;
76 static const Color COLOR_CANVAS_BG (Color::GetColor(COLOR_ID_BLACK));
78 static const String RESERVED_MEDIA_PATH = Environment::GetMediaPath();
79 static const String RESERVED_CAMERA_PATH = Environment::GetMediaPath() + L"Camera";
80 static const String RESERVED_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera";
81 static const String RESERVED_DOWNLOAD_PATH = Environment::GetMediaPath() + L"Downloads";
82 static const String CONTENT_INFO_ORDER = L"ContentFileName";
84 static const int FORMAT_BUFFER_SIZE = 256;
86 static const int DOUBLE_NUMBER = 2;
87 static const int TRIPLE_NUMBER = 3;
89 AlbumListPresentationModel* AlbumListPresentationModel::__pPresentationModelInstance = null;
90 ArrayList* AlbumListPresentationModel::__pPresentationModelListener = null;
91 ArrayList* AlbumListPresentationModel::__pContentEventListener = null;
92 ThumbnailProvider* AlbumListPresentationModel::__pThumbnailProvider = null;
93 ThumbnailEvent* AlbumListPresentationModel::__pThumbnailEvent = null;
94 IList* AlbumListPresentationModel::__pAlbumInfoList = null;
96 AlbumListPresentationModel::AlbumListPresentationModel(void)
97 : __pFolderBackgroundBitmap(null)
98 , __pContentManager(null)
99 , __pAlbumListener(null)
100 , __appControlMode(APPCONTROL_MODE_MAIN)
101 , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
102 , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
103 , __updateProgressStatus(false)
105 AppLogDebug("ENTER");
106 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
109 AlbumListPresentationModel::~AlbumListPresentationModel(void)
111 AppLogDebug("ENTER");
112 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
113 delete __pFolderBackgroundBitmap;
114 delete __pContentManager;
115 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
118 AlbumListPresentationModel*
119 AlbumListPresentationModel::GetInstance(void)
121 AppLogDebug("ENTER");
122 if (__pPresentationModelInstance == null)
126 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
128 return __pPresentationModelInstance;
132 AlbumListPresentationModel::Construct(void)
134 AppLogDebug("ENTER");
135 __pPresentationModelListener = new (std::nothrow) ArrayList();
136 __pPresentationModelListener->Construct();
138 ContentUpdateEventListener::GetInstance();
139 __pContentEventListener = new (std::nothrow) ArrayList();
140 __pContentEventListener->Construct();
142 IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
143 __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
144 __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
146 __pContentManager = new (std::nothrow) ContentManager();
147 __pContentManager->Construct();
149 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
151 __pThumbnailProvider = ThumbnailProvider::GetInstance();
152 AppLogDebug("ENTER1");
153 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
154 const IMap* pArguments = pApp->GetAppControlArguments();
155 String operationId = pApp->GetAppControlOperationId();
157 if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
159 __appControlMode = APPCONTROL_MODE_MAIN;
161 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
163 __appControlMode = APPCONTROL_MODE_PICK;
165 String mimeType = pApp->GetMimeType();
166 if (mimeType.IsEmpty() != true)
168 if (mimeType.StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
170 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
173 if (pArguments != null)
175 const String* selectionMode =
176 static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
177 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
179 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
183 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
185 __appControlMode = APPCONTROL_MODE_SETTING;
188 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
194 AlbumListPresentationModel::CreateInstance(void)
196 AppLogDebug("ENTER");
197 __pPresentationModelInstance = new (std::nothrow) AlbumListPresentationModel;
198 result r = __pPresentationModelInstance->Construct();
200 if (IsFailed(r) == true)
202 delete __pPresentationModelInstance;
203 __pPresentationModelInstance = null;
204 AppLogDebug("EXIT false");
207 std::atexit(DestroyInstance);
208 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
212 AlbumListPresentationModel::DestroyInstance(void)
214 AppLogDebug("ENTER");
216 delete __pThumbnailEvent;
217 __pThumbnailEvent = null;
219 if (__pAlbumInfoList != null)
221 delete __pAlbumInfoList;
222 __pAlbumInfoList = null;
225 if (__pPresentationModelListener != null)
227 delete __pPresentationModelListener;
228 __pPresentationModelListener = null;
231 if (__pContentEventListener != null)
233 delete __pContentEventListener;
234 __pContentEventListener = null;
237 delete __pPresentationModelInstance;
238 __pPresentationModelInstance = null;
240 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
244 AlbumListPresentationModel::AddPresentationModelListener(IAlbumEventListener* listener)
246 AppLogDebug("ENTER");
247 result r = __pPresentationModelListener->Add(listener);
248 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
254 AlbumListPresentationModel::RemovePresentationModelListener(IAlbumEventListener& listner)
256 AppLogDebug("ENTER");
257 result r = __pPresentationModelListener->Remove(listner);
258 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
264 AlbumListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
266 AppLogDebug("ENTER");
267 if (__pContentEventListener != null)
269 __pContentEventListener->RemoveAll();
270 __pContentEventListener->Add((Object*)listener);
271 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
276 AlbumListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener& listener)
278 AppLogDebug("ENTER");
279 __pContentEventListener->Remove(listener);
280 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
284 AlbumListPresentationModel::CallAlbumChangedEvent(void)
286 AppLogDebug("ENTER");
287 if (__pPresentationModelListener->GetCount() > 0)
289 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
291 while (pEnum->MoveNext() == E_SUCCESS)
293 IAlbumEventListener* pListener = null;
294 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
295 pListener->OnFileInfoChanged(CONTENT_TYPE_ALL);
300 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
304 AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& newPath,
305 IAlbumRenameEventListener* pAlbumListener)
307 AppLogDebug("ENTER");
308 result r = Directory::Rename(orgPath, newPath);
311 AppLogDebug("Album Rename failed(%s)", GetErrorMessage(r));
315 __pAlbumListener = pAlbumListener;
316 __renameNewPath = newPath;
\r
317 r = ContentManager::ScanDirectory(newPath, true, NULL, __reqId);
\r
318 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
319 r = ContentManager::ScanDirectory(orgPath, true, NULL, __reqId);
\r
320 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
326 bool AlbumListPresentationModel::OnContentScanCompleted (const Tizen::Base::String &scanPath)
\r
328 AppLogDebug("ENTER");
\r
329 if (__pAlbumListener && (scanPath == __renameNewPath))
\r
331 InitializeAlbumInfoList(CONTENT_TYPE_ALL);
332 __pAlbumListener->OnAlbumRenameComplete();
333 __renameNewPath = L"";
342 AlbumListPresentationModel::DrawPartialImage(Canvas& canvas, AlbumInfo* pAlbumInfo, const Rectangle& rectNew)
344 AppLogDebug("ENTER");
345 if (&canvas == null || __pFolderBackgroundBitmap == null || pAlbumInfo == null)
347 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
351 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
353 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
357 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
358 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
359 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
360 canvas.DrawBitmap(rectFirst, *pBitmap);
363 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
367 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
369 AppLogDebug("ENTER");
373 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
380 Bitmap* pBitmap = null;
381 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
383 EnrichedText enTextCount;
384 TextElement textElement;
385 TextElement textElementCount;
387 int allContentCount = pAlbumInfo->GetContentIdCount();
388 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
390 String strFolderName = pAlbumInfo->GetAlbumName();
392 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
393 Color bgColor(COLOR_CANVAS_BG);
394 bgColor.SetAlpha(ALPHA_BG);
395 canvas.FillRectangle(bgColor, rectCanvas);
397 if (strFolderName == ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"))
399 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
401 else if (strFolderName == ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"))
403 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
407 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
412 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
413 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
417 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
418 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
419 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
420 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
422 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
423 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
425 textElement.Construct(strFolderName);
426 textElement.SetFont(ftFolderName);
427 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
428 enText.SetTextAbbreviationEnabled(true);
429 enText.Add(textElement);
431 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
432 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
434 textElementCount.Construct(strCnt);
436 if (strCnt.GetLength() > 3)
438 textElementCount.SetFont(ftCntSmall);
442 textElementCount.SetFont(ftCnt);
444 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
445 enTextCount.SetTextAbbreviationEnabled(true);
446 enTextCount.Add(textElementCount);
448 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH,
449 rectCanvas.y + HEIGHT_OFFSET);
450 canvas.SetFont(ftCnt);
451 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
452 canvas.DrawText(pointText, enTextCount);
454 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP,
455 rectCanvas.y + GAP + HEIGHT_OFFSET);
456 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
457 canvas.DrawText(pointText, enText);
459 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
463 AlbumListPresentationModel::CreateMergeBitmapN(const int index)
465 AppLogDebug("ENTER index(%d)", index);
467 if (__pAlbumInfoList == null)
469 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
474 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
476 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
477 BufferInfo bufferinfo;
479 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
480 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
482 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
486 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
491 pBitmapNew->Lock(bufferinfo);
492 r = canvas.Construct(bufferinfo);
496 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
501 DrawPartialImage(canvas, pAlbumInfo, rectNew);
502 DrawFontImage(canvas, pAlbumInfo, index);
504 pBitmapNew->Unlock();
505 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
511 AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
512 const String* pUriData, const String* pMimeType, const HashMap* pDataList,
513 IAppControlResponseListener* pListener)
515 AppLogDebug("ENTER");
516 FileListPresentationModel::GetInstance()->ClearProviderId();
517 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
520 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
524 result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
528 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
529 pGalleryApp->SetFrameEnabled(false);
534 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
540 AlbumListPresentationModel::GetDirectoryName(String& directoryPath) const
542 AppLogDebug("ENTER");
543 String directoryName;
546 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
547 directoryPath.SubString(lastIndex + 1, directoryName);
548 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
550 return directoryName;
554 AlbumListPresentationModel::GetFolderCount(void) const
556 AppLogDebug("ENTER");
557 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
559 return __pAlbumInfoList->GetCount();
563 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
565 AppLogDebug("ENTER");
567 if (__pFolderBackgroundBitmap == null)
569 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
572 if (__pAlbumInfoList != null)
574 AlbumInfo* pInfo = null;
575 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
577 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
578 if (pInfo->GetAlbumName().IsEmpty() == false)
580 AppLog("Print AlbumName(%d)(%ls)", i, pInfo->GetAlbumName().GetPointer());
583 delete __pAlbumInfoList;
585 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
587 ContentDirectory directory;
589 if (contentType == CONTENT_TYPE_ALL)
591 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
592 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
593 pListT->Add(CONTENT_TYPE_IMAGE);
594 pListT->Add(CONTENT_TYPE_VIDEO);
596 result r = directory.Construct(*pListT);
601 delete __pAlbumInfoList;
602 __pAlbumInfoList = null;
603 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
609 result r = directory.Construct(contentType);
612 delete __pAlbumInfoList;
613 __pAlbumInfoList = null;
614 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
619 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
620 String* pDirPath = null;
621 AlbumInfo* pAlbumInfo = null;
623 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
624 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
625 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
626 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
628 result r = pAllAlbumInfo->Construct();
629 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
630 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
632 r = pCameraAlbumInfo->Construct();
633 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
634 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
636 r = pDownloadAlbumInfo->Construct();
637 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
638 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
640 r = pNoNameAlbumInfo->Construct();
641 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
642 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
644 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
646 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
647 while (pEnum->MoveNext() == E_SUCCESS)
649 pDirPath = static_cast<String*>(pEnum->GetCurrent());
650 String mediaPath = RESERVED_MEDIA_PATH;
651 int length = mediaPath.GetLength();
652 mediaPath.Remove(length-1,1);
654 if (pDirPath == null)
659 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
661 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
663 if (pContentIdList != null)
665 pCameraAlbumInfo->AppendDirectory(*pDirPath);
666 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
668 pAllAlbumInfo->AppendDirectory(*pDirPath);
669 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
670 delete pContentIdList;
673 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
675 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
677 if (pContentIdList != null)
679 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
680 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
682 pAllAlbumInfo->AppendDirectory(*pDirPath);
683 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
685 pContentIdList->RemoveAll(true);
686 delete pContentIdList;
689 else if (*pDirPath == mediaPath)
691 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
693 if (pContentIdList != null)
695 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
696 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
698 pAllAlbumInfo->AppendDirectory(*pDirPath);
699 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
701 pContentIdList->RemoveAll(true);
702 delete pContentIdList;
707 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
709 if (pContentIdList != null)
711 if (pContentIdList->GetCount() > 0)
713 pAlbumInfo = new (std::nothrow) AlbumInfo();
714 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
716 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
718 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
721 pAllAlbumInfo->AppendDirectory(*pDirPath);
722 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
724 pSubDirList->RemoveAll(true);
728 if (pContentIdList != NULL)
730 pContentIdList->RemoveAll(true);
731 delete pContentIdList;
734 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
736 __pAlbumInfoList->Add(pAlbumInfo);
737 AppLog("Adding album");
748 if (pAllAlbumInfo->GetContentIdCount() > 0)
750 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
754 delete pAllAlbumInfo;
757 if (pCameraAlbumInfo->GetContentIdCount() > 0)
759 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
763 delete pCameraAlbumInfo;
766 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
768 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
772 delete pDownloadAlbumInfo;
775 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
777 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
781 delete pNoNameAlbumInfo;
788 delete pAllAlbumInfo;
789 delete pCameraAlbumInfo;
790 delete pDownloadAlbumInfo;
791 delete pNoNameAlbumInfo;
794 if (pContentDirectoryPathList != null)
796 pContentDirectoryPathList->RemoveAll(true);
797 delete pContentDirectoryPathList;
799 ClearThumbnailRequests(false);
800 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
804 if (pContentDirectoryPathList != null)
806 pContentDirectoryPathList->RemoveAll(true);
807 delete pContentDirectoryPathList;
809 delete pAllAlbumInfo;
810 delete pCameraAlbumInfo;
811 delete pDownloadAlbumInfo;
812 delete pNoNameAlbumInfo;
816 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
818 AppLogDebug("ENTER");
819 if (fullPath == null)
821 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
825 String delim(DIRECTORY_SEPARATOR);
826 StringTokenizer st(fullPath,delim);
828 while (st.HasMoreTokens())
830 st.GetNextToken(token);
832 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
838 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
840 AppLogDebug("ENTER");
842 if (&directoryPath == null)
844 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
848 ContentDirectory directory;
849 const String contentDirectoryPath = directoryPath;
850 if (contentType == CONTENT_TYPE_ALL)
852 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
853 pListT->Add(CONTENT_TYPE_IMAGE);
854 pListT->Add(CONTENT_TYPE_VIDEO);
855 result r = directory.Construct(*pListT);
859 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
865 result r = directory.Construct(contentType);
868 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
874 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
875 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
876 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
877 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
879 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
881 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
883 while (pEnum->MoveNext() == E_SUCCESS)
885 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
886 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
887 pContentIdList->Add(pItem);
892 if (pContentInfoList != NULL)
894 pContentInfoList->RemoveAll(true);
895 delete pContentInfoList;
898 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
900 return pContentIdList;
904 AlbumListPresentationModel::DeleteContentFile(const ContentId& contentId)
906 AppLogDebug("ENTER");
907 result r = E_SUCCESS;
908 ContentManager contentManager;
909 r = contentManager.Construct();
912 r = contentManager.DeleteContent(contentId);
914 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
920 AlbumListPresentationModel::GetAppControlMode(void) const
922 AppLogDebug("Enter");
924 return __appControlMode;
928 AlbumListPresentationModel::GetAppControlMediaType(void) const
930 AppLogDebug("Enter");
932 return __appControlMediaType;
935 AppControlSelectionMode
936 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
938 AppLogDebug("Enter");
940 return __appControlSelectionMode;
944 AlbumListPresentationModel::GetAlbumInfoList(void) const
946 AppLogDebug("ENTER");
947 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
949 return __pAlbumInfoList;
952 IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
954 AppLogDebug("ENTER");
955 ContentDirectory directory;
956 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
958 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
959 TryReturn(pListT != null,null, "Unable to Create ArrayListT");
960 pListT->Add(CONTENT_TYPE_IMAGE);
961 pListT->Add(CONTENT_TYPE_VIDEO);
963 result r = directory.Construct(*pListT);
968 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
969 delete pContentIdList;
973 if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
975 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
976 String* pDirPath = null;
977 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
979 int loopCount = pContentDirectoryPathList->GetCount();
980 for (int i = 0; i < loopCount; ++i)
982 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
983 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
989 if(__pAlbumInfoList != null)
991 int loopCount = indexList.GetCount();
992 AlbumInfo* pInfo = null;
993 for (int i = 0; i < loopCount; ++i)
995 int index = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
996 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
1000 IList* pList = pInfo->GetContentIdListN();
1003 pContentIdList->AddItems(*pList);
1009 return pContentIdList;
1013 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
1015 AppLogDebug("ENTER");
1016 if (&eventArg != null)
1018 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
1019 if (pThumbnailEventArg == null)
1021 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1025 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
1026 if (pThumbnailInfo == null)
1028 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1033 ContentId contentId = pThumbnailInfo->GetContentId();
1034 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1036 if (__pAlbumInfoList != null)
1038 int outterLoopCount = __pAlbumInfoList->GetCount();
1039 for (int x = 0; x < outterLoopCount; ++x)
1041 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1042 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1043 for (int i = 0; i < innerLoopCount; ++i)
1045 if (i >= FOLDER_BITMAP_MAX)
1050 if (contentId == pAlbumInfo->GetContentId(i))
1052 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1054 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1055 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1062 delete pThumbnailInfo;
1064 if (__pPresentationModelListener->GetCount() > 0)
1066 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1067 while (pEnum->MoveNext() == E_SUCCESS)
1069 IAlbumEventListener* pListener = null;
1070 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1072 int loopCount = pUpdateFolderIndex->GetCount();
1073 for (int k = 0; k < loopCount; ++k)
1075 Integer *pIndex = (Integer*)pUpdateFolderIndex->GetAt(k);
1076 int folderIndex = pIndex->ToInt();
1077 pListener->OnThumbnailDecoded(folderIndex);
1083 delete pUpdateFolderIndex;
1085 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1089 AlbumListPresentationModel::OnContentCreated(void)
1091 AppLogDebug("ENTER");
1092 if (__updateProgressStatus == true)
1094 AppLogDebug("EXIT update in application");
1097 IFormContentUpdateEventListener* pInterface = null;
1098 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1099 while (pEventEnum->MoveNext() == E_SUCCESS)
1101 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1102 if (pInterface != null)
1104 pInterface->OnContentUpdated();
1108 AppLogDebug("EXIT");
1112 AlbumListPresentationModel::OnContentUpdated(void)
1114 AppLogDebug("ENTER");
1115 if (__updateProgressStatus == true)
1117 AppLogDebug("EXIT update in application");
1120 IFormContentUpdateEventListener* pInterface = null;
1121 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1122 while (pEventEnum->MoveNext() == E_SUCCESS)
1124 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1125 pInterface->OnContentUpdated();
1128 AppLogDebug("EXIT");
1132 AlbumListPresentationModel::OnContentDeleted(void)
1134 AppLogDebug("ENTER");
1135 if (__updateProgressStatus == true)
1137 AppLogDebug("EXIT update in application");
1140 IFormContentUpdateEventListener* pInterface = null;
1141 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1142 while (pEventEnum->MoveNext() == E_SUCCESS)
1144 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1145 pInterface->OnContentUpdated();
1148 AppLogDebug("EXIT");
1152 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1154 AppLogDebug("ENTER");
1155 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1159 AlbumListPresentationModel::SetUpdateProgressStatus(const bool status)
1161 AppLogDebug("ENTER status = %d",status);
1162 __updateProgressStatus = status;
1163 AppLogDebug("EXIT");
1167 AlbumListPresentationModel::RotateImage(int index, RotateMode rotateMode)
1173 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, const int pathIndex)
1175 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1177 ContentId contentId;
1178 if (__pAlbumInfoList != null)
1180 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1181 contentId = pAlbumInfo->GetContentId(pathIndex);
1184 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1185 AppLogDebug("EXIT");
1189 AlbumListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
1191 AppLogDebug("ENTER");
1192 if (__pThumbnailProvider != null)
1194 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1196 AppLogDebug("EXIT");