diff document/SVFileReader.cpp @ 88:51be0daa1386

Several changes related to referring to remote URLs for sessions and files: * Pull file dialog wrapper functions out from MainWindow into FileFinder * If a file referred to in a session is not found at its expected location, try a few other alternatives (same location as the session file or same location as the last audio file) before asking the user to locate it * Allow user to give a URL when locating an audio file, not just locate on the filesystem * Make wave file models remember the "original" location (e.g. URL) of the audio file, not just the actual location from which the data was loaded (e.g. local copy of that URL) -- when saving a session, use the original location so as not to refer to a temporary file * Clean up incompletely-downloaded local copies of files
author Chris Cannam
date Thu, 11 Jan 2007 13:29:58 +0000
parents 8944f3005a15
children e6c4b27cba2c
line wrap: on
line diff
--- a/document/SVFileReader.cpp	Wed Jan 10 17:26:39 2007 +0000
+++ b/document/SVFileReader.cpp	Thu Jan 11 13:29:58 2007 +0000
@@ -499,8 +499,10 @@
     if (type == "wavefile") {
 	
         WaveFileModel *model = 0;
-        FileFinder finder(attributes.value("file"), m_location);
-        QString path = finder.getLocation();
+        FileFinder *ff = FileFinder::getInstance();
+        QString originalPath = attributes.value("file");
+        QString path = ff->find(FileFinder::AudioFile,
+                                originalPath, m_location);
         QUrl url(path);
 
         if (RemoteFile::canHandleScheme(url)) {
@@ -509,7 +511,8 @@
             rf.wait();
 
             if (rf.isOK()) {
-                model = new WaveFileModel(rf.getLocalFilename());
+
+                model = new WaveFileModel(rf.getLocalFilename(), path);
                 if (!model->isOK()) {
                     delete model;
                     model = 0;
@@ -527,37 +530,6 @@
 
         if (!model) return false;
 
-/*
-	QString file = attributes.value("file");
-	WaveFileModel *model = new WaveFileModel(file);
-
-	while (!model->isOK()) {
-
-	    delete model;
-	    model = 0;
-
-	    if (QMessageBox::question(0,
-				      QMessageBox::tr("Failed to open file"),
-				      QMessageBox::tr("Audio file \"%1\" could not be opened.\nLocate it?").arg(file),
-				      QMessageBox::Ok,
-				      QMessageBox::Cancel) == QMessageBox::Ok) {
-
-		QString path = QFileDialog::getOpenFileName
-		    (0, QFileDialog::tr("Locate file \"%1\"").arg(QFileInfo(file).fileName()), file,
-		     QFileDialog::tr("Audio files (%1)\nAll files (*.*)")
-		     .arg(AudioFileReaderFactory::getKnownExtensions()));
-
-		if (path != "") {
-		    model = new WaveFileModel(path);
-		} else {
-		    return false;
-		}
-	    } else {
-		return false;
-	    }
-	}
-*/
-
 	m_models[id] = model;
 	if (mainModel) {
 	    m_document->setMainModel(model);
@@ -665,7 +637,7 @@
     } else {
 
 	std::cerr << "WARNING: SV-XML: Unexpected model type \""
-		  << type.toLocal8Bit().data() << "\" for model id" << id << std::endl;
+		  << type.toLocal8Bit().data() << "\" for model id " << id << std::endl;
     }
 
     return false;