Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SVTOOLS_SOURCE_CONTNR_CONTENTENUMERATION_HXX
21 : #define INCLUDED_SVTOOLS_SOURCE_CONTNR_CONTENTENUMERATION_HXX
22 :
23 : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
24 : #include <com/sun/star/document/XDocumentProperties.hpp>
25 : #include <salhelper/thread.hxx>
26 : #include <ucbhelper/content.hxx>
27 : #include <rtl/ustring.hxx>
28 : #include <tools/datetime.hxx>
29 : #include <vcl/image.hxx>
30 :
31 :
32 : namespace svt
33 : {
34 :
35 :
36 :
37 : //= SortingData_Impl
38 :
39 0 : struct SortingData_Impl
40 : {
41 : private:
42 : OUString maFilename; // only filename in upper case - for compare purposes
43 : OUString maTitle; // -> be careful when changing maTitle to update maFilename only when new
44 : OUString maLowerTitle;
45 :
46 :
47 : public:
48 : OUString maType;
49 : OUString maTargetURL;
50 : OUString maImageURL;
51 : OUString maDisplayText;
52 : DateTime maModDate;
53 : Image maImage;
54 : sal_Int64 maSize;
55 : bool mbIsFolder;
56 : bool mbIsVolume;
57 : bool mbIsRemote;
58 : bool mbIsRemoveable;
59 : bool mbIsFloppy;
60 : bool mbIsCompactDisc;
61 :
62 : inline SortingData_Impl();
63 : inline const OUString& GetTitle() const;
64 : inline const OUString& GetLowerTitle() const;
65 : inline const OUString& GetFileName() const;
66 : inline void SetNewTitle( const OUString& rNewTitle ); // new maTitle is set -> maFilename is set to same!
67 : inline void ChangeTitle( const OUString& rChangedTitle ); // maTitle is changed, maFilename is unchanged!
68 :
69 : private:
70 : inline void SetTitles( const OUString& rNewTitle );
71 : };
72 :
73 0 : inline SortingData_Impl::SortingData_Impl() :
74 : maModDate ( DateTime::EMPTY ),
75 : maSize ( 0 ),
76 : mbIsFolder ( false ),
77 : mbIsVolume ( false ),
78 : mbIsRemote ( false ),
79 : mbIsRemoveable ( false ),
80 : mbIsFloppy ( false ),
81 0 : mbIsCompactDisc ( false )
82 : {
83 0 : }
84 :
85 0 : inline const OUString& SortingData_Impl::GetTitle() const
86 : {
87 0 : return maTitle;
88 : }
89 :
90 0 : inline const OUString& SortingData_Impl::GetLowerTitle() const
91 : {
92 0 : return maLowerTitle;
93 : }
94 :
95 0 : inline const OUString& SortingData_Impl::GetFileName() const
96 : {
97 0 : return maFilename;
98 : }
99 :
100 0 : inline void SortingData_Impl::SetNewTitle( const OUString& rNewTitle )
101 : {
102 0 : SetTitles( rNewTitle );
103 0 : maFilename = rNewTitle.toAsciiUpperCase();
104 0 : }
105 :
106 0 : inline void SortingData_Impl::ChangeTitle( const OUString& rChangedTitle )
107 : {
108 0 : SetTitles( rChangedTitle );
109 0 : }
110 :
111 0 : inline void SortingData_Impl::SetTitles( const OUString& rNewTitle )
112 : {
113 0 : maTitle = rNewTitle;
114 0 : maLowerTitle = rNewTitle.toAsciiLowerCase();
115 0 : }
116 :
117 :
118 : //= IContentTitleTranslation
119 :
120 0 : class IContentTitleTranslation
121 : {
122 : public:
123 : virtual bool GetTranslation( const OUString& _rOriginalName, OUString& _rTranslatedName ) const = 0;
124 :
125 : protected:
126 0 : ~IContentTitleTranslation() {}
127 : };
128 :
129 :
130 : //= EnumerationResult
131 :
132 : enum EnumerationResult
133 : {
134 : SUCCESS, /// the enumeration was successful
135 : ERROR, /// the enumeration was unsuccessful
136 : RUNNING /// the enumeration is still running, and the maximum wait time has passed
137 : };
138 :
139 :
140 : //= FolderDescriptor
141 :
142 0 : struct FolderDescriptor
143 : {
144 : /** a content object describing the folder. Can be <NULL/>, in this case <member>sURL</member>
145 : is relevant.
146 : */
147 : ::ucbhelper::Content aContent;
148 : /** the URL of a folder. Will be ignored if <member>aContent</member> is not <NULL/>.
149 : */
150 : OUString sURL;
151 :
152 0 : FolderDescriptor() { }
153 :
154 0 : explicit FolderDescriptor( const ::ucbhelper::Content& _rContent )
155 0 : :aContent( _rContent )
156 : {
157 0 : }
158 :
159 0 : explicit FolderDescriptor( const OUString& _rURL )
160 0 : :sURL( _rURL )
161 : {
162 0 : }
163 : };
164 :
165 :
166 : //= IEnumerationResultHandler
167 :
168 0 : class IEnumerationResultHandler
169 : {
170 : public:
171 : virtual void enumerationDone( EnumerationResult _eResult ) = 0;
172 :
173 : protected:
174 0 : ~IEnumerationResultHandler() {}
175 : };
176 :
177 :
178 : //= FileViewContentEnumerator
179 :
180 : class FileViewContentEnumerator: public salhelper::Thread
181 : {
182 : public:
183 : typedef ::std::vector< SortingData_Impl* > ContentData;
184 :
185 : private:
186 : ContentData& m_rContent;
187 : ::osl::Mutex& m_rContentMutex;
188 :
189 : mutable ::osl::Mutex m_aMutex;
190 :
191 : FolderDescriptor m_aFolder;
192 : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >
193 : m_xCommandEnv;
194 : const IContentTitleTranslation* m_pTranslator;
195 : IEnumerationResultHandler* m_pResultHandler;
196 : bool m_bCancelled;
197 :
198 : mutable ::com::sun::star::uno::Reference<
199 : ::com::sun::star::document::XDocumentProperties>
200 : m_xDocProps;
201 :
202 : ::com::sun::star::uno::Sequence< OUString > m_rBlackList;
203 :
204 : bool URLOnBlackList ( const OUString& sRealURL );
205 :
206 : public:
207 : /** constructs an enumerator instance
208 :
209 : @param _rContentToFill
210 : the structure which is to be filled with the found content
211 : @param _rContentMutex
212 : the mutex which protects the access to <arg>_rContentToFill</arg>
213 : @param _pTranslator
214 : an instance which should be used to translate content titles. May be <NULL/>
215 : */
216 : FileViewContentEnumerator(
217 : const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& _rxCommandEnv,
218 : ContentData& _rContentToFill,
219 : ::osl::Mutex& _rContentMutex,
220 : const IContentTitleTranslation* _pTranslator
221 : );
222 :
223 : /** enumerates the content of a given folder
224 :
225 : @param _rFolder
226 : the folder whose content is to be enumerated
227 : @param _pFilter
228 : a filter to apply to the found contents
229 : @param _pResultHandler
230 : an instance which should handle the results of the enumeration
231 : */
232 : void enumerateFolderContent(
233 : const FolderDescriptor& _rFolder,
234 : IEnumerationResultHandler* _pResultHandler
235 : );
236 :
237 : /** enumerates the content of a given folder synchronously
238 : */
239 : EnumerationResult enumerateFolderContentSync(
240 : const FolderDescriptor& _rFolder,
241 : const ::com::sun::star::uno::Sequence< OUString >& rBlackList = ::com::sun::star::uno::Sequence< OUString >()
242 : );
243 :
244 : /** cancels the running operation.
245 :
246 : Note that "cancel" may mean that the operation is running, but its result
247 : is simply disregarded later on.
248 : */
249 : void cancel();
250 :
251 : protected:
252 : virtual ~FileViewContentEnumerator();
253 :
254 : private:
255 : EnumerationResult enumerateFolderContent();
256 :
257 : // Thread overridables
258 : virtual void execute() SAL_OVERRIDE;
259 :
260 : private:
261 : bool implGetDocTitle( const OUString& _rTargetURL, OUString& _rRet ) const;
262 : };
263 :
264 :
265 : } // namespace svt
266 :
267 :
268 : #endif // INCLUDED_SVTOOLS_SOURCE_CONTNR_CONTENTENUMERATION_HXX
269 :
270 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|