mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02: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:
@@ -96,7 +96,24 @@ DropJob::acceptsMimeData( const QMimeData* data, bool tracksOnly )
|
|||||||
|
|
||||||
|
|
||||||
void
|
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;
|
QList< query_ptr > results;
|
||||||
if ( data->hasFormat( "application/tomahawk.query.list" ) )
|
if ( data->hasFormat( "application/tomahawk.query.list" ) )
|
||||||
@@ -116,11 +133,7 @@ DropJob::tracksFromMimeData( const QMimeData* data )
|
|||||||
handleTrackUrls ( plainData );
|
handleTrackUrls ( plainData );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !results.isEmpty() )
|
m_resultList.append( results );
|
||||||
{
|
|
||||||
emit tracks( results );
|
|
||||||
deleteLater();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList< query_ptr >
|
QList< query_ptr >
|
||||||
@@ -267,7 +280,7 @@ DropJob::tracksFromMixedData( const QMimeData *data )
|
|||||||
}
|
}
|
||||||
|
|
||||||
singleMimeData.setData( mimeType, singleData );
|
singleMimeData.setData( mimeType, singleData );
|
||||||
tracksFromMimeData( &singleMimeData );
|
parseMimeData( &singleMimeData );
|
||||||
}
|
}
|
||||||
return queries;
|
return queries;
|
||||||
}
|
}
|
||||||
@@ -314,8 +327,32 @@ DropJob::expandedUrls( QStringList urls )
|
|||||||
void
|
void
|
||||||
DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList )
|
DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList )
|
||||||
{
|
{
|
||||||
qDebug() << "here i am with" << tracksList.count() << "tracks";
|
m_resultList.append( tracksList );
|
||||||
emit tracks( tracksList );
|
|
||||||
if ( --m_queryCount == 0 )
|
if ( --m_queryCount == 0 )
|
||||||
|
{
|
||||||
|
if ( !m_allowDuplicates )
|
||||||
|
removeDuplicates();
|
||||||
|
|
||||||
|
emit tracks( m_resultList );
|
||||||
deleteLater();
|
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 bool acceptsMimeData( const QMimeData* data, bool tracksOnly = true );
|
||||||
static QStringList mimeTypes();
|
static QStringList mimeTypes();
|
||||||
void tracksFromMimeData( const QMimeData* data );
|
void tracksFromMimeData( const QMimeData* data, bool allowDuplicates = false );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/// QMimeData parsing results
|
/// QMimeData parsing results
|
||||||
@@ -56,6 +56,8 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/// handle parsing mime data
|
/// handle parsing mime data
|
||||||
|
void parseMimeData( const QMimeData* data );
|
||||||
|
|
||||||
void handleTrackUrls( const QString& urls );
|
void handleTrackUrls( const QString& urls );
|
||||||
QList< Tomahawk::query_ptr > tracksFromQueryList( const QMimeData* d );
|
QList< Tomahawk::query_ptr > tracksFromQueryList( const QMimeData* d );
|
||||||
QList< Tomahawk::query_ptr > tracksFromResultList( 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 > tracksFromAlbumMetaData( const QMimeData* d );
|
||||||
QList< Tomahawk::query_ptr > tracksFromMixedData( const QMimeData* d );
|
QList< Tomahawk::query_ptr > tracksFromMixedData( const QMimeData* d );
|
||||||
|
|
||||||
|
void removeDuplicates();
|
||||||
|
|
||||||
int m_queryCount;
|
int m_queryCount;
|
||||||
|
bool m_allowDuplicates;
|
||||||
|
|
||||||
|
QList< Tomahawk::query_ptr > m_resultList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DROPJOB_H
|
#endif // DROPJOB_H
|
||||||
|
Reference in New Issue
Block a user