mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-21 05:11:44 +02:00
* Support dropping items on Queue in sidebar.
This commit is contained in:
@@ -20,10 +20,12 @@
|
|||||||
#include "QueueItem.h"
|
#include "QueueItem.h"
|
||||||
|
|
||||||
#include "utils/ImageRegistry.h"
|
#include "utils/ImageRegistry.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
#include "playlist/TrackView.h"
|
#include "playlist/TrackView.h"
|
||||||
#include "playlist/PlayableProxyModel.h"
|
#include "playlist/PlayableProxyModel.h"
|
||||||
#include "ViewManager.h"
|
#include "ViewManager.h"
|
||||||
#include "ViewPage.h"
|
#include "ViewPage.h"
|
||||||
|
#include "DropJob.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
@@ -83,3 +85,89 @@ QueueItem::activate()
|
|||||||
Tomahawk::ViewPage* page = ViewManager::instance()->showQueuePage();
|
Tomahawk::ViewPage* page = ViewManager::instance()->showQueuePage();
|
||||||
model()->linkSourceItemToPage( this, page );
|
model()->linkSourceItemToPage( this, page );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
QueueItem::willAcceptDrag( const QMimeData* data ) const
|
||||||
|
{
|
||||||
|
return DropJob::acceptsMimeData( data, DropJob::Track );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SourceTreeItem::DropTypes
|
||||||
|
QueueItem::supportedDropTypes( const QMimeData* data ) const
|
||||||
|
{
|
||||||
|
if ( data->hasFormat( "application/tomahawk.mixed" ) )
|
||||||
|
{
|
||||||
|
// If this is mixed but only queries/results, we can still handle them
|
||||||
|
bool mixedQueries = true;
|
||||||
|
|
||||||
|
QByteArray itemData = data->data( "application/tomahawk.mixed" );
|
||||||
|
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||||
|
QString mimeType;
|
||||||
|
qlonglong val;
|
||||||
|
|
||||||
|
while ( !stream.atEnd() )
|
||||||
|
{
|
||||||
|
stream >> mimeType;
|
||||||
|
if ( mimeType != "application/tomahawk.query.list" &&
|
||||||
|
mimeType != "application/tomahawk.result.list" )
|
||||||
|
{
|
||||||
|
mixedQueries = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
stream >> val;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mixedQueries )
|
||||||
|
return (DropTypes)(DropTypeThisTrack | DropTypeThisAlbum | DropTypeAllFromArtist | DropTypeLocalItems | DropTypeTop50);
|
||||||
|
else
|
||||||
|
return DropTypesNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( data->hasFormat( "application/tomahawk.query.list" ) )
|
||||||
|
return (DropTypes)(DropTypeThisTrack | DropTypeThisAlbum | DropTypeAllFromArtist | DropTypeLocalItems | DropTypeTop50);
|
||||||
|
else if ( data->hasFormat( "application/tomahawk.result.list" ) )
|
||||||
|
return (DropTypes)(DropTypeThisTrack | DropTypeThisAlbum | DropTypeAllFromArtist | DropTypeLocalItems | DropTypeTop50);
|
||||||
|
else if ( data->hasFormat( "application/tomahawk.metadata.album" ) )
|
||||||
|
return (DropTypes)(DropTypeThisAlbum | DropTypeAllFromArtist | DropTypeLocalItems | DropTypeTop50);
|
||||||
|
else if ( data->hasFormat( "application/tomahawk.metadata.artist" ) )
|
||||||
|
return (DropTypes)(DropTypeAllFromArtist | DropTypeLocalItems | DropTypeTop50);
|
||||||
|
else if ( data->hasFormat( "text/plain" ) )
|
||||||
|
{
|
||||||
|
return DropTypesNone;
|
||||||
|
}
|
||||||
|
return DropTypesNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
QueueItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
||||||
|
{
|
||||||
|
Q_UNUSED( action );
|
||||||
|
|
||||||
|
if ( !DropJob::acceptsMimeData( data, DropJob::Track ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
DropJob *dj = new DropJob();
|
||||||
|
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
||||||
|
|
||||||
|
dj->setDropTypes( DropJob::Track );
|
||||||
|
dj->setDropAction( DropJob::Append );
|
||||||
|
dj->tracksFromMimeData( data, false, false );
|
||||||
|
|
||||||
|
// TODO can't know if it works or not yet...
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
QueueItem::parsedDroppedTracks( const QList< Tomahawk::query_ptr >& tracks )
|
||||||
|
{
|
||||||
|
if ( tracks.count() )
|
||||||
|
{
|
||||||
|
ViewManager::instance()->queue()->trackView()->model()->appendQueries( tracks );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tDebug() << "ERROR: Could not add empty track list to queue!";
|
||||||
|
}
|
||||||
|
@@ -36,9 +36,16 @@ public:
|
|||||||
|
|
||||||
int unlistenedCount() const;
|
int unlistenedCount() const;
|
||||||
|
|
||||||
|
virtual bool willAcceptDrag( const QMimeData* data ) const;
|
||||||
|
virtual DropTypes supportedDropTypes( const QMimeData* data ) const;
|
||||||
|
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void activate();
|
virtual void activate();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void parsedDroppedTracks( const QList<Tomahawk::query_ptr>& tracks );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_sortValue;
|
int m_sortValue;
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
|
Reference in New Issue
Block a user