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

* Moved QMessageBox out of XSPFLoader and into TomahawkWindow.

This commit is contained in:
Christian Muehlhaeuser
2011-09-16 16:27:00 +02:00
parent 695902d962
commit 483386e440
4 changed files with 58 additions and 24 deletions

View File

@@ -34,7 +34,9 @@ XSPFLoader::XSPFLoader( bool autoCreate, QObject *parent )
: QObject( parent ) : QObject( parent )
, m_autoCreate( autoCreate ) , m_autoCreate( autoCreate )
, m_NS("http://xspf.org/ns/0/") , m_NS("http://xspf.org/ns/0/")
{} {
qRegisterMetaType< XSPFErrorCode >("XSPFErrorCode");
}
XSPFLoader::~XSPFLoader() XSPFLoader::~XSPFLoader()
@@ -124,14 +126,22 @@ XSPFLoader::gotBody()
QString origTitle; QString origTitle;
QDomNodeList tracklist; QDomNodeList tracklist;
QDomElement n = docElement.firstChildElement(); QDomElement n = docElement.firstChildElement();
for ( ; !n.isNull(); n = n.nextSiblingElement() ) { for ( ; !n.isNull(); n = n.nextSiblingElement() )
if (n.namespaceURI() == m_NS && n.localName() == "title") { {
if (n.namespaceURI() == m_NS && n.localName() == "title")
{
origTitle = n.text(); 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(); 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(); 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(); tracklist = n.childNodes();
} }
} }
@@ -151,17 +161,28 @@ XSPFLoader::gotBody()
QDomElement n = e.firstChildElement(); QDomElement n = e.firstChildElement();
for ( ; !n.isNull(); n = n.nextSiblingElement() ) 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(); duration = n.text();
} else if (n.namespaceURI() == m_NS && n.localName() == "annotation") { }
else if (n.namespaceURI() == m_NS && n.localName() == "annotation")
{
annotation = n.text(); annotation = n.text();
} else if (n.namespaceURI() == m_NS && n.localName() == "creator") { }
else if (n.namespaceURI() == m_NS && n.localName() == "creator")
{
artist = n.text(); artist = n.text();
} else if (n.namespaceURI() == m_NS && n.localName() == "album") { }
else if (n.namespaceURI() == m_NS && n.localName() == "album")
{
album = n.text(); album = n.text();
} else if (n.namespaceURI() == m_NS && n.localName() == "title") { }
else if (n.namespaceURI() == m_NS && n.localName() == "title")
{
track = n.text(); track = n.text();
} else if (n.namespaceURI() == m_NS && n.localName() == "url") { }
else if (n.namespaceURI() == m_NS && n.localName() == "url")
{
url = n.text(); url = n.text();
} }
} }
@@ -170,7 +191,7 @@ XSPFLoader::gotBody()
{ {
if( !shownError ) 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; shownError = true;
} }
continue; continue;
@@ -186,18 +207,11 @@ XSPFLoader::gotBody()
if ( origTitle.isEmpty() && m_entries.isEmpty() ) if ( origTitle.isEmpty() && m_entries.isEmpty() )
{ {
emit error( ParseError );
if ( m_autoCreate ) if ( m_autoCreate )
{
QMessageBox::critical( 0, tr( "XSPF Error" ), tr( "This is not a valid XSPF playlist." ) );
deleteLater(); deleteLater();
return; return;
} }
else
{
emit failed();
return;
}
}
if ( m_autoCreate ) if ( m_autoCreate )
{ {

View File

@@ -39,6 +39,7 @@ class DLLEXPORT XSPFLoader : public QObject
Q_OBJECT Q_OBJECT
public: public:
enum XSPFErrorCode { ParseError, InvalidTrackError };
explicit XSPFLoader( bool autoCreate = true, QObject* parent = 0 ); explicit XSPFLoader( bool autoCreate = true, QObject* parent = 0 );
virtual ~XSPFLoader(); virtual ~XSPFLoader();
@@ -48,6 +49,7 @@ public:
signals: signals:
void failed(); void failed();
void error( XSPFLoader::XSPFErrorCode error );
void ok( const Tomahawk::playlist_ptr& ); void ok( const Tomahawk::playlist_ptr& );
public slots: public slots:

View File

@@ -36,14 +36,12 @@
#include "playlist.h" #include "playlist.h"
#include "query.h" #include "query.h"
#include "artist.h" #include "artist.h"
#include "audio/audioengine.h" #include "audio/audioengine.h"
#include "viewmanager.h" #include "viewmanager.h"
#include "sip/SipHandler.h" #include "sip/SipHandler.h"
#include "sourcetree/sourcetreeview.h" #include "sourcetree/sourcetreeview.h"
#include "network/servent.h" #include "network/servent.h"
#include "utils/proxystyle.h" #include "utils/proxystyle.h"
#include "utils/xspfloader.h"
#include "widgets/animatedsplitter.h" #include "widgets/animatedsplitter.h"
#include "widgets/newplaylistwidget.h" #include "widgets/newplaylistwidget.h"
#include "widgets/searchwidget.h" #include "widgets/searchwidget.h"
@@ -496,10 +494,27 @@ TomahawkWindow::loadSpiff()
return; return;
XSPFLoader* loader = new XSPFLoader; XSPFLoader* loader = new XSPFLoader;
connect( loader, SIGNAL( error( XSPFLoader::XSPFErrorCode ) ), SLOT( onXSPFError( XSPFLoader::XSPFErrorCode ) ) );
loader->load( QUrl::fromUserInput( urlstr ) ); 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 void
TomahawkWindow::createAutomaticPlaylist( QString playlistName ) TomahawkWindow::createAutomaticPlaylist( QString playlistName )
{ {

View File

@@ -26,6 +26,7 @@
#include <QStackedWidget> #include <QStackedWidget>
#include "result.h" #include "result.h"
#include "utils/xspfloader.h"
class QSearchField; class QSearchField;
class SipPlugin; class SipPlugin;
@@ -82,6 +83,8 @@ private slots:
void onSipDisconnected(); void onSipDisconnected();
void onSipError(); void onSipError();
void onXSPFError( XSPFLoader::XSPFErrorCode error );
void addPeerManually(); void addPeerManually();
void onPlaybackLoading( const Tomahawk::result_ptr& result ); void onPlaybackLoading( const Tomahawk::result_ptr& result );