diff --git a/src/libtomahawk/GlobalActionManager.cpp b/src/libtomahawk/GlobalActionManager.cpp index 0cc4e1cd7..2b31b7586 100644 --- a/src/libtomahawk/GlobalActionManager.cpp +++ b/src/libtomahawk/GlobalActionManager.cpp @@ -495,6 +495,23 @@ GlobalActionManager::handleOpenTrack( const query_ptr& q ) } +void +GlobalActionManager::handleOpenTracks( const QList< query_ptr >& queries ) +{ + if ( queries.isEmpty() ) + return; + + ViewManager::instance()->queue()->model()->append( queries ); + ViewManager::instance()->showQueue(); + + if ( !AudioEngine::instance()->isPlaying() && !AudioEngine::instance()->isPaused() ) + { + connect( queries.first().data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( waitingForResolved( bool ) ) ); + m_waitingToPlay = queries.first(); + } +} + + void GlobalActionManager::handlePlayTrack( const query_ptr& qry ) { @@ -591,6 +608,43 @@ GlobalActionManager::doQueueAdd( const QStringList& parts, const QList< QPair< Q } } } + else if ( parts.size() && parts[ 0 ] == "playlist" ) + { + QString xspfUrl, jspfUrl; + for ( int i = 0; i < queryItems.size(); i++ ) + { + const QPair< QString, QString > queryItem = queryItems.at( i ); + if ( queryItem.first == "xspf" ) + { + xspfUrl = queryItem.second; + break; + } + else if ( queryItem.first == "jspf" ) + { + jspfUrl = queryItem.second; + break; + } + } + + if ( !xspfUrl.isEmpty() ) + { + XSPFLoader* loader = new XSPFLoader( false, false, this ); + connect( loader, SIGNAL( tracks( QList ) ), this, SLOT( handleOpenTracks( QList< Tomahawk::query_ptr > ) ) ); + loader->load( QUrl( xspfUrl ) ); + loader->setAutoDelete( true ); + + return true; + } + else if ( !jspfUrl.isEmpty() ) + { + JSPFLoader* loader = new JSPFLoader( false, this ); + connect( loader, SIGNAL( tracks( QList ) ), this, SLOT( handleOpenTracks( QList< Tomahawk::query_ptr > ) ) ); + loader->load( QUrl( jspfUrl ) ); + loader->setAutoDelete( true ); + + return true; + } + } return false; } @@ -1225,7 +1279,8 @@ GlobalActionManager::waitingForResolved( bool /* success */ ) ViewManager::instance()->queue()->model()->append( m_waitingToPlay ); AudioEngine::instance()->play(); } - } else + } + else AudioEngine::instance()->play(); m_waitingToPlay.clear(); diff --git a/src/libtomahawk/GlobalActionManager.h b/src/libtomahawk/GlobalActionManager.h index d28a5aa39..fbd985ef2 100644 --- a/src/libtomahawk/GlobalActionManager.h +++ b/src/libtomahawk/GlobalActionManager.h @@ -67,6 +67,8 @@ public slots: Tomahawk::dynplaylist_ptr loadDynamicPlaylist( const QUrl& url, bool station ); void handleOpenTrack( const Tomahawk::query_ptr& qry ); + void handleOpenTracks( const QList< Tomahawk::query_ptr >& queries ); + void handlePlayTrack( const Tomahawk::query_ptr& qry ); #endif diff --git a/src/libtomahawk/utils/JspfLoader.cpp b/src/libtomahawk/utils/JspfLoader.cpp index a3b6d8ab9..85c1d568c 100644 --- a/src/libtomahawk/utils/JspfLoader.cpp +++ b/src/libtomahawk/utils/JspfLoader.cpp @@ -37,6 +37,7 @@ using namespace Tomahawk; JSPFLoader::JSPFLoader( bool autoCreate, QObject *parent ) : QObject( parent ) , m_autoCreate( autoCreate ) + , m_autoDelete( true ) {} JSPFLoader::~JSPFLoader() @@ -87,7 +88,9 @@ void JSPFLoader::reportError() { emit failed(); - deleteLater(); + + if ( m_autoDelete ) + deleteLater(); } @@ -180,7 +183,6 @@ JSPFLoader::gotBody() if ( m_autoCreate ) { QMessageBox::critical( 0, tr( "XSPF Error" ), tr( "This is not a valid XSPF playlist." ) ); - deleteLater(); return; } else @@ -200,8 +202,10 @@ JSPFLoader::gotBody() false, m_entries ); - deleteLater(); } emit ok( m_playlist ); + + if ( m_autoDelete ) + deleteLater(); } diff --git a/src/libtomahawk/utils/JspfLoader.h b/src/libtomahawk/utils/JspfLoader.h index 0eaf6dff4..89c04bb0a 100644 --- a/src/libtomahawk/utils/JspfLoader.h +++ b/src/libtomahawk/utils/JspfLoader.h @@ -45,6 +45,8 @@ public: QList< Tomahawk::query_ptr > entries() const; void setOverrideTitle( const QString& newTitle ) { m_overrideTitle = newTitle; } + void setAutoDelete( bool autoDelete ) { m_autoDelete = autoDelete; } + signals: void failed(); void ok( const Tomahawk::playlist_ptr& ); @@ -61,7 +63,7 @@ private: void reportError(); void gotBody(); - bool m_autoCreate; + bool m_autoCreate, m_autoDelete; QList< Tomahawk::query_ptr > m_entries; QString m_title, m_info, m_creator, m_overrideTitle;