mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 16:44:05 +02:00
Allow users to drop tracks onto New Station, and creates a station seeded with song filters
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
#include "sourcetreeview.h"
|
#include "sourcetreeview.h"
|
||||||
|
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <playlist/dynamic/GeneratorInterface.h>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -94,17 +95,18 @@ CategoryAddItem::icon() const
|
|||||||
bool
|
bool
|
||||||
CategoryAddItem::willAcceptDrag( const QMimeData* data ) const
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction )
|
||||||
{
|
{
|
||||||
// Create a new playlist seeded with these items
|
// 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" );
|
QByteArray itemData = data->data( "application/tomahawk.query.list" );
|
||||||
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||||
QList< Tomahawk::query_ptr > queries;
|
QList< Tomahawk::query_ptr > queries;
|
||||||
@@ -122,11 +124,34 @@ CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( m_categoryType == SourcesModel::PlaylistsCategory ) {
|
||||||
|
|
||||||
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false, queries );
|
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false, queries );
|
||||||
ViewManager::instance()->show( newpl );
|
ViewManager::instance()->show( newpl );
|
||||||
|
|
||||||
// Give a shot to try to rename it. The playlist has to be created first. ugly.
|
// Give a shot to try to rename it. The playlist has to be created first. ugly.
|
||||||
QTimer::singleShot( 300, APP->mainWindow()->sourceTreeView(), SLOT( renamePlaylist() ) );
|
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() ) );
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user