1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

dropping "All items" and "Only local items" works now

This commit is contained in:
Michael Zanetti 2011-08-20 22:31:37 +02:00
parent eea5fa2826
commit 6aa7531623
5 changed files with 32 additions and 5 deletions

View File

@ -96,9 +96,10 @@ DropJob::acceptsMimeData( const QMimeData* data, bool tracksOnly )
void
DropJob::tracksFromMimeData( const QMimeData* data, bool allowDuplicates )
DropJob::tracksFromMimeData( const QMimeData* data, bool allowDuplicates, bool onlyLocal )
{
m_allowDuplicates = allowDuplicates;
m_onlyLocal = onlyLocal;
parseMimeData( data );
@ -107,6 +108,9 @@ DropJob::tracksFromMimeData( const QMimeData* data, bool allowDuplicates )
if ( !allowDuplicates )
removeDuplicates();
if ( onlyLocal )
removeRemoteSources();
emit tracks( m_resultList );
deleteLater();
}
@ -339,6 +343,9 @@ DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList )
if ( !m_allowDuplicates )
removeDuplicates();
if ( m_onlyLocal )
removeRemoteSources();
emit tracks( m_resultList );
deleteLater();
}
@ -361,3 +368,16 @@ DropJob::removeDuplicates()
}
m_resultList = list;
}
void
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 );
}
m_resultList = list;
}

View File

@ -43,7 +43,7 @@ public:
*/
static bool acceptsMimeData( const QMimeData* data, bool tracksOnly = true );
static QStringList mimeTypes();
void tracksFromMimeData( const QMimeData* data, bool allowDuplicates = false );
void tracksFromMimeData( const QMimeData* data, bool allowDuplicates = false, bool onlyLocal = false );
signals:
/// QMimeData parsing results
@ -66,9 +66,11 @@ private:
QList< Tomahawk::query_ptr > tracksFromMixedData( const QMimeData* d );
void removeDuplicates();
void removeRemoteSources();
int m_queryCount;
bool m_allowDuplicates;
bool m_onlyLocal;
QList< Tomahawk::query_ptr > m_resultList;
};

View File

@ -158,7 +158,11 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
DropJob *dj = new DropJob();
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
dj->tracksFromMimeData( data );
if ( dropType() == DropTypeLocalItems )
dj->tracksFromMimeData( data, false, true );
else
dj->tracksFromMimeData( data, false, false );
// TODO cant' know if it works or not yet...
return true;

View File

@ -68,6 +68,7 @@ public:
virtual int IDValue() const { return 0; }
virtual DropTypes supportedDropTypes() const { return DropTypesNone; }
virtual void setDropType( DropType type ) { m_dropType = type; }
virtual DropType dropType() const { return m_dropType; }
/// don't call me unless you are a sourcetreeitem. i prefer this to making everyone a friend
void beginRowsAdded( int from, int to ) { emit beginChildRowsAdded( from, to ); }

View File

@ -501,11 +501,11 @@ SourceTreeView::dropEvent( QDropEvent* event )
item->setDropType( m_delegate->hoveredDropType() );
qDebug() << "dropType is " << m_delegate->hoveredDropType();
m_delegate->setDropHoverIndex( QModelIndex() );
dataChanged( index, index );
QTreeView::dropEvent( event );
m_dragging = false;
m_dropIndex = QPersistentModelIndex();
m_delegate->setDropHoverIndex( QModelIndex() );
dataChanged( index, index );
}