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.
18 * @file FCntContentInfo.cpp
19 * @brief This is the implementation file for the %ContentInfo class.
21 * This file contains implementation of the %ContentInfo class.
24 #include <FBaseSysLog.h>
25 #include <FCntContentInfo.h>
26 #include <FCntAudioMetadata.h>
27 #include <FCntContentManagerUtil.h>
29 #include <FGrpBitmap.h>
30 #include <FMediaImage.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::Graphics;
37 using namespace Tizen::Media;
38 using namespace Tizen::App;
41 namespace Tizen { namespace Content
44 static const int THUMBNAIL_IMAGE_WIDTH = 80;
45 static const int THUMBNAIL_IMAGE_HEIGHT = 60;
46 static const int MAX_CUSTOM_FIELD_COMMON = 45;
47 static const int MAX_CUSTOM_FIELD_DESCRIPTION = 140;
48 static const double DEFAULT_COORDINATE = -200.0;
50 ContentInfo::ContentInfo(void)
52 , __pContentData(null)
58 ContentInfo::~ContentInfo(void)
60 if (__pContentData != null)
62 if (__pContentData->pThumbnailPath != null)
64 delete __pContentData->pThumbnailPath;
65 __pContentData->pThumbnailPath = null;
67 if (__pContentData->pAuthor != null)
69 delete __pContentData->pAuthor;
70 __pContentData->pAuthor = null;
72 if (__pContentData->pCategory != null)
74 delete __pContentData->pCategory;
75 __pContentData->pCategory = null;
77 if (__pContentData->pContentName)
79 delete __pContentData->pContentName;
80 __pContentData->pContentName = null;
82 if (__pContentData->pDescription != null)
84 delete __pContentData->pDescription;
85 __pContentData->pDescription = null;
87 if (__pContentData->pKeyword != null)
89 delete __pContentData->pKeyword;
90 __pContentData->pKeyword = null;
92 if (__pContentData->pLocationTag != null)
94 delete __pContentData->pLocationTag;
95 __pContentData->pLocationTag = null;
97 if (__pContentData->pProvider != null)
99 delete __pContentData->pProvider;
100 __pContentData->pProvider = null;
102 if (__pContentData->pRating != null)
104 delete __pContentData->pRating;
105 __pContentData->pRating = null;
108 delete __pContentData;
109 __pContentData = null;
114 ContentInfo::SetContentData(const _ContentData* pContentData)
118 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
120 if (__pContentData == null)
122 __pContentData = new (nothrow) _ContentData();
123 SysTryReturnResult(NID_CNT, __pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
126 __pContentData->contentId = pContentData->contentId;
127 __pContentData->storageType = pContentData->storageType;
128 __pContentData->contentType = pContentData->contentType;
129 __pContentData->contentSize = pContentData->contentSize;
130 __pContentData->contentPath = pContentData->contentPath;
131 __pContentData->dateTime = pContentData->dateTime;
132 __pContentData->latitude = pContentData->latitude;
133 __pContentData->longitude = pContentData->longitude;
134 __pContentData->altitude = pContentData->altitude;
135 __pContentData->isDrm = pContentData->isDrm;
137 if (pContentData->pThumbnailPath != null)
139 __pContentData->pThumbnailPath = new (nothrow) String(*(pContentData->pThumbnailPath));
140 SysTryReturnResult(NID_CNT, __pContentData->pThumbnailPath != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
142 if (pContentData->pAuthor != null)
144 __pContentData->pAuthor = new (nothrow) String(*(pContentData->pAuthor));
145 SysTryReturnResult(NID_CNT, __pContentData->pAuthor != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
147 if (pContentData->pCategory != null)
149 __pContentData->pCategory = new (nothrow) String(*(pContentData->pCategory));
150 SysTryReturnResult(NID_CNT, __pContentData->pCategory != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
152 if (pContentData->pContentName != null)
154 __pContentData->pContentName = new (nothrow) String(*(pContentData->pContentName));
155 SysTryReturnResult(NID_CNT, __pContentData->pContentName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
157 if (pContentData->pDescription != null)
159 __pContentData->pDescription = new (nothrow) String(*(pContentData->pDescription));
160 SysTryReturnResult(NID_CNT, __pContentData->pDescription != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
162 if (pContentData->pKeyword != null)
164 __pContentData->pKeyword = new (nothrow) String(*(pContentData->pKeyword));
165 SysTryReturnResult(NID_CNT, __pContentData->pKeyword != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
167 if (pContentData->pLocationTag != null)
169 __pContentData->pLocationTag = new (nothrow) String(*(pContentData->pLocationTag));
170 SysTryReturnResult(NID_CNT, __pContentData->pLocationTag != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
172 if (pContentData->pProvider != null)
174 __pContentData->pProvider = new (nothrow) String(*(pContentData->pProvider));
175 SysTryReturnResult(NID_CNT, __pContentData->pProvider != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
177 if (pContentData->pRating != null)
179 __pContentData->pRating = new (nothrow) String(*(pContentData->pRating));
180 SysTryReturnResult(NID_CNT, __pContentData->pRating != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
186 ContentInfo::_ContentData*
187 ContentInfo::GetContentData(void)
189 if (__pContentData == null)
191 __pContentData = new (nothrow) ContentInfo::_ContentData;
192 SysTryReturn(NID_CNT, __pContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
194 return __pContentData;
198 ContentInfo::GetContentId(void) const
200 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
202 if (__pContentData->contentId == UuId::GetInvalidUuId())
204 SysLog(NID_CNT, "GetContentId() failed.");
205 return UuId::GetInvalidUuId();
207 return __pContentData->contentId;
211 ContentInfo::GetContentType(void) const
213 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
215 return __pContentData->contentType;
219 ContentInfo::GetDateTime(void) const
221 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
223 return __pContentData->dateTime;
227 ContentInfo::GetMimeType(void) const
229 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
231 return __pContentData->mimeType;
235 ContentInfo::GetContentSize(void) const
237 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
239 return __pContentData->contentSize;
243 ContentInfo::GetContentName(void) const
245 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
247 if (__pContentData->pContentName == null)
249 SysLog(NID_CNT, "GetContentName() failed.");
252 return *(__pContentData->pContentName);
256 ContentInfo::GetContentPath(void) const
258 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
260 return __pContentData->contentPath;
264 ContentInfo::GetCoordinates(void) const
266 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
268 result r = E_SUCCESS;
270 if (Double::Compare(__pContentData->latitude, DEFAULT_COORDINATE) == 0 ||
271 Double::Compare(__pContentData->longitude, DEFAULT_COORDINATE) == 0)
273 SysLog(NID_CNT, "Invalid latitude or longitude");
277 if (Double::Compare(__pContentData->altitude, DEFAULT_COORDINATE) == 0)
279 r = coordinates.SetLatitude(__pContentData->latitude);
282 SysLog(NID_CNT, "GetCoordinates() failed.");
286 r = coordinates.SetLongitude(__pContentData->longitude);
289 SysLog(NID_CNT, "GetCoordinates() failed.");
295 r = coordinates.Set(__pContentData->latitude, __pContentData->longitude, __pContentData->altitude);
298 SysLog(NID_CNT, "GetCoordinates() failed.");
307 ContentInfo::SetCoordinates(const Coordinates& coordinates)
309 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
313 double latitude = coordinates.GetLatitude();
314 double longitude = coordinates.GetLongitude();
315 double altitude = coordinates.GetAltitude();
317 if (!Double::IsNaN(latitude))
319 __pContentData->latitude = latitude;
321 if (!Double::IsNaN(longitude))
323 __pContentData->longitude = longitude;
325 if (!Double::IsNaN(altitude))
327 __pContentData->altitude = altitude;
334 ContentInfo::SetLocationTag(const String& locationTag)
336 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
340 SysTryReturnResult(NID_CNT, locationTag.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
341 "The max input length is 45 characters.");
343 if (__pContentData->pLocationTag != null)
345 // Deletes previous data
346 delete __pContentData->pLocationTag;
347 __pContentData->pLocationTag = null;
350 __pContentData->pLocationTag = new (nothrow) String(locationTag);
351 SysTryReturnResult(NID_CNT, __pContentData->pLocationTag != null, E_OUT_OF_MEMORY,
352 "The memory is insufficient.");
358 ContentInfo::GetLocationTag(void) const
360 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
362 if (__pContentData->pLocationTag == null)
364 SysLog(NID_CNT, "GetLocationTag() failed.");
367 return *(__pContentData->pLocationTag);
371 ContentInfo::SetRating(const String& rating)
373 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
377 SysTryReturnResult(NID_CNT, rating.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
378 "The max input length is 45 characters.");
380 if (__pContentData->pRating != null)
382 // Deletes previous data
383 delete __pContentData->pRating;
384 __pContentData->pRating = null;
387 __pContentData->pRating = new (nothrow) String(rating);
388 SysTryReturnResult(NID_CNT, __pContentData->pRating != null, E_OUT_OF_MEMORY,
389 "The memory is insufficient.");
395 ContentInfo::GetRating(void) const
397 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
399 if (__pContentData->pRating == null)
401 SysLog(NID_CNT, "GetRating() failed.");
404 return *(__pContentData->pRating);
408 ContentInfo::SetCategory(const String& category)
410 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
414 SysTryReturnResult(NID_CNT, category.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
415 "The max input length is 45 characters.");
417 if (__pContentData->pCategory != null)
419 // Deletes previous data
420 delete __pContentData->pCategory;
421 __pContentData->pCategory = null;
424 __pContentData->pCategory = new (nothrow) String(category);
425 SysTryReturnResult(NID_CNT, __pContentData->pCategory != null, E_OUT_OF_MEMORY,
426 "The memory is insufficient.");
432 ContentInfo::GetCategory(void) const
434 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
436 if (__pContentData->pCategory == null)
438 SysLog(NID_CNT, "GetCategory() failed.");
441 return *(__pContentData->pCategory);
445 ContentInfo::SetDescription(const String& description)
447 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
451 SysTryReturnResult(NID_CNT, description.GetLength() <= MAX_CUSTOM_FIELD_DESCRIPTION, E_INVALID_ARG,
452 "The max input length is 140 characters.");
454 if (__pContentData->pDescription != null)
456 // Deletes previous data
457 delete __pContentData->pDescription;
458 __pContentData->pDescription = null;
461 __pContentData->pDescription = new (nothrow) String(description);
462 SysTryReturnResult(NID_CNT, __pContentData->pDescription != null, E_OUT_OF_MEMORY,
463 "The memory is insufficient.");
469 ContentInfo::GetDescription(void) const
471 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
473 if (__pContentData->pDescription == null)
475 SysLog(NID_CNT, "GetDescription() failed.");
478 return *(__pContentData->pDescription);
482 ContentInfo::GetThumbnailN(void) const
484 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
488 result r = E_SUCCESS;
490 Bitmap* pBitmap = null;
492 SysTryReturn(NID_CNT, __pContentData->pThumbnailPath != null, null, E_DATA_NOT_FOUND,
493 "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
495 if (__pContentData->contentType == CONTENT_TYPE_IMAGE || __pContentData->contentType == CONTENT_TYPE_AUDIO
496 || __pContentData->contentType == CONTENT_TYPE_VIDEO)
498 r = image.Construct();
499 SysTryReturn(NID_CNT, !IsFailed(r), null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
501 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
503 pBitmap = image.DecodeN(*(__pContentData->pThumbnailPath), BITMAP_PIXEL_FORMAT_ARGB8888, THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
507 pBitmap = image.DecodeN(*(__pContentData->pThumbnailPath), BITMAP_PIXEL_FORMAT_ARGB8888);
514 if (r == E_OUT_OF_MEMORY)
516 SysLogException(NID_CNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN() failed.");
521 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
528 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
536 ContentInfo::IsDrmProtected(void) const
538 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
540 return __pContentData->isDrm;
544 ContentInfo::GetKeyword(void) const
546 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
548 if (__pContentData->pKeyword == null)
550 SysLog(NID_CNT, "GetKeyword() failed.");
553 return *(__pContentData->pKeyword);
557 ContentInfo::SetContentName(const String& contentName)
559 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
563 SysTryReturnResult(NID_CNT, contentName.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
564 "The max input length is 45 characters.");
566 if (__pContentData->pContentName != null)
568 // Deletes previous data
569 delete __pContentData->pContentName;
570 __pContentData->pContentName = null;
573 __pContentData->pContentName = new (nothrow) String(contentName);
574 SysTryReturnResult(NID_CNT, __pContentData->pContentName != null, E_OUT_OF_MEMORY,
575 "The memory is insufficient.");
581 ContentInfo::SetKeyword(const String& keyword)
583 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
587 SysTryReturnResult(NID_CNT, keyword.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
588 "The max input length is 45 characters.");
590 if (__pContentData->pKeyword != null)
592 // Deletes previous data
593 delete __pContentData->pKeyword;
594 __pContentData->pKeyword = null;
597 __pContentData->pKeyword = new (nothrow) String(keyword);
598 SysTryReturnResult(NID_CNT, __pContentData->pKeyword != null, E_OUT_OF_MEMORY,
599 "SetKeyword() failed.");
605 ContentInfo::SetAuthor(const String& author)
607 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
611 SysTryReturnResult(NID_CNT, author.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
612 "The max input length is 45 characters.");
614 if (__pContentData->pAuthor != null)
616 // Deletes previous data
617 delete __pContentData->pAuthor;
618 __pContentData->pAuthor = null;
621 __pContentData->pAuthor = new (nothrow) String(author);
622 SysTryReturnResult(NID_CNT, __pContentData->pAuthor != null, E_OUT_OF_MEMORY,
623 "SetAuthor() failed.");
629 ContentInfo::GetAuthor(void) const
631 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
633 if (__pContentData->pAuthor == null)
635 SysLog(NID_CNT, "GetAuthor() failed.");
638 return *(__pContentData->pAuthor);
642 ContentInfo::SetProvider(const String& provider)
644 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
648 SysTryReturnResult(NID_CNT, provider.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
649 "The max input length is 45 characters.");
651 if (__pContentData->pProvider != null)
653 // Deletes previous data
654 delete __pContentData->pProvider;
655 __pContentData->pProvider = null;
658 __pContentData->pProvider = new (nothrow) String(provider);
659 SysTryReturnResult(NID_CNT, __pContentData->pProvider != null, E_OUT_OF_MEMORY,
660 "SetProvider() failed.");
666 ContentInfo::GetProvider(void) const
668 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
670 if (__pContentData->pProvider == null)
672 SysLog(NID_CNT, "GetProvider() failed.");
675 return *(__pContentData->pProvider);
679 ContentInfo::GetMediaFormat(void) const
681 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
683 return File::GetFileExtension(__pContentData->contentPath);