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.
17 * @file FCntContentInfo.cpp
18 * @brief This is the implementation file for the %ContentInfo class.
20 * This file contains implementation of the %ContentInfo class.
23 #include <FBaseSysLog.h>
24 #include <FCntContentInfo.h>
25 #include <FCntAudioMetadata.h>
26 #include <FCntContentManagerUtil.h>
28 #include <FGrpBitmap.h>
29 #include <FMediaImage.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::Graphics;
36 using namespace Tizen::Media;
37 using namespace Tizen::App;
40 namespace Tizen { namespace Content
43 static const int THUMBNAIL_IMAGE_WIDTH = 80;
44 static const int THUMBNAIL_IMAGE_HEIGHT = 60;
45 static const int MAX_CUSTOM_FIELD_COMMON = 45;
46 static const int MAX_CUSTOM_FIELD_DESCRIPTION = 140;
47 static const double DEFAULT_COORDINATE = -200.0;
49 ContentInfo::ContentInfo(void)
51 , __pContentData(null)
57 ContentInfo::~ContentInfo(void)
59 if (__pContentData != null)
61 if (__pContentData->pThumbnailPath != null)
63 delete __pContentData->pThumbnailPath;
64 __pContentData->pThumbnailPath = null;
66 if (__pContentData->pAuthor != null)
68 delete __pContentData->pAuthor;
69 __pContentData->pAuthor = null;
71 if (__pContentData->pCategory != null)
73 delete __pContentData->pCategory;
74 __pContentData->pCategory = null;
76 if (__pContentData->pContentName)
78 delete __pContentData->pContentName;
79 __pContentData->pContentName = null;
81 if (__pContentData->pDescription != null)
83 delete __pContentData->pDescription;
84 __pContentData->pDescription = null;
86 if (__pContentData->pKeyword != null)
88 delete __pContentData->pKeyword;
89 __pContentData->pKeyword = null;
91 if (__pContentData->pLocationTag != null)
93 delete __pContentData->pLocationTag;
94 __pContentData->pLocationTag = null;
96 if (__pContentData->pProvider != null)
98 delete __pContentData->pProvider;
99 __pContentData->pProvider = null;
101 if (__pContentData->pRating != null)
103 delete __pContentData->pRating;
104 __pContentData->pRating = null;
107 delete __pContentData;
108 __pContentData = null;
113 ContentInfo::SetContentData(const _ContentData* pContentData)
117 SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
119 if (__pContentData == null)
121 __pContentData = new (nothrow) _ContentData();
122 SysTryReturnResult(NID_CNT, __pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
125 __pContentData->contentId = pContentData->contentId;
126 __pContentData->storageType = pContentData->storageType;
127 __pContentData->contentType = pContentData->contentType;
128 __pContentData->contentSize = pContentData->contentSize;
129 __pContentData->contentPath = pContentData->contentPath;
130 __pContentData->dateTime = pContentData->dateTime;
131 __pContentData->latitude = pContentData->latitude;
132 __pContentData->longitude = pContentData->longitude;
133 __pContentData->altitude = pContentData->altitude;
134 __pContentData->isDrm = pContentData->isDrm;
136 if (pContentData->pThumbnailPath != null)
138 __pContentData->pThumbnailPath = new (nothrow) String(*(pContentData->pThumbnailPath));
139 SysTryReturnResult(NID_CNT, __pContentData->pThumbnailPath != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
141 if (pContentData->pAuthor != null)
143 __pContentData->pAuthor = new (nothrow) String(*(pContentData->pAuthor));
144 SysTryReturnResult(NID_CNT, __pContentData->pAuthor != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
146 if (pContentData->pCategory != null)
148 __pContentData->pCategory = new (nothrow) String(*(pContentData->pCategory));
149 SysTryReturnResult(NID_CNT, __pContentData->pCategory != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
151 if (pContentData->pContentName != null)
153 __pContentData->pContentName = new (nothrow) String(*(pContentData->pContentName));
154 SysTryReturnResult(NID_CNT, __pContentData->pContentName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
156 if (pContentData->pDescription != null)
158 __pContentData->pDescription = new (nothrow) String(*(pContentData->pDescription));
159 SysTryReturnResult(NID_CNT, __pContentData->pDescription != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
161 if (pContentData->pKeyword != null)
163 __pContentData->pKeyword = new (nothrow) String(*(pContentData->pKeyword));
164 SysTryReturnResult(NID_CNT, __pContentData->pKeyword != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
166 if (pContentData->pLocationTag != null)
168 __pContentData->pLocationTag = new (nothrow) String(*(pContentData->pLocationTag));
169 SysTryReturnResult(NID_CNT, __pContentData->pLocationTag != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
171 if (pContentData->pProvider != null)
173 __pContentData->pProvider = new (nothrow) String(*(pContentData->pProvider));
174 SysTryReturnResult(NID_CNT, __pContentData->pProvider != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
176 if (pContentData->pRating != null)
178 __pContentData->pRating = new (nothrow) String(*(pContentData->pRating));
179 SysTryReturnResult(NID_CNT, __pContentData->pRating != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
185 ContentInfo::_ContentData*
186 ContentInfo::GetContentData(void)
188 if (__pContentData == null)
190 __pContentData = new (nothrow) ContentInfo::_ContentData;
191 SysTryReturn(NID_CNT, __pContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
193 return __pContentData;
197 ContentInfo::GetContentId(void) const
199 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
201 if (__pContentData->contentId == UuId::GetInvalidUuId())
203 SysLog(NID_CNT, "GetContentId() failed.");
204 return UuId::GetInvalidUuId();
206 return __pContentData->contentId;
210 ContentInfo::GetContentType(void) const
212 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
214 return __pContentData->contentType;
218 ContentInfo::GetDateTime(void) const
220 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
222 return __pContentData->dateTime;
226 ContentInfo::GetMimeType(void) const
228 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
230 return __pContentData->mimeType;
234 ContentInfo::GetContentSize(void) const
236 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
238 return __pContentData->contentSize;
242 ContentInfo::GetContentName(void) const
244 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
246 if (__pContentData->pContentName == null)
248 SysLog(NID_CNT, "GetContentName() failed.");
251 return *(__pContentData->pContentName);
255 ContentInfo::GetContentPath(void) const
257 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
259 return __pContentData->contentPath;
263 ContentInfo::GetCoordinates(void) const
265 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
267 result r = E_SUCCESS;
269 if (Double::Compare(__pContentData->latitude, DEFAULT_COORDINATE) == 0 ||
270 Double::Compare(__pContentData->longitude, DEFAULT_COORDINATE) == 0)
272 SysLog(NID_CNT, "Invalid latitude or longitude");
276 if (Double::Compare(__pContentData->altitude, DEFAULT_COORDINATE) == 0)
278 r = coordinates.SetLatitude(__pContentData->latitude);
281 SysLog(NID_CNT, "GetCoordinates() failed.");
285 r = coordinates.SetLongitude(__pContentData->longitude);
288 SysLog(NID_CNT, "GetCoordinates() failed.");
294 r = coordinates.Set(__pContentData->latitude, __pContentData->longitude, __pContentData->altitude);
297 SysLog(NID_CNT, "GetCoordinates() failed.");
306 ContentInfo::SetCoordinates(const Coordinates& coordinates)
308 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
312 double latitude = coordinates.GetLatitude();
313 double longitude = coordinates.GetLongitude();
314 double altitude = coordinates.GetAltitude();
316 if (!Double::IsNaN(latitude))
318 __pContentData->latitude = latitude;
320 if (!Double::IsNaN(longitude))
322 __pContentData->longitude = longitude;
324 if (!Double::IsNaN(altitude))
326 __pContentData->altitude = altitude;
333 ContentInfo::SetLocationTag(const String& locationTag)
335 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
339 SysTryReturnResult(NID_CNT, locationTag.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
340 "The max input length is 45 characters.");
342 if (__pContentData->pLocationTag != null)
344 // Deletes previous data
345 delete __pContentData->pLocationTag;
346 __pContentData->pLocationTag = null;
349 __pContentData->pLocationTag = new (nothrow) String(locationTag);
350 SysTryReturnResult(NID_CNT, __pContentData->pLocationTag != null, E_OUT_OF_MEMORY,
351 "The memory is insufficient.");
357 ContentInfo::GetLocationTag(void) const
359 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
361 if (__pContentData->pLocationTag == null)
363 SysLog(NID_CNT, "GetLocationTag() failed.");
366 return *(__pContentData->pLocationTag);
370 ContentInfo::SetRating(const String& rating)
372 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
376 SysTryReturnResult(NID_CNT, rating.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
377 "The max input length is 45 characters.");
379 if (__pContentData->pRating != null)
381 // Deletes previous data
382 delete __pContentData->pRating;
383 __pContentData->pRating = null;
386 __pContentData->pRating = new (nothrow) String(rating);
387 SysTryReturnResult(NID_CNT, __pContentData->pRating != null, E_OUT_OF_MEMORY,
388 "The memory is insufficient.");
394 ContentInfo::GetRating(void) const
396 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
398 if (__pContentData->pRating == null)
400 SysLog(NID_CNT, "GetRating() failed.");
403 return *(__pContentData->pRating);
407 ContentInfo::SetCategory(const String& category)
409 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
413 SysTryReturnResult(NID_CNT, category.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
414 "The max input length is 45 characters.");
416 if (__pContentData->pCategory != null)
418 // Deletes previous data
419 delete __pContentData->pCategory;
420 __pContentData->pCategory = null;
423 __pContentData->pCategory = new (nothrow) String(category);
424 SysTryReturnResult(NID_CNT, __pContentData->pCategory != null, E_OUT_OF_MEMORY,
425 "The memory is insufficient.");
431 ContentInfo::GetCategory(void) const
433 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
435 if (__pContentData->pCategory == null)
437 SysLog(NID_CNT, "GetCategory() failed.");
440 return *(__pContentData->pCategory);
444 ContentInfo::SetDescription(const String& description)
446 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
450 SysTryReturnResult(NID_CNT, description.GetLength() <= MAX_CUSTOM_FIELD_DESCRIPTION, E_INVALID_ARG,
451 "The max input length is 140 characters.");
453 if (__pContentData->pDescription != null)
455 // Deletes previous data
456 delete __pContentData->pDescription;
457 __pContentData->pDescription = null;
460 __pContentData->pDescription = new (nothrow) String(description);
461 SysTryReturnResult(NID_CNT, __pContentData->pDescription != null, E_OUT_OF_MEMORY,
462 "The memory is insufficient.");
468 ContentInfo::GetDescription(void) const
470 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
472 if (__pContentData->pDescription == null)
474 SysLog(NID_CNT, "GetDescription() failed.");
477 return *(__pContentData->pDescription);
481 ContentInfo::GetThumbnailN(void) const
483 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
487 result r = E_SUCCESS;
489 Bitmap* pBitmap = null;
491 SysTryReturn(NID_CNT, __pContentData->pThumbnailPath != null, null, E_DATA_NOT_FOUND,
492 "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
494 if (__pContentData->contentType == CONTENT_TYPE_IMAGE || __pContentData->contentType == CONTENT_TYPE_AUDIO
495 || __pContentData->contentType == CONTENT_TYPE_VIDEO)
497 r = image.Construct();
498 SysTryReturn(NID_CNT, !IsFailed(r), null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
500 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
502 pBitmap = image.DecodeN(*(__pContentData->pThumbnailPath), BITMAP_PIXEL_FORMAT_ARGB8888, THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
506 pBitmap = image.DecodeN(*(__pContentData->pThumbnailPath), BITMAP_PIXEL_FORMAT_ARGB8888);
513 if (r == E_OUT_OF_MEMORY)
515 SysLogException(NID_CNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN() failed.");
520 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
527 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
535 ContentInfo::IsDrmProtected(void) const
537 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
539 return __pContentData->isDrm;
543 ContentInfo::GetKeyword(void) const
545 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
547 if (__pContentData->pKeyword == null)
549 SysLog(NID_CNT, "GetKeyword() failed.");
552 return *(__pContentData->pKeyword);
556 ContentInfo::SetContentName(const String& contentName)
558 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
562 SysTryReturnResult(NID_CNT, contentName.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
563 "The max input length is 45 characters.");
565 if (__pContentData->pContentName != null)
567 // Deletes previous data
568 delete __pContentData->pContentName;
569 __pContentData->pContentName = null;
572 __pContentData->pContentName = new (nothrow) String(contentName);
573 SysTryReturnResult(NID_CNT, __pContentData->pContentName != null, E_OUT_OF_MEMORY,
574 "The memory is insufficient.");
580 ContentInfo::SetKeyword(const String& keyword)
582 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
586 SysTryReturnResult(NID_CNT, keyword.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
587 "The max input length is 45 characters.");
589 if (__pContentData->pKeyword != null)
591 // Deletes previous data
592 delete __pContentData->pKeyword;
593 __pContentData->pKeyword = null;
596 __pContentData->pKeyword = new (nothrow) String(keyword);
597 SysTryReturnResult(NID_CNT, __pContentData->pKeyword != null, E_OUT_OF_MEMORY,
598 "SetKeyword() failed.");
604 ContentInfo::SetAuthor(const String& author)
606 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
610 SysTryReturnResult(NID_CNT, author.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
611 "The max input length is 45 characters.");
613 if (__pContentData->pAuthor != null)
615 // Deletes previous data
616 delete __pContentData->pAuthor;
617 __pContentData->pAuthor = null;
620 __pContentData->pAuthor = new (nothrow) String(author);
621 SysTryReturnResult(NID_CNT, __pContentData->pAuthor != null, E_OUT_OF_MEMORY,
622 "SetAuthor() failed.");
628 ContentInfo::GetAuthor(void) const
630 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
632 if (__pContentData->pAuthor == null)
634 SysLog(NID_CNT, "GetAuthor() failed.");
637 return *(__pContentData->pAuthor);
641 ContentInfo::SetProvider(const String& provider)
643 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
647 SysTryReturnResult(NID_CNT, provider.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
648 "The max input length is 45 characters.");
650 if (__pContentData->pProvider != null)
652 // Deletes previous data
653 delete __pContentData->pProvider;
654 __pContentData->pProvider = null;
657 __pContentData->pProvider = new (nothrow) String(provider);
658 SysTryReturnResult(NID_CNT, __pContentData->pProvider != null, E_OUT_OF_MEMORY,
659 "SetProvider() failed.");
665 ContentInfo::GetProvider(void) const
667 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
669 if (__pContentData->pProvider == null)
671 SysLog(NID_CNT, "GetProvider() failed.");
674 return *(__pContentData->pProvider);
678 ContentInfo::GetMediaFormat(void) const
680 SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
682 return File::GetFileExtension(__pContentData->contentPath);