changeset 85:4eae5b521a34

* Framework for retrieving files from remote locations
author Chris Cannam
date Mon, 08 Jan 2007 17:04:35 +0000
parents 41c491657587
children 6113fdda2737
files main/MainWindow.cpp main/MainWindow.h main/main.cpp sv.pro
diffstat 4 files changed, 43 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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;
     }
--- 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 <QFrame>
 #include <QString>
+#include <QUrl>
 #include <QMainWindow>
 #include <QPointer>
 
@@ -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
--- 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")) {
--- 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