From a39a9812892574ad35b0f93d46320ed47b76d48b Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 26 Apr 2013 05:06:24 +0200 Subject: [PATCH] * Make SpotifyPlaylistUpdater check for playlists being loaded. --- .../spotify/SpotifyPlaylistUpdater.cpp | 45 ++++++++++++------- .../accounts/spotify/SpotifyPlaylistUpdater.h | 13 ++++-- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.cpp b/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.cpp index eb7dd8394..0979d5ab0 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2012, Leo Franchi * Copyright 2012, Hugo Lindström + * Copyright 2013, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -220,6 +221,7 @@ SpotifyPlaylistUpdater::typeIcon() const } #endif + void SpotifyPlaylistUpdater::setSync( bool sync ) { @@ -239,6 +241,7 @@ SpotifyPlaylistUpdater::sync() const return m_sync; } + void SpotifyPlaylistUpdater::setOwner( bool owner ) { @@ -251,12 +254,14 @@ SpotifyPlaylistUpdater::setOwner( bool owner ) emit changed(); } + bool SpotifyPlaylistUpdater::owner() const { return m_isOwner; } + void SpotifyPlaylistUpdater::setCollaborative( bool collab ) { @@ -269,12 +274,14 @@ SpotifyPlaylistUpdater::setCollaborative( bool collab ) emit changed(); } + bool SpotifyPlaylistUpdater::collaborative() const { return m_collaborative; } + void SpotifyPlaylistUpdater::setSubscribedStatus( bool subscribed ) { @@ -324,6 +331,7 @@ SpotifyPlaylistUpdater::canSubscribe() const return m_canSubscribe; } + void SpotifyPlaylistUpdater::setSubscribers( int numSubscribers ) { @@ -336,6 +344,7 @@ SpotifyPlaylistUpdater::setSubscribers( int numSubscribers ) emit changed(); } + PlaylistDeleteQuestions SpotifyPlaylistUpdater::deleteQuestions() const { @@ -358,7 +367,11 @@ SpotifyPlaylistUpdater::setQuestionResults( const QMap< int, bool > results ) void SpotifyPlaylistUpdater::spotifyTracksAdded( const QVariantList& tracks, const QString& startPosId, const QString& newRev, const QString& oldRev ) { - if( playlist()->busy() ) + if ( !playlist()->loaded() ) + { + playlist()->loadRevision(); + } + if ( playlist()->busy() || !playlist()->loaded() ) { // 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 @@ -399,7 +412,11 @@ SpotifyPlaylistUpdater::spotifyTracksAdded( const QVariantList& tracks, const QS void SpotifyPlaylistUpdater::spotifyTracksRemoved( const QVariantList& trackIds, const QString& newRev, const QString& oldRev ) { - if( playlist()->busy() ) + if ( !playlist()->loaded() ) + { + playlist()->loadRevision(); + } + if ( playlist()->busy() || !playlist()->loaded() ) { // 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 @@ -435,7 +452,6 @@ SpotifyPlaylistUpdater::spotifyTracksRemoved( const QVariantList& trackIds, cons } } - // Now remove them all foreach( const plentry_ptr& torm, toRemove ) entries.removeAll( torm ); @@ -452,10 +468,11 @@ SpotifyPlaylistUpdater::spotifyTracksRemoved( const QVariantList& trackIds, cons } } + void SpotifyPlaylistUpdater::spotifyPlaylistRenamed( const QString& title, const QString& newRev, const QString& oldRev ) { - if( playlist()->busy() ) + 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 @@ -467,11 +484,11 @@ SpotifyPlaylistUpdater::spotifyPlaylistRenamed( const QString& title, const QStr Q_UNUSED( oldRev ); /// @note to self: should do some checking before trying to update playlist()->rename( title ); - } + void -SpotifyPlaylistUpdater::tomahawkPlaylistRenamed(const QString &newT, const QString &oldT) +SpotifyPlaylistUpdater::tomahawkPlaylistRenamed( const QString &newT, const QString &oldT ) { qDebug() << Q_FUNC_INFO; QVariantMap msg; @@ -485,10 +502,15 @@ SpotifyPlaylistUpdater::tomahawkPlaylistRenamed(const QString &newT, const QStri m_spotify.data()->sendMessage( msg, this, "onPlaylistRename" ); } + void SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QString& newStartPos, const QString& newRev, const QString& oldRev ) { - if( playlist()->busy() ) + if ( !playlist()->loaded() ) + { + playlist()->loadRevision(); + } + if ( playlist()->busy() || !playlist()->loaded() ) { // 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 @@ -496,13 +518,11 @@ SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QS 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(); ) { @@ -519,7 +539,6 @@ SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QS ++iter; } - // Find the position of the track to insert from if ( newStartPos.isEmpty() ) { @@ -579,7 +598,6 @@ SpotifyPlaylistUpdater::tomahawkTracksInserted( const QList< plentry_ptr >& trac m_waitingForIds = tracks; msg[ "playlistid" ] = m_spotifyId; - msg[ "tracks" ] = plentryToVariant( tracks ); m_spotify.data()->sendMessage( msg, this, "onTracksInsertedReturn" ); @@ -629,7 +647,6 @@ SpotifyPlaylistUpdater::onTracksInsertedReturn( const QString& msgType, const QV qDebug() << Q_FUNC_INFO << "GOT RETURN FOR tracksInserted call from spotify!" << msgType << msg << "Succeeded?" << success; m_latestRev = msg.value( "revid" ).toString(); - const QVariantList trackPositionsInserted = msg.value( "trackPosInserted" ).toList(); const QVariantList trackIdsInserted = msg.value( "trackIdInserted" ).toList(); @@ -677,7 +694,6 @@ SpotifyPlaylistUpdater::onTracksInsertedReturn( const QString& msgType, const QV // Update with latest rev when/if we use it // saveToSettings(); - } @@ -718,7 +734,7 @@ SpotifyPlaylistUpdater::onTracksRemovedReturn( const QString& msgType, const QVa void SpotifyPlaylistUpdater::tomahawkTracksMoved( const QList< plentry_ptr >& tracks, int position ) { - if( playlist()->busy() ) + if ( playlist()->busy() ) { // the playlist has had the new revision set, but it might not be finished, if it's not finished, playlist()->entries() still // contains the *old* order, so we get the wrong data @@ -747,7 +763,6 @@ SpotifyPlaylistUpdater::tomahawkTracksMoved( const QList< plentry_ptr >& tracks, msg[ "startPosition" ] = startPos; msg[ "playlistid" ] = m_spotifyId; - msg[ "tracks" ] = plentryToVariant( tracks ); m_spotify.data()->sendMessage( msg, this, "onTracksMovedReturn" ); diff --git a/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.h b/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.h index df1320a3d..1a566f7af 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.h +++ b/src/libtomahawk/accounts/spotify/SpotifyPlaylistUpdater.h @@ -2,6 +2,7 @@ * * Copyright 2010-2012, Leo Franchi * Copyright 2012, Hugo Lindström + * Copyright 2013, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,9 +30,9 @@ #include namespace Tomahawk { -namespace Accounts { - class SpotifyAccount; -} + namespace Accounts { + class SpotifyAccount; + } } class DLLEXPORT SpotifyPlaylistUpdater : public Tomahawk::PlaylistUpdaterInterface @@ -54,6 +55,7 @@ public: bool sync() const; void setSync( bool sync ); + bool subscribed() const; // actually change the subscribed value in spotify void setSubscribed( bool subscribed ); @@ -64,6 +66,7 @@ public: void setSubscribers( int numSubscribers ); int subscribers() const { return m_subscribers; } // Collaborative actions + void setOwner( bool owner ); bool owner() const; bool collaborative() const; @@ -76,6 +79,7 @@ public: virtual void setQuestionResults( const QMap< int, bool > results ); void remove( bool askToDeletePlaylist = true ); + 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 ); @@ -97,12 +101,13 @@ private slots: void unsyncOrDelete( bool toDelete ); void playlistRevisionLoaded(); + private: void init(); void saveToSettings(); /// Finds the nearest spotify id from pos to the beginning of the playlist - QString nearestSpotifyTrack( const QList< Tomahawk::plentry_ptr >& entries, int pos ); + 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 );