bump product version to 6.3.0.0.beta1
[LibreOffice.git] / svtools / source / contnr / foldertree.cxx
blobbd4dc5812c27412375a5d0e31245bcf24daf9924
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 <comphelper/processfactory.hxx>
11 #include <svtools/foldertree.hxx>
12 #include <toolkit/helper/vclunohelper.hxx>
13 #include <tools/urlobj.hxx>
14 #include <ucbhelper/commandenvironment.hxx>
15 #include <vcl/dialog.hxx>
16 #include <vcl/treelistentry.hxx>
17 #include <vcl/ptrstyle.hxx>
18 #include <com/sun/star/task/InteractionHandler.hpp>
19 #include "contentenumeration.hxx"
20 #include <bitmaps.hlst>
22 using namespace ::com::sun::star::task;
24 FolderTree::FolderTree( vcl::Window* pParent, WinBits nBits )
25 : SvTreeListBox( pParent, nBits | WB_SORT | WB_TABSTOP )
27 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
28 Reference< XInteractionHandler > xInteractionHandler(
29 InteractionHandler::createWithParent(xContext, VCLUnoHelper::GetInterface(GetParentDialog())), UNO_QUERY_THROW );
30 m_xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
32 Image aFolderImage(StockImage::Yes, RID_BMP_FOLDER);
33 Image aFolderExpandedImage(StockImage::Yes, RID_BMP_FOLDER_OPEN);
34 SetDefaultCollapsedEntryBmp( aFolderImage );
35 SetDefaultExpandedEntryBmp( aFolderExpandedImage );
38 void FolderTree::RequestingChildren( SvTreeListEntry* pEntry )
40 EnableChildPointerOverwrite( true );
41 SetPointer( PointerStyle::Wait );
42 Invalidate(InvalidateFlags::Update);
44 FillTreeEntry( pEntry );
46 SetPointer( PointerStyle::Arrow );
47 EnableChildPointerOverwrite( false );
50 void FolderTree::FillTreeEntry( SvTreeListEntry* pEntry )
52 if( !pEntry )
53 return;
55 OUString* pURL = static_cast< OUString* >( pEntry->GetUserData() );
57 if( pURL && m_sLastUpdatedDir != *pURL )
59 while (SvTreeListEntry* pChild = FirstChild(pEntry))
61 GetModel()->Remove(pChild);
64 ::std::vector< std::unique_ptr<SortingData_Impl> > aContent;
66 ::rtl::Reference< ::svt::FileViewContentEnumerator >
67 xContentEnumerator(new FileViewContentEnumerator(
68 m_xEnv, aContent, m_aMutex));
70 FolderDescriptor aFolder( *pURL );
72 EnumerationResult eResult =
73 xContentEnumerator->enumerateFolderContentSync( aFolder, m_aBlackList );
75 if ( EnumerationResult::SUCCESS == eResult )
77 for(auto & i : aContent)
79 if( i->mbIsFolder )
81 SvTreeListEntry* pNewEntry = InsertEntry( i->GetTitle(), pEntry, true );
83 OUString* sData = new OUString( i->maTargetURL );
84 pNewEntry->SetUserData( static_cast< void* >( sData ) );
89 else
91 // this dir was updated recently
92 // next time read this remote folder
93 m_sLastUpdatedDir.clear();
97 void FolderTree::FillTreeEntry( const OUString & rUrl, const ::std::vector< std::pair< OUString, OUString > >& rFolders )
99 SetTreePath( rUrl );
101 SvTreeListEntry* pParent = GetCurEntry();
103 if( !(pParent && !IsExpanded( pParent )) )
104 return;
106 while (SvTreeListEntry* pChild = FirstChild(pParent))
108 GetModel()->Remove(pChild);
111 for (auto const& folder : rFolders)
113 SvTreeListEntry* pNewEntry = InsertEntry( folder.first, pParent, true );
114 OUString* sData = new OUString( folder.second );
115 pNewEntry->SetUserData( static_cast< void* >( sData ) );
118 m_sLastUpdatedDir = rUrl;
119 Expand( pParent );
122 void FolderTree::SetTreePath( OUString const & sUrl )
124 INetURLObject aUrl( sUrl );
125 aUrl.setFinalSlash();
127 OUString sPath = aUrl.GetURLPath( INetURLObject::DecodeMechanism::WithCharset );
129 SvTreeListEntry* pEntry = First();
130 bool end = false;
132 while( pEntry && !end )
134 if( pEntry->GetUserData() )
136 OUString sNodeUrl = *static_cast< OUString* >( pEntry->GetUserData() );
138 INetURLObject aUrlObj( sNodeUrl );
139 aUrlObj.setFinalSlash();
141 sNodeUrl = aUrlObj.GetURLPath( INetURLObject::DecodeMechanism::WithCharset );
143 if( sPath == sNodeUrl )
145 Select( pEntry );
146 end = true;
148 else if( sPath.startsWith( sNodeUrl ) )
150 if( !IsExpanded( pEntry ) )
151 Expand( pEntry );
153 pEntry = FirstChild( pEntry );
155 else
157 pEntry = pEntry->NextSibling();
160 else
161 break;
165 void FolderTree::SetBlackList( const css::uno::Sequence< OUString >& rBlackList )
167 m_aBlackList = rBlackList;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */