2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FCntContentDirectory.cpp
18 * @brief This is the implementation file for the %ContentDirectory class.
20 * This is the implementation file for %ContentDirectory class.
23 #include <FBaseSysLog.h>
24 #include <FCntContentDirectory.h>
25 #include <FBaseColIList.h>
27 #include <FCnt_ContentDirectoryImpl.h>
29 using namespace Tizen::Io;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
33 namespace Tizen { namespace Content
36 ContentDirectory::ContentDirectory(void)
42 ContentDirectory::~ContentDirectory(void)
52 ContentDirectory::Construct(ContentType type)
56 SysAssertf(__pImpl == null,
57 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
59 SysTryReturnResult(NID_CNT, type != CONTENT_TYPE_UNKNOWN && type != CONTENT_TYPE_ALL, E_INVALID_ARG, "Construct failed.");
61 _ContentDirectoryImpl* pContentDirectoryImpl = new (std::nothrow) _ContentDirectoryImpl();
62 SysTryReturnResult(NID_CNT, pContentDirectoryImpl != null, E_OUT_OF_MEMORY, "Construct failed.");
64 r = pContentDirectoryImpl->Construct(type);
65 SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
67 __pImpl = pContentDirectoryImpl;
72 if (pContentDirectoryImpl != NULL)
74 delete pContentDirectoryImpl;
75 pContentDirectoryImpl = null;
81 ContentDirectory::Construct(const Tizen::Base::Collection::IListT<ContentType>& contentTypeList)
84 ContentType type = CONTENT_TYPE_UNKNOWN;
85 int listCount = contentTypeList.GetCount();
87 SysAssertf(__pImpl == null,
88 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
90 SysTryReturnResult(NID_CNT, ((listCount > MIN_CONTENTTYPE_LIST_COUNT) && (listCount < MAX_CONTENTTYPE_LIST_COUNT)), E_INVALID_ARG, "Construct failed.");
92 for(int index = 0; index < listCount; index++)
94 contentTypeList.GetAt(index, type);
95 SysTryReturnResult(NID_CNT, type != CONTENT_TYPE_UNKNOWN && type != CONTENT_TYPE_ALL, E_INVALID_ARG, "Construct failed.");
98 _ContentDirectoryImpl* pContentDirectoryImpl = new (std::nothrow) _ContentDirectoryImpl();
99 SysTryReturnResult(NID_CNT, pContentDirectoryImpl != null, E_OUT_OF_MEMORY, "Construct failed.");
101 if (listCount == CONTENTTYPE_LIST_COUNT_ONE)
103 r = pContentDirectoryImpl->Construct(type);
104 SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
108 r = pContentDirectoryImpl->Construct(contentTypeList);
109 SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
112 __pImpl = pContentDirectoryImpl;
117 if (pContentDirectoryImpl != NULL)
119 delete pContentDirectoryImpl;
120 pContentDirectoryImpl = null;
126 ContentDirectory::GetContentDirectoryCount(void) const
130 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
132 return __pImpl->GetContentDirectoryCount();
136 ContentDirectory::GetContentDirectoryPathListN(Tizen::Base::SortOrder sortOrder) const
140 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
142 return __pImpl->GetContentDirectoryPathListN(sortOrder);
146 ContentDirectory::GetContentDirectoryItemCount(const Tizen::Base::String& contentDirectoryPath) const
150 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
152 SysTryReturn(NID_CNT, !contentDirectoryPath.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath is empty.");
154 SysTryReturn(NID_CNT, File::IsFileExist(contentDirectoryPath) == true, null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath doesn't exist.");
156 return __pImpl->GetContentDirectoryItemCount(contentDirectoryPath);
160 ContentDirectory::GetContentDirectoryItemListN(const Tizen::Base::String& contentDirectoryPath, int pageNo, int countPerPage,
161 const Tizen::Base::String& column, Tizen::Base::SortOrder sortOrder) const
165 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
167 if(sortOrder != SORT_ORDER_NONE)
169 SysTryReturn(NID_CNT, !column.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The column name is empty.");
172 SysTryReturn(NID_CNT, pageNo > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] pageNo <=0: GetContentDirectoryItemListN failed.");
174 SysTryReturn(NID_CNT, countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] countPerPage <=0: GetContentDirectoryItemListN failed.");
176 SysTryReturn(NID_CNT, !contentDirectoryPath.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath is empty.");
178 SysTryReturn(NID_CNT, File::IsFileExist(contentDirectoryPath) == true, null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath doesn't exist.");
180 return __pImpl->GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage, column, sortOrder);