diff data/fileio/PlaylistFileReader.cpp @ 401:d030801113b6

* Add ability to load playlists from a FileSource (used by runner)
author Chris Cannam
date Mon, 07 Apr 2008 16:55:21 +0000
parents c022976d18e8
children 5746c559af15
line wrap: on
line diff
--- a/data/fileio/PlaylistFileReader.cpp	Thu Apr 03 08:30:25 2008 +0000
+++ b/data/fileio/PlaylistFileReader.cpp	Mon Apr 07 16:55:21 2008 +0000
@@ -19,15 +19,52 @@
 #include <QTextStream>
 #include <QStringList>
 
-PlaylistFileReader::PlaylistFileReader(QString path)
+PlaylistFileReader::PlaylistFileReader(QString path) :
+    m_source(path),
+    m_file(0)
 {
-    m_file = new QFile(path);
+    if (!m_source.isAvailable()) {
+        m_error = QFile::tr("File or URL \"%1\" could not be retrieved")
+            .arg(path);
+        return;
+    }
+    init();
+}
+
+PlaylistFileReader::PlaylistFileReader(FileSource source) :
+    m_source(source),
+    m_file(0)
+{
+    if (!m_source.isAvailable()) {
+        m_error = QFile::tr("File or URL \"%1\" could not be retrieved")
+            .arg(source.getLocation());
+        return;
+    }
+    init();
+}
+
+PlaylistFileReader::~PlaylistFileReader()
+{
+    if (m_file) m_file->close();
+    delete m_file;
+}
+
+void
+PlaylistFileReader::init()
+{
+    if (!m_source.isAvailable()) return;
+
+    m_source.waitForData();
+
+    m_file = new QFile(m_source.getLocalFilename());
     bool good = false;
 
     if (!m_file->exists()) {
-	m_error = QFile::tr("File \"%1\" does not exist").arg(path);
+	m_error = QFile::tr("File \"%1\" does not exist")
+            .arg(m_source.getLocation());
     } else if (!m_file->open(QIODevice::ReadOnly | QIODevice::Text)) {
-	m_error = QFile::tr("Failed to open file \"%1\"").arg(path);
+	m_error = QFile::tr("Failed to open file \"%1\"")
+            .arg(m_source.getLocation());
     } else {
 	good = true;
     }
@@ -38,12 +75,6 @@
     }
 }
 
-PlaylistFileReader::~PlaylistFileReader()
-{
-    if (m_file) m_file->close();
-    delete m_file;
-}
-
 bool
 PlaylistFileReader::isOK() const
 {