/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include "contentenumeration.hxx" #include "foldertree.hxx" #include using namespace ::com::sun::star::task; FolderTree::FolderTree(std::unique_ptr xTreeView, weld::Window* pTopLevel) : m_xTreeView(std::move(xTreeView)) , m_pTopLevel(pTopLevel) { m_xTreeView->set_size_request(m_xTreeView->get_approximate_digit_width() * 24, m_xTreeView->get_height_rows(7)); Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext(); Reference< XInteractionHandler > xInteractionHandler( InteractionHandler::createWithParent(xContext, pTopLevel->GetXWindow()), UNO_QUERY_THROW); m_xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() ); m_xTreeView->connect_expanding(LINK(this, FolderTree, RequestingChildrenHdl)); } IMPL_LINK(FolderTree, RequestingChildrenHdl, const weld::TreeIter&, rEntry, bool) { weld::WaitObject aWait(m_pTopLevel); FillTreeEntry(rEntry); return true; } void FolderTree::InsertRootEntry(const OUString& rId, const OUString& rRootLabel) { std::unique_ptr xEntry(m_xTreeView->make_iterator()); OUString sFolderImage(RID_BMP_FOLDER); m_xTreeView->insert(nullptr, -1, &rRootLabel, &rId, nullptr, nullptr, &sFolderImage, true, xEntry.get()); m_xTreeView->set_cursor(*xEntry); } void FolderTree::FillTreeEntry(const weld::TreeIter& rEntry) { OUString sURL = m_xTreeView->get_id(rEntry); OUString sFolderImage(RID_BMP_FOLDER); if (m_sLastUpdatedDir != sURL) { while (m_xTreeView->iter_has_child(rEntry)) { std::unique_ptr xChild(m_xTreeView->make_iterator(&rEntry)); (void)m_xTreeView->iter_children(*xChild); m_xTreeView->remove(*xChild); } ::std::vector< std::unique_ptr > aContent; ::rtl::Reference< ::svt::FileViewContentEnumerator > xContentEnumerator(new FileViewContentEnumerator( m_xEnv, aContent, m_aMutex)); FolderDescriptor aFolder(sURL); EnumerationResult eResult = xContentEnumerator->enumerateFolderContentSync( aFolder, m_aBlackList ); if (EnumerationResult::SUCCESS == eResult) { for(const auto & i : aContent) { if (!i->mbIsFolder) continue; m_xTreeView->insert(&rEntry, -1, &i->GetTitle(), &i->maTargetURL, nullptr, nullptr, &sFolderImage, true, nullptr); } } } else { // this dir was updated recently // next time read this remote folder m_sLastUpdatedDir.clear(); } } void FolderTree::FillTreeEntry( const OUString & rUrl, const ::std::vector< std::pair< OUString, OUString > >& rFolders ) { SetTreePath(rUrl); std::unique_ptr xParent(m_xTreeView->make_iterator()); bool bParent = m_xTreeView->get_cursor(xParent.get()); if (!bParent || m_xTreeView->get_row_expanded(*xParent)) return; OUString sFolderImage(RID_BMP_FOLDER); while (m_xTreeView->iter_has_child(*xParent)) { std::unique_ptr xChild(m_xTreeView->make_iterator(xParent.get())); (void)m_xTreeView->iter_children(*xChild); m_xTreeView->remove(*xChild); } for (auto const& folder : rFolders) { m_xTreeView->insert(xParent.get(), -1, &folder.first, &folder.second, nullptr, nullptr, &sFolderImage, true, nullptr); } m_sLastUpdatedDir = rUrl; m_xTreeView->expand_row(*xParent); } void FolderTree::SetTreePath( OUString const & sUrl ) { INetURLObject aUrl( sUrl ); aUrl.setFinalSlash(); OUString sPath = aUrl.GetURLPath( INetURLObject::DecodeMechanism::WithCharset ); std::unique_ptr xEntry(m_xTreeView->make_iterator()); bool bEntry = m_xTreeView->get_iter_first(*xEntry); bool bEnd = false; while (bEntry && !bEnd) { if (!m_xTreeView->get_id(*xEntry).isEmpty()) { OUString sNodeUrl = m_xTreeView->get_id(*xEntry); INetURLObject aUrlObj( sNodeUrl ); aUrlObj.setFinalSlash(); sNodeUrl = aUrlObj.GetURLPath( INetURLObject::DecodeMechanism::WithCharset ); if( sPath == sNodeUrl ) { m_xTreeView->select(*xEntry); bEnd = true; } else if( sPath.startsWith( sNodeUrl ) ) { if (!m_xTreeView->get_row_expanded(*xEntry)) m_xTreeView->expand_row(*xEntry); bEntry = m_xTreeView->iter_children(*xEntry); } else { bEntry = m_xTreeView->iter_next_sibling(*xEntry); } } else break; } } void FolderTree::SetBlackList( const css::uno::Sequence< OUString >& rBlackList ) { m_aBlackList = rBlackList; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */