1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
)
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
)
81 SvTreeListEntry
* pNewEntry
= InsertEntry( i
->GetTitle(), pEntry
, true );
83 OUString
* sData
= new OUString( i
->maTargetURL
);
84 pNewEntry
->SetUserData( static_cast< void* >( sData
) );
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
)
101 SvTreeListEntry
* pParent
= GetCurEntry();
103 if( !(pParent
&& !IsExpanded( pParent
)) )
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
;
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();
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
)
148 else if( sPath
.startsWith( sNodeUrl
) )
150 if( !IsExpanded( pEntry
) )
153 pEntry
= FirstChild( pEntry
);
157 pEntry
= pEntry
->NextSibling();
165 void FolderTree::SetBlackList( const css::uno::Sequence
< OUString
>& rBlackList
)
167 m_aBlackList
= rBlackList
;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */