From 6a6e2754c4f182bc24cd9ef67383cf4aa015384d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Sat, 7 Apr 2012 00:35:39 +0200 Subject: [PATCH] Also rename playlist if renamed in spotify. Todo: Both ways --- src/accounts/spotify/SpotifyAccount.cpp | 20 +++++++++++++++++++ .../spotify/SpotifyPlaylistUpdater.cpp | 9 +++++++++ src/accounts/spotify/SpotifyPlaylistUpdater.h | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/accounts/spotify/SpotifyAccount.cpp b/src/accounts/spotify/SpotifyAccount.cpp index b00d25729..5ad79aaa6 100644 --- a/src/accounts/spotify/SpotifyAccount.cpp +++ b/src/accounts/spotify/SpotifyAccount.cpp @@ -216,6 +216,26 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg updater->spotifyTracksMoved( tracksList, newRev, oldRev ); } + else if( msgType == "playlistRenamed" ) + { + const QString plid = msg.value( "id" ).toString(); + // We should already be syncing this playlist if we get updates for it + Q_ASSERT( m_updaters.contains( plid ) ); + + qDebug() << Q_FUNC_INFO; + if ( !m_updaters.contains( plid ) ) + return; + + SpotifyPlaylistUpdater* updater = m_updaters[ plid ]; + Q_ASSERT( updater->sync() ); + + qDebug() << "Playlist renamed fetched in tomahawk"; + const QString title = msg.value( "name" ).toString(); + const QString newRev = msg.value( "revid" ).toString(); + const QString oldRev = msg.value( "oldRev" ).toString(); + + updater->spotifyPlaylistRenamed( title, newRev, oldRev ); + } } diff --git a/src/accounts/spotify/SpotifyPlaylistUpdater.cpp b/src/accounts/spotify/SpotifyPlaylistUpdater.cpp index 29b540bd0..29bfbeec7 100644 --- a/src/accounts/spotify/SpotifyPlaylistUpdater.cpp +++ b/src/accounts/spotify/SpotifyPlaylistUpdater.cpp @@ -221,6 +221,15 @@ SpotifyPlaylistUpdater::spotifyTracksRemoved( const QVariantList& trackIds, cons } } +void +SpotifyPlaylistUpdater::spotifyPlaylistRenamed( const QString title, const QString& newRev, const QString& oldRev ) +{ + Q_UNUSED( newRev ); + Q_UNUSED( oldRev ); + /// @note to self: should do some checking before trying to update + playlist()->rename( title ); + +} void SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QString& newRev, const QString& oldRev ) diff --git a/src/accounts/spotify/SpotifyPlaylistUpdater.h b/src/accounts/spotify/SpotifyPlaylistUpdater.h index 719deaf7b..f8cb7fb47 100644 --- a/src/accounts/spotify/SpotifyPlaylistUpdater.h +++ b/src/accounts/spotify/SpotifyPlaylistUpdater.h @@ -52,7 +52,7 @@ public: 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 spotifyPlaylistRenamed( const QString title, const QString& newRev, const QString& oldRev ); protected: virtual void removeFromSettings(const QString& group) const; virtual void saveToSettings(const QString& group) const;