Fix : Search APIs don't return exception despite the content in DB doesn't match...
[platform/framework/native/content.git] / src / FCnt_ImageContentInfoImpl.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_ImageContentInfoImpl.cpp
18  * @brief               This is the implementation file for the %_ImageContentInfoImpl class.
19  *
20  * This file contains implementation of the %_ImageContentInfoImpl class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FIoFile.h>
25 #include <FIoDirectory.h>
26 #include <FSysEnvironment.h>
27 #include <FIo_FileImpl.h>
28 #include <FApp_AppInfo.h>
29 #include "FCnt_ImageContentInfoImpl.h"
30
31 using namespace std;
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Io;
35 using namespace Tizen::Locations;
36 using namespace Tizen::System;
37
38 namespace Tizen { namespace Content
39 {
40
41 _ImageContentInfoImpl::_ImageContentInfoImpl(void)
42         : __width(0)
43         , __height(0)
44         , __isBurst(false)
45         , __orientationType(IMAGE_ORIENTATION_TYPE_UNKNOWN)
46         , __title(L"")
47         , __burstShotId(L"")
48 {
49
50 }
51
52 _ImageContentInfoImpl::~_ImageContentInfoImpl(void)
53 {
54
55 }
56
57 _ImageContentInfoImpl*
58 _ImageContentInfoImpl::GetInstance(ImageContentInfo& imageContentInfo)
59 {
60         return imageContentInfo.__pImageContentInfoImpl;
61 }
62
63 const _ImageContentInfoImpl*
64 _ImageContentInfoImpl::GetInstance(const ImageContentInfo& imageContentInfo)
65 {
66         return imageContentInfo.__pImageContentInfoImpl;
67 }
68
69 result
70 _ImageContentInfoImpl::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
71 {
72         result r = E_SUCCESS;
73         String tempPath(contentPath);
74
75         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
76         {
77                 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
78                 {
79                         // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
80                         // it should be converted in 2.0.
81                         r = tempPath.Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
82                         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
83                 }
84                 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
85                 {
86                         r = tempPath.Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
87                         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
88                 }
89                 else
90                 {
91                         SysLogException(NID_CNT, E_INVALID_ARG,
92                                         "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
93                         return E_INVALID_ARG;
94                 }
95         }
96
97         // checks parameters
98         SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
99                         "The contentPath should start with /Media or /Storagecard/Media.");
100         SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
101                         "The file corresponding to contentPath could not be found.");
102
103         if (!thumbnailPath.IsEmpty())
104         {
105                 SysLog(NID_CNT,
106                                 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
107         }
108
109         if (setGps)
110         {
111                 SysLog(NID_CNT, "The setGps is not supported.");
112         }
113
114         SetContentPath(tempPath);
115         SetContentType(CONTENT_TYPE_IMAGE);
116
117         return r;
118 }
119
120 result
121 _ImageContentInfoImpl::Construct(const String* pContentPath)
122 {
123         result r = E_SUCCESS;
124
125         if (pContentPath != null)
126         {
127                 String contentPath(*pContentPath);
128
129                 if (!_AppInfo::IsOspCompat())
130                 {
131                         if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0)
132                                 || contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
133                         {
134                                 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
135                                 return E_INVALID_ARG;
136                         }
137                 }
138                 else
139                 {
140                         // prior to 2.0
141                         if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
142                         {
143                                 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
144                                 // it should be converted in 2.0.
145                                 r = contentPath.Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
146                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
147                         }
148                         else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
149                         {
150                                 r = contentPath.Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
151                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
152                         }
153                         else
154                         {
155                                 SysLogException(NID_CNT, E_INVALID_ARG,
156                                                 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
157                                 return E_INVALID_ARG;
158                         }
159                 }
160
161                 int length = contentPath.GetLength();
162                 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
163                                 "The length of pContentPath is 0.");
164                 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
165                                 "The file corresponding to pContentPath could not be found.");
166
167                 SetContentPath(contentPath);
168                 SetContentType(CONTENT_TYPE_IMAGE);
169         }
170         else
171         {
172                 SetContentType(CONTENT_TYPE_IMAGE);
173         }
174
175         return r;
176 }
177
178 int
179 _ImageContentInfoImpl::GetWidth(void) const
180 {
181         return __width;
182 }
183
184 int
185 _ImageContentInfoImpl::GetHeight(void) const
186 {
187         return __height;
188 }
189
190 ImageOrientationType
191 _ImageContentInfoImpl::GetOrientation(void) const
192 {
193         return __orientationType;
194 }
195
196 DateTime
197 _ImageContentInfoImpl::GetImageTakenDate(void) const
198 {
199         return __takenDate;
200 }
201
202 String
203 _ImageContentInfoImpl::GetTitle(void) const
204 {
205         if (__title.IsEmpty())
206         {
207                 SysLog(NID_CNT, "Title is empty.");
208                 return L"Unknown";
209         }
210
211         return __title;
212 }
213
214 bool
215 _ImageContentInfoImpl::IsBurstShot(void) const
216 {
217         return __isBurst;
218 }
219
220 String
221 _ImageContentInfoImpl::GetBurstShotId(void) const
222 {
223         return __burstShotId;
224 }
225
226 void
227 _ImageContentInfoImpl::SetWidth(int width)
228 {
229         __width = width;
230 }
231
232 void
233 _ImageContentInfoImpl::SetHeight(int height)
234 {
235         __height = height;
236 }
237
238 void
239 _ImageContentInfoImpl::SetTitle(const String& title)
240 {
241         __title = title;
242 }
243
244 void
245 _ImageContentInfoImpl::SetOrientation(const ImageOrientationType& orientationType)
246 {
247         __orientationType = orientationType;
248 }
249
250 void
251 _ImageContentInfoImpl::SetImageTakenDate(const DateTime& takenDate)
252 {
253         __takenDate = takenDate;
254 }
255
256 void
257 _ImageContentInfoImpl::SetBurstShot(const bool isBurst)
258 {
259         __isBurst = isBurst;
260 }
261
262 void
263 _ImageContentInfoImpl::SetBurstShotId(const String& burstShotId)
264 {
265         __burstShotId = burstShotId;
266 }
267
268 }}