mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
* Make SpotifyPlaylistUpdater check for playlists being loaded.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
|
* Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
|
||||||
* Copyright 2012, Hugo Lindström <hugolm84@gmail.com>
|
* Copyright 2012, Hugo Lindström <hugolm84@gmail.com>
|
||||||
|
* Copyright 2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -220,6 +221,7 @@ SpotifyPlaylistUpdater::typeIcon() const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::setSync( bool sync )
|
SpotifyPlaylistUpdater::setSync( bool sync )
|
||||||
{
|
{
|
||||||
@@ -239,6 +241,7 @@ SpotifyPlaylistUpdater::sync() const
|
|||||||
return m_sync;
|
return m_sync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::setOwner( bool owner )
|
SpotifyPlaylistUpdater::setOwner( bool owner )
|
||||||
{
|
{
|
||||||
@@ -251,12 +254,14 @@ SpotifyPlaylistUpdater::setOwner( bool owner )
|
|||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SpotifyPlaylistUpdater::owner() const
|
SpotifyPlaylistUpdater::owner() const
|
||||||
{
|
{
|
||||||
return m_isOwner;
|
return m_isOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::setCollaborative( bool collab )
|
SpotifyPlaylistUpdater::setCollaborative( bool collab )
|
||||||
{
|
{
|
||||||
@@ -269,12 +274,14 @@ SpotifyPlaylistUpdater::setCollaborative( bool collab )
|
|||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SpotifyPlaylistUpdater::collaborative() const
|
SpotifyPlaylistUpdater::collaborative() const
|
||||||
{
|
{
|
||||||
return m_collaborative;
|
return m_collaborative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::setSubscribedStatus( bool subscribed )
|
SpotifyPlaylistUpdater::setSubscribedStatus( bool subscribed )
|
||||||
{
|
{
|
||||||
@@ -324,6 +331,7 @@ SpotifyPlaylistUpdater::canSubscribe() const
|
|||||||
return m_canSubscribe;
|
return m_canSubscribe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::setSubscribers( int numSubscribers )
|
SpotifyPlaylistUpdater::setSubscribers( int numSubscribers )
|
||||||
{
|
{
|
||||||
@@ -336,6 +344,7 @@ SpotifyPlaylistUpdater::setSubscribers( int numSubscribers )
|
|||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PlaylistDeleteQuestions
|
PlaylistDeleteQuestions
|
||||||
SpotifyPlaylistUpdater::deleteQuestions() const
|
SpotifyPlaylistUpdater::deleteQuestions() const
|
||||||
{
|
{
|
||||||
@@ -358,7 +367,11 @@ SpotifyPlaylistUpdater::setQuestionResults( const QMap< int, bool > results )
|
|||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::spotifyTracksAdded( const QVariantList& tracks, const QString& startPosId, const QString& newRev, const QString& oldRev )
|
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
|
// 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
|
// wait for any to be complete
|
||||||
@@ -399,7 +412,11 @@ SpotifyPlaylistUpdater::spotifyTracksAdded( const QVariantList& tracks, const QS
|
|||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::spotifyTracksRemoved( const QVariantList& trackIds, const QString& newRev, const QString& oldRev )
|
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
|
// 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
|
// wait for any to be complete
|
||||||
@@ -435,7 +452,6 @@ SpotifyPlaylistUpdater::spotifyTracksRemoved( const QVariantList& trackIds, cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Now remove them all
|
// Now remove them all
|
||||||
foreach( const plentry_ptr& torm, toRemove )
|
foreach( const plentry_ptr& torm, toRemove )
|
||||||
entries.removeAll( torm );
|
entries.removeAll( torm );
|
||||||
@@ -452,10 +468,11 @@ SpotifyPlaylistUpdater::spotifyTracksRemoved( const QVariantList& trackIds, cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::spotifyPlaylistRenamed( const QString& title, const QString& newRev, const QString& oldRev )
|
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
|
// 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
|
// wait for any to be complete
|
||||||
@@ -467,11 +484,11 @@ SpotifyPlaylistUpdater::spotifyPlaylistRenamed( const QString& title, const QStr
|
|||||||
Q_UNUSED( oldRev );
|
Q_UNUSED( oldRev );
|
||||||
/// @note to self: should do some checking before trying to update
|
/// @note to self: should do some checking before trying to update
|
||||||
playlist()->rename( title );
|
playlist()->rename( title );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::tomahawkPlaylistRenamed(const QString &newT, const QString &oldT)
|
SpotifyPlaylistUpdater::tomahawkPlaylistRenamed( const QString &newT, const QString &oldT )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
QVariantMap msg;
|
QVariantMap msg;
|
||||||
@@ -485,10 +502,15 @@ SpotifyPlaylistUpdater::tomahawkPlaylistRenamed(const QString &newT, const QStri
|
|||||||
m_spotify.data()->sendMessage( msg, this, "onPlaylistRename" );
|
m_spotify.data()->sendMessage( msg, this, "onPlaylistRename" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QString& newStartPos, const QString& newRev, const QString& oldRev )
|
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
|
// 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
|
// wait for any to be complete
|
||||||
@@ -496,13 +518,11 @@ SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QS
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "Moving some tracks in a spotify-synced playlist, tracks:" << tracks << "to new startpos:" << newStartPos;
|
qDebug() << "Moving some tracks in a spotify-synced playlist, tracks:" << tracks << "to new startpos:" << newStartPos;
|
||||||
// Uh oh, dont' want to get out of sync!!
|
// Uh oh, dont' want to get out of sync!!
|
||||||
// Q_ASSERT( m_latestRev == oldRev );
|
// Q_ASSERT( m_latestRev == oldRev );
|
||||||
// m_latestRev = newRev;
|
// m_latestRev = newRev;
|
||||||
QList< plentry_ptr > entries = playlist()->entries();
|
QList< plentry_ptr > entries = playlist()->entries();
|
||||||
|
|
||||||
QList< plentry_ptr > toMove;
|
QList< plentry_ptr > toMove;
|
||||||
for ( QList< plentry_ptr >::iterator iter = entries.begin(); iter != entries.end(); )
|
for ( QList< plentry_ptr >::iterator iter = entries.begin(); iter != entries.end(); )
|
||||||
{
|
{
|
||||||
@@ -519,7 +539,6 @@ SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QS
|
|||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Find the position of the track to insert from
|
// Find the position of the track to insert from
|
||||||
if ( newStartPos.isEmpty() )
|
if ( newStartPos.isEmpty() )
|
||||||
{
|
{
|
||||||
@@ -579,7 +598,6 @@ SpotifyPlaylistUpdater::tomahawkTracksInserted( const QList< plentry_ptr >& trac
|
|||||||
m_waitingForIds = tracks;
|
m_waitingForIds = tracks;
|
||||||
|
|
||||||
msg[ "playlistid" ] = m_spotifyId;
|
msg[ "playlistid" ] = m_spotifyId;
|
||||||
|
|
||||||
msg[ "tracks" ] = plentryToVariant( tracks );
|
msg[ "tracks" ] = plentryToVariant( tracks );
|
||||||
|
|
||||||
m_spotify.data()->sendMessage( msg, this, "onTracksInsertedReturn" );
|
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;
|
qDebug() << Q_FUNC_INFO << "GOT RETURN FOR tracksInserted call from spotify!" << msgType << msg << "Succeeded?" << success;
|
||||||
m_latestRev = msg.value( "revid" ).toString();
|
m_latestRev = msg.value( "revid" ).toString();
|
||||||
|
|
||||||
|
|
||||||
const QVariantList trackPositionsInserted = msg.value( "trackPosInserted" ).toList();
|
const QVariantList trackPositionsInserted = msg.value( "trackPosInserted" ).toList();
|
||||||
const QVariantList trackIdsInserted = msg.value( "trackIdInserted" ).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
|
// Update with latest rev when/if we use it
|
||||||
// saveToSettings();
|
// saveToSettings();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -718,7 +734,7 @@ SpotifyPlaylistUpdater::onTracksRemovedReturn( const QString& msgType, const QVa
|
|||||||
void
|
void
|
||||||
SpotifyPlaylistUpdater::tomahawkTracksMoved( const QList< plentry_ptr >& tracks, int position )
|
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
|
// 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
|
// 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[ "startPosition" ] = startPos;
|
||||||
msg[ "playlistid" ] = m_spotifyId;
|
msg[ "playlistid" ] = m_spotifyId;
|
||||||
|
|
||||||
msg[ "tracks" ] = plentryToVariant( tracks );
|
msg[ "tracks" ] = plentryToVariant( tracks );
|
||||||
|
|
||||||
m_spotify.data()->sendMessage( msg, this, "onTracksMovedReturn" );
|
m_spotify.data()->sendMessage( msg, this, "onTracksMovedReturn" );
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
|
* Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
|
||||||
* Copyright 2012, Hugo Lindström <hugolm84@gmail.com>
|
* Copyright 2012, Hugo Lindström <hugolm84@gmail.com>
|
||||||
|
* Copyright 2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -29,9 +30,9 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
namespace Tomahawk {
|
namespace Tomahawk {
|
||||||
namespace Accounts {
|
namespace Accounts {
|
||||||
class SpotifyAccount;
|
class SpotifyAccount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DLLEXPORT SpotifyPlaylistUpdater : public Tomahawk::PlaylistUpdaterInterface
|
class DLLEXPORT SpotifyPlaylistUpdater : public Tomahawk::PlaylistUpdaterInterface
|
||||||
@@ -54,6 +55,7 @@ public:
|
|||||||
|
|
||||||
bool sync() const;
|
bool sync() const;
|
||||||
void setSync( bool sync );
|
void setSync( bool sync );
|
||||||
|
|
||||||
bool subscribed() const;
|
bool subscribed() const;
|
||||||
// actually change the subscribed value in spotify
|
// actually change the subscribed value in spotify
|
||||||
void setSubscribed( bool subscribed );
|
void setSubscribed( bool subscribed );
|
||||||
@@ -64,6 +66,7 @@ public:
|
|||||||
void setSubscribers( int numSubscribers );
|
void setSubscribers( int numSubscribers );
|
||||||
int subscribers() const { return m_subscribers; }
|
int subscribers() const { return m_subscribers; }
|
||||||
// Collaborative actions
|
// Collaborative actions
|
||||||
|
|
||||||
void setOwner( bool owner );
|
void setOwner( bool owner );
|
||||||
bool owner() const;
|
bool owner() const;
|
||||||
bool collaborative() const;
|
bool collaborative() const;
|
||||||
@@ -76,6 +79,7 @@ public:
|
|||||||
virtual void setQuestionResults( const QMap< int, bool > results );
|
virtual void setQuestionResults( const QMap< int, bool > results );
|
||||||
|
|
||||||
void remove( bool askToDeletePlaylist = true );
|
void remove( bool askToDeletePlaylist = true );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/// Spotify callbacks when we are directly instructed from the resolver
|
/// 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 spotifyTracksAdded( const QVariantList& tracks, const QString& startPosId, const QString& newRev, const QString& oldRev );
|
||||||
@@ -97,6 +101,7 @@ private slots:
|
|||||||
void unsyncOrDelete( bool toDelete );
|
void unsyncOrDelete( bool toDelete );
|
||||||
|
|
||||||
void playlistRevisionLoaded();
|
void playlistRevisionLoaded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
void saveToSettings();
|
void saveToSettings();
|
||||||
|
Reference in New Issue
Block a user