mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 15:59:42 +01:00
* Query class uses and exposes Track objects.
This commit is contained in:
parent
2213613cff
commit
4f6a532f99
@ -40,45 +40,6 @@
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
SocialAction::SocialAction() {}
|
||||
SocialAction::~SocialAction() {}
|
||||
|
||||
SocialAction& SocialAction::operator=( const SocialAction& other )
|
||||
{
|
||||
action = other.action;
|
||||
value = other.value;
|
||||
timestamp = other.timestamp;
|
||||
source = other.source;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
SocialAction::SocialAction( const SocialAction& other )
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
|
||||
PlaybackLog::PlaybackLog() {}
|
||||
PlaybackLog::~PlaybackLog() {}
|
||||
|
||||
PlaybackLog& PlaybackLog::operator=( const PlaybackLog& other )
|
||||
{
|
||||
source = other.source;
|
||||
timestamp = other.timestamp;
|
||||
secsPlayed = other.secsPlayed;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PlaybackLog::PlaybackLog( const PlaybackLog& other )
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
|
||||
query_ptr
|
||||
Query::get( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve )
|
||||
{
|
||||
@ -88,7 +49,7 @@ Query::get( const QString& artist, const QString& track, const QString& album, c
|
||||
if ( qid.isEmpty() )
|
||||
autoResolve = false;
|
||||
|
||||
query_ptr q = query_ptr( new Query( artist, track, album, qid, autoResolve ), &QObject::deleteLater );
|
||||
query_ptr q = query_ptr( new Query( Track::get( artist, track, album ), qid, autoResolve ), &QObject::deleteLater );
|
||||
q->setWeakRef( q.toWeakRef() );
|
||||
|
||||
if ( autoResolve )
|
||||
@ -98,6 +59,16 @@ Query::get( const QString& artist, const QString& track, const QString& album, c
|
||||
}
|
||||
|
||||
|
||||
query_ptr
|
||||
Query::get( const Tomahawk::track_ptr& track, const QID& qid )
|
||||
{
|
||||
query_ptr q = query_ptr( new Query( track, qid, false ), &QObject::deleteLater );
|
||||
q->setWeakRef( q.toWeakRef() );
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
query_ptr
|
||||
Query::get( const QString& query, const QID& qid )
|
||||
{
|
||||
@ -113,15 +84,9 @@ Query::get( const QString& query, const QID& qid )
|
||||
}
|
||||
|
||||
|
||||
Query::Query( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve )
|
||||
Query::Query( const track_ptr& track, const QID& qid, bool autoResolve )
|
||||
: m_qid( qid )
|
||||
, m_artist( artist )
|
||||
, m_album( album )
|
||||
, m_track( track )
|
||||
, m_socialActionsLoaded( false )
|
||||
, m_simTracksLoaded( false )
|
||||
, m_lyricsLoaded( false )
|
||||
, m_infoJobs( 0 )
|
||||
, m_queryTrack( track )
|
||||
{
|
||||
init();
|
||||
|
||||
@ -149,6 +114,8 @@ Query::Query( const QString& query, const QID& qid )
|
||||
|
||||
Query::~Query()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << toString();
|
||||
|
||||
QMutexLocker lock( &m_mutex );
|
||||
m_ownRef.clear();
|
||||
m_results.clear();
|
||||
@ -161,42 +128,24 @@ Query::init()
|
||||
m_resolveFinished = false;
|
||||
m_solved = false;
|
||||
m_playable = false;
|
||||
m_duration = -1;
|
||||
m_albumpos = 0;
|
||||
m_discnumber = 0;
|
||||
m_saveResultHint = false;
|
||||
|
||||
updateSortNames();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Query::updateSortNames()
|
||||
track_ptr
|
||||
Query::queryTrack() const
|
||||
{
|
||||
if ( isFullTextQuery() )
|
||||
{
|
||||
m_artistSortname = DatabaseImpl::sortname( m_fullTextQuery, true );
|
||||
m_composerSortname = DatabaseImpl::sortname( m_composer, true );
|
||||
m_albumSortname = DatabaseImpl::sortname( m_fullTextQuery );
|
||||
m_trackSortname = m_albumSortname;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_artistSortname = DatabaseImpl::sortname( m_artist, true );
|
||||
m_composerSortname = DatabaseImpl::sortname( m_composer, true );
|
||||
m_albumSortname = DatabaseImpl::sortname( m_album );
|
||||
m_trackSortname = DatabaseImpl::sortname( m_track );
|
||||
}
|
||||
return m_queryTrack;
|
||||
}
|
||||
|
||||
|
||||
query_ptr
|
||||
Query::displayQuery() const
|
||||
track_ptr
|
||||
Query::track() const
|
||||
{
|
||||
if ( !results().isEmpty() )
|
||||
return results().first()->toQuery();
|
||||
return results().first()->track();
|
||||
|
||||
return m_ownRef.toStrongRef();
|
||||
return m_queryTrack;
|
||||
}
|
||||
|
||||
|
||||
@ -350,14 +299,6 @@ Query::id() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Query::setPlayedBy( const Tomahawk::source_ptr& source, unsigned int playtime )
|
||||
{
|
||||
m_playedBy.first = source;
|
||||
m_playedBy.second = playtime;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Query::resultSorter( const result_ptr& left, const result_ptr& right )
|
||||
{
|
||||
@ -403,7 +344,7 @@ Query::currentResolver() const
|
||||
void
|
||||
Query::clearResults()
|
||||
{
|
||||
foreach( const result_ptr& rp, m_results )
|
||||
foreach( const result_ptr& rp, results() )
|
||||
{
|
||||
removeResult( rp );
|
||||
}
|
||||
@ -422,14 +363,8 @@ Query::checkResults()
|
||||
// hook up signals, and check solved status
|
||||
foreach( const result_ptr& rp, m_results )
|
||||
{
|
||||
if ( rp->score() > 0.0 && rp->collection().isNull() )
|
||||
{
|
||||
if ( rp->playable() )
|
||||
playable = true;
|
||||
}
|
||||
else if ( !rp->collection().isNull() && rp->collection()->source()->isOnline() )
|
||||
{
|
||||
playable = true;
|
||||
}
|
||||
|
||||
if ( rp->score() > 0.99 )
|
||||
{
|
||||
@ -445,7 +380,6 @@ Query::checkResults()
|
||||
{
|
||||
refreshResults();
|
||||
}
|
||||
|
||||
if ( m_playable != playable )
|
||||
{
|
||||
m_playable = playable;
|
||||
@ -466,13 +400,13 @@ Query::equals( const Tomahawk::query_ptr& other, bool ignoreCase ) const
|
||||
return false;
|
||||
|
||||
if ( ignoreCase )
|
||||
return ( artist().toLower() == other->artist().toLower() &&
|
||||
album().toLower() == other->album().toLower() &&
|
||||
track().toLower() == other->track().toLower() );
|
||||
return ( queryTrack()->artist().toLower() == other->queryTrack()->artist().toLower() &&
|
||||
queryTrack()->album().toLower() == other->queryTrack()->album().toLower() &&
|
||||
queryTrack()->track().toLower() == other->queryTrack()->track().toLower() );
|
||||
else
|
||||
return ( artist() == other->artist() &&
|
||||
album() == other->album() &&
|
||||
track() == other->track() );
|
||||
return ( queryTrack()->artist() == other->queryTrack()->artist() &&
|
||||
queryTrack()->album() == other->queryTrack()->album() &&
|
||||
queryTrack()->track() == other->queryTrack()->track() );
|
||||
}
|
||||
|
||||
|
||||
@ -480,10 +414,10 @@ QVariant
|
||||
Query::toVariant() const
|
||||
{
|
||||
QVariantMap m;
|
||||
m.insert( "artist", artist() );
|
||||
m.insert( "album", album() );
|
||||
m.insert( "track", track() );
|
||||
m.insert( "duration", duration() );
|
||||
m.insert( "artist", queryTrack()->artist() );
|
||||
m.insert( "album", queryTrack()->album() );
|
||||
m.insert( "track", queryTrack()->track() );
|
||||
m.insert( "duration", queryTrack()->duration() );
|
||||
m.insert( "qid", id() );
|
||||
|
||||
return m;
|
||||
@ -497,9 +431,9 @@ Query::toString() const
|
||||
{
|
||||
return QString( "Query(%1, %2 - %3%4)" )
|
||||
.arg( id() )
|
||||
.arg( artist() )
|
||||
.arg( track() )
|
||||
.arg( album().isEmpty() ? "" : QString( " on %1" ).arg( album() ) );
|
||||
.arg( queryTrack()->artist() )
|
||||
.arg( queryTrack()->track() )
|
||||
.arg( queryTrack()->album().isEmpty() ? "" : QString( " on %1" ).arg( queryTrack()->album() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -514,25 +448,37 @@ Query::toString() const
|
||||
float
|
||||
Query::howSimilar( const Tomahawk::result_ptr& r )
|
||||
{
|
||||
Q_ASSERT( !r->artist().isNull() );
|
||||
Q_ASSERT( !r->album().isNull() );
|
||||
if ( r->artist().isNull() || r->album().isNull() )
|
||||
return 0.0;
|
||||
|
||||
// result values
|
||||
const QString rArtistname = r->artist()->sortname();
|
||||
const QString rAlbumname = r->album()->sortname();
|
||||
const QString rTrackname = DatabaseImpl::sortname( r->track() );
|
||||
const QString rArtistname = r->track()->artistSortname();
|
||||
const QString rAlbumname = r->track()->albumSortname();
|
||||
const QString rTrackname = r->track()->trackSortname();
|
||||
|
||||
QString qArtistname;
|
||||
QString qAlbumname;
|
||||
QString qTrackname;
|
||||
|
||||
if ( isFullTextQuery() )
|
||||
{
|
||||
qArtistname = DatabaseImpl::sortname( m_fullTextQuery, true );
|
||||
qAlbumname = DatabaseImpl::sortname( m_fullTextQuery );
|
||||
qTrackname = qAlbumname;
|
||||
}
|
||||
else
|
||||
{
|
||||
qArtistname = queryTrack()->artistSortname();
|
||||
qAlbumname = queryTrack()->albumSortname();
|
||||
qTrackname = queryTrack()->trackSortname();
|
||||
}
|
||||
|
||||
// normal edit distance
|
||||
int artdist = TomahawkUtils::levenshtein( m_artistSortname, rArtistname );
|
||||
int albdist = TomahawkUtils::levenshtein( m_albumSortname, rAlbumname );
|
||||
int trkdist = TomahawkUtils::levenshtein( m_trackSortname, rTrackname );
|
||||
int artdist = TomahawkUtils::levenshtein( qArtistname, rArtistname );
|
||||
int albdist = TomahawkUtils::levenshtein( qAlbumname, rAlbumname );
|
||||
int trkdist = TomahawkUtils::levenshtein( qTrackname, rTrackname );
|
||||
|
||||
// max length of name
|
||||
int mlart = qMax( m_artistSortname.length(), rArtistname.length() );
|
||||
int mlalb = qMax( m_albumSortname.length(), rAlbumname.length() );
|
||||
int mltrk = qMax( m_trackSortname.length(), rTrackname.length() );
|
||||
int mlart = qMax( qArtistname.length(), rArtistname.length() );
|
||||
int mlalb = qMax( qAlbumname.length(), rAlbumname.length() );
|
||||
int mltrk = qMax( qTrackname.length(), rTrackname.length() );
|
||||
|
||||
// distance scores
|
||||
float dcart = (float)( mlart - artdist ) / mlart;
|
||||
@ -542,7 +488,7 @@ Query::howSimilar( const Tomahawk::result_ptr& r )
|
||||
if ( isFullTextQuery() )
|
||||
{
|
||||
const QString artistTrackname = DatabaseImpl::sortname( fullTextQuery() );
|
||||
const QString rArtistTrackname = DatabaseImpl::sortname( r->artist()->name() + " " + r->track() );
|
||||
const QString rArtistTrackname = DatabaseImpl::sortname( r->track()->artist() + " " + r->track()->track() );
|
||||
|
||||
int atrdist = TomahawkUtils::levenshtein( artistTrackname, rArtistTrackname );
|
||||
int mlatr = qMax( artistTrackname.length(), rArtistTrackname.length() );
|
||||
@ -555,7 +501,7 @@ Query::howSimilar( const Tomahawk::result_ptr& r )
|
||||
else
|
||||
{
|
||||
// don't penalize for missing album name
|
||||
if ( m_albumSortname.isEmpty() )
|
||||
if ( queryTrack()->albumSortname().isEmpty() )
|
||||
dcalb = 1.0;
|
||||
|
||||
// weighted, so album match is worth less than track title
|
||||
@ -565,403 +511,8 @@ Query::howSimilar( const Tomahawk::result_ptr& r )
|
||||
}
|
||||
|
||||
|
||||
QPair< Tomahawk::source_ptr, unsigned int >
|
||||
Query::playedBy() const
|
||||
{
|
||||
return m_playedBy;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Query::loadStats()
|
||||
{
|
||||
query_ptr q = m_ownRef.toStrongRef();
|
||||
|
||||
DatabaseCommand_TrackStats* cmd = new DatabaseCommand_TrackStats( q );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||
}
|
||||
|
||||
|
||||
QList< Tomahawk::PlaybackLog >
|
||||
Query::playbackHistory( const Tomahawk::source_ptr& source ) const
|
||||
{
|
||||
QList< Tomahawk::PlaybackLog > history;
|
||||
|
||||
foreach ( const PlaybackLog& log, m_playbackHistory )
|
||||
{
|
||||
if ( source.isNull() || log.source == source )
|
||||
{
|
||||
history << log;
|
||||
}
|
||||
}
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Query::setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData )
|
||||
{
|
||||
m_playbackHistory = playbackData;
|
||||
emit statsLoaded();
|
||||
}
|
||||
|
||||
|
||||
unsigned int
|
||||
Query::playbackCount( const source_ptr& source )
|
||||
{
|
||||
unsigned int count = 0;
|
||||
foreach ( const PlaybackLog& log, m_playbackHistory )
|
||||
{
|
||||
if ( source.isNull() || log.source == source )
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Query::loadSocialActions()
|
||||
{
|
||||
if ( m_socialActionsLoaded )
|
||||
return;
|
||||
|
||||
m_socialActionsLoaded = true;
|
||||
query_ptr q = m_ownRef.toStrongRef();
|
||||
|
||||
DatabaseCommand_LoadSocialActions* cmd = new DatabaseCommand_LoadSocialActions( q );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Query::setAllSocialActions( const QList< SocialAction >& socialActions )
|
||||
{
|
||||
m_allSocialActions = socialActions;
|
||||
parseSocialActions();
|
||||
|
||||
emit socialActionsLoaded();
|
||||
}
|
||||
|
||||
|
||||
QList< SocialAction >
|
||||
Query::allSocialActions() const
|
||||
{
|
||||
return m_allSocialActions;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Query::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
|
||||
Query::loved()
|
||||
{
|
||||
if ( m_socialActionsLoaded )
|
||||
{
|
||||
return m_currentSocialActions[ "Love" ].toBool();
|
||||
}
|
||||
else
|
||||
{
|
||||
loadSocialActions();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Query::setLoved( bool loved )
|
||||
{
|
||||
query_ptr q = m_ownRef.toStrongRef();
|
||||
if ( q )
|
||||
{
|
||||
m_currentSocialActions[ "Love" ] = loved;
|
||||
|
||||
QVariantMap loveInfo;
|
||||
Tomahawk::InfoSystem::InfoStringHash trackInfo;
|
||||
trackInfo["title"] = track();
|
||||
trackInfo["artist"] = artist();
|
||||
trackInfo["album"] = album();
|
||||
|
||||
loveInfo[ "trackinfo" ] = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
|
||||
|
||||
Tomahawk::InfoSystem::InfoPushData pushData ( id(),
|
||||
( loved ? Tomahawk::InfoSystem::InfoLove : Tomahawk::InfoSystem::InfoUnLove ),
|
||||
loveInfo,
|
||||
Tomahawk::InfoSystem::PushShortUrlFlag );
|
||||
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData );
|
||||
|
||||
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( q, QString( "Love" ), loved ? QString( "true" ) : QString( "false" ) );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||
|
||||
emit socialActionsLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
Query::socialActionDescription( const QString& action, DescriptionMode mode ) const
|
||||
{
|
||||
QString desc;
|
||||
QList< Tomahawk::SocialAction > socialActions = allSocialActions();
|
||||
|
||||
QStringList actionSources;
|
||||
int loveTotal = 0;
|
||||
foreach ( const Tomahawk::SocialAction& sa, socialActions )
|
||||
{
|
||||
if ( sa.action == action )
|
||||
{
|
||||
if ( actionSources.contains( sa.source->friendlyName() ) )
|
||||
continue;
|
||||
actionSources << sa.source->friendlyName();
|
||||
loveTotal++;
|
||||
}
|
||||
}
|
||||
|
||||
QDateTime earliestTimestamp = QDateTime::currentDateTime();
|
||||
actionSources.clear();
|
||||
int loveCounter = 0;
|
||||
foreach ( const Tomahawk::SocialAction& sa, socialActions )
|
||||
{
|
||||
if ( sa.action == action )
|
||||
{
|
||||
if ( actionSources.contains( sa.source->friendlyName() ) )
|
||||
continue;
|
||||
actionSources << sa.source->friendlyName();
|
||||
|
||||
if ( ++loveCounter > 3 )
|
||||
continue;
|
||||
else if ( loveCounter > 1 )
|
||||
{
|
||||
if ( loveCounter == loveTotal )
|
||||
desc += tr( " and " );
|
||||
else
|
||||
desc += ", ";
|
||||
}
|
||||
|
||||
if ( sa.source->isLocal() )
|
||||
{
|
||||
if ( loveCounter == 1 )
|
||||
desc += "<b>" + tr( "You" ) + "</b>";
|
||||
else
|
||||
desc += "<b>" + tr( "you" ) + "</b>";
|
||||
}
|
||||
else
|
||||
desc += "<b>" + sa.source->friendlyName() + "</b>";
|
||||
|
||||
QDateTime saTimestamp = QDateTime::fromTime_t( sa.timestamp.toInt() );
|
||||
if ( saTimestamp < earliestTimestamp && saTimestamp.toTime_t() > 0 )
|
||||
earliestTimestamp = saTimestamp;
|
||||
}
|
||||
}
|
||||
if ( loveCounter > 0 )
|
||||
{
|
||||
if ( loveCounter > 3 )
|
||||
desc += " " + tr( "and" ) + " <b>" + tr( "%n other(s)", "", loveCounter - 3 ) + "</b>";
|
||||
|
||||
if ( mode == Short )
|
||||
desc = "<b>" + tr( "%n people", "", loveCounter ) + "</b>";
|
||||
|
||||
//FIXME: more action descs required
|
||||
if ( action == "Love" )
|
||||
desc += " " + tr( "loved this track" );
|
||||
else if ( action == "Inbox" )
|
||||
desc += " " + tr( "sent you this track %1" )
|
||||
.arg( TomahawkUtils::ageToString( earliestTimestamp, true ) );
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Query::setSaveHTTPResultHint( bool saveResultHint )
|
||||
{
|
||||
m_saveResultHint = saveResultHint;
|
||||
}
|
||||
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
QPixmap
|
||||
Query::cover( const QSize& size, bool forceLoad ) const
|
||||
{
|
||||
if ( m_albumPtr.isNull() )
|
||||
{
|
||||
m_artistPtr = Artist::get( artist(), false );
|
||||
m_albumPtr = Album::get( m_artistPtr, album(), false );
|
||||
connect( m_artistPtr.data(), SIGNAL( updated() ), SIGNAL( updated() ), Qt::UniqueConnection );
|
||||
connect( m_artistPtr.data(), SIGNAL( coverChanged() ), SIGNAL( coverChanged() ), Qt::UniqueConnection );
|
||||
connect( m_albumPtr.data(), SIGNAL( updated() ), SIGNAL( updated() ), Qt::UniqueConnection );
|
||||
connect( m_albumPtr.data(), SIGNAL( coverChanged() ), SIGNAL( coverChanged() ), Qt::UniqueConnection );
|
||||
}
|
||||
|
||||
m_albumPtr->cover( size, forceLoad );
|
||||
if ( m_albumPtr->coverLoaded() )
|
||||
{
|
||||
if ( !m_albumPtr->cover( size ).isNull() )
|
||||
return m_albumPtr->cover( size );
|
||||
|
||||
return m_artistPtr->cover( size, forceLoad );
|
||||
}
|
||||
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Query::coverLoaded() const
|
||||
{
|
||||
if ( m_albumPtr.isNull() )
|
||||
return false;
|
||||
|
||||
if ( m_albumPtr->coverLoaded() && !m_albumPtr->cover( QSize( 0, 0 ) ).isNull() )
|
||||
return true;
|
||||
|
||||
return m_artistPtr->coverLoaded();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
QList<Tomahawk::query_ptr>
|
||||
Query::similarTracks() const
|
||||
{
|
||||
if ( !m_simTracksLoaded )
|
||||
{
|
||||
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
|
||||
Query::lyrics() const
|
||||
{
|
||||
if ( !m_lyricsLoaded )
|
||||
{
|
||||
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
|
||||
Query::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
|
||||
Query::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();
|
||||
}
|
||||
|
@ -27,12 +27,11 @@
|
||||
|
||||
#include "Typedefs.h"
|
||||
#include "Result.h"
|
||||
#include "Track.h"
|
||||
#include "infosystem/InfoSystem.h"
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
class DatabaseCommand_LogPlayback;
|
||||
class DatabaseCommand_PlaybackHistory;
|
||||
class DatabaseCommand_LoadPlaylistEntries;
|
||||
|
||||
namespace Tomahawk
|
||||
@ -40,139 +39,63 @@ namespace Tomahawk
|
||||
|
||||
class Resolver;
|
||||
|
||||
struct SocialAction
|
||||
{
|
||||
QVariant action;
|
||||
QVariant value;
|
||||
QVariant timestamp;
|
||||
Tomahawk::source_ptr source;
|
||||
|
||||
// Make explicit so compiler won't auto-generate, since destructor of
|
||||
// source_ptr is not defined yet (only typedef included in header)
|
||||
SocialAction();
|
||||
~SocialAction();
|
||||
SocialAction& operator=( const SocialAction& other );
|
||||
SocialAction( const SocialAction& other );
|
||||
};
|
||||
|
||||
struct PlaybackLog
|
||||
{
|
||||
Tomahawk::source_ptr source;
|
||||
unsigned int timestamp;
|
||||
unsigned int secsPlayed;
|
||||
|
||||
// Make explicit so compiler won't auto-generate, since destructor of
|
||||
// source_ptr is not defined yet (only typedef included in header)
|
||||
PlaybackLog();
|
||||
~PlaybackLog();
|
||||
PlaybackLog& operator=( const PlaybackLog& other );
|
||||
PlaybackLog( const PlaybackLog& other );
|
||||
};
|
||||
|
||||
|
||||
class DLLEXPORT Query : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class ::DatabaseCommand_LogPlayback;
|
||||
friend class ::DatabaseCommand_PlaybackHistory;
|
||||
friend class ::DatabaseCommand_LoadPlaylistEntries;
|
||||
friend class Pipeline;
|
||||
|
||||
public:
|
||||
enum DescriptionMode
|
||||
{ Detailed = 0, Short = 1 };
|
||||
|
||||
static query_ptr get( const QString& artist, const QString& track, const QString& album, const QID& qid = QString(), bool autoResolve = true );
|
||||
static query_ptr get( const QString& artist, const QString& title, const QString& album, const QID& qid = QString(), bool autoResolve = true );
|
||||
static query_ptr get( const Tomahawk::track_ptr& track, const QID& qid = QString() );
|
||||
static query_ptr get( const QString& query, const QID& qid );
|
||||
|
||||
virtual ~Query();
|
||||
|
||||
bool equals( const Tomahawk::query_ptr& other, bool ignoreCase = false ) const;
|
||||
float howSimilar( const Tomahawk::result_ptr& r );
|
||||
|
||||
QVariant toVariant() const;
|
||||
QString toString() const;
|
||||
|
||||
QID id() const;
|
||||
|
||||
track_ptr queryTrack() const;
|
||||
track_ptr track() const;
|
||||
|
||||
/// returns list of all results so far
|
||||
QList< result_ptr > results() const;
|
||||
|
||||
/// how many results found so far?
|
||||
unsigned int numResults() const;
|
||||
|
||||
QID id() const;
|
||||
|
||||
/// sorter for list of results
|
||||
static bool resultSorter( const result_ptr& left, const result_ptr& right );
|
||||
|
||||
bool resolvingFinished() const { return m_resolveFinished; }
|
||||
/// true when a perfect result has been found (score of 1.0)
|
||||
bool solved() const { return m_solved; }
|
||||
/// true when any result has been found (score may be less than 1.0)
|
||||
bool playable() const { return m_playable; }
|
||||
|
||||
QString fullTextQuery() const { return m_fullTextQuery; }
|
||||
bool isFullTextQuery() const { return !m_fullTextQuery.isEmpty(); }
|
||||
bool resolvingFinished() const { return m_resolveFinished; }
|
||||
float howSimilar( const Tomahawk::result_ptr& r );
|
||||
|
||||
QPair< Tomahawk::source_ptr, unsigned int > playedBy() const;
|
||||
Tomahawk::Resolver* currentResolver() const;
|
||||
QList< QPointer< Tomahawk::Resolver > > resolvedBy() const { return m_resolvers; }
|
||||
|
||||
void setArtist( const QString& artist ) { m_artist = artist; updateSortNames(); }
|
||||
void setComposer( const QString& composer ) { m_composer = composer; updateSortNames(); }
|
||||
void setAlbum( const QString& album ) { m_album = album; updateSortNames(); }
|
||||
void setTrack( const QString& track ) { m_track = track; updateSortNames(); }
|
||||
void setResultHint( const QString& resultHint ) { m_resultHint = resultHint; }
|
||||
void setDuration( int duration ) { m_duration = duration; }
|
||||
void setAlbumPos( unsigned int albumpos ) { m_albumpos = albumpos; }
|
||||
void setDiscNumber( unsigned int discnumber ) { m_discnumber = discnumber; }
|
||||
|
||||
bool equals( const Tomahawk::query_ptr& other, bool ignoreCase = false ) const;
|
||||
|
||||
QVariant toVariant() const;
|
||||
QString toString() const;
|
||||
|
||||
QString resultHint() const { return m_resultHint; }
|
||||
QString artistSortname() const { return m_artistSortname; }
|
||||
QString composerSortname() const { return m_composerSortname; }
|
||||
QString albumSortname() const { return m_albumSortname; }
|
||||
QString trackSortname() const { return m_trackSortname; }
|
||||
|
||||
QString artist() const { return m_artist; }
|
||||
QString composer() const { return m_composer; }
|
||||
QString album() const { return m_album; }
|
||||
QString track() const { return m_track; }
|
||||
int duration() const { return m_duration; }
|
||||
unsigned int albumpos() const { return m_albumpos; }
|
||||
unsigned int discnumber() const { return m_discnumber; }
|
||||
|
||||
query_ptr displayQuery() const;
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
QPixmap cover( const QSize& size, bool forceLoad = true ) const;
|
||||
#endif
|
||||
bool coverLoaded() const;
|
||||
QString fullTextQuery() const { return m_fullTextQuery; }
|
||||
bool isFullTextQuery() const { return !m_fullTextQuery.isEmpty(); }
|
||||
|
||||
void setResolveFinished( bool resolved ) { m_resolveFinished = resolved; }
|
||||
void setPlayedBy( const Tomahawk::source_ptr& source, unsigned int playtime );
|
||||
|
||||
void setLoved( bool loved );
|
||||
bool loved();
|
||||
|
||||
void loadStats();
|
||||
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() );
|
||||
|
||||
void loadSocialActions();
|
||||
QList< Tomahawk::SocialAction > allSocialActions() const;
|
||||
void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions );
|
||||
QString socialActionDescription( const QString& action, DescriptionMode mode ) const;
|
||||
|
||||
void setSaveHTTPResultHint( bool saveResultHint );
|
||||
bool saveHTTPResultHint() const { return m_saveResultHint; }
|
||||
|
||||
QList<Tomahawk::query_ptr> similarTracks() const;
|
||||
QStringList lyrics() const;
|
||||
QString resultHint() const { return m_resultHint; }
|
||||
void setResultHint( const QString& resultHint ) { m_resultHint = resultHint; }
|
||||
|
||||
QWeakPointer< Tomahawk::Query > weakRef() { return m_ownRef; }
|
||||
void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef ) { m_ownRef = weakRef; }
|
||||
|
||||
/// sorter for list of results
|
||||
static bool resultSorter( const result_ptr& left, const result_ptr& right );
|
||||
|
||||
signals:
|
||||
void resultsAdded( const QList<Tomahawk::result_ptr>& );
|
||||
void resultsRemoved( const Tomahawk::result_ptr& );
|
||||
@ -185,15 +108,6 @@ signals:
|
||||
void playableStateChanged( bool state );
|
||||
void resolvingFinished( bool hasResults );
|
||||
|
||||
void coverChanged();
|
||||
|
||||
void socialActionsLoaded();
|
||||
void statsLoaded();
|
||||
void similarTracksLoaded();
|
||||
void lyricsLoaded();
|
||||
|
||||
void updated();
|
||||
|
||||
public slots:
|
||||
/// (indirectly) called by resolver plugins when results are found
|
||||
void addResults( const QList< Tomahawk::result_ptr >& );
|
||||
@ -206,15 +120,12 @@ public slots:
|
||||
void onResolverAdded();
|
||||
|
||||
private slots:
|
||||
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
void infoSystemFinished( QString target );
|
||||
|
||||
void onResultStatusChanged();
|
||||
void refreshResults();
|
||||
|
||||
private:
|
||||
Query();
|
||||
explicit Query( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve );
|
||||
explicit Query( const track_ptr& track, const QID& qid, bool autoResolve );
|
||||
explicit Query( const QString& query, const QID& qid );
|
||||
|
||||
void init();
|
||||
@ -223,10 +134,6 @@ private:
|
||||
void clearResults();
|
||||
void checkResults();
|
||||
|
||||
void updateSortNames();
|
||||
|
||||
void parseSocialActions();
|
||||
|
||||
QList< Tomahawk::artist_ptr > m_artists;
|
||||
QList< Tomahawk::album_ptr > m_albums;
|
||||
QList< Tomahawk::result_ptr > m_results;
|
||||
@ -235,47 +142,17 @@ private:
|
||||
bool m_resolveFinished;
|
||||
mutable QID m_qid;
|
||||
|
||||
QString m_artistSortname;
|
||||
QString m_composerSortname;
|
||||
QString m_albumSortname;
|
||||
QString m_trackSortname;
|
||||
|
||||
QString m_artist;
|
||||
QString m_composer;
|
||||
QString m_album;
|
||||
QString m_track;
|
||||
QString m_fullTextQuery;
|
||||
|
||||
int m_duration;
|
||||
unsigned int m_albumpos;
|
||||
unsigned int m_discnumber;
|
||||
QString m_resultHint;
|
||||
bool m_saveResultHint;
|
||||
|
||||
mutable Tomahawk::artist_ptr m_artistPtr;
|
||||
mutable Tomahawk::album_ptr m_albumPtr;
|
||||
|
||||
QPair< Tomahawk::source_ptr, unsigned int > m_playedBy;
|
||||
QList< QPointer< Tomahawk::Resolver > > m_resolvers;
|
||||
|
||||
bool m_saveResultHint;
|
||||
track_ptr m_queryTrack;
|
||||
|
||||
mutable QMutex m_mutex;
|
||||
QWeakPointer< Tomahawk::Query > m_ownRef;
|
||||
|
||||
bool m_playbackHistoryLoaded;
|
||||
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;
|
||||
};
|
||||
|
||||
}; //ns
|
||||
|
Loading…
x
Reference in New Issue
Block a user