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 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
116 AlbumListPresentationModel*
117 AlbumListPresentationModel::GetInstance(void)
119 AppLogDebug("ENTER");
120 if (__pPresentationModelInstance == null)
124 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
126 return __pPresentationModelInstance;
130 AlbumListPresentationModel::Construct(void)
132 AppLogDebug("ENTER");
133 __pPresentationModelListener = new (std::nothrow) ArrayList();
134 __pPresentationModelListener->Construct();
136 ContentUpdateEventListener::GetInstance();
137 __pContentEventListener = new (std::nothrow) ArrayList();
138 __pContentEventListener->Construct();
140 IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
141 __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
142 __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
144 __pContentManager = new (std::nothrow) ContentManager();
145 __pContentManager->Construct();
147 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
149 __pThumbnailProvider = ThumbnailProvider::GetInstance();
150 AppLogDebug("ENTER1");
151 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
152 const IMap* pArguments = pApp->GetAppControlArguments();
153 String operationId = pApp->GetAppControlOperationId();
155 if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
157 __appControlMode = APPCONTROL_MODE_MAIN;
159 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
161 __appControlMode = APPCONTROL_MODE_PICK;
163 String mimeType = pApp->GetMimeType();
164 if (mimeType.IsEmpty() != true)
166 if (mimeType.StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
168 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
171 if (pArguments != null)
173 const String* selectionMode =
174 static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
175 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
177 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
181 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
183 __appControlMode = APPCONTROL_MODE_SETTING;
186 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
192 AlbumListPresentationModel::CreateInstance(void)
194 AppLogDebug("ENTER");
195 __pPresentationModelInstance = new (std::nothrow) AlbumListPresentationModel;
196 result r = __pPresentationModelInstance->Construct();
198 if (IsFailed(r) == true)
200 delete __pPresentationModelInstance;
201 __pPresentationModelInstance = null;
202 AppLogDebug("EXIT false");
205 std::atexit(DestroyInstance);
206 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
210 AlbumListPresentationModel::DestroyInstance(void)
212 AppLogDebug("ENTER");
214 delete __pThumbnailEvent;
215 __pThumbnailEvent = null;
217 if (__pAlbumInfoList != null)
219 delete __pAlbumInfoList;
220 __pAlbumInfoList = null;
223 if (__pPresentationModelListener != null)
225 delete __pPresentationModelListener;
226 __pPresentationModelListener = null;
229 if (__pContentEventListener != null)
231 delete __pContentEventListener;
232 __pContentEventListener = null;
235 delete __pPresentationModelInstance;
236 __pPresentationModelInstance = null;
238 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
242 AlbumListPresentationModel::AddPresentationModelListener(IAlbumEventListener* listener)
244 AppLogDebug("ENTER");
245 result r = __pPresentationModelListener->Add(listener);
246 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
252 AlbumListPresentationModel::RemovePresentationModelListener(IAlbumEventListener& listner)
254 AppLogDebug("ENTER");
255 result r = __pPresentationModelListener->Remove(listner);
256 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
262 AlbumListPresentationModel::AddContentEventListener(const IFormContentUpdateEventListener* listener)
264 AppLogDebug("ENTER");
265 if (__pContentEventListener != null)
267 __pContentEventListener->RemoveAll();
268 __pContentEventListener->Add((Object*)listener);
269 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
274 AlbumListPresentationModel::RemoveContentEventListener(const IFormContentUpdateEventListener& listener)
276 AppLogDebug("ENTER");
277 __pContentEventListener->Remove(listener);
278 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
282 AlbumListPresentationModel::CallAlbumChangedEvent(void)
284 AppLogDebug("ENTER");
285 if (__pPresentationModelListener->GetCount() > 0)
287 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
289 while (pEnum->MoveNext() == E_SUCCESS)
291 IAlbumEventListener* pListener = null;
292 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
293 pListener->OnFileInfoChanged(CONTENT_TYPE_ALL);
298 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
302 AlbumListPresentationModel::RenameAlbum(const String& orgPath, const String& newPath,
303 IAlbumRenameEventListener* pAlbumListener)
305 AppLogDebug("ENTER");
306 result r = Directory::Rename(orgPath, newPath);
309 AppLogDebug("Album Rename failed(%s)", GetErrorMessage(r));
313 __pAlbumListener = pAlbumListener;
314 __renameNewPath = newPath;
\r
315 r = ContentManager::ScanDirectory(newPath, true, NULL, __reqId);
\r
316 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
317 r = ContentManager::ScanDirectory(orgPath, true, NULL, __reqId);
\r
318 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
324 void AlbumListPresentationModel::OnContentScanCompleted (const Tizen::Base::String &scanPath)
\r
326 AppLogDebug("ENTER");
\r
327 if (__pAlbumListener && ( scanPath == __renameNewPath))
\r
329 InitializeAlbumInfoList(CONTENT_TYPE_ALL);
330 __pAlbumListener->OnAlbumRenameComplete();
331 __renameNewPath = L"";
337 AlbumListPresentationModel::DrawPartialImage(Canvas& canvas, AlbumInfo* pAlbumInfo, const Rectangle& rectNew)
339 AppLogDebug("ENTER");
340 if (&canvas == null || __pFolderBackgroundBitmap == null || pAlbumInfo == null)
342 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
346 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
348 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
352 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
353 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
354 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
355 canvas.DrawBitmap(rectFirst, *pBitmap);
358 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
362 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
364 AppLogDebug("ENTER");
368 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
375 Bitmap* pBitmap = null;
376 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
378 EnrichedText enTextCount;
379 TextElement textElement;
380 TextElement textElementCount;
382 int allContentCount = pAlbumInfo->GetContentIdCount();
383 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
385 String strFolderName = pAlbumInfo->GetAlbumName();
387 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
388 Color bgColor(COLOR_CANVAS_BG);
389 bgColor.SetAlpha(ALPHA_BG);
390 canvas.FillRectangle(bgColor, rectCanvas);
392 if (strFolderName == ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"))
394 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
396 else if (strFolderName == ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"))
398 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
402 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
407 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
408 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
412 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
413 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
414 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
415 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
417 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
418 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
420 textElement.Construct(strFolderName);
421 textElement.SetFont(ftFolderName);
422 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
423 enText.SetTextAbbreviationEnabled(true);
424 enText.Add(textElement);
426 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
427 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
429 textElementCount.Construct(strCnt);
431 if (strCnt.GetLength() > 3)
433 textElementCount.SetFont(ftCntSmall);
437 textElementCount.SetFont(ftCnt);
439 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
440 enTextCount.SetTextAbbreviationEnabled(true);
441 enTextCount.Add(textElementCount);
443 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH , rectCanvas.y + HEIGHT_OFFSET);
444 canvas.SetFont(ftCnt);
445 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
446 canvas.DrawText(pointText, enTextCount);
448 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP , rectCanvas.y + GAP + HEIGHT_OFFSET);
449 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
450 canvas.DrawText(pointText, enText);
452 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
456 AlbumListPresentationModel::CreateMergeBitmapN(const int index)
458 AppLogDebug("ENTER index(%d)", index);
460 if (__pAlbumInfoList == null)
462 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
467 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
469 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
470 BufferInfo bufferinfo;
472 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
473 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
475 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
479 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
484 pBitmapNew->Lock(bufferinfo);
485 r = canvas.Construct(bufferinfo);
489 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
494 DrawPartialImage(canvas, pAlbumInfo, rectNew);
495 DrawFontImage(canvas, pAlbumInfo, index);
497 pBitmapNew->Unlock();
498 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
504 AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
505 const String* pUriData, const String* pMimeType, const HashMap* pDataList,
506 IAppControlResponseListener* pListener)
508 AppLogDebug("ENTER");
509 FileListPresentationModel::GetInstance()->ClearProviderId();
510 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
513 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
517 result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
521 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
522 pGalleryApp->SetFrameEnabled(false);
527 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
533 AlbumListPresentationModel::GetDirectoryName(String& directoryPath) const
535 AppLogDebug("ENTER");
536 String directoryName;
539 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
540 directoryPath.SubString(lastIndex + 1, directoryName);
541 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
543 return directoryName;
547 AlbumListPresentationModel::GetFolderCount(void) const
549 AppLogDebug("ENTER");
550 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
552 return __pAlbumInfoList->GetCount();
556 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
558 AppLogDebug("ENTER");
560 if (__pFolderBackgroundBitmap == null)
562 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
565 if (__pAlbumInfoList != null)
567 AlbumInfo* pInfo = null;
568 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
570 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
571 if (pInfo->GetAlbumName().IsEmpty() == false)
573 AppLog("Print AlbumName(%d)(%ls)", i, pInfo->GetAlbumName().GetPointer());
576 delete __pAlbumInfoList;
578 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
580 ContentDirectory directory;
582 if (contentType == CONTENT_TYPE_ALL)
584 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
585 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
586 pListT->Add(CONTENT_TYPE_IMAGE);
587 pListT->Add(CONTENT_TYPE_VIDEO);
589 result r = directory.Construct(*pListT);
594 delete __pAlbumInfoList;
595 __pAlbumInfoList = null;
596 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
602 result r = directory.Construct(contentType);
605 delete __pAlbumInfoList;
606 __pAlbumInfoList = null;
607 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
612 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
613 String* pDirPath = null;
614 AlbumInfo* pAlbumInfo = null;
616 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
617 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
618 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
619 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
621 result r = pAllAlbumInfo->Construct();
622 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
623 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
625 r = pCameraAlbumInfo->Construct();
626 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
627 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
629 r = pDownloadAlbumInfo->Construct();
630 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
631 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
633 r = pNoNameAlbumInfo->Construct();
634 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
635 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
637 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
639 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
640 while (pEnum->MoveNext() == E_SUCCESS)
642 pDirPath = static_cast<String*>(pEnum->GetCurrent());
643 String mediaPath = RESERVED_MEDIA_PATH;
644 int length = mediaPath.GetLength();
645 mediaPath.Remove(length-1,1);
647 if (pDirPath == null)
652 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
654 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
656 if (pContentIdList != null)
658 pCameraAlbumInfo->AppendDirectory(*pDirPath);
659 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
661 pAllAlbumInfo->AppendDirectory(*pDirPath);
662 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
663 delete pContentIdList;
666 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
668 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
670 if (pContentIdList != null)
672 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
673 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
675 pAllAlbumInfo->AppendDirectory(*pDirPath);
676 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
678 pContentIdList->RemoveAll(true);
679 delete pContentIdList;
682 else if (*pDirPath == mediaPath)
684 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
686 if (pContentIdList != null)
688 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
689 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
691 pAllAlbumInfo->AppendDirectory(*pDirPath);
692 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
694 pContentIdList->RemoveAll(true);
695 delete pContentIdList;
700 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
702 if (pContentIdList != null)
704 if (pContentIdList->GetCount() > 0)
706 pAlbumInfo = new (std::nothrow) AlbumInfo();
707 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
709 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
711 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
714 pAllAlbumInfo->AppendDirectory(*pDirPath);
715 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
717 pSubDirList->RemoveAll(true);
721 if ( pContentIdList != NULL)
723 pContentIdList->RemoveAll(true);
724 delete pContentIdList;
727 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
729 __pAlbumInfoList->Add(pAlbumInfo);
740 if (pAllAlbumInfo->GetContentIdCount() > 0)
742 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
746 delete pAllAlbumInfo;
749 if (pCameraAlbumInfo->GetContentIdCount() > 0)
751 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
755 delete pCameraAlbumInfo;
758 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
760 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
764 delete pDownloadAlbumInfo;
767 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
769 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
773 delete pNoNameAlbumInfo;
780 delete pAllAlbumInfo;
781 delete pCameraAlbumInfo;
782 delete pDownloadAlbumInfo;
783 delete pNoNameAlbumInfo;
786 if (pContentDirectoryPathList != null)
788 pContentDirectoryPathList->RemoveAll(true);
789 delete pContentDirectoryPathList;
791 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
795 if (pContentDirectoryPathList != null)
797 pContentDirectoryPathList->RemoveAll(true);
798 delete pContentDirectoryPathList;
800 delete pAllAlbumInfo;
801 delete pCameraAlbumInfo;
802 delete pDownloadAlbumInfo;
803 delete pNoNameAlbumInfo;
807 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
809 AppLogDebug("ENTER");
810 if (fullPath == null)
812 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
816 String delim(DIRECTORY_SEPARATOR);
817 StringTokenizer st(fullPath,delim);
819 while (st.HasMoreTokens())
821 st.GetNextToken(token);
823 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
829 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
831 AppLogDebug("ENTER");
833 if (&directoryPath == null)
835 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
839 ContentDirectory directory;
840 const String contentDirectoryPath = directoryPath;
841 if (contentType == CONTENT_TYPE_ALL)
843 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
844 pListT->Add(CONTENT_TYPE_IMAGE);
845 pListT->Add(CONTENT_TYPE_VIDEO);
846 result r = directory.Construct(*pListT);
850 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
856 result r = directory.Construct(contentType);
859 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
865 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
866 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
867 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
868 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
870 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
872 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
874 while (pEnum->MoveNext() == E_SUCCESS)
876 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
877 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
878 pContentIdList->Add(pItem);
883 if ( pContentInfoList != NULL)
885 pContentInfoList->RemoveAll(true);
886 delete pContentInfoList;
889 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
891 return pContentIdList;
895 AlbumListPresentationModel::DeleteContentFile(const ContentId& contentId)
897 AppLogDebug("ENTER");
898 result r = E_SUCCESS;
899 ContentManager contentManager;
900 r = contentManager.Construct();
903 r = contentManager.DeleteContent(contentId);
905 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
911 AlbumListPresentationModel::GetAppControlMode(void) const
913 AppLogDebug("Enter");
915 return __appControlMode;
919 AlbumListPresentationModel::GetAppControlMediaType(void) const
921 AppLogDebug("Enter");
923 return __appControlMediaType;
926 AppControlSelectionMode
927 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
929 AppLogDebug("Enter");
931 return __appControlSelectionMode;
935 AlbumListPresentationModel::GetAlbumInfoList(void) const
937 AppLogDebug("ENTER");
938 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
940 return __pAlbumInfoList;
943 IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
945 AppLogDebug("ENTER");
946 ContentDirectory directory;
947 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
949 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
950 TryReturn(pListT != null,null, "Unable to Create ArrayListT");
951 pListT->Add(CONTENT_TYPE_IMAGE);
952 pListT->Add(CONTENT_TYPE_VIDEO);
954 result r = directory.Construct(*pListT);
959 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
960 delete pContentIdList;
964 if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
966 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
967 String* pDirPath = null;
968 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
970 int loopCount = pContentDirectoryPathList->GetCount();
971 for (int i = 0; i < loopCount; ++i)
973 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
974 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
980 if(__pAlbumInfoList != null)
982 int loopCount = indexList.GetCount();
983 AlbumInfo* pInfo = null;
984 for (int i = 0; i < loopCount; ++i)
986 int index = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
987 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
991 IList* pList = pInfo->GetContentIdListN();
994 pContentIdList->AddItems(*pList);
1000 return pContentIdList;
1004 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
1006 AppLogDebug("ENTER");
1007 if (&eventArg != null)
1009 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
1010 if (pThumbnailEventArg == null)
1012 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1016 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
1017 if (pThumbnailInfo == null)
1019 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1024 ContentId contentId = pThumbnailInfo->GetContentId();
1025 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1027 if (__pAlbumInfoList != null)
1029 int outterLoopCount = __pAlbumInfoList->GetCount();
1030 for (int x = 0; x < outterLoopCount; ++x)
1032 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1033 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1034 for (int i = 0; i < innerLoopCount; ++i)
1036 if (i >= FOLDER_BITMAP_MAX)
1041 if (contentId == pAlbumInfo->GetContentId(i))
1043 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1045 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1046 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1053 if (__pPresentationModelListener->GetCount() > 0)
1055 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1056 while (pEnum->MoveNext() == E_SUCCESS)
1058 IAlbumEventListener* pListener = null;
1059 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1061 int loopCount = pUpdateFolderIndex->GetCount();
1062 for (int k = 0; k < loopCount; ++k)
1064 Integer *pIndex = (Integer*)pUpdateFolderIndex->GetAt(k);
1065 int folderIndex = pIndex->ToInt();
1066 pListener->OnThumbnailDecoded(folderIndex);
1072 delete pUpdateFolderIndex;
1074 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1078 AlbumListPresentationModel::OnContentCreated(void)
1080 AppLogDebug("ENTER");
1081 if (__updateProgressStatus == true)
1083 AppLogDebug("EXIT update in application");
1086 IFormContentUpdateEventListener* pInterface = null;
1087 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1088 while (pEventEnum->MoveNext() == E_SUCCESS)
1090 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1091 if (pInterface != null)
1093 pInterface->OnContentUpdated();
1097 AppLogDebug("EXIT");
1101 AlbumListPresentationModel::OnContentUpdated(void)
1103 AppLogDebug("ENTER");
1104 if (__updateProgressStatus == true)
1106 AppLogDebug("EXIT update in application");
1109 IFormContentUpdateEventListener* pInterface = null;
1110 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1111 while (pEventEnum->MoveNext() == E_SUCCESS)
1113 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1114 pInterface->OnContentUpdated();
1117 AppLogDebug("EXIT");
1121 AlbumListPresentationModel::OnContentDeleted(void)
1123 AppLogDebug("ENTER");
1124 if (__updateProgressStatus == true)
1126 AppLogDebug("EXIT update in application");
1129 IFormContentUpdateEventListener* pInterface = null;
1130 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1131 while (pEventEnum->MoveNext() == E_SUCCESS)
1133 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1134 pInterface->OnContentUpdated();
1137 AppLogDebug("EXIT");
1141 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1143 AppLogDebug("ENTER");
1144 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1148 AlbumListPresentationModel::SetUpdateProgressStatus(const bool status)
1150 AppLogDebug("ENTER status = %d",status);
1151 __updateProgressStatus = status;
1152 AppLogDebug("EXIT");
1156 AlbumListPresentationModel::RotateImage(int index, RotateMode rotateMode)
1162 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, const int pathIndex)
1164 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1166 ContentId contentId;
1167 if (__pAlbumInfoList != null)
1169 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1170 contentId = pAlbumInfo->GetContentId(pathIndex);
1173 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1174 AppLogDebug("EXIT");
1178 AlbumListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
1180 AppLogDebug("ENTER");
1181 if (__pThumbnailProvider != null)
1183 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1185 AppLogDebug("EXIT");