[content] Change secure log
[platform/framework/native/content.git] / src / FCntContentInfo.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17 /**
18  * @file                FCntContentInfo.cpp
19  * @brief               This is the implementation file for the %ContentInfo class.
20  *
21  * This file contains implementation of the %ContentInfo class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FCntContentInfo.h>
26 #include <FCntAudioMetadata.h>
27 #include <FCntContentManagerUtil.h>
28 #include <FIoFile.h>
29 #include <FGrpBitmap.h>
30 #include <FMediaImage.h>
31 #include <FApp_AppInfo.h>
32
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;
39 using namespace std;
40
41 namespace Tizen { namespace Content
42 {
43
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;
49
50 ContentInfo::ContentInfo(void)
51         : Object()
52         , __pContentData(null)
53         , __pImpl(null)
54 {
55
56 }
57
58 ContentInfo::~ContentInfo(void)
59 {
60         if (__pContentData != null)
61         {
62                 if (__pContentData->pThumbnailPath != null)
63                 {
64                         delete __pContentData->pThumbnailPath;
65                         __pContentData->pThumbnailPath = null;
66                 }
67                 if (__pContentData->pAuthor != null)
68                 {
69                         delete __pContentData->pAuthor;
70                         __pContentData->pAuthor = null;
71                 }
72                 if (__pContentData->pCategory != null)
73                 {
74                         delete __pContentData->pCategory;
75                         __pContentData->pCategory = null;
76                 }
77                 if (__pContentData->pContentName)
78                 {
79                         delete __pContentData->pContentName;
80                         __pContentData->pContentName = null;
81                 }
82                 if (__pContentData->pDescription != null)
83                 {
84                         delete __pContentData->pDescription;
85                         __pContentData->pDescription = null;
86                 }
87                 if (__pContentData->pKeyword != null)
88                 {
89                         delete __pContentData->pKeyword;
90                         __pContentData->pKeyword = null;
91                 }
92                 if (__pContentData->pLocationTag != null)
93                 {
94                         delete __pContentData->pLocationTag;
95                         __pContentData->pLocationTag = null;
96                 }
97                 if (__pContentData->pProvider != null)
98                 {
99                         delete __pContentData->pProvider;
100                         __pContentData->pProvider = null;
101                 }
102                 if (__pContentData->pRating != null)
103                 {
104                         delete __pContentData->pRating;
105                         __pContentData->pRating = null;
106                 }
107
108                 delete __pContentData;
109                 __pContentData = null;
110         }
111 }
112
113 result
114 ContentInfo::SetContentData(const _ContentData* pContentData)
115 {
116         ClearLastResult();
117
118         SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
119
120         if (__pContentData == null)
121         {
122                 __pContentData = new (nothrow) _ContentData();
123                 SysTryReturnResult(NID_CNT, __pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
124         }
125
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;
136
137         if (pContentData->pThumbnailPath != null)
138         {
139                 __pContentData->pThumbnailPath = new (nothrow) String(*(pContentData->pThumbnailPath));
140                 SysTryReturnResult(NID_CNT, __pContentData->pThumbnailPath != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
141         }
142         if (pContentData->pAuthor != null)
143         {
144                 __pContentData->pAuthor = new (nothrow) String(*(pContentData->pAuthor));
145                 SysTryReturnResult(NID_CNT, __pContentData->pAuthor != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
146         }
147         if (pContentData->pCategory != null)
148         {
149                 __pContentData->pCategory = new (nothrow) String(*(pContentData->pCategory));
150                 SysTryReturnResult(NID_CNT, __pContentData->pCategory != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
151         }
152         if (pContentData->pContentName != null)
153         {
154                 __pContentData->pContentName = new (nothrow) String(*(pContentData->pContentName));
155                 SysTryReturnResult(NID_CNT, __pContentData->pContentName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
156         }
157         if (pContentData->pDescription != null)
158         {
159                 __pContentData->pDescription = new (nothrow) String(*(pContentData->pDescription));
160                 SysTryReturnResult(NID_CNT, __pContentData->pDescription != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
161         }
162         if (pContentData->pKeyword != null)
163         {
164                 __pContentData->pKeyword = new (nothrow) String(*(pContentData->pKeyword));
165                 SysTryReturnResult(NID_CNT, __pContentData->pKeyword != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
166         }
167         if (pContentData->pLocationTag != null)
168         {
169                 __pContentData->pLocationTag = new (nothrow) String(*(pContentData->pLocationTag));
170                 SysTryReturnResult(NID_CNT, __pContentData->pLocationTag != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
171         }
172         if (pContentData->pProvider != null)
173         {
174                 __pContentData->pProvider = new (nothrow) String(*(pContentData->pProvider));
175                 SysTryReturnResult(NID_CNT, __pContentData->pProvider != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
176         }
177         if (pContentData->pRating != null)
178         {
179                 __pContentData->pRating = new (nothrow) String(*(pContentData->pRating));
180                 SysTryReturnResult(NID_CNT, __pContentData->pRating != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
181         }
182
183         return E_SUCCESS;
184 }
185
186 ContentInfo::_ContentData*
187 ContentInfo::GetContentData(void)
188 {
189         if (__pContentData == null)
190         {
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.");
193         }
194         return __pContentData;
195 }
196
197 ContentId
198 ContentInfo::GetContentId(void) const
199 {
200         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
201
202         if (__pContentData->contentId == UuId::GetInvalidUuId())
203         {
204                 SysLog(NID_CNT, "GetContentId() failed.");
205                 return UuId::GetInvalidUuId();
206         }
207         return __pContentData->contentId;
208 }
209
210 ContentType
211 ContentInfo::GetContentType(void) const
212 {
213         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
214
215         return __pContentData->contentType;
216 }
217
218 DateTime
219 ContentInfo::GetDateTime(void) const
220 {
221         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
222
223         return __pContentData->dateTime;
224 }
225
226 String
227 ContentInfo::GetMimeType(void) const
228 {
229         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
230
231         return __pContentData->mimeType;
232 }
233
234 unsigned long
235 ContentInfo::GetContentSize(void) const
236 {
237         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
238
239         return __pContentData->contentSize;
240 }
241
242 String
243 ContentInfo::GetContentName(void) const
244 {
245         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
246
247         if (__pContentData->pContentName == null)
248         {
249                 SysLog(NID_CNT, "GetContentName() failed.");
250                 return String();
251         }
252         return *(__pContentData->pContentName);
253 }
254
255 String
256 ContentInfo::GetContentPath(void) const
257 {
258         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
259
260         return __pContentData->contentPath;
261 }
262
263 const Coordinates&
264 ContentInfo::GetCoordinates(void) const
265 {
266         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
267
268         result r = E_SUCCESS;
269
270         if (Double::Compare(__pContentData->latitude, DEFAULT_COORDINATE) == 0 ||
271                 Double::Compare(__pContentData->longitude, DEFAULT_COORDINATE) == 0)
272         {
273                 SysLog(NID_CNT, "Invalid latitude or longitude");
274                 return coordinates;
275         }
276
277         if (Double::Compare(__pContentData->altitude, DEFAULT_COORDINATE) == 0)
278         {
279                 r = coordinates.SetLatitude(__pContentData->latitude);
280                 if (IsFailed(r))
281                 {
282                         SysLog(NID_CNT, "GetCoordinates() failed.");
283                         return coordinates;
284                 }
285
286                 r = coordinates.SetLongitude(__pContentData->longitude);
287                 if (IsFailed(r))
288                 {
289                         SysLog(NID_CNT, "GetCoordinates() failed.");
290                         return coordinates;
291                 }
292         }
293         else
294         {
295                 r = coordinates.Set(__pContentData->latitude, __pContentData->longitude, __pContentData->altitude);
296                 if (IsFailed(r))
297                 {
298                         SysLog(NID_CNT, "GetCoordinates() failed.");
299                         return coordinates;
300                 }
301         }
302
303         return coordinates;
304 }
305
306 result
307 ContentInfo::SetCoordinates(const Coordinates& coordinates)
308 {
309         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
310
311         ClearLastResult();
312
313         double latitude = coordinates.GetLatitude();
314         double longitude = coordinates.GetLongitude();
315         double altitude = coordinates.GetAltitude();
316
317         if (!Double::IsNaN(latitude))
318         {
319                 __pContentData->latitude = latitude;
320         }
321         if (!Double::IsNaN(longitude))
322         {
323                 __pContentData->longitude = longitude;
324         }
325         if (!Double::IsNaN(altitude))
326         {
327                 __pContentData->altitude = altitude;
328         }
329
330         return E_SUCCESS;
331 }
332
333 result
334 ContentInfo::SetLocationTag(const String& locationTag)
335 {
336         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
337
338         ClearLastResult();
339
340         SysTryReturnResult(NID_CNT, locationTag.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
341                         "The max input length is 45 characters.");
342
343         if (__pContentData->pLocationTag != null)
344         {
345                 // Deletes previous data
346                 delete __pContentData->pLocationTag;
347                 __pContentData->pLocationTag = null;
348         }
349
350         __pContentData->pLocationTag = new (nothrow) String(locationTag);
351         SysTryReturnResult(NID_CNT, __pContentData->pLocationTag != null, E_OUT_OF_MEMORY,
352                         "The memory is insufficient.");
353
354         return E_SUCCESS;
355 }
356
357 String
358 ContentInfo::GetLocationTag(void) const
359 {
360         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
361
362         if (__pContentData->pLocationTag == null)
363         {
364                 SysLog(NID_CNT, "GetLocationTag() failed.");
365                 return String();
366         }
367         return *(__pContentData->pLocationTag);
368 }
369
370 result
371 ContentInfo::SetRating(const String& rating)
372 {
373         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
374
375         ClearLastResult();
376
377         SysTryReturnResult(NID_CNT, rating.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
378                         "The max input length is 45 characters.");
379
380         if (__pContentData->pRating != null)
381         {
382                 // Deletes previous data
383                 delete __pContentData->pRating;
384                 __pContentData->pRating = null;
385         }
386
387         __pContentData->pRating = new (nothrow) String(rating);
388         SysTryReturnResult(NID_CNT, __pContentData->pRating != null, E_OUT_OF_MEMORY,
389                         "The memory is insufficient.");
390
391         return E_SUCCESS;
392 }
393
394 String
395 ContentInfo::GetRating(void) const
396 {
397         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
398
399         if (__pContentData->pRating == null)
400         {
401                 SysLog(NID_CNT, "GetRating() failed.");
402                 return String();
403         }
404         return *(__pContentData->pRating);
405 }
406
407 result
408 ContentInfo::SetCategory(const String& category)
409 {
410         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
411
412         ClearLastResult();
413
414         SysTryReturnResult(NID_CNT, category.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
415                         "The max input length is 45 characters.");
416
417         if (__pContentData->pCategory != null)
418         {
419                 // Deletes previous data
420                 delete __pContentData->pCategory;
421                 __pContentData->pCategory = null;
422         }
423
424         __pContentData->pCategory = new (nothrow) String(category);
425         SysTryReturnResult(NID_CNT, __pContentData->pCategory != null, E_OUT_OF_MEMORY,
426                         "The memory is insufficient.");
427
428         return E_SUCCESS;
429 }
430
431 String
432 ContentInfo::GetCategory(void) const
433 {
434         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
435
436         if (__pContentData->pCategory == null)
437         {
438                 SysLog(NID_CNT, "GetCategory() failed.");
439                 return String();
440         }
441         return *(__pContentData->pCategory);
442 }
443
444 result
445 ContentInfo::SetDescription(const String& description)
446 {
447         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
448
449         ClearLastResult();
450
451         SysTryReturnResult(NID_CNT, description.GetLength() <= MAX_CUSTOM_FIELD_DESCRIPTION, E_INVALID_ARG,
452                         "The max input length is 140 characters.");
453
454         if (__pContentData->pDescription != null)
455         {
456                 // Deletes previous data
457                 delete __pContentData->pDescription;
458                 __pContentData->pDescription = null;
459         }
460
461         __pContentData->pDescription = new (nothrow) String(description);
462         SysTryReturnResult(NID_CNT, __pContentData->pDescription != null, E_OUT_OF_MEMORY,
463                         "The memory is insufficient.");
464
465         return E_SUCCESS;
466 }
467
468 String
469 ContentInfo::GetDescription(void) const
470 {
471         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
472
473         if (__pContentData->pDescription == null)
474         {
475                 SysLog(NID_CNT, "GetDescription() failed.");
476                 return String();
477         }
478         return *(__pContentData->pDescription);
479 }
480
481 Bitmap*
482 ContentInfo::GetThumbnailN(void) const
483 {
484         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
485
486         ClearLastResult();
487
488         result r = E_SUCCESS;
489         Image image;
490         Bitmap* pBitmap = null;
491
492         SysTryReturn(NID_CNT, __pContentData->pThumbnailPath != null, null, E_DATA_NOT_FOUND,
493                         "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
494
495         if (__pContentData->contentType == CONTENT_TYPE_IMAGE || __pContentData->contentType == CONTENT_TYPE_AUDIO
496                 || __pContentData->contentType == CONTENT_TYPE_VIDEO)
497         {
498                 r = image.Construct();
499                 SysTryReturn(NID_CNT, !IsFailed(r), null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
500
501                 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
502                 {
503                         pBitmap = image.DecodeN(*(__pContentData->pThumbnailPath), BITMAP_PIXEL_FORMAT_ARGB8888, THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
504                 }
505                 else
506                 {
507                         pBitmap = image.DecodeN(*(__pContentData->pThumbnailPath), BITMAP_PIXEL_FORMAT_ARGB8888);
508                 }
509
510                 if (pBitmap == null)
511                 {
512                         r = GetLastResult();
513
514                         if (r == E_OUT_OF_MEMORY)
515                         {
516                                 SysLogException(NID_CNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN() failed.");
517                                 return null;
518                         }
519                         else
520                         {
521                                 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
522                                 return null;
523                         }
524                 }
525         }
526         else
527         {
528                 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
529                 return null;
530         }
531
532         return pBitmap;
533 }
534
535 bool
536 ContentInfo::IsDrmProtected(void) const
537 {
538         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
539
540         return __pContentData->isDrm;
541 }
542
543 String
544 ContentInfo::GetKeyword(void) const
545 {
546         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
547
548         if (__pContentData->pKeyword == null)
549         {
550                 SysLog(NID_CNT, "GetKeyword() failed.");
551                 return String();
552         }
553         return *(__pContentData->pKeyword);
554 }
555
556 result
557 ContentInfo::SetContentName(const String& contentName)
558 {
559         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
560
561         ClearLastResult();
562
563         SysTryReturnResult(NID_CNT, contentName.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
564                         "The max input length is 45 characters.");
565
566         if (__pContentData->pContentName != null)
567         {
568                 // Deletes previous data
569                 delete __pContentData->pContentName;
570                 __pContentData->pContentName = null;
571         }
572
573         __pContentData->pContentName = new (nothrow) String(contentName);
574         SysTryReturnResult(NID_CNT, __pContentData->pContentName != null, E_OUT_OF_MEMORY,
575                         "The memory is insufficient.");
576
577         return E_SUCCESS;
578 }
579
580 result
581 ContentInfo::SetKeyword(const String& keyword)
582 {
583         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
584
585         ClearLastResult();
586
587         SysTryReturnResult(NID_CNT, keyword.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
588                         "The max input length is 45 characters.");
589
590         if (__pContentData->pKeyword != null)
591         {
592                 // Deletes previous data
593                 delete __pContentData->pKeyword;
594                 __pContentData->pKeyword = null;
595         }
596
597         __pContentData->pKeyword = new (nothrow) String(keyword);
598         SysTryReturnResult(NID_CNT, __pContentData->pKeyword != null, E_OUT_OF_MEMORY,
599                         "SetKeyword() failed.");
600
601         return E_SUCCESS;
602 }
603
604 result
605 ContentInfo::SetAuthor(const String& author)
606 {
607         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
608
609         ClearLastResult();
610
611         SysTryReturnResult(NID_CNT, author.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
612                         "The max input length is 45 characters.");
613
614         if (__pContentData->pAuthor != null)
615         {
616                 // Deletes previous data
617                 delete __pContentData->pAuthor;
618                 __pContentData->pAuthor = null;
619         }
620
621         __pContentData->pAuthor = new (nothrow) String(author);
622         SysTryReturnResult(NID_CNT, __pContentData->pAuthor != null, E_OUT_OF_MEMORY,
623                         "SetAuthor() failed.");
624
625         return E_SUCCESS;
626 }
627
628 String
629 ContentInfo::GetAuthor(void) const
630 {
631         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
632
633         if (__pContentData->pAuthor == null)
634         {
635                 SysLog(NID_CNT, "GetAuthor() failed.");
636                 return String();
637         }
638         return *(__pContentData->pAuthor);
639 }
640
641 result
642 ContentInfo::SetProvider(const String& provider)
643 {
644         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
645
646         ClearLastResult();
647
648         SysTryReturnResult(NID_CNT, provider.GetLength() <= MAX_CUSTOM_FIELD_COMMON, E_INVALID_ARG,
649                         "The max input length is 45 characters.");
650
651         if (__pContentData->pProvider != null)
652         {
653                 // Deletes previous data
654                 delete __pContentData->pProvider;
655                 __pContentData->pProvider = null;
656         }
657
658         __pContentData->pProvider = new (nothrow) String(provider);
659         SysTryReturnResult(NID_CNT, __pContentData->pProvider != null, E_OUT_OF_MEMORY,
660                         "SetProvider() failed.");
661
662         return E_SUCCESS;
663 }
664
665 String
666 ContentInfo::GetProvider(void) const
667 {
668         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
669
670         if (__pContentData->pProvider == null)
671         {
672                 SysLog(NID_CNT, "GetProvider() failed.");
673                 return String();
674         }
675         return *(__pContentData->pProvider);
676 }
677
678 String
679 ContentInfo::GetMediaFormat(void) const
680 {
681         SysAssertf(__pContentData != null, "Not yet constructed. Construct() should be called before use.");
682
683         return File::GetFileExtension(__pContentData->contentPath);
684 }
685
686 }}