Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 140:9ccaa8fd9b9f
* Add code to identify (usually) the type of an XML file that contains
either SV session or layer data, and use it to permit loading files
with plain .xml extension that contain complete uncompression sessions
author | Chris Cannam |
---|---|
date | Thu, 20 Nov 2008 10:59:14 +0000 |
parents | 2cf711ed89e2 |
children | 9a8c73ffdce0 |
comparison
equal
deleted
inserted
replaced
139:2cf711ed89e2 | 140:9ccaa8fd9b9f |
---|---|
1155 return FileOpenSucceeded; | 1155 return FileOpenSucceeded; |
1156 } | 1156 } |
1157 | 1157 |
1158 return FileOpenFailed; | 1158 return FileOpenFailed; |
1159 | 1159 |
1160 } else if (source.getExtension() == "svl" || source.getExtension() == "xml") { | 1160 } else if (source.getExtension() == "svl" || |
1161 (source.getExtension() == "xml" && | |
1162 (SVFileReader::identifyXmlFile(source.getLocalFilename()) | |
1163 == SVFileReader::SVLayerFile))) { | |
1161 | 1164 |
1162 PaneCallback callback(this); | 1165 PaneCallback callback(this); |
1163 QFile file(path); | 1166 QFile file(path); |
1164 | 1167 |
1165 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | 1168 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
1312 MainWindowBase::openSession(FileSource source) | 1315 MainWindowBase::openSession(FileSource source) |
1313 { | 1316 { |
1314 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl; | 1317 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl; |
1315 | 1318 |
1316 if (!source.isAvailable()) return FileOpenFailed; | 1319 if (!source.isAvailable()) return FileOpenFailed; |
1317 if (source.getExtension() != "sv") return FileOpenFailed; | 1320 |
1321 if (source.getExtension() != "sv") { | |
1322 if (source.getExtension() == "xml") { | |
1323 source.waitForData(); | |
1324 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) == | |
1325 SVFileReader::SVSessionFile) { | |
1326 std::cerr << "This XML file looks like a session file, attempting to open it as a session" << std::endl; | |
1327 } else { | |
1328 return FileOpenFailed; | |
1329 } | |
1330 } else { | |
1331 return FileOpenFailed; | |
1332 } | |
1333 } | |
1318 source.waitForData(); | 1334 source.waitForData(); |
1319 | 1335 |
1320 BZipFileDevice bzFile(source.getLocalFilename()); | 1336 QXmlInputSource *inputSource = 0; |
1321 if (!bzFile.open(QIODevice::ReadOnly)) return FileOpenFailed; | 1337 BZipFileDevice *bzFile = 0; |
1322 | 1338 QFile *rawFile = 0; |
1323 if (!checkSaveModified()) return FileOpenCancelled; | 1339 |
1340 if (source.getExtension() == "sv") { | |
1341 bzFile = new BZipFileDevice(source.getLocalFilename()); | |
1342 if (!bzFile->open(QIODevice::ReadOnly)) { | |
1343 delete bzFile; | |
1344 return FileOpenFailed; | |
1345 } | |
1346 inputSource = new QXmlInputSource(bzFile); | |
1347 } else { | |
1348 rawFile = new QFile(source.getLocalFilename()); | |
1349 inputSource = new QXmlInputSource(rawFile); | |
1350 } | |
1351 | |
1352 if (!checkSaveModified()) { | |
1353 if (bzFile) bzFile->close(); | |
1354 delete inputSource; | |
1355 delete bzFile; | |
1356 delete rawFile; | |
1357 return FileOpenCancelled; | |
1358 } | |
1324 | 1359 |
1325 QString error; | 1360 QString error; |
1326 closeSession(); | 1361 closeSession(); |
1327 createDocument(); | 1362 createDocument(); |
1328 | 1363 |
1334 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)), | 1369 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)), |
1335 this, SLOT(modelRegenerationFailed(QString, QString, QString))); | 1370 this, SLOT(modelRegenerationFailed(QString, QString, QString))); |
1336 connect | 1371 connect |
1337 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)), | 1372 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)), |
1338 this, SLOT(modelRegenerationWarning(QString, QString, QString))); | 1373 this, SLOT(modelRegenerationWarning(QString, QString, QString))); |
1339 QXmlInputSource inputSource(&bzFile); | 1374 |
1340 reader.parse(inputSource); | 1375 reader.parse(*inputSource); |
1341 | 1376 |
1342 if (!reader.isOK()) { | 1377 if (!reader.isOK()) { |
1343 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString()); | 1378 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString()); |
1344 } | 1379 } |
1345 | 1380 |
1346 bzFile.close(); | 1381 if (bzFile) bzFile->close(); |
1382 | |
1383 delete inputSource; | |
1384 delete bzFile; | |
1385 delete rawFile; | |
1347 | 1386 |
1348 bool ok = (error == ""); | 1387 bool ok = (error == ""); |
1349 | 1388 |
1350 if (ok) { | 1389 if (ok) { |
1351 | 1390 |