mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
fixed order of filtering. initial work on the Top10 drop action (does actually Top50 for now and tracks can not be resolved yet)
This commit is contained in:
parent
6aa7531623
commit
34c8c79ef5
@ -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<Tomahawk::query_ptr> ) ),
|
||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||
m_queryCount++;
|
||||
artist_ptr artistPtr = Artist::get( artist );
|
||||
if ( artistPtr->tracks().isEmpty() )
|
||||
{
|
||||
connect( artistPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||
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<Tomahawk::query_ptr>& 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 );
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include "query.h"
|
||||
|
||||
#include "infosystem/infosystem.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QMimeData>
|
||||
@ -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<Tomahawk::query_ptr>& );
|
||||
|
||||
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;
|
||||
};
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user