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

Handle moves from spotify (doesn't show up till a restart)

This commit is contained in:
Leo Franchi 2012-04-13 19:58:57 -04:00
parent bc443d25ac
commit f72e123140
3 changed files with 57 additions and 12 deletions

View File

@ -318,11 +318,12 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
SpotifyPlaylistUpdater* updater = m_updaters[ plid ];
Q_ASSERT( updater->sync() );
const QVariantList tracksList = msg.value( "trackPositions" ).toList();
const QString newStartPos = msg.value( "newStartPosition" ).toString();
const QVariantList tracksList = msg.value( "tracks" ).toList();
const QString newRev = msg.value( "revid" ).toString();
const QString oldRev = msg.value( "oldRev" ).toString();
updater->spotifyTracksMoved( tracksList, newRev, oldRev );
updater->spotifyTracksMoved( tracksList, newStartPos, newRev, oldRev );
}
else if( msgType == "playlistRenamed" )
{

View File

@ -344,16 +344,60 @@ SpotifyPlaylistUpdater::tomahawkPlaylistRenamed(const QString &newT, const QStri
}
void
SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QString& newRev, const QString& oldRev )
SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QString& newStartPos, const QString& newRev, const QString& oldRev )
{
// TODO
// if( playlist()->busy() )
// {
// // We might still be waiting for a add/remove tracks command to finish, so the entries we get here might be stale
// // wait for any to be complete
// m_queuedOps << NewClosure( 0, "", this, "spotifyPlaylistRenamed", title, newRev, oldRev );
// return;
// }
if( playlist()->busy() )
{
// We might still be waiting for a add/remove tracks command to finish, so the entries we get here might be stale
// wait for any to be complete
m_queuedOps << NewClosure( 0, "", this, SLOT(spotifyTracksMoved(QVariantList, QString, QString, QString)), tracks, newStartPos, newRev, oldRev );
return;
}
qDebug() << "Moving some tracks in a spotify-synced playlist, tracks:" << tracks << "to new startpos:" << newStartPos;
// Uh oh, dont' want to get out of sync!!
// Q_ASSERT( m_latestRev == oldRev );
// m_latestRev = newRev;
QList< plentry_ptr > entries = playlist()->entries();
QList< plentry_ptr > toMove;
for ( QList< plentry_ptr >::iterator iter = entries.begin(); iter != entries.end(); )
{
if ( (*iter)->annotation().isEmpty() )
continue;
if ( tracks.contains( (*iter)->annotation() ) )
{
toMove << *iter;
iter = entries.erase( iter );
continue;
}
++iter;
}
// Find the position of the track to insert from
for ( QList< plentry_ptr >::iterator iter = entries.begin(); iter != entries.end(); ++iter )
{
if ( (*iter)->annotation() == newStartPos )
{
++iter;
while ( !toMove.isEmpty() )
{
qDebug() << "Adding moved track to playlist at pos (end:" << (iter == entries.end());
if ( iter != entries.end() )
qDebug() << (*iter)->query()->track() << (*iter)->query()->artist();
iter = entries.insert( iter, toMove.takeLast() );
}
break;
}
}
m_blockUpdatesForNextRevision = true;
playlist()->createNewRevision( uuid(), playlist()->currentrevision(), entries );
}

View File

@ -59,7 +59,7 @@ public slots:
/// Spotify callbacks when we are directly instructed from the resolver
void spotifyTracksAdded( const QVariantList& tracks, const QString& startPosId, const QString& newRev, const QString& oldRev );
void spotifyTracksRemoved( const QVariantList& tracks, const QString& newRev, const QString& oldRev );
void spotifyTracksMoved( const QVariantList& tracks, const QString& newRev, const QString& oldRev );
void spotifyTracksMoved( const QVariantList& tracks, const QString& newStartPos, const QString& newRev, const QString& oldRev );
void spotifyPlaylistRenamed( const QString& title, const QString& newRev, const QString& oldRev );
protected: