1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01: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 )
, 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 )

View File

@ -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:

View File

@ -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 )
{

View File

@ -26,6 +26,7 @@
#include <QStackedWidget>
#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 );