mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 15:47:38 +02:00
Fix some logic in the subscribing, and properly subscribe on initial drop
This commit is contained in:
@@ -547,47 +547,12 @@ SpotifyAccount::subscribeActionTriggered( bool )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_ASSERT( updater );
|
||||||
if ( !updater )
|
if ( !updater )
|
||||||
{
|
|
||||||
tLog() << "No SpotifyPlaylistUpdater in payload slot of triggered action! Uh oh!!";
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
SpotifyPlaylistInfo* info = m_allSpotifyPlaylists.value( updater->spotifyId(), 0 );
|
// Toggle subscription status
|
||||||
|
setSubscribedForPlaylist( playlist, !updater->subscribed() );
|
||||||
// When we unsubscribe, all playlists is resent
|
|
||||||
// and we will could loose the SpotifyPlaylistInfo, but all we really need is the id
|
|
||||||
if ( updater->spotifyId().isEmpty() )
|
|
||||||
{
|
|
||||||
tLog() << "No spotify id in updater, WTF?";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !info )
|
|
||||||
{
|
|
||||||
info = new SpotifyPlaylistInfo( playlist->title(),
|
|
||||||
updater->spotifyId(),
|
|
||||||
updater->spotifyId(),
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
registerPlaylistInfo( info );
|
|
||||||
}
|
|
||||||
|
|
||||||
info->subscribed = !updater->subscribed();
|
|
||||||
|
|
||||||
QVariantMap msg;
|
|
||||||
msg[ "_msgtype" ] = "setSubscription";
|
|
||||||
msg[ "subscribe" ] = info->subscribed;
|
|
||||||
msg[ "playlistid" ] = info->plid;
|
|
||||||
|
|
||||||
sendMessage( msg, this );
|
|
||||||
|
|
||||||
updater->setSync( !updater->sync() );
|
|
||||||
updater->setSubscribed( !updater->subscribed() );
|
|
||||||
info->sync = !updater->sync();
|
|
||||||
info->subscribed = !updater->subscribed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -661,6 +626,63 @@ SpotifyAccount::syncActionTriggered( bool )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::setSubscribedForPlaylist( const playlist_ptr& playlist, bool subscribed )
|
||||||
|
{
|
||||||
|
SpotifyPlaylistUpdater* updater = 0;
|
||||||
|
QList<PlaylistUpdaterInterface*> updaters = playlist->updaters();
|
||||||
|
foreach ( PlaylistUpdaterInterface* u, updaters )
|
||||||
|
{
|
||||||
|
if ( SpotifyPlaylistUpdater* spotifyUpdater = qobject_cast< SpotifyPlaylistUpdater* >( u ) )
|
||||||
|
{
|
||||||
|
updater = spotifyUpdater;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !updater )
|
||||||
|
{
|
||||||
|
tLog() << "No SpotifyPlaylistUpdater in payload slot of triggered action! Uh oh!!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpotifyPlaylistInfo* info = m_allSpotifyPlaylists.value( updater->spotifyId(), 0 );
|
||||||
|
|
||||||
|
// When we unsubscribe, all playlists is resent
|
||||||
|
// and we will could loose the SpotifyPlaylistInfo, but all we really need is the id
|
||||||
|
if ( updater->spotifyId().isEmpty() )
|
||||||
|
{
|
||||||
|
tLog() << "No spotify id in updater, WTF?";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !info )
|
||||||
|
{
|
||||||
|
info = new SpotifyPlaylistInfo( playlist->title(),
|
||||||
|
updater->spotifyId(),
|
||||||
|
updater->spotifyId(),
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
registerPlaylistInfo( info );
|
||||||
|
}
|
||||||
|
|
||||||
|
info->subscribed = subscribed;
|
||||||
|
info->sync = subscribed;
|
||||||
|
|
||||||
|
QVariantMap msg;
|
||||||
|
msg[ "_msgtype" ] = "setSubscription";
|
||||||
|
msg[ "subscribe" ] = info->subscribed;
|
||||||
|
msg[ "playlistid" ] = info->plid;
|
||||||
|
|
||||||
|
sendMessage( msg, this );
|
||||||
|
|
||||||
|
updater->setSync( subscribed );
|
||||||
|
updater->setSubscribed( subscribed );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
playlist_ptr
|
playlist_ptr
|
||||||
SpotifyAccount::playlistFromAction( QAction* action ) const
|
SpotifyAccount::playlistFromAction( QAction* action ) const
|
||||||
{
|
{
|
||||||
|
@@ -36,6 +36,8 @@ class ScriptResolver;
|
|||||||
|
|
||||||
namespace Tomahawk {
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
class SpotifyParser;
|
||||||
|
|
||||||
namespace InfoSystem
|
namespace InfoSystem
|
||||||
{
|
{
|
||||||
class SpotifyInfoPlugin;
|
class SpotifyInfoPlugin;
|
||||||
@@ -150,6 +152,7 @@ private:
|
|||||||
void fetchFullPlaylist( SpotifyPlaylistInfo* playlist );
|
void fetchFullPlaylist( SpotifyPlaylistInfo* playlist );
|
||||||
|
|
||||||
void setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync );
|
void setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync );
|
||||||
|
void setSubscribedForPlaylist( const playlist_ptr& pl, bool subscribed );
|
||||||
|
|
||||||
void createActions();
|
void createActions();
|
||||||
void removeActions();
|
void removeActions();
|
||||||
@@ -175,6 +178,7 @@ private:
|
|||||||
|
|
||||||
SmartPointerList< QAction > m_customActions;
|
SmartPointerList< QAction > m_customActions;
|
||||||
friend class ::SpotifyPlaylistUpdater;
|
friend class ::SpotifyPlaylistUpdater;
|
||||||
|
friend class Tomahawk::SpotifyParser;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -370,12 +370,13 @@ SpotifyParser::checkBrowseFinished()
|
|||||||
if ( !m_browseUri.contains( creds.value( "username" ).toString() ) )
|
if ( !m_browseUri.contains( creds.value( "username" ).toString() ) )
|
||||||
updater->setCanSubscribe( true );
|
updater->setCanSubscribe( true );
|
||||||
|
|
||||||
updater->setSubscribed( true );
|
|
||||||
updater->setSync( true );
|
|
||||||
|
|
||||||
// Just register the infos
|
// Just register the infos
|
||||||
Accounts::SpotifyAccount::instance()->registerPlaylistInfo( m_title, m_browseUri, m_browseUri, false, false );
|
Accounts::SpotifyAccount::instance()->registerPlaylistInfo( m_title, m_browseUri, m_browseUri, false, false );
|
||||||
Accounts::SpotifyAccount::instance()->registerUpdaterForPlaylist( m_browseUri, updater );
|
Accounts::SpotifyAccount::instance()->registerUpdaterForPlaylist( m_browseUri, updater );
|
||||||
|
|
||||||
|
|
||||||
|
Accounts::SpotifyAccount::instance()->setSubscribedForPlaylist( m_playlist, true );
|
||||||
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user