Mercurial > hg > svcore
changeset 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 | 78dd9b35559b |
children | 7e1b7fcb6c00 |
files | data/fileio/PlaylistFileReader.cpp data/fileio/PlaylistFileReader.h |
diffstat | 2 files changed, 47 insertions(+), 10 deletions(-) [+] |
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 {
--- a/data/fileio/PlaylistFileReader.h Thu Apr 03 08:30:25 2008 +0000 +++ b/data/fileio/PlaylistFileReader.h Mon Apr 07 16:55:21 2008 +0000 @@ -16,6 +16,8 @@ #ifndef _PLAYLIST_FILE_READER_H_ #define _PLAYLIST_FILE_READER_H_ +#include "FileSource.h" + #include <QString> #include <vector> @@ -29,6 +31,7 @@ typedef std::vector<QString> Playlist; PlaylistFileReader(QString path); + PlaylistFileReader(FileSource source); virtual ~PlaylistFileReader(); virtual bool isOK() const; @@ -38,6 +41,9 @@ static void getSupportedExtensions(std::set<QString> &extensions); protected: + void init(); + + FileSource m_source; QFile *m_file; QString m_error; };