[content] Change secure log
[platform/framework/native/content.git] / src / FCntImageContentInfo.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                FCntImageContentInfo.cpp
19  * @brief               This is the implementation file for the %ImageContentInfo class.
20  *
21  * This file contains implementation of the %ImageContentInfo class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FCntImageContentInfo.h>
26 #include <FIoFile.h>
27 #include <FIoDirectory.h>
28 #include <FSysEnvironment.h>
29 #include <FIo_FileImpl.h>
30 #include <FApp_AppInfo.h>
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Io;
34 using namespace Tizen::Locations;
35 using namespace Tizen::App;
36 using namespace Tizen::System;
37 using namespace std;
38
39 namespace Tizen { namespace Content
40 {
41
42 ImageContentInfo::ImageContentInfo(void)
43         : ContentInfo()
44         , __pImageContentData(null)
45         , __pImpl(null)
46 {
47
48 }
49
50 ImageContentInfo::~ImageContentInfo(void)
51 {
52         if (__pImageContentData != null)
53         {
54                 delete __pImageContentData;
55                 __pImageContentData = null;
56         }
57 }
58
59 /**
60  * E_SUCCESS
61  * E_FILE_NOT_FOUND
62  * E_INVALID_ARG
63  * E_OUT_OF_MEMORY
64  * - E_IO
65  */
66 result
67 ImageContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
68 {
69         ClearLastResult();
70
71         SysAssertf(__pImageContentData == null,
72                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
73
74         result r = E_SUCCESS;
75         _ContentData contentData;
76         int contentLength = 0;
77         FileAttributes attribute;
78
79         // checks parameters
80         contentLength = contentPath.GetLength();
81         SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
82                         "The contentPath should start with /Media or /Storagecard/Media.");
83         SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
84                         "The file corresponding to contentPath could not be found.");
85
86         if (!thumbnailPath.IsEmpty())
87         {
88                 SysLog(NID_CNT,
89                                 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
90         }
91
92         if (setGps)
93         {
94                 SysLog(NID_CNT, "The setGps is not supported.");
95         }
96
97         // Sets the content path
98         contentData.contentPath = contentPath;
99
100         // Sets the content type
101         contentData.contentType = CONTENT_TYPE_IMAGE;
102
103         // E_INVALID_ARG, E_OUT_OF_MEMORY
104         r = SetContentData(&contentData);
105         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
106
107         _ImageContentData* pImageContentData = new (nothrow) _ImageContentData();
108         SysTryReturnResult(NID_CNT, pImageContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
109
110         __pImageContentData = pImageContentData;
111
112         return r;
113 }
114
115 /**
116  * E_SUCCESS
117  * E_FILE_NOT_FOUND
118  * E_INVALID_ARG
119  * E_OUT_OF_MEMORY
120  * - E_IO
121  * - E_SYSTEM
122  */
123 result
124 ImageContentInfo::Construct(const String* pContentPath)
125 {
126         ClearLastResult();
127
128         SysAssertf(__pImageContentData == null,
129                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
130
131         result r = E_SUCCESS;
132         _ContentData contentData;
133
134         if (pContentPath != null)
135         {
136                 if (!_AppInfo::IsOspCompat())
137                 {
138                         if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
139                         {
140                                 SysLogException(NID_CNT, E_INVALID_ARG,
141                                                 "[E_INVALID_ARG] /Media/ and /Storagecard/Media/ are not supported from Tizen 2.0.");
142                                 return E_INVALID_ARG;
143                         }
144                         if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
145                                 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
146                         {
147                                 SysLogException(NID_CNT, E_INVALID_ARG,
148                                                 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
149                                 return E_INVALID_ARG;
150                         }
151                 }
152                 else
153                 {
154                         // prior to 2.0
155                         if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
156                         {
157                                 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
158                                 // it should be converted in 2.0.
159                                 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
160                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
161                         }
162                         else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
163                         {
164                                 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
165                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
166                         }
167                         else
168                         {
169                                 SysLogException(NID_CNT, E_INVALID_ARG,
170                                                 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
171                                 return E_INVALID_ARG;
172                         }
173                 }
174
175                 int length = pContentPath->GetLength();
176                 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
177                                 "The length of pContentPath is 0.");
178                 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
179                                 "The file corresponding to pContentPath could not be found.");
180
181                 // Sets the content path
182                 contentData.contentPath = *pContentPath;
183
184                 // Sets the content type
185                 contentData.contentType = CONTENT_TYPE_IMAGE;
186
187                 r = SetContentData(&contentData);
188                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
189         }
190         else
191         {
192                 contentData.contentType = CONTENT_TYPE_IMAGE;
193
194                 r = SetContentData(&contentData);
195                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
196         }
197
198         _ImageContentData* pImageContentData = new (nothrow) _ImageContentData();
199         SysTryReturnResult(NID_CNT, pImageContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
200
201         __pImageContentData = pImageContentData;
202
203         return r;
204 }
205
206 result
207 ImageContentInfo::SetImageContentData(const _ImageContentData* pImageContentData)
208 {
209         ClearLastResult();
210
211         SysTryReturnResult(NID_CNT, pImageContentData != null, E_INVALID_ARG, "pImageContentData is null.");
212
213         // _ContentManagerImpl::GetContentInfoN makes an instance of this class. at that time it does not call Construct().
214         // Because __pImageContentData is created in Construct(), If there is no codes for allocation, crash will occur.
215         if (__pImageContentData == null)
216         {
217                 __pImageContentData = new (nothrow) _ImageContentData;
218                 SysTryReturnResult(NID_CNT, __pImageContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
219         }
220
221         __pImageContentData->width = pImageContentData->width;
222         __pImageContentData->height = pImageContentData->height;
223         __pImageContentData->orientationType = pImageContentData->orientationType;
224         __pImageContentData->title = pImageContentData->title;
225
226         return E_SUCCESS;
227 }
228
229 ImageContentInfo::_ImageContentData*
230 ImageContentInfo::GetImageContentData(void)
231 {
232         if (__pImageContentData == null)
233         {
234                 __pImageContentData = new (nothrow) ImageContentInfo::_ImageContentData;
235                 SysTryReturn(NID_CNT, __pImageContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
236         }
237         return __pImageContentData;
238 }
239
240 int
241 ImageContentInfo::GetWidth(void) const
242 {
243         SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
244
245         return __pImageContentData->width;
246 }
247
248 int
249 ImageContentInfo::GetHeight(void) const
250 {
251         SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
252
253         return __pImageContentData->height;
254 }
255
256 ImageOrientationType
257 ImageContentInfo::GetOrientation(void) const
258 {
259         SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
260
261         return __pImageContentData->orientationType;
262 }
263
264 String
265 ImageContentInfo::GetTitle(void) const
266 {
267         SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
268
269         if ((__pImageContentData->title).IsEmpty())
270         {
271                 return String(L"Unknown");
272         }
273
274         return __pImageContentData->title;
275 }
276
277 }}