1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 17:29:42 +01:00

Send tracks moved to spotify

This commit is contained in:
Leo Franchi 2012-04-14 11:44:27 -04:00
parent b7b5e60f98
commit 4ec0117c43
2 changed files with 59 additions and 12 deletions

View File

@ -432,22 +432,39 @@ SpotifyPlaylistUpdater::tomahawkTracksInserted( const QList< plentry_ptr >& trac
// Find the trackid of the nearest spotify track
QList< plentry_ptr > plTracks = playlist()->entries();
Q_ASSERT( pos-1 < plTracks.size() );
for ( int i = pos-1; i >= 0; i-- )
{
if ( !plTracks[ i ]->annotation().isEmpty() && plTracks[ i ]->annotation().contains( "spotify:track") )
{
msg[ "startPosition" ] = plTracks[ i ]->annotation();
break;
}
}
const QString startPos = nearestSpotifyTrack( plTracks, pos - 1 );
msg[ "startPosition" ] = startPos;
m_waitingForIds = tracks;
msg[ "playlistid" ] = m_spotifyId;
msg[ "tracks" ] = plentryToVariant( tracks );
m_spotify.data()->sendMessage( msg, this, "onTracksInsertedReturn" );
}
QString
SpotifyPlaylistUpdater::nearestSpotifyTrack( const QList< plentry_ptr >& entries, int pos )
{
for ( int i = pos; i >= 0; i-- )
{
if ( !entries[ i ]->annotation().isEmpty() && entries[ i ]->annotation().contains( "spotify:track") )
{
return entries[ i ]->annotation();
}
}
return QString();
}
QVariantList
SpotifyPlaylistUpdater::plentryToVariant( const QList< plentry_ptr >& entries )
{
QVariantList tracksJson;
foreach ( const plentry_ptr& ple, tracks )
foreach ( const plentry_ptr& ple, entries )
{
const query_ptr q = ple->query();
if ( q.isNull() )
@ -458,9 +475,8 @@ SpotifyPlaylistUpdater::tomahawkTracksInserted( const QList< plentry_ptr >& trac
tracksJson << queryToVariant( q );
}
msg[ "tracks" ] = tracksJson;
m_spotify.data()->sendMessage( msg, this, "onTracksInsertedReturn" );
return tracksJson;
}
@ -563,6 +579,33 @@ SpotifyPlaylistUpdater::tomahawkTracksMoved( const QList< plentry_ptr >& tracks,
{
qDebug() << ple->query()->track() << ple->query()->artist();
}
qDebug() << Q_FUNC_INFO << "updating spotify resolver with moved tracks to:" << position;
QVariantMap msg;
msg[ "_msgtype" ] = "moveTracksInPlaylist";
msg[ "oldrev" ] = m_latestRev;
// Find the trackid of the nearest spotify track
QList< plentry_ptr > plTracks = playlist()->entries();
Q_ASSERT( position-1 < plTracks.size() );
const QString startPos = nearestSpotifyTrack( plTracks, position );
msg[ "startPosition" ] = startPos;
msg[ "playlistid" ] = m_spotifyId;
msg[ "tracks" ] = plentryToVariant( tracks );
m_spotify.data()->sendMessage( msg, this, "onTracksMovedReturn" );
}
void
SpotifyPlaylistUpdater::onTracksMovedReturn( const QString& msgType, const QVariantMap& msg )
{
const bool success = msg.value( "success" ).toBool();
qDebug() << Q_FUNC_INFO << "GOT RETURN FOR tracksMoved call from spotify!" << msgType << msg << "Succeeded?" << success;
m_latestRev = msg.value( "revid" ).toString();
}

View File

@ -74,12 +74,16 @@ private slots:
// SpotifyResolver message handlers, all take msgtype, msg as argument
void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg );
void onTracksRemovedReturn( const QString& msgType, const QVariantMap& msg );
void onTracksMovedReturn( const QString& msgType, const QVariantMap& msg );
void checkDeleteDialog() const;
void playlistRevisionLoaded();
private:
void init();
/// Finds the nearest spotify id from pos to the beginning of the playlist
QString nearestSpotifyTrack( const QList< Tomahawk::plentry_ptr >& entries, int pos );
QVariantList plentryToVariant( const QList< Tomahawk::plentry_ptr >& entries );
static QVariantList queriesToVariant( const QList< Tomahawk::query_ptr >& queries );
static QVariant queryToVariant( const Tomahawk::query_ptr& query );