mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 08:04:25 +02:00
* Track is now proxying a TrackData object (which is cached and only loaded once per track-id).
This commit is contained in:
@@ -19,14 +19,10 @@
|
|||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
|
|
||||||
#include <QtAlgorithms>
|
#include <QtAlgorithms>
|
||||||
|
#include <QReadWriteLock>
|
||||||
|
|
||||||
#include "database/Database.h"
|
#include "database/Database.h"
|
||||||
#include "database/DatabaseImpl.h"
|
#include "database/DatabaseImpl.h"
|
||||||
#include "database/DatabaseCommand_LogPlayback.h"
|
|
||||||
#include "database/DatabaseCommand_LoadPlaylistEntries.h"
|
|
||||||
#include "database/DatabaseCommand_LoadSocialActions.h"
|
|
||||||
#include "database/DatabaseCommand_SocialAction.h"
|
|
||||||
#include "database/DatabaseCommand_TrackStats.h"
|
|
||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
#include "collection/Collection.h"
|
#include "collection/Collection.h"
|
||||||
#include "Pipeline.h"
|
#include "Pipeline.h"
|
||||||
@@ -38,8 +34,10 @@
|
|||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
static QHash< QString, track_wptr > s_tracks;
|
QHash< QString, track_wptr > Track::s_tracksByName = QHash< QString, track_wptr >();
|
||||||
static QMutex s_mutex;
|
|
||||||
|
static QMutex s_nameCacheMutex;
|
||||||
|
|
||||||
|
|
||||||
inline QString
|
inline QString
|
||||||
cacheKey( const QString& artist, const QString& track, const QString& album, int duration, const QString& composer, unsigned int albumpos, unsigned int discnumber )
|
cacheKey( const QString& artist, const QString& track, const QString& album, int duration, const QString& composer, unsigned int albumpos, unsigned int discnumber )
|
||||||
@@ -60,35 +58,66 @@ Track::get( const QString& artist, const QString& track, const QString& album, i
|
|||||||
return track_ptr();
|
return track_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker lock( &s_mutex );
|
QMutexLocker lock( &s_nameCacheMutex );
|
||||||
const QString key = cacheKey( artist, track, album, duration, composer, albumpos, discnumber );
|
const QString key = cacheKey( artist, track, album, duration, composer, albumpos, discnumber );
|
||||||
if ( s_tracks.contains( key ) )
|
if ( s_tracksByName.contains( key ) )
|
||||||
{
|
{
|
||||||
return s_tracks.value( key );
|
track_wptr track = s_tracksByName.value( key );
|
||||||
|
if ( track )
|
||||||
|
return track.toStrongRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
track_ptr t = track_ptr( new Track( artist, track, album, duration, composer, albumpos, discnumber ), &Track::deleteLater );
|
track_ptr t = track_ptr( new Track( artist, track, album, duration, composer, albumpos, discnumber ), &Track::deleteLater );
|
||||||
t->setWeakRef( t.toWeakRef() );
|
t->setWeakRef( t.toWeakRef() );
|
||||||
s_tracks.insert( key, t );
|
s_tracksByName.insert( key, t );
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Track::Track( const QString& artist, const QString& track, const QString& album, int duration, const QString& composer, unsigned int albumpos, unsigned int discnumber )
|
track_ptr
|
||||||
: m_artist( artist )
|
Track::get( unsigned int id, const QString& artist, const QString& track, const QString& album, int duration, const QString& composer, unsigned int albumpos, unsigned int discnumber )
|
||||||
, m_composer( composer )
|
{
|
||||||
|
QMutexLocker lock( &s_nameCacheMutex );
|
||||||
|
const QString key = cacheKey( artist, track, album, duration, composer, albumpos, discnumber );
|
||||||
|
if ( s_tracksByName.contains( key ) )
|
||||||
|
{
|
||||||
|
track_wptr track = s_tracksByName.value( key );
|
||||||
|
if ( track )
|
||||||
|
return track;
|
||||||
|
}
|
||||||
|
|
||||||
|
track_ptr t = track_ptr( new Track( id, artist, track, album, duration, composer, albumpos, discnumber ), &Track::deleteLater );
|
||||||
|
t->setWeakRef( t.toWeakRef() );
|
||||||
|
s_tracksByName.insert( key, t );
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Track::Track( unsigned int id, const QString& artist, const QString& track, const QString& album, int duration, const QString& composer, unsigned int albumpos, unsigned int discnumber )
|
||||||
|
: m_composer( composer )
|
||||||
, m_album( album )
|
, m_album( album )
|
||||||
, m_track( track )
|
|
||||||
, m_duration( duration )
|
, m_duration( duration )
|
||||||
, m_albumpos( albumpos )
|
, m_albumpos( albumpos )
|
||||||
, m_discnumber( discnumber )
|
, m_discnumber( discnumber )
|
||||||
, m_socialActionsLoaded( false )
|
|
||||||
, m_simTracksLoaded( false )
|
|
||||||
, m_lyricsLoaded( false )
|
|
||||||
, m_infoJobs( 0 )
|
|
||||||
{
|
{
|
||||||
updateSortNames();
|
m_trackData = TrackData::get( id, artist, track );
|
||||||
|
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Track::Track( const QString& artist, const QString& track, const QString& album, int duration, const QString& composer, unsigned int albumpos, unsigned int discnumber )
|
||||||
|
: m_composer( composer )
|
||||||
|
, m_album( album )
|
||||||
|
, m_duration( duration )
|
||||||
|
, m_albumpos( albumpos )
|
||||||
|
, m_discnumber( discnumber )
|
||||||
|
{
|
||||||
|
m_trackData = TrackData::get( 0, artist, track );
|
||||||
|
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -98,28 +127,48 @@ Track::~Track()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Track::init()
|
||||||
|
{
|
||||||
|
updateSortNames();
|
||||||
|
|
||||||
|
connect( m_trackData.data(), SIGNAL( attributesLoaded() ), SIGNAL( attributesLoaded() ) );
|
||||||
|
connect( m_trackData.data(), SIGNAL( socialActionsLoaded() ), SIGNAL( socialActionsLoaded() ) );
|
||||||
|
connect( m_trackData.data(), SIGNAL( statsLoaded() ), SIGNAL( statsLoaded() ) );
|
||||||
|
connect( m_trackData.data(), SIGNAL( similarTracksLoaded() ), SIGNAL( similarTracksLoaded() ) );
|
||||||
|
connect( m_trackData.data(), SIGNAL( lyricsLoaded() ), SIGNAL( lyricsLoaded() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Track::deleteLater()
|
Track::deleteLater()
|
||||||
{
|
{
|
||||||
QMutexLocker lock( &s_mutex );
|
QMutexLocker lock( &s_nameCacheMutex );
|
||||||
|
|
||||||
const QString key = cacheKey( m_artist, m_track, m_album, m_duration, m_composer, m_albumpos, m_discnumber );
|
const QString key = cacheKey( artist(), track(), m_album, m_duration, m_composer, m_albumpos, m_discnumber );
|
||||||
if ( s_tracks.contains( key ) )
|
if ( s_tracksByName.contains( key ) )
|
||||||
{
|
{
|
||||||
s_tracks.remove( key );
|
s_tracksByName.remove( key );
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject::deleteLater();
|
QObject::deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
Track::trackId() const
|
||||||
|
{
|
||||||
|
return m_trackData->trackId();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Track::updateSortNames()
|
Track::updateSortNames()
|
||||||
{
|
{
|
||||||
m_artistSortname = DatabaseImpl::sortname( m_artist, true );
|
m_artistSortname = DatabaseImpl::sortname( artist(), true );
|
||||||
m_composerSortname = DatabaseImpl::sortname( m_composer, true );
|
m_composerSortname = DatabaseImpl::sortname( m_composer, true );
|
||||||
m_albumSortname = DatabaseImpl::sortname( m_album );
|
m_albumSortname = DatabaseImpl::sortname( m_album );
|
||||||
m_trackSortname = DatabaseImpl::sortname( m_track );
|
m_trackSortname = DatabaseImpl::sortname( track() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -183,138 +232,74 @@ Track::toQuery()
|
|||||||
void
|
void
|
||||||
Track::loadStats()
|
Track::loadStats()
|
||||||
{
|
{
|
||||||
DatabaseCommand_TrackStats* cmd = new DatabaseCommand_TrackStats( m_ownRef.toStrongRef() );
|
m_trackData->loadStats();
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QList< Tomahawk::PlaybackLog >
|
QList< Tomahawk::PlaybackLog >
|
||||||
Track::playbackHistory( const Tomahawk::source_ptr& source ) const
|
Track::playbackHistory( const Tomahawk::source_ptr& source ) const
|
||||||
{
|
{
|
||||||
QList< Tomahawk::PlaybackLog > history;
|
return m_trackData->playbackHistory( source );
|
||||||
|
|
||||||
foreach ( const PlaybackLog& log, m_playbackHistory )
|
|
||||||
{
|
|
||||||
if ( source.isNull() || log.source == source )
|
|
||||||
{
|
|
||||||
history << log;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return history;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Track::setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData )
|
|
||||||
{
|
|
||||||
m_playbackHistory = playbackData;
|
|
||||||
emit statsLoaded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
Track::playbackCount( const source_ptr& source )
|
Track::playbackCount( const source_ptr& source )
|
||||||
{
|
{
|
||||||
unsigned int count = 0;
|
return m_trackData->playbackCount( source );
|
||||||
foreach ( const PlaybackLog& log, m_playbackHistory )
|
}
|
||||||
{
|
|
||||||
if ( source.isNull() || log.source == source )
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
|
void
|
||||||
|
Track::loadAttributes()
|
||||||
|
{
|
||||||
|
m_trackData->loadAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Track::loadSocialActions()
|
Track::loadSocialActions()
|
||||||
{
|
{
|
||||||
if ( m_socialActionsLoaded )
|
m_trackData->loadSocialActions();
|
||||||
return;
|
|
||||||
|
|
||||||
m_socialActionsLoaded = true;
|
|
||||||
|
|
||||||
DatabaseCommand_LoadSocialActions* cmd = new DatabaseCommand_LoadSocialActions( m_ownRef.toStrongRef() );
|
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Track::setAllSocialActions( const QList< SocialAction >& socialActions )
|
|
||||||
{
|
|
||||||
m_allSocialActions = socialActions;
|
|
||||||
parseSocialActions();
|
|
||||||
|
|
||||||
emit socialActionsLoaded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QList< SocialAction >
|
QList< SocialAction >
|
||||||
Track::allSocialActions() const
|
Track::allSocialActions() const
|
||||||
{
|
{
|
||||||
return m_allSocialActions;
|
return m_trackData->allSocialActions();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Track::parseSocialActions()
|
|
||||||
{
|
|
||||||
QListIterator< Tomahawk::SocialAction > it( m_allSocialActions );
|
|
||||||
unsigned int highestTimestamp = 0;
|
|
||||||
|
|
||||||
while ( it.hasNext() )
|
|
||||||
{
|
|
||||||
Tomahawk::SocialAction socialAction;
|
|
||||||
socialAction = it.next();
|
|
||||||
if ( socialAction.timestamp.toUInt() > highestTimestamp && socialAction.source->isLocal() )
|
|
||||||
{
|
|
||||||
m_currentSocialActions[ socialAction.action.toString() ] = socialAction.value.toBool();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Track::loved()
|
Track::loved()
|
||||||
{
|
{
|
||||||
if ( m_socialActionsLoaded )
|
return m_trackData->loved();
|
||||||
{
|
|
||||||
return m_currentSocialActions[ "Love" ].toBool();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
loadSocialActions();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Track::setLoved( bool loved )
|
Track::setLoved( bool loved, bool postToInfoSystem )
|
||||||
{
|
{
|
||||||
m_currentSocialActions[ "Love" ] = loved;
|
m_trackData->setLoved( loved );
|
||||||
|
|
||||||
QVariantMap loveInfo;
|
if ( postToInfoSystem )
|
||||||
Tomahawk::InfoSystem::InfoStringHash trackInfo;
|
{
|
||||||
trackInfo["title"] = track();
|
QVariantMap loveInfo;
|
||||||
trackInfo["artist"] = artist();
|
Tomahawk::InfoSystem::InfoStringHash trackInfo;
|
||||||
trackInfo["album"] = album();
|
trackInfo["title"] = track();
|
||||||
|
trackInfo["artist"] = artist();
|
||||||
|
trackInfo["album"] = album();
|
||||||
|
|
||||||
loveInfo[ "trackinfo" ] = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
|
loveInfo[ "trackinfo" ] = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
|
||||||
|
|
||||||
Tomahawk::InfoSystem::InfoPushData pushData ( id(),
|
Tomahawk::InfoSystem::InfoPushData pushData ( m_trackData->id(),
|
||||||
( loved ? Tomahawk::InfoSystem::InfoLove : Tomahawk::InfoSystem::InfoUnLove ),
|
( loved ? Tomahawk::InfoSystem::InfoLove : Tomahawk::InfoSystem::InfoUnLove ),
|
||||||
loveInfo,
|
loveInfo,
|
||||||
Tomahawk::InfoSystem::PushShortUrlFlag );
|
Tomahawk::InfoSystem::PushShortUrlFlag );
|
||||||
|
|
||||||
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData );
|
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData );
|
||||||
|
}
|
||||||
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( m_ownRef.toStrongRef(), QString( "Love" ), loved ? QString( "true" ) : QString( "false" ) );
|
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
|
||||||
|
|
||||||
emit socialActionsLoaded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -466,136 +451,47 @@ Track::coverLoaded() const
|
|||||||
QList<Tomahawk::query_ptr>
|
QList<Tomahawk::query_ptr>
|
||||||
Track::similarTracks() const
|
Track::similarTracks() const
|
||||||
{
|
{
|
||||||
if ( !m_simTracksLoaded )
|
return m_trackData->similarTracks();
|
||||||
{
|
|
||||||
Tomahawk::InfoSystem::InfoStringHash trackInfo;
|
|
||||||
trackInfo["artist"] = artist();
|
|
||||||
trackInfo["track"] = track();
|
|
||||||
|
|
||||||
Tomahawk::InfoSystem::InfoRequestData requestData;
|
|
||||||
requestData.caller = id();
|
|
||||||
requestData.customData = QVariantMap();
|
|
||||||
|
|
||||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
|
|
||||||
requestData.type = Tomahawk::InfoSystem::InfoTrackSimilars;
|
|
||||||
requestData.requestId = TomahawkUtils::infosystemRequestId();
|
|
||||||
|
|
||||||
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
|
||||||
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
|
||||||
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
|
|
||||||
|
|
||||||
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
|
||||||
SIGNAL( finished( QString ) ),
|
|
||||||
SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection );
|
|
||||||
|
|
||||||
m_infoJobs++;
|
|
||||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_similarTracks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList
|
QStringList
|
||||||
Track::lyrics() const
|
Track::lyrics() const
|
||||||
{
|
{
|
||||||
if ( !m_lyricsLoaded )
|
return m_trackData->lyrics();
|
||||||
{
|
|
||||||
Tomahawk::InfoSystem::InfoStringHash trackInfo;
|
|
||||||
trackInfo["artist"] = artist();
|
|
||||||
trackInfo["track"] = track();
|
|
||||||
|
|
||||||
Tomahawk::InfoSystem::InfoRequestData requestData;
|
|
||||||
requestData.caller = id();
|
|
||||||
requestData.customData = QVariantMap();
|
|
||||||
|
|
||||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
|
|
||||||
requestData.type = Tomahawk::InfoSystem::InfoTrackLyrics;
|
|
||||||
requestData.requestId = TomahawkUtils::infosystemRequestId();
|
|
||||||
|
|
||||||
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
|
||||||
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
|
||||||
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
|
|
||||||
|
|
||||||
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
|
||||||
SIGNAL( finished( QString ) ),
|
|
||||||
SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection );
|
|
||||||
|
|
||||||
m_infoJobs++;
|
|
||||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_lyrics;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Track::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
|
||||||
{
|
|
||||||
if ( requestData.caller != id() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
QVariantMap returnedData = output.value< QVariantMap >();
|
|
||||||
switch ( requestData.type )
|
|
||||||
{
|
|
||||||
case InfoSystem::InfoTrackLyrics:
|
|
||||||
{
|
|
||||||
m_lyrics = output.value< QVariant >().toString().split( "\n" );
|
|
||||||
|
|
||||||
m_lyricsLoaded = true;
|
|
||||||
emit lyricsLoaded();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case InfoSystem::InfoTrackSimilars:
|
|
||||||
{
|
|
||||||
const QStringList artists = returnedData["artists"].toStringList();
|
|
||||||
const QStringList tracks = returnedData["tracks"].toStringList();
|
|
||||||
|
|
||||||
for ( int i = 0; i < tracks.count() && i < 50; i++ )
|
|
||||||
{
|
|
||||||
m_similarTracks << Query::get( artists.at( i ), tracks.at( i ), QString(), uuid(), false );
|
|
||||||
}
|
|
||||||
Pipeline::instance()->resolve( m_similarTracks );
|
|
||||||
|
|
||||||
m_simTracksLoaded = true;
|
|
||||||
emit similarTracksLoaded();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
Q_ASSERT( false );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Track::infoSystemFinished( QString target )
|
|
||||||
{
|
|
||||||
if ( target != id() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( --m_infoJobs == 0 )
|
|
||||||
{
|
|
||||||
disconnect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
|
||||||
this, SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
|
|
||||||
|
|
||||||
disconnect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ),
|
|
||||||
this, SLOT( infoSystemFinished( QString ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
emit updated();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
Track::id() const
|
Track::artist() const
|
||||||
{
|
{
|
||||||
if ( m_uuid.isEmpty() )
|
return m_trackData->artist();
|
||||||
{
|
}
|
||||||
m_uuid = uuid();
|
|
||||||
}
|
|
||||||
|
QString
|
||||||
return m_uuid;
|
Track::track() const
|
||||||
|
{
|
||||||
|
return m_trackData->track();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantMap
|
||||||
|
Track::attributes() const
|
||||||
|
{
|
||||||
|
return m_trackData->attributes();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
Track::year() const
|
||||||
|
{
|
||||||
|
return m_trackData->year();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Track::share( const Tomahawk::source_ptr& source )
|
||||||
|
{
|
||||||
|
m_trackData->share( source );
|
||||||
}
|
}
|
||||||
|
@@ -24,39 +24,18 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
#include "TrackData.h"
|
||||||
#include "infosystem/InfoSystem.h"
|
#include "infosystem/InfoSystem.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
class DatabaseCommand_LogPlayback;
|
|
||||||
class DatabaseCommand_PlaybackHistory;
|
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
struct SocialAction
|
|
||||||
{
|
|
||||||
QVariant action;
|
|
||||||
QVariant value;
|
|
||||||
QVariant timestamp;
|
|
||||||
Tomahawk::source_ptr source;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PlaybackLog
|
|
||||||
{
|
|
||||||
Tomahawk::source_ptr source;
|
|
||||||
unsigned int timestamp;
|
|
||||||
unsigned int secsPlayed;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TrackPrivate;
|
|
||||||
|
|
||||||
class DLLEXPORT Track : public QObject
|
class DLLEXPORT Track : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class ::DatabaseCommand_LogPlayback;
|
|
||||||
friend class ::DatabaseCommand_PlaybackHistory;
|
|
||||||
friend class Pipeline;
|
friend class Pipeline;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -64,14 +43,13 @@ public:
|
|||||||
{ Detailed = 0, Short = 1 };
|
{ Detailed = 0, Short = 1 };
|
||||||
|
|
||||||
static track_ptr get( const QString& artist, const QString& track, const QString& album = QString(), int duration = 0, const QString& composer = QString(), unsigned int albumpos = 0, unsigned int discnumber = 0 );
|
static track_ptr get( const QString& artist, const QString& track, const QString& album = QString(), int duration = 0, const QString& composer = QString(), unsigned int albumpos = 0, unsigned int discnumber = 0 );
|
||||||
|
static track_ptr get( unsigned int id, const QString& artist, const QString& track, const QString& album, int duration, const QString& composer, unsigned int albumpos, unsigned int discnumber );
|
||||||
|
|
||||||
virtual ~Track();
|
virtual ~Track();
|
||||||
|
|
||||||
QString id() const;
|
// void setArtist( const QString& artist ) { m_artist = artist; updateSortNames(); }
|
||||||
|
|
||||||
void setArtist( const QString& artist ) { m_artist = artist; updateSortNames(); }
|
|
||||||
void setAlbum( const QString& album ) { m_album = album; updateSortNames(); }
|
void setAlbum( const QString& album ) { m_album = album; updateSortNames(); }
|
||||||
void setTrack( const QString& track ) { m_track = track; updateSortNames(); }
|
// void setTrack( const QString& track ) { m_track = track; updateSortNames(); }
|
||||||
/* void setDuration( int duration ) { m_duration = duration; }
|
/* void setDuration( int duration ) { m_duration = duration; }
|
||||||
void setAlbumPos( unsigned int albumpos ) { m_albumpos = albumpos; }
|
void setAlbumPos( unsigned int albumpos ) { m_albumpos = albumpos; }
|
||||||
void setDiscNumber( unsigned int discnumber ) { m_discnumber = discnumber; }
|
void setDiscNumber( unsigned int discnumber ) { m_discnumber = discnumber; }
|
||||||
@@ -88,11 +66,12 @@ public:
|
|||||||
QString albumSortname() const { return m_albumSortname; }
|
QString albumSortname() const { return m_albumSortname; }
|
||||||
QString trackSortname() const { return m_trackSortname; }
|
QString trackSortname() const { return m_trackSortname; }
|
||||||
|
|
||||||
QString artist() const { return m_artist; }
|
QString artist() const;
|
||||||
|
QString track() const;
|
||||||
QString composer() const { return m_composer; }
|
QString composer() const { return m_composer; }
|
||||||
QString album() const { return m_album; }
|
QString album() const { return m_album; }
|
||||||
QString track() const { return m_track; }
|
|
||||||
int duration() const { return m_duration; }
|
int duration() const { return m_duration; }
|
||||||
|
int year() const;
|
||||||
unsigned int albumpos() const { return m_albumpos; }
|
unsigned int albumpos() const { return m_albumpos; }
|
||||||
unsigned int discnumber() const { return m_discnumber; }
|
unsigned int discnumber() const { return m_discnumber; }
|
||||||
|
|
||||||
@@ -105,28 +84,34 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
bool coverLoaded() const;
|
bool coverLoaded() const;
|
||||||
|
|
||||||
void setLoved( bool loved );
|
void setLoved( bool loved, bool postToInfoSystem = true );
|
||||||
bool loved();
|
bool loved();
|
||||||
|
|
||||||
|
void share( const Tomahawk::source_ptr& source );
|
||||||
|
|
||||||
|
void loadAttributes();
|
||||||
|
QVariantMap attributes() const;
|
||||||
|
|
||||||
void loadStats();
|
void loadStats();
|
||||||
QList< Tomahawk::PlaybackLog > playbackHistory( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() ) const;
|
QList< Tomahawk::PlaybackLog > playbackHistory( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() ) const;
|
||||||
void setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData );
|
|
||||||
unsigned int playbackCount( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() );
|
unsigned int playbackCount( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() );
|
||||||
|
|
||||||
void loadSocialActions();
|
void loadSocialActions();
|
||||||
QList< Tomahawk::SocialAction > allSocialActions() const;
|
QList< Tomahawk::SocialAction > allSocialActions() const;
|
||||||
void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions );
|
|
||||||
QString socialActionDescription( const QString& action, DescriptionMode mode ) const;
|
QString socialActionDescription( const QString& action, DescriptionMode mode ) const;
|
||||||
|
|
||||||
QList<Tomahawk::query_ptr> similarTracks() const;
|
QList<Tomahawk::query_ptr> similarTracks() const;
|
||||||
QStringList lyrics() const;
|
QStringList lyrics() const;
|
||||||
|
|
||||||
|
unsigned int trackId() const;
|
||||||
|
|
||||||
QWeakPointer< Tomahawk::Track > weakRef() { return m_ownRef; }
|
QWeakPointer< Tomahawk::Track > weakRef() { return m_ownRef; }
|
||||||
void setWeakRef( QWeakPointer< Tomahawk::Track > weakRef ) { m_ownRef = weakRef; }
|
void setWeakRef( QWeakPointer< Tomahawk::Track > weakRef ) { m_ownRef = weakRef; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void coverChanged();
|
void coverChanged();
|
||||||
void socialActionsLoaded();
|
void socialActionsLoaded();
|
||||||
|
void attributesLoaded();
|
||||||
void statsLoaded();
|
void statsLoaded();
|
||||||
void similarTracksLoaded();
|
void similarTracksLoaded();
|
||||||
void lyricsLoaded();
|
void lyricsLoaded();
|
||||||
@@ -136,25 +121,21 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void deleteLater();
|
void deleteLater();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
|
||||||
void infoSystemFinished( QString target );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit Track( unsigned int id, const QString& artist, const QString& track, const QString& album, int duration, const QString& composer, unsigned int albumpos, unsigned int discnumber );
|
||||||
explicit Track( const QString& artist, const QString& track, const QString& album, int duration, const QString& composer, unsigned int albumpos, unsigned int discnumber );
|
explicit Track( const QString& artist, const QString& track, const QString& album, int duration, const QString& composer, unsigned int albumpos, unsigned int discnumber );
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
void updateSortNames();
|
void updateSortNames();
|
||||||
void parseSocialActions();
|
|
||||||
|
|
||||||
QString m_artistSortname;
|
QString m_artistSortname;
|
||||||
QString m_composerSortname;
|
QString m_composerSortname;
|
||||||
QString m_albumSortname;
|
QString m_albumSortname;
|
||||||
QString m_trackSortname;
|
QString m_trackSortname;
|
||||||
|
|
||||||
QString m_artist;
|
|
||||||
QString m_composer;
|
QString m_composer;
|
||||||
QString m_album;
|
QString m_album;
|
||||||
QString m_track;
|
|
||||||
|
|
||||||
int m_duration;
|
int m_duration;
|
||||||
unsigned int m_albumpos;
|
unsigned int m_albumpos;
|
||||||
@@ -164,29 +145,16 @@ private:
|
|||||||
mutable Tomahawk::album_ptr m_albumPtr;
|
mutable Tomahawk::album_ptr m_albumPtr;
|
||||||
mutable Tomahawk::artist_ptr m_composerPtr;
|
mutable Tomahawk::artist_ptr m_composerPtr;
|
||||||
|
|
||||||
bool m_playbackHistoryLoaded;
|
mutable trackdata_ptr m_trackData;
|
||||||
QList< PlaybackLog > m_playbackHistory;
|
|
||||||
|
|
||||||
bool m_socialActionsLoaded;
|
|
||||||
QHash< QString, QVariant > m_currentSocialActions;
|
|
||||||
QList< SocialAction > m_allSocialActions;
|
|
||||||
|
|
||||||
bool m_simTracksLoaded;
|
|
||||||
QList<Tomahawk::query_ptr> m_similarTracks;
|
|
||||||
|
|
||||||
bool m_lyricsLoaded;
|
|
||||||
QStringList m_lyrics;
|
|
||||||
|
|
||||||
mutable int m_infoJobs;
|
|
||||||
mutable QString m_uuid;
|
|
||||||
|
|
||||||
query_wptr m_query;
|
query_wptr m_query;
|
||||||
QWeakPointer< Tomahawk::Track > m_ownRef;
|
QWeakPointer< Tomahawk::Track > m_ownRef;
|
||||||
|
|
||||||
|
static QHash< QString, track_wptr > s_tracksByName;
|
||||||
};
|
};
|
||||||
|
|
||||||
}; //ns
|
}; //ns
|
||||||
|
|
||||||
Q_DECLARE_METATYPE( QList<Tomahawk::PlaybackLog> );
|
|
||||||
Q_DECLARE_METATYPE( Tomahawk::track_ptr );
|
Q_DECLARE_METATYPE( Tomahawk::track_ptr );
|
||||||
|
|
||||||
#endif // TRACK_H
|
#endif // TRACK_H
|
||||||
|
Reference in New Issue
Block a user