diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index a2608c22a2582b53e857f916ad119bb283a293f0..39b1bd46c89f5ad43562c04508a8b61b9ab8db4b 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1806,12 +1806,10 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::audioItemToLinkedAudio(UBGraphicsAud } QString audioFileHref = audioItem->mediaFileUrl().toString(); - //on windows - if(audioFileHref.startsWith("file:///")) - audioFileHref = audioFileHref.replace("file:///" + mDocumentPath + "/",""); - //mac and linux - if(audioFileHref.startsWith("file://")) - audioFileHref = audioFileHref.replace("file://" + mDocumentPath + "/",""); + audioFileHref = UBFileSystemUtils::removeLocalFilePrefix(audioFileHref); + if(audioFileHref.startsWith(mDocumentPath)) + audioFileHref = audioFileHref.replace(mDocumentPath + "/",""); + mXmlWriter.writeAttribute(nsXLink, "href", audioFileHref); mXmlWriter.writeEndElement(); } @@ -1837,13 +1835,11 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::videoItemToLinkedVideo(UBGraphicsVid } QString videoFileHref = videoItem->mediaFileUrl().toString(); - //on windows - if(videoFileHref.startsWith("file:///")) - videoFileHref = videoFileHref.replace("file:///" + mDocumentPath + "/",""); - //on mac and linux - if(videoFileHref.startsWith("file://")) - videoFileHref = videoFileHref.replace("file://" + mDocumentPath + "/",""); - mXmlWriter.writeAttribute(nsXLink, "href", videoFileHref); + + videoFileHref = UBFileSystemUtils::removeLocalFilePrefix(videoFileHref); + if(videoFileHref.startsWith(mDocumentPath)) + videoFileHref = videoFileHref.replace(mDocumentPath + "/",""); + mXmlWriter.writeAttribute(nsXLink, "href", videoFileHref); mXmlWriter.writeEndElement(); } diff --git a/src/domain/UBW3CWidget.cpp b/src/domain/UBW3CWidget.cpp index 599380a6a317861d026e78ab812bcd630a94ebef..7367036dfbe84a261d5290394d0f1791bdad970a 100644 --- a/src/domain/UBW3CWidget.cpp +++ b/src/domain/UBW3CWidget.cpp @@ -246,9 +246,7 @@ QString UBW3CWidget::createNPAPIWrapperInDir(const QString& pUrl, const QDir& pD const QString& pName) { QString url = pUrl; - // if the file name start with file:// it has be removed because QFileInfo doesn't support this form - url = url.replace("file:///",""); - url = url.replace("file://",""); + url = UBFileSystemUtils::removeLocalFilePrefix(url); QString name = pName; QFileInfo fi(url); @@ -305,8 +303,7 @@ QString UBW3CWidget::createNPAPIWrapperInDir(const QString& pUrl, const QDir& pD if (fi.exists()){ QString target = widgetLibraryPath + "/" + fi.fileName(); QString source = pUrl; - source = source.replace("file:///",""); - source = source.replace("file://",""); + source = UBFileSystemUtils::removeLocalFilePrefix(source); QFile::copy(source, target); } diff --git a/src/frameworks/UBFileSystemUtils.cpp b/src/frameworks/UBFileSystemUtils.cpp index 97a7d15734f63ef06e238671be1d59ec2514cf9c..26f0e85acfc2f14066c3aa0181eeb3cb5cc2ab7d 100644 --- a/src/frameworks/UBFileSystemUtils.cpp +++ b/src/frameworks/UBFileSystemUtils.cpp @@ -39,6 +39,22 @@ UBFileSystemUtils::~UBFileSystemUtils() // NOOP } + +QString UBFileSystemUtils::removeLocalFilePrefix(QString input) +{ +#ifdef Q_WS_WIN + if(input.startsWith("file:///")) + return input.mid(8); + else + return input; +#else + if(input.startsWith("file://")) + return input.mid(7); + else + return input; +#endif +} + bool UBFileSystemUtils::isAZipFile(QString &filePath) { if(QFileInfo(filePath).isDir()) return false; diff --git a/src/frameworks/UBFileSystemUtils.h b/src/frameworks/UBFileSystemUtils.h index bd20755bd4c68576cca42c29f76d6668f1f7806a..ebf4bc7828017391f73d6fa628a4b802b85bf96d 100644 --- a/src/frameworks/UBFileSystemUtils.h +++ b/src/frameworks/UBFileSystemUtils.h @@ -28,6 +28,8 @@ class UBFileSystemUtils UBFileSystemUtils(); virtual ~UBFileSystemUtils(); + static QString removeLocalFilePrefix(QString input); + static QString defaultTempDirName() { return QCoreApplication::applicationName(); } static QString defaultTempDirPath(); static QString createTempDir(const QString& templateString = defaultTempDirName(), bool autoDeleteOnExit = true);