comparison framework/MainWindowBase.cpp @ 227:a6398a7400c1 templating

Break out openSessionTemplate into its own method, so as to ensure it doesn't do any of that stuff like setting the session save path or last loaded-from location
author Chris Cannam
date Wed, 11 May 2011 13:49:21 +0100
parents 2c827ac7c8e7
children 976d43d3c67d
comparison
equal deleted inserted replaced
226:2c827ac7c8e7 227:a6398a7400c1
1082 return FileOpenFailed; 1082 return FileOpenFailed;
1083 } 1083 }
1084 } 1084 }
1085 1085
1086 MainWindowBase::FileOpenStatus 1086 MainWindowBase::FileOpenStatus
1087 MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode, QString templateName) 1087 MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode,
1088 QString templateName)
1088 { 1089 {
1089 // std::cerr << "MainWindowBase::openAudio(" << source.getLocation().toStdString() << ")" << std::endl; 1090 // std::cerr << "MainWindowBase::openAudio(" << source.getLocation().toStdString() << ")" << std::endl;
1090 1091
1091 if (templateName == "") { 1092 if (templateName == "") {
1092 templateName = m_defaultSessionTemplate; 1093 templateName = m_defaultSessionTemplate;
1194 // open directly from the bundled file (where applicable) 1195 // open directly from the bundled file (where applicable)
1195 ResourceFinder rf; 1196 ResourceFinder rf;
1196 QString tfile = rf.getResourcePath("templates", templateName + ".svt"); 1197 QString tfile = rf.getResourcePath("templates", templateName + ".svt");
1197 if (tfile != "") { 1198 if (tfile != "") {
1198 std::cerr << "SV loading template file " << tfile.toStdString() << std::endl; 1199 std::cerr << "SV loading template file " << tfile.toStdString() << std::endl;
1199 FileOpenStatus tplStatus = openSessionFile("file:" + tfile); 1200 FileOpenStatus tplStatus = openSessionTemplate("file:" + tfile);
1200 if (tplStatus != FileOpenFailed) { 1201 if (tplStatus != FileOpenFailed) {
1201 std::cerr << "Template load succeeded" << std::endl; 1202 std::cerr << "Template load succeeded" << std::endl;
1202 loadedTemplate = true; 1203 loadedTemplate = true;
1203 } 1204 }
1204 } 1205 }
1562 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl; 1563 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl;
1563 1564
1564 if (!source.isAvailable()) return FileOpenFailed; 1565 if (!source.isAvailable()) return FileOpenFailed;
1565 source.waitForData(); 1566 source.waitForData();
1566 1567
1567 if (source.getExtension().toLower() != "sv" && 1568 if (source.getExtension().toLower() != "sv") {
1568 source.getExtension().toLower() != "svt") {
1569 1569
1570 RDFImporter::RDFDocumentType rdfType = 1570 RDFImporter::RDFDocumentType rdfType =
1571 RDFImporter::identifyDocumentType 1571 RDFImporter::identifyDocumentType
1572 (QUrl::fromLocalFile(source.getLocalFilename()).toString()); 1572 (QUrl::fromLocalFile(source.getLocalFilename()).toString());
1573 1573
1593 } 1593 }
1594 1594
1595 QXmlInputSource *inputSource = 0; 1595 QXmlInputSource *inputSource = 0;
1596 BZipFileDevice *bzFile = 0; 1596 BZipFileDevice *bzFile = 0;
1597 QFile *rawFile = 0; 1597 QFile *rawFile = 0;
1598 bool isTemplate = false;
1599 1598
1600 if (source.getExtension().toLower() == "sv") { 1599 if (source.getExtension().toLower() == "sv") {
1601 bzFile = new BZipFileDevice(source.getLocalFilename()); 1600 bzFile = new BZipFileDevice(source.getLocalFilename());
1602 if (!bzFile->open(QIODevice::ReadOnly)) { 1601 if (!bzFile->open(QIODevice::ReadOnly)) {
1603 delete bzFile; 1602 delete bzFile;
1604 return FileOpenFailed; 1603 return FileOpenFailed;
1605 } 1604 }
1606 inputSource = new QXmlInputSource(bzFile); 1605 inputSource = new QXmlInputSource(bzFile);
1607 } else { 1606 } else {
1608 if (source.getExtension().toLower() == "svt") {
1609 isTemplate = true;
1610 }
1611 rawFile = new QFile(source.getLocalFilename()); 1607 rawFile = new QFile(source.getLocalFilename());
1612 inputSource = new QXmlInputSource(rawFile); 1608 inputSource = new QXmlInputSource(rawFile);
1613 } 1609 }
1614 1610
1615 if (!checkSaveModified()) { 1611 if (!checkSaveModified()) {
1664 CommandHistory::getInstance()->clear(); 1660 CommandHistory::getInstance()->clear();
1665 CommandHistory::getInstance()->documentSaved(); 1661 CommandHistory::getInstance()->documentSaved();
1666 m_documentModified = false; 1662 m_documentModified = false;
1667 updateMenuStates(); 1663 updateMenuStates();
1668 1664
1669 if (!isTemplate) { 1665 m_recentFiles.addFile(source.getLocation());
1670 m_recentFiles.addFile(source.getLocation());
1671 }
1672 1666
1673 if (!source.isRemote()) { 1667 if (!source.isRemote()) {
1674 // for file dialog 1668 // for file dialog
1675 registerLastOpenedFilePath(FileFinder::SessionFile, 1669 registerLastOpenedFilePath(FileFinder::SessionFile,
1676 source.getLocalFilename()); 1670 source.getLocalFilename());
1677 } 1671 }
1678 1672
1679 } else { 1673 } else {
1680 setWindowTitle(QApplication::applicationName()); 1674 setWindowTitle(QApplication::applicationName());
1675 }
1676
1677 return ok ? FileOpenSucceeded : FileOpenFailed;
1678 }
1679
1680 MainWindowBase::FileOpenStatus
1681 MainWindowBase::openSessionTemplate(FileSource source)
1682 {
1683 std::cerr << "MainWindowBase::openSessionTemplate(" << source.getLocation().toStdString() << ")" << std::endl;
1684
1685 if (!source.isAvailable()) return FileOpenFailed;
1686 source.waitForData();
1687
1688 QXmlInputSource *inputSource = 0;
1689 QFile *file = 0;
1690 bool isTemplate = false;
1691
1692 file = new QFile(source.getLocalFilename());
1693 inputSource = new QXmlInputSource(file);
1694
1695 if (!checkSaveModified()) {
1696 delete inputSource;
1697 delete file;
1698 return FileOpenCancelled;
1699 }
1700
1701 QString error;
1702 closeSession();
1703 createDocument();
1704
1705 PaneCallback callback(this);
1706 m_viewManager->clearSelections();
1707
1708 SVFileReader reader(m_document, callback, source.getLocation());
1709 connect
1710 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
1711 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
1712 connect
1713 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
1714 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
1715
1716 reader.parse(*inputSource);
1717
1718 if (!reader.isOK()) {
1719 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
1720 }
1721
1722 delete inputSource;
1723 delete file;
1724
1725 bool ok = (error == "");
1726
1727 setWindowTitle(QApplication::applicationName());
1728
1729 if (ok) {
1730
1731 emit activity(tr("Open session template \"%1\"").arg(source.getLocation()));
1732
1733 setupMenus();
1734
1735 CommandHistory::getInstance()->clear();
1736 CommandHistory::getInstance()->documentSaved();
1737 m_documentModified = false;
1738 updateMenuStates();
1681 } 1739 }
1682 1740
1683 return ok ? FileOpenSucceeded : FileOpenFailed; 1741 return ok ? FileOpenSucceeded : FileOpenFailed;
1684 } 1742 }
1685 1743