2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FCntContentDirectory.cpp
19 * @brief This is the implementation file for the %ContentDirectory class.
21 * This is the implementation file for %ContentDirectory class.
24 #include <FBaseSysLog.h>
25 #include <FCntContentDirectory.h>
26 #include <FBaseColIList.h>
28 #include <FCnt_ContentDirectoryImpl.h>
30 using namespace Tizen::Io;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
34 namespace Tizen { namespace Content
37 ContentDirectory::ContentDirectory(void)
43 ContentDirectory::~ContentDirectory(void)
53 ContentDirectory::Construct(ContentType type)
57 SysAssertf(__pImpl == null,
58 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
60 SysTryReturnResult(NID_CNT, type != CONTENT_TYPE_UNKNOWN && type != CONTENT_TYPE_ALL, E_INVALID_ARG, "Construct failed.");
62 _ContentDirectoryImpl* pContentDirectoryImpl = new (std::nothrow) _ContentDirectoryImpl();
63 SysTryReturnResult(NID_CNT, pContentDirectoryImpl != null, E_OUT_OF_MEMORY, "Construct failed.");
65 r = pContentDirectoryImpl->Construct(type);
66 SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
68 __pImpl = pContentDirectoryImpl;
73 if (pContentDirectoryImpl != NULL)
75 delete pContentDirectoryImpl;
76 pContentDirectoryImpl = null;
82 ContentDirectory::Construct(const Tizen::Base::Collection::IListT<ContentType>& contentTypeList)
85 ContentType type = CONTENT_TYPE_UNKNOWN;
86 int listCount = contentTypeList.GetCount();
88 SysAssertf(__pImpl == null,
89 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
91 SysTryReturnResult(NID_CNT, ((listCount > MIN_CONTENTTYPE_LIST_COUNT) && (listCount < MAX_CONTENTTYPE_LIST_COUNT)), E_INVALID_ARG, "Construct failed.");
93 for(int index = 0; index < listCount; index++)
95 contentTypeList.GetAt(index, type);
96 SysTryReturnResult(NID_CNT, type != CONTENT_TYPE_UNKNOWN && type != CONTENT_TYPE_ALL, E_INVALID_ARG, "Construct failed.");
99 _ContentDirectoryImpl* pContentDirectoryImpl = new (std::nothrow) _ContentDirectoryImpl();
100 SysTryReturnResult(NID_CNT, pContentDirectoryImpl != null, E_OUT_OF_MEMORY, "Construct failed.");
102 if (listCount == CONTENTTYPE_LIST_COUNT_ONE)
104 r = pContentDirectoryImpl->Construct(type);
105 SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
109 r = pContentDirectoryImpl->Construct(contentTypeList);
110 SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
113 __pImpl = pContentDirectoryImpl;
118 if (pContentDirectoryImpl != NULL)
120 delete pContentDirectoryImpl;
121 pContentDirectoryImpl = null;
127 ContentDirectory::GetContentDirectoryCount(void) const
131 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
133 return __pImpl->GetContentDirectoryCount();
137 ContentDirectory::GetContentDirectoryPathListN(Tizen::Base::SortOrder sortOrder) const
141 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
143 return __pImpl->GetContentDirectoryPathListN(sortOrder);
147 ContentDirectory::GetContentDirectoryItemCount(const Tizen::Base::String& contentDirectoryPath) const
151 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
153 SysTryReturn(NID_CNT, !contentDirectoryPath.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath is empty.");
155 SysTryReturn(NID_CNT, File::IsFileExist(contentDirectoryPath) == true, null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath doesn't exist.");
157 return __pImpl->GetContentDirectoryItemCount(contentDirectoryPath);
161 ContentDirectory::GetContentDirectoryItemListN(const Tizen::Base::String& contentDirectoryPath, int pageNo, int countPerPage,
162 const Tizen::Base::String& column, Tizen::Base::SortOrder sortOrder) const
166 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
168 if(sortOrder != SORT_ORDER_NONE)
170 SysTryReturn(NID_CNT, !column.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The column name is empty.");
173 SysTryReturn(NID_CNT, pageNo > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] pageNo <=0: GetContentDirectoryItemListN failed.");
175 SysTryReturn(NID_CNT, countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] countPerPage <=0: GetContentDirectoryItemListN failed.");
177 SysTryReturn(NID_CNT, !contentDirectoryPath.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath is empty.");
179 SysTryReturn(NID_CNT, File::IsFileExist(contentDirectoryPath) == true, null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath doesn't exist.");
181 return __pImpl->GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage, column, sortOrder);