2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FCntImageContentInfo.cpp
18 * @brief This is the implementation file for the %ImageContentInfo class.
20 * This file contains implementation of the %ImageContentInfo class.
23 #include <FBaseSysLog.h>
24 #include <FCntImageContentInfo.h>
26 #include <FIoDirectory.h>
27 #include <FSysEnvironment.h>
28 #include <FIo_FileImpl.h>
29 #include <FApp_AppInfo.h>
31 using namespace Tizen::Base;
32 using namespace Tizen::Io;
33 using namespace Tizen::Locations;
34 using namespace Tizen::App;
35 using namespace Tizen::System;
38 namespace Tizen { namespace Content
41 ImageContentInfo::ImageContentInfo(void)
43 , __pImageContentData(null)
49 ImageContentInfo::~ImageContentInfo(void)
51 if (__pImageContentData != null)
53 delete __pImageContentData;
54 __pImageContentData = null;
66 ImageContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
70 SysAssertf(__pImageContentData == null,
71 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
74 _ContentData contentData;
75 int contentLength = 0;
76 FileAttributes attribute;
79 contentLength = contentPath.GetLength();
80 SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
81 "The contentPath should start with /Media or /Storagecard/Media.");
82 SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
83 "The file corresponding to contentPath could not be found.");
85 if (!thumbnailPath.IsEmpty())
88 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
93 SysLog(NID_CNT, "The setGps is not supported.");
96 // Sets the content path
97 contentData.contentPath = contentPath;
99 // Sets the content type
100 contentData.contentType = CONTENT_TYPE_IMAGE;
102 // E_INVALID_ARG, E_OUT_OF_MEMORY
103 r = SetContentData(&contentData);
104 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
106 _ImageContentData* pImageContentData = new (nothrow) _ImageContentData();
107 SysTryReturnResult(NID_CNT, pImageContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
109 __pImageContentData = pImageContentData;
123 ImageContentInfo::Construct(const String* pContentPath)
127 SysAssertf(__pImageContentData == null,
128 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
130 result r = E_SUCCESS;
131 _ContentData contentData;
133 if (pContentPath != null)
135 if (!_AppInfo::IsOspCompat())
137 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
139 SysLogException(NID_CNT, E_INVALID_ARG,
140 "[E_INVALID_ARG] /Media/ and /Storagecard/Media/ are not supported from Tizen 2.0.");
141 return E_INVALID_ARG;
143 if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
144 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
146 SysLogException(NID_CNT, E_INVALID_ARG,
147 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
148 return E_INVALID_ARG;
154 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
156 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
157 // it should be converted in 2.0.
158 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
159 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
161 else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
163 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
164 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
168 SysLogException(NID_CNT, E_INVALID_ARG,
169 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
170 return E_INVALID_ARG;
174 int length = pContentPath->GetLength();
175 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
176 "The length of pContentPath is 0.");
177 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
178 "The file corresponding to pContentPath could not be found.");
180 // Sets the content path
181 contentData.contentPath = *pContentPath;
183 // Sets the content type
184 contentData.contentType = CONTENT_TYPE_IMAGE;
186 r = SetContentData(&contentData);
187 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
191 contentData.contentType = CONTENT_TYPE_IMAGE;
193 r = SetContentData(&contentData);
194 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
197 _ImageContentData* pImageContentData = new (nothrow) _ImageContentData();
198 SysTryReturnResult(NID_CNT, pImageContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
200 __pImageContentData = pImageContentData;
206 ImageContentInfo::SetImageContentData(const _ImageContentData* pImageContentData)
210 SysTryReturnResult(NID_CNT, pImageContentData != null, E_INVALID_ARG, "pImageContentData is null.");
212 // _ContentManagerImpl::GetContentInfoN makes an instance of this class. at that time it does not call Construct().
213 // Because __pImageContentData is created in Construct(), If there is no codes for allocation, crash will occur.
214 if (__pImageContentData == null)
216 __pImageContentData = new (nothrow) _ImageContentData;
217 SysTryReturnResult(NID_CNT, __pImageContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
220 __pImageContentData->width = pImageContentData->width;
221 __pImageContentData->height = pImageContentData->height;
222 __pImageContentData->orientationType = pImageContentData->orientationType;
223 __pImageContentData->title = pImageContentData->title;
228 ImageContentInfo::_ImageContentData*
229 ImageContentInfo::GetImageContentData(void)
231 if (__pImageContentData == null)
233 __pImageContentData = new (nothrow) ImageContentInfo::_ImageContentData;
234 SysTryReturn(NID_CNT, __pImageContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
236 return __pImageContentData;
240 ImageContentInfo::GetWidth(void) const
242 SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
244 return __pImageContentData->width;
248 ImageContentInfo::GetHeight(void) const
250 SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
252 return __pImageContentData->height;
256 ImageContentInfo::GetOrientation(void) const
258 SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
260 return __pImageContentData->orientationType;
264 ImageContentInfo::GetTitle(void) const
266 SysAssertf(__pImageContentData != null, "Not yet constructed. Construct() should be called before use.");
268 if ((__pImageContentData->title).IsEmpty())
270 return String(L"Unknown");
273 return __pImageContentData->title;