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 <FLocLocationProvider.h>
31 //#include <FLocQualifiedCoordinates.h>
32 #include <FIo_FileImpl.h>
33 #include <FApp_AppInfo.h>
35 using namespace Tizen::Base;
36 using namespace Tizen::Io;
37 using namespace Tizen::Locations;
38 using namespace Tizen::App;
39 using namespace Tizen::System;
42 namespace Tizen { namespace Content
45 AudioContentInfo::AudioContentInfo(void)
47 , __pAudioContentData(null)
53 AudioContentInfo::~AudioContentInfo(void)
55 if (__pAudioContentData != null)
57 if (__pAudioContentData->pTitle != null)
59 delete __pAudioContentData->pTitle;
60 __pAudioContentData->pTitle = null;
62 if (__pAudioContentData->pAlbumName != null)
64 delete __pAudioContentData->pAlbumName;
65 __pAudioContentData->pAlbumName = null;
67 if (__pAudioContentData->pArtist != null)
69 delete __pAudioContentData->pArtist;
70 __pAudioContentData->pArtist = null;
72 if (__pAudioContentData->pComposer != null)
74 delete __pAudioContentData->pComposer;
75 __pAudioContentData->pComposer = null;
77 if (__pAudioContentData->pGenre != null)
79 delete __pAudioContentData->pGenre;
80 __pAudioContentData->pGenre = null;
82 if (__pAudioContentData->pCopyright != null)
84 delete __pAudioContentData->pCopyright;
85 __pAudioContentData->pCopyright = null;
87 if (__pAudioContentData->pTrackInfo != null)
89 delete __pAudioContentData->pTrackInfo;
90 __pAudioContentData->pTrackInfo = null;
93 delete __pAudioContentData;
94 __pAudioContentData = null;
106 AudioContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
110 SysAssertf(__pAudioContentData == null,
111 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
113 result r = E_SUCCESS;
114 _ContentData contentData;
115 int contentLength = 0;
116 FileAttributes attribute;
119 contentLength = contentPath.GetLength();
120 SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
121 "The contentPath should start with /Media or /Storagecard/Media(%ls).", contentPath.GetPointer());
122 SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
123 "The file corresponding to contentPath could not be found.");
125 if (!thumbnailPath.IsEmpty())
128 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
133 SysLog(NID_CNT, "The setGps is not supported.");
136 // Sets the content path
137 contentData.contentPath = contentPath;
139 // Sets the content type
140 contentData.contentType = CONTENT_TYPE_AUDIO;
142 // E_INVALID_ARG, E_OUT_OF_MEMORY
143 r = SetContentData(&contentData);
144 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
146 _AudioContentData* pAudioContentData = new (nothrow) _AudioContentData();
147 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
149 __pAudioContentData = pAudioContentData;
163 AudioContentInfo::Construct(const String* pContentPath)
167 SysAssertf(__pAudioContentData == null,
168 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
170 result r = E_SUCCESS;
171 _ContentData contentData;
173 if (pContentPath != null)
175 if (!_AppInfo::IsOspCompat())
177 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
179 SysLogException(NID_CNT, E_INVALID_ARG,
180 "[E_INVALID_ARG] /Media/ and /Storagecard/Media/ are not supported from Tizen 2.0.");
181 return E_INVALID_ARG;
183 if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
184 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
186 SysLogException(NID_CNT, E_INVALID_ARG,
187 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
188 return E_INVALID_ARG;
194 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
196 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
197 // it should be converted in 2.0.
198 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
199 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
201 else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
203 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
204 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
208 SysLogException(NID_CNT, E_INVALID_ARG,
209 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
210 return E_INVALID_ARG;
214 int length = pContentPath->GetLength();
215 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
216 "The length of pContentPath is 0.");
217 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
218 "The file corresponding to pContentPath could not be found.");
220 // Sets the content path
221 contentData.contentPath = *pContentPath;
223 // Sets the content type
224 contentData.contentType = CONTENT_TYPE_AUDIO;
226 r = SetContentData(&contentData);
227 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
231 contentData.contentType = CONTENT_TYPE_AUDIO;
233 r = SetContentData(&contentData);
234 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
237 _AudioContentData* pAudioContentData = new (nothrow) _AudioContentData();
238 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
240 __pAudioContentData = pAudioContentData;
251 AudioContentInfo::SetAudioContentData(const _AudioContentData* pAudioContentData)
255 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_INVALID_ARG, "pAudioContentData is null.");
257 if (__pAudioContentData == null)
259 __pAudioContentData = new (nothrow) _AudioContentData;
260 SysTryReturnResult(NID_CNT, __pAudioContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
263 __pAudioContentData->bitrate = pAudioContentData->bitrate;
264 __pAudioContentData->releaseYear = pAudioContentData->releaseYear;
265 __pAudioContentData->duration = pAudioContentData->duration;
267 if (pAudioContentData->pTitle != null)
269 __pAudioContentData->pTitle = new (nothrow) String(*(pAudioContentData->pTitle));
270 SysTryReturnResult(NID_CNT, __pAudioContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
272 if (pAudioContentData->pAlbumName != null)
274 __pAudioContentData->pAlbumName = new (nothrow) String(*(pAudioContentData->pAlbumName));
275 SysTryReturnResult(NID_CNT, __pAudioContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
277 if (pAudioContentData->pArtist != null)
279 __pAudioContentData->pArtist = new (nothrow) String(*(pAudioContentData->pArtist));
280 SysTryReturnResult(NID_CNT, __pAudioContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
282 if (pAudioContentData->pComposer != null)
284 __pAudioContentData->pComposer = new (nothrow) String(*(pAudioContentData->pComposer));
285 SysTryReturnResult(NID_CNT, __pAudioContentData->pComposer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
287 if (pAudioContentData->pGenre != null)
289 __pAudioContentData->pGenre = new (nothrow) String(*(pAudioContentData->pGenre));
290 SysTryReturnResult(NID_CNT, __pAudioContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
292 if (pAudioContentData->pCopyright != null)
294 __pAudioContentData->pCopyright = new (nothrow) String(*(pAudioContentData->pCopyright));
295 SysTryReturnResult(NID_CNT, __pAudioContentData->pCopyright != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
297 if (pAudioContentData->pTrackInfo != null)
299 __pAudioContentData->pTrackInfo = new (nothrow) String(*(pAudioContentData->pTrackInfo));
300 SysTryReturnResult(NID_CNT, __pAudioContentData->pTrackInfo != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
306 AudioContentInfo::_AudioContentData*
307 AudioContentInfo::GetAudioContentData(void)
309 if (__pAudioContentData == null)
311 __pAudioContentData = new (nothrow) AudioContentInfo::_AudioContentData;
312 SysTryReturn(NID_CNT, __pAudioContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
314 return __pAudioContentData;
318 AudioContentInfo::GetGenre(void) const
320 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
322 if (__pAudioContentData->pGenre == null)
324 SysLog(NID_CNT, "GetGenre() failed.");
325 return String(L"Unknown");
328 return *(__pAudioContentData->pGenre);
332 AudioContentInfo::GetArtist(void) const
334 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
336 if (__pAudioContentData->pArtist == null)
338 SysLog(NID_CNT, "GetArtist() failed.");
339 return String(L"Unknown");
342 return *(__pAudioContentData->pArtist);
346 AudioContentInfo::GetComposer(void) const
348 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
350 if (__pAudioContentData->pComposer == null)
352 SysLog(NID_CNT, "GetComposer() failed.");
353 return String(L"Unknown");
356 return *(__pAudioContentData->pComposer);
360 AudioContentInfo::GetAlbumName(void) const
362 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
364 if (__pAudioContentData->pAlbumName == null)
366 SysLog(NID_CNT, "GetAlbumName() failed.");
367 return String(L"Unknown");
370 return *(__pAudioContentData->pAlbumName);
374 AudioContentInfo::GetReleaseYear(void) const
376 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
378 return __pAudioContentData->releaseYear;
382 AudioContentInfo::GetBitrate(void) const
384 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
386 return __pAudioContentData->bitrate;
390 AudioContentInfo::GetTitle(void) const
392 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
394 if (__pAudioContentData->pTitle == null)
396 SysLog(NID_CNT, "GetTitle() failed.");
397 return String(L"Unknown");
400 return *(__pAudioContentData->pTitle);
404 AudioContentInfo::GetCopyright(void) const
406 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
408 if (__pAudioContentData->pCopyright == null)
410 SysLog(NID_CNT, "GetCopyright() failed.");
411 return String(L"Unknown");
414 return *(__pAudioContentData->pCopyright);
418 AudioContentInfo::GetTrackInfo(void) const
420 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
422 if (__pAudioContentData->pTrackInfo == null)
424 SysLog(NID_CNT, "GetTrackInfo() failed.");
425 return String(L"Unknown");
428 return *(__pAudioContentData->pTrackInfo);
432 AudioContentInfo::GetDuration(void) const
434 SysAssertf(__pAudioContentData != null, "Not yet constructed. Construct() should be called before use.");
436 return __pAudioContentData->duration;