Fix memory leaks
[apps/osp/Gallery.git] / src / GlThumbnailInfo.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 /**
18  * @file                GlThumbnailInfo.cpp
19  * @brief               This is the implementation file for ThumbnailInfo class.
20  */
21
22 #include <FGraphics.h>
23 #include "GlThumbnailInfo.h"
24 #include "GlTypes.h"
25
26 using namespace Tizen::Base;
27 using namespace Tizen::Content;
28 using namespace Tizen::Graphics;
29
30 ThumbnailInfo::ThumbnailInfo(void)
31         : __pBitmap(null)
32         , __contentType(CONTENT_TYPE_IMAGE)
33         , __duration(0)
34 {
35 }
36
37 ThumbnailInfo::~ThumbnailInfo(void)
38 {
39         delete __pBitmap;
40 }
41
42 void
43 ThumbnailInfo::Construct(const ContentId& contentId, const String& filePath,
44                 const Bitmap& bitmap, const ContentType contentType, const long duration)
45 {
46         __contentId = contentId;
47         __filePath = filePath;
48         __pBitmap = CloneBitmapN(bitmap);
49         __contentType = contentType;
50         __duration = duration;
51 }
52
53 ContentId
54 ThumbnailInfo::GetContentId(void) const
55 {
56         return __contentId;
57 }
58
59 String
60 ThumbnailInfo::GetFilePath(void) const
61 {
62         return __filePath;
63 }
64
65 void
66 ThumbnailInfo::SetFilePath(const String& filePath)
67 {
68         if (&filePath == null)
69         {
70                 __filePath = EMPTY_SPACE;
71         }
72         else
73         {
74                 __filePath = filePath;
75         }
76 }
77
78 Bitmap*
79 ThumbnailInfo::GetBitmapN(void) const
80 {
81         return CloneBitmapN(*__pBitmap);
82 }
83
84 void
85 ThumbnailInfo::SetBitmap(const Bitmap& bitmap)
86 {
87         if (__pBitmap)
88         {
89                 delete __pBitmap;
90         }
91         __pBitmap = CloneBitmapN(bitmap);
92 }
93
94 ContentType
95 ThumbnailInfo::GetContentType(void) const
96 {
97         return __contentType;
98 }
99
100 void
101 ThumbnailInfo::SetContentType(ContentType contentType)
102 {
103         __contentType = contentType;
104 }
105
106 long
107 ThumbnailInfo::GetDuration(void) const
108 {
109         return __duration;
110 }
111
112 void
113 ThumbnailInfo::SetDuration(long duration)
114 {
115         __duration = duration;
116 }
117
118 Bitmap*
119 ThumbnailInfo::CloneBitmapN(const Bitmap& bitmap) const
120 {
121         Bitmap* pResultBitmap = null;
122         if (&bitmap != null)
123         {
124                 Rectangle mainRect(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
125                 Canvas mainCanvas;
126                 mainCanvas.Construct(mainRect);
127                 mainCanvas.DrawBitmap(mainRect, bitmap);
128                 pResultBitmap = new (std::nothrow) Bitmap();
129                 result r = pResultBitmap->Construct(mainCanvas, mainRect);
130                 TryCatch(r == E_SUCCESS, , "pResultBitmap->Construct Failed:%s", GetErrorMessage(r));
131         }
132         return pResultBitmap;
133
134 CATCH:
135         delete pResultBitmap;
136         pResultBitmap = null;
137
138         return null;
139
140 }