Bump version to 5.0-14
[LibreOffice.git] / svtools / source / contnr / foldertree.cxx
blobdaeb9e7fd38987948810c2ace0b53cbadad9ce5c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <svtools/foldertree.hxx>
12 #include "contentenumeration.hxx"
14 FolderTree::FolderTree( vcl::Window* pParent, WinBits nBits )
15 : SvTreeListBox( pParent, nBits | WB_SORT | WB_TABSTOP )
16 , m_aFolderImage( SvtResId( IMG_SVT_FOLDER ) )
17 , m_aFolderExpandedImage( SvtResId( IMG_SVT_FOLDER_OPEN ) )
19 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
20 Reference< XInteractionHandler > xInteractionHandler(
21 InteractionHandler::createWithParent( xContext, 0 ), UNO_QUERY_THROW );
22 m_xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
24 SetDefaultCollapsedEntryBmp( m_aFolderImage );
25 SetDefaultExpandedEntryBmp( m_aFolderExpandedImage );
28 void FolderTree::RequestingChildren( SvTreeListEntry* pEntry )
30 EnableChildPointerOverwrite( true );
31 SetPointer( PointerStyle::Wait );
32 Invalidate(INVALIDATE_UPDATE);
34 FillTreeEntry( pEntry );
36 SetPointer( PointerStyle::Arrow );
37 EnableChildPointerOverwrite( false );
40 void FolderTree::FillTreeEntry( SvTreeListEntry* pEntry )
42 if( pEntry )
44 OUString* pURL = static_cast< OUString* >( pEntry->GetUserData() );
46 if( pURL && m_sLastUpdatedDir != *pURL )
48 while (SvTreeListEntry* pChild = FirstChild(pEntry))
50 GetModel()->Remove(pChild);
53 ::std::vector< SortingData_Impl* > aContent;
55 ::rtl::Reference< ::svt::FileViewContentEnumerator >
56 xContentEnumerator(new FileViewContentEnumerator(
57 m_xEnv, aContent, m_aMutex, NULL));
59 FolderDescriptor aFolder( *pURL );
61 EnumerationResult eResult =
62 xContentEnumerator->enumerateFolderContentSync( aFolder, m_aBlackList );
64 if ( SUCCESS == eResult )
66 for( std::vector<SortingData_Impl *>::size_type i = 0; i < aContent.size(); i++ )
68 if( aContent[i]->mbIsFolder )
70 SvTreeListEntry* pNewEntry = InsertEntry( aContent[i]->GetTitle(), pEntry, true );
72 OUString* sData = new OUString( aContent[i]->maTargetURL );
73 pNewEntry->SetUserData( static_cast< void* >( sData ) );
78 else
80 // this dir was updated recently
81 // next time read this remote folder
82 m_sLastUpdatedDir = "";
87 void FolderTree::FillTreeEntry( const OUString & rUrl, const ::std::vector< std::pair< OUString, OUString > >& rFolders )
89 SetTreePath( rUrl );
91 SvTreeListEntry* pParent = GetCurEntry();
93 if( pParent && !IsExpanded( pParent ) )
95 while( GetChildCount( pParent ) > 0 )
97 SvTreeListEntry* pChild = FirstChild( pParent );
98 GetModel()->Remove( pChild );
101 for(::std::vector< std::pair< OUString, OUString > >::const_iterator it = rFolders.begin(); it != rFolders.end() ; ++it)
103 SvTreeListEntry* pNewEntry = InsertEntry( it->first, pParent, true );
104 OUString* sData = new OUString( it->second );
105 pNewEntry->SetUserData( static_cast< void* >( sData ) );
108 m_sLastUpdatedDir = rUrl;
109 Expand( pParent );
113 void FolderTree::SetTreePath( OUString const & sUrl )
115 INetURLObject aUrl( sUrl );
116 aUrl.setFinalSlash();
118 OUString sPath = aUrl.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
120 SvTreeListEntry* pEntry = First();
121 bool end = false;
123 while( pEntry && !end )
125 if( pEntry->GetUserData() )
127 OUString sNodeUrl = *static_cast< OUString* >( pEntry->GetUserData() );
129 INetURLObject aUrlObj( sNodeUrl );
130 aUrlObj.setFinalSlash();
132 sNodeUrl = aUrlObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
134 if( sPath == sNodeUrl )
136 Select( pEntry );
137 end = true;
139 else if( sPath.startsWith( sNodeUrl ) )
141 if( !IsExpanded( pEntry ) )
142 Expand( pEntry );
144 pEntry = FirstChild( pEntry );
146 else
148 pEntry = NextSibling( pEntry );
151 else
152 break;
156 void FolderTree::SetBlackList( const ::com::sun::star::uno::Sequence< OUString >& rBlackList )
158 m_aBlackList = rBlackList;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */