Fix : Search APIs don't return exception despite the content in DB doesn't match...
[platform/framework/native/content.git] / src / FCnt_ContentInfoImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16 /**
17  * @file                FCnt_ContentInfoImpl.cpp
18  * @brief               This is the implementation file for the %_ContentInfoImpl class.
19  *
20  * This file contains implementation of the %_ContentInfoImpl class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FCntContentInfo.h>
25 #include <FCntAudioMetadata.h>
26 #include <FCntContentManagerUtil.h>
27 #include <FIoFile.h>
28 #include <FGrpBitmap.h>
29 #include <FMediaImage.h>
30 #include <FApp_AppInfo.h>
31 #include <FIo_FileImpl.h>
32 #include "FCnt_ContentInfoImpl.h"
33
34 using namespace std;
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Io;
38 using namespace Tizen::Locations;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Media;
41
42 namespace Tizen { namespace Content
43 {
44
45 static const int _THUMBNAIL_IMAGE_WIDTH = 80;
46 static const int _THUMBNAIL_IMAGE_HEIGHT = 60;
47 static const double _DEFAULT_COORDINATE = -200.0;
48
49 _ContentInfoImpl::_ContentInfoImpl(void)
50         : __contentId(Tizen::Base::UuId::GetInvalidUuId())
51         , __storageType(0)
52         , __contentType(CONTENT_TYPE_UNKNOWN)
53         , __contentSize(0)
54         , __latitude(-200.0)
55         , __longitude(-200.0)
56         , __altitude(-200.0)
57         , __isDrm(false)
58         , __contentPath(L"")
59         , __mimeType(L"")
60         , __thumbnailPath(L"")
61         , __author(L"")
62         , __category(L"")
63         , __contentName(L"")
64         , __description(L"")
65         , __keyword(L"")
66         , __locationTag(L"")
67         , __provider(L"")
68         , __rating(L"")
69         , __mediaFormat(L"")
70         , __isConstructed(false)
71 {
72
73 }
74
75 _ContentInfoImpl::~_ContentInfoImpl(void)
76 {
77
78 }
79
80 _ContentInfoImpl*
81 _ContentInfoImpl::GetInstance(ContentInfo& contentInfo)
82 {
83         return contentInfo.__pContentInfoImpl;
84 }
85
86 const _ContentInfoImpl*
87 _ContentInfoImpl::GetInstance(const ContentInfo& contentInfo)
88 {
89         return contentInfo.__pContentInfoImpl;
90 }
91
92 result
93 _ContentInfoImpl::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
94 {
95         return E_SUCCESS;
96 }
97
98 ContentId
99 _ContentInfoImpl::GetContentId(void) const
100 {
101         return __contentId;
102 }
103
104 ContentType
105 _ContentInfoImpl::GetContentType(void) const
106 {
107         return __contentType;
108 }
109
110 DateTime
111 _ContentInfoImpl::GetDateTime(void) const
112 {
113         return __dateTime;
114 }
115
116 String
117 _ContentInfoImpl::GetMimeType(void) const
118 {
119         return __mimeType;
120 }
121
122 unsigned long
123 _ContentInfoImpl::GetContentSize(void) const
124 {
125         return __contentSize;
126 }
127
128 String
129 _ContentInfoImpl::GetContentName(void) const
130 {
131         return __contentName;
132 }
133
134 String
135 _ContentInfoImpl::GetContentPath(void) const
136 {
137         String changedPath(L"");
138         result r = GetCompatContentPath(__contentPath, changedPath);
139         SysTryLogReturn(NID_CNT, !IsFailed(r), L"", "Failed to perform GetCompatContentPath.");
140
141         return changedPath;
142 }
143
144 String
145 _ContentInfoImpl::GetPhysicalContentPath(void) const
146 {
147         return __contentPath;
148 }
149
150 Coordinates
151 _ContentInfoImpl::GetCoordinates(void) const
152 {
153         return __coordinates;
154 }
155
156 void
157 _ContentInfoImpl::SetCoordinates(const Coordinates& coordinates)
158 {
159         double latitude = coordinates.GetLatitude();
160         double longitude = coordinates.GetLongitude();
161         double altitude = coordinates.GetAltitude();
162
163         if (!Double::IsNaN(latitude))
164         {
165                 __latitude = latitude;
166         }
167         if (!Double::IsNaN(longitude))
168         {
169                 __longitude = longitude;
170         }
171         if (!Double::IsNaN(altitude))
172         {
173                 __altitude = altitude;
174         }
175
176         __coordinates = coordinates;
177 }
178
179 void
180 _ContentInfoImpl::SetLocationTag(const String& locationTag)
181 {
182         __locationTag = locationTag;
183 }
184
185 String
186 _ContentInfoImpl::GetLocationTag(void) const
187 {
188         return __locationTag;
189 }
190
191 void
192 _ContentInfoImpl::SetRating(const String& rating)
193 {
194         __rating = rating;
195 }
196
197 String
198 _ContentInfoImpl::GetRating(void) const
199 {
200         return __rating;
201 }
202
203 void
204 _ContentInfoImpl::SetCategory(const String& category)
205 {
206         __category = category;
207 }
208
209 String
210 _ContentInfoImpl::GetCategory(void) const
211 {
212         return __category;
213 }
214
215 void
216 _ContentInfoImpl::SetDescription(const String& description)
217 {
218         __description = description;
219 }
220
221 String
222 _ContentInfoImpl::GetDescription(void) const
223 {
224         return __description;
225 }
226
227 Bitmap*
228 _ContentInfoImpl::GetThumbnailN(void) const
229 {
230         result r = E_SUCCESS;
231         Image image;
232         Bitmap* pBitmap = null;
233
234         SysTryReturn(NID_CNT, !__thumbnailPath.IsEmpty(), null, E_DATA_NOT_FOUND,
235                         "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
236
237         String changedPath(L"");
238         r = GetCompatContentPath(__thumbnailPath, changedPath);
239         SysTryReturn(NID_CNT, !IsFailed(r), null, E_DATA_NOT_FOUND, "[%s] Failed to perform GetCompatContentPath.", GetErrorMessage(E_DATA_NOT_FOUND));
240
241         if (__contentType == CONTENT_TYPE_IMAGE || __contentType == CONTENT_TYPE_AUDIO
242                 || __contentType == CONTENT_TYPE_VIDEO)
243         {
244                 r = image.Construct();
245                 SysTryReturn(NID_CNT, !IsFailed(r), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN() failed.");
246
247                 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
248                 {
249                         pBitmap = image.DecodeN(changedPath, BITMAP_PIXEL_FORMAT_ARGB8888, _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
250                 }
251                 else
252                 {
253                         pBitmap = image.DecodeN(changedPath, BITMAP_PIXEL_FORMAT_ARGB8888);
254                 }
255
256                 if (pBitmap == null)
257                 {
258                         r = GetLastResult();
259
260                         if (r == E_OUT_OF_MEMORY)
261                         {
262                                 SysLogException(NID_CNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN() failed.");
263                                 return null;
264                         }
265                         else
266                         {
267                                 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
268                                 return null;
269                         }
270                 }
271         }
272         else
273         {
274                 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
275                 return null;
276         }
277
278         return pBitmap;
279 }
280
281 bool
282 _ContentInfoImpl::IsDrmProtected(void) const
283 {
284         return __isDrm;
285 }
286
287 String
288 _ContentInfoImpl::GetKeyword(void) const
289 {
290         return __keyword;
291 }
292
293 void
294 _ContentInfoImpl::SetContentName(const String& contentName)
295 {
296         __contentName = contentName;
297 }
298
299 void
300 _ContentInfoImpl::SetKeyword(const String& keyword)
301 {
302         __keyword = keyword;
303 }
304
305 void
306 _ContentInfoImpl::SetAuthor(const String& author)
307 {
308         __author = author;
309 }
310
311 String
312 _ContentInfoImpl::GetAuthor(void) const
313 {
314         return __author;
315 }
316
317 void
318 _ContentInfoImpl::SetProvider(const String& provider)
319 {
320         __provider = provider;
321 }
322
323 String
324 _ContentInfoImpl::GetProvider(void) const
325 {
326         return __provider;
327 }
328
329 String
330 _ContentInfoImpl::GetMediaFormat(void) const
331 {
332         return File::GetFileExtension(__contentPath);
333 }
334
335 void
336 _ContentInfoImpl::SetContentId(const ContentId& contentId)
337 {
338         __contentId = contentId;
339 }
340
341 void
342 _ContentInfoImpl::SetContentType(const ContentType& contentType)
343 {
344         __contentType = contentType;
345 }
346
347 void
348 _ContentInfoImpl::SetContentSize(unsigned long contentSize)
349 {
350         __contentSize = contentSize;
351 }
352
353 void
354 _ContentInfoImpl::SetMimeType(const String& mimeType)
355 {
356         __mimeType = mimeType;
357 }
358
359 void
360 _ContentInfoImpl::SetDateTime(const DateTime& dateTime)
361 {
362         __dateTime = dateTime;
363 }
364
365 void
366 _ContentInfoImpl::SetContentPath(const String& contentPath)
367 {
368         __contentPath = contentPath;
369 }
370
371 void
372 _ContentInfoImpl::SetMediaFormat(const String& mediaFormat)
373 {
374         __mediaFormat = mediaFormat;
375 }
376
377 void
378 _ContentInfoImpl::SetDrmProtected(bool isDrm)
379 {
380         __isDrm = isDrm;
381 }
382
383 double
384 _ContentInfoImpl::GetLatitude(void) const
385 {
386         return __latitude;
387 }
388
389 double
390 _ContentInfoImpl::GetLongitude(void) const
391 {
392         return __longitude;
393 }
394
395 double
396 _ContentInfoImpl::GetAltitude(void) const
397 {
398         return __altitude;
399 }
400
401 void
402 _ContentInfoImpl::SetLatitude(double latitude)
403 {
404         __latitude = latitude;
405 }
406
407 void
408 _ContentInfoImpl::SetLongitude(double longitude)
409 {
410         __longitude = longitude;
411 }
412
413 void
414 _ContentInfoImpl::SetAltitude(double altitude)
415 {
416         __altitude = altitude;
417 }
418
419 String
420 _ContentInfoImpl::GetThumbnailPath(void) const
421 {
422         return __thumbnailPath;
423 }
424
425 void
426 _ContentInfoImpl::SetThumbnailPath(const String& thumbnailPath)
427 {
428         __thumbnailPath = thumbnailPath;
429 }
430
431 void
432 _ContentInfoImpl::SetStorageType(int storageType)
433 {
434         __storageType = storageType;
435 }
436
437 DateTime
438 _ContentInfoImpl::GetModifiedTime(void) const
439 {
440         return __modifiedTime;
441 }
442
443 void
444 _ContentInfoImpl::SetModifiedTime(const DateTime& modifiedTime)
445 {
446         __modifiedTime = modifiedTime;
447 }
448
449 result
450 _ContentInfoImpl::GetCompatContentPath(const String& contentPath, String& changedPath) const
451 {
452         result r = E_SUCCESS;
453         changedPath = contentPath;
454
455         // If the api version is 2.0, the content path has to be changed.
456         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
457         {
458                 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
459                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
460                                 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
461         }
462
463         return r;
464 }
465
466 bool
467 _ContentInfoImpl::IsReconstructable(void) const
468 {
469         return __isConstructed;
470 }
471
472 void
473 _ContentInfoImpl::SetReconstructable(bool isConstructed)
474 {
475         __isConstructed = isConstructed;
476 }
477
478 }}