1*01aa44aaSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*01aa44aaSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*01aa44aaSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*01aa44aaSAndrew Rist * distributed with this work for additional information 6*01aa44aaSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*01aa44aaSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*01aa44aaSAndrew Rist * "License"); you may not use this file except in compliance 9*01aa44aaSAndrew Rist * with the License. You may obtain a copy of the License at 10*01aa44aaSAndrew Rist * 11*01aa44aaSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*01aa44aaSAndrew Rist * 13*01aa44aaSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*01aa44aaSAndrew Rist * software distributed under the License is distributed on an 15*01aa44aaSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*01aa44aaSAndrew Rist * KIND, either express or implied. See the License for the 17*01aa44aaSAndrew Rist * specific language governing permissions and limitations 18*01aa44aaSAndrew Rist * under the License. 19*01aa44aaSAndrew Rist * 20*01aa44aaSAndrew Rist *************************************************************/ 21*01aa44aaSAndrew Rist 22*01aa44aaSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SVTOOLS_SOURCE_CONTNR_CONTENTENUMERATION_HXX 25cdf0e10cSrcweir #define SVTOOLS_SOURCE_CONTNR_CONTENTENUMERATION_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir /** === begin UNO includes === **/ 28cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp> 29cdf0e10cSrcweir #include <com/sun/star/document/XStandaloneDocumentInfo.hpp> 30cdf0e10cSrcweir /** === end UNO includes === **/ 31cdf0e10cSrcweir #include <osl/thread.hxx> 32cdf0e10cSrcweir #include <rtl/ref.hxx> 33cdf0e10cSrcweir #include <ucbhelper/content.hxx> 34cdf0e10cSrcweir #include <rtl/ustring.hxx> 35cdf0e10cSrcweir #include <tools/datetime.hxx> 36cdf0e10cSrcweir #include <vcl/image.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir class IUrlFilter; 39cdf0e10cSrcweir //........................................................................ 40cdf0e10cSrcweir namespace svt 41cdf0e10cSrcweir { 42cdf0e10cSrcweir //........................................................................ 43cdf0e10cSrcweir 44cdf0e10cSrcweir //==================================================================== 45cdf0e10cSrcweir //= SortingData_Impl 46cdf0e10cSrcweir //==================================================================== 47cdf0e10cSrcweir struct SortingData_Impl 48cdf0e10cSrcweir { 49cdf0e10cSrcweir private: 50cdf0e10cSrcweir ::rtl::OUString maFilename; // only filename in upper case - for compare purposes 51cdf0e10cSrcweir ::rtl::OUString maTitle; // -> be carefull when changing maTitle to update maFilename only when new 52cdf0e10cSrcweir ::rtl::OUString maLowerTitle; 53cdf0e10cSrcweir 54cdf0e10cSrcweir 55cdf0e10cSrcweir public: 56cdf0e10cSrcweir ::rtl::OUString maType; 57cdf0e10cSrcweir ::rtl::OUString maTargetURL; 58cdf0e10cSrcweir ::rtl::OUString maImageURL; 59cdf0e10cSrcweir ::rtl::OUString maDisplayText; 60cdf0e10cSrcweir DateTime maModDate; 61cdf0e10cSrcweir Image maImage; 62cdf0e10cSrcweir sal_Int64 maSize; 63cdf0e10cSrcweir sal_Bool mbIsFolder; 64cdf0e10cSrcweir sal_Bool mbIsVolume; 65cdf0e10cSrcweir sal_Bool mbIsRemote; 66cdf0e10cSrcweir sal_Bool mbIsRemoveable; 67cdf0e10cSrcweir sal_Bool mbIsFloppy; 68cdf0e10cSrcweir sal_Bool mbIsCompactDisc; 69cdf0e10cSrcweir 70cdf0e10cSrcweir inline SortingData_Impl(); 71cdf0e10cSrcweir inline const ::rtl::OUString& GetTitle() const; 72cdf0e10cSrcweir inline const ::rtl::OUString& GetLowerTitle() const; 73cdf0e10cSrcweir inline const ::rtl::OUString& GetFileName() const; 74cdf0e10cSrcweir inline void SetNewTitle( const ::rtl::OUString& rNewTitle ); // new maTitle is set -> maFilename is set to same! 75cdf0e10cSrcweir inline void ChangeTitle( const ::rtl::OUString& rChangedTitle ); // maTitle is changed, maFilename is unchanged! 76cdf0e10cSrcweir 77cdf0e10cSrcweir private: 78cdf0e10cSrcweir inline void SetTitles( const ::rtl::OUString& rNewTitle ); 79cdf0e10cSrcweir }; 80cdf0e10cSrcweir 81cdf0e10cSrcweir inline SortingData_Impl::SortingData_Impl() : 82cdf0e10cSrcweir maSize ( 0 ), 83cdf0e10cSrcweir mbIsFolder ( sal_False ), 84cdf0e10cSrcweir mbIsVolume ( sal_False ), 85cdf0e10cSrcweir mbIsRemote ( sal_False ), 86cdf0e10cSrcweir mbIsRemoveable ( sal_False ), 87cdf0e10cSrcweir mbIsFloppy ( sal_False ), 88cdf0e10cSrcweir mbIsCompactDisc ( sal_False ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir inline const ::rtl::OUString& SortingData_Impl::GetTitle() const 93cdf0e10cSrcweir { 94cdf0e10cSrcweir return maTitle; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir inline const ::rtl::OUString& SortingData_Impl::GetLowerTitle() const 98cdf0e10cSrcweir { 99cdf0e10cSrcweir return maLowerTitle; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir inline const ::rtl::OUString& SortingData_Impl::GetFileName() const 103cdf0e10cSrcweir { 104cdf0e10cSrcweir return maFilename; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir inline void SortingData_Impl::SetNewTitle( const ::rtl::OUString& rNewTitle ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir SetTitles( rNewTitle ); 110cdf0e10cSrcweir maFilename = rNewTitle.toAsciiUpperCase(); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir inline void SortingData_Impl::ChangeTitle( const ::rtl::OUString& rChangedTitle ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir SetTitles( rChangedTitle ); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir inline void SortingData_Impl::SetTitles( const ::rtl::OUString& rNewTitle ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir maTitle = rNewTitle; 121cdf0e10cSrcweir maLowerTitle = rNewTitle.toAsciiLowerCase(); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir //==================================================================== 125cdf0e10cSrcweir //= IContentTitleTranslation 126cdf0e10cSrcweir //==================================================================== 127cdf0e10cSrcweir class IContentTitleTranslation 128cdf0e10cSrcweir { 129cdf0e10cSrcweir public: 130cdf0e10cSrcweir virtual sal_Bool GetTranslation( const ::rtl::OUString& _rOriginalName, ::rtl::OUString& _rTranslatedName ) const = 0; 131cdf0e10cSrcweir }; 132cdf0e10cSrcweir 133cdf0e10cSrcweir //==================================================================== 134cdf0e10cSrcweir //= EnumerationResult 135cdf0e10cSrcweir //==================================================================== 136cdf0e10cSrcweir enum EnumerationResult 137cdf0e10cSrcweir { 138cdf0e10cSrcweir SUCCESS, /// the enumration was successfull 139cdf0e10cSrcweir ERROR, /// the enumration was unsuccessfull 140cdf0e10cSrcweir RUNNING /// the enumeration is still running, and the maximum wait time has passed 141cdf0e10cSrcweir }; 142cdf0e10cSrcweir 143cdf0e10cSrcweir //==================================================================== 144cdf0e10cSrcweir //= FolderDescriptor 145cdf0e10cSrcweir //==================================================================== 146cdf0e10cSrcweir struct FolderDescriptor 147cdf0e10cSrcweir { 148cdf0e10cSrcweir /** a content object describing the folder. Can be <NULL/>, in this case <member>sURL</member> 149cdf0e10cSrcweir is relevant. 150cdf0e10cSrcweir */ 151cdf0e10cSrcweir ::ucbhelper::Content aContent; 152cdf0e10cSrcweir /** the URL of a folder. Will be ignored if <member>aContent</member> is not <NULL/>. 153cdf0e10cSrcweir */ 154cdf0e10cSrcweir String sURL; 155cdf0e10cSrcweir 156cdf0e10cSrcweir FolderDescriptor() { } 157cdf0e10cSrcweir 158cdf0e10cSrcweir FolderDescriptor( const ::ucbhelper::Content& _rContent ) 159cdf0e10cSrcweir :aContent( _rContent ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir FolderDescriptor( const String& _rURL ) 164cdf0e10cSrcweir :sURL( _rURL ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir } 167cdf0e10cSrcweir }; 168cdf0e10cSrcweir 169cdf0e10cSrcweir //==================================================================== 170cdf0e10cSrcweir //= IEnumerationResultHandler 171cdf0e10cSrcweir //==================================================================== 172cdf0e10cSrcweir class IEnumerationResultHandler 173cdf0e10cSrcweir { 174cdf0e10cSrcweir public: 175cdf0e10cSrcweir virtual void enumerationDone( EnumerationResult _eResult ) = 0; 176cdf0e10cSrcweir }; 177cdf0e10cSrcweir 178cdf0e10cSrcweir //==================================================================== 179cdf0e10cSrcweir //= FileViewContentEnumerator 180cdf0e10cSrcweir //==================================================================== 181cdf0e10cSrcweir class FileViewContentEnumerator 182cdf0e10cSrcweir :public ::rtl::IReference 183cdf0e10cSrcweir ,private ::osl::Thread 184cdf0e10cSrcweir { 185cdf0e10cSrcweir public: 186cdf0e10cSrcweir typedef ::std::vector< SortingData_Impl* > ContentData; 187cdf0e10cSrcweir 188cdf0e10cSrcweir private: 189cdf0e10cSrcweir ContentData& m_rContent; 190cdf0e10cSrcweir ::osl::Mutex& m_rContentMutex; 191cdf0e10cSrcweir 192cdf0e10cSrcweir oslInterlockedCount m_refCount; 193cdf0e10cSrcweir mutable ::osl::Mutex m_aMutex; 194cdf0e10cSrcweir 195cdf0e10cSrcweir FolderDescriptor m_aFolder; 196cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > 197cdf0e10cSrcweir m_xCommandEnv; 198cdf0e10cSrcweir const IUrlFilter* m_pFilter; 199cdf0e10cSrcweir const IContentTitleTranslation* m_pTranslator; 200cdf0e10cSrcweir IEnumerationResultHandler* m_pResultHandler; 201cdf0e10cSrcweir bool m_bCancelled; 202cdf0e10cSrcweir 203cdf0e10cSrcweir mutable ::com::sun::star::uno::Reference< ::com::sun::star::document::XStandaloneDocumentInfo > 204cdf0e10cSrcweir m_xDocInfo; 205cdf0e10cSrcweir 206cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > m_rBlackList; 207cdf0e10cSrcweir 208cdf0e10cSrcweir sal_Bool URLOnBlackList ( const ::rtl::OUString& sRealURL ); 209cdf0e10cSrcweir 210cdf0e10cSrcweir public: 211cdf0e10cSrcweir /** constructs an enumerator instance 212cdf0e10cSrcweir 213cdf0e10cSrcweir @param _rContentToFill 214cdf0e10cSrcweir the structure which is to be filled with the found content 215cdf0e10cSrcweir @param _rContentMutex 216cdf0e10cSrcweir the mutex which protects the access to <arg>_rContentToFill</arg> 217cdf0e10cSrcweir @param _pTranslator 218cdf0e10cSrcweir an instance which should be used to translate content titles. May be <NULL/> 219cdf0e10cSrcweir */ 220cdf0e10cSrcweir FileViewContentEnumerator( 221cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& _rxCommandEnv, 222cdf0e10cSrcweir ContentData& _rContentToFill, 223cdf0e10cSrcweir ::osl::Mutex& _rContentMutex, 224cdf0e10cSrcweir const IContentTitleTranslation* _pTranslator 225cdf0e10cSrcweir ); 226cdf0e10cSrcweir 227cdf0e10cSrcweir /** enumerates the content of a given folder 228cdf0e10cSrcweir 229cdf0e10cSrcweir @param _rFolder 230cdf0e10cSrcweir the folder whose content is to be enumerated 231cdf0e10cSrcweir @param _pFilter 232cdf0e10cSrcweir a filter to apply to the found contents 233cdf0e10cSrcweir @param _pResultHandler 234cdf0e10cSrcweir an instance which should handle the results of the enumeration 235cdf0e10cSrcweir */ 236cdf0e10cSrcweir void enumerateFolderContent( 237cdf0e10cSrcweir const FolderDescriptor& _rFolder, 238cdf0e10cSrcweir const IUrlFilter* _pFilter, 239cdf0e10cSrcweir IEnumerationResultHandler* _pResultHandler 240cdf0e10cSrcweir ); 241cdf0e10cSrcweir 242cdf0e10cSrcweir /** enumerates the content of a given folder synchronously 243cdf0e10cSrcweir */ 244cdf0e10cSrcweir EnumerationResult enumerateFolderContentSync( 245cdf0e10cSrcweir const FolderDescriptor& _rFolder, 246cdf0e10cSrcweir const IUrlFilter* _pFilter, 247cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList = ::com::sun::star::uno::Sequence< ::rtl::OUString >() 248cdf0e10cSrcweir ); 249cdf0e10cSrcweir 250cdf0e10cSrcweir /** cancels the running operation. 251cdf0e10cSrcweir 252cdf0e10cSrcweir Note that "cancel" may mean that the operation is running, but its result 253cdf0e10cSrcweir is simply disregarded later on. 254cdf0e10cSrcweir */ 255cdf0e10cSrcweir void cancel(); 256cdf0e10cSrcweir 257cdf0e10cSrcweir // IReference overridables 258cdf0e10cSrcweir virtual oslInterlockedCount SAL_CALL acquire(); 259cdf0e10cSrcweir virtual oslInterlockedCount SAL_CALL release(); 260cdf0e10cSrcweir 261cdf0e10cSrcweir using Thread::operator new; 262cdf0e10cSrcweir using Thread::operator delete; 263cdf0e10cSrcweir 264cdf0e10cSrcweir protected: 265cdf0e10cSrcweir ~FileViewContentEnumerator(); 266cdf0e10cSrcweir 267cdf0e10cSrcweir private: 268cdf0e10cSrcweir EnumerationResult enumerateFolderContent(); 269cdf0e10cSrcweir 270cdf0e10cSrcweir // Thread overridables 271cdf0e10cSrcweir virtual void SAL_CALL run(); 272cdf0e10cSrcweir virtual void SAL_CALL onTerminated(); 273cdf0e10cSrcweir 274cdf0e10cSrcweir private: 275cdf0e10cSrcweir sal_Bool implGetDocTitle( const ::rtl::OUString& _rTargetURL, ::rtl::OUString& _rRet ) const; 276cdf0e10cSrcweir }; 277cdf0e10cSrcweir 278cdf0e10cSrcweir //........................................................................ 279cdf0e10cSrcweir } // namespace svt 280cdf0e10cSrcweir //........................................................................ 281cdf0e10cSrcweir 282cdf0e10cSrcweir #endif // SVTOOLS_SOURCE_CONTNR_CONTENTENUMERATION_HXX 283cdf0e10cSrcweir 284