2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FCntImageContentInfo.cpp
19 * @brief This is the implementation file for the %ImageContentInfo class.
21 * This file contains implementation of the %ImageContentInfo class.
24 #include <FBaseSysLog.h>
25 #include <FCntImageContentInfo.h>
27 #include <FIoDirectory.h>
28 #include <FSysEnvironment.h>
29 #include <FIo_FileImpl.h>
30 #include <FApp_AppInfo.h>
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;
39 namespace Tizen { namespace Content
42 ImageContentInfo::ImageContentInfo(void)
44 , __pImageContentData(null)
50 ImageContentInfo::~ImageContentInfo(void)
52 if (__pImageContentData != null)
54 delete __pImageContentData;
55 __pImageContentData = null;
67 ImageContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
71 SysAssertf(__pImageContentData == null,
72 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
75 _ContentData contentData;
76 int contentLength = 0;
77 FileAttributes attribute;
80 contentLength = contentPath.GetLength();
81 SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
82 "The contentPath should start with /Media or /Storagecard/Media(%ls).", contentPath.GetPointer());
83 SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
84 "The file corresponding to contentPath could not be found.");
86 if (!thumbnailPath.IsEmpty())
89 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
94 SysLog(NID_CNT, "The setGps is not supported.");
97 // Sets the content path
98 contentData.contentPath = contentPath;
100 // Sets the content type
101 contentData.contentType = CONTENT_TYPE_IMAGE;
103 // E_INVALID_ARG, E_OUT_OF_MEMORY
104 r = SetContentData(&contentData);
105 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
107 _ImageContentData* pImageContentData = new (nothrow) _ImageContentData();
108 SysTryReturnResult(NID_CNT, pImageContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
110 __pImageContentData = pImageContentData;
124 ImageContentInfo::Construct(const String* pContentPath)
128 SysAssertf(__pImageContentData == null,
129 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
131 result r = E_SUCCESS;
132 _ContentData contentData;
134 if (pContentPath != null)
136 if (!_AppInfo::IsOspCompat())
138 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
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;
144 if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
145 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
147 SysLogException(NID_CNT, E_INVALID_ARG,
148 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
149 return E_INVALID_ARG;
155 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
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.");
162 else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
164 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
165 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
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;
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.");
181 // Sets the content path
182 contentData.contentPath = *pContentPath;
184 // Sets the content type
185 contentData.contentType = CONTENT_TYPE_IMAGE;
187 r = SetContentData(&contentData);
188 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
192 contentData.contentType = CONTENT_TYPE_IMAGE;
194 r = SetContentData(&contentData);
195 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
198 _ImageContentData* pImageContentData = new (nothrow) _ImageContentData();
199 SysTryReturnResult(NID_CNT, pImageContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
201 __pImageContentData = pImageContentData;
207 ImageContentInfo::SetImageContentData(const _ImageContentData* pImageContentData)
211 SysTryReturnResult(NID_CNT, pImageContentData != null, E_INVALID_ARG, "pImageContentData is null.");
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)
217 __pImageContentData = new (nothrow) _ImageContentData;
218 SysTryReturnResult(NID_CNT, __pImageContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
221 __pImageContentData->width = pImageContentData->width;
222 __pImageContentData->height = pImageContentData->height;
223 __pImageContentData->orientationType = pImageContentData->orientationType;
224 __pImageContentData->title = pImageContentData->title;
229 ImageContentInfo::_ImageContentData*
230 ImageContentInfo::GetImageContentData(void)
232 if (__pImageContentData == null)
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.");
237 return __pImageContentData;
241 ImageContentInfo::GetWidth(void) const
243 SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
245 return __pImageContentData->width;
249 ImageContentInfo::GetHeight(void) const
251 SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
253 return __pImageContentData->height;
257 ImageContentInfo::GetOrientation(void) const
259 SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
261 return __pImageContentData->orientationType;
265 ImageContentInfo::GetTitle(void) const
267 SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
269 if ((__pImageContentData->title).IsEmpty())
271 return String(L"Unknown");
274 return __pImageContentData->title;