diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-04-09 17:20:30 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-04-09 21:16:11 +0200 |
commit | 6c6046a83e0285f4c4303ee8a049759113dac16d (patch) | |
tree | c667cd887691a633050b76be370d00e77fc7f6a7 /svtools | |
parent | b721a1cecb6ea0013be8402350110822e50b4415 (diff) |
Avoid user interaction when determining recent documents' MIME types
After 6fcabbd6199869753fd6a266f23901962a77f556 "tdf#129153: Show MIME type icon
in main menu File>Recent documents list", I e.g. got an "Authentication
Required" dialog asking for user name and password if there was an sftp URI
among my recent documents.
Change-Id: Ic772c500f9dd2bc2418ea7dbea966e8478a35729
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113887
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/misc/imagemgr.cxx | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/svtools/source/misc/imagemgr.cxx b/svtools/source/misc/imagemgr.cxx index 2a3932ac86a5..ff7fe554d869 100644 --- a/svtools/source/misc/imagemgr.cxx +++ b/svtools/source/misc/imagemgr.cxx @@ -29,6 +29,7 @@ #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/document/XTypeDetection.hpp> +#include <com/sun/star/ucb/CommandAbortedException.hpp> #include <com/sun/star/ucb/ContentCreationException.hpp> #include <com/sun/star/ucb/XCommandEnvironment.hpp> #include <com/sun/star/uno/XComponentContext.hpp> @@ -350,7 +351,25 @@ static SvImageId GetFolderImageId_Impl( const OUString& rURL ) return nRet; } -static SvImageId GetImageId_Impl( const INetURLObject& rObject, bool bDetectFolder ) +static bool isFolder( + OUString const & url, css::uno::Reference<css::ucb::XCommandEnvironment> const & env) +{ + try { + return ucbhelper::Content(url, env, comphelper::getProcessComponentContext()).isFolder(); + } catch (css::uno::RuntimeException &) { + throw; + } catch (css::ucb::CommandAbortedException &) { + assert(false); // this cannot happen + throw; + } catch (css::uno::Exception &) { + TOOLS_INFO_EXCEPTION("svtools.misc", "isFolder(" << url << ")"); + return false; + } +} + +static SvImageId GetImageId_Impl( + const INetURLObject& rObject, bool bDetectFolder, + css::uno::Reference<css::ucb::XCommandEnvironment> const & env ) { OUString aExt, sURL = rObject.GetMainURL( INetURLObject::DecodeMechanism::NONE ); SvImageId nImage = SvImageId::File; @@ -404,7 +423,7 @@ static SvImageId GetImageId_Impl( const INetURLObject& rObject, bool bDetectFold if ( nImage == SvImageId::File && !sURL.isEmpty() ) { - if ( bDetectFolder && CONTENT_HELPER::IsFolder( sURL ) ) + if ( bDetectFolder && isFolder( sURL, env ) ) nImage = GetFolderImageId_Impl( sURL ); else if ( !aExt.isEmpty() ) nImage = GetImageId_Impl( aExt ); @@ -783,28 +802,33 @@ OUString SvFileInformationManager::GetDescription_Impl( const INetURLObject& rOb OUString SvFileInformationManager::GetImageId(const INetURLObject& rObject, bool bBig) { - SvImageId nImage = GetImageId_Impl( rObject, true ); + SvImageId nImage = GetImageId_Impl( + rObject, true, utl::UCBContentHelper::getDefaultCommandEnvironment() ); DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" ); return GetImageNameFromList_Impl(nImage, bBig ? vcl::ImageType::Size26 : vcl::ImageType::Size16); } -Image SvFileInformationManager::GetImage(const INetURLObject& rObject, bool bBig) +Image SvFileInformationManager::GetImage( + const INetURLObject& rObject, bool bBig, + css::uno::Reference<css::ucb::XCommandEnvironment> const & env) { - SvImageId nImage = GetImageId_Impl( rObject, true ); + SvImageId nImage = GetImageId_Impl( rObject, true, env ); DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" ); return GetImageFromList_Impl(nImage, bBig ? vcl::ImageType::Size26 : vcl::ImageType::Size16); } OUString SvFileInformationManager::GetFileImageId(const INetURLObject& rObject) { - SvImageId nImage = GetImageId_Impl( rObject, false ); + SvImageId nImage = GetImageId_Impl( + rObject, false, utl::UCBContentHelper::getDefaultCommandEnvironment() ); DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" ); return GetImageNameFromList_Impl(nImage, vcl::ImageType::Size16); } Image SvFileInformationManager::GetImageNoDefault(const INetURLObject& rObject, vcl::ImageType eImageType) { - SvImageId nImage = GetImageId_Impl(rObject, true); + SvImageId nImage = GetImageId_Impl( + rObject, true, utl::UCBContentHelper::getDefaultCommandEnvironment()); DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" ); if ( nImage == SvImageId::File ) |