Mercurial > hg > svcore
comparison data/fileio/PlaylistFileReader.cpp @ 440:5746c559af15
* Merge revisions 1131 to 1201 from sv-rdf-import branch
author | Chris Cannam |
---|---|
date | Thu, 18 Sep 2008 12:33:30 +0000 |
parents | d030801113b6 |
children | b4a8d8221eaf |
comparison
equal
deleted
inserted
replaced
439:beb2948baa77 | 440:5746c559af15 |
---|---|
16 #include "PlaylistFileReader.h" | 16 #include "PlaylistFileReader.h" |
17 | 17 |
18 #include <QFile> | 18 #include <QFile> |
19 #include <QTextStream> | 19 #include <QTextStream> |
20 #include <QStringList> | 20 #include <QStringList> |
21 #include <QFileInfo> | |
22 #include <QDir> | |
23 | |
24 #include <iostream> | |
21 | 25 |
22 PlaylistFileReader::PlaylistFileReader(QString path) : | 26 PlaylistFileReader::PlaylistFileReader(QString path) : |
23 m_source(path), | 27 m_source(path), |
24 m_file(0) | 28 m_file(0) |
25 { | 29 { |
54 { | 58 { |
55 if (!m_source.isAvailable()) return; | 59 if (!m_source.isAvailable()) return; |
56 | 60 |
57 m_source.waitForData(); | 61 m_source.waitForData(); |
58 | 62 |
59 m_file = new QFile(m_source.getLocalFilename()); | 63 QString filename = m_source.getLocalFilename(); |
64 | |
65 m_file = new QFile(filename); | |
60 bool good = false; | 66 bool good = false; |
61 | 67 |
62 if (!m_file->exists()) { | 68 if (!m_file->exists()) { |
63 m_error = QFile::tr("File \"%1\" does not exist") | 69 m_error = QFile::tr("File \"%1\" does not exist") |
64 .arg(m_source.getLocation()); | 70 .arg(m_source.getLocation()); |
65 } else if (!m_file->open(QIODevice::ReadOnly | QIODevice::Text)) { | 71 } else if (!m_file->open(QIODevice::ReadOnly | QIODevice::Text)) { |
66 m_error = QFile::tr("Failed to open file \"%1\"") | 72 m_error = QFile::tr("Failed to open file \"%1\"") |
67 .arg(m_source.getLocation()); | 73 .arg(m_source.getLocation()); |
68 } else { | 74 } else { |
69 good = true; | 75 good = true; |
76 } | |
77 | |
78 if (good) { | |
79 if (!m_source.isRemote()) { | |
80 m_basedir = QFileInfo(filename).dir().canonicalPath(); | |
81 } | |
70 } | 82 } |
71 | 83 |
72 if (!good) { | 84 if (!good) { |
73 delete m_file; | 85 delete m_file; |
74 m_file = 0; | 86 m_file = 0; |
103 // as well as DOS/Unix style | 115 // as well as DOS/Unix style |
104 | 116 |
105 QString chunk = in.readLine(); | 117 QString chunk = in.readLine(); |
106 QStringList lines = chunk.split('\r', QString::SkipEmptyParts); | 118 QStringList lines = chunk.split('\r', QString::SkipEmptyParts); |
107 | 119 |
108 for (size_t li = 0; li < lines.size(); ++li) { | 120 for (int li = 0; li < lines.size(); ++li) { |
109 | 121 |
110 QString line = lines[li]; | 122 QString line = lines[li]; |
111 | 123 |
112 if (line.startsWith("#")) continue; | 124 if (line.startsWith("#")) continue; |
125 | |
126 // line is expected to be a URL or a file path. If it | |
127 // appears to be a local relative file path, then we | |
128 // should check whether it can be resolved relative to the | |
129 // location of the playlist file and, if so, do so. | |
130 | |
131 if (!FileSource::isRemote(line)) { | |
132 if (QFileInfo(line).isRelative() && m_basedir != "") { | |
133 QString testpath = QDir(m_basedir).filePath(line); | |
134 if (QFileInfo(testpath).exists() && | |
135 QFileInfo(testpath).isFile()) { | |
136 std::cerr << "Path \"" << line.toStdString() | |
137 << "\" is relative, resolving to \"" | |
138 << testpath.toStdString() << "\"" | |
139 << std::endl; | |
140 line = testpath; | |
141 } | |
142 } | |
143 } | |
113 | 144 |
114 playlist.push_back(line); | 145 playlist.push_back(line); |
115 } | 146 } |
116 } | 147 } |
117 | 148 |