From f845ee17d52bca18b86bf6f28a74147085175d6a Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 18 Oct 2021 09:58:26 +0100 Subject: Related: tdf#145169 use INetURLObject::getName and removeSegment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to get the name and link for each part of the path otherwise for sftp:// clicking on the "Root" doesn't work for me Change-Id: If6f0ac8f105afd8be2d264b54f76a3d8f345ad75 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123735 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- fpicker/source/office/breadcrumb.cxx | 56 ++++++++++++++---------------------- 1 file changed, 22 insertions(+), 34 deletions(-) (limited to 'fpicker') diff --git a/fpicker/source/office/breadcrumb.cxx b/fpicker/source/office/breadcrumb.cxx index d884d5b3fc8e..0b27367d8a8e 100644 --- a/fpicker/source/office/breadcrumb.cxx +++ b/fpicker/source/office/breadcrumb.cxx @@ -68,61 +68,49 @@ void Breadcrumb::SetRootName( const OUString& rURL ) void Breadcrumb::SetURL( const OUString& rURL ) { m_aCurrentURL = rURL; - INetURLObject aURL( rURL ); + INetURLObject aURL(rURL); aURL.setFinalSlash(); - //prepare the Host port - OUString sHostPort; - if( aURL.HasPort() ) - { - sHostPort += ":" + OUString::number( aURL.GetPort() ); - } - - OUString sUser = aURL.GetUser( INetURLObject::DecodeMechanism::NONE ); - OUString sPath = aURL.GetURLPath(INetURLObject::DecodeMechanism::WithCharset); - OUString sRootPath = INetURLObject::GetScheme( aURL.GetProtocol() ) - + sUser - + ( sUser.isEmpty() ? OUString() : "@" ) - + aURL.GetHost() - + sHostPort; + bool bClear = m_eMode == SvtBreadcrumbMode::ONLY_CURRENT_PATH; int nSegments = aURL.getSegmentCount(); - unsigned int nPos = 0; - bool bClear = ( m_eMode == SvtBreadcrumbMode::ONLY_CURRENT_PATH ); - - // root field - m_aSegments[0]->m_xLink->set_label( m_sRootName ); - m_aSegments[0]->m_xLink->set_sensitive(true); - m_aSegments[0]->m_xLink->set_uri(sRootPath); - m_aUris[m_aSegments[0]->m_xLink.get()] = sRootPath; + size_t nVecSizeRequired = nSegments + 1; - // fill the other fields + while (m_aSegments.size() < nVecSizeRequired) + appendField(); - for( unsigned int i = 1; i < static_cast(nSegments) + 1; i++ ) + // fill the fields under root + for (int i = nSegments; i; --i) { - if( i >= m_aSegments.size() ) - appendField(); + OUString sLabel = aURL.getName(INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset); + OUString sLink = aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); - unsigned int nEnd = sPath.indexOf( '/', nPos + 1 ); - OUString sLabel = sPath.copy( nPos + 1, nEnd - nPos - 1 ); - - if( m_eMode == SvtBreadcrumbMode::ALL_VISITED ) + if (m_eMode == SvtBreadcrumbMode::ALL_VISITED) { if( m_aSegments[i]->m_xLink->get_label() != sLabel ) bClear = true; } - m_aSegments[i]->m_xLink->set_label( sLabel ); - m_aUris[m_aSegments[i]->m_xLink.get()] = sRootPath + sPath.subView(0, nEnd); m_aSegments[i]->m_xLink->hide(); + m_aSegments[i]->m_xLink->set_label(sLabel); m_aSegments[i]->m_xLink->set_sensitive(true); + m_aSegments[i]->m_xLink->set_uri(sLink); + m_aUris[m_aSegments[i]->m_xLink.get()] = sLink; m_aSegments[i]->m_xSeparator->hide(); - nPos = nEnd; + aURL.removeSegment(); } + OUString sRootPath = aURL.GetMainURL(INetURLObject::DecodeMechanism::WithCharset); + + // root field + m_aSegments[0]->m_xLink->set_label( m_sRootName ); + m_aSegments[0]->m_xLink->set_sensitive(true); + m_aSegments[0]->m_xLink->set_uri(sRootPath); + m_aUris[m_aSegments[0]->m_xLink.get()] = sRootPath; + // clear unused fields for (size_t i = nSegments + 1; i < m_aSegments.size(); i++ ) { -- cgit v1.2.3