1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 00:09:47 +01:00

Allow users to drop tracks onto New Station, and creates a station seeded with song filters

This commit is contained in:
Leo Franchi 2011-05-25 20:01:02 -04:00
parent d1b8b2851d
commit 5f2791f2b3

View File

@ -25,6 +25,7 @@
#include "sourcetreeview.h"
#include <QMimeData>
#include <playlist/dynamic/GeneratorInterface.h>
using namespace Tomahawk;
@ -94,17 +95,18 @@ CategoryAddItem::icon() const
bool
CategoryAddItem::willAcceptDrag( const QMimeData* data ) const
{
if( m_categoryType == SourcesModel::PlaylistsCategory && data->hasFormat( "application/tomahawk.query.list" ) ) {
if( ( m_categoryType == SourcesModel::PlaylistsCategory || m_categoryType == SourcesModel::StationsCategory ) &&
data->hasFormat( "application/tomahawk.query.list" ) ) {
return true;
}
return false;
}
bool
CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction )
{
// Create a new playlist seeded with these items
if( m_categoryType == SourcesModel::PlaylistsCategory && data->hasFormat( "application/tomahawk.query.list" ) ) {
if( data->hasFormat( "application/tomahawk.query.list" ) ) {
QByteArray itemData = data->data( "application/tomahawk.query.list" );
QDataStream stream( &itemData, QIODevice::ReadOnly );
QList< Tomahawk::query_ptr > queries;
@ -122,11 +124,34 @@ CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
}
}
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false, queries );
ViewManager::instance()->show( newpl );
if( m_categoryType == SourcesModel::PlaylistsCategory ) {
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false, queries );
ViewManager::instance()->show( newpl );
// Give a shot to try to rename it. The playlist has to be created first. ugly.
QTimer::singleShot( 300, APP->mainWindow()->sourceTreeView(), SLOT( renamePlaylist() ) );
} else if( m_categoryType == SourcesModel::StationsCategory ) {
// seed the playlist with these song filters
dynplaylist_ptr newpl = DynamicPlaylist::create( SourceList::instance()->getLocal(), uuid(), "New Station", "", SourceList::instance()->getLocal()->friendlyName(), OnDemand, false );
newpl->setMode( OnDemand );
// now we want to add each query as a song filter...
QList< dyncontrol_ptr > contrls;
foreach( const Tomahawk::query_ptr& q, queries ) {
dyncontrol_ptr c = newpl->generator()->createControl( "Song" );
c->setInput( QString( "%1 %2" ).arg( q->track() ).arg( q->artist() ) );
contrls << c;
}
newpl->createNewRevision( uuid(), newpl->currentrevision(), newpl->type(), contrls );
ViewManager::instance()->show( newpl );
// Give a shot to try to rename it. The playlist has to be created first. ugly.
QTimer::singleShot( 300, APP->mainWindow()->sourceTreeView(), SLOT( renamePlaylist() ) );
}
// Give a shot to try to rename it. The playlist has to be created first. ugly.
QTimer::singleShot( 300, APP->mainWindow()->sourceTreeView(), SLOT( renamePlaylist() ) );
return true;
}
return false;