mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
TWK-411: Dragging an album/artist to "New Station" creates a station based on that artist instead of all the tracks
This commit is contained in:
parent
a227ae4bcb
commit
1d6c407003
@ -149,6 +149,91 @@ CategoryAddItem::supportedDropTypes( const QMimeData* data ) const
|
||||
bool
|
||||
CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction )
|
||||
{
|
||||
// As DropJob always converts dropped items to query_ptrs for all tracks we need to extract album/artist metadata ourselves for stations
|
||||
if ( m_categoryType == SourcesModel::StationsCategory &&
|
||||
( data->hasFormat( "application/tomahawk.metadata.artist" ) || data->hasFormat( "application/tomahawk.metadata.album" ) ) )
|
||||
{
|
||||
QByteArray mimeData;
|
||||
if ( data->hasFormat( "application/tomahawk.metadata.artist" ) )
|
||||
mimeData = data->data( "application/tomahawk.metadata.artist" );
|
||||
else if ( data->hasFormat( "application/tomahawk.metadata.album" ) )
|
||||
mimeData = data->data( "application/tomahawk.metadata.album" );
|
||||
|
||||
QDataStream stream( &mimeData, QIODevice::ReadOnly );
|
||||
|
||||
dynplaylist_ptr newpl = DynamicPlaylist::create( SourceList::instance()->getLocal(), uuid(), QString(), "", SourceList::instance()->getLocal()->friendlyName(), OnDemand, false );
|
||||
newpl->setMode( OnDemand );
|
||||
|
||||
QString firstArtist;
|
||||
// now we want to add each artist as a filter...
|
||||
QList< dyncontrol_ptr > contrls;
|
||||
while ( !stream.atEnd() )
|
||||
{
|
||||
QString artist;
|
||||
stream >> artist;
|
||||
if ( firstArtist.isEmpty() )
|
||||
firstArtist = artist;
|
||||
|
||||
QString album;
|
||||
if ( data->hasFormat( "application/tomahawk.metadata.album" ) )
|
||||
stream >> album; // throw away album title... we only create artists filters for now
|
||||
|
||||
dyncontrol_ptr c = newpl->generator()->createControl( "Artist" );
|
||||
c->setInput( QString( "%1" ).arg( artist ) );
|
||||
contrls << c;
|
||||
}
|
||||
|
||||
QString name = firstArtist.isEmpty() ? tr( "New Station" ) : tr( "%1 Station" ).arg( firstArtist );
|
||||
newpl->rename( name );
|
||||
newpl->createNewRevision( uuid(), newpl->currentrevision(), newpl->type(), contrls );
|
||||
|
||||
ViewManager::instance()->show( newpl );
|
||||
return true;
|
||||
}
|
||||
|
||||
// This could be needed once echonest supports filtering by album.
|
||||
// If they never will, or if they do and this code still is not used, throw it away!
|
||||
// If you enable this, make sure to remove the checks for album above.
|
||||
|
||||
/* if ( m_categoryType == SourcesModel::StationsCategory && data->hasFormat( "application/tomahawk.metadata.album" ) )
|
||||
{
|
||||
QByteArray mimeData = data->data( "application/tomahawk.metadata.album" );
|
||||
QDataStream stream( &mimeData, QIODevice::ReadOnly );
|
||||
|
||||
dynplaylist_ptr newpl = DynamicPlaylist::create( SourceList::instance()->getLocal(), uuid(), QString(), "", SourceList::instance()->getLocal()->friendlyName(), OnDemand, false );
|
||||
newpl->setMode( OnDemand );
|
||||
|
||||
QString firstAlbum;
|
||||
// now we want to add each artist as a filter...
|
||||
QList< dyncontrol_ptr > contrls;
|
||||
while ( !stream.atEnd() )
|
||||
{
|
||||
QString artist;
|
||||
stream >> artist;
|
||||
QString album;
|
||||
stream >> album;
|
||||
|
||||
if ( firstAlbum.isEmpty() )
|
||||
{
|
||||
firstAlbum = album;
|
||||
}
|
||||
|
||||
dyncontrol_ptr c = newpl->generator()->createControl( "Album" );
|
||||
c->setInput( QString( "%1" ).arg( artist ) );
|
||||
contrls << c;
|
||||
}
|
||||
|
||||
QString name = firstAlbum.isEmpty() ? tr( "New Station" ) : tr( "%1 Station" ).arg( firstAlbum );
|
||||
newpl->rename( name );
|
||||
newpl->createNewRevision( uuid(), newpl->currentrevision(), newpl->type(), contrls );
|
||||
|
||||
ViewManager::instance()->show( newpl );
|
||||
// Give a shot to try to rename it. The playlist has to be created first. ugly.
|
||||
QTimer::singleShot( 300, APP->mainWindow()->sourceTreeView(), SLOT( renamePlaylist() ) );
|
||||
return true;
|
||||
|
||||
} */
|
||||
|
||||
// Create a new playlist seeded with these items
|
||||
DropJob *dj = new DropJob();
|
||||
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
||||
|
@ -496,11 +496,16 @@ SourceTreeView::dropEvent( QDropEvent* event )
|
||||
{
|
||||
const QPoint pos = event->pos();
|
||||
const QModelIndex index = indexAt( pos );
|
||||
PlaylistItem* item = itemFromIndex< PlaylistItem >( index );
|
||||
Q_ASSERT( item );
|
||||
|
||||
item->setDropType( m_delegate->hoveredDropType() );
|
||||
qDebug() << "dropType is " << m_delegate->hoveredDropType();
|
||||
if ( model()->data( index, SourcesModel::SourceTreeItemTypeRole ).toInt() == SourcesModel::PlaylistsCategory )
|
||||
{
|
||||
PlaylistItem* item = itemFromIndex< PlaylistItem >( index );
|
||||
Q_ASSERT( item );
|
||||
|
||||
item->setDropType( m_delegate->hoveredDropType() );
|
||||
qDebug() << "dropType is " << m_delegate->hoveredDropType();
|
||||
}
|
||||
|
||||
QTreeView::dropEvent( event );
|
||||
m_dragging = false;
|
||||
m_dropIndex = QPersistentModelIndex();
|
||||
|
Loading…
x
Reference in New Issue
Block a user