mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-14 04:51:53 +02:00
* Streamlined creating new playlists with entries.
* Made XSPFLoader, NewPlaylistWidget & GlobalActionManager use the new Playlist API. * This prevents race-conditions. * Fixed not being able to re-order playlist items.
This commit is contained in:
parent
273eb9654f
commit
ad62bf87dc
@ -62,6 +62,10 @@ void
|
||||
Collection::addPlaylist( const Tomahawk::playlist_ptr& p )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
if ( m_playlists.contains( p->guid() ) )
|
||||
return;
|
||||
|
||||
QList<playlist_ptr> toadd;
|
||||
toadd << p;
|
||||
qDebug() << "Inserted playlist with guid:" << p->guid();
|
||||
|
@ -97,7 +97,7 @@ DatabaseCommand_CreatePlaylist::createPlaylist( DatabaseImpl* lib, bool dynamic)
|
||||
}
|
||||
|
||||
TomahawkSqlQuery cre = lib->newquery();
|
||||
cre.prepare( "INSERT INTO playlist( guid, source, shared, title, info, creator, lastmodified, dynplaylist, createdOn) "
|
||||
cre.prepare( "INSERT INTO playlist( guid, source, shared, title, info, creator, lastmodified, dynplaylist, createdOn ) "
|
||||
"VALUES( :guid, :source, :shared, :title, :info, :creator, :lastmodified, :dynplaylist, :createdOn )" );
|
||||
|
||||
cre.bindValue( ":source", source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
||||
|
@ -56,12 +56,6 @@ void
|
||||
DatabaseCommand_SetPlaylistRevision::postCommitHook()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if ( source().isNull() || source()->collection().isNull() )
|
||||
{
|
||||
qDebug() << "Source has gone offline, not emitting to GUI.";
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_localOnly )
|
||||
return;
|
||||
|
||||
@ -85,7 +79,7 @@ DatabaseCommand_SetPlaylistRevision::postCommitHook()
|
||||
m_addedmap,
|
||||
m_applied );
|
||||
|
||||
if( source()->isLocal() )
|
||||
if ( source()->isLocal() )
|
||||
Servent::instance()->triggerDBSync();
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,6 @@ GlobalActionManager::handlePlaylistCommand( const QUrl& url )
|
||||
return false;
|
||||
}
|
||||
Tomahawk::playlist_ptr pl = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), url.queryItemValue( "title" ), QString(), QString(), false );
|
||||
pl->createNewRevision( uuid(), pl->currentrevision(), QList< Tomahawk::plentry_ptr >() );
|
||||
ViewManager::instance()->show( pl );
|
||||
} else if( parts[ 0 ] == "add" ) {
|
||||
if( !url.hasQueryItem( "playlistid" ) || !url.hasQueryItem( "title" ) || !url.hasQueryItem( "artist" ) ) {
|
||||
|
@ -125,7 +125,8 @@ Playlist::Playlist( const source_ptr& author,
|
||||
const QString& title,
|
||||
const QString& info,
|
||||
const QString& creator,
|
||||
bool shared )
|
||||
bool shared,
|
||||
const QList< Tomahawk::plentry_ptr >& entries )
|
||||
: QObject()
|
||||
, m_source( author )
|
||||
, m_guid( guid )
|
||||
@ -136,6 +137,7 @@ Playlist::Playlist( const source_ptr& author,
|
||||
, m_createdOn( 0 ) // will be set by db command
|
||||
, m_shared( shared )
|
||||
, m_busy( false )
|
||||
, m_initEntries( entries )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "2";
|
||||
init();
|
||||
@ -159,9 +161,24 @@ Playlist::create( const source_ptr& author,
|
||||
const QString& title,
|
||||
const QString& info,
|
||||
const QString& creator,
|
||||
bool shared )
|
||||
bool shared,
|
||||
const QList<Tomahawk::query_ptr>& queries )
|
||||
{
|
||||
playlist_ptr playlist( new Playlist( author, guid, title, info, creator, shared ) );
|
||||
QList< plentry_ptr > entries;
|
||||
foreach( const Tomahawk::query_ptr& query, queries )
|
||||
{
|
||||
plentry_ptr p( new PlaylistEntry );
|
||||
p->setGuid( uuid() );
|
||||
p->setDuration( query->duration() );
|
||||
p->setLastmodified( 0 );
|
||||
p->setAnnotation( "" );
|
||||
p->setQuery( query );
|
||||
|
||||
entries << p;
|
||||
}
|
||||
|
||||
playlist_ptr playlist( new Playlist( author, guid, title, info, creator, shared, entries ) );
|
||||
|
||||
// save to DB in the background
|
||||
// Hope this doesn't cause any problems..
|
||||
// Watch for the created() signal if you need to be sure it's written.
|
||||
@ -178,6 +195,7 @@ Playlist::create( const source_ptr& author,
|
||||
connect( cmd, SIGNAL( finished() ), playlist.data(), SIGNAL( created() ) );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||
playlist->reportCreated( playlist );
|
||||
|
||||
return playlist;
|
||||
}
|
||||
|
||||
@ -223,7 +241,6 @@ Playlist::reportCreated( const playlist_ptr& self )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
Q_ASSERT( self.data() == this );
|
||||
// will emit Collection::playlistCreated(...)
|
||||
m_source->collection()->addPlaylist( self );
|
||||
}
|
||||
|
||||
@ -337,7 +354,14 @@ Playlist::setRevision( const QString& rev,
|
||||
}
|
||||
|
||||
setBusy( false );
|
||||
emit revisionLoaded( pr );
|
||||
|
||||
if ( m_initEntries.count() && currentrevision().isEmpty() )
|
||||
{
|
||||
// add initial tracks
|
||||
createNewRevision( uuid(), currentrevision(), m_initEntries );
|
||||
}
|
||||
else
|
||||
emit revisionLoaded( pr );
|
||||
}
|
||||
|
||||
|
||||
|
@ -123,11 +123,12 @@ public:
|
||||
|
||||
// one CTOR is private, only called by DatabaseCommand_LoadAllPlaylists
|
||||
static Tomahawk::playlist_ptr create( const source_ptr& author,
|
||||
const QString& guid,
|
||||
const QString& title,
|
||||
const QString& info,
|
||||
const QString& creator,
|
||||
bool shared );
|
||||
const QString& guid,
|
||||
const QString& title,
|
||||
const QString& info,
|
||||
const QString& creator,
|
||||
bool shared,
|
||||
const QList<Tomahawk::query_ptr>& queries = QList<Tomahawk::query_ptr>() );
|
||||
|
||||
static bool remove( const playlist_ptr& playlist );
|
||||
bool rename( const QString& title );
|
||||
@ -232,7 +233,8 @@ protected:
|
||||
const QString& title,
|
||||
const QString& info,
|
||||
const QString& creator,
|
||||
bool shared );
|
||||
bool shared,
|
||||
const QList< Tomahawk::plentry_ptr >& entries = QList< Tomahawk::plentry_ptr >() );
|
||||
|
||||
QList< plentry_ptr > newEntries( const QList< plentry_ptr >& entries );
|
||||
PlaylistRevision setNewRevision( const QString& rev,
|
||||
@ -260,7 +262,9 @@ private:
|
||||
unsigned int m_createdOn;
|
||||
bool m_shared;
|
||||
|
||||
QList< plentry_ptr > m_initEntries;
|
||||
QList< plentry_ptr > m_entries;
|
||||
|
||||
bool m_locallyChanged;
|
||||
bool m_busy;
|
||||
};
|
||||
|
@ -326,10 +326,6 @@ 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;
|
||||
|
@ -160,18 +160,12 @@ XSPFLoader::gotBody()
|
||||
continue;
|
||||
}
|
||||
|
||||
plentry_ptr p( new PlaylistEntry );
|
||||
p->setGuid( uuid() );
|
||||
p->setDuration( duration.toInt() / 1000 );
|
||||
p->setLastmodified( 0 );
|
||||
p->setAnnotation( annotation );
|
||||
|
||||
p->setQuery( Tomahawk::Query::get( artist, track, album, uuid() ) );
|
||||
p->query()->setDuration( duration.toInt() / 1000 );
|
||||
query_ptr q = Tomahawk::Query::get( artist, track, album, uuid() );
|
||||
q->setDuration( duration.toInt() / 1000 );
|
||||
if( !url.isEmpty() )
|
||||
p->query()->setResultHint( url );
|
||||
q->setResultHint( url );
|
||||
|
||||
m_entries << p;
|
||||
m_entries << q;
|
||||
}
|
||||
|
||||
if ( origTitle.isEmpty() && m_entries.isEmpty() )
|
||||
@ -196,21 +190,11 @@ XSPFLoader::gotBody()
|
||||
m_title,
|
||||
m_info,
|
||||
m_creator,
|
||||
false );
|
||||
false,
|
||||
m_entries );
|
||||
|
||||
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( onCreated() ) );
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
emit ok( m_playlist );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XSPFLoader::onCreated()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
Playlist* playlist = qobject_cast<Playlist*>(sender());
|
||||
m_playlist->createNewRevision( uuid(), m_playlist->currentrevision(), m_entries );
|
||||
deleteLater();
|
||||
}
|
||||
|
@ -51,9 +51,10 @@ public:
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
QList< Tomahawk::plentry_ptr > entries() const { return m_entries; }
|
||||
QList< Tomahawk::query_ptr > entries() const { return m_entries; }
|
||||
|
||||
void setOverrideTitle( const QString& newTitle );
|
||||
|
||||
signals:
|
||||
void failed();
|
||||
void ok( const Tomahawk::playlist_ptr& );
|
||||
@ -66,15 +67,13 @@ private slots:
|
||||
void networkLoadFinished();
|
||||
void networkError( QNetworkReply::NetworkError e );
|
||||
|
||||
void onCreated();
|
||||
|
||||
private:
|
||||
void reportError();
|
||||
void gotBody();
|
||||
|
||||
bool m_autoCreate;
|
||||
QString m_NS,m_overrideTitle;
|
||||
QList< Tomahawk::plentry_ptr > m_entries;
|
||||
QList< Tomahawk::query_ptr > m_entries;
|
||||
QString m_title, m_info, m_creator;
|
||||
|
||||
QByteArray m_body;
|
||||
|
@ -119,17 +119,17 @@ NewPlaylistWidget::suggestionsFound()
|
||||
{
|
||||
XSPFLoader* loader = qobject_cast<XSPFLoader*>( sender() );
|
||||
|
||||
m_entries = loader->entries();
|
||||
m_queries = loader->entries();
|
||||
|
||||
delete m_suggestionsModel;
|
||||
m_suggestionsModel = new PlaylistModel( ui->suggestionsView );
|
||||
ui->suggestionsView->setPlaylistModel( m_suggestionsModel );
|
||||
|
||||
QList<Tomahawk::query_ptr> ql;
|
||||
foreach( const Tomahawk::plentry_ptr& entry, m_entries )
|
||||
foreach( const Tomahawk::query_ptr& query, m_queries )
|
||||
{
|
||||
m_suggestionsModel->append( entry->query() );
|
||||
ql.append( entry->query() );
|
||||
m_suggestionsModel->append( query );
|
||||
ql.append( query );
|
||||
}
|
||||
|
||||
loader->deleteLater();
|
||||
@ -141,8 +141,7 @@ NewPlaylistWidget::savePlaylist()
|
||||
{
|
||||
Tomahawk::playlist_ptr playlist;
|
||||
|
||||
playlist = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), ui->titleEdit->text(), "", "", false );
|
||||
playlist->createNewRevision( uuid(), playlist->currentrevision(), m_entries );
|
||||
playlist = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), ui->titleEdit->text(), "", "", false, m_queries );
|
||||
|
||||
ViewManager::instance()->show( playlist );
|
||||
cancel();
|
||||
|
@ -75,7 +75,7 @@ private:
|
||||
Ui::NewPlaylistWidget *ui;
|
||||
|
||||
PlaylistModel* m_suggestionsModel;
|
||||
QList< Tomahawk::plentry_ptr > m_entries;
|
||||
QList< Tomahawk::query_ptr > m_queries;
|
||||
|
||||
QTimer m_filterTimer;
|
||||
QString m_tag;
|
||||
|
@ -34,12 +34,10 @@ CategoryAddItem::CategoryAddItem( SourcesModel* model, SourceTreeItem* parent, S
|
||||
: SourceTreeItem( model, parent, SourcesModel::CategoryAdd )
|
||||
, m_categoryType( type )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CategoryAddItem::~CategoryAddItem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString
|
||||
@ -124,8 +122,7 @@ CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
||||
}
|
||||
}
|
||||
|
||||
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false );
|
||||
newpl->addEntries( queries, newpl->currentrevision() );
|
||||
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.
|
||||
|
@ -34,7 +34,6 @@ public:
|
||||
virtual bool willAcceptDrag(const QMimeData* data) const;
|
||||
virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action);
|
||||
|
||||
|
||||
private:
|
||||
SourcesModel::CategoryType m_categoryType;
|
||||
};
|
||||
|
@ -131,7 +131,6 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
||||
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" );
|
||||
@ -174,8 +173,6 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
||||
{
|
||||
qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid() << m_playlist->currentrevision();
|
||||
|
||||
// TODO do we need to use this in the refactor?
|
||||
// QString rev = item->currentlyLoadedPlaylistRevision( playlist->guid() );
|
||||
m_playlist->addEntries( queries, m_playlist->currentrevision() );
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user