[content] Fix remove item bug on PlayList
[platform/framework/native/content.git] / src / FCnt_ImageMetadataImpl.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                FCnt_ImageMetadataImpl.cpp
19  * @brief               This is the implementation file for the %_ImageMetadataImpl class.
20  *
21  * This file contains implementation of the %_ImageMetadataImpl class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FMediaImage.h>
26 #include <FGrpBitmap.h>
27 #include <FCntImageMetadata.h>
28 #include <FCnt_ImageMetadataImpl.h>
29 #include <FIo_FileImpl.h>
30 #include <FMedia_ImageImpl.h>
31
32 using namespace std;
33 using namespace Tizen::Base;
34 using namespace Tizen::Io;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Media;
37
38 namespace Tizen { namespace Content
39 {
40
41 static const int THUMBNAIL_IMAGE_WIDTH = 320;
42 static const int THUMBNAIL_IMAGE_HEIGHT = 240;
43 static const double DEFAULT_COORDINATE = -200.0;
44
45 _ImageMetadataImpl::_ImageMetadataImpl(void)
46         : Object()
47 {
48         unique_ptr<ImageMeta, ImageMetaDeleter> pNewImageMeta(new (nothrow) ImageMeta());
49         if (pNewImageMeta != null)
50         {
51                 __pImageMeta = move(pNewImageMeta);
52         }
53         else
54         {
55                 __pImageMeta = null;
56                 SysLog(NID_CNT, "The memory is insufficient.");
57         }
58 }
59
60 _ImageMetadataImpl::~_ImageMetadataImpl(void)
61 {
62
63 }
64
65 _ImageMetadataImpl*
66 _ImageMetadataImpl::GetInstance(ImageMetadata& imageMetadata)
67 {
68         return imageMetadata.__pImpl;
69 }
70
71 const _ImageMetadataImpl*
72 _ImageMetadataImpl::GetInstance(const ImageMetadata& imageMetadata)
73 {
74         return imageMetadata.__pImpl;
75 }
76
77 result
78 _ImageMetadataImpl::SetImageMetadata(const ImageMeta* pImageMeta)
79 {
80         ClearLastResult();
81
82         SysTryReturnResult(NID_CNT, pImageMeta != null, E_INVALID_ARG, "pImageMeta is null.");
83
84         __pImageMeta->width = pImageMeta->width;
85         __pImageMeta->height = pImageMeta->height;
86         __pImageMeta->orientation = pImageMeta->orientation;
87         __pImageMeta->latitude = pImageMeta->latitude;
88         __pImageMeta->longitude = pImageMeta->longitude;
89         __pImageMeta->contentPath = pImageMeta->contentPath;
90
91         if (pImageMeta->pManufacturer != null)
92         {
93                 __pImageMeta->pManufacturer = new (nothrow) String(*(pImageMeta->pManufacturer));
94                 SysTryReturnResult(NID_CNT, __pImageMeta->pManufacturer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
95         }
96         if (pImageMeta->pModel != null)
97         {
98                 __pImageMeta->pModel = new (nothrow) String(*(pImageMeta->pModel));
99                 SysTryReturnResult(NID_CNT, __pImageMeta->pModel != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
100         }
101         if (pImageMeta->pDateTime != null)
102         {
103                 __pImageMeta->pDateTime = new (nothrow) String(*(pImageMeta->pDateTime));
104                 SysTryReturnResult(NID_CNT, __pImageMeta->pDateTime != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
105         }
106         if (pImageMeta->pSoftware != null)
107         {
108                 __pImageMeta->pSoftware = new (nothrow) String(*(pImageMeta->pSoftware));
109                 SysTryReturnResult(NID_CNT, __pImageMeta->pSoftware != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
110         }
111         if (pImageMeta->pWhiteBalance != null)
112         {
113                 __pImageMeta->pWhiteBalance = new (nothrow) String(*(pImageMeta->pWhiteBalance));
114                 SysTryReturnResult(NID_CNT, __pImageMeta->pWhiteBalance != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
115         }
116
117         return E_SUCCESS;
118 }
119
120 ImageMeta*
121 _ImageMetadataImpl::GetImageMetadata(void) const
122 {
123         return __pImageMeta.get();
124 }
125
126 _ImageMetadataImpl::_ImageMetadataImpl(const _ImageMetadataImpl& rhs)
127         : Object()
128 {
129         unique_ptr<ImageMeta, ImageMetaDeleter> pNewImageMeta(new (nothrow) ImageMeta());
130         if (pNewImageMeta != null)
131         {
132                 pNewImageMeta->width = (rhs.__pImageMeta)->width;
133                 pNewImageMeta->height = (rhs.__pImageMeta)->height;
134                 pNewImageMeta->orientation = (rhs.__pImageMeta)->orientation;
135                 pNewImageMeta->latitude = (rhs.__pImageMeta)->latitude;
136                 pNewImageMeta->longitude = (rhs.__pImageMeta)->longitude;
137                 pNewImageMeta->contentPath = (rhs.__pImageMeta)->contentPath;
138
139                 if ((rhs.__pImageMeta)->pManufacturer != null)
140                 {
141                         pNewImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
142                         if (pNewImageMeta->pManufacturer == null)
143                         {
144                                 SysLog(NID_CNT, "The memory is insufficient.");
145                                 return;
146                         }
147                 }
148                 if ((rhs.__pImageMeta)->pModel != null)
149                 {
150                         pNewImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
151                         if (pNewImageMeta->pModel == null)
152                         {
153                                 SysLog(NID_CNT, "The memory is insufficient.");
154                                 return;
155                         }
156                 }
157                 if ((rhs.__pImageMeta)->pDateTime != null)
158                 {
159                         pNewImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
160                         if (pNewImageMeta->pDateTime == null)
161                         {
162                                 SysLog(NID_CNT, "The memory is insufficient.");
163                                 return;
164                         }
165                 }
166                 if ((rhs.__pImageMeta)->pSoftware != null)
167                 {
168                         pNewImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
169                         if (pNewImageMeta->pSoftware == null)
170                         {
171                                 SysLog(NID_CNT, "The memory is insufficient.");
172                                 return;
173                         }
174                 }
175                 if ((rhs.__pImageMeta)->pWhiteBalance != null)
176                 {
177                         pNewImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
178                         if (pNewImageMeta->pWhiteBalance == null)
179                         {
180                                 SysLog(NID_CNT, "The memory is insufficient.");
181                                 return;
182                         }
183                 }
184
185                 __pImageMeta = move(pNewImageMeta);
186         }
187         else
188         {
189                 __pImageMeta = null;
190                 SysLog(NID_CNT, "The memory is insufficient.");
191         }
192 }
193
194 _ImageMetadataImpl&
195 _ImageMetadataImpl::operator =(const _ImageMetadataImpl& rhs)
196 {
197         // check for self-assignment
198         if (this == &rhs)
199         {
200                 return *this;
201         }
202
203         // __pImageMeta
204         if (__pImageMeta != null && (rhs.__pImageMeta) != null)
205         {
206                 // DeleteMetadata(__pImageMeta);
207                 // __pImageMeta = new (nothrow) ImageMeta;
208
209                 __pImageMeta.reset(new (nothrow) ImageMeta);
210         }
211         else if (__pImageMeta != null)
212         {
213                 //DeleteMetadata(__pImageMeta);
214
215                 __pImageMeta.reset(null);
216                 return *this;
217         }
218         else if ((rhs.__pImageMeta) != null)
219         {
220                 //__pImageMeta = new (nothrow) ImageMeta;
221
222                 __pImageMeta.reset(new (nothrow) ImageMeta);
223         }
224         else
225         {
226                 // __pImageMeta and rhs.__pImageMeta are null.
227                 return *this;
228         }
229
230         __pImageMeta->width = (rhs.__pImageMeta)->width;
231         __pImageMeta->height = (rhs.__pImageMeta)->height;
232         __pImageMeta->orientation = (rhs.__pImageMeta)->orientation;
233         __pImageMeta->latitude = (rhs.__pImageMeta)->latitude;
234         __pImageMeta->longitude = (rhs.__pImageMeta)->longitude;
235         __pImageMeta->contentPath = (rhs.__pImageMeta)->contentPath;
236
237         // pManufacturer
238         if (__pImageMeta->pManufacturer != null && (rhs.__pImageMeta)->pManufacturer != null)
239         {
240                 // delete previous data
241                 delete __pImageMeta->pManufacturer;
242                 __pImageMeta->pManufacturer = null;
243
244                 __pImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
245         }
246         else if (__pImageMeta->pManufacturer != null)
247         {
248                 delete __pImageMeta->pManufacturer;
249                 __pImageMeta->pManufacturer = null;
250         }
251         else if ((rhs.__pImageMeta)->pManufacturer != null)
252         {
253                 __pImageMeta->pManufacturer = new (nothrow) String(*((rhs.__pImageMeta)->pManufacturer));
254         }
255
256         // pModel
257         if (__pImageMeta->pModel != null && (rhs.__pImageMeta)->pModel != null)
258         {
259                 // delete previous data
260                 delete __pImageMeta->pModel;
261                 __pImageMeta->pModel = null;
262
263                 __pImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
264         }
265         else if (__pImageMeta->pModel != null)
266         {
267                 delete __pImageMeta->pModel;
268                 __pImageMeta->pModel = null;
269         }
270         else if ((rhs.__pImageMeta)->pModel != null)
271         {
272                 __pImageMeta->pModel = new (nothrow) String(*((rhs.__pImageMeta)->pModel));
273         }
274
275         // pDateTime
276         if (__pImageMeta->pDateTime != null && (rhs.__pImageMeta)->pDateTime != null)
277         {
278                 // delete previous data
279                 delete __pImageMeta->pDateTime;
280                 __pImageMeta->pDateTime = null;
281
282                 __pImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
283         }
284         else if (__pImageMeta->pDateTime != null)
285         {
286                 delete __pImageMeta->pDateTime;
287                 __pImageMeta->pDateTime = null;
288         }
289         else if ((rhs.__pImageMeta)->pDateTime != null)
290         {
291                 __pImageMeta->pDateTime = new (nothrow) String(*((rhs.__pImageMeta)->pDateTime));
292         }
293
294         // pSoftware
295         if (__pImageMeta->pSoftware != null && (rhs.__pImageMeta)->pSoftware != null)
296         {
297                 // delete previous data
298                 delete __pImageMeta->pSoftware;
299                 __pImageMeta->pSoftware = null;
300
301                 __pImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
302         }
303         else if (__pImageMeta->pSoftware != null)
304         {
305                 delete __pImageMeta->pSoftware;
306                 __pImageMeta->pSoftware = null;
307         }
308         else if ((rhs.__pImageMeta)->pSoftware != null)
309         {
310                 __pImageMeta->pSoftware = new (nothrow) String(*((rhs.__pImageMeta)->pSoftware));
311         }
312
313         // pWhiteBalance
314         if (__pImageMeta->pWhiteBalance != null && (rhs.__pImageMeta)->pWhiteBalance != null)
315         {
316                 // delete previous data
317                 delete __pImageMeta->pWhiteBalance;
318                 __pImageMeta->pWhiteBalance = null;
319
320                 __pImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
321         }
322         else if (__pImageMeta->pWhiteBalance != null)
323         {
324                 delete __pImageMeta->pWhiteBalance;
325                 __pImageMeta->pWhiteBalance = null;
326         }
327         else if ((rhs.__pImageMeta)->pWhiteBalance != null)
328         {
329                 __pImageMeta->pWhiteBalance = new (nothrow) String(*((rhs.__pImageMeta)->pWhiteBalance));
330         }
331
332         SysLog(NID_CNT, "_ImageMetadataImpl::operator =(const _ImageMetadataImpl& rhs) is called.");
333         return *this;
334 }
335
336 bool
337 _ImageMetadataImpl::Equals(const Tizen::Base::Object& rhs) const
338 {
339         const _ImageMetadataImpl* pRhs = dynamic_cast <const _ImageMetadataImpl*>(&rhs);
340         if (pRhs == null)
341         {
342                 return false;
343         }
344
345         if (!((this->GetCameraManufacturer()).Equals(pRhs->GetCameraManufacturer())))
346         {
347                 return false;
348         }
349         if (!((this->GetCameraModel()).Equals(pRhs->GetCameraModel())))
350         {
351                 return false;
352         }
353         if (!((this->GetDateTime()).Equals(pRhs->GetDateTime())))
354         {
355                 return false;
356         }
357         if (this->GetHeight() != pRhs->GetHeight())
358         {
359                 return false;
360         }
361         if (Double::Compare(this->GetLatitude(), pRhs->GetLatitude()) != 0)
362         {
363                 return false;
364         }
365         if (Double::Compare(this->GetLongitude(), pRhs->GetLongitude()) != 0)
366         {
367                 return false;
368         }
369         if (this->GetOrientation() != pRhs->GetOrientation())
370         {
371                 return false;
372         }
373         if (!((this->GetSoftware()).Equals(pRhs->GetSoftware())))
374         {
375                 return false;
376         }
377         if (!((this->GetWhiteBalance()).Equals(pRhs->GetWhiteBalance())))
378         {
379                 return false;
380         }
381         if (this->GetWidth() != pRhs->GetWidth())
382         {
383                 return false;
384         }
385
386         return true;
387 }
388
389 int
390 _ImageMetadataImpl::GetHashCode(void) const
391 {
392         return (this->GetCameraManufacturer()).GetHashCode()
393                         ^ (this->GetCameraModel()).GetHashCode()
394                         ^ (this->GetDateTime()).GetHashCode()
395                         ^ Integer::GetHashCode(this->GetHeight())
396                         ^ Double::GetHashCode(this->GetLatitude())
397                         ^ Double::GetHashCode(this->GetLongitude())
398                         ^ Integer::GetHashCode(this->GetOrientation())
399                         ^ (this->GetSoftware()).GetHashCode()
400                         ^ (this->GetWhiteBalance()).GetHashCode()
401                         ^ Integer::GetHashCode(this->GetWidth());
402 }
403
404 int
405 _ImageMetadataImpl::GetWidth(void) const
406 {
407         if (__pImageMeta == null)
408         {
409                 SysLog(NID_CNT, "__pImageMeta is null.");
410                 return 0;
411         }
412         return __pImageMeta->width;
413 }
414
415 int
416 _ImageMetadataImpl::GetHeight(void) const
417 {
418         if (__pImageMeta == null)
419         {
420                 SysLog(NID_CNT, "__pImageMeta is null.");
421                 return 0;
422         }
423         return __pImageMeta->height;
424 }
425
426 String
427 _ImageMetadataImpl::GetCameraManufacturer(void) const
428 {
429         if (__pImageMeta == null || __pImageMeta->pManufacturer == null)
430         {
431                 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pManufacturer is null.");
432                 return String();
433         }
434         return *(__pImageMeta->pManufacturer);
435 }
436
437 String
438 _ImageMetadataImpl::GetCameraModel(void) const
439 {
440         if (__pImageMeta == null || __pImageMeta->pModel == null)
441         {
442                 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pModel is null.");
443                 return String();
444         }
445         return *(__pImageMeta->pModel);
446 }
447
448 String
449 _ImageMetadataImpl::GetSoftware(void) const
450 {
451         if (__pImageMeta == null || __pImageMeta->pSoftware == null)
452         {
453                 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pSoftware is null.");
454                 return String();
455         }
456         return *(__pImageMeta->pSoftware);
457 }
458
459 String
460 _ImageMetadataImpl::GetDateTime(void) const
461 {
462         if (__pImageMeta == null || __pImageMeta->pDateTime == null)
463         {
464                 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pDateTime is null.");
465                 return String();
466         }
467         return *(__pImageMeta->pDateTime);
468 }
469
470 double
471 _ImageMetadataImpl::GetLatitude(void) const
472 {
473         if (__pImageMeta == null)
474         {
475                 SysLog(NID_CNT, "__pImageMeta is null.");
476                 return DEFAULT_COORDINATE;
477         }
478         return __pImageMeta->latitude;
479 }
480
481 double
482 _ImageMetadataImpl::GetLongitude(void) const
483 {
484         if (__pImageMeta == null)
485         {
486                 SysLog(NID_CNT, "__pImageMeta is null.");
487                 return DEFAULT_COORDINATE;
488         }
489         return __pImageMeta->longitude;
490 }
491
492 ImageOrientationType
493 _ImageMetadataImpl::GetOrientation(void) const
494 {
495         if (__pImageMeta == null)
496         {
497                 SysLog(NID_CNT, "__pImageMeta is null.");
498                 return IMAGE_ORIENTATION_TYPE_UNKNOWN;
499         }
500         return __pImageMeta->orientation;
501 }
502
503 String
504 _ImageMetadataImpl::GetWhiteBalance(void) const
505 {
506         if (__pImageMeta == null || __pImageMeta->pWhiteBalance == null)
507         {
508                 SysLog(NID_CNT, "__pImageMeta or __pImageMeta->pWhiteBalance is null.");
509                 return String();
510         }
511         return *(__pImageMeta->pWhiteBalance);
512 }
513
514 //
515 // E_SUCCESS
516 // E_DATA_NOT_FOUND
517 // E_OUT_OF_MEMORY
518 //
519 Bitmap*
520 _ImageMetadataImpl::GetThumbnailN(void) const
521 {
522         ClearLastResult();
523
524         SysTryReturn(NID_CNT, __pImageMeta != null, null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
525         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(__pImageMeta->contentPath), null, E_DATA_NOT_FOUND,
526                                 "[E_DATA_NOT_FOUND] GetThumbnailN failed [%ls].", (__pImageMeta->contentPath).GetPointer());
527
528         Image image;
529         result r = image.Construct();
530         SysTryReturn(NID_CNT, !IsFailed(r), null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
531
532         Bitmap* pBitmap = image.DecodeN(__pImageMeta->contentPath, BITMAP_PIXEL_FORMAT_ARGB8888, THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
533         if (pBitmap == null)
534         {
535                 r = GetLastResult();
536
537                 if (r == E_OUT_OF_MEMORY)
538                 {
539                         SysLogException(NID_CNT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetThumbnailN failed.");
540                 }
541                 else
542                 {
543                         SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] GetThumbnailN failed.");
544                 }
545
546                 return null;
547         }
548
549         return pBitmap;
550 }
551 }}