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 MpGenreListPresentationModel.cpp
19 * @brief This is the implementation file for GenreListPresentationModel class.
22 #include "MpGenreListPresentationModel.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::Social;
29 using namespace Tizen::Ui::Controls;
31 GenreListPresentationModel* GenreListPresentationModel::pGenreListPresentationModelInstance = null;
33 GenreListPresentationModel*
34 GenreListPresentationModel::GetInstance(void)
37 if (pGenreListPresentationModelInstance == null)
39 pGenreListPresentationModelInstance = new (std::nothrow) GenreListPresentationModel();
40 TryReturn(pGenreListPresentationModelInstance != null, null, "GenreListPresentationModel instance is not created.");
42 result r = pGenreListPresentationModelInstance->Construct();
43 TryCatch(r == E_SUCCESS, , null, "GenreListPresentationModel instance is not constrcuted.");
46 return pGenreListPresentationModelInstance;
49 delete pGenreListPresentationModelInstance;
53 GenreListPresentationModel::GenreListPresentationModel(void)
55 , __pContentList(null)
56 , __currentGenreIndex(-1)
62 GenreListPresentationModel::~GenreListPresentationModel(void)
69 GenreListPresentationModel::Construct(void)
72 if (__pGnereList != null)
74 __pGnereList->RemoveAll(true);
78 __pGnereList = CommonUtil::SearchContentList(STRING_SORT_GENRE);
85 GenreListPresentationModel::GetContentCount(int genreIndex)
88 int totalCount = INIT_VALUE;
89 if (__pGnereList == null)
94 if ((__pContentList != null) && (__currentGenreIndex == genreIndex))
96 totalCount = __pContentList->GetCount();
100 IList* pContentSearchResultList = CommonUtil::ContentSearchResultListN(
101 *(static_cast<String*>(__pGnereList->GetAt(genreIndex))), STRING_SORT_GENRE, STRING_SORT_TITLE);
102 if (pContentSearchResultList == null)
104 AppLogDebug("CommonUtil::ContentSearchResultListN() failed");
108 totalCount = pContentSearchResultList->GetCount();
110 pContentSearchResultList->RemoveAt(true);
111 delete pContentSearchResultList;
118 GenreListPresentationModel::GetAllGenreCount(void)
120 AppLogDebug("ENTER");
121 if (__pGnereList == null)
126 return __pGnereList->GetCount();
130 GenreListPresentationModel::GetGenreInfoN(int genreIndex)
132 AppLogDebug("ENTER");
133 if (__pGnereList == null)
138 IList* pContentSearchResultList = CommonUtil::ContentSearchResultListN(
139 *(static_cast<String*>(__pGnereList->GetAt(genreIndex))), STRING_SORT_GENRE, STRING_SORT_TITLE);
140 if (pContentSearchResultList == null)
142 AppLogDebug("CommonUtil::ContentSearchResultListN() failed");
146 ContentInformation* pContentInformation = null;
147 ContentSearchResult* pResult = static_cast<ContentSearchResult*>(pContentSearchResultList->GetAt(INIT_VALUE));
148 if (pResult != null && pResult->GetContentType() == CONTENT_TYPE_AUDIO)
150 pContentInformation = CommonUtil::GetContentInformationN(*static_cast<AudioContentInfo*>(pResult->GetContentInfo()));
153 pContentSearchResultList->RemoveAll(true);
154 delete pContentSearchResultList;
157 return pContentInformation;
161 GenreListPresentationModel::GetGenreName(int genreIndex)
163 AppLogDebug("ENTER");
164 if (__pGnereList == null)
170 return static_cast<String*>(__pGnereList->GetAt(genreIndex));
174 GenreListPresentationModel::InitializeContentList(int genreIndex)
176 AppLogDebug("ENTER");
177 if (__pContentList != null)
179 __pContentList->RemoveAll(true);
180 delete __pContentList;
183 __currentGenreIndex = genreIndex;
184 __pContentList = CommonUtil::ContentSearchResultListN(
185 *(static_cast<String*>(__pGnereList->GetAt(genreIndex))), STRING_SORT_GENRE, STRING_SORT_TITLE);
190 GenreListPresentationModel::GetContentInfoN(int contentIndex)
192 AppLogDebug("ENTER");
193 ContentInformation* pContentInfoStruct = null;
194 ContentSearchResult* pResult = static_cast<ContentSearchResult*>(__pContentList->GetAt(contentIndex));
195 if (pResult != null && pResult->GetContentType() == CONTENT_TYPE_AUDIO)
197 pContentInfoStruct = CommonUtil::GetContentInformationN(*static_cast<AudioContentInfo*>(pResult->GetContentInfo()));
201 return pContentInfoStruct;
204 Tizen::Base::Collection::ArrayList*
205 GenreListPresentationModel::GetContentPathListN(int genreIndex)
207 AppLogDebug("ENTER");
208 if (__pGnereList == null)
214 IList* pContentSearchResultList = CommonUtil::ContentSearchResultListN(
215 *(static_cast<String*>(__pGnereList->GetAt(genreIndex))), STRING_SORT_GENRE, STRING_SORT_TITLE);
216 if (pContentSearchResultList == null)
218 AppLogDebug("CommonUtil::ContentSearchResultListN() failed");
222 ArrayList* pContentPath = new (std::nothrow) ArrayList();
223 pContentPath->Construct();
225 int totalCount = pContentSearchResultList->GetCount();
226 for (int iCount = 0; iCount < totalCount; iCount++)
228 ContentSearchResult* pResult = static_cast<ContentSearchResult*>(pContentSearchResultList->GetAt(iCount));
229 pContentPath->Add(*(new (std::nothrow) String(pResult->GetContentInfo()->GetContentPath())));
232 pContentSearchResultList->RemoveAt(true);
233 delete pContentSearchResultList;
240 GenreListPresentationModel::RefreshContentList(int genreIndex)
242 AppLogDebug("ENTER");
243 if (__pContentList != null)
245 __pContentList->RemoveAll(true);
246 delete __pContentList;
249 __pContentList = CommonUtil::ContentSearchResultListN(
250 *(static_cast<String*>(__pGnereList->GetAt(genreIndex))), STRING_SORT_GENRE, STRING_SORT_TITLE);
251 if (__pContentList != null && __pContentList->GetCount() == INIT_VALUE)
253 delete __pContentList;
254 __pContentList = null;
256 __currentGenreIndex = genreIndex;
261 GenreListPresentationModel::GetCurrentGenreIndex(void)
263 AppLogDebug("ENTER");
265 return __currentGenreIndex;
269 GenreListPresentationModel::AddContent(Tizen::Base::String path, int playlistIndex)
271 AppLogDebug("ENTER");
272 ContentInformation* pContentInfoStruct = GetContentInfoN(playlistIndex);
273 PlayList* pPlayList = PlayListManager::GetInstance()->GetPlayListN(path);
274 pPlayList->AddItem(pContentInfoStruct->contentId);
276 delete pContentInfoStruct;
277 pContentInfoStruct = null;
285 GenreListPresentationModel::UpdateGnereList(void)
287 AppLogDebug("ENTER");
288 result r = E_SUCCESS;
290 if (__pGnereList != null)
292 __pGnereList->RemoveAll(true);
296 __pGnereList = CommonUtil::SearchContentList(STRING_SORT_GENRE);
297 TryCatch(__pGnereList != null, r = E_FAILURE, "__pGnereList is null");