mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
Send tracks moved to spotify
This commit is contained in:
@@ -432,22 +432,39 @@ SpotifyPlaylistUpdater::tomahawkTracksInserted( const QList< plentry_ptr >& trac
|
|||||||
// Find the trackid of the nearest spotify track
|
// Find the trackid of the nearest spotify track
|
||||||
QList< plentry_ptr > plTracks = playlist()->entries();
|
QList< plentry_ptr > plTracks = playlist()->entries();
|
||||||
Q_ASSERT( pos-1 < plTracks.size() );
|
Q_ASSERT( pos-1 < plTracks.size() );
|
||||||
|
const QString startPos = nearestSpotifyTrack( plTracks, pos - 1 );
|
||||||
for ( int i = pos-1; i >= 0; i-- )
|
msg[ "startPosition" ] = startPos;
|
||||||
{
|
|
||||||
if ( !plTracks[ i ]->annotation().isEmpty() && plTracks[ i ]->annotation().contains( "spotify:track") )
|
|
||||||
{
|
|
||||||
msg[ "startPosition" ] = plTracks[ i ]->annotation();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_waitingForIds = tracks;
|
m_waitingForIds = tracks;
|
||||||
|
|
||||||
msg[ "playlistid" ] = m_spotifyId;
|
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;
|
QVariantList tracksJson;
|
||||||
foreach ( const plentry_ptr& ple, tracks )
|
foreach ( const plentry_ptr& ple, entries )
|
||||||
{
|
{
|
||||||
const query_ptr q = ple->query();
|
const query_ptr q = ple->query();
|
||||||
if ( q.isNull() )
|
if ( q.isNull() )
|
||||||
@@ -458,9 +475,8 @@ SpotifyPlaylistUpdater::tomahawkTracksInserted( const QList< plentry_ptr >& trac
|
|||||||
|
|
||||||
tracksJson << queryToVariant( q );
|
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() << 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -74,12 +74,16 @@ private slots:
|
|||||||
// SpotifyResolver message handlers, all take msgtype, msg as argument
|
// SpotifyResolver message handlers, all take msgtype, msg as argument
|
||||||
void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg );
|
void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg );
|
||||||
void onTracksRemovedReturn( 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 checkDeleteDialog() const;
|
||||||
|
|
||||||
void playlistRevisionLoaded();
|
void playlistRevisionLoaded();
|
||||||
private:
|
private:
|
||||||
void init();
|
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 QVariantList queriesToVariant( const QList< Tomahawk::query_ptr >& queries );
|
||||||
static QVariant queryToVariant( const Tomahawk::query_ptr& query );
|
static QVariant queryToVariant( const Tomahawk::query_ptr& query );
|
||||||
|
Reference in New Issue
Block a user