ScriptForge (SF_Calc new Intersect() method
[LibreOffice.git] / fpicker / source / office / contentenumeration.hxx
blobd15db4d7a55ff91f77c47e5323b67467df4eb7f1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <memory>
25 #include <mutex>
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>
32 #include <utility>
34 namespace svt
38 //= SortingData_Impl
40 struct SortingData_Impl
42 private:
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;
48 public:
49 OUString maType;
50 OUString maTargetURL;
51 OUString maDisplayName;
52 OUString maDisplaySize;
53 OUString maDisplayDate;
54 DateTime maModDate;
55 OUString maImage;
56 sal_Int64 maSize;
57 bool mbIsFolder;
58 bool mbIsVolume;
59 bool mbIsRemote;
60 bool mbIsRemoveable;
61 bool mbIsFloppy;
62 bool mbIsCompactDisc;
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!
70 private:
71 inline void SetTitles( const OUString& rNewTitle );
74 inline SortingData_Impl::SortingData_Impl() :
75 maModDate ( DateTime::EMPTY ),
76 maSize ( 0 ),
77 mbIsFolder ( false ),
78 mbIsVolume ( false ),
79 mbIsRemote ( false ),
80 mbIsRemoveable ( false ),
81 mbIsFloppy ( false ),
82 mbIsCompactDisc ( false )
86 inline const OUString& SortingData_Impl::GetTitle() const
88 return maTitle;
91 inline const OUString& SortingData_Impl::GetLowerTitle() const
93 return maLowerTitle;
96 inline const OUString& SortingData_Impl::GetFileName() const
98 return maFilename;
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 )
109 maTitle = rNewTitle;
110 maLowerTitle = rNewTitle.toAsciiLowerCase();
114 //= EnumerationResult
116 enum class EnumerationResult
118 SUCCESS, /// the enumeration was successful
119 ERROR, /// the enumeration was unsuccessful
123 //= FolderDescriptor
125 struct FolderDescriptor
127 /** a content object describing the folder. Can be <NULL/>, in this case <member>sURL</member>
128 is relevant.
130 ::ucbhelper::Content aContent;
131 /** the URL of a folder. Will be ignored if <member>aContent</member> is not <NULL/>.
133 OUString sURL;
135 FolderDescriptor() { }
137 explicit FolderDescriptor( OUString _aURL )
138 :sURL(std::move( _aURL ))
144 //= IEnumerationResultHandler
146 class IEnumerationResultHandler
148 public:
149 virtual void enumerationDone( EnumerationResult _eResult ) = 0;
151 protected:
152 ~IEnumerationResultHandler() {}
156 //= FileViewContentEnumerator
158 class FileViewContentEnumerator: public salhelper::Thread
160 public:
161 typedef ::std::vector< std::unique_ptr<SortingData_Impl> > ContentData;
163 private:
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 >
171 m_xCommandEnv;
172 IEnumerationResultHandler* m_pResultHandler;
173 bool m_bCancelled;
175 css::uno::Sequence< OUString > m_rDenyList;
177 bool URLOnDenyList ( std::u16string_view sRealURL );
179 public:
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>
186 @param _pTranslator
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
197 @param _rFolder
198 the folder whose content is to be enumerated
199 @param _pFilter
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.
221 void cancel();
223 protected:
224 virtual ~FileViewContentEnumerator() override;
226 private:
227 EnumerationResult enumerateFolderContent();
229 // Thread overridables
230 virtual void execute() override;
235 } // namespace svt
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */