mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-13 20:39:57 +01:00
Use a QHash to avoid a bunch of loops
This commit is contained in:
parent
74d6ccd47d
commit
6194517eab
@ -553,16 +553,8 @@ SpotifyAccount::subscribeActionTriggered( bool )
|
||||
return;
|
||||
}
|
||||
|
||||
SpotifyPlaylistInfo* info = 0;
|
||||
foreach ( SpotifyPlaylistInfo* ifo, m_allSpotifyPlaylists )
|
||||
{
|
||||
if ( ifo->plid == updater->spotifyId() )
|
||||
{
|
||||
info = ifo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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() )
|
||||
@ -648,22 +640,14 @@ SpotifyAccount::syncActionTriggered( bool )
|
||||
}
|
||||
else
|
||||
{
|
||||
SpotifyPlaylistInfo* info = 0;
|
||||
foreach ( SpotifyPlaylistInfo* ifo, m_allSpotifyPlaylists )
|
||||
{
|
||||
if ( ifo->plid == updater->spotifyId() )
|
||||
{
|
||||
info = ifo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SpotifyPlaylistInfo* info = m_allSpotifyPlaylists.value( updater->spotifyId(), 0 );
|
||||
|
||||
Q_ASSERT( info );
|
||||
if ( info )
|
||||
info->sync = !updater->sync();
|
||||
|
||||
if ( m_configWidget.data() )
|
||||
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
|
||||
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists.values() );
|
||||
|
||||
if ( !updater->sync() )
|
||||
{
|
||||
@ -737,7 +721,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
|
||||
else if ( msgType == "allPlaylists" )
|
||||
{
|
||||
const QVariantList playlists = msg.value( "playlists" ).toList();
|
||||
qDeleteAll( m_allSpotifyPlaylists );
|
||||
qDeleteAll( m_allSpotifyPlaylists.values() );
|
||||
m_allSpotifyPlaylists.clear();
|
||||
|
||||
foreach ( const QVariant& playlist, playlists )
|
||||
@ -755,12 +739,12 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
|
||||
continue;
|
||||
}
|
||||
|
||||
m_allSpotifyPlaylists << new SpotifyPlaylistInfo( name, plid, revid, sync, subscribed );
|
||||
registerPlaylistInfo( new SpotifyPlaylistInfo( name, plid, revid, sync, subscribed ) );
|
||||
}
|
||||
|
||||
if ( !m_configWidget.isNull() )
|
||||
{
|
||||
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
|
||||
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists.values() );
|
||||
}
|
||||
}
|
||||
else if ( msgType == "tracksAdded" )
|
||||
@ -936,7 +920,7 @@ SpotifyAccount::clearUser( bool permanentlyDelete )
|
||||
|
||||
m_updaters.clear();
|
||||
|
||||
qDeleteAll( m_allSpotifyPlaylists );
|
||||
qDeleteAll( m_allSpotifyPlaylists.values() );
|
||||
m_allSpotifyPlaylists.clear();
|
||||
|
||||
m_qidToSlotMap.clear();
|
||||
@ -964,7 +948,7 @@ SpotifyAccount::configurationWidget()
|
||||
m_configWidget = QWeakPointer< SpotifyAccountConfig >( new SpotifyAccountConfig( this ) );
|
||||
connect( m_configWidget.data(), SIGNAL( login( QString,QString ) ), this, SLOT( login( QString,QString ) ) );
|
||||
connect( m_configWidget.data(), SIGNAL( logout() ), this, SLOT( logout() ) );
|
||||
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
|
||||
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists.values() );
|
||||
}
|
||||
|
||||
if ( m_spotifyResolver.isNull() || !m_spotifyResolver.data()->running() )
|
||||
@ -1021,7 +1005,7 @@ SpotifyAccount::saveConfig()
|
||||
setConfiguration( config );
|
||||
|
||||
m_configWidget.data()->saveSettings();
|
||||
foreach ( SpotifyPlaylistInfo* pl, m_allSpotifyPlaylists )
|
||||
foreach ( SpotifyPlaylistInfo* pl, m_allSpotifyPlaylists.values() )
|
||||
{
|
||||
// qDebug() << "Checking changed state:" << pl->changed << pl->name << pl->sync;
|
||||
if ( pl->changed )
|
||||
@ -1224,14 +1208,16 @@ SpotifyAccount::registerUpdaterForPlaylist( const QString& plId, SpotifyPlaylist
|
||||
void
|
||||
SpotifyAccount::registerPlaylistInfo( const QString& name, const QString& plid, const QString &revid, const bool sync, const bool subscribed )
|
||||
{
|
||||
m_allSpotifyPlaylists << new SpotifyPlaylistInfo( name, plid, revid, sync, subscribed );
|
||||
m_allSpotifyPlaylists[ plid ] = new SpotifyPlaylistInfo( name, plid, revid, sync, subscribed );
|
||||
}
|
||||
|
||||
void
|
||||
SpotifyAccount::registerPlaylistInfo( SpotifyPlaylistInfo* info )
|
||||
{
|
||||
m_allSpotifyPlaylists << info;
|
||||
m_allSpotifyPlaylists[ info->plid ] = info;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SpotifyAccount::unregisterUpdater( const QString& plid )
|
||||
{
|
||||
@ -1300,14 +1286,14 @@ SpotifyAccount::loadPlaylists()
|
||||
void
|
||||
SpotifyAccount::setSyncForPlaylist( const QString& spotifyPlaylistId, bool sync )
|
||||
{
|
||||
foreach ( SpotifyPlaylistInfo* info, m_allSpotifyPlaylists )
|
||||
{
|
||||
if ( info->plid == spotifyPlaylistId )
|
||||
info->sync = sync;
|
||||
}
|
||||
SpotifyPlaylistInfo* info = m_allSpotifyPlaylists.value( spotifyPlaylistId, 0 );
|
||||
|
||||
if ( info )
|
||||
info->sync = sync;
|
||||
|
||||
|
||||
if ( !m_configWidget.isNull() )
|
||||
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists );
|
||||
m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists.values() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -166,7 +166,7 @@ private:
|
||||
QMap<QString, QVariant > m_qidToExtraData;
|
||||
|
||||
// List of synced spotify playlists in config UI
|
||||
QList< SpotifyPlaylistInfo* > m_allSpotifyPlaylists;
|
||||
QHash< QString, SpotifyPlaylistInfo* > m_allSpotifyPlaylists;
|
||||
QHash< QString, SpotifyPlaylistUpdater* > m_updaters;
|
||||
|
||||
QHash< QString, playlist_ptr > m_waitingForCreateReply;
|
||||
|
Loading…
x
Reference in New Issue
Block a user