1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 13:47:26 +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 void
Track::loadSocialActions() Track::loadSocialActions( bool force )
{ {
Q_D( Track ); Q_D( Track );
d->trackData->loadSocialActions();
d->trackData->loadSocialActions( force );
} }
@@ -569,26 +570,11 @@ Track::socialActionDescription( const QString& action, DescriptionMode mode ) co
} }
QList< QPixmap > QList< Tomahawk::source_ptr >
Track::socialActionPixmaps( const QString& action, unsigned int height ) const Track::sourcesWithSocialAction( const QString& action, const QVariant& value )
{ {
QList< QPixmap > pixmaps; Q_D( Track );
QList< Tomahawk::SocialAction > socialActions = allSocialActions(); return d->trackData->sourcesWithSocialAction( action, value );
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;
} }

View File

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

View File

@@ -244,9 +244,9 @@ TrackData::updateAttributes()
void void
TrackData::loadSocialActions() TrackData::loadSocialActions( bool force )
{ {
if ( m_socialActionsLoaded ) if ( !force && m_socialActionsLoaded )
return; return;
m_socialActionsLoaded = true; m_socialActionsLoaded = true;
@@ -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 void
TrackData::parseSocialActions() TrackData::parseSocialActions()
{ {
@@ -316,12 +342,8 @@ TrackData::loved()
void void
TrackData::setLoved( bool loved ) TrackData::setLoved( bool loved )
{ {
m_currentSocialActions[ "Love" ] = loved;
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( m_ownRef.toStrongRef(), QString( "Love" ), loved ? QString( "true" ) : QString( "false" ) ); DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( m_ownRef.toStrongRef(), QString( "Love" ), loved ? QString( "true" ) : QString( "false" ) );
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) ); Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
emit socialActionsLoaded();
} }

View File

@@ -78,8 +78,9 @@ public:
QVariantMap attributes() const { return m_attributes; } QVariantMap attributes() const { return m_attributes; }
void setAttributes( const QVariantMap& map ) { m_attributes = map; updateAttributes(); } void setAttributes( const QVariantMap& map ) { m_attributes = map; updateAttributes(); }
void loadSocialActions(); void loadSocialActions( bool force = false );
QList< Tomahawk::SocialAction > allSocialActions() const; 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 setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions );
void loadStats(); void loadStats();