Update ooo320-m1
[ooovba.git] / svtools / source / contnr / contentenumeration.hxx
blob8a764152c0513c56c0312e07f63b2b72fd427887
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: contentenumeration.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SVTOOLS_SOURCE_CONTNR_CONTENTENUMERATION_HXX
32 #define SVTOOLS_SOURCE_CONTNR_CONTENTENUMERATION_HXX
34 /** === begin UNO includes === **/
35 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
36 #include <com/sun/star/document/XStandaloneDocumentInfo.hpp>
37 /** === end UNO includes === **/
38 #include <osl/thread.hxx>
39 #include <rtl/ref.hxx>
40 #include <ucbhelper/content.hxx>
41 #include <rtl/ustring.hxx>
42 #include <tools/datetime.hxx>
43 #include <vcl/image.hxx>
45 class IUrlFilter;
46 //........................................................................
47 namespace svt
49 //........................................................................
51 //====================================================================
52 //= SortingData_Impl
53 //====================================================================
54 struct SortingData_Impl
56 private:
57 ::rtl::OUString maFilename; // only filename in upper case - for compare purposes
58 ::rtl::OUString maTitle; // -> be carefull when changing maTitle to update maFilename only when new
59 ::rtl::OUString maLowerTitle;
62 public:
63 ::rtl::OUString maType;
64 ::rtl::OUString maTargetURL;
65 ::rtl::OUString maImageURL;
66 ::rtl::OUString maDisplayText;
67 DateTime maModDate;
68 Image maImage;
69 sal_Int64 maSize;
70 sal_Bool mbIsFolder;
71 sal_Bool mbIsVolume;
72 sal_Bool mbIsRemote;
73 sal_Bool mbIsRemoveable;
74 sal_Bool mbIsFloppy;
75 sal_Bool mbIsCompactDisc;
77 inline SortingData_Impl();
78 inline const ::rtl::OUString& GetTitle() const;
79 inline const ::rtl::OUString& GetLowerTitle() const;
80 inline const ::rtl::OUString& GetFileName() const;
81 inline void SetNewTitle( const ::rtl::OUString& rNewTitle ); // new maTitle is set -> maFilename is set to same!
82 inline void ChangeTitle( const ::rtl::OUString& rChangedTitle ); // maTitle is changed, maFilename is unchanged!
84 private:
85 inline void SetTitles( const ::rtl::OUString& rNewTitle );
88 inline SortingData_Impl::SortingData_Impl() :
89 maSize ( 0 ),
90 mbIsFolder ( sal_False ),
91 mbIsVolume ( sal_False ),
92 mbIsRemote ( sal_False ),
93 mbIsRemoveable ( sal_False ),
94 mbIsFloppy ( sal_False ),
95 mbIsCompactDisc ( sal_False )
99 inline const ::rtl::OUString& SortingData_Impl::GetTitle() const
101 return maTitle;
104 inline const ::rtl::OUString& SortingData_Impl::GetLowerTitle() const
106 return maLowerTitle;
109 inline const ::rtl::OUString& SortingData_Impl::GetFileName() const
111 return maFilename;
114 inline void SortingData_Impl::SetNewTitle( const ::rtl::OUString& rNewTitle )
116 SetTitles( rNewTitle );
117 maFilename = rNewTitle.toAsciiUpperCase();
120 inline void SortingData_Impl::ChangeTitle( const ::rtl::OUString& rChangedTitle )
122 SetTitles( rChangedTitle );
125 inline void SortingData_Impl::SetTitles( const ::rtl::OUString& rNewTitle )
127 maTitle = rNewTitle;
128 maLowerTitle = rNewTitle.toAsciiLowerCase();
131 //====================================================================
132 //= IContentTitleTranslation
133 //====================================================================
134 class IContentTitleTranslation
136 public:
137 virtual sal_Bool GetTranslation( const ::rtl::OUString& _rOriginalName, ::rtl::OUString& _rTranslatedName ) const = 0;
140 //====================================================================
141 //= EnumerationResult
142 //====================================================================
143 enum EnumerationResult
145 SUCCESS, /// the enumration was successfull
146 ERROR, /// the enumration was unsuccessfull
147 RUNNING /// the enumeration is still running, and the maximum wait time has passed
150 //====================================================================
151 //= FolderDescriptor
152 //====================================================================
153 struct FolderDescriptor
155 /** a content object describing the folder. Can be <NULL/>, in this case <member>sURL</member>
156 is relevant.
158 ::ucbhelper::Content aContent;
159 /** the URL of a folder. Will be ignored if <member>aContent</member> is not <NULL/>.
161 String sURL;
163 FolderDescriptor() { }
165 FolderDescriptor( const ::ucbhelper::Content& _rContent )
166 :aContent( _rContent )
170 FolderDescriptor( const String& _rURL )
171 :sURL( _rURL )
176 //====================================================================
177 //= IEnumerationResultHandler
178 //====================================================================
179 class IEnumerationResultHandler
181 public:
182 virtual void enumerationDone( EnumerationResult _eResult ) = 0;
185 //====================================================================
186 //= FileViewContentEnumerator
187 //====================================================================
188 class FileViewContentEnumerator
189 :public ::rtl::IReference
190 ,private ::osl::Thread
192 public:
193 typedef ::std::vector< SortingData_Impl* > ContentData;
195 private:
196 ContentData& m_rContent;
197 ::osl::Mutex& m_rContentMutex;
199 oslInterlockedCount m_refCount;
200 mutable ::osl::Mutex m_aMutex;
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;
210 mutable ::com::sun::star::uno::Reference< ::com::sun::star::document::XStandaloneDocumentInfo >
211 m_xDocInfo;
213 ::com::sun::star::uno::Sequence< ::rtl::OUString > m_rBlackList;
215 sal_Bool URLOnBlackList ( const ::rtl::OUString& sRealURL );
217 public:
218 /** constructs an enumerator instance
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/>
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
234 /** enumerates the content of a given folder
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
243 void enumerateFolderContent(
244 const FolderDescriptor& _rFolder,
245 const IUrlFilter* _pFilter,
246 IEnumerationResultHandler* _pResultHandler
249 /** enumerates the content of a given folder synchronously
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 >()
257 /** cancels the running operation.
259 Note that "cancel" may mean that the operation is running, but its result
260 is simply disregarded later on.
262 void cancel();
264 // IReference overridables
265 virtual oslInterlockedCount SAL_CALL acquire();
266 virtual oslInterlockedCount SAL_CALL release();
268 using Thread::operator new;
269 using Thread::operator delete;
271 protected:
272 ~FileViewContentEnumerator();
274 private:
275 EnumerationResult enumerateFolderContent();
277 // Thread overridables
278 virtual void SAL_CALL run();
279 virtual void SAL_CALL onTerminated();
281 private:
282 sal_Bool implGetDocTitle( const ::rtl::OUString& _rTargetURL, ::rtl::OUString& _rRet ) const;
285 //........................................................................
286 } // namespace svt
287 //........................................................................
289 #endif // SVTOOLS_SOURCE_CONTNR_CONTENTENUMERATION_HXX