2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file GlAlbumListPresentationModel.cpp
19 * @brief This is the implementation file for AlbumListPresentationModel class.
26 #include "GlAlbumInfo.h"
27 #include "GlAlbumListPresentationModel.h"
28 #include "GlAlbumRenameEventListener.h"
29 #include "GlContentUpdateEventListener.h"
30 #include "GlGalleryApp.h"
31 #include "GlThumbnailEvent.h"
32 #include "GlThumbnailEventArg.h"
33 #include "GlThumbnailProvider.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::Base::Utility;
40 using namespace Tizen::Content;
41 using namespace Tizen::Graphics;
42 using namespace Tizen::Io;
43 using namespace Tizen::Media;
44 using namespace Tizen::System;
45 using namespace Tizen::Ui::Controls;
47 static const int ICON_CAP = 3;
48 static const int FOLDER_CAP = 8;
49 static const int ICON_SIZE = 107;
50 static const int FOLDER_SIZE_WIDTH = 348;
51 static const int FOLDER_SIZE_HEIGHT = 348;
53 static const int CANVAS_HEIGHT = 71;
54 static const int CANVAS_WIDTH = 326;
56 static const int FONT_SIZE_FOLDER_NAME = 32;
57 static const int FONT_SIZE_FOLDER_DATE = 25;
58 static const int FONT_SIZE_FOLDER_COUNT = 45;
59 static const int FONT_SIZE_FOLDER_COUNT_SMALL = 35;
61 static const int CANVAS_IMAGE_FOLDER_HEIGHT = 48;
62 static const int CANVAS_IMAGE_FOLDER_WIDTH = 48;
63 static const int IMAGE_COUNT_WIDTH = 100;
64 static const int IMAGE_COUNT_HEIGHT = 60;
65 static const int CANVAS_MARGIN_LEFT = 10;
66 static const int GAP = 10;
67 static const int HEIGHT_OFFSET = 5;
68 static const int Y_POS_CANVAS = 260;
69 static const int FOLDER_NAME_WIDTH = 165;
70 static const int FOLDER_NAME_HEIGHT = 38 ;
73 static const int ALPHA_BG = 110;
75 static const Color COLOR_CANVAS_BG (Color::GetColor(COLOR_ID_BLACK));
77 static const String RESERVED_MEDIA_PATH = Environment::GetMediaPath();
78 static const String RESERVED_CAMERA_PATH = Environment::GetMediaPath() + L"Camera";
79 static const String RESERVED_CAMERA_PATH_EXT = Environment::GetExternalStoragePath() + L"Camera";
80 static const String RESERVED_DOWNLOAD_PATH = Environment::GetMediaPath() + L"Downloads";
81 static const String CONTENT_INFO_ORDER = L"ContentFileName";
83 static const int FORMAT_BUFFER_SIZE = 256;
85 static const int DOUBLE_NUMBER = 2;
86 static const int TRIPLE_NUMBER = 3;
88 AlbumListPresentationModel* AlbumListPresentationModel::__pPresentationModelInstance = null;
89 ArrayList* AlbumListPresentationModel::__pPresentationModelListener = null;
90 ArrayList* AlbumListPresentationModel::__pContentEventListener = null;
91 ThumbnailProvider* AlbumListPresentationModel::__pThumbnailProvider = null;
92 ThumbnailEvent* AlbumListPresentationModel::__pThumbnailEvent = null;
93 IList* AlbumListPresentationModel::__pAlbumInfoList = null;
95 AlbumListPresentationModel::AlbumListPresentationModel(void)
96 : __pFolderBackgroundBitmap(null)
97 , __pAlbumListener(null)
98 , __appControlMode(APP_CONTROL_MODE_MAIN)
99 , __appControlMediaType(APPCONTROL_MEDIA_TYPE_IMAGE)
100 , __appControlSelectionMode(APPCONTROL_SELECTION_MODE_SINGLE)
101 , __updateProgressStatus(false)
103 AppLogDebug("ENTER");
104 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
107 AlbumListPresentationModel::~AlbumListPresentationModel(void)
109 AppLogDebug("ENTER");
110 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
113 AlbumListPresentationModel*
114 AlbumListPresentationModel::GetInstance(void)
116 AppLogDebug("ENTER");
117 if (__pPresentationModelInstance == null)
121 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
123 return __pPresentationModelInstance;
127 AlbumListPresentationModel::Construct(void)
129 AppLogDebug("ENTER");
130 __pPresentationModelListener = new (std::nothrow) ArrayList();
131 __pPresentationModelListener->Construct();
133 ContentUpdateEventListener::GetInstance();
134 __pContentEventListener = new (std::nothrow) ArrayList();
135 __pContentEventListener->Construct();
137 IThumbnailEventListener* pThumbnailEventListener = static_cast<IThumbnailEventListener*>(this);
138 __pThumbnailEvent = new (std::nothrow) ThumbnailEvent();
139 __pThumbnailEvent->AddListener(*pThumbnailEventListener, true);
141 __pContentManager = new (std::nothrow) ContentManager();
142 __pContentManager->Construct();
144 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
146 __pThumbnailProvider = ThumbnailProvider::GetInstance();
147 AppLogDebug("ENTER1");
148 GalleryApp* pApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
149 const IMap* pArguments = pApp->GetAppControlArguments();
150 String operationId = pApp->GetAppControlOperationId();
152 if (operationId.CompareTo(APPCONTROL_OPERATION_ID_MAIN) == 0)
154 __appControlMode = APP_CONTROL_MODE_MAIN;
156 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_PICK) == 0)
158 __appControlMode = APP_CONTROL_MODE_PICK;
160 String mimeType = pApp->GetMimeType();
161 if (mimeType.IsEmpty() != true)
163 if (mimeType.StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
165 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
168 if (pArguments != null)
170 const String* selectionMode =
171 static_cast<const String*>(pArguments->GetValue(String(APPCONTROL_KEY_SELECTION_MODE)));
172 if (selectionMode != null && selectionMode->CompareTo(APPCONTROL_DATA_MULTIPLE) == 0)
174 __appControlSelectionMode = APPCONTROL_SELECTION_MODE_MULTIPLE;
177 if (pApp->GetMimeType().StartsWith(APPCONTROL_DATA_VIDEO, 0) == true)
179 __appControlMediaType = APPCONTROL_MEDIA_TYPE_VIDEO;
183 else if (operationId.CompareTo(APPCONTROL_OPERATION_ID_CONFIGURE) == 0)
185 __appControlMode = APP_CONTROL_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 r = ContentManager::ScanDirectory(Tizen::System::Environment::GetMediaPath(), true, this, __reqId);
317 AppLogDebug("Content scan failed (%s)", GetErrorMessage(r));
323 void AlbumListPresentationModel::OnContentScanCompleted (RequestId reqId, const Tizen::Base::String &scanPath, result r)
325 AppLogDebug("ENTER");
326 if (__pAlbumListener && __reqId == reqId)
328 InitializeAlbumInfoList(CONTENT_TYPE_ALL);
329 __pAlbumListener->OnAlbumRenameComplete();
335 AlbumListPresentationModel::DrawPartialImage(Canvas& canvas, AlbumInfo* pAlbumInfo, const Rectangle& rectNew)
337 AppLogDebug("ENTER");
338 if (&canvas == null || __pFolderBackgroundBitmap == null || pAlbumInfo == null)
340 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
344 canvas.DrawBitmap(rectNew, *__pFolderBackgroundBitmap);
346 Bitmap* pBitmap = pAlbumInfo->GetFolderThumnailBitmap();
350 Rectangle rectFirst(ICON_CAP+FOLDER_CAP, ICON_CAP,
351 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER,
352 ICON_CAP * DOUBLE_NUMBER + ICON_SIZE * TRIPLE_NUMBER);
353 canvas.DrawBitmap(rectFirst, *pBitmap);
356 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
360 AlbumListPresentationModel::DrawFontImage(Canvas& canvas, AlbumInfo* pAlbumInfo, int index)
362 AppLogDebug("ENTER");
366 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
373 Bitmap* pBitmap = null;
374 Font ftFolderName, ftDate, ftCnt,ftCntSmall;
376 EnrichedText enTextCount;
377 TextElement textElement;
378 TextElement textElementCount;
380 int allContentCount = pAlbumInfo->GetContentIdCount();
381 strCnt.Format(FORMAT_BUFFER_SIZE, L"%d", allContentCount);
383 String strFolderName = pAlbumInfo->GetAlbumName();
385 Rectangle rectCanvas(ICON_CAP + FOLDER_CAP, Y_POS_CANVAS, CANVAS_WIDTH, CANVAS_HEIGHT);
386 Color bgColor(COLOR_CANVAS_BG);
387 bgColor.SetAlpha(ALPHA_BG);
388 canvas.FillRectangle(bgColor, rectCanvas);
390 if (strFolderName == ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"))
392 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_DOWNLOAD);
394 else if (strFolderName == ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"))
396 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_CAMERA);
400 pBitmap = ResourceManager::GetBitmapN(IDB_ALBUM_ICON_FOLDER);
405 canvas.DrawBitmap(Rectangle(ICON_CAP + FOLDER_CAP, rectCanvas.y + HEIGHT_OFFSET, CANVAS_IMAGE_FOLDER_WIDTH,
406 CANVAS_IMAGE_FOLDER_HEIGHT), *pBitmap);
410 ftFolderName.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_NAME);
411 ftDate.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_DATE);
412 ftCnt.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT);
413 ftCntSmall.Construct(FONT_STYLE_PLAIN, FONT_SIZE_FOLDER_COUNT_SMALL);
415 enText.Construct(Dimension(FOLDER_NAME_WIDTH, FOLDER_NAME_HEIGHT));
416 enText.SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
418 textElement.Construct(strFolderName);
419 textElement.SetFont(ftFolderName);
420 textElement.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
421 enText.SetTextAbbreviationEnabled(true);
422 enText.Add(textElement);
424 enTextCount.Construct(Dimension(IMAGE_COUNT_WIDTH, IMAGE_COUNT_HEIGHT));
425 enTextCount.SetHorizontalAlignment(TEXT_ALIGNMENT_RIGHT);
427 textElementCount.Construct(strCnt);
429 if (strCnt.GetLength() > 3)
431 textElementCount.SetFont(ftCntSmall);
435 textElementCount.SetFont(ftCnt);
437 textElementCount.SetTextColor(Color::GetColor(COLOR_ID_WHITE));
438 enTextCount.SetTextAbbreviationEnabled(true);
439 enTextCount.Add(textElementCount);
441 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP + FOLDER_NAME_WIDTH , rectCanvas.y + HEIGHT_OFFSET);
442 canvas.SetFont(ftCnt);
443 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
444 canvas.DrawText(pointText, enTextCount);
446 pointText = Point(CANVAS_MARGIN_LEFT + CANVAS_IMAGE_FOLDER_WIDTH + GAP , rectCanvas.y + GAP + HEIGHT_OFFSET);
447 canvas.SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
448 canvas.DrawText(pointText, enText);
450 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
454 AlbumListPresentationModel::CreateMergeBitmapN(int index)
456 AppLogDebug("ENTER index(%d)", index);
458 if (__pAlbumInfoList == null)
460 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
465 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
467 Bitmap* pBitmapNew = new (std::nothrow) Bitmap();
468 BufferInfo bufferinfo;
470 Rectangle rectNew(0, 0, FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
471 Dimension size(FOLDER_SIZE_WIDTH, FOLDER_SIZE_HEIGHT);
473 result r = pBitmapNew->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
477 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
482 pBitmapNew->Lock(bufferinfo);
483 r = canvas.Construct(bufferinfo);
487 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
492 DrawPartialImage(canvas, pAlbumInfo, rectNew);
493 DrawFontImage(canvas, pAlbumInfo, index);
495 pBitmapNew->Unlock();
496 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
502 AlbumListPresentationModel::StartAppControl(const String& providerId, const String& operationId,
503 const String* pUriData, const String* pMimeType, const HashMap* pDataList,
504 IAppControlResponseListener* pListener)
506 AppLogDebug("ENTER");
507 AppControl* pAc = AppManager::FindAppControlN(providerId, operationId);
510 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
514 result r = pAc->Start(pUriData, pMimeType, pDataList, pListener);
518 GalleryApp* pGalleryApp = static_cast<GalleryApp*>(GalleryApp::GetInstance());
519 pGalleryApp->SetFrameEnabled(false);
524 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
530 AlbumListPresentationModel::GetDirectoryName(String& directoryPath)
532 AppLogDebug("ENTER");
533 String directoryName;
536 directoryPath.LastIndexOf(DIRECTORY_SEPARATOR, directoryPath.GetLength() - 1, lastIndex);
537 directoryPath.SubString(lastIndex + 1, directoryName);
538 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
540 return directoryName;
544 AlbumListPresentationModel::GetFolderCount(void)
546 AppLogDebug("ENTER");
547 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
549 return __pAlbumInfoList->GetCount();
553 AlbumListPresentationModel::InitializeAlbumInfoList(const ContentType& contentType)
555 AppLogDebug("ENTER");
557 if (__pFolderBackgroundBitmap == null)
559 __pFolderBackgroundBitmap = ResourceManager::GetBitmapN(IDB_MAIN_FOLDER_BACKGROUND);
562 if (__pAlbumInfoList != null)
564 AlbumInfo* info = null;
565 for (int i = 0; i < __pAlbumInfoList->GetCount(); ++i)
567 info = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(i));
568 if (info->GetAlbumName().IsEmpty() == false)
570 AppLog("Print AlbumName(%d)(%ls)", i, info->GetAlbumName().GetPointer());
573 delete __pAlbumInfoList;
575 __pAlbumInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
577 ContentDirectory directory;
579 if (contentType == CONTENT_TYPE_ALL)
581 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
582 TryReturnVoid(pListT != null, "Unable to Create ArrayListT");
583 pListT->Add(CONTENT_TYPE_IMAGE);
584 pListT->Add(CONTENT_TYPE_VIDEO);
586 result r = directory.Construct(*pListT);
591 delete __pAlbumInfoList;
592 __pAlbumInfoList = null;
593 AppLogDebug("EXIT 1(%s)", GetErrorMessage(r));
599 result r = directory.Construct(contentType);
602 delete __pAlbumInfoList;
603 __pAlbumInfoList = null;
604 AppLogDebug("EXIT 2(%s)", GetErrorMessage(r));
609 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
610 String* pDirPath = null;
611 AlbumInfo* pAlbumInfo = null;
613 AlbumInfo* pAllAlbumInfo = new (std::nothrow) AlbumInfo();
614 AlbumInfo* pCameraAlbumInfo = new (std::nothrow) AlbumInfo();
615 AlbumInfo* pDownloadAlbumInfo = new (std::nothrow) AlbumInfo();
616 AlbumInfo* pNoNameAlbumInfo = new (std::nothrow) AlbumInfo();
618 result r = pAllAlbumInfo->Construct();
619 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
620 pAllAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_ALL_ALBUMS"));
622 r = pCameraAlbumInfo->Construct();
623 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
624 pCameraAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_BODY_CAMERA_ROLL_ABB"));
626 r = pDownloadAlbumInfo->Construct();
627 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
628 pDownloadAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_COM_BODY_DOWNLOADS"));
630 r = pNoNameAlbumInfo->Construct();
631 TryCatch(IsFailed(r) == E_SUCCESS,,"new pNoNameAlbumInfo is %s",GetErrorMessage(r));
632 pNoNameAlbumInfo->SetAlbumName(ResourceManager::GetString(L"IDS_MEDIABR_POP_NO_NAME"));
634 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
636 IEnumerator* pEnum = pContentDirectoryPathList->GetEnumeratorN();
637 while (pEnum->MoveNext() == E_SUCCESS)
639 pDirPath = static_cast<String*>(pEnum->GetCurrent());
640 if (pDirPath == null)
645 if ((*pDirPath == RESERVED_CAMERA_PATH) ||(*pDirPath == RESERVED_CAMERA_PATH_EXT))
647 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
649 if (pContentIdList != null)
651 pCameraAlbumInfo->AppendDirectory(*pDirPath);
652 pCameraAlbumInfo->AppendContentIdList(*pContentIdList);
654 pAllAlbumInfo->AppendDirectory(*pDirPath);
655 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
656 delete pContentIdList;
659 else if (*pDirPath == RESERVED_DOWNLOAD_PATH)
661 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
663 if (pContentIdList != null)
665 pDownloadAlbumInfo->AppendDirectory(*pDirPath);
666 pDownloadAlbumInfo->AppendContentIdList(*pContentIdList);
668 pAllAlbumInfo->AppendDirectory(*pDirPath);
669 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
670 delete pContentIdList;
673 else if (*pDirPath == RESERVED_MEDIA_PATH)
675 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
677 if (pContentIdList != null)
679 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
680 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
682 pAllAlbumInfo->AppendDirectory(*pDirPath);
683 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
684 delete pContentIdList;
689 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
691 if (pContentIdList != null)
693 if (pContentIdList->GetCount() > 0)
695 pAlbumInfo = new (std::nothrow) AlbumInfo();
696 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
698 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
700 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
703 pAllAlbumInfo->AppendDirectory(*pDirPath);
704 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
707 delete pContentIdList;
709 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
711 __pAlbumInfoList->Add(pAlbumInfo);
721 if (pAllAlbumInfo->GetContentIdCount() > 0)
723 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
727 delete pAllAlbumInfo;
730 if (pCameraAlbumInfo->GetContentIdCount() > 0)
732 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
736 delete pCameraAlbumInfo;
739 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
741 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
745 delete pDownloadAlbumInfo;
748 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
750 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
754 delete pNoNameAlbumInfo;
761 delete pAllAlbumInfo;
762 delete pCameraAlbumInfo;
763 delete pDownloadAlbumInfo;
764 delete pNoNameAlbumInfo;
767 if (pContentDirectoryPathList != null)
769 delete pContentDirectoryPathList;
771 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
775 if (pContentDirectoryPathList != null)
777 delete pContentDirectoryPathList;
779 if (pAllAlbumInfo != null)
781 delete pAllAlbumInfo;
783 if (pCameraAlbumInfo != null)
785 delete pCameraAlbumInfo;
787 if (pDownloadAlbumInfo != null)
789 delete pDownloadAlbumInfo;
791 if (pNoNameAlbumInfo != null)
793 delete pNoNameAlbumInfo;
798 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
800 AppLogDebug("ENTER");
801 if (fullPath == null)
803 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
807 String delim(DIRECTORY_SEPARATOR);
808 StringTokenizer st(fullPath,delim);
810 while (st.HasMoreTokens())
812 st.GetNextToken(token);
814 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
820 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
822 AppLogDebug("ENTER");
824 if (&directoryPath == null)
826 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
830 ContentDirectory directory;
831 const String contentDirectoryPath = directoryPath;
832 if (contentType == CONTENT_TYPE_ALL)
834 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
835 pListT->Add(CONTENT_TYPE_IMAGE);
836 pListT->Add(CONTENT_TYPE_VIDEO);
837 result r = directory.Construct(*pListT);
841 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
847 result r = directory.Construct(contentType);
850 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
856 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
857 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
858 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
859 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
861 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
863 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
865 while (pEnum->MoveNext() == E_SUCCESS)
867 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
868 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
869 pContentIdList->Add(pItem);
873 delete pContentInfoList;
874 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
876 return pContentIdList;
880 AlbumListPresentationModel::DeleteContentFile(const ContentId& contentId)
882 AppLogDebug("ENTER");
883 result r = E_SUCCESS;
884 ContentManager contentManager;
885 r = contentManager.Construct();
888 r = contentManager.DeleteContent(contentId);
890 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
896 AlbumListPresentationModel::GetAppControlMode(void) const
898 AppLogDebug("Enter");
900 return __appControlMode;
904 AlbumListPresentationModel::GetAppControlMediaType(void) const
906 AppLogDebug("Enter");
908 return __appControlMediaType;
911 AppControlSelectionMode
912 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
914 AppLogDebug("Enter");
916 return __appControlSelectionMode;
920 AlbumListPresentationModel::GetAlbumInfoList(void)
922 AppLogDebug("ENTER");
923 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
925 return __pAlbumInfoList;
928 IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList)
930 AppLogDebug("ENTER");
931 ContentDirectory directory;
932 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
934 IListT< ContentType >* pListT = new (std::nothrow) ArrayListT<ContentType>();
935 TryReturn(pListT != null,null, "Unable to Create ArrayListT");
936 pListT->Add(CONTENT_TYPE_IMAGE);
937 pListT->Add(CONTENT_TYPE_VIDEO);
939 directory.Construct(*pListT);
942 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
943 String* pDirPath = null;
944 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
946 if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
948 int loopCount = pContentDirectoryPathList->GetCount();
949 for (int i = 0; i < loopCount; ++i)
951 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
952 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
955 else //get all files in directories which are checked for deletion
957 int loopCount = indexList.GetCount();
958 for (int i = 0; i < loopCount; ++i)
960 const Integer* pIndex = static_cast<const Integer*>(indexList.GetAt(i));
961 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(pIndex->ToInt() - 1)); //index 0 is all-album which is not counted as a directory. hence delete 1 index
962 if (pDirPath == null)
966 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
970 return pContentIdList;
974 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
976 AppLogDebug("ENTER");
977 if (&eventArg != null)
979 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
980 if (pThumbnailEventArg == null)
982 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
986 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
987 if (pThumbnailInfo == null)
989 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
994 ContentId contentId = pThumbnailInfo->GetContentId();
995 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
997 if (__pAlbumInfoList != null)
999 int outterLoopCount = __pAlbumInfoList->GetCount();
1000 for (int x = 0; x < outterLoopCount; ++x)
1002 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1003 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1004 for (int i = 0; i < innerLoopCount; ++i)
1006 if (i >= FOLDER_BITMAP_MAX)
1011 if (contentId == pAlbumInfo->GetContentId(i))
1013 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1015 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1016 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1023 if (__pPresentationModelListener->GetCount() > 0)
1025 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1026 while (pEnum->MoveNext() == E_SUCCESS)
1028 IAlbumEventListener* pListener = null;
1029 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1031 int loopCount = pUpdateFolderIndex->GetCount();
1032 for (int k = 0; k < loopCount; ++k)
1034 Integer *index = (Integer*)pUpdateFolderIndex->GetAt(k);
1035 int folderIndex = index->ToInt();
1036 pListener->OnThumbnailDecoded(folderIndex);
1042 delete pUpdateFolderIndex;
1044 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1048 AlbumListPresentationModel::OnContentCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1050 AppLogDebug("ENTER");
1051 if (__updateProgressStatus == true)
1053 AppLogDebug("EXIT update in application");
1056 IFormContentUpdateEventListener* pInterface = null;
1057 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1058 while (pEventEnum->MoveNext() == E_SUCCESS)
1060 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1061 if (pInterface != null)
1063 pInterface->OnContentUpdated();
1067 AppLogDebug("EXIT");
1071 AlbumListPresentationModel::OnContentUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1073 AppLogDebug("ENTER");
1074 if (__updateProgressStatus == true)
1076 AppLogDebug("EXIT update in application");
1079 IFormContentUpdateEventListener* pInterface = null;
1080 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1081 while (pEventEnum->MoveNext() == E_SUCCESS)
1083 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1084 pInterface->OnContentUpdated();
1087 AppLogDebug("EXIT");
1091 AlbumListPresentationModel::OnContentDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r)
1093 AppLogDebug("ENTER");
1094 if (__updateProgressStatus == true)
1096 AppLogDebug("EXIT update in application");
1099 IFormContentUpdateEventListener* pInterface = null;
1100 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1101 while (pEventEnum->MoveNext() == E_SUCCESS)
1103 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1104 pInterface->OnContentUpdated();
1107 AppLogDebug("EXIT");
1111 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1113 AppLogDebug("ENTER");
1114 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
1116 IFormContentUpdateEventListener* pInterface = null;
1117 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1118 while (pEventEnum->MoveNext() == E_SUCCESS)
1120 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1121 pInterface->OnContentUpdated();
1125 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1129 AlbumListPresentationModel::SetUpdateProgressStatus(bool status)
1131 AppLogDebug("ENTER status = %d",status);
1132 __updateProgressStatus = status;
1133 AppLogDebug("EXIT");
1137 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, int pathIndex)
1139 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1141 ContentId contentId;
1142 if (__pAlbumInfoList != null)
1144 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1145 contentId = pAlbumInfo->GetContentId(pathIndex);
1148 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1149 AppLogDebug("EXIT");
1153 AlbumListPresentationModel::CancelThumbnailRequest(const int folderIndex)
1155 AppLogDebug("ENTER : folderIndex(%d)", folderIndex);
1156 if (__pAlbumInfoList != null)
1158 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1159 if (pAlbumInfo != null)
1162 for (int i = 0; i < loopCount ; ++i)
1164 contentId = pAlbumInfo->GetContentId(i);
1165 __pThumbnailProvider->CancelThumbnailRequest(contentId, __pThumbnailEvent);
1170 AppLogDebug("EXIT");
1174 AlbumListPresentationModel::ClearThumbnailRequests(bool appTerminating)
1176 AppLogDebug("ENTER");
1177 if (__pThumbnailProvider != null)
1179 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1181 AppLogDebug("EXIT");