1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-16 14:01:58 +02:00

* Added Track and TrackData::sourcesWithSocialAction( action, value ).

This commit is contained in:
Christian Muehlhaeuser 2013-09-08 01:20:07 +02:00
parent aee9754e95
commit b30a75ba85
4 changed files with 41 additions and 32 deletions

View File

@ -445,10 +445,11 @@ Track::loadAttributes()
void
Track::loadSocialActions()
Track::loadSocialActions( bool force )
{
Q_D( Track );
d->trackData->loadSocialActions();
d->trackData->loadSocialActions( force );
}
@ -569,26 +570,11 @@ Track::socialActionDescription( const QString& action, DescriptionMode mode ) co
}
QList< QPixmap >
Track::socialActionPixmaps( const QString& action, unsigned int height ) const
QList< Tomahawk::source_ptr >
Track::sourcesWithSocialAction( const QString& action, const QVariant& value )
{
QList< QPixmap > pixmaps;
QList< Tomahawk::SocialAction > socialActions = allSocialActions();
QStringList actionSources;
foreach ( const Tomahawk::SocialAction& sa, socialActions )
{
if ( sa.action == action )
{
if ( actionSources.contains( sa.source->friendlyName() ) )
continue;
actionSources << sa.source->friendlyName();
pixmaps << sa.source->avatar( TomahawkUtils::Original, QSize( height, height ) );
}
}
return pixmaps;
Q_D( Track );
return d->trackData->sourcesWithSocialAction( action, value );
}

View File

@ -107,10 +107,10 @@ public:
unsigned int chartPosition() const;
unsigned int chartCount() const;
void loadSocialActions();
void loadSocialActions( bool force = false );
QList< Tomahawk::SocialAction > allSocialActions() const;
QList< Tomahawk::source_ptr > sourcesWithSocialAction( const QString& action, const QVariant& value = QVariant() );
QString socialActionDescription( const QString& action, DescriptionMode mode ) const;
QList< QPixmap > socialActionPixmaps( const QString& action, unsigned int height ) const;
QList<Tomahawk::query_ptr> similarTracks() const;
QStringList lyrics() const;

View File

@ -244,15 +244,15 @@ TrackData::updateAttributes()
void
TrackData::loadSocialActions()
TrackData::loadSocialActions( bool force )
{
if ( m_socialActionsLoaded )
if ( !force && m_socialActionsLoaded )
return;
m_socialActionsLoaded = true;
DatabaseCommand_LoadSocialActions* cmd = new DatabaseCommand_LoadSocialActions( m_ownRef.toStrongRef() );
Database::instance()->enqueue( Tomahawk::dbcmd_ptr(cmd) );
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
}
@ -277,6 +277,32 @@ TrackData::allSocialActions() const
}
QList< Tomahawk::source_ptr >
TrackData::sourcesWithSocialAction( const QString& action, const QVariant& value )
{
QMutexLocker locker( &s_memberMutex );
QList< Tomahawk::source_ptr > sources;
foreach ( const Tomahawk::SocialAction& sa, m_allSocialActions )
{
if ( sa.action == action )
{
if ( !value.isNull() && sa.value != value )
{
sources.removeAll( sa.source );
continue;
}
if ( sources.contains( sa.source ) )
continue;
sources << sa.source;
}
}
return sources;
}
void
TrackData::parseSocialActions()
{
@ -316,12 +342,8 @@ TrackData::loved()
void
TrackData::setLoved( bool loved )
{
m_currentSocialActions[ "Love" ] = loved;
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( m_ownRef.toStrongRef(), QString( "Love" ), loved ? QString( "true" ) : QString( "false" ) );
Database::instance()->enqueue( Tomahawk::dbcmd_ptr(cmd) );
emit socialActionsLoaded();
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
}

View File

@ -78,8 +78,9 @@ public:
QVariantMap attributes() const { return m_attributes; }
void setAttributes( const QVariantMap& map ) { m_attributes = map; updateAttributes(); }
void loadSocialActions();
void loadSocialActions( bool force = false );
QList< Tomahawk::SocialAction > allSocialActions() const;
QList< Tomahawk::source_ptr > sourcesWithSocialAction( const QString& action, const QVariant& value = QVariant() );
void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions );
void loadStats();