Merge branch 'tizen_2.2' into devel_3.0_main
[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 "FCnt_ContentInfoImpl.h"
32
33 using namespace std;
34 using namespace Tizen::Base;
35 using namespace Tizen::Io;
36 using namespace Tizen::Locations;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Media;
39 using namespace Tizen::App;
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 double _DEFAULT_COORDINATE = -200.0;
47
48 _ContentInfoImpl::_ContentInfoImpl(void)
49         : __contentId(Tizen::Base::UuId::GetInvalidUuId())
50         , __storageType(0)
51         , __contentType(CONTENT_TYPE_UNKNOWN)
52         , __contentSize(0)
53         , __latitude(-200.0)
54         , __longitude(-200.0)
55         , __altitude(-200.0)
56         , __isDrm(false)
57         , __contentPath(L"")
58         , __mimeType(L"")
59         , __thumbnailPath(L"")
60         , __author(L"")
61         , __category(L"")
62         , __contentName(L"")
63         , __description(L"")
64         , __keyword(L"")
65         , __locationTag(L"")
66         , __provider(L"")
67         , __rating(L"")
68         , __mediaFormat(L"")
69 {
70
71 }
72
73 _ContentInfoImpl::~_ContentInfoImpl(void)
74 {
75
76 }
77
78 _ContentInfoImpl*
79 _ContentInfoImpl::GetInstance(ContentInfo& contentInfo)
80 {
81         return contentInfo.__pContentInfoImpl;
82 }
83
84 const _ContentInfoImpl*
85 _ContentInfoImpl::GetInstance(const ContentInfo& contentInfo)
86 {
87         return contentInfo.__pContentInfoImpl;
88 }
89
90 result
91 _ContentInfoImpl::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
92 {
93         return E_SUCCESS;
94 }
95
96 ContentId
97 _ContentInfoImpl::GetContentId(void) const
98 {
99         return __contentId;
100 }
101
102 ContentType
103 _ContentInfoImpl::GetContentType(void) const
104 {
105         return __contentType;
106 }
107
108 DateTime
109 _ContentInfoImpl::GetDateTime(void) const
110 {
111         return __dateTime;
112 }
113
114 String
115 _ContentInfoImpl::GetMimeType(void) const
116 {
117         return __mimeType;
118 }
119
120 unsigned long
121 _ContentInfoImpl::GetContentSize(void) const
122 {
123         return __contentSize;
124 }
125
126 String
127 _ContentInfoImpl::GetContentName(void) const
128 {
129         return __contentName;
130 }
131
132 String
133 _ContentInfoImpl::GetContentPath(void) const
134 {
135         return __contentPath;
136 }
137
138 Coordinates
139 _ContentInfoImpl::GetCoordinates(void) const
140 {
141         return __coordinates;
142 }
143
144 void
145 _ContentInfoImpl::SetCoordinates(const Coordinates& coordinates)
146 {
147         double latitude = coordinates.GetLatitude();
148         double longitude = coordinates.GetLongitude();
149         double altitude = coordinates.GetAltitude();
150
151         if (!Double::IsNaN(latitude))
152         {
153                 __latitude = latitude;
154         }
155         if (!Double::IsNaN(longitude))
156         {
157                 __longitude = longitude;
158         }
159         if (!Double::IsNaN(altitude))
160         {
161                 __altitude = altitude;
162         }
163
164         __coordinates = coordinates;
165 }
166
167 void
168 _ContentInfoImpl::SetLocationTag(const String& locationTag)
169 {
170         __locationTag = locationTag;
171 }
172
173 String
174 _ContentInfoImpl::GetLocationTag(void) const
175 {
176         return __locationTag;
177 }
178
179 void
180 _ContentInfoImpl::SetRating(const String& rating)
181 {
182         __rating = rating;
183 }
184
185 String
186 _ContentInfoImpl::GetRating(void) const
187 {
188         return __rating;
189 }
190
191 void
192 _ContentInfoImpl::SetCategory(const String& category)
193 {
194         __category = category;
195 }
196
197 String
198 _ContentInfoImpl::GetCategory(void) const
199 {
200         return __category;
201 }
202
203 void
204 _ContentInfoImpl::SetDescription(const String& description)
205 {
206         __description = description;
207 }
208
209 String
210 _ContentInfoImpl::GetDescription(void) const
211 {
212         return __description;
213 }
214
215 Bitmap*
216 _ContentInfoImpl::GetThumbnailN(void) const
217 {
218         result r = E_SUCCESS;
219         Image image;
220         Bitmap* pBitmap = null;
221
222         SysTryReturn(NID_CNT, !__thumbnailPath.IsEmpty(), null, E_DATA_NOT_FOUND,
223                         "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
224
225         if (__contentType == CONTENT_TYPE_IMAGE || __contentType == CONTENT_TYPE_AUDIO
226                 || __contentType == CONTENT_TYPE_VIDEO)
227         {
228                 r = image.Construct();
229                 SysTryReturn(NID_CNT, !IsFailed(r), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN() failed.");
230
231                 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
232                 {
233                         pBitmap = image.DecodeN(__thumbnailPath, BITMAP_PIXEL_FORMAT_ARGB8888, _THUMBNAIL_IMAGE_WIDTH, _THUMBNAIL_IMAGE_HEIGHT);
234                 }
235                 else
236                 {
237                         pBitmap = image.DecodeN(__thumbnailPath, BITMAP_PIXEL_FORMAT_ARGB8888);
238                 }
239
240                 if (pBitmap == null)
241                 {
242                         r = GetLastResult();
243
244                         if (r == E_OUT_OF_MEMORY)
245                         {
246                                 SysLogException(NID_CNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN() failed.");
247                                 return null;
248                         }
249                         else
250                         {
251                                 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
252                                 return null;
253                         }
254                 }
255         }
256         else
257         {
258                 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN() failed.");
259                 return null;
260         }
261
262         return pBitmap;
263 }
264
265 bool
266 _ContentInfoImpl::IsDrmProtected(void) const
267 {
268         return __isDrm;
269 }
270
271 String
272 _ContentInfoImpl::GetKeyword(void) const
273 {
274         return __keyword;
275 }
276
277 void
278 _ContentInfoImpl::SetContentName(const String& contentName)
279 {
280         __contentName = contentName;
281 }
282
283 void
284 _ContentInfoImpl::SetKeyword(const String& keyword)
285 {
286         __keyword = keyword;
287 }
288
289 void
290 _ContentInfoImpl::SetAuthor(const String& author)
291 {
292         __author = author;
293 }
294
295 String
296 _ContentInfoImpl::GetAuthor(void) const
297 {
298         return __author;
299 }
300
301 void
302 _ContentInfoImpl::SetProvider(const String& provider)
303 {
304         __provider = provider;
305 }
306
307 String
308 _ContentInfoImpl::GetProvider(void) const
309 {
310         return __provider;
311 }
312
313 String
314 _ContentInfoImpl::GetMediaFormat(void) const
315 {
316         return File::GetFileExtension(__contentPath);
317 }
318
319 void
320 _ContentInfoImpl::SetContentId(const ContentId& contentId)
321 {
322         __contentId = contentId;
323 }
324
325 void
326 _ContentInfoImpl::SetContentType(const ContentType& contentType)
327 {
328         __contentType = contentType;
329 }
330
331 void
332 _ContentInfoImpl::SetContentSize(unsigned long contentSize)
333 {
334         __contentSize = contentSize;
335 }
336
337 void
338 _ContentInfoImpl::SetMimeType(const String& mimeType)
339 {
340         __mimeType = mimeType;
341 }
342
343 void
344 _ContentInfoImpl::SetDateTime(const DateTime& dateTime)
345 {
346         __dateTime = dateTime;
347 }
348
349 void
350 _ContentInfoImpl::SetContentPath(const String& contentPath)
351 {
352         __contentPath = contentPath;
353 }
354
355 void
356 _ContentInfoImpl::SetMediaFormat(const String& mediaFormat)
357 {
358         __mediaFormat = mediaFormat;
359 }
360
361 void
362 _ContentInfoImpl::SetDrmProtected(bool isDrm)
363 {
364         __isDrm = isDrm;
365 }
366
367 double
368 _ContentInfoImpl::GetLatitude(void) const
369 {
370         return __latitude;
371 }
372
373 double
374 _ContentInfoImpl::GetLongitude(void) const
375 {
376         return __longitude;
377 }
378
379 double
380 _ContentInfoImpl::GetAltitude(void) const
381 {
382         return __altitude;
383 }
384
385 void
386 _ContentInfoImpl::SetLatitude(double latitude)
387 {
388         __latitude = latitude;
389 }
390
391 void
392 _ContentInfoImpl::SetLongitude(double longitude)
393 {
394         __longitude = longitude;
395 }
396
397 void
398 _ContentInfoImpl::SetAltitude(double altitude)
399 {
400         __altitude = altitude;
401 }
402
403 String
404 _ContentInfoImpl::GetThumbnailPath(void) const
405 {
406         return __thumbnailPath;
407 }
408
409 void
410 _ContentInfoImpl::SetThumbnailPath(const String& thumbnailPath)
411 {
412         __thumbnailPath = thumbnailPath;
413 }
414
415 void
416 _ContentInfoImpl::SetStorageType(int storageType)
417 {
418         __storageType = storageType;
419 }
420
421 DateTime
422 _ContentInfoImpl::GetModifiedTime(void) const
423 {
424         return __modifiedTime;
425 }
426
427 void
428 _ContentInfoImpl::SetModifiedTime(const DateTime& modifiedTime)
429 {
430         __modifiedTime = modifiedTime;
431 }
432
433 }}