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 MpFolderListPresentationModel.cpp
19 * @brief This is the implementation file for FolderListPresentationModel class.
22 #include "MpFolderListPresentationModel.h"
24 using namespace Tizen::Base;
25 using namespace Tizen::Base::Collection;
26 using namespace Tizen::Content;
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Io;
29 using namespace Tizen::Social;
30 using namespace Tizen::Ui::Controls;
32 FolderListPresentationModel* FolderListPresentationModel::pFolderListPresentationModelInstance = null;
34 FolderListPresentationModel::FolderListPresentationModel(void)
35 : __pFolderPathList(null)
36 , __pContentList(null)
37 , __currentFolderIndex(-1)
43 FolderListPresentationModel::~FolderListPresentationModel(void)
49 FolderListPresentationModel*
50 FolderListPresentationModel::GetInstance(void)
53 if (pFolderListPresentationModelInstance == null)
55 pFolderListPresentationModelInstance = new (std::nothrow) FolderListPresentationModel();
56 TryReturn(pFolderListPresentationModelInstance != null, null, "FolderListPresentationModel instance is not created.");
58 result r = pFolderListPresentationModelInstance->Construct();
59 TryCatch(r == E_SUCCESS, , null, "FolderListPresentationModel instance is not constrcuted.");
62 return pFolderListPresentationModelInstance;
65 delete pFolderListPresentationModelInstance;
69 Tizen::Base::Collection::IList*
70 FolderListPresentationModel::ContentDirectoryPathList(void)
73 ContentDirectory directory;
74 result r = directory.Construct(CONTENT_TYPE_AUDIO);
81 return directory.GetContentDirectoryPathListN(SORT_ORDER_ASCENDING);
85 FolderListPresentationModel::Construct(void)
94 FolderListPresentationModel::GetAllFolderCount(void)
97 if (__pFolderPathList == null)
102 return __pFolderPathList->GetCount();
106 FolderListPresentationModel::GetContentCount(int folderIndex)
108 AppLogDebug("ENTER");
109 result r = E_SUCCESS;
110 int totalCount = INIT_VALUE;
112 if ((__pContentList != null) && (__currentFolderIndex == folderIndex))
114 totalCount = __pContentList->GetCount();
118 if (__pFolderPathList == null)
124 String* pStrPath = static_cast<String*>(__pFolderPathList->GetAt(folderIndex));
125 ContentDirectory directory;
126 r = directory.Construct(CONTENT_TYPE_AUDIO);
128 if (IsFailed(r) || pStrPath == null)
134 totalCount = directory.GetContentDirectoryItemCount(*pStrPath);
135 if (IsFailed(GetLastResult()))
146 FolderListPresentationModel::GetFolderInfoN(int folderIndex)
148 AppLogDebug("ENTER");
149 if (__pFolderPathList == null)
154 String* pFolderPath = static_cast<String*>(__pFolderPathList->GetAt(folderIndex));
156 ContentDirectory contentDirectory;
157 result r = contentDirectory.Construct(CONTENT_TYPE_AUDIO);
158 if (IsFailed(r) || pFolderPath == null)
160 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
164 IList* pSearchList = contentDirectory.GetContentDirectoryItemListN(*pFolderPath, SEARCH_PAGE_NO, SEARCH_COUNT_PER_PAGE, STRING_SORT_TITLE, SORT_ORDER_ASCENDING);
165 if (pSearchList == null || IsFailed(GetLastResult()))
167 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
168 if (pSearchList != null)
170 pSearchList->RemoveAll();
176 ContentInformation* pContentInfoStruct = null;
177 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pSearchList->GetAt(INIT_VALUE));
178 AudioContentInfo* pAudioContentInfo = static_cast<AudioContentInfo*>(pContentInfo);
180 if (pAudioContentInfo != null && pAudioContentInfo->GetContentType() == CONTENT_TYPE_AUDIO)
182 pContentInfoStruct = CommonUtil::GetContentInformationN(*pAudioContentInfo);
185 pSearchList->RemoveAll(true);
190 return pContentInfoStruct;
193 Tizen::Base::Collection::ArrayList*
194 FolderListPresentationModel::GetContentPathListN(int folderIndex)
196 AppLogDebug("ENTER");
197 if (__pFolderPathList == null)
203 ContentDirectory contentDirectory;
204 result r = contentDirectory.Construct(CONTENT_TYPE_AUDIO);
207 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
211 IList* pSearchList = null;
212 String* pFolderPath = static_cast<String*>(__pFolderPathList->GetAt(folderIndex));
213 if (pFolderPath != null)
215 pSearchList = contentDirectory.GetContentDirectoryItemListN(*pFolderPath, SEARCH_PAGE_NO, SEARCH_COUNT_PER_PAGE, STRING_SORT_TITLE, SORT_ORDER_ASCENDING);
218 if (pSearchList == null || IsFailed(GetLastResult()))
220 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
221 if (pSearchList != null)
223 pSearchList->RemoveAll();
229 ArrayList* pContentPathList = new (std::nothrow) ArrayList();
230 pContentPathList->Construct();
232 for (int iCount = 0; iCount < pSearchList->GetCount(); iCount++)
234 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pSearchList->GetAt(iCount));
235 if (pContentInfo != null)
237 pContentPathList->Add(*(new (std::nothrow) String(pContentInfo->GetContentPath())));
241 pSearchList->RemoveAll(true);
245 return pContentPathList;
249 FolderListPresentationModel::GetFolderPath(int folderIndex)
251 AppLogDebug("ENTER");
252 if (__pFolderPathList == null)
258 return static_cast<String*>(__pFolderPathList->GetAt(folderIndex));
262 FolderListPresentationModel::InitializeContentList(int folderIndex)
264 AppLogDebug("ENTER");
265 if (__pContentList != null)
267 __pContentList->RemoveAll(true);
268 delete __pContentList;
269 __pContentList = null;
272 ContentDirectory contentDirectory;
273 result r = contentDirectory.Construct(CONTENT_TYPE_AUDIO);
274 if (IsFailed(r) || __pFolderPathList == null)
276 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
280 String* pFolderPath = static_cast<String*>(__pFolderPathList->GetAt(folderIndex));
281 if (pFolderPath != null)
283 __pContentList = contentDirectory.GetContentDirectoryItemListN(*pFolderPath, SEARCH_PAGE_NO, SEARCH_COUNT_PER_PAGE, STRING_SORT_TITLE, SORT_ORDER_ASCENDING);
285 __currentFolderIndex = folderIndex;
290 FolderListPresentationModel::GetContentInfoN(int contentIndex)
292 AppLogDebug("ENTER");
293 if (__pContentList == null || contentIndex < INIT_VALUE)
295 AppLogDebug("EXIT(index(%d) MUST be greater than or equal to 0 OR __pContentList is null)", contentIndex);
299 ContentInformation* pContentInfoStruct = null;
300 ContentInfo* pContentInfo = static_cast<ContentInfo*>(__pContentList->GetAt(contentIndex));
301 if (pContentInfo != null && pContentInfo->GetContentType() == CONTENT_TYPE_AUDIO)
303 AudioContentInfo* pAudioContentInfo = static_cast<AudioContentInfo*>(pContentInfo);
304 if (pAudioContentInfo != null)
306 pContentInfoStruct = CommonUtil::GetContentInformationN(*pAudioContentInfo);
311 return pContentInfoStruct;
315 FolderListPresentationModel::GetFolderName(int folderIndex)
317 AppLogDebug("ENTER");
318 if (__pFolderPathList == null)
324 return static_cast<String*>(__pFolderPathList->GetAt(folderIndex));
328 FolderListPresentationModel::RemoveFolderList(int folderIndex)
330 AppLogDebug("ENTER");
331 IList* pRemoveFolderList = null;
334 ContentManager contentManager;
335 result r = contentManager.Construct();
338 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
342 ContentDirectory contentDirectory;
343 r = contentDirectory.Construct(CONTENT_TYPE_AUDIO);
346 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
350 if (__pFolderPathList != null)
352 String* pFolderPath = static_cast<String*>(__pFolderPathList->GetAt(folderIndex));
353 if (pFolderPath != null)
355 pRemoveFolderList = contentDirectory.GetContentDirectoryItemListN(*pFolderPath, SEARCH_PAGE_NO, SEARCH_COUNT_PER_PAGE, STRING_SORT_TITLE, SORT_ORDER_ASCENDING);
360 AppLogDebug("EXIT(__pFolderPathList is null)");
364 totalCount = pRemoveFolderList->GetCount();
365 for (int iCount = 0; iCount < totalCount; iCount++)
367 ContentInfo* pContentInfo = static_cast<ContentInfo*>(pRemoveFolderList->GetAt(iCount));
368 if (pContentInfo != null && pContentInfo->GetContentType() == CONTENT_TYPE_AUDIO)
370 AudioContentInfo* pAudioContentInfo = static_cast<AudioContentInfo*>(pContentInfo);
371 ContentInformation* pContentInfoStruct = CommonUtil::GetContentInformationN(*pAudioContentInfo);
372 if (pContentInfoStruct != null)
374 contentManager.DeleteContent(pContentInfoStruct->contentId);
375 delete pContentInfoStruct;
380 pRemoveFolderList->RemoveAll(true);
381 delete pRemoveFolderList;
386 FolderListPresentationModel::RefreshContentList(int folderIndex)
388 AppLogDebug("ENTER");
389 ContentDirectory contentDirectory;
390 result r = contentDirectory.Construct(CONTENT_TYPE_AUDIO);
393 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
397 if (__pContentList != null)
399 __pContentList->RemoveAll(true);
400 delete __pContentList;
401 __pContentList = null;
404 String* pFolderPath = static_cast<String*>(__pFolderPathList->GetAt(folderIndex));
405 if (pFolderPath != null)
407 __pContentList = contentDirectory.GetContentDirectoryItemListN(*pFolderPath, SEARCH_PAGE_NO, SEARCH_COUNT_PER_PAGE, STRING_SORT_TITLE, SORT_ORDER_ASCENDING);
410 __currentFolderIndex = folderIndex;
415 FolderListPresentationModel::GetCurrentFolderIndex(void)
417 AppLogDebug("ENTER");
419 return __currentFolderIndex;
423 FolderListPresentationModel::AddContent(String path, int playlistIndex)
425 AppLogDebug("ENTER");
426 ContentInformation* pContentInfoStruct = GetContentInfoN(playlistIndex);
427 PlayList* pPlayList = PlayListManager::GetInstance()->GetPlayListN(path);
428 if (pContentInfoStruct != null)
430 pPlayList->AddItem(pContentInfoStruct->contentId);
431 delete pContentInfoStruct;
439 FolderListPresentationModel::UpdateFolderPathList(void)
441 AppLogDebug("ENTER");
442 if (__pFolderPathList != null)
444 __pFolderPathList->RemoveAll(true);
445 delete __pFolderPathList;
448 __pFolderPathList = ContentDirectoryPathList();
449 result r = GetLastResult();
450 if (__pFolderPathList == null)