tdf#158510 Launch media from a presentation dir path

Added a check for the existence of a file at a given URL.
If the specified file could not be found, the path formed from the
directory containing the presentation file and the file name is used.

Change-Id: Ia4124f4fa5e5cef19c81f325676749a2540e486a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164023
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Vladislav Tarakanov
2024-07-12 14:02:42 +02:00
committed by Mike Kaganski
parent 7fbce44cac
commit fe897b36ae
+12
View File
@@ -30,6 +30,7 @@
#include <svx/svdomedia.hxx>
#include <svx/svdpool.hxx>
#include <comphelper/classids.hxx>
#include <comphelper/DirectoryHelper.hxx>
#include <comphelper/embeddedobjectcontainer.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/propertyvalue.hxx>
@@ -822,6 +823,17 @@ bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPr
if( rValue >>= aURL )
{
bOk = true;
if ( aURL.startsWith("file:///") && !comphelper::DirectoryHelper::fileExists(aURL) )
{
comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
auto fileDirectoryEndIdx = pPersist->getDocumentBaseURL().lastIndexOf("/");
auto fileNameStartIdx = aURL.lastIndexOf("/");
if (fileDirectoryEndIdx != -1 && fileNameStartIdx != -1)
{
aURL = OUString::Concat(pPersist->getDocumentBaseURL().subView(0, fileDirectoryEndIdx + 1))
+ aURL.subView(fileNameStartIdx + 1);
}
}
aItem.setURL( aURL, u""_ustr, referer_ );
}
}