1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <sal/config.h>
27 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
28 #include <salhelper/thread.hxx>
29 #include <ucbhelper/content.hxx>
30 #include <rtl/ustring.hxx>
31 #include <tools/datetime.hxx>
40 struct SortingData_Impl
43 OUString maFilename
; // only filename in upper case - for compare purposes
44 OUString maTitle
; // -> be careful when changing maTitle to update maFilename only when new
45 OUString maLowerTitle
;
51 OUString maDisplayName
;
52 OUString maDisplaySize
;
53 OUString maDisplayDate
;
64 inline SortingData_Impl();
65 inline const OUString
& GetTitle() const;
66 inline const OUString
& GetLowerTitle() const;
67 inline const OUString
& GetFileName() const;
68 inline void SetNewTitle( const OUString
& rNewTitle
); // new maTitle is set -> maFilename is set to same!
71 inline void SetTitles( const OUString
& rNewTitle
);
74 inline SortingData_Impl::SortingData_Impl() :
75 maModDate ( DateTime::EMPTY
),
80 mbIsRemoveable ( false ),
82 mbIsCompactDisc ( false )
86 inline const OUString
& SortingData_Impl::GetTitle() const
91 inline const OUString
& SortingData_Impl::GetLowerTitle() const
96 inline const OUString
& SortingData_Impl::GetFileName() const
101 inline void SortingData_Impl::SetNewTitle( const OUString
& rNewTitle
)
103 SetTitles( rNewTitle
);
104 maFilename
= rNewTitle
.toAsciiUpperCase();
107 inline void SortingData_Impl::SetTitles( const OUString
& rNewTitle
)
110 maLowerTitle
= rNewTitle
.toAsciiLowerCase();
114 //= EnumerationResult
116 enum class EnumerationResult
118 SUCCESS
, /// the enumeration was successful
119 ERROR
, /// the enumeration was unsuccessful
125 struct FolderDescriptor
127 /** a content object describing the folder. Can be <NULL/>, in this case <member>sURL</member>
130 ::ucbhelper::Content aContent
;
131 /** the URL of a folder. Will be ignored if <member>aContent</member> is not <NULL/>.
135 FolderDescriptor() { }
137 explicit FolderDescriptor( OUString _aURL
)
138 :sURL(std::move( _aURL
))
144 //= IEnumerationResultHandler
146 class IEnumerationResultHandler
149 virtual void enumerationDone( EnumerationResult _eResult
) = 0;
152 ~IEnumerationResultHandler() {}
156 //= FileViewContentEnumerator
158 class FileViewContentEnumerator
: public salhelper::Thread
161 typedef ::std::vector
< std::unique_ptr
<SortingData_Impl
> > ContentData
;
164 ContentData
& m_rContent
;
165 ::osl::Mutex
& m_rContentMutex
;
167 mutable std::mutex m_aMutex
;
169 FolderDescriptor m_aFolder
;
170 css::uno::Reference
< css::ucb::XCommandEnvironment
>
172 IEnumerationResultHandler
* m_pResultHandler
;
175 css::uno::Sequence
< OUString
> m_rDenyList
;
177 bool URLOnDenyList ( std::u16string_view sRealURL
);
180 /** constructs an enumerator instance
182 @param _rContentToFill
183 the structure which is to be filled with the found content
184 @param _rContentMutex
185 the mutex which protects the access to <arg>_rContentToFill</arg>
187 an instance which should be used to translate content titles. May be <NULL/>
189 FileViewContentEnumerator(
190 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& _rxCommandEnv
,
191 ContentData
& _rContentToFill
,
192 ::osl::Mutex
& _rContentMutex
195 /** enumerates the content of a given folder
198 the folder whose content is to be enumerated
200 a filter to apply to the found contents
201 @param _pResultHandler
202 an instance which should handle the results of the enumeration
204 void enumerateFolderContent(
205 const FolderDescriptor
& _rFolder
,
206 IEnumerationResultHandler
* _pResultHandler
209 /** enumerates the content of a given folder synchronously
211 EnumerationResult
enumerateFolderContentSync(
212 const FolderDescriptor
& _rFolder
,
213 const css::uno::Sequence
< OUString
>& rDenyList
216 /** cancels the running operation.
218 Note that "cancel" may mean that the operation is running, but its result
219 is simply disregarded later on.
224 virtual ~FileViewContentEnumerator() override
;
227 EnumerationResult
enumerateFolderContent();
229 // Thread overridables
230 virtual void execute() override
;
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */