From 34c8c79ef5490f0b8bd4bed4b835ab5392566f81 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 21 Aug 2011 00:19:01 +0200 Subject: [PATCH] fixed order of filtering. initial work on the Top10 drop action (does actually Top50 for now and tracks can not be resolved yet) --- src/libtomahawk/dropjob.cpp | 86 +++++++++++++++++++++----- src/libtomahawk/dropjob.h | 7 ++- src/sourcetree/items/playlistitems.cpp | 3 + 3 files changed, 79 insertions(+), 17 deletions(-) diff --git a/src/libtomahawk/dropjob.cpp b/src/libtomahawk/dropjob.cpp index 8fff1080d..6f1a79d2e 100644 --- a/src/libtomahawk/dropjob.cpp +++ b/src/libtomahawk/dropjob.cpp @@ -27,6 +27,7 @@ #include "utils/shortenedlinkparser.h" #include "utils/logger.h" #include "globalactionmanager.h" +#include "infosystem/infosystem.h" using namespace Tomahawk; @@ -96,21 +97,22 @@ DropJob::acceptsMimeData( const QMimeData* data, bool tracksOnly ) void -DropJob::tracksFromMimeData( const QMimeData* data, bool allowDuplicates, bool onlyLocal ) +DropJob::tracksFromMimeData( const QMimeData* data, bool allowDuplicates, bool onlyLocal, bool top10 ) { m_allowDuplicates = allowDuplicates; m_onlyLocal = onlyLocal; + m_top10 = top10; parseMimeData( data ); if ( m_queryCount == 0 ) { - if ( !allowDuplicates ) - removeDuplicates(); - if ( onlyLocal ) removeRemoteSources(); + if ( !allowDuplicates ) + removeDuplicates(); + emit tracks( m_resultList ); deleteLater(); } @@ -228,15 +230,38 @@ DropJob::tracksFromArtistMetaData( const QMimeData *data ) QString artist; stream >> artist; - artist_ptr artistPtr = Artist::get( artist ); - if ( artistPtr->tracks().isEmpty() ) + if ( !m_top10 ) { - connect( artistPtr.data(), SIGNAL( tracksAdded( QList ) ), - SLOT( onTracksAdded( QList ) ) ); - m_queryCount++; + artist_ptr artistPtr = Artist::get( artist ); + if ( artistPtr->tracks().isEmpty() ) + { + connect( artistPtr.data(), SIGNAL( tracksAdded( QList ) ), + SLOT( onTracksAdded( QList ) ) ); + m_queryCount++; + } + else + queries << artistPtr->tracks(); } else - queries << artistPtr->tracks(); + { + connect( Tomahawk::InfoSystem::InfoSystem::instance(), + SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), + SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); + + Tomahawk::InfoSystem::InfoCriteriaHash artistInfo; + artistInfo["artist"] = artist; + + Tomahawk::InfoSystem::InfoRequestData requestData; + requestData.caller = "changeme"; + requestData.customData = QVariantMap(); + + requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( artistInfo ); + + requestData.type = Tomahawk::InfoSystem::InfoArtistSongs; + Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); + + m_queryCount++; + } } return queries; } @@ -340,12 +365,12 @@ DropJob::onTracksAdded( const QList& tracksList ) if ( --m_queryCount == 0 ) { - if ( !m_allowDuplicates ) - removeDuplicates(); - if ( m_onlyLocal ) removeRemoteSources(); + if ( !m_allowDuplicates ) + removeDuplicates(); + emit tracks( m_resultList ); deleteLater(); } @@ -375,9 +400,38 @@ DropJob::removeRemoteSources() QList< Tomahawk::query_ptr > list; foreach ( const Tomahawk::query_ptr& item, m_resultList ) { - if ( !item->results().isEmpty() && item->results().first()->collection()->source() ) - if ( item->results().first()->collection()->source()->isLocal() ) - list.append( item ); + bool hasLocalSource = false; + foreach ( const Tomahawk::result_ptr& result, item->results() ) + { + if ( result->collection()->source() && result->collection()->source()->isLocal() ) + hasLocalSource = true; + } + if ( hasLocalSource ) + list.append( item ); } m_resultList = list; } + +void +DropJob::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) +{ + if ( requestData.caller == "changeme" ) + { + Tomahawk::InfoSystem::InfoCriteriaHash artistInfo; + + artistInfo = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); + + QString artist = artistInfo["artist"]; + + qDebug() << "Got requestData response for artist" << artist << output; + + QList< query_ptr > results; + foreach ( const QVariant& title, output.toMap().value( "tracks" ).toList() ) + { + qDebug() << "got title" << title; + results << Query::get( artist, title.toString(), QString() ); + } + + onTracksAdded( results ); + } +} diff --git a/src/libtomahawk/dropjob.h b/src/libtomahawk/dropjob.h index aab952cb0..ca542ee7b 100644 --- a/src/libtomahawk/dropjob.h +++ b/src/libtomahawk/dropjob.h @@ -22,6 +22,8 @@ #include "query.h" +#include "infosystem/infosystem.h" + #include #include #include @@ -43,7 +45,7 @@ public: */ static bool acceptsMimeData( const QMimeData* data, bool tracksOnly = true ); static QStringList mimeTypes(); - void tracksFromMimeData( const QMimeData* data, bool allowDuplicates = false, bool onlyLocal = false ); + void tracksFromMimeData( const QMimeData* data, bool allowDuplicates = false, bool onlyLocal = false, bool top10 = false ); signals: /// QMimeData parsing results @@ -54,6 +56,8 @@ private slots: void onTracksAdded( const QList& ); + void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); + private: /// handle parsing mime data void parseMimeData( const QMimeData* data ); @@ -71,6 +75,7 @@ private: int m_queryCount; bool m_allowDuplicates; bool m_onlyLocal; + bool m_top10; QList< Tomahawk::query_ptr > m_resultList; }; diff --git a/src/sourcetree/items/playlistitems.cpp b/src/sourcetree/items/playlistitems.cpp index b3a55ef92..5899405f9 100644 --- a/src/sourcetree/items/playlistitems.cpp +++ b/src/sourcetree/items/playlistitems.cpp @@ -161,6 +161,8 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action ) if ( dropType() == DropTypeLocalItems ) dj->tracksFromMimeData( data, false, true ); + else if ( dropType() == DropTypeTop10 ) + dj->tracksFromMimeData( data, false, false, true ); else dj->tracksFromMimeData( data, false, false ); @@ -171,6 +173,7 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action ) void PlaylistItem::parsedDroppedTracks( const QList< query_ptr >& tracks) { + qDebug() << "adding" << tracks.count() << "tracks"; if ( tracks.count() && !m_playlist.isNull() && m_playlist->author()->isLocal() ) { qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid() << m_playlist->currentrevision();