Mercurial > hg > sonic-visualiser
comparison 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 |
comparison
equal
deleted
inserted
replaced
87:8944f3005a15 | 88:51be0daa1386 |
---|---|
497 bool mainModel = (attributes.value("mainModel").trimmed() == "true"); | 497 bool mainModel = (attributes.value("mainModel").trimmed() == "true"); |
498 | 498 |
499 if (type == "wavefile") { | 499 if (type == "wavefile") { |
500 | 500 |
501 WaveFileModel *model = 0; | 501 WaveFileModel *model = 0; |
502 FileFinder finder(attributes.value("file"), m_location); | 502 FileFinder *ff = FileFinder::getInstance(); |
503 QString path = finder.getLocation(); | 503 QString originalPath = attributes.value("file"); |
504 QString path = ff->find(FileFinder::AudioFile, | |
505 originalPath, m_location); | |
504 QUrl url(path); | 506 QUrl url(path); |
505 | 507 |
506 if (RemoteFile::canHandleScheme(url)) { | 508 if (RemoteFile::canHandleScheme(url)) { |
507 | 509 |
508 RemoteFile rf(url); | 510 RemoteFile rf(url); |
509 rf.wait(); | 511 rf.wait(); |
510 | 512 |
511 if (rf.isOK()) { | 513 if (rf.isOK()) { |
512 model = new WaveFileModel(rf.getLocalFilename()); | 514 |
515 model = new WaveFileModel(rf.getLocalFilename(), path); | |
513 if (!model->isOK()) { | 516 if (!model->isOK()) { |
514 delete model; | 517 delete model; |
515 model = 0; | 518 model = 0; |
516 //!!! and delete local file? | 519 //!!! and delete local file? |
517 } | 520 } |
524 model = 0; | 527 model = 0; |
525 } | 528 } |
526 } | 529 } |
527 | 530 |
528 if (!model) return false; | 531 if (!model) return false; |
529 | |
530 /* | |
531 QString file = attributes.value("file"); | |
532 WaveFileModel *model = new WaveFileModel(file); | |
533 | |
534 while (!model->isOK()) { | |
535 | |
536 delete model; | |
537 model = 0; | |
538 | |
539 if (QMessageBox::question(0, | |
540 QMessageBox::tr("Failed to open file"), | |
541 QMessageBox::tr("Audio file \"%1\" could not be opened.\nLocate it?").arg(file), | |
542 QMessageBox::Ok, | |
543 QMessageBox::Cancel) == QMessageBox::Ok) { | |
544 | |
545 QString path = QFileDialog::getOpenFileName | |
546 (0, QFileDialog::tr("Locate file \"%1\"").arg(QFileInfo(file).fileName()), file, | |
547 QFileDialog::tr("Audio files (%1)\nAll files (*.*)") | |
548 .arg(AudioFileReaderFactory::getKnownExtensions())); | |
549 | |
550 if (path != "") { | |
551 model = new WaveFileModel(path); | |
552 } else { | |
553 return false; | |
554 } | |
555 } else { | |
556 return false; | |
557 } | |
558 } | |
559 */ | |
560 | 532 |
561 m_models[id] = model; | 533 m_models[id] = model; |
562 if (mainModel) { | 534 if (mainModel) { |
563 m_document->setMainModel(model); | 535 m_document->setMainModel(model); |
564 m_addedModels.insert(model); | 536 m_addedModels.insert(model); |
663 << dimensions << ")" << std::endl; | 635 << dimensions << ")" << std::endl; |
664 } | 636 } |
665 } else { | 637 } else { |
666 | 638 |
667 std::cerr << "WARNING: SV-XML: Unexpected model type \"" | 639 std::cerr << "WARNING: SV-XML: Unexpected model type \"" |
668 << type.toLocal8Bit().data() << "\" for model id" << id << std::endl; | 640 << type.toLocal8Bit().data() << "\" for model id " << id << std::endl; |
669 } | 641 } |
670 | 642 |
671 return false; | 643 return false; |
672 } | 644 } |
673 | 645 |