1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 01:09:42 +01:00

* Added lyrics support to Query class.

This commit is contained in:
Christian Muehlhaeuser 2012-05-19 09:36:27 +02:00
parent b17b5ed276
commit b6b3bf1a1c
2 changed files with 50 additions and 1 deletions

View File

@ -110,6 +110,7 @@ Query::Query( const QString& artist, const QString& track, const QString& album,
, m_track( track )
, m_socialActionsLoaded( false )
, m_simTracksLoaded( false )
, m_lyricsLoaded( false )
, m_infoJobs( 0 )
{
init();
@ -810,6 +811,39 @@ Query::similarTracks() const
}
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 )
{
@ -819,6 +853,15 @@ Query::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVaria
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();

View File

@ -161,6 +161,7 @@ public:
QString socialActionDescription( const QString& action, DescriptionMode mode ) const;
QList<Tomahawk::query_ptr> similarTracks() const;
QStringList lyrics() const;
QWeakPointer< Tomahawk::Query > weakRef() { return m_ownRef; }
void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef ) { m_ownRef = weakRef; }
@ -182,6 +183,8 @@ signals:
void socialActionsLoaded();
void statsLoaded();
void similarTracksLoaded();
void lyricsLoaded();
void updated();
public slots:
@ -264,11 +267,14 @@ private:
bool m_simTracksLoaded;
QList<Tomahawk::query_ptr> m_similarTracks;
bool m_lyricsLoaded;
QStringList m_lyrics;
mutable int m_infoJobs;
};
}; //ns
Q_DECLARE_METATYPE(Tomahawk::query_ptr);
Q_DECLARE_METATYPE( Tomahawk::query_ptr );
#endif // QUERY_H