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 MpYearListPresentationModel.cpp
19 * @brief This is the implementation file for YearListPresentationModel class.
22 #include "MpYearListPresentationModel.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 YearListPresentationModel* YearListPresentationModel::pYearListPresentationModelInstance = null;
33 YearListPresentationModel*
34 YearListPresentationModel::GetInstance(void)
37 if (pYearListPresentationModelInstance == null)
39 pYearListPresentationModelInstance = new (std::nothrow) YearListPresentationModel();
40 TryReturn(pYearListPresentationModelInstance != null, null, "YearListPresentationModel instance is not created.");
42 result r = pYearListPresentationModelInstance->Construct();
43 TryCatch(r == E_SUCCESS, , null, "YearListPresentationModel instance is not constrcuted.");
46 return pYearListPresentationModelInstance;
49 delete pYearListPresentationModelInstance;
54 YearListPresentationModel::GetContentCount(int yearIndex)
57 int totalCount = INIT_VALUE;
59 if (__pYearList == null)
64 if ((__pContentList != null) && (__currentYearIndex == yearIndex))
66 totalCount = __pContentList->GetCount();
70 IList* pContentSearchResultList = CommonUtil::ContentSearchResultListN(
71 *(static_cast<String*>(__pYearList->GetAt(yearIndex))), STRING_SORT_YEAR, STRING_SORT_YEAR);
72 if (pContentSearchResultList == null)
74 AppLogDebug("CommonUtil::ContentSearchResultListN() failed");
78 totalCount = pContentSearchResultList->GetCount();
80 pContentSearchResultList->RemoveAll(true);
81 delete pContentSearchResultList;
88 YearListPresentationModel::GetAllYearCount(void)
91 if (__pYearList == null)
96 return __pYearList->GetCount();
99 YearListPresentationModel::YearListPresentationModel(void)
101 , __pContentList(null)
102 , __currentYearIndex(-1)
104 AppLogDebug("ENTER");
108 YearListPresentationModel::~YearListPresentationModel(void)
110 AppLogDebug("ENTER");
115 YearListPresentationModel::Construct(void)
117 AppLogDebug("ENTER");
119 if (__pYearList != null)
121 __pYearList->RemoveAll(true);
125 __pYearList = CommonUtil::SearchContentList(STRING_SORT_YEAR);
132 YearListPresentationModel::GetYearInfoN(int yearIndex)
134 AppLogDebug("ENTER");
135 IList* pContentSearchResultList = CommonUtil::ContentSearchResultListN(
136 *(static_cast<String*>(__pYearList->GetAt(yearIndex))), STRING_SORT_YEAR, STRING_SORT_YEAR);
137 if (pContentSearchResultList == null)
139 AppLogDebug("CommonUtil::ContentSearchResultListN() failed");
143 ContentInformation* pContentInformation = null;
144 ContentSearchResult* pResult = static_cast<ContentSearchResult*>(pContentSearchResultList->GetAt(INIT_VALUE));
145 if (pResult!= null && pResult->GetContentType() == CONTENT_TYPE_AUDIO)
147 pContentInformation = CommonUtil::GetContentInformationN(*static_cast<AudioContentInfo*>(pResult->GetContentInfo()));
150 pContentSearchResultList->RemoveAll(true);
151 delete pContentSearchResultList;
154 return pContentInformation;
158 YearListPresentationModel::GetYearName(int yearIndex)
160 AppLogDebug("ENTER");
161 if (__pYearList == null)
166 return static_cast<String*>(__pYearList->GetAt(yearIndex));
170 YearListPresentationModel::InitializeContentList(int yearIndex)
172 AppLogDebug("ENTER");
173 if (__pContentList != null)
175 __pContentList->RemoveAll(true);
176 delete __pContentList;
179 __pContentList = CommonUtil::ContentSearchResultListN(
180 *(static_cast<String*>(__pYearList->GetAt(yearIndex))), STRING_SORT_YEAR, STRING_SORT_TITLE);
181 __currentYearIndex = yearIndex;
186 YearListPresentationModel::GetContentInfoN(int contentIndex)
188 AppLogDebug("ENTER");
189 ContentSearchResult* pResult = static_cast<ContentSearchResult*>(__pContentList->GetAt(contentIndex));
190 ContentInformation* pContentInformation = null;
191 if (pResult != null && pResult->GetContentType() == CONTENT_TYPE_AUDIO)
193 pContentInformation = CommonUtil::GetContentInformationN(*static_cast<AudioContentInfo*>(pResult->GetContentInfo()));
197 return pContentInformation;
200 Tizen::Base::Collection::ArrayList*
201 YearListPresentationModel::GetContentPathListN(int yearIndex)
203 AppLogDebug("ENTER");
204 IList* pContentSearchResultList = CommonUtil::ContentSearchResultListN(
205 *(static_cast<String*>(__pYearList->GetAt(yearIndex))), STRING_SORT_YEAR, STRING_SORT_TITLE);
206 if (pContentSearchResultList == null)
208 AppLogDebug("CommonUtil::ContentSearchResultListN() failed");
212 ArrayList* pContentPath = new (std::nothrow) ArrayList();
213 pContentPath->Construct();
215 int totalCount = pContentSearchResultList->GetCount();
216 for (int iCount = 0; iCount < totalCount; iCount++)
218 ContentSearchResult* pResult = static_cast<ContentSearchResult*>(pContentSearchResultList->GetAt(iCount));
219 pContentPath->Add(*(new (std::nothrow) String(pResult->GetContentInfo()->GetContentPath())));
222 pContentSearchResultList->RemoveAll(true);
223 delete pContentSearchResultList;
230 YearListPresentationModel::RefreshContentList(int yearIndex)
232 AppLogDebug("ENTER");
233 if (__pContentList != null)
235 __pContentList->RemoveAll(true);
236 delete __pContentList;
239 __pContentList = CommonUtil::ContentSearchResultListN(
240 *(static_cast<String*>(__pYearList->GetAt(yearIndex))), STRING_SORT_YEAR, STRING_SORT_TITLE);
241 if (__pContentList != null && __pContentList->GetCount() == INIT_VALUE)
243 __pContentList->RemoveAll(true);
244 delete __pContentList;
245 __pContentList = null;
248 __currentYearIndex = yearIndex;
253 YearListPresentationModel::GetCurrentYearIndex(void)
255 AppLogDebug("ENTER");
257 return __currentYearIndex;
261 YearListPresentationModel::AddContent(Tizen::Base::String path, int playlistIndex)
263 AppLogDebug("ENTER");
264 ContentInformation* pContentInfoStruct = GetContentInfoN(playlistIndex);
265 PlayList* pPlayList = PlayListManager::GetInstance()->GetPlayListN(path);
266 pPlayList->AddItem(pContentInfoStruct->contentId);
268 delete pContentInfoStruct;
269 pContentInfoStruct = null;
277 YearListPresentationModel::UpdateYearList(void)
279 AppLogDebug("ENTER");
280 result r = E_SUCCESS;
282 if (__pYearList != null)
284 __pYearList->RemoveAll(true);
288 __pYearList = CommonUtil::SearchContentList(STRING_SORT_YEAR);
289 TryCatch(__pYearList != null, r = E_FAILURE, "__pYearList is null");