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);
677 delete pContentIdList;
680 else if (*pDirPath == mediaPath)
682 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
684 if (pContentIdList != null)
686 pNoNameAlbumInfo->AppendDirectory(*pDirPath);
687 pNoNameAlbumInfo->AppendContentIdList(*pContentIdList);
689 pAllAlbumInfo->AppendDirectory(*pDirPath);
690 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
691 delete pContentIdList;
696 IList* pContentIdList = GetContentIdListInDirectoryN(*pDirPath, contentType);
698 if (pContentIdList != null)
700 if (pContentIdList->GetCount() > 0)
702 pAlbumInfo = new (std::nothrow) AlbumInfo();
703 IList* pSubDirList = new (std::nothrow) ArrayList(SingleObjectDeleter);
705 pSubDirList->Add(new (std::nothrow) String(*pDirPath));
707 pAlbumInfo->Construct(GetDirectoryNameFromFullPath(*pDirPath), contentType, *pSubDirList,
710 pAllAlbumInfo->AppendDirectory(*pDirPath);
711 pAllAlbumInfo->AppendContentIdList(*pContentIdList);
714 delete pContentIdList;
716 if (pAlbumInfo != null && pAlbumInfo->GetContentIdCount() > 0)
718 __pAlbumInfoList->Add(pAlbumInfo);
729 if (pAllAlbumInfo->GetContentIdCount() > 0)
731 __pAlbumInfoList->InsertAt((Object&)*pAllAlbumInfo, insertIndex++);
735 delete pAllAlbumInfo;
738 if (pCameraAlbumInfo->GetContentIdCount() > 0)
740 __pAlbumInfoList->InsertAt((Object&)*pCameraAlbumInfo, insertIndex++);
744 delete pCameraAlbumInfo;
747 if (pDownloadAlbumInfo->GetContentIdCount() > 0)
749 __pAlbumInfoList->InsertAt((Object&)*pDownloadAlbumInfo, insertIndex++);
753 delete pDownloadAlbumInfo;
756 if (pNoNameAlbumInfo->GetContentIdCount() > 0)
758 __pAlbumInfoList->InsertAt((Object&)*pNoNameAlbumInfo, insertIndex++);
762 delete pNoNameAlbumInfo;
769 delete pAllAlbumInfo;
770 delete pCameraAlbumInfo;
771 delete pDownloadAlbumInfo;
772 delete pNoNameAlbumInfo;
775 if (pContentDirectoryPathList != null)
777 delete pContentDirectoryPathList;
779 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
783 if (pContentDirectoryPathList != null)
785 delete pContentDirectoryPathList;
787 if (pAllAlbumInfo != null)
789 delete pAllAlbumInfo;
791 if (pCameraAlbumInfo != null)
793 delete pCameraAlbumInfo;
795 if (pDownloadAlbumInfo != null)
797 delete pDownloadAlbumInfo;
799 if (pNoNameAlbumInfo != null)
801 delete pNoNameAlbumInfo;
806 AlbumListPresentationModel::GetDirectoryNameFromFullPath(const String& fullPath)const
808 AppLogDebug("ENTER");
809 if (fullPath == null)
811 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
815 String delim(DIRECTORY_SEPARATOR);
816 StringTokenizer st(fullPath,delim);
818 while (st.HasMoreTokens())
820 st.GetNextToken(token);
822 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
828 AlbumListPresentationModel::GetContentIdListInDirectoryN(const String& directoryPath, ContentType contentType)const
830 AppLogDebug("ENTER");
832 if (&directoryPath == null)
834 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
838 ContentDirectory directory;
839 const String contentDirectoryPath = directoryPath;
840 if (contentType == CONTENT_TYPE_ALL)
842 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
843 pListT->Add(CONTENT_TYPE_IMAGE);
844 pListT->Add(CONTENT_TYPE_VIDEO);
845 result r = directory.Construct(*pListT);
849 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
855 result r = directory.Construct(contentType);
858 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
864 int countPerPage = directory.GetContentDirectoryItemCount(contentDirectoryPath);
865 IList* pContentInfoList = directory.GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage,
866 CONTENT_INFO_ORDER, SORT_ORDER_ASCENDING);
867 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
869 if ((pContentInfoList != null) && (pContentInfoList->GetCount() > 0))
871 IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
873 while (pEnum->MoveNext() == E_SUCCESS)
875 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pEnum->GetCurrent());
876 pItem = new (std::nothrow) ContentId(pContentInfo->GetContentId());
877 pContentIdList->Add(pItem);
881 delete pContentInfoList;
882 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
884 return pContentIdList;
888 AlbumListPresentationModel::DeleteContentFile(const ContentId& contentId)
890 AppLogDebug("ENTER");
891 result r = E_SUCCESS;
892 ContentManager contentManager;
893 r = contentManager.Construct();
896 r = contentManager.DeleteContent(contentId);
898 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
904 AlbumListPresentationModel::GetAppControlMode(void) const
906 AppLogDebug("Enter");
908 return __appControlMode;
912 AlbumListPresentationModel::GetAppControlMediaType(void) const
914 AppLogDebug("Enter");
916 return __appControlMediaType;
919 AppControlSelectionMode
920 AlbumListPresentationModel::GetAppControlSelectionMode(void) const
922 AppLogDebug("Enter");
924 return __appControlSelectionMode;
928 AlbumListPresentationModel::GetAlbumInfoList(void) const
930 AppLogDebug("ENTER");
931 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
933 return __pAlbumInfoList;
936 IList* AlbumListPresentationModel::GetContentIdListAtIndexN(const IList& indexList) const
938 AppLogDebug("ENTER");
939 ContentDirectory directory;
940 IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
942 IListT<ContentType>* pListT = new (std::nothrow) ArrayListT<ContentType>();
943 TryReturn(pListT != null,null, "Unable to Create ArrayListT");
944 pListT->Add(CONTENT_TYPE_IMAGE);
945 pListT->Add(CONTENT_TYPE_VIDEO);
947 result r = directory.Construct(*pListT);
952 AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
953 delete pContentIdList;
957 if (static_cast<const Integer*>(indexList.GetAt(0))->ToInt() == 0) //if all-album is selected, get all files for delete
959 IList* pContentDirectoryPathList = directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
960 String* pDirPath = null;
961 if ((pContentDirectoryPathList != null) && (pContentDirectoryPathList->GetCount() > 0))
963 int loopCount = pContentDirectoryPathList->GetCount();
964 for (int i = 0; i < loopCount; ++i)
966 pDirPath = static_cast<String*>(pContentDirectoryPathList->GetAt(i));
967 pContentIdList->AddItems(*(GetContentIdListInDirectoryN(*pDirPath, CONTENT_TYPE_ALL)));
973 if(__pAlbumInfoList != null)
975 int loopCount = indexList.GetCount();
976 AlbumInfo* pInfo = null;
977 for (int i = 0; i < loopCount; ++i)
979 int index = static_cast<const Integer*>(indexList.GetAt(i))->ToInt();
980 pInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(index));
984 IList* pList = pInfo->GetContentIdListN();
987 pContentIdList->AddItems(*pList);
993 return pContentIdList;
997 AlbumListPresentationModel::OnThumbnailReceivedN(IEventArg& eventArg)
999 AppLogDebug("ENTER");
1000 if (&eventArg != null)
1002 ThumbnailEventArg* pThumbnailEventArg = static_cast<ThumbnailEventArg*>(&eventArg);
1003 if (pThumbnailEventArg == null)
1005 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1009 ThumbnailInfo* pThumbnailInfo = pThumbnailEventArg->GetThumbnailInfoN();
1010 if (pThumbnailInfo == null)
1012 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1017 ContentId contentId = pThumbnailInfo->GetContentId();
1018 ArrayList* pUpdateFolderIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1020 if (__pAlbumInfoList != null)
1022 int outterLoopCount = __pAlbumInfoList->GetCount();
1023 for (int x = 0; x < outterLoopCount; ++x)
1025 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(x));
1026 int innerLoopCount = pAlbumInfo->GetContentIdCount();
1027 for (int i = 0; i < innerLoopCount; ++i)
1029 if (i >= FOLDER_BITMAP_MAX)
1034 if (contentId == pAlbumInfo->GetContentId(i))
1036 if (pAlbumInfo->GetFolderThumnailBitmap() == null)
1038 pAlbumInfo->SetFolderThumnailBitmap(pThumbnailInfo->GetBitmapN());
1039 pUpdateFolderIndex->Add(new (std::nothrow) Integer(x));
1046 if (__pPresentationModelListener->GetCount() > 0)
1048 IEnumerator* pEnum = __pPresentationModelListener->GetEnumeratorN();
1049 while (pEnum->MoveNext() == E_SUCCESS)
1051 IAlbumEventListener* pListener = null;
1052 pListener = static_cast<IAlbumEventListener*>(pEnum->GetCurrent());
1054 int loopCount = pUpdateFolderIndex->GetCount();
1055 for (int k = 0; k < loopCount; ++k)
1057 Integer *pIndex = (Integer*)pUpdateFolderIndex->GetAt(k);
1058 int folderIndex = pIndex->ToInt();
1059 pListener->OnThumbnailDecoded(folderIndex);
1065 delete pUpdateFolderIndex;
1067 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1071 AlbumListPresentationModel::OnContentCreated(void)
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 if (pInterface != null)
1086 pInterface->OnContentUpdated();
1090 AppLogDebug("EXIT");
1094 AlbumListPresentationModel::OnContentUpdated(void)
1096 AppLogDebug("ENTER");
1097 if (__updateProgressStatus == true)
1099 AppLogDebug("EXIT update in application");
1102 IFormContentUpdateEventListener* pInterface = null;
1103 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1104 while (pEventEnum->MoveNext() == E_SUCCESS)
1106 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1107 pInterface->OnContentUpdated();
1110 AppLogDebug("EXIT");
1114 AlbumListPresentationModel::OnContentDeleted(void)
1116 AppLogDebug("ENTER");
1117 if (__updateProgressStatus == true)
1119 AppLogDebug("EXIT update in application");
1122 IFormContentUpdateEventListener* pInterface = null;
1123 IEnumerator* pEventEnum = __pContentEventListener->GetEnumeratorN();
1124 while (pEventEnum->MoveNext() == E_SUCCESS)
1126 pInterface = static_cast<IFormContentUpdateEventListener*>(pEventEnum->GetCurrent());
1127 pInterface->OnContentUpdated();
1130 AppLogDebug("EXIT");
1134 AlbumListPresentationModel::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
1136 AppLogDebug("ENTER");
1137 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1141 AlbumListPresentationModel::SetUpdateProgressStatus(const bool status)
1143 AppLogDebug("ENTER status = %d",status);
1144 __updateProgressStatus = status;
1145 AppLogDebug("EXIT");
1149 AlbumListPresentationModel::RotateImage(int index, RotateMode rotateMode)
1155 AlbumListPresentationModel::RequestThumbnail(const int folderIndex, const int pathIndex)
1157 AppLogDebug("ENTER : folderIndex(%d), pathIndex(%d)", folderIndex, pathIndex);
1159 ContentId contentId;
1160 if (__pAlbumInfoList != null)
1162 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(__pAlbumInfoList->GetAt(folderIndex));
1163 contentId = pAlbumInfo->GetContentId(pathIndex);
1166 __pThumbnailProvider->RequestThumbnail(contentId, __pThumbnailEvent);
1167 AppLogDebug("EXIT");
1171 AlbumListPresentationModel::ClearThumbnailRequests(const bool appTerminating)
1173 AppLogDebug("ENTER");
1174 if (__pThumbnailProvider != null)
1176 __pThumbnailProvider->ClearThumbnailRequests(appTerminating);
1178 AppLogDebug("EXIT");