From f72c60969bae1c67c356b7551f631278120ea1a7 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 17 Jun 2011 12:40:30 -0400 Subject: [PATCH] allow dropping of results as well as queries on the categoryadd items Fixes TWK-232 --- src/sourcetree/items/categoryitems.cpp | 47 +++++++++++++++++++------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/sourcetree/items/categoryitems.cpp b/src/sourcetree/items/categoryitems.cpp index 82064636e..ec15b582d 100644 --- a/src/sourcetree/items/categoryitems.cpp +++ b/src/sourcetree/items/categoryitems.cpp @@ -114,7 +114,8 @@ bool CategoryAddItem::willAcceptDrag( const QMimeData* data ) const { if( ( m_categoryType == SourcesModel::PlaylistsCategory || m_categoryType == SourcesModel::StationsCategory ) && - data->hasFormat( "application/tomahawk.query.list" ) ) { + data->hasFormat( "application/tomahawk.query.list" ) || + data->hasFormat( "application/tomahawk.result.list" ) ) { return true; } return false; @@ -124,21 +125,43 @@ bool CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction ) { // Create a new playlist seeded with these items - if( data->hasFormat( "application/tomahawk.query.list" ) ) { - QByteArray itemData = data->data( "application/tomahawk.query.list" ); - QDataStream stream( &itemData, QIODevice::ReadOnly ); + if( data->hasFormat( "application/tomahawk.query.list" ) || data->hasFormat( "application/tomahawk.result.list" ) ) { + QList< Tomahawk::query_ptr > queries; - while ( !stream.atEnd() ) - { - qlonglong qptr; - stream >> qptr; + if( data->hasFormat( "application/tomahawk.query.list" ) ) { + QByteArray itemData = data->data( "application/tomahawk.query.list" ); + QDataStream stream( &itemData, QIODevice::ReadOnly ); - Tomahawk::query_ptr* query = reinterpret_cast(qptr); - if ( query && !query->isNull() ) + while ( !stream.atEnd() ) { - qDebug() << "Dropped query item:" << query->data()->artist() << "-" << query->data()->track(); - queries << *query; + qlonglong qptr; + stream >> qptr; + + Tomahawk::query_ptr* query = reinterpret_cast(qptr); + if ( query && !query->isNull() ) + { + qDebug() << "Dropped query item:" << query->data()->artist() << "-" << query->data()->track(); + queries << *query; + } + } + } else if( data->hasFormat( "application/tomahawk.result.list" ) ) { + QByteArray itemData = data->data( "application/tomahawk.result.list" ); + QDataStream stream( &itemData, QIODevice::ReadOnly ); + + while ( !stream.atEnd() ) + { + qlonglong qptr; + stream >> qptr; + + Tomahawk::result_ptr* result = reinterpret_cast(qptr); + if ( result && !result->isNull() ) + { + qDebug() << "Dropped result item:" << result->data()->artist() << "-" << result->data()->track(); + query_ptr q = result->data()->toQuery(); + q->addResults( QList< result_ptr >() << *result ); + queries << q; + } } }