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