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 void 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"";
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()));
348 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
350 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
354 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
355 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
356 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
357 canvas.DrawBitmap(rectFirst, *pBitmap);
360 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
364 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
366 AppLogDebug("ENTER");
370 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
377 Bitmap* pBitmap = null;
378 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
380 EnrichedText enTextCount;
381 TextElement textElement;
382 TextElement textElementCount;
384 int allContentCount = pAlbumInfo->GetContentIdCount();
385 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
387 String strFolderName = pAlbumInfo->GetAlbumName();
389 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
390 Color bgColor(COLOR_CANVAS_BG);
391 bgColor.SetAlpha(ALPHA_BG);
392 canvas.FillRectangle(bgColor, rectCanvas);
394 if (strFolderName == ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"))
396 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
398 else if (strFolderName == ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"))
400 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
404 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
409 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
410 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
414 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
415 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
416 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
417 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
419 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
420 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
422 textElement.Construct(strFolderName);
423 textElement.SetFont(ftFolderName);
424 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
425 enText.SetTextAbbreviationEnabled(true);
426 enText.Add(textElement);
428 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
429 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
431 textElementCount.Construct(strCnt);
433 if (strCnt.GetLength() > 3)
435 textElementCount.SetFont(ftCntSmall);
439 textElementCount.SetFont(ftCnt);
441 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
442 enTextCount.SetTextAbbreviationEnabled(true);
443 enTextCount.Add(textElementCount);
445 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH,
446 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,
452 rectCanvas.y + GAP + HEIGHT_OFFSET);
453 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
454 canvas.DrawText(pointText, enText);
456 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
460 AlbumListPresentationModel::CreateMergeBitmapN(const int index)
462 AppLogDebug("ENTER index(%d)", index);
464 if (__pAlbumInfoList == null)
466 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
471 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
473 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
474 BufferInfo bufferinfo;
476 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
477 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
479 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
483 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
488 pBitmapNew->Lock(bufferinfo);
489 r = canvas.Construct(bufferinfo);
493 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
498 DrawPartialImage(canvas, pAlbumInfo, rectNew);
499 DrawFontImage(canvas, pAlbumInfo, index);
501 pBitmapNew->Unlock();
502 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
508 AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
509 const String* pUriData, const String* pMimeType, const HashMap* pDataList,
510 IAppControlResponseListener* pListener)
512 AppLogDebug("ENTER");
513 FileListPresentationModel::GetInstance()->ClearProviderId();
514 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
517 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
521 result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
525 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
526 pGalleryApp->SetFrameEnabled(false);
531 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
537 AlbumListPresentationModel::GetDirectoryName(String& directoryPath) const
539 AppLogDebug("ENTER");
540 String directoryName;
543 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
544 directoryPath.SubString(lastIndex + 1, directoryName);
545 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
547 return directoryName;
551 AlbumListPresentationModel::GetFolderCount(void) const
553 AppLogDebug("ENTER");
554 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
556 return __pAlbumInfoList->GetCount();
560 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
562 AppLogDebug("ENTER");
564 if (__pFolderBackgroundBitmap == null)
566 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
569 if (__pAlbumInfoList != null)
571 AlbumInfo* pInfo = null;
572 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
574 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
575 if (pInfo->GetAlbumName().IsEmpty() == false)
577 AppLog("Print AlbumName(%d)(%ls)", i, pInfo->GetAlbumName().GetPointer());
580 delete __pAlbumInfoList;
582 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
584 ContentDirectory directory;
586 if (contentType == CONTENT_TYPE_ALL)
588 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
589 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
590 pListT->Add(CONTENT_TYPE_IMAGE);
591 pListT->Add(CONTENT_TYPE_VIDEO);
593 result r = directory.Construct(*pListT);
598 delete __pAlbumInfoList;
599 __pAlbumInfoList = null;
600 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
606 result r = directory.Construct(contentType);
609 delete __pAlbumInfoList;
610 __pAlbumInfoList = null;
611 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
616 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
617 String* pDirPath = null;
618 AlbumInfo* pAlbumInfo = null;
620 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
621 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
622 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
623 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
625 result r = pAllAlbumInfo->Construct();
626 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
627 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
629 r = pCameraAlbumInfo->Construct();
630 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
631 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
633 r = pDownloadAlbumInfo->Construct();
634 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
635 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
637 r = pNoNameAlbumInfo->Construct();
638 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
639 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
641 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
643 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
644 while (pEnum->MoveNext() == E_SUCCESS)
646 pDirPath = static_cast<String*>(pEnum->GetCurrent());
647 String mediaPath = RESERVED_MEDIA_PATH;
648 int length = mediaPath.GetLength();
649 mediaPath.Remove(length-1,1);
651 if (pDirPath == null)
656 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
658 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
660 if (pContentIdList != null)
662 pCameraAlbumInfo->AppendDirectory(*pDirPath);
663 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
665 pAllAlbumInfo->AppendDirectory(*pDirPath);
666 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
667 delete pContentIdList;
670 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
672 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
674 if (pContentIdList != null)
676 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
677 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
679 pAllAlbumInfo->AppendDirectory(*pDirPath);
680 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
682 pContentIdList->RemoveAll(true);
683 delete pContentIdList;
686 else if (*pDirPath == mediaPath)
688 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
690 if (pContentIdList != null)
692 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
693 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
695 pAllAlbumInfo->AppendDirectory(*pDirPath);
696 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
698 pContentIdList->RemoveAll(true);
699 delete pContentIdList;
704 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
706 if (pContentIdList != null)
708 if (pContentIdList->GetCount() > 0)
710 pAlbumInfo = new (std::nothrow) AlbumInfo();
711 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
713 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
715 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
718 pAllAlbumInfo->AppendDirectory(*pDirPath);
719 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
721 pSubDirList->RemoveAll(true);
725 if (pContentIdList != NULL)
727 pContentIdList->RemoveAll(true);
728 delete pContentIdList;
731 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
733 __pAlbumInfoList->Add(pAlbumInfo);
744 if (pAllAlbumInfo->GetContentIdCount() > 0)
746 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, ++insertIndex);
750 delete pAllAlbumInfo;
753 if (pCameraAlbumInfo->GetContentIdCount() > 0)
755 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, ++insertIndex);
759 delete pCameraAlbumInfo;
762 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
764 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, ++insertIndex);
768 delete pDownloadAlbumInfo;
771 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
773 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, ++insertIndex);
777 delete pNoNameAlbumInfo;
784 delete pAllAlbumInfo;
785 delete pCameraAlbumInfo;
786 delete pDownloadAlbumInfo;
787 delete pNoNameAlbumInfo;
790 if (pContentDirectoryPathList != null)
792 pContentDirectoryPathList->RemoveAll(true);
793 delete pContentDirectoryPathList;
795 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
799 if (pContentDirectoryPathList != null)
801 pContentDirectoryPathList->RemoveAll(true);
802 delete pContentDirectoryPathList;
804 delete pAllAlbumInfo;
805 delete pCameraAlbumInfo;
806 delete pDownloadAlbumInfo;
807 delete pNoNameAlbumInfo;
811 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
813 AppLogDebug("ENTER");
814 if (fullPath == null)
816 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
820 String delim(DIRECTORY_SEPARATOR);
821 StringTokenizer st(fullPath,delim);
823 while (st.HasMoreTokens())
825 st.GetNextToken(token);
827 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
833 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
835 AppLogDebug("ENTER");
837 if (&directoryPath == null)
839 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
843 ContentDirectory directory;
844 const String contentDirectoryPath = directoryPath;
845 if (contentType == CONTENT_TYPE_ALL)
847 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
848 pListT->Add(CONTENT_TYPE_IMAGE);
849 pListT->Add(CONTENT_TYPE_VIDEO);
850 result r = directory.Construct(*pListT);
854 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
860 result r = directory.Construct(contentType);
863 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
869 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
870 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
871 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
872 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
874 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
876 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
878 while (pEnum->MoveNext() == E_SUCCESS)
880 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
881 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
882 pContentIdList->Add(pItem);
887 if (pContentInfoList != NULL)
889 pContentInfoList->RemoveAll(true);
890 delete pContentInfoList;
893 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
895 return pContentIdList;
899 AlbumListPresentationModel::DeleteContentFile(const ContentId& contentId)
901 AppLogDebug("ENTER");
902 result r = E_SUCCESS;
903 ContentManager contentManager;
904 r = contentManager.Construct();
907 r = contentManager.DeleteContent(contentId);
909 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
915 AlbumListPresentationModel::GetAppControlMode(void) const
917 AppLogDebug("Enter");
919 return __appControlMode;
923 AlbumListPresentationModel::GetAppControlMediaType(void) const
925 AppLogDebug("Enter");
927 return __appControlMediaType;
930 AppControlSelectionMode
931 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
933 AppLogDebug("Enter");
935 return __appControlSelectionMode;
939 AlbumListPresentationModel::GetAlbumInfoList(void) const
941 AppLogDebug("ENTER");
942 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
944 return __pAlbumInfoList;
947 IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
949 AppLogDebug("ENTER");
950 ContentDirectory directory;
951 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
953 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
954 TryReturn(pListT != null,null, "Unable to Create ArrayListT");
955 pListT->Add(CONTENT_TYPE_IMAGE);
956 pListT->Add(CONTENT_TYPE_VIDEO);
958 result r = directory.Construct(*pListT);
963 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
964 delete pContentIdList;
968 if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
970 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
971 String* pDirPath = null;
972 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
974 int loopCount = pContentDirectoryPathList->GetCount();
975 for (int i = 0; i < loopCount; ++i)
977 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
978 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
984 if(__pAlbumInfoList != null)
986 int loopCount = indexList.GetCount();
987 AlbumInfo* pInfo = null;
988 for (int i = 0; i < loopCount; ++i)
990 int index = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
991 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
995 IList* pList = pInfo->GetContentIdListN();
998 pContentIdList->AddItems(*pList);
1004 return pContentIdList;
1008 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
1010 AppLogDebug("ENTER");
1011 if (&eventArg != null)
1013 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
1014 if (pThumbnailEventArg == null)
1016 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1020 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
1021 if (pThumbnailInfo == null)
1023 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1028 ContentId contentId = pThumbnailInfo->GetContentId();
1029 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1031 if (__pAlbumInfoList != null)
1033 int outterLoopCount = __pAlbumInfoList->GetCount();
1034 for (int x = 0; x < outterLoopCount; ++x)
1036 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1037 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1038 for (int i = 0; i < innerLoopCount; ++i)
1040 if (i >= FOLDER_BITMAP_MAX)
1045 if (contentId == pAlbumInfo->GetContentId(i))
1047 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1049 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1050 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1057 if (__pPresentationModelListener->GetCount() > 0)
1059 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1060 while (pEnum->MoveNext() == E_SUCCESS)
1062 IAlbumEventListener* pListener = null;
1063 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1065 int loopCount = pUpdateFolderIndex->GetCount();
1066 for (int k = 0; k < loopCount; ++k)
1068 Integer *pIndex = (Integer*)pUpdateFolderIndex->GetAt(k);
1069 int folderIndex = pIndex->ToInt();
1070 pListener->OnThumbnailDecoded(folderIndex);
1076 delete pUpdateFolderIndex;
1078 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1082 AlbumListPresentationModel::OnContentCreated(void)
1084 AppLogDebug("ENTER");
1085 if (__updateProgressStatus == true)
1087 AppLogDebug("EXIT update in application");
1090 IFormContentUpdateEventListener* pInterface = null;
1091 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1092 while (pEventEnum->MoveNext() == E_SUCCESS)
1094 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1095 if (pInterface != null)
1097 pInterface->OnContentUpdated();
1101 AppLogDebug("EXIT");
1105 AlbumListPresentationModel::OnContentUpdated(void)
1107 AppLogDebug("ENTER");
1108 if (__updateProgressStatus == true)
1110 AppLogDebug("EXIT update in application");
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();
1121 AppLogDebug("EXIT");
1125 AlbumListPresentationModel::OnContentDeleted(void)
1127 AppLogDebug("ENTER");
1128 if (__updateProgressStatus == true)
1130 AppLogDebug("EXIT update in application");
1133 IFormContentUpdateEventListener* pInterface = null;
1134 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1135 while (pEventEnum->MoveNext() == E_SUCCESS)
1137 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1138 pInterface->OnContentUpdated();
1141 AppLogDebug("EXIT");
1145 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1147 AppLogDebug("ENTER");
1148 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1152 AlbumListPresentationModel::SetUpdateProgressStatus(const bool status)
1154 AppLogDebug("ENTER status = %d",status);
1155 __updateProgressStatus = status;
1156 AppLogDebug("EXIT");
1160 AlbumListPresentationModel::RotateImage(int index, RotateMode rotateMode)
1166 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, const int pathIndex)
1168 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1170 ContentId contentId;
1171 if (__pAlbumInfoList != null)
1173 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1174 contentId = pAlbumInfo->GetContentId(pathIndex);
1177 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1178 AppLogDebug("EXIT");
1182 AlbumListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
1184 AppLogDebug("ENTER");
1185 if (__pThumbnailProvider != null)
1187 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1189 AppLogDebug("EXIT");