Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 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 |
comparison
equal
deleted
inserted
replaced
759:5f8fc01e01c7 | 760:3a63f1f61bd6 |
---|---|
1464 | 1464 |
1465 bool canImportLayer = (getMainModel() != nullptr && | 1465 bool canImportLayer = (getMainModel() != nullptr && |
1466 m_paneStack != nullptr && | 1466 m_paneStack != nullptr && |
1467 m_paneStack->getCurrentPane() != nullptr); | 1467 m_paneStack->getCurrentPane() != nullptr); |
1468 | 1468 |
1469 bool rdf = (source.getExtension().toLower() == "rdf" || | 1469 QString extension = source.getExtension().toLower(); |
1470 source.getExtension().toLower() == "n3" || | 1470 |
1471 source.getExtension().toLower() == "ttl"); | 1471 bool rdf = (extension == "rdf" || extension == "n3" || extension == "ttl"); |
1472 | 1472 bool audio = |
1473 bool audio = AudioFileReaderFactory::getKnownExtensions().contains | 1473 AudioFileReaderFactory::getKnownExtensions().contains(extension); |
1474 (source.getExtension().toLower()); | |
1475 | 1474 |
1476 bool rdfSession = false; | 1475 bool rdfSession = false; |
1477 if (rdf) { | 1476 if (rdf) { |
1478 RDFImporter::RDFDocumentType rdfType = | 1477 RDFImporter::RDFDocumentType rdfType = |
1479 RDFImporter::identifyDocumentType | 1478 RDFImporter::identifyDocumentType |
1480 (QUrl::fromLocalFile(source.getLocalFilename()).toString()); | 1479 (QUrl::fromLocalFile(source.getLocalFilename())); |
1481 if (rdfType == RDFImporter::AudioRefAndAnnotations || | 1480 if (rdfType == RDFImporter::AudioRefAndAnnotations || |
1482 rdfType == RDFImporter::AudioRef) { | 1481 rdfType == RDFImporter::AudioRef) { |
1483 rdfSession = true; | 1482 rdfSession = true; |
1484 } else if (rdfType == RDFImporter::NotRDF) { | 1483 } else if (rdfType == RDFImporter::NotRDF) { |
1485 rdf = false; | 1484 rdf = false; |
1908 source.waitForData(); | 1907 source.waitForData(); |
1909 | 1908 |
1910 QString path = source.getLocalFilename(); | 1909 QString path = source.getLocalFilename(); |
1911 | 1910 |
1912 RDFImporter::RDFDocumentType rdfType = | 1911 RDFImporter::RDFDocumentType rdfType = |
1913 RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString()); | 1912 RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path)); |
1914 | 1913 |
1915 // cerr << "RDF type: (in layer) " << (int) rdfType << endl; | 1914 // cerr << "RDF type: (in layer) " << (int) rdfType << endl; |
1916 | 1915 |
1917 if (rdfType != RDFImporter::NotRDF) { | 1916 if (rdfType != RDFImporter::NotRDF) { |
1918 | 1917 |
2137 source.waitForData(); | 2136 source.waitForData(); |
2138 | 2137 |
2139 QString sessionExt = | 2138 QString sessionExt = |
2140 InteractiveFileFinder::getInstance()->getApplicationSessionExtension(); | 2139 InteractiveFileFinder::getInstance()->getApplicationSessionExtension(); |
2141 | 2140 |
2142 if (source.getExtension().toLower() != sessionExt) { | 2141 QString extension = source.getExtension().toLower(); |
2143 | 2142 |
2144 RDFImporter::RDFDocumentType rdfType = | 2143 bool rdf = (extension == "rdf" || extension == "n3" || extension == "ttl"); |
2145 RDFImporter::identifyDocumentType | 2144 |
2146 (QUrl::fromLocalFile(source.getLocalFilename()).toString()); | 2145 if (extension != sessionExt) { |
2146 | |
2147 if (rdf) { | |
2148 | |
2149 RDFImporter::RDFDocumentType rdfType = | |
2150 RDFImporter::identifyDocumentType | |
2151 (QUrl::fromLocalFile(source.getLocalFilename())); | |
2147 | 2152 |
2148 // cerr << "RDF type: " << (int)rdfType << endl; | 2153 // cerr << "RDF type: " << (int)rdfType << endl; |
2149 | 2154 |
2150 if (rdfType == RDFImporter::AudioRefAndAnnotations || | 2155 if (rdfType == RDFImporter::AudioRefAndAnnotations || |
2151 rdfType == RDFImporter::AudioRef) { | 2156 rdfType == RDFImporter::AudioRef) { |
2152 return openSessionFromRDF(source); | 2157 return openSessionFromRDF(source); |
2153 } else if (rdfType != RDFImporter::NotRDF) { | 2158 } else if (rdfType != RDFImporter::NotRDF) { |
2154 return FileOpenFailed; | 2159 return FileOpenFailed; |
2155 } | 2160 } |
2156 | 2161 |
2157 if (source.getExtension().toLower() == "xml") { | 2162 } else if (extension == "xml") { |
2163 | |
2158 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) == | 2164 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) == |
2159 SVFileReader::SVSessionFile) { | 2165 SVFileReader::SVSessionFile) { |
2160 cerr << "This XML file looks like a session file, attempting to open it as a session" << endl; | 2166 cerr << "This XML file looks like a session file, attempting to open it as a session" << endl; |
2161 } else { | 2167 } else { |
2162 return FileOpenFailed; | 2168 return FileOpenFailed; |
2168 | 2174 |
2169 QXmlInputSource *inputSource = nullptr; | 2175 QXmlInputSource *inputSource = nullptr; |
2170 BZipFileDevice *bzFile = nullptr; | 2176 BZipFileDevice *bzFile = nullptr; |
2171 QFile *rawFile = nullptr; | 2177 QFile *rawFile = nullptr; |
2172 | 2178 |
2173 if (source.getExtension().toLower() == sessionExt) { | 2179 if (extension == sessionExt) { |
2174 bzFile = new BZipFileDevice(source.getLocalFilename()); | 2180 bzFile = new BZipFileDevice(source.getLocalFilename()); |
2175 if (!bzFile->open(QIODevice::ReadOnly)) { | 2181 if (!bzFile->open(QIODevice::ReadOnly)) { |
2176 delete bzFile; | 2182 delete bzFile; |
2177 return FileOpenFailed; | 2183 return FileOpenFailed; |
2178 } | 2184 } |