[content] Add impl classes for ContentInfo
[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         , __orientationType(IMAGE_ORIENTATION_TYPE_UNKNOWN)
45         , __title(L"")
46 {
47
48 }
49
50 _ImageContentInfoImpl::~_ImageContentInfoImpl(void)
51 {
52
53 }
54
55 _ImageContentInfoImpl*
56 _ImageContentInfoImpl::GetInstance(ImageContentInfo& imageContentInfo)
57 {
58         return imageContentInfo.__pImageContentInfoImpl;
59 }
60
61 const _ImageContentInfoImpl*
62 _ImageContentInfoImpl::GetInstance(const ImageContentInfo& imageContentInfo)
63 {
64         return imageContentInfo.__pImageContentInfoImpl;
65 }
66
67 result
68 _ImageContentInfoImpl::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
69 {
70         result r = E_SUCCESS;
71         int contentLength = 0;
72         FileAttributes attribute;
73
74         // checks parameters
75         contentLength = contentPath.GetLength();
76         SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
77                         "The contentPath should start with /Media or /Storagecard/Media.");
78         SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
79                         "The file corresponding to contentPath could not be found.");
80
81         if (!thumbnailPath.IsEmpty())
82         {
83                 SysLog(NID_CNT,
84                                 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
85         }
86
87         if (setGps)
88         {
89                 SysLog(NID_CNT, "The setGps is not supported.");
90         }
91
92         SetContentPath(contentPath);
93         SetContentType(CONTENT_TYPE_IMAGE);
94
95         return r;
96 }
97
98 result
99 _ImageContentInfoImpl::Construct(const String* pContentPath)
100 {
101         result r = E_SUCCESS;
102
103         if (pContentPath != null)
104         {
105                 String contentPath(*pContentPath);
106
107                 if (!_AppInfo::IsOspCompat())
108                 {
109                         if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0)
110                                 || contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
111                         {
112                                 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
113                                 return E_INVALID_ARG;
114                         }
115                 }
116                 else
117                 {
118                         // prior to 2.0
119                         if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
120                         {
121                                 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
122                                 // it should be converted in 2.0.
123                                 r = contentPath.Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
124                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
125                         }
126                         else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
127                         {
128                                 r = contentPath.Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
129                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
130                         }
131                         else
132                         {
133                                 SysLogException(NID_CNT, E_INVALID_ARG,
134                                                 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
135                                 return E_INVALID_ARG;
136                         }
137                 }
138
139                 int length = contentPath.GetLength();
140                 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
141                                 "The length of pContentPath is 0.");
142                 SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
143                                 "The file corresponding to pContentPath could not be found.");
144
145                 SetContentPath(contentPath);
146                 SetContentType(CONTENT_TYPE_IMAGE);
147         }
148         else
149         {
150                 SetContentType(CONTENT_TYPE_IMAGE);
151         }
152
153         return r;
154 }
155
156 int
157 _ImageContentInfoImpl::GetWidth(void) const
158 {
159         return __width;
160 }
161
162 int
163 _ImageContentInfoImpl::GetHeight(void) const
164 {
165         return __height;
166 }
167
168 ImageOrientationType
169 _ImageContentInfoImpl::GetOrientation(void) const
170 {
171         return __orientationType;
172 }
173
174 String
175 _ImageContentInfoImpl::GetTitle(void) const
176 {
177         if (__title.IsEmpty())
178         {
179                 SysLog(NID_CNT, "Title is empty.");
180                 return L"Unknown";
181         }
182
183         return __title;
184 }
185
186 void
187 _ImageContentInfoImpl::SetWidth(int width)
188 {
189         __width = width;
190 }
191
192 void
193 _ImageContentInfoImpl::SetHeight(int height)
194 {
195         __height = height;
196 }
197
198 void
199 _ImageContentInfoImpl::SetTitle(const String& title)
200 {
201         __title = title;
202 }
203
204 void
205 _ImageContentInfoImpl::SetOrientation(const ImageOrientationType& orientationType)
206 {
207         __orientationType = orientationType;
208 }
209
210 }}