2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FCntAudioContentInfo.cpp
20 * @brief This is the implementation file for the %AudioContentInfo class.
22 * This file contains implementation of the %AudioContentInfo class.
25 #include <FBaseSysLog.h>
26 #include <FCntAudioContentInfo.h>
28 #include <FIoDirectory.h>
29 #include <FSysEnvironment.h>
30 #include <FIo_FileImpl.h>
31 #include <FApp_AppInfo.h>
33 using namespace Tizen::Base;
34 using namespace Tizen::Io;
35 using namespace Tizen::Locations;
36 using namespace Tizen::App;
37 using namespace Tizen::System;
40 namespace Tizen { namespace Content
43 AudioContentInfo::AudioContentInfo(void)
45 , __pAudioContentData(null)
51 AudioContentInfo::~AudioContentInfo(void)
53 if (__pAudioContentData != null)
55 if (__pAudioContentData->pTitle != null)
57 delete __pAudioContentData->pTitle;
58 __pAudioContentData->pTitle = null;
60 if (__pAudioContentData->pAlbumName != null)
62 delete __pAudioContentData->pAlbumName;
63 __pAudioContentData->pAlbumName = null;
65 if (__pAudioContentData->pArtist != null)
67 delete __pAudioContentData->pArtist;
68 __pAudioContentData->pArtist = null;
70 if (__pAudioContentData->pComposer != null)
72 delete __pAudioContentData->pComposer;
73 __pAudioContentData->pComposer = null;
75 if (__pAudioContentData->pGenre != null)
77 delete __pAudioContentData->pGenre;
78 __pAudioContentData->pGenre = null;
80 if (__pAudioContentData->pCopyright != null)
82 delete __pAudioContentData->pCopyright;
83 __pAudioContentData->pCopyright = null;
85 if (__pAudioContentData->pTrackInfo != null)
87 delete __pAudioContentData->pTrackInfo;
88 __pAudioContentData->pTrackInfo = null;
91 delete __pAudioContentData;
92 __pAudioContentData = null;
104 AudioContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
108 SysAssertf(__pAudioContentData == null,
109 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
111 result r = E_SUCCESS;
112 _ContentData contentData;
113 int contentLength = 0;
114 FileAttributes attribute;
117 contentLength = contentPath.GetLength();
118 SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
119 "The contentPath should start with /Media or /Storagecard/Media.");
120 SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
121 "The file corresponding to contentPath could not be found.");
123 if (!thumbnailPath.IsEmpty())
126 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
131 SysLog(NID_CNT, "The setGps is not supported.");
134 // Sets the content path
135 contentData.contentPath = contentPath;
137 // Sets the content type
138 contentData.contentType = CONTENT_TYPE_AUDIO;
140 // E_INVALID_ARG, E_OUT_OF_MEMORY
141 r = SetContentData(&contentData);
142 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
144 _AudioContentData* pAudioContentData = new (nothrow) _AudioContentData();
145 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
147 __pAudioContentData = pAudioContentData;
161 AudioContentInfo::Construct(const String* pContentPath)
165 SysAssertf(__pAudioContentData == null,
166 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
168 result r = E_SUCCESS;
169 _ContentData contentData;
171 if (pContentPath != null)
173 if (!_AppInfo::IsOspCompat())
175 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
177 SysLogException(NID_CNT, E_INVALID_ARG,
178 "[E_INVALID_ARG] /Media/ and /Storagecard/Media/ are not supported from Tizen 2.0.");
179 return E_INVALID_ARG;
181 if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
182 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
184 SysLogException(NID_CNT, E_INVALID_ARG,
185 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
186 return E_INVALID_ARG;
192 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
194 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
195 // it should be converted in 2.0.
196 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
197 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
199 else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
201 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
202 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
206 SysLogException(NID_CNT, E_INVALID_ARG,
207 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
208 return E_INVALID_ARG;
212 int length = pContentPath->GetLength();
213 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
214 "The length of pContentPath is 0.");
215 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
216 "The file corresponding to pContentPath could not be found.");
218 // Sets the content path
219 contentData.contentPath = *pContentPath;
221 // Sets the content type
222 contentData.contentType = CONTENT_TYPE_AUDIO;
224 r = SetContentData(&contentData);
225 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
229 contentData.contentType = CONTENT_TYPE_AUDIO;
231 r = SetContentData(&contentData);
232 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
235 _AudioContentData* pAudioContentData = new (nothrow) _AudioContentData();
236 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
238 __pAudioContentData = pAudioContentData;
249 AudioContentInfo::SetAudioContentData(const _AudioContentData* pAudioContentData)
253 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_INVALID_ARG, "pAudioContentData is null.");
255 if (__pAudioContentData == null)
257 __pAudioContentData = new (nothrow) _AudioContentData;
258 SysTryReturnResult(NID_CNT, __pAudioContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
261 __pAudioContentData->bitrate = pAudioContentData->bitrate;
262 __pAudioContentData->releaseYear = pAudioContentData->releaseYear;
263 __pAudioContentData->duration = pAudioContentData->duration;
265 if (pAudioContentData->pTitle != null)
267 __pAudioContentData->pTitle = new (nothrow) String(*(pAudioContentData->pTitle));
268 SysTryReturnResult(NID_CNT, __pAudioContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
270 if (pAudioContentData->pAlbumName != null)
272 __pAudioContentData->pAlbumName = new (nothrow) String(*(pAudioContentData->pAlbumName));
273 SysTryReturnResult(NID_CNT, __pAudioContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
275 if (pAudioContentData->pArtist != null)
277 __pAudioContentData->pArtist = new (nothrow) String(*(pAudioContentData->pArtist));
278 SysTryReturnResult(NID_CNT, __pAudioContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
280 if (pAudioContentData->pComposer != null)
282 __pAudioContentData->pComposer = new (nothrow) String(*(pAudioContentData->pComposer));
283 SysTryReturnResult(NID_CNT, __pAudioContentData->pComposer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
285 if (pAudioContentData->pGenre != null)
287 __pAudioContentData->pGenre = new (nothrow) String(*(pAudioContentData->pGenre));
288 SysTryReturnResult(NID_CNT, __pAudioContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
290 if (pAudioContentData->pCopyright != null)
292 __pAudioContentData->pCopyright = new (nothrow) String(*(pAudioContentData->pCopyright));
293 SysTryReturnResult(NID_CNT, __pAudioContentData->pCopyright != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
295 if (pAudioContentData->pTrackInfo != null)
297 __pAudioContentData->pTrackInfo = new (nothrow) String(*(pAudioContentData->pTrackInfo));
298 SysTryReturnResult(NID_CNT, __pAudioContentData->pTrackInfo != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
304 AudioContentInfo::_AudioContentData*
305 AudioContentInfo::GetAudioContentData(void)
307 if (__pAudioContentData == null)
309 __pAudioContentData = new (nothrow) AudioContentInfo::_AudioContentData;
310 SysTryReturn(NID_CNT, __pAudioContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
312 return __pAudioContentData;
316 AudioContentInfo::GetGenre(void) const
318 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
320 if (__pAudioContentData->pGenre == null)
322 SysLog(NID_CNT, "GetGenre() failed.");
323 return String(L"Unknown");
326 return *(__pAudioContentData->pGenre);
330 AudioContentInfo::GetArtist(void) const
332 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
334 if (__pAudioContentData->pArtist == null)
336 SysLog(NID_CNT, "GetArtist() failed.");
337 return String(L"Unknown");
340 return *(__pAudioContentData->pArtist);
344 AudioContentInfo::GetComposer(void) const
346 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
348 if (__pAudioContentData->pComposer == null)
350 SysLog(NID_CNT, "GetComposer() failed.");
351 return String(L"Unknown");
354 return *(__pAudioContentData->pComposer);
358 AudioContentInfo::GetAlbumName(void) const
360 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
362 if (__pAudioContentData->pAlbumName == null)
364 SysLog(NID_CNT, "GetAlbumName() failed.");
365 return String(L"Unknown");
368 return *(__pAudioContentData->pAlbumName);
372 AudioContentInfo::GetReleaseYear(void) const
374 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
376 return __pAudioContentData->releaseYear;
380 AudioContentInfo::GetBitrate(void) const
382 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
384 return __pAudioContentData->bitrate;
388 AudioContentInfo::GetTitle(void) const
390 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
392 if (__pAudioContentData->pTitle == null)
394 SysLog(NID_CNT, "GetTitle() failed.");
395 return String(L"Unknown");
398 return *(__pAudioContentData->pTitle);
402 AudioContentInfo::GetCopyright(void) const
404 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
406 if (__pAudioContentData->pCopyright == null)
408 SysLog(NID_CNT, "GetCopyright() failed.");
409 return String(L"Unknown");
412 return *(__pAudioContentData->pCopyright);
416 AudioContentInfo::GetTrackInfo(void) const
418 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
420 if (__pAudioContentData->pTrackInfo == null)
422 SysLog(NID_CNT, "GetTrackInfo() failed.");
423 return String(L"Unknown");
426 return *(__pAudioContentData->pTrackInfo);
430 AudioContentInfo::GetDuration(void) const
432 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
434 return __pAudioContentData->duration;