# HG changeset patch # User Chris Cannam # Date 1168275875 0 # Node ID 4eae5b521a3452e9549be68482992b2fc28ce2f1 # Parent 41c4916575872be02196f30881cd12abe9d5ee54 * Framework for retrieving files from remote locations diff -r 41c491657587 -r 4eae5b521a34 main/MainWindow.cpp --- a/main/MainWindow.cpp Fri Jan 05 15:49:10 2007 +0000 +++ b/main/MainWindow.cpp Mon Jan 08 17:04:35 2007 +0000 @@ -47,6 +47,7 @@ #include "data/fileio/WavFileWriter.h" #include "data/fileio/CSVFileWriter.h" #include "data/fileio/BZipFileDevice.h" +#include "data/fileio/RemoteFile.h" #include "base/RecentFiles.h" #include "transform/TransformFactory.h" #include "base/PlayParameterRepository.h" @@ -2667,14 +2668,48 @@ } MainWindow::FileOpenStatus +MainWindow::openURL(QUrl url) +{ + if (url.scheme().toLower() == "file") { + return openSomeFile(url.toLocalFile()); + } else if (url.scheme().toLower() != "http" && + url.scheme().toLower() != "ftp") { + QMessageBox::critical(this, tr("Unsupported scheme in URL"), + tr("The URL scheme \"%1\" is not supported") + .arg(url.scheme())); + return FileOpenFailed; + } else { + RemoteFile rf(url); + rf.wait(); + if (!rf.isOK()) { + //!!! need to clean up any partially downloaded file! + QMessageBox::critical(this, tr("File download failed"), + tr("Failed to download URL \"%1\": %2") + .arg(url.toString()).arg(rf.getErrorString())); + return FileOpenFailed; + } + //!!! and delete the file if we fail to open it here? + return openSomeFile(rf.getLocalFilename()); + } +} + +MainWindow::FileOpenStatus MainWindow::openSomeFile(QString path, AudioFileOpenMode mode) { FileOpenStatus status; + bool canImportLayer = (getMainModel() != 0 && + m_paneStack != 0 && + m_paneStack->getCurrentPane() != 0); + if ((status = openAudioFile(path, mode)) != FileOpenFailed) { return status; } else if ((status = openSessionFile(path)) != FileOpenFailed) { return status; + } else if (!canImportLayer) { + return FileOpenFailed; + } else if ((status = openLayerFile(path)) != FileOpenFailed) { + return status; } else { return FileOpenFailed; } diff -r 41c491657587 -r 4eae5b521a34 main/MainWindow.h --- a/main/MainWindow.h Fri Jan 05 15:49:10 2007 +0000 +++ b/main/MainWindow.h Mon Jan 08 17:04:35 2007 +0000 @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -77,6 +78,7 @@ FileOpenStatus openAudioFile(QString path, AudioFileOpenMode = AskUser); FileOpenStatus openLayerFile(QString path); FileOpenStatus openSessionFile(QString path); + FileOpenStatus openURL(QUrl url); bool saveSessionFile(QString path); bool commitData(bool mayAskUser); // on session shutdown diff -r 41c491657587 -r 4eae5b521a34 main/main.cpp --- a/main/main.cpp Fri Jan 05 15:49:10 2007 +0000 +++ b/main/main.cpp Mon Jan 08 17:04:35 2007 +0000 @@ -155,6 +155,11 @@ if (i == args.begin()) continue; if (i->startsWith('-')) continue; + if (i->startsWith("http:") || i->startsWith("ftp:")) { + status = gui.openURL(QUrl(*i)); + continue; + } + QString path = *i; if (path.endsWith("sv")) { diff -r 41c491657587 -r 4eae5b521a34 sv.pro --- a/sv.pro Fri Jan 05 15:49:10 2007 +0000 +++ b/sv.pro Mon Jan 08 17:04:35 2007 +0000 @@ -5,7 +5,7 @@ load(../sv.prf) CONFIG += sv qt thread warn_on stl rtti exceptions -QT += xml +QT += xml network TARGET = sonic-visualiser