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