2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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 FCntAudioContentInfo.cpp
19 * @brief This is the implementation file for the %AudioContentInfo class.
21 * This file contains implementation of the %AudioContentInfo class.
24 #include <FBaseSysLog.h>
25 #include <FCntAudioContentInfo.h>
27 #include <FIoDirectory.h>
28 #include <FSysEnvironment.h>
29 #include <FIo_FileImpl.h>
30 #include <FApp_AppInfo.h>
32 using namespace Tizen::Base;
33 using namespace Tizen::Io;
34 using namespace Tizen::Locations;
35 using namespace Tizen::App;
36 using namespace Tizen::System;
39 namespace Tizen { namespace Content
42 AudioContentInfo::AudioContentInfo(void)
44 , __pAudioContentData(null)
50 AudioContentInfo::~AudioContentInfo(void)
52 if (__pAudioContentData != null)
54 if (__pAudioContentData->pTitle != null)
56 delete __pAudioContentData->pTitle;
57 __pAudioContentData->pTitle = null;
59 if (__pAudioContentData->pAlbumName != null)
61 delete __pAudioContentData->pAlbumName;
62 __pAudioContentData->pAlbumName = null;
64 if (__pAudioContentData->pArtist != null)
66 delete __pAudioContentData->pArtist;
67 __pAudioContentData->pArtist = null;
69 if (__pAudioContentData->pComposer != null)
71 delete __pAudioContentData->pComposer;
72 __pAudioContentData->pComposer = null;
74 if (__pAudioContentData->pGenre != null)
76 delete __pAudioContentData->pGenre;
77 __pAudioContentData->pGenre = null;
79 if (__pAudioContentData->pCopyright != null)
81 delete __pAudioContentData->pCopyright;
82 __pAudioContentData->pCopyright = null;
84 if (__pAudioContentData->pTrackInfo != null)
86 delete __pAudioContentData->pTrackInfo;
87 __pAudioContentData->pTrackInfo = null;
90 delete __pAudioContentData;
91 __pAudioContentData = null;
103 AudioContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
107 SysAssertf(__pAudioContentData == null,
108 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
110 result r = E_SUCCESS;
111 _ContentData contentData;
112 int contentLength = 0;
113 FileAttributes attribute;
116 contentLength = contentPath.GetLength();
117 SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
118 "The contentPath should start with /Media or /Storagecard/Media.");
119 SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
120 "The file corresponding to contentPath could not be found.");
122 if (!thumbnailPath.IsEmpty())
125 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
130 SysLog(NID_CNT, "The setGps is not supported.");
133 // Sets the content path
134 contentData.contentPath = contentPath;
136 // Sets the content type
137 contentData.contentType = CONTENT_TYPE_AUDIO;
139 // E_INVALID_ARG, E_OUT_OF_MEMORY
140 r = SetContentData(&contentData);
141 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
143 _AudioContentData* pAudioContentData = new (nothrow) _AudioContentData();
144 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
146 __pAudioContentData = pAudioContentData;
160 AudioContentInfo::Construct(const String* pContentPath)
164 SysAssertf(__pAudioContentData == null,
165 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
167 result r = E_SUCCESS;
168 _ContentData contentData;
170 if (pContentPath != null)
172 if (!_AppInfo::IsOspCompat())
174 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
176 SysLogException(NID_CNT, E_INVALID_ARG,
177 "[E_INVALID_ARG] /Media/ and /Storagecard/Media/ are not supported from Tizen 2.0.");
178 return E_INVALID_ARG;
180 if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
181 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
183 SysLogException(NID_CNT, E_INVALID_ARG,
184 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
185 return E_INVALID_ARG;
191 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
193 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
194 // it should be converted in 2.0.
195 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
196 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
198 else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
200 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
201 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
205 SysLogException(NID_CNT, E_INVALID_ARG,
206 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
207 return E_INVALID_ARG;
211 int length = pContentPath->GetLength();
212 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
213 "The length of pContentPath is 0.");
214 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
215 "The file corresponding to pContentPath could not be found.");
217 // Sets the content path
218 contentData.contentPath = *pContentPath;
220 // Sets the content type
221 contentData.contentType = CONTENT_TYPE_AUDIO;
223 r = SetContentData(&contentData);
224 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
228 contentData.contentType = CONTENT_TYPE_AUDIO;
230 r = SetContentData(&contentData);
231 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
234 _AudioContentData* pAudioContentData = new (nothrow) _AudioContentData();
235 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
237 __pAudioContentData = pAudioContentData;
248 AudioContentInfo::SetAudioContentData(const _AudioContentData* pAudioContentData)
252 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_INVALID_ARG, "pAudioContentData is null.");
254 if (__pAudioContentData == null)
256 __pAudioContentData = new (nothrow) _AudioContentData;
257 SysTryReturnResult(NID_CNT, __pAudioContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
260 __pAudioContentData->bitrate = pAudioContentData->bitrate;
261 __pAudioContentData->releaseYear = pAudioContentData->releaseYear;
262 __pAudioContentData->duration = pAudioContentData->duration;
264 if (pAudioContentData->pTitle != null)
266 __pAudioContentData->pTitle = new (nothrow) String(*(pAudioContentData->pTitle));
267 SysTryReturnResult(NID_CNT, __pAudioContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
269 if (pAudioContentData->pAlbumName != null)
271 __pAudioContentData->pAlbumName = new (nothrow) String(*(pAudioContentData->pAlbumName));
272 SysTryReturnResult(NID_CNT, __pAudioContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
274 if (pAudioContentData->pArtist != null)
276 __pAudioContentData->pArtist = new (nothrow) String(*(pAudioContentData->pArtist));
277 SysTryReturnResult(NID_CNT, __pAudioContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
279 if (pAudioContentData->pComposer != null)
281 __pAudioContentData->pComposer = new (nothrow) String(*(pAudioContentData->pComposer));
282 SysTryReturnResult(NID_CNT, __pAudioContentData->pComposer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
284 if (pAudioContentData->pGenre != null)
286 __pAudioContentData->pGenre = new (nothrow) String(*(pAudioContentData->pGenre));
287 SysTryReturnResult(NID_CNT, __pAudioContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
289 if (pAudioContentData->pCopyright != null)
291 __pAudioContentData->pCopyright = new (nothrow) String(*(pAudioContentData->pCopyright));
292 SysTryReturnResult(NID_CNT, __pAudioContentData->pCopyright != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
294 if (pAudioContentData->pTrackInfo != null)
296 __pAudioContentData->pTrackInfo = new (nothrow) String(*(pAudioContentData->pTrackInfo));
297 SysTryReturnResult(NID_CNT, __pAudioContentData->pTrackInfo != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
303 AudioContentInfo::_AudioContentData*
304 AudioContentInfo::GetAudioContentData(void)
306 if (__pAudioContentData == null)
308 __pAudioContentData = new (nothrow) AudioContentInfo::_AudioContentData;
309 SysTryReturn(NID_CNT, __pAudioContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
311 return __pAudioContentData;
315 AudioContentInfo::GetGenre(void) const
317 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
319 if (__pAudioContentData->pGenre == null)
321 SysLog(NID_CNT, "GetGenre() failed.");
322 return String(L"Unknown");
325 return *(__pAudioContentData->pGenre);
329 AudioContentInfo::GetArtist(void) const
331 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
333 if (__pAudioContentData->pArtist == null)
335 SysLog(NID_CNT, "GetArtist() failed.");
336 return String(L"Unknown");
339 return *(__pAudioContentData->pArtist);
343 AudioContentInfo::GetComposer(void) const
345 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
347 if (__pAudioContentData->pComposer == null)
349 SysLog(NID_CNT, "GetComposer() failed.");
350 return String(L"Unknown");
353 return *(__pAudioContentData->pComposer);
357 AudioContentInfo::GetAlbumName(void) const
359 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
361 if (__pAudioContentData->pAlbumName == null)
363 SysLog(NID_CNT, "GetAlbumName() failed.");
364 return String(L"Unknown");
367 return *(__pAudioContentData->pAlbumName);
371 AudioContentInfo::GetReleaseYear(void) const
373 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
375 return __pAudioContentData->releaseYear;
379 AudioContentInfo::GetBitrate(void) const
381 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
383 return __pAudioContentData->bitrate;
387 AudioContentInfo::GetTitle(void) const
389 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
391 if (__pAudioContentData->pTitle == null)
393 SysLog(NID_CNT, "GetTitle() failed.");
394 return String(L"Unknown");
397 return *(__pAudioContentData->pTitle);
401 AudioContentInfo::GetCopyright(void) const
403 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
405 if (__pAudioContentData->pCopyright == null)
407 SysLog(NID_CNT, "GetCopyright() failed.");
408 return String(L"Unknown");
411 return *(__pAudioContentData->pCopyright);
415 AudioContentInfo::GetTrackInfo(void) const
417 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
419 if (__pAudioContentData->pTrackInfo == null)
421 SysLog(NID_CNT, "GetTrackInfo() failed.");
422 return String(L"Unknown");
425 return *(__pAudioContentData->pTrackInfo);
429 AudioContentInfo::GetDuration(void) const
431 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
433 return __pAudioContentData->duration;