Replace readElementText properly, with one that doesn't error out when it sees a child element.
This commit is contained in:
parent
9e47eb420a
commit
4ed73d74b0
|
@ -165,7 +165,8 @@ Song MagnatuneService::ReadTrack(QXmlStreamReader& reader) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
||||||
QString value = reader.readElementText();
|
QString value = ReadElementText(reader);
|
||||||
|
|
||||||
if (reader.name() == "artist") song.set_artist(value);
|
if (reader.name() == "artist") song.set_artist(value);
|
||||||
if (reader.name() == "albumname") song.set_album(value);
|
if (reader.name() == "albumname") song.set_album(value);
|
||||||
if (reader.name() == "trackname") song.set_title(value);
|
if (reader.name() == "trackname") song.set_title(value);
|
||||||
|
@ -190,6 +191,26 @@ Song MagnatuneService::ReadTrack(QXmlStreamReader& reader) {
|
||||||
return song;
|
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,
|
void MagnatuneService::ShowContextMenu(RadioItem*, const QModelIndex& index,
|
||||||
const QPoint& global_pos) {
|
const QPoint& global_pos) {
|
||||||
if (index.model() == library_sort_model_)
|
if (index.model() == library_sort_model_)
|
||||||
|
|
|
@ -60,6 +60,7 @@ class MagnatuneService : public RadioService {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Song ReadTrack(QXmlStreamReader& reader);
|
Song ReadTrack(QXmlStreamReader& reader);
|
||||||
|
QString ReadElementText(QXmlStreamReader& reader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RadioItem* root_;
|
RadioItem* root_;
|
||||||
|
|
Loading…
Reference in New Issue