[content] Fix bug on ContentDirectory
[platform/framework/native/content.git] / src / FCntOtherContentInfo.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17 /**
18  * @file                FCntOtherContentInfo.cpp
19  * @brief               This is the implementation file for the %OtherContentInfo class.
20  *
21  * This file contains implementation of the %OtherContentInfo class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FCntOtherContentInfo.h>
26 #include <FIoFile.h>
27 #include <FIoDirectory.h>
28 #include <FSysEnvironment.h>
29 #include <FIo_FileImpl.h>
30 #include <FApp_AppInfo.h>
31
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;
37
38 namespace Tizen { namespace Content
39 {
40
41 OtherContentInfo::OtherContentInfo(void)
42         : ContentInfo()
43         , __isCreated(false)
44         , __pImpl(null)
45 {
46
47 }
48
49 OtherContentInfo::~OtherContentInfo(void)
50 {
51
52 }
53
54 /**
55  * E_SUCCESS
56  * E_FILE_NOT_FOUND
57  * E_INVALID_ARG
58  * E_OUT_OF_MEMORY
59  * - E_IO
60   */
61 result
62 OtherContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
63 {
64         ClearLastResult();
65
66         SysAssertf(!__isCreated, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
67
68         result r = E_SUCCESS;
69         _ContentData contentData;
70         int contentLength = 0;
71         FileAttributes attribute;
72
73         // checks parameters
74         contentLength = contentPath.GetLength();
75         SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
76                         "The contentPath should start with /Media or /Storagecard/Media.");
77         SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
78                         "The file corresponding to contentPath could not be found.");
79
80         if (thumbnailPath.GetLength() > 0)
81         {
82                 SysLog(NID_CNT, "The thumbnailPath is not supported.");
83         }
84
85         if (setGps)
86         {
87                 SysLog(NID_CNT, "The setGps is not supported.");
88         }
89
90         // Sets the content path
91         contentData.contentPath = contentPath;
92
93         // Sets the content type
94         contentData.contentType = CONTENT_TYPE_OTHER;
95
96         // E_INVALID_ARG, E_OUT_OF_MEMORY
97         r = SetContentData(&contentData);
98         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
99
100         __isCreated = true;
101         return r;
102 }
103
104 /**
105  * E_SUCCESS
106  * E_FILE_NOT_FOUND
107  * E_INVALID_ARG
108  * E_OUT_OF_MEMORY
109  * - E_IO
110  * - E_SYSTEM
111  */
112 result
113 OtherContentInfo::Construct(const String* pContentPath)
114 {
115         ClearLastResult();
116
117         result r = E_SUCCESS;
118         _ContentData contentData;
119
120         SysAssertf(!__isCreated,
121                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
122
123         if (pContentPath != null)
124         {
125                 if (!_AppInfo::IsOspCompat())
126                 {
127                         if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
128                         {
129                                 SysLogException(NID_CNT, E_INVALID_ARG,
130                                                 "[E_INVALID_ARG] /Media/ and /Storagecard/Media/ are not supported from Tizen 2.0.");
131                                 return E_INVALID_ARG;
132                         }
133                         if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
134                                 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
135                         {
136                                 SysLogException(NID_CNT, E_INVALID_ARG,
137                                                 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
138                                 return E_INVALID_ARG;
139                         }
140                 }
141                 else
142                 {
143                         // prior to 2.0
144                         if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
145                         {
146                                 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
147                                 // it should be converted in 2.0.
148                                 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
149                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
150                         }
151                         else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
152                         {
153                                 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
154                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
155                         }
156                         else
157                         {
158                                 SysLogException(NID_CNT, E_INVALID_ARG,
159                                                 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
160                                 return E_INVALID_ARG;
161                         }
162                 }
163
164                 int length = pContentPath->GetLength();
165                 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG, "The length of pContentPath is 0.");
166                 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND, "The file corresponding to pContentPath could not be found.");
167
168                 // Sets the content path
169                 contentData.contentPath = *pContentPath;
170
171                 // Sets the content type
172                 contentData.contentType = CONTENT_TYPE_OTHER;
173
174                 r = SetContentData(&contentData);
175                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
176         }
177         else
178         {
179                 contentData.contentType = CONTENT_TYPE_OTHER;
180
181                 r = SetContentData(&contentData);
182                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
183         }
184
185         __isCreated = true;
186         return r;
187 }
188
189 }}