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