mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
added drag and drop to playlists for albums and artists
This commit is contained in:
@@ -793,7 +793,9 @@ GlobalActionManager::acceptsMimeData( const QMimeData* data, bool tracksOnly )
|
|||||||
{
|
{
|
||||||
if ( data->hasFormat( "application/tomahawk.query.list" )
|
if ( data->hasFormat( "application/tomahawk.query.list" )
|
||||||
|| data->hasFormat( "application/tomahawk.plentry.list" )
|
|| data->hasFormat( "application/tomahawk.plentry.list" )
|
||||||
|| data->hasFormat( "application/tomahawk.result.list" ) )
|
|| data->hasFormat( "application/tomahawk.result.list" )
|
||||||
|
|| data->hasFormat( "application/tomahawk.metadata.album" )
|
||||||
|
|| data->hasFormat( "application/tomahawk.metadata.artist" ) )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -827,6 +829,10 @@ GlobalActionManager::tracksFromMimeData( const QMimeData* data )
|
|||||||
emit tracks( tracksFromQueryList( data ) );
|
emit tracks( tracksFromQueryList( data ) );
|
||||||
else if ( data->hasFormat( "application/tomahawk.result.list" ) )
|
else if ( data->hasFormat( "application/tomahawk.result.list" ) )
|
||||||
emit tracks( tracksFromResultList( data ) );
|
emit tracks( tracksFromResultList( data ) );
|
||||||
|
else if ( data->hasFormat( "application/tomahawk.metadata.album" ) )
|
||||||
|
emit tracks( tracksFromAlbumMetaData( data ) );
|
||||||
|
else if ( data->hasFormat( "application/tomahawk.metadata.artist" ) )
|
||||||
|
emit tracks( tracksFromArtistMetaData( data ) );
|
||||||
else if ( data->hasFormat( "text/plain" ) )
|
else if ( data->hasFormat( "text/plain" ) )
|
||||||
{
|
{
|
||||||
QString plainData = QString::fromUtf8( data->data( "text/plain" ).constData() );
|
QString plainData = QString::fromUtf8( data->data( "text/plain" ).constData() );
|
||||||
@@ -923,6 +929,45 @@ GlobalActionManager::tracksFromResultList( const QMimeData* data )
|
|||||||
return queries;
|
return queries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList< query_ptr >
|
||||||
|
GlobalActionManager::tracksFromAlbumMetaData( const QMimeData *data )
|
||||||
|
{
|
||||||
|
QList<query_ptr> queries;
|
||||||
|
QByteArray itemData = data->data( "application/tomahawk.metadata.album" );
|
||||||
|
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||||
|
|
||||||
|
while ( !stream.atEnd() )
|
||||||
|
{
|
||||||
|
QString artist;
|
||||||
|
stream >> artist;
|
||||||
|
QString album;
|
||||||
|
stream >> album;
|
||||||
|
|
||||||
|
artist_ptr artistPtr = Artist::get( artist );
|
||||||
|
album_ptr albumPtr = Album::get( artistPtr, album );
|
||||||
|
queries << albumPtr->tracks();
|
||||||
|
}
|
||||||
|
return queries;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList< query_ptr >
|
||||||
|
GlobalActionManager::tracksFromArtistMetaData( const QMimeData *data )
|
||||||
|
{
|
||||||
|
QList<query_ptr> queries;
|
||||||
|
QByteArray itemData = data->data( "application/tomahawk.metadata.artist" );
|
||||||
|
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||||
|
|
||||||
|
while ( !stream.atEnd() )
|
||||||
|
{
|
||||||
|
QString artist;
|
||||||
|
stream >> artist;
|
||||||
|
|
||||||
|
artist_ptr artistPtr = Artist::get( artist );
|
||||||
|
queries << artistPtr->tracks();
|
||||||
|
}
|
||||||
|
return queries;
|
||||||
|
}
|
||||||
|
|
||||||
/// SPOTIFY URL HANDLING
|
/// SPOTIFY URL HANDLING
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@@ -105,6 +105,8 @@ private:
|
|||||||
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 );
|
||||||
|
QList< Tomahawk::query_ptr > tracksFromArtistMetaData( const QMimeData* d );
|
||||||
|
QList< Tomahawk::query_ptr > tracksFromAlbumMetaData( const QMimeData* d );
|
||||||
|
|
||||||
QString hostname() const;
|
QString hostname() const;
|
||||||
|
|
||||||
|
@@ -293,6 +293,8 @@ TreeModel::flags( const QModelIndex& index ) const
|
|||||||
TreeModelItem* item = itemFromIndex( index );
|
TreeModelItem* item = itemFromIndex( index );
|
||||||
if ( item && !item->result().isNull() )
|
if ( item && !item->result().isNull() )
|
||||||
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
|
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
|
||||||
|
if ( item && ( !item->album().isNull() || !item->artist().isNull() ) )
|
||||||
|
return Qt::ItemIsDragEnabled | defaultFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultFlags;
|
return defaultFlags;
|
||||||
@@ -314,7 +316,11 @@ TreeModel::mimeData( const QModelIndexList &indexes ) const
|
|||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
QByteArray resultData;
|
QByteArray resultData;
|
||||||
|
QByteArray albumData;
|
||||||
|
QByteArray artistData;
|
||||||
QDataStream resultStream( &resultData, QIODevice::WriteOnly );
|
QDataStream resultStream( &resultData, QIODevice::WriteOnly );
|
||||||
|
QDataStream albumStream( &albumData, QIODevice::WriteOnly );
|
||||||
|
QDataStream artistStream( &artistData, QIODevice::WriteOnly );
|
||||||
|
|
||||||
foreach ( const QModelIndex& i, indexes )
|
foreach ( const QModelIndex& i, indexes )
|
||||||
{
|
{
|
||||||
@@ -328,10 +334,25 @@ TreeModel::mimeData( const QModelIndexList &indexes ) const
|
|||||||
const result_ptr& result = item->result();
|
const result_ptr& result = item->result();
|
||||||
resultStream << qlonglong( &result );
|
resultStream << qlonglong( &result );
|
||||||
}
|
}
|
||||||
|
if ( item && !item->album().isNull() )
|
||||||
|
{
|
||||||
|
const album_ptr& album = item->album();
|
||||||
|
albumStream << album->artist()->name() << album->name();
|
||||||
|
}
|
||||||
|
if ( item && !item->artist().isNull() )
|
||||||
|
{
|
||||||
|
const artist_ptr& artist = item->artist();
|
||||||
|
artistStream << artist->name();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QMimeData* mimeData = new QMimeData();
|
QMimeData* mimeData = new QMimeData();
|
||||||
mimeData->setData( "application/tomahawk.result.list", resultData );
|
if ( !artistData.isEmpty() )
|
||||||
|
mimeData->setData( "application/tomahawk.metadata.artist", artistData );
|
||||||
|
else if ( !albumData.isEmpty() )
|
||||||
|
mimeData->setData( "application/tomahawk.metadata.album", albumData );
|
||||||
|
else
|
||||||
|
mimeData->setData( "application/tomahawk.result.list", resultData );
|
||||||
|
|
||||||
return mimeData;
|
return mimeData;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user