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