[content] Fix a bug of scan listener
[platform/framework/native/content.git] / src / FCntContentDirectory.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                FCntContentDirectory.cpp
19  * @brief               This is the implementation file for the %ContentDirectory class.
20  *
21  * This is the implementation file for %ContentDirectory class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FCntContentDirectory.h>
26 #include <FBaseColIList.h>
27 #include <FIoFile.h>
28 #include <FCnt_ContentDirectoryImpl.h>
29
30 using namespace Tizen::Io;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33
34 namespace Tizen { namespace Content
35 {
36
37 ContentDirectory::ContentDirectory(void)
38         : Object()
39         , __pImpl(null)
40 {
41 }
42
43 ContentDirectory::~ContentDirectory(void)
44 {
45         if (__pImpl != null)
46         {
47                 delete __pImpl;
48                 __pImpl = null;
49         }
50 }
51
52 result
53 ContentDirectory::Construct(ContentType type)
54 {
55         result r = E_SUCCESS;
56
57         SysAssertf(__pImpl == null,
58                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
59
60         SysTryReturnResult(NID_CNT, type != CONTENT_TYPE_UNKNOWN && type != CONTENT_TYPE_ALL, E_INVALID_ARG, "Construct failed.");
61
62         _ContentDirectoryImpl* pContentDirectoryImpl = new (std::nothrow) _ContentDirectoryImpl();
63         SysTryReturnResult(NID_CNT, pContentDirectoryImpl != null, E_OUT_OF_MEMORY, "Construct failed.");
64
65         r = pContentDirectoryImpl->Construct(type);
66         SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
67
68         __pImpl = pContentDirectoryImpl;
69
70         return E_SUCCESS;;
71
72 CATCH:
73         if (pContentDirectoryImpl != NULL)
74         {
75                 delete pContentDirectoryImpl;
76                 pContentDirectoryImpl = null;
77         }
78         return r;
79 }
80
81 result
82 ContentDirectory::Construct(const Tizen::Base::Collection::IListT<ContentType>& contentTypeList)
83 {
84         result r = E_SUCCESS;
85         ContentType type = CONTENT_TYPE_UNKNOWN;
86         int listCount = contentTypeList.GetCount();
87
88         SysAssertf(__pImpl == null,
89                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
90
91         SysTryReturnResult(NID_CNT, ((listCount > MIN_CONTENTTYPE_LIST_COUNT) && (listCount < MAX_CONTENTTYPE_LIST_COUNT)), E_INVALID_ARG, "Construct failed.");
92
93         for(int index = 0; index < listCount; index++)
94         {
95                 contentTypeList.GetAt(index, type);
96                 SysTryReturnResult(NID_CNT, type != CONTENT_TYPE_UNKNOWN && type != CONTENT_TYPE_ALL, E_INVALID_ARG, "Construct failed.");
97         }
98
99         _ContentDirectoryImpl* pContentDirectoryImpl = new (std::nothrow) _ContentDirectoryImpl();
100         SysTryReturnResult(NID_CNT, pContentDirectoryImpl != null, E_OUT_OF_MEMORY, "Construct failed.");
101
102         if (listCount == CONTENTTYPE_LIST_COUNT_ONE)
103         {
104                 r = pContentDirectoryImpl->Construct(type);
105                 SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
106         }
107         else
108         {
109                 r = pContentDirectoryImpl->Construct(contentTypeList);
110                 SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
111         }
112
113         __pImpl = pContentDirectoryImpl;
114
115         return E_SUCCESS;;
116
117 CATCH:
118         if (pContentDirectoryImpl != NULL)
119         {
120                 delete pContentDirectoryImpl;
121                 pContentDirectoryImpl = null;
122         }
123         return r;
124 }
125
126 int
127 ContentDirectory::GetContentDirectoryCount(void) const
128 {
129         ClearLastResult();
130
131         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
132
133         return __pImpl->GetContentDirectoryCount();
134 }
135
136 IList*
137 ContentDirectory::GetContentDirectoryPathListN(Tizen::Base::SortOrder sortOrder) const
138 {
139         ClearLastResult();
140
141         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
142
143         return __pImpl->GetContentDirectoryPathListN(sortOrder);
144 }
145
146 int
147 ContentDirectory::GetContentDirectoryItemCount(const Tizen::Base::String& contentDirectoryPath) const
148 {
149         ClearLastResult();
150
151         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
152
153         SysTryReturn(NID_CNT, !contentDirectoryPath.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath is empty.");
154
155         SysTryReturn(NID_CNT, File::IsFileExist(contentDirectoryPath) == true, null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath doesn't exist.");
156
157         return __pImpl->GetContentDirectoryItemCount(contentDirectoryPath);
158 }
159
160 IList*
161 ContentDirectory::GetContentDirectoryItemListN(const Tizen::Base::String& contentDirectoryPath, int pageNo, int countPerPage,
162                                                     const Tizen::Base::String& column, Tizen::Base::SortOrder sortOrder) const
163 {
164         ClearLastResult();
165
166         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
167
168         if(sortOrder != SORT_ORDER_NONE)
169         {
170                 SysTryReturn(NID_CNT, !column.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The column name is empty.");
171         }
172
173         SysTryReturn(NID_CNT, pageNo > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] pageNo <=0: GetContentDirectoryItemListN failed.");
174
175         SysTryReturn(NID_CNT, countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] countPerPage <=0: GetContentDirectoryItemListN failed.");
176
177         SysTryReturn(NID_CNT, !contentDirectoryPath.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath is empty.");
178
179         SysTryReturn(NID_CNT, File::IsFileExist(contentDirectoryPath) == true, null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath doesn't exist.");
180
181         return __pImpl->GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage, column, sortOrder);
182 }
183
184 }}