Fix : Search APIs don't return exception despite the content in DB doesn't match...
[platform/framework/native/content.git] / src / FCnt_AudioContentInfoImpl.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 /**
18  * @file                FCnt_AudioContentInfoImpl.cpp
19  * @brief               This is the implementation file for the %_AudioContentInfoImpl class.
20  *
21  * This file contains implementation of the %_AudioContentInfoImpl class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FIoFile.h>
26 #include <FIoDirectory.h>
27 #include <FSysEnvironment.h>
28 #include <FIo_FileImpl.h>
29 #include <FApp_AppInfo.h>
30 #include "FCnt_AudioContentInfoImpl.h"
31
32 using namespace std;
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Io;
36 using namespace Tizen::Locations;
37 using namespace Tizen::System;
38
39 namespace Tizen { namespace Content
40 {
41
42 _AudioContentInfoImpl::_AudioContentInfoImpl(void)
43         : __bitrate(0)
44         , __releaseYear(0)
45         , __duration(0)
46         , __title(L"")
47         , __albumName(L"")
48         , __artist(L"")
49         , __composer(L"")
50         , __genre(L"")
51         , __copyright(L"")
52         , __trackInfo(L"")
53 {
54
55 }
56
57 _AudioContentInfoImpl::~_AudioContentInfoImpl(void)
58 {
59
60 }
61
62 _AudioContentInfoImpl*
63 _AudioContentInfoImpl::GetInstance(AudioContentInfo& audioContentInfo)
64 {
65         return audioContentInfo.__pAudioContentInfoImpl;
66 }
67
68 const _AudioContentInfoImpl*
69 _AudioContentInfoImpl::GetInstance(const AudioContentInfo& audioContentInfo)
70 {
71         return audioContentInfo.__pAudioContentInfoImpl;
72 }
73
74 result
75 _AudioContentInfoImpl::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
76 {
77         result r = E_SUCCESS;
78         String tempPath(contentPath);
79
80         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
81         {
82                 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
83                 {
84                         // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
85                         // it should be converted in 2.0.
86                         r = tempPath.Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
87                         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
88                 }
89                 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
90                 {
91                         r = tempPath.Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
92                         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
93                 }
94                 else
95                 {
96                         SysLogException(NID_CNT, E_INVALID_ARG,
97                                         "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
98                         return E_INVALID_ARG;
99                 }
100         }
101
102         // checks parameters
103         SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
104                         "The contentPath should start with /Media or /Storagecard/Media.");
105         SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
106                         "The file corresponding to contentPath could not be found.");
107
108         if (!thumbnailPath.IsEmpty())
109         {
110                 SysLog(NID_CNT,
111                                 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
112         }
113
114         if (setGps)
115         {
116                 SysLog(NID_CNT, "The setGps is not supported.");
117         }
118
119         SetContentPath(tempPath);
120         SetContentType(CONTENT_TYPE_AUDIO);
121
122         return r;
123 }
124
125 result
126 _AudioContentInfoImpl::Construct(const String* pContentPath)
127 {
128         result r = E_SUCCESS;
129
130         if (pContentPath != null)
131         {
132                 String contentPath(*pContentPath);
133
134                 if (!_AppInfo::IsOspCompat())
135                 {
136                         if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0)
137                                 || contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
138                         {
139                                 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
140                                 return E_INVALID_ARG;
141                         }
142                 }
143                 else
144                 {
145                         // prior to 2.0
146                         if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
147                         {
148                                 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
149                                 // it should be converted in 2.0.
150                                 r = contentPath.Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
151                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
152                         }
153                         else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
154                         {
155                                 r = contentPath.Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
156                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
157                         }
158                         else
159                         {
160                                 SysLogException(NID_CNT, E_INVALID_ARG,
161                                                 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
162                                 return E_INVALID_ARG;
163                         }
164                 }
165
166                 int length = contentPath.GetLength();
167                 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
168                                 "The length of pContentPath is 0.");
169                 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
170                                 "The file corresponding to pContentPath could not be found.");
171
172                 SetContentPath(contentPath);
173                 SetContentType(CONTENT_TYPE_AUDIO);
174         }
175         else
176         {
177                 SetContentType(CONTENT_TYPE_AUDIO);
178         }
179
180         return r;
181 }
182
183 String
184 _AudioContentInfoImpl::GetGenre(void) const
185 {
186         if (__genre.IsEmpty())
187         {
188                 SysLog(NID_CNT, "Genre is empty.");
189                 return String(L"Unknown");
190         }
191
192         return __genre;
193 }
194
195 String
196 _AudioContentInfoImpl::GetArtist(void) const
197 {
198         if (__artist.IsEmpty())
199         {
200                 SysLog(NID_CNT, "Artist is empty.");
201                 return String(L"Unknown");
202         }
203
204         return __artist;
205 }
206
207 String
208 _AudioContentInfoImpl::GetComposer(void) const
209 {
210         if (__composer.IsEmpty())
211         {
212                 SysLog(NID_CNT, "Composer is empty.");
213                 return String(L"Unknown");
214         }
215
216         return __composer;
217 }
218
219 String
220 _AudioContentInfoImpl::GetAlbumName(void) const
221 {
222         if (__albumName.IsEmpty())
223         {
224                 SysLog(NID_CNT, "AlbumName is empty.");
225                 return String(L"Unknown");
226         }
227
228         return __albumName;
229 }
230
231 int
232 _AudioContentInfoImpl::GetReleaseYear(void) const
233 {
234         return __releaseYear;
235 }
236
237 int
238 _AudioContentInfoImpl::GetBitrate(void) const
239 {
240         return __bitrate;
241 }
242
243 String
244 _AudioContentInfoImpl::GetTitle(void) const
245 {
246         if (__title.IsEmpty())
247         {
248                 SysLog(NID_CNT, "Title is empty.");
249                 return String(L"Unknown");
250         }
251
252         return __title;
253 }
254
255 String
256 _AudioContentInfoImpl::GetCopyright(void) const
257 {
258         if (__copyright.IsEmpty())
259         {
260                 SysLog(NID_CNT, "Copyright is empty.");
261                 return String(L"Unknown");
262         }
263
264         return __copyright;
265 }
266
267 String
268 _AudioContentInfoImpl::GetTrackInfo(void) const
269 {
270         if (__trackInfo.IsEmpty())
271         {
272                 SysLog(NID_CNT, "TrackInfo is empty.");
273                 return String(L"Unknown");
274         }
275
276         return __trackInfo;
277 }
278
279 long
280 _AudioContentInfoImpl::GetDuration(void) const
281 {
282         return __duration;
283 }
284
285 void
286 _AudioContentInfoImpl::SetGenre(const Tizen::Base::String& genre)
287 {
288         __genre = genre;
289 }
290
291 void
292 _AudioContentInfoImpl::SetArtist(const Tizen::Base::String& artist)
293 {
294         __artist = artist;
295 }
296
297 void
298 _AudioContentInfoImpl::SetComposer(const Tizen::Base::String& composer)
299 {
300         __composer = composer;
301 }
302
303 void
304 _AudioContentInfoImpl::SetAlbumName(const Tizen::Base::String& albumName)
305 {
306         __albumName = albumName;
307 }
308
309 void
310 _AudioContentInfoImpl::SetReleaseYear(int releaseYear)
311 {
312         __releaseYear = releaseYear;
313 }
314
315 void
316 _AudioContentInfoImpl::SetBitrate(int bitrate)
317 {
318         __bitrate = bitrate;
319 }
320
321 void
322 _AudioContentInfoImpl::SetTitle(const Tizen::Base::String& title)
323 {
324         __title = title;
325 }
326
327 void
328 _AudioContentInfoImpl::SetCopyright(const Tizen::Base::String& copyright)
329 {
330         __copyright = copyright;
331 }
332
333 void
334 _AudioContentInfoImpl::SetTrackInfo(const Tizen::Base::String& trackInfo)
335 {
336         __trackInfo = trackInfo;
337 }
338
339 void
340 _AudioContentInfoImpl::SetDuration(long duration)
341 {
342         __duration = duration;
343 }
344
345 }}