Replace readElementText properly, with one that doesn't error out when it sees a child element.

This commit is contained in:
David Sansome 2010-05-10 10:58:02 +00:00
parent 9e47eb420a
commit 4ed73d74b0
2 changed files with 23 additions and 1 deletions

View File

@ -165,7 +165,8 @@ Song MagnatuneService::ReadTrack(QXmlStreamReader& reader) {
break;
if (reader.tokenType() == QXmlStreamReader::StartElement) {
QString value = reader.readElementText();
QString value = ReadElementText(reader);
if (reader.name() == "artist") song.set_artist(value);
if (reader.name() == "albumname") song.set_album(value);
if (reader.name() == "trackname") song.set_title(value);
@ -190,6 +191,26 @@ Song MagnatuneService::ReadTrack(QXmlStreamReader& reader) {
return song;
}
// TODO: Replace with readElementText(SkipChildElements) in Qt 4.6
QString MagnatuneService::ReadElementText(QXmlStreamReader& reader) {
int level = 1;
QString ret;
while (!reader.atEnd()) {
switch (reader.readNext()) {
case QXmlStreamReader::StartElement: level++; break;
case QXmlStreamReader::EndElement: level--; break;
case QXmlStreamReader::Characters:
ret += reader.text().toString().trimmed();
break;
default: break;
}
if (level == 0)
break;
}
return ret;
}
void MagnatuneService::ShowContextMenu(RadioItem*, const QModelIndex& index,
const QPoint& global_pos) {
if (index.model() == library_sort_model_)

View File

@ -60,6 +60,7 @@ class MagnatuneService : public RadioService {
private:
Song ReadTrack(QXmlStreamReader& reader);
QString ReadElementText(QXmlStreamReader& reader);
private:
RadioItem* root_;