mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Merge pull request #182 from xhochy/feature/select-existing-spotify-playlist-instead-of-double-adding
Do not double add existing spotify playlists
This commit is contained in:
@@ -1396,6 +1396,18 @@ SpotifyAccount::sendMessage( const QVariantMap &m, QObject* obj, const QString&
|
|||||||
return qid;
|
return qid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
SpotifyAccount::hasPlaylist(const QString& plId)
|
||||||
|
{
|
||||||
|
return m_updaters.contains( plId );
|
||||||
|
}
|
||||||
|
|
||||||
|
Tomahawk::playlist_ptr
|
||||||
|
SpotifyAccount::playlistForURI(const QString& plId)
|
||||||
|
{
|
||||||
|
return m_updaters[ plId ]->playlist();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyAccount::registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylistUpdater* updater )
|
SpotifyAccount::registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylistUpdater* updater )
|
||||||
|
@@ -103,7 +103,8 @@ public:
|
|||||||
virtual SipPlugin* sipPlugin() { return 0; }
|
virtual SipPlugin* sipPlugin() { return 0; }
|
||||||
virtual bool preventEnabling() const { return m_preventEnabling; }
|
virtual bool preventEnabling() const { return m_preventEnabling; }
|
||||||
|
|
||||||
|
bool hasPlaylist( const QString& plId );
|
||||||
|
Tomahawk::playlist_ptr playlistForURI( const QString& plId );
|
||||||
void registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylistUpdater* updater );
|
void registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylistUpdater* updater );
|
||||||
void registerPlaylistInfo( const QString& name, const QString& plid, const QString &revid, const bool sync, const bool subscribed , const bool owner = false);
|
void registerPlaylistInfo( const QString& name, const QString& plid, const QString &revid, const bool sync, const bool subscribed , const bool owner = false);
|
||||||
void registerPlaylistInfo( SpotifyPlaylistInfo* info );
|
void registerPlaylistInfo( SpotifyPlaylistInfo* info );
|
||||||
|
@@ -401,14 +401,23 @@ SpotifyParser::checkBrowseFinished()
|
|||||||
if ( m_createNewPlaylist && !m_tracks.isEmpty() )
|
if ( m_createNewPlaylist && !m_tracks.isEmpty() )
|
||||||
{
|
{
|
||||||
QString spotifyUsername;
|
QString spotifyUsername;
|
||||||
|
bool spotifyAccountLoggedIn = Accounts::SpotifyAccount::instance() && Accounts::SpotifyAccount::instance()->loggedIn();
|
||||||
|
|
||||||
if ( Accounts::SpotifyAccount::instance() && Accounts::SpotifyAccount::instance()->loggedIn() )
|
if ( spotifyAccountLoggedIn )
|
||||||
{
|
{
|
||||||
QVariantHash creds = Accounts::SpotifyAccount::instance()->credentials();
|
QVariantHash creds = Accounts::SpotifyAccount::instance()->credentials();
|
||||||
spotifyUsername = creds.value( "username" ).toString();
|
spotifyUsername = creds.value( "username" ).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_playlist = Playlist::create( SourceList::instance()->getLocal(),
|
if ( spotifyAccountLoggedIn && Accounts::SpotifyAccount::instance()->hasPlaylist( m_browseUri ) )
|
||||||
|
{
|
||||||
|
// The playlist is already registered with Tomahawk, so just open it instead of adding another instance.
|
||||||
|
m_playlist = Accounts::SpotifyAccount::instance()->playlistForURI( m_browseUri );
|
||||||
|
playlistCreated();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_playlist = Playlist::create( SourceList::instance()->getLocal(),
|
||||||
uuid(),
|
uuid(),
|
||||||
m_title,
|
m_title,
|
||||||
m_info,
|
m_info,
|
||||||
@@ -416,29 +425,30 @@ SpotifyParser::checkBrowseFinished()
|
|||||||
false,
|
false,
|
||||||
m_tracks );
|
m_tracks );
|
||||||
|
|
||||||
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
|
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
|
||||||
|
|
||||||
if ( Accounts::SpotifyAccount::instance() && Accounts::SpotifyAccount::instance()->loggedIn() )
|
if ( spotifyAccountLoggedIn )
|
||||||
{
|
{
|
||||||
SpotifyPlaylistUpdater* updater = new SpotifyPlaylistUpdater(
|
SpotifyPlaylistUpdater* updater = new SpotifyPlaylistUpdater(
|
||||||
Accounts::SpotifyAccount::instance(), m_playlist->currentrevision(), m_browseUri, m_playlist );
|
Accounts::SpotifyAccount::instance(), m_playlist->currentrevision(), m_browseUri, m_playlist );
|
||||||
|
|
||||||
|
|
||||||
// If the user isnt dropping a playlist the he owns, its subscribeable
|
// If the user isnt dropping a playlist the he owns, its subscribeable
|
||||||
if ( !m_browseUri.contains( spotifyUsername ) )
|
if ( !m_browseUri.contains( spotifyUsername ) )
|
||||||
updater->setCanSubscribe( true );
|
updater->setCanSubscribe( true );
|
||||||
else
|
else
|
||||||
updater->setOwner( true );
|
updater->setOwner( true );
|
||||||
|
|
||||||
updater->setCollaborative( m_collaborative );
|
updater->setCollaborative( m_collaborative );
|
||||||
updater->setSubscribers( m_subscribers );
|
updater->setSubscribers( m_subscribers );
|
||||||
// Just register the infos
|
// Just register the infos
|
||||||
Accounts::SpotifyAccount::instance()->registerPlaylistInfo( m_title, m_browseUri, m_browseUri, false, false, updater->owner() );
|
Accounts::SpotifyAccount::instance()->registerPlaylistInfo( m_title, m_browseUri, m_browseUri, false, false, updater->owner() );
|
||||||
Accounts::SpotifyAccount::instance()->registerUpdaterForPlaylist( m_browseUri, updater );
|
Accounts::SpotifyAccount::instance()->registerUpdaterForPlaylist( m_browseUri, updater );
|
||||||
// On default, set the playlist as subscribed
|
// On default, set the playlist as subscribed
|
||||||
if( !updater->owner() )
|
if( !updater->owner() )
|
||||||
Accounts::SpotifyAccount::instance()->setSubscribedForPlaylist( m_playlist, true );
|
Accounts::SpotifyAccount::instance()->setSubscribedForPlaylist( m_playlist, true );
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user