Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
400:78dd9b35559b | 401:d030801113b6 |
---|---|
17 | 17 |
18 #include <QFile> | 18 #include <QFile> |
19 #include <QTextStream> | 19 #include <QTextStream> |
20 #include <QStringList> | 20 #include <QStringList> |
21 | 21 |
22 PlaylistFileReader::PlaylistFileReader(QString path) | 22 PlaylistFileReader::PlaylistFileReader(QString path) : |
23 m_source(path), | |
24 m_file(0) | |
23 { | 25 { |
24 m_file = new QFile(path); | 26 if (!m_source.isAvailable()) { |
27 m_error = QFile::tr("File or URL \"%1\" could not be retrieved") | |
28 .arg(path); | |
29 return; | |
30 } | |
31 init(); | |
32 } | |
33 | |
34 PlaylistFileReader::PlaylistFileReader(FileSource source) : | |
35 m_source(source), | |
36 m_file(0) | |
37 { | |
38 if (!m_source.isAvailable()) { | |
39 m_error = QFile::tr("File or URL \"%1\" could not be retrieved") | |
40 .arg(source.getLocation()); | |
41 return; | |
42 } | |
43 init(); | |
44 } | |
45 | |
46 PlaylistFileReader::~PlaylistFileReader() | |
47 { | |
48 if (m_file) m_file->close(); | |
49 delete m_file; | |
50 } | |
51 | |
52 void | |
53 PlaylistFileReader::init() | |
54 { | |
55 if (!m_source.isAvailable()) return; | |
56 | |
57 m_source.waitForData(); | |
58 | |
59 m_file = new QFile(m_source.getLocalFilename()); | |
25 bool good = false; | 60 bool good = false; |
26 | 61 |
27 if (!m_file->exists()) { | 62 if (!m_file->exists()) { |
28 m_error = QFile::tr("File \"%1\" does not exist").arg(path); | 63 m_error = QFile::tr("File \"%1\" does not exist") |
64 .arg(m_source.getLocation()); | |
29 } else if (!m_file->open(QIODevice::ReadOnly | QIODevice::Text)) { | 65 } else if (!m_file->open(QIODevice::ReadOnly | QIODevice::Text)) { |
30 m_error = QFile::tr("Failed to open file \"%1\"").arg(path); | 66 m_error = QFile::tr("Failed to open file \"%1\"") |
67 .arg(m_source.getLocation()); | |
31 } else { | 68 } else { |
32 good = true; | 69 good = true; |
33 } | 70 } |
34 | 71 |
35 if (!good) { | 72 if (!good) { |
36 delete m_file; | 73 delete m_file; |
37 m_file = 0; | 74 m_file = 0; |
38 } | 75 } |
39 } | |
40 | |
41 PlaylistFileReader::~PlaylistFileReader() | |
42 { | |
43 if (m_file) m_file->close(); | |
44 delete m_file; | |
45 } | 76 } |
46 | 77 |
47 bool | 78 bool |
48 PlaylistFileReader::isOK() const | 79 PlaylistFileReader::isOK() const |
49 { | 80 { |