1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 17:29:42 +01:00

Don't allow dropping of playlist items onto the current playlist in the sourcetree.

This commit is contained in:
Leo Franchi 2011-05-18 18:13:41 -04:00
parent 73ffa506c7
commit f16451196b
3 changed files with 21 additions and 1 deletions

View File

@ -296,11 +296,19 @@ PlaylistModel::onRevisionLoaded( Tomahawk::PlaylistRevision revision )
loadPlaylist( m_playlist );
}
QMimeData*
PlaylistModel::mimeData( const QModelIndexList& indexes ) const
{
// Add the playlist id to the mime data so that we can detect dropping on ourselves
QMimeData* d = TrackModel::mimeData( indexes );
d->setData( "application/tomahawk.playlist.id", m_playlist->guid().toLatin1() );
return d;
}
bool
PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent )
{
qDebug() << "LALALA";
Q_UNUSED( column );
if ( action == Qt::IgnoreAction || isReadOnly() )
return true;
@ -310,6 +318,10 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r
&& !data->hasFormat( "application/tomahawk.result.list" ) )
return false;
if ( data->hasFormat( "application/tomahawk.playlist.id" ) &&
data->data( "application/tomahawk.playlist.id" ) == m_playlist->guid() )
return false; // don't allow dropping on ourselves
int beginRow;
if ( row != -1 )
beginRow = row;

View File

@ -32,6 +32,7 @@
#include "dllmacro.h"
class QMimeData;
class QMetaData;
class DLLEXPORT PlaylistModel : public TrackModel
@ -47,6 +48,7 @@ public:
QVariant data( const QModelIndex& index, int role ) const;
QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
virtual QMimeData* mimeData ( const QModelIndexList& indexes ) const;
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent );
Tomahawk::playlist_ptr playlist() const { return m_playlist; }

View File

@ -112,6 +112,12 @@ bool
PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
{
QList< Tomahawk::query_ptr > queries;
if ( data->hasFormat( "application/tomahawk.playlist.id" ) &&
data->data( "application/tomahawk.playlist.id" ) == m_playlist->guid() )
return false; // don't allow dropping on ourselves
if ( data->hasFormat( "application/tomahawk.result.list" ) )
{
QByteArray itemData = data->data( "application/tomahawk.result.list" );