mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 15:59:42 +01:00
don't add duplicates when dropping albums or artists and fix losing items when combining synchronous and asynchrounous drop operations
This commit is contained in:
parent
5d512c180f
commit
97c694baba
@ -96,7 +96,24 @@ DropJob::acceptsMimeData( const QMimeData* data, bool tracksOnly )
|
||||
|
||||
|
||||
void
|
||||
DropJob::tracksFromMimeData( const QMimeData* data )
|
||||
DropJob::tracksFromMimeData( const QMimeData* data, bool allowDuplicates )
|
||||
{
|
||||
m_allowDuplicates = allowDuplicates;
|
||||
|
||||
parseMimeData( data );
|
||||
|
||||
if ( m_queryCount == 0 )
|
||||
{
|
||||
if ( !allowDuplicates )
|
||||
removeDuplicates();
|
||||
|
||||
emit tracks( m_resultList );
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DropJob::parseMimeData( const QMimeData *data )
|
||||
{
|
||||
QList< query_ptr > results;
|
||||
if ( data->hasFormat( "application/tomahawk.query.list" ) )
|
||||
@ -116,11 +133,7 @@ DropJob::tracksFromMimeData( const QMimeData* data )
|
||||
handleTrackUrls ( plainData );
|
||||
}
|
||||
|
||||
if ( !results.isEmpty() )
|
||||
{
|
||||
emit tracks( results );
|
||||
deleteLater();
|
||||
}
|
||||
m_resultList.append( results );
|
||||
}
|
||||
|
||||
QList< query_ptr >
|
||||
@ -267,7 +280,7 @@ DropJob::tracksFromMixedData( const QMimeData *data )
|
||||
}
|
||||
|
||||
singleMimeData.setData( mimeType, singleData );
|
||||
tracksFromMimeData( &singleMimeData );
|
||||
parseMimeData( &singleMimeData );
|
||||
}
|
||||
return queries;
|
||||
}
|
||||
@ -314,8 +327,32 @@ DropJob::expandedUrls( QStringList urls )
|
||||
void
|
||||
DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList )
|
||||
{
|
||||
qDebug() << "here i am with" << tracksList.count() << "tracks";
|
||||
emit tracks( tracksList );
|
||||
m_resultList.append( tracksList );
|
||||
|
||||
if ( --m_queryCount == 0 )
|
||||
{
|
||||
if ( !m_allowDuplicates )
|
||||
removeDuplicates();
|
||||
|
||||
emit tracks( m_resultList );
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DropJob::removeDuplicates()
|
||||
{
|
||||
QList< Tomahawk::query_ptr > list;
|
||||
foreach ( const Tomahawk::query_ptr& item, m_resultList )
|
||||
{
|
||||
bool contains = false;
|
||||
foreach( const Tomahawk::query_ptr &tmpItem, list )
|
||||
if ( item->album() == tmpItem->album()
|
||||
&& item->artist() == tmpItem->artist()
|
||||
&& item->track() == tmpItem->track() )
|
||||
contains = true;
|
||||
if ( !contains )
|
||||
list.append( item );
|
||||
}
|
||||
m_resultList = list;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
*/
|
||||
static bool acceptsMimeData( const QMimeData* data, bool tracksOnly = true );
|
||||
static QStringList mimeTypes();
|
||||
void tracksFromMimeData( const QMimeData* data );
|
||||
void tracksFromMimeData( const QMimeData* data, bool allowDuplicates = false );
|
||||
|
||||
signals:
|
||||
/// QMimeData parsing results
|
||||
@ -56,6 +56,8 @@ private slots:
|
||||
|
||||
private:
|
||||
/// handle parsing mime data
|
||||
void parseMimeData( const QMimeData* data );
|
||||
|
||||
void handleTrackUrls( const QString& urls );
|
||||
QList< Tomahawk::query_ptr > tracksFromQueryList( const QMimeData* d );
|
||||
QList< Tomahawk::query_ptr > tracksFromResultList( const QMimeData* d );
|
||||
@ -63,7 +65,12 @@ private:
|
||||
QList< Tomahawk::query_ptr > tracksFromAlbumMetaData( const QMimeData* d );
|
||||
QList< Tomahawk::query_ptr > tracksFromMixedData( const QMimeData* d );
|
||||
|
||||
void removeDuplicates();
|
||||
|
||||
int m_queryCount;
|
||||
bool m_allowDuplicates;
|
||||
|
||||
QList< Tomahawk::query_ptr > m_resultList;
|
||||
};
|
||||
|
||||
#endif // DROPJOB_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user