mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-21 16:31:58 +02:00
more work to be able to drag and drop mixed mimetypes (e.g. an artist and some tracks)
This commit is contained in:
parent
09de8c8387
commit
6cb2677c9b
@ -64,7 +64,14 @@ GlobalActionManager::instance()
|
||||
GlobalActionManager::GlobalActionManager( QObject* parent )
|
||||
: QObject( parent )
|
||||
{
|
||||
m_mimeTypes << "application/tomahawk.query.list" << "application/tomahawk.plentry.list" << "application/tomahawk.result.list" << "text/plain";
|
||||
m_mimeTypes << "application/tomahawk.query.list"
|
||||
<< "application/tomahawk.plentry.list"
|
||||
<< "application/tomahawk.result.list"
|
||||
<< "application/tomahawk.result"
|
||||
<< "application/tomahawk.metadata.artist"
|
||||
<< "application/tomahawk.metadata.album"
|
||||
<< "application/tomahawk.mixed"
|
||||
<< "text/plain";
|
||||
}
|
||||
|
||||
GlobalActionManager::~GlobalActionManager()
|
||||
@ -794,6 +801,8 @@ GlobalActionManager::acceptsMimeData( const QMimeData* data, bool tracksOnly )
|
||||
if ( data->hasFormat( "application/tomahawk.query.list" )
|
||||
|| data->hasFormat( "application/tomahawk.plentry.list" )
|
||||
|| data->hasFormat( "application/tomahawk.result.list" )
|
||||
|| data->hasFormat( "application/tomahawk.result" )
|
||||
|| data->hasFormat( "application/tomahawk.mixed" )
|
||||
|| data->hasFormat( "application/tomahawk.metadata.album" )
|
||||
|| data->hasFormat( "application/tomahawk.metadata.artist" ) )
|
||||
{
|
||||
@ -833,6 +842,8 @@ GlobalActionManager::tracksFromMimeData( const QMimeData* data )
|
||||
emit tracks( tracksFromAlbumMetaData( data ) );
|
||||
else if ( data->hasFormat( "application/tomahawk.metadata.artist" ) )
|
||||
emit tracks( tracksFromArtistMetaData( data ) );
|
||||
else if ( data->hasFormat( "application/tomahawk.mixed" ) )
|
||||
tracksFromMixedData( data );
|
||||
else if ( data->hasFormat( "text/plain" ) )
|
||||
{
|
||||
QString plainData = QString::fromUtf8( data->data( "text/plain" ).constData() );
|
||||
@ -968,6 +979,54 @@ GlobalActionManager::tracksFromArtistMetaData( const QMimeData *data )
|
||||
return queries;
|
||||
}
|
||||
|
||||
QList< query_ptr >
|
||||
GlobalActionManager::tracksFromMixedData( const QMimeData *data )
|
||||
{
|
||||
QList< query_ptr > queries;
|
||||
QByteArray itemData = data->data( "application/tomahawk.mixed" );
|
||||
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||
|
||||
QString mimeType;
|
||||
|
||||
while ( !stream.atEnd() )
|
||||
{
|
||||
stream >> mimeType;
|
||||
qDebug() << "mimetype is" << mimeType;
|
||||
|
||||
QByteArray singleData;
|
||||
QDataStream singleStream( &singleData, QIODevice::WriteOnly );
|
||||
|
||||
QMimeData singleMimeData;
|
||||
if ( mimeType == "application/tomahawk.query.list" || mimeType == "application/tomahawk.result.list" )
|
||||
{
|
||||
qlonglong query;
|
||||
stream >> query;
|
||||
singleStream << query;
|
||||
}
|
||||
else if ( mimeType == "application/tomahawk.metadata.album" )
|
||||
{
|
||||
QString artist;
|
||||
stream >> artist;
|
||||
singleStream << artist;
|
||||
QString album;
|
||||
stream >> album;
|
||||
singleStream << album;
|
||||
qDebug() << "got artist" << artist << "and album" << album;
|
||||
}
|
||||
else if ( mimeType == "application/tomahawk.metadata.artist" )
|
||||
{
|
||||
QString artist;
|
||||
stream >> artist;
|
||||
singleStream << artist;
|
||||
qDebug() << "got artist" << artist;
|
||||
}
|
||||
|
||||
singleMimeData.setData( mimeType, singleData );
|
||||
tracksFromMimeData( &singleMimeData );
|
||||
}
|
||||
return queries;
|
||||
}
|
||||
|
||||
/// SPOTIFY URL HANDLING
|
||||
|
||||
bool
|
||||
|
@ -107,6 +107,7 @@ private:
|
||||
QList< Tomahawk::query_ptr > tracksFromResultList( const QMimeData* d );
|
||||
QList< Tomahawk::query_ptr > tracksFromArtistMetaData( const QMimeData* d );
|
||||
QList< Tomahawk::query_ptr > tracksFromAlbumMetaData( const QMimeData* d );
|
||||
QList< Tomahawk::query_ptr > tracksFromMixedData( const QMimeData* d );
|
||||
|
||||
QString hostname() const;
|
||||
|
||||
|
@ -305,7 +305,7 @@ QStringList
|
||||
TreeModel::mimeTypes() const
|
||||
{
|
||||
QStringList types;
|
||||
types << "application/tomahawk.result.list";
|
||||
types << "application/tomahawk.mixed";
|
||||
return types;
|
||||
}
|
||||
|
||||
@ -316,44 +316,36 @@ TreeModel::mimeData( const QModelIndexList &indexes ) const
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
QByteArray resultData;
|
||||
QByteArray albumData;
|
||||
QByteArray artistData;
|
||||
QDataStream resultStream( &resultData, QIODevice::WriteOnly );
|
||||
QDataStream albumStream( &albumData, QIODevice::WriteOnly );
|
||||
QDataStream artistStream( &artistData, QIODevice::WriteOnly );
|
||||
|
||||
foreach ( const QModelIndex& i, indexes )
|
||||
{
|
||||
if ( i.column() > 0 )
|
||||
if ( i.column() > 0 || indexes.contains( i.parent() ) )
|
||||
continue;
|
||||
|
||||
QModelIndex idx = index( i.row(), 0, i.parent() );
|
||||
TreeModelItem* item = itemFromIndex( idx );
|
||||
if ( item && !item->result().isNull() )
|
||||
{
|
||||
const result_ptr& result = item->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() )
|
||||
TreeModelItem* item = itemFromIndex( i );
|
||||
if ( !item )
|
||||
continue;
|
||||
|
||||
if ( !item->artist().isNull() )
|
||||
{
|
||||
const artist_ptr& artist = item->artist();
|
||||
artistStream << artist->name();
|
||||
resultStream << QString( "application/tomahawk.metadata.artist" ) << artist->name();
|
||||
}
|
||||
else if ( !item->album().isNull() )
|
||||
{
|
||||
const album_ptr& album = item->album();
|
||||
resultStream << QString( "application/tomahawk.metadata.album" ) << album->artist()->name() << album->name();
|
||||
}
|
||||
else if ( !item->result().isNull() )
|
||||
{
|
||||
const result_ptr& result = item->result();
|
||||
resultStream << QString( "application/tomahawk.result.list" ) << qlonglong( &result );
|
||||
}
|
||||
}
|
||||
|
||||
QMimeData* mimeData = new QMimeData();
|
||||
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 );
|
||||
|
||||
mimeData->setData( "application/tomahawk.mixed", resultData );
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user