Mercurial > hg > svapp
changeset 760:3a63f1f61bd6
Don't try to open an RDF document unless it has an RDF-like extension
author | Chris Cannam |
---|---|
date | Thu, 30 Apr 2020 14:48:14 +0100 |
parents | 5f8fc01e01c7 |
children | 83ae68de4401 da57ab54f0e8 |
files | framework/MainWindowBase.cpp |
diffstat | 1 files changed, 28 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/framework/MainWindowBase.cpp Wed Apr 29 17:48:20 2020 +0100 +++ b/framework/MainWindowBase.cpp Thu Apr 30 14:48:14 2020 +0100 @@ -1466,18 +1466,17 @@ m_paneStack != nullptr && m_paneStack->getCurrentPane() != nullptr); - bool rdf = (source.getExtension().toLower() == "rdf" || - source.getExtension().toLower() == "n3" || - source.getExtension().toLower() == "ttl"); - - bool audio = AudioFileReaderFactory::getKnownExtensions().contains - (source.getExtension().toLower()); + QString extension = source.getExtension().toLower(); + + bool rdf = (extension == "rdf" || extension == "n3" || extension == "ttl"); + bool audio = + AudioFileReaderFactory::getKnownExtensions().contains(extension); bool rdfSession = false; if (rdf) { RDFImporter::RDFDocumentType rdfType = RDFImporter::identifyDocumentType - (QUrl::fromLocalFile(source.getLocalFilename()).toString()); + (QUrl::fromLocalFile(source.getLocalFilename())); if (rdfType == RDFImporter::AudioRefAndAnnotations || rdfType == RDFImporter::AudioRef) { rdfSession = true; @@ -1910,7 +1909,7 @@ QString path = source.getLocalFilename(); RDFImporter::RDFDocumentType rdfType = - RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString()); + RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path)); // cerr << "RDF type: (in layer) " << (int) rdfType << endl; @@ -2139,22 +2138,29 @@ QString sessionExt = InteractiveFileFinder::getInstance()->getApplicationSessionExtension(); - if (source.getExtension().toLower() != sessionExt) { - - RDFImporter::RDFDocumentType rdfType = - RDFImporter::identifyDocumentType - (QUrl::fromLocalFile(source.getLocalFilename()).toString()); + QString extension = source.getExtension().toLower(); + + bool rdf = (extension == "rdf" || extension == "n3" || extension == "ttl"); + + if (extension != sessionExt) { + + if (rdf) { + + RDFImporter::RDFDocumentType rdfType = + RDFImporter::identifyDocumentType + (QUrl::fromLocalFile(source.getLocalFilename())); // cerr << "RDF type: " << (int)rdfType << endl; - if (rdfType == RDFImporter::AudioRefAndAnnotations || - rdfType == RDFImporter::AudioRef) { - return openSessionFromRDF(source); - } else if (rdfType != RDFImporter::NotRDF) { - return FileOpenFailed; - } - - if (source.getExtension().toLower() == "xml") { + if (rdfType == RDFImporter::AudioRefAndAnnotations || + rdfType == RDFImporter::AudioRef) { + return openSessionFromRDF(source); + } else if (rdfType != RDFImporter::NotRDF) { + return FileOpenFailed; + } + + } else if (extension == "xml") { + if (SVFileReader::identifyXmlFile(source.getLocalFilename()) == SVFileReader::SVSessionFile) { cerr << "This XML file looks like a session file, attempting to open it as a session" << endl; @@ -2170,7 +2176,7 @@ BZipFileDevice *bzFile = nullptr; QFile *rawFile = nullptr; - if (source.getExtension().toLower() == sessionExt) { + if (extension == sessionExt) { bzFile = new BZipFileDevice(source.getLocalFilename()); if (!bzFile->open(QIODevice::ReadOnly)) { delete bzFile;