diff --git a/src/libtomahawk/utils/xspfloader.cpp b/src/libtomahawk/utils/xspfloader.cpp index 54779c002..23b72ca2e 100644 --- a/src/libtomahawk/utils/xspfloader.cpp +++ b/src/libtomahawk/utils/xspfloader.cpp @@ -34,7 +34,9 @@ XSPFLoader::XSPFLoader( bool autoCreate, QObject *parent ) : QObject( parent ) , m_autoCreate( autoCreate ) , m_NS("http://xspf.org/ns/0/") -{} +{ + qRegisterMetaType< XSPFErrorCode >("XSPFErrorCode"); +} XSPFLoader::~XSPFLoader() @@ -124,14 +126,22 @@ XSPFLoader::gotBody() QString origTitle; QDomNodeList tracklist; QDomElement n = docElement.firstChildElement(); - for ( ; !n.isNull(); n = n.nextSiblingElement() ) { - if (n.namespaceURI() == m_NS && n.localName() == "title") { + for ( ; !n.isNull(); n = n.nextSiblingElement() ) + { + if (n.namespaceURI() == m_NS && n.localName() == "title") + { origTitle = n.text(); - } else if (n.namespaceURI() == m_NS && n.localName() == "creator") { + } + else if (n.namespaceURI() == m_NS && n.localName() == "creator") + { m_creator = n.text(); - } else if (n.namespaceURI() == m_NS && n.localName() == "info") { + } + else if (n.namespaceURI() == m_NS && n.localName() == "info") + { m_info = n.text(); - } else if (n.namespaceURI() == m_NS && n.localName() == "trackList") { + } + else if (n.namespaceURI() == m_NS && n.localName() == "trackList") + { tracklist = n.childNodes(); } } @@ -151,17 +161,28 @@ XSPFLoader::gotBody() QDomElement n = e.firstChildElement(); for ( ; !n.isNull(); n = n.nextSiblingElement() ) { - if (n.namespaceURI() == m_NS && n.localName() == "duration") { + if (n.namespaceURI() == m_NS && n.localName() == "duration") + { duration = n.text(); - } else if (n.namespaceURI() == m_NS && n.localName() == "annotation") { + } + else if (n.namespaceURI() == m_NS && n.localName() == "annotation") + { annotation = n.text(); - } else if (n.namespaceURI() == m_NS && n.localName() == "creator") { + } + else if (n.namespaceURI() == m_NS && n.localName() == "creator") + { artist = n.text(); - } else if (n.namespaceURI() == m_NS && n.localName() == "album") { + } + else if (n.namespaceURI() == m_NS && n.localName() == "album") + { album = n.text(); - } else if (n.namespaceURI() == m_NS && n.localName() == "title") { + } + else if (n.namespaceURI() == m_NS && n.localName() == "title") + { track = n.text(); - } else if (n.namespaceURI() == m_NS && n.localName() == "url") { + } + else if (n.namespaceURI() == m_NS && n.localName() == "url") + { url = n.text(); } } @@ -170,7 +191,7 @@ XSPFLoader::gotBody() { if( !shownError ) { - QMessageBox::warning( 0, tr( "Failed to save tracks" ), tr( "Some tracks in the playlist do not contain an artist and a title. They will be ignored." ), QMessageBox::Ok ); + emit error( InvalidTrackError ); shownError = true; } continue; @@ -186,17 +207,10 @@ XSPFLoader::gotBody() if ( origTitle.isEmpty() && m_entries.isEmpty() ) { + emit error( ParseError ); if ( m_autoCreate ) - { - QMessageBox::critical( 0, tr( "XSPF Error" ), tr( "This is not a valid XSPF playlist." ) ); deleteLater(); - return; - } - else - { - emit failed(); - return; - } + return; } if ( m_autoCreate ) diff --git a/src/libtomahawk/utils/xspfloader.h b/src/libtomahawk/utils/xspfloader.h index b496c4ba8..12c1098c7 100644 --- a/src/libtomahawk/utils/xspfloader.h +++ b/src/libtomahawk/utils/xspfloader.h @@ -39,6 +39,7 @@ class DLLEXPORT XSPFLoader : public QObject Q_OBJECT public: + enum XSPFErrorCode { ParseError, InvalidTrackError }; explicit XSPFLoader( bool autoCreate = true, QObject* parent = 0 ); virtual ~XSPFLoader(); @@ -48,6 +49,7 @@ public: signals: void failed(); + void error( XSPFLoader::XSPFErrorCode error ); void ok( const Tomahawk::playlist_ptr& ); public slots: diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index bf8cbc869..5c94bc2d3 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -36,14 +36,12 @@ #include "playlist.h" #include "query.h" #include "artist.h" - #include "audio/audioengine.h" #include "viewmanager.h" #include "sip/SipHandler.h" #include "sourcetree/sourcetreeview.h" #include "network/servent.h" #include "utils/proxystyle.h" -#include "utils/xspfloader.h" #include "widgets/animatedsplitter.h" #include "widgets/newplaylistwidget.h" #include "widgets/searchwidget.h" @@ -496,10 +494,27 @@ TomahawkWindow::loadSpiff() return; XSPFLoader* loader = new XSPFLoader; + connect( loader, SIGNAL( error( XSPFLoader::XSPFErrorCode ) ), SLOT( onXSPFError( XSPFLoader::XSPFErrorCode ) ) ); loader->load( QUrl::fromUserInput( urlstr ) ); } +void +TomahawkWindow::onXSPFError( XSPFLoader::XSPFErrorCode error ) +{ + switch ( error ) + { + case XSPFLoader::ParseError: + QMessageBox::critical( this, tr( "XSPF Error" ), tr( "This is not a valid XSPF playlist." ) ); + break; + + case XSPFLoader::InvalidTrackError: + QMessageBox::warning( this, tr( "Failed to save tracks" ), tr( "Some tracks in the playlist do not contain an artist and a title. They will be ignored." ), QMessageBox::Ok ); + break; + } +} + + void TomahawkWindow::createAutomaticPlaylist( QString playlistName ) { diff --git a/src/tomahawkwindow.h b/src/tomahawkwindow.h index b8ccc59df..608f5d780 100644 --- a/src/tomahawkwindow.h +++ b/src/tomahawkwindow.h @@ -26,6 +26,7 @@ #include #include "result.h" +#include "utils/xspfloader.h" class QSearchField; class SipPlugin; @@ -82,6 +83,8 @@ private slots: void onSipDisconnected(); void onSipError(); + void onXSPFError( XSPFLoader::XSPFErrorCode error ); + void addPeerManually(); void onPlaybackLoading( const Tomahawk::result_ptr& result );