diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index a2608c22..39b1bd46 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 599380a6..7367036d 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 97a7d157..26f0e85a 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 bd20755b..ebf4bc78 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);