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 <tools/urlobj.hxx>
12 #include <ucbhelper/commandenvironment.hxx>
13 #include <com/sun/star/task/InteractionHandler.hpp>
14 #include "contentenumeration.hxx"
15 #include "foldertree.hxx"
16 #include <bitmaps.hlst>
18 using namespace ::com::sun::star::task
;
20 using namespace ::svt
;
22 FolderTree::FolderTree(std::unique_ptr
<weld::TreeView
> xTreeView
, weld::Window
* pTopLevel
)
23 : m_xTreeView(std::move(xTreeView
))
24 , m_xScratchIter(m_xTreeView
->make_iterator())
25 , m_pTopLevel(pTopLevel
)
27 m_xTreeView
->set_size_request(m_xTreeView
->get_approximate_digit_width() * 24,
28 m_xTreeView
->get_height_rows(7));
30 const Reference
< XComponentContext
>& xContext
= ::comphelper::getProcessComponentContext();
31 Reference
< XInteractionHandler
> xInteractionHandler(
32 InteractionHandler::createWithParent(xContext
, pTopLevel
->GetXWindow()), UNO_QUERY_THROW
);
33 m_xEnv
= new ::ucbhelper::CommandEnvironment( xInteractionHandler
, Reference
< XProgressHandler
>() );
35 m_xTreeView
->connect_expanding(LINK(this, FolderTree
, RequestingChildrenHdl
));
38 FolderTree::~FolderTree() {}
40 IMPL_LINK(FolderTree
, RequestingChildrenHdl
, const weld::TreeIter
&, rEntry
, bool)
42 weld::WaitObject
aWait(m_pTopLevel
);
44 FillTreeEntry(rEntry
);
49 void FolderTree::InsertRootEntry(const OUString
& rId
, const OUString
& rRootLabel
)
51 m_xTreeView
->insert(nullptr, -1, &rRootLabel
, &rId
, nullptr, nullptr,
52 true, m_xScratchIter
.get());
53 m_xTreeView
->set_image(*m_xScratchIter
, RID_BMP_FOLDER
);
54 m_xTreeView
->set_cursor(*m_xScratchIter
);
57 void FolderTree::FillTreeEntry(const weld::TreeIter
& rEntry
)
59 OUString sURL
= m_xTreeView
->get_id(rEntry
);
60 OUString
sFolderImage(RID_BMP_FOLDER
);
62 if (m_sLastUpdatedDir
!= sURL
)
64 while (m_xTreeView
->iter_has_child(rEntry
))
66 std::unique_ptr
<weld::TreeIter
> xChild(m_xTreeView
->make_iterator(&rEntry
));
67 (void)m_xTreeView
->iter_children(*xChild
);
68 m_xTreeView
->remove(*xChild
);
71 ::std::vector
< std::unique_ptr
<SortingData_Impl
> > aContent
;
73 ::rtl::Reference
< ::svt::FileViewContentEnumerator
>
74 xContentEnumerator(new FileViewContentEnumerator(
75 m_xEnv
, aContent
, m_aMutex
));
77 FolderDescriptor
aFolder(sURL
);
79 EnumerationResult eResult
=
80 xContentEnumerator
->enumerateFolderContentSync( aFolder
, m_aDenyList
);
82 if (EnumerationResult::SUCCESS
== eResult
)
84 for(const auto & i
: aContent
)
88 m_xTreeView
->insert(&rEntry
, -1, &i
->GetTitle(), &i
->maTargetURL
,
89 nullptr, nullptr, true, m_xScratchIter
.get());
90 m_xTreeView
->set_image(*m_xScratchIter
, sFolderImage
);
96 // this dir was updated recently
97 // next time read this remote folder
98 m_sLastUpdatedDir
.clear();
102 void FolderTree::FillTreeEntry( const OUString
& rUrl
, const ::std::vector
< std::pair
< OUString
, OUString
> >& rFolders
)
106 std::unique_ptr
<weld::TreeIter
> xParent(m_xTreeView
->make_iterator());
107 bool bParent
= m_xTreeView
->get_cursor(xParent
.get());
109 if (!bParent
|| m_xTreeView
->get_row_expanded(*xParent
))
112 OUString
sFolderImage(RID_BMP_FOLDER
);
113 while (m_xTreeView
->iter_has_child(*xParent
))
115 std::unique_ptr
<weld::TreeIter
> xChild(m_xTreeView
->make_iterator(xParent
.get()));
116 (void)m_xTreeView
->iter_children(*xChild
);
117 m_xTreeView
->remove(*xChild
);
120 for (auto const& folder
: rFolders
)
122 m_xTreeView
->insert(xParent
.get(), -1, &folder
.first
, &folder
.second
,
123 nullptr, nullptr, true, m_xScratchIter
.get());
124 m_xTreeView
->set_image(*m_xScratchIter
, sFolderImage
);
127 m_sLastUpdatedDir
= rUrl
;
128 m_xTreeView
->expand_row(*xParent
);
131 void FolderTree::SetTreePath( std::u16string_view sUrl
)
133 INetURLObject
aUrl( sUrl
);
134 aUrl
.setFinalSlash();
136 OUString sPath
= aUrl
.GetURLPath( INetURLObject::DecodeMechanism::WithCharset
);
138 std::unique_ptr
<weld::TreeIter
> xEntry(m_xTreeView
->make_iterator());
139 bool bEntry
= m_xTreeView
->get_iter_first(*xEntry
);
142 while (bEntry
&& !bEnd
)
144 if (!m_xTreeView
->get_id(*xEntry
).isEmpty())
146 OUString sNodeUrl
= m_xTreeView
->get_id(*xEntry
);
148 INetURLObject
aUrlObj( sNodeUrl
);
149 aUrlObj
.setFinalSlash();
151 sNodeUrl
= aUrlObj
.GetURLPath( INetURLObject::DecodeMechanism::WithCharset
);
153 if( sPath
== sNodeUrl
)
155 m_xTreeView
->select(*xEntry
);
158 else if( sPath
.startsWith( sNodeUrl
) )
160 if (!m_xTreeView
->get_row_expanded(*xEntry
))
161 m_xTreeView
->expand_row(*xEntry
);
163 bEntry
= m_xTreeView
->iter_children(*xEntry
);
167 bEntry
= m_xTreeView
->iter_next_sibling(*xEntry
);
175 void FolderTree::SetDenyList( const css::uno::Sequence
< OUString
>& rDenyList
)
177 m_aDenyList
= rDenyList
;
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */