1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 22:26:32 +02:00

Handle namespaces in xspf files

This commit is contained in:
Alastair Porter
2011-03-06 22:21:32 -05:00
parent eec2c3a9bf
commit 5b87f97320
2 changed files with 36 additions and 13 deletions

View File

@@ -76,36 +76,57 @@ XSPFLoader::gotBody()
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QDomDocument xmldoc; QDomDocument xmldoc;
xmldoc.setContent( m_body ); bool namespaceProcessing = true;
xmldoc.setContent( m_body, namespaceProcessing );
QDomElement docElement( xmldoc.documentElement() ); QDomElement docElement( xmldoc.documentElement() );
QString origTitle; QString origTitle;
origTitle = docElement.firstChildElement( "title" ).text(); QDomNodeList tracklist;
m_info = docElement.firstChildElement( "creator" ).text(); QDomElement n = docElement.firstChildElement();
m_creator = docElement.firstChildElement( "info" ).text(); for ( ; !n.isNull(); n = n.nextSiblingElement() ) {
if (n.namespaceURI() == NS && n.localName() == "title") {
origTitle = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "creator") {
m_creator = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "info") {
m_info = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "trackList") {
tracklist = n.childNodes();
}
}
m_title = origTitle; m_title = origTitle;
if ( m_title.isEmpty() ) if ( m_title.isEmpty() )
m_title = tr( "New Playlist" ); m_title = tr( "New Playlist" );
QDomNodeList tracklist = docElement.elementsByTagName( "track" );
for ( unsigned int i = 0; i < tracklist.length(); i++ ) for ( unsigned int i = 0; i < tracklist.length(); i++ )
{ {
QDomNode e = tracklist.at( i ); QDomNode e = tracklist.at( i );
QString artist, album, track, duration, annotation;
QDomElement n = e.firstChildElement();
for ( ; !n.isNull(); n = n.nextSiblingElement() ) {
if (n.namespaceURI() == NS && n.localName() == "duration") {
duration = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "annotation") {
annotation = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "creator") {
artist = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "album") {
album = n.text();
} else if (n.namespaceURI() == NS && n.localName() == "title") {
track = n.text();
}
}
plentry_ptr p( new PlaylistEntry ); plentry_ptr p( new PlaylistEntry );
p->setGuid( uuid() ); p->setGuid( uuid() );
p->setDuration( e.firstChildElement( "duration" ).text().toInt() / 1000 ); p->setDuration( duration.toInt() / 1000 );
p->setLastmodified( 0 ); p->setLastmodified( 0 );
p->setAnnotation( e.firstChildElement( "annotation" ).text() ); p->setAnnotation( annotation );
QString artist, album, track;
artist = e.firstChildElement( "creator" ).text();
album = e.firstChildElement( "album" ).text();
track = e.firstChildElement( "title" ).text();
p->setQuery( Tomahawk::Query::get( artist, track, album, uuid() ) ); p->setQuery( Tomahawk::Query::get( artist, track, album, uuid() ) );
p->query()->setDuration( e.firstChildElement( "duration" ).text().toInt() / 1000 ); p->query()->setDuration( duration.toInt() / 1000 );
m_entries << p; m_entries << p;
} }

View File

@@ -25,6 +25,7 @@ public:
explicit XSPFLoader( bool autoCreate = true, QObject* parent = 0 ) explicit XSPFLoader( bool autoCreate = true, QObject* parent = 0 )
: QObject( parent ) : QObject( parent )
, m_autoCreate( autoCreate ) , m_autoCreate( autoCreate )
, NS("http://xspf.org/ns/0/")
{} {}
virtual ~XSPFLoader() virtual ~XSPFLoader()
@@ -47,6 +48,7 @@ private slots:
void networkError( QNetworkReply::NetworkError e ); void networkError( QNetworkReply::NetworkError e );
private: private:
QString NS;
void reportError(); void reportError();
void gotBody(); void gotBody();