1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

Requests for cover art from lastfm now go through the infosystem caching mechanism. It's not actually storing a cache yet but the information flow works (at least, for cache misses :-) )

This commit is contained in:
Jeff Mitchell
2011-04-02 22:49:11 -04:00
parent 1da0a34d89
commit 2b85beb704
16 changed files with 215 additions and 121 deletions

View File

@@ -93,7 +93,8 @@ enum InfoType {
typedef QMap< InfoType, QVariant > InfoMap; typedef QMap< InfoType, QVariant > InfoMap;
typedef QMap< QString, QMap< QString, QString > > InfoGenericMap; typedef QMap< QString, QMap< QString, QString > > InfoGenericMap;
typedef QHash< QString, QVariant > InfoCustomDataHash; typedef QHash< QString, QVariant > InfoCustomData;
typedef QHash< QString, QString > InfoCacheCriteria;
class InfoPlugin : public QObject class InfoPlugin : public QObject
{ {
@@ -107,16 +108,17 @@ public:
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
} }
virtual void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomDataHash customData ) = 0; virtual void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData ) = 0;
signals: signals:
void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ); void getCachedInfo( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
void getCachedInfo( QHash< QString, QString > criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ); void updateCache( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output );
void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void finished( QString, Tomahawk::InfoSystem::InfoType ); void finished( QString, Tomahawk::InfoSystem::InfoType );
public slots: public slots:
//FIXME: Make pure virtual when everything supports it //FIXME: Make pure virtual when everything supports it
void notInCacheSlot( QHash<QString, QString> criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ) virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
{ {
} }
@@ -137,17 +139,17 @@ public:
void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &types ); void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &types );
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomDataHash customData ); void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData );
void getInfo( const QString &caller, const InfoMap &input, InfoCustomDataHash customData ); void getInfo( const QString &caller, const InfoMap &input, InfoCustomData customData );
InfoSystemCache* getCache() { return m_cache; } InfoSystemCache* getCache() { return m_cache; }
signals: signals:
void info( QString caller, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ); void info( QString caller, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void finished( QString target ); void finished( QString target );
public slots: public slots:
void infoSlot( QString target, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ); void infoSlot( QString target, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void finishedSlot( QString target, Tomahawk::InfoSystem::InfoType type); void finishedSlot( QString target, Tomahawk::InfoSystem::InfoType type);
private: private:
@@ -169,6 +171,7 @@ private:
} }
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoGenericMap ); Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoGenericMap );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCustomDataHash ); Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCustomData );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCacheCriteria );
#endif // TOMAHAWK_INFOSYSTEM_H #endif // TOMAHAWK_INFOSYSTEM_H

View File

@@ -168,8 +168,8 @@ AudioControls::AudioControls( QWidget* parent )
.scaled( ui->coverImage->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); .scaled( ui->coverImage->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
connect( TomahawkApp::instance()->infoSystem(), connect( TomahawkApp::instance()->infoSystem(),
SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash ) ), SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
SLOT( infoSystemInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash ) ) ); SLOT( infoSystemInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ) );
connect( TomahawkApp::instance()->infoSystem(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); connect( TomahawkApp::instance()->infoSystem(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
@@ -252,17 +252,17 @@ AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
QString artistName = result->artist()->name(); QString artistName = result->artist()->name();
QString albumName = result->album()->name(); QString albumName = result->album()->name();
Tomahawk::InfoSystem::InfoCustomDataHash trackInfo; Tomahawk::InfoSystem::InfoCustomData trackInfo;
trackInfo["artist"] = QVariant::fromValue< QString >( result->artist()->name() ); trackInfo["artist"] = QVariant::fromValue< QString >( result->artist()->name() );
trackInfo["album"] = QVariant::fromValue< QString >( result->album()->name() ); trackInfo["album"] = QVariant::fromValue< QString >( result->album()->name() );
TomahawkApp::instance()->infoSystem()->getInfo( TomahawkApp::instance()->infoSystem()->getInfo(
s_infoIdentifier, Tomahawk::InfoSystem::InfoAlbumCoverArt, s_infoIdentifier, Tomahawk::InfoSystem::InfoAlbumCoverArt,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomDataHash >( trackInfo ), Tomahawk::InfoSystem::InfoCustomDataHash() ); QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomData >( trackInfo ), Tomahawk::InfoSystem::InfoCustomData() );
} }
void void
AudioControls::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ) AudioControls::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if ( caller != s_infoIdentifier || type != Tomahawk::InfoSystem::InfoAlbumCoverArt ) if ( caller != s_infoIdentifier || type != Tomahawk::InfoSystem::InfoAlbumCoverArt )
@@ -277,13 +277,13 @@ AudioControls::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType ty
return; return;
} }
if ( !output.canConvert< Tomahawk::InfoSystem::InfoCustomDataHash >() ) if ( !output.canConvert< Tomahawk::InfoSystem::InfoCustomData >() )
{ {
qDebug() << "Cannot convert fetched art from a QByteArray"; qDebug() << "Cannot convert fetched art from a QByteArray";
return; return;
} }
Tomahawk::InfoSystem::InfoCustomDataHash returnedData = output.value< Tomahawk::InfoSystem::InfoCustomDataHash >(); Tomahawk::InfoSystem::InfoCustomData returnedData = output.value< Tomahawk::InfoSystem::InfoCustomData >();
const QByteArray ba = returnedData["imgbytes"].toByteArray(); const QByteArray ba = returnedData["imgbytes"].toByteArray();
if ( ba.length() ) if ( ba.length() )
{ {

View File

@@ -45,7 +45,7 @@ signals:
public slots: public slots:
void onRepeatModeChanged( PlaylistInterface::RepeatMode mode ); void onRepeatModeChanged( PlaylistInterface::RepeatMode mode );
void onShuffleModeChanged( bool enabled ); void onShuffleModeChanged( bool enabled );
void infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ); void infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void infoSystemFinished( QString target ); void infoSystemFinished( QString target );
protected: protected:

View File

@@ -41,7 +41,7 @@ EchoNestPlugin::~EchoNestPlugin()
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
} }
void EchoNestPlugin::getInfo(const QString &caller, const InfoType type, const QVariant& data, InfoCustomDataHash customData) void EchoNestPlugin::getInfo(const QString &caller, const InfoType type, const QVariant& data, InfoCustomData customData)
{ {
switch (type) switch (type)
{ {
@@ -65,7 +65,7 @@ void EchoNestPlugin::getInfo(const QString &caller, const InfoType type, const Q
} }
} }
void EchoNestPlugin::getSongProfile(const QString &caller, const QVariant& data, InfoCustomDataHash &customData, const QString &item) void EchoNestPlugin::getSongProfile(const QString &caller, const QVariant& data, InfoCustomData &customData, const QString &item)
{ {
//WARNING: Totally not implemented yet //WARNING: Totally not implemented yet
@@ -80,7 +80,7 @@ void EchoNestPlugin::getSongProfile(const QString &caller, const QVariant& data,
// connect(reply, SIGNAL(finished()), SLOT(getArtistBiographySlot())); // connect(reply, SIGNAL(finished()), SLOT(getArtistBiographySlot()));
} }
void EchoNestPlugin::getArtistBiography(const QString &caller, const QVariant& data, InfoCustomDataHash &customData) void EchoNestPlugin::getArtistBiography(const QString &caller, const QVariant& data, InfoCustomData &customData)
{ {
if( !isValidArtistData( caller, data, customData ) ) if( !isValidArtistData( caller, data, customData ) )
return; return;
@@ -94,7 +94,7 @@ void EchoNestPlugin::getArtistBiography(const QString &caller, const QVariant& d
connect(reply, SIGNAL(finished()), SLOT(getArtistBiographySlot())); connect(reply, SIGNAL(finished()), SLOT(getArtistBiographySlot()));
} }
void EchoNestPlugin::getArtistFamiliarity(const QString &caller, const QVariant& data, InfoCustomDataHash &customData) void EchoNestPlugin::getArtistFamiliarity(const QString &caller, const QVariant& data, InfoCustomData &customData)
{ {
if( !isValidArtistData( caller, data, customData ) ) if( !isValidArtistData( caller, data, customData ) )
return; return;
@@ -109,7 +109,7 @@ void EchoNestPlugin::getArtistFamiliarity(const QString &caller, const QVariant&
connect(reply, SIGNAL(finished()), SLOT(getArtistFamiliaritySlot())); connect(reply, SIGNAL(finished()), SLOT(getArtistFamiliaritySlot()));
} }
void EchoNestPlugin::getArtistHotttnesss(const QString &caller, const QVariant& data, InfoCustomDataHash &customData) void EchoNestPlugin::getArtistHotttnesss(const QString &caller, const QVariant& data, InfoCustomData &customData)
{ {
if( !isValidArtistData( caller, data, customData ) ) if( !isValidArtistData( caller, data, customData ) )
return; return;
@@ -123,7 +123,7 @@ void EchoNestPlugin::getArtistHotttnesss(const QString &caller, const QVariant&
connect(reply, SIGNAL(finished()), SLOT(getArtistHotttnesssSlot())); connect(reply, SIGNAL(finished()), SLOT(getArtistHotttnesssSlot()));
} }
void EchoNestPlugin::getArtistTerms(const QString &caller, const QVariant& data, InfoCustomDataHash &customData) void EchoNestPlugin::getArtistTerms(const QString &caller, const QVariant& data, InfoCustomData &customData)
{ {
if( !isValidArtistData( caller, data, customData ) ) if( !isValidArtistData( caller, data, customData ) )
return; return;
@@ -137,7 +137,7 @@ void EchoNestPlugin::getArtistTerms(const QString &caller, const QVariant& data,
connect(reply, SIGNAL(finished()), SLOT(getArtistTermsSlot())); connect(reply, SIGNAL(finished()), SLOT(getArtistTermsSlot()));
} }
void EchoNestPlugin::getMiscTopTerms(const QString &caller, const QVariant& data, InfoCustomDataHash& customData) void EchoNestPlugin::getMiscTopTerms(const QString &caller, const QVariant& data, InfoCustomData& customData)
{ {
QNetworkReply* reply = Echonest::Artist::topTerms( 20 ); QNetworkReply* reply = Echonest::Artist::topTerms( 20 );
m_replyMap[reply] = customData; m_replyMap[reply] = customData;
@@ -230,7 +230,7 @@ void EchoNestPlugin::getMiscTopSlot()
reply->deleteLater(); reply->deleteLater();
} }
bool EchoNestPlugin::isValidArtistData(const QString &caller, const QVariant& data, InfoCustomDataHash &customData) bool EchoNestPlugin::isValidArtistData(const QString &caller, const QVariant& data, InfoCustomData &customData)
{ {
if (data.isNull() || !data.isValid() || !data.canConvert<QString>()) if (data.isNull() || !data.isValid() || !data.canConvert<QString>())
{ {
@@ -246,7 +246,7 @@ bool EchoNestPlugin::isValidArtistData(const QString &caller, const QVariant& da
return true; return true;
} }
bool EchoNestPlugin::isValidTrackData(const QString &caller, const QVariant& data, InfoCustomDataHash &customData) bool EchoNestPlugin::isValidTrackData(const QString &caller, const QVariant& data, InfoCustomData &customData)
{ {
if (data.isNull() || !data.isValid() || !data.canConvert<QString>()) if (data.isNull() || !data.isValid() || !data.canConvert<QString>())
{ {

View File

@@ -42,18 +42,18 @@ public:
EchoNestPlugin(QObject *parent); EchoNestPlugin(QObject *parent);
virtual ~EchoNestPlugin(); virtual ~EchoNestPlugin();
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomDataHash customData ); void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData );
private: private:
void getSongProfile( const QString &caller, const QVariant &data, InfoCustomDataHash &customData, const QString &item = QString() ); void getSongProfile( const QString &caller, const QVariant &data, InfoCustomData &customData, const QString &item = QString() );
void getArtistBiography ( const QString &caller, const QVariant &data, InfoCustomDataHash &customData ); void getArtistBiography ( const QString &caller, const QVariant &data, InfoCustomData &customData );
void getArtistFamiliarity( const QString &caller, const QVariant &data, InfoCustomDataHash &customData ); void getArtistFamiliarity( const QString &caller, const QVariant &data, InfoCustomData &customData );
void getArtistHotttnesss( const QString &caller, const QVariant &data, InfoCustomDataHash &customData ); void getArtistHotttnesss( const QString &caller, const QVariant &data, InfoCustomData &customData );
void getArtistTerms( const QString &caller, const QVariant &data, InfoCustomDataHash &customData ); void getArtistTerms( const QString &caller, const QVariant &data, InfoCustomData &customData );
void getMiscTopTerms( const QString &caller, const QVariant &data, InfoCustomDataHash &customData ); void getMiscTopTerms( const QString &caller, const QVariant &data, InfoCustomData &customData );
bool isValidArtistData( const QString &caller, const QVariant& data, InfoCustomDataHash& customData ); bool isValidArtistData( const QString &caller, const QVariant& data, InfoCustomData& customData );
bool isValidTrackData( const QString &caller, const QVariant& data, InfoCustomDataHash& customData ); bool isValidTrackData( const QString &caller, const QVariant& data, InfoCustomData& customData );
Echonest::Artist artistFromReply( QNetworkReply* ); Echonest::Artist artistFromReply( QNetworkReply* );
private slots: private slots:
@@ -64,7 +64,7 @@ private slots:
void getMiscTopSlot(); void getMiscTopSlot();
private: private:
QHash< QNetworkReply*, InfoCustomDataHash > m_replyMap; QHash< QNetworkReply*, InfoCustomData > m_replyMap;
QHash< QNetworkReply*, QString > m_callerMap; QHash< QNetworkReply*, QString > m_callerMap;
}; };

View File

@@ -92,7 +92,7 @@ LastFmPlugin::~LastFmPlugin()
} }
void void
LastFmPlugin::dataError( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomDataHash &customData ) LastFmPlugin::dataError( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData )
{ {
emit info( caller, type, data, QVariant(), customData ); emit info( caller, type, data, QVariant(), customData );
emit finished( caller, type ); emit finished( caller, type );
@@ -100,7 +100,7 @@ LastFmPlugin::dataError( const QString &caller, const InfoType type, const QVari
} }
void void
LastFmPlugin::getInfo( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomDataHash customData ) LastFmPlugin::getInfo( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData customData )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if ( type == InfoMiscSubmitNowPlaying ) if ( type == InfoMiscSubmitNowPlaying )
@@ -114,14 +114,14 @@ LastFmPlugin::getInfo( const QString &caller, const InfoType type, const QVarian
} }
void void
LastFmPlugin::nowPlaying( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomDataHash &customData ) LastFmPlugin::nowPlaying( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData )
{ {
if ( !data.canConvert< Tomahawk::InfoSystem::InfoCustomDataHash >() || !m_scrobbler ) if ( !data.canConvert< Tomahawk::InfoSystem::InfoCustomData >() || !m_scrobbler )
{ {
dataError( caller, type, data, customData ); dataError( caller, type, data, customData );
return; return;
} }
InfoCustomDataHash hash = data.value< Tomahawk::InfoSystem::InfoCustomDataHash >(); InfoCustomData hash = data.value< Tomahawk::InfoSystem::InfoCustomData >();
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) || !hash.contains( "duration" ) ) if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) || !hash.contains( "duration" ) )
{ {
dataError( caller, type, data, customData ); dataError( caller, type, data, customData );
@@ -143,7 +143,7 @@ LastFmPlugin::nowPlaying( const QString &caller, const InfoType type, const QVar
} }
void void
LastFmPlugin::scrobble( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomDataHash &customData ) LastFmPlugin::scrobble( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData )
{ {
Q_ASSERT( QThread::currentThread() == thread() ); Q_ASSERT( QThread::currentThread() == thread() );
@@ -162,33 +162,50 @@ LastFmPlugin::scrobble( const QString &caller, const InfoType type, const QVaria
} }
void void
LastFmPlugin::fetchCoverArt( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomDataHash &customData ) LastFmPlugin::fetchCoverArt( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if ( !data.canConvert< Tomahawk::InfoSystem::InfoCustomDataHash >() ) if ( !data.canConvert< Tomahawk::InfoSystem::InfoCustomData >() )
{ {
dataError( caller, type, data, customData ); dataError( caller, type, data, customData );
return; return;
} }
InfoCustomDataHash hash = data.value< Tomahawk::InfoSystem::InfoCustomDataHash >(); InfoCustomData hash = data.value< Tomahawk::InfoSystem::InfoCustomData >();
if ( !hash.contains( "artist" ) || !hash.contains( "album" ) ) if ( !hash.contains( "artist" ) || !hash.contains( "album" ) )
{ {
dataError( caller, type, data, customData ); dataError( caller, type, data, customData );
return; return;
} }
QString artistName = hash["artist"].toString(); Tomahawk::InfoSystem::InfoCacheCriteria criteria;
QString albumName = hash["album"].toString(); criteria["artist"] = hash["artist"].toString();
criteria["album"] = hash["album"].toString();
emit getCachedInfo( criteria, caller, type, data, customData );
}
void
LastFmPlugin::notInCacheSlot( QHash<QString, QString> criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
{
qDebug() << Q_FUNC_INFO;
if ( type == InfoAlbumCoverArt )
{
QString artistName = criteria["artist"];
QString albumName = criteria["album"];
QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=album.imageredirect&artist=%1&album=%2&size=medium&api_key=7a90f6672a04b809ee309af169f34b8b"; QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=album.imageredirect&artist=%1&album=%2&size=medium&api_key=7a90f6672a04b809ee309af169f34b8b";
QNetworkRequest req( imgurl.arg( artistName ).arg( albumName ) ); QNetworkRequest req( imgurl.arg( artistName ).arg( albumName ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( req ); QNetworkReply* reply = TomahawkUtils::nam()->get( req );
reply->setProperty("customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomDataHash>(customData)); reply->setProperty( "customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>( customData ) );
reply->setProperty("origData", data); reply->setProperty( "origData", input );
reply->setProperty("caller", caller); reply->setProperty( "caller", caller );
reply->setProperty("type", (uint)(type) ); reply->setProperty( "type", (uint)(type) );
connect( reply, SIGNAL( finished() ), SLOT( coverArtReturned() ) ); connect( reply, SIGNAL( finished() ), SLOT( coverArtReturned() ) );
return;
}
else
qDebug() << "Couldn't figure out what to do with this type of request after cache miss";
} }
void void
@@ -200,17 +217,26 @@ LastFmPlugin::coverArtReturned()
if ( redir.isEmpty() ) if ( redir.isEmpty() )
{ {
const QByteArray ba = reply->readAll(); const QByteArray ba = reply->readAll();
Tomahawk::InfoSystem::InfoCustomDataHash returnedData; InfoCustomData returnedData;
returnedData["imgbytes"] = ba; returnedData["imgbytes"] = ba;
returnedData["url"] = reply->url().toString(); returnedData["url"] = reply->url().toString();
InfoCustomData customData = reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt());
emit info( emit info(
reply->property( "caller" ).toString(), reply->property( "caller" ).toString(),
(Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt()), type,
reply->property( "origData" ), reply->property( "origData" ),
returnedData, returnedData,
reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomDataHash >() customData
); );
emit finished( reply->property( "caller" ).toString(), (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt()) ); emit finished( reply->property( "caller" ).toString(), (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt()) );
InfoCustomData origData = reply->property( "origData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
Tomahawk::InfoSystem::InfoCacheCriteria criteria;
criteria["artist"] = origData["artist"].toString();
criteria["album"] = origData["album"].toString();
emit updateCache( criteria, type, returnedData );
} }
else else
{ {

View File

@@ -43,19 +43,20 @@ public:
LastFmPlugin( QObject *parent ); LastFmPlugin( QObject *parent );
virtual ~LastFmPlugin(); virtual ~LastFmPlugin();
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomDataHash customData ); void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData );
public slots: public slots:
void settingsChanged(); void settingsChanged();
void onAuthenticated(); void onAuthenticated();
void coverArtReturned(); void coverArtReturned();
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
private: private:
void fetchCoverArt( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomDataHash &customData ); void fetchCoverArt( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData );
void scrobble( const QString &caller, const InfoType type, const QVariant& data, InfoCustomDataHash &customData ); void scrobble( const QString &caller, const InfoType type, const QVariant& data, InfoCustomData &customData );
void createScrobbler(); void createScrobbler();
void nowPlaying( const QString &caller, const InfoType type, const QVariant& data, InfoCustomDataHash &customData ); void nowPlaying( const QString &caller, const InfoType type, const QVariant& data, InfoCustomData &customData );
void dataError( const QString &caller, const InfoType type, const QVariant& data, InfoCustomDataHash &customData ); void dataError( const QString &caller, const InfoType type, const QVariant& data, InfoCustomData &customData );
lastfm::MutableTrack m_track; lastfm::MutableTrack m_track;
lastfm::Audioscrobbler* m_scrobbler; lastfm::Audioscrobbler* m_scrobbler;

View File

@@ -42,12 +42,12 @@ MusixMatchPlugin::~MusixMatchPlugin()
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
} }
void MusixMatchPlugin::getInfo(const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomDataHash customData) void MusixMatchPlugin::getInfo(const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData customData)
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if( !isValidTrackData(caller, data, customData) || !data.canConvert<Tomahawk::InfoSystem::InfoCustomDataHash>()) if( !isValidTrackData(caller, data, customData) || !data.canConvert<Tomahawk::InfoSystem::InfoCustomData>())
return; return;
Tomahawk::InfoSystem::InfoCustomDataHash hash = data.value<Tomahawk::InfoSystem::InfoCustomDataHash>(); Tomahawk::InfoSystem::InfoCustomData hash = data.value<Tomahawk::InfoSystem::InfoCustomData>();
QString artist = hash["artistName"].toString(); QString artist = hash["artistName"].toString();
QString track = hash["trackName"].toString(); QString track = hash["trackName"].toString();
if( artist.isEmpty() || track.isEmpty() ) if( artist.isEmpty() || track.isEmpty() )
@@ -63,24 +63,24 @@ void MusixMatchPlugin::getInfo(const QString &caller, const InfoType type, const
url.addQueryItem("q_artist", artist); url.addQueryItem("q_artist", artist);
url.addQueryItem("q_track", track); url.addQueryItem("q_track", track);
QNetworkReply* reply = TomahawkUtils::nam()->get(QNetworkRequest(url)); QNetworkReply* reply = TomahawkUtils::nam()->get(QNetworkRequest(url));
reply->setProperty("customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomDataHash>(customData)); reply->setProperty("customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>(customData));
reply->setProperty("origData", data); reply->setProperty("origData", data);
reply->setProperty("caller", caller); reply->setProperty("caller", caller);
connect(reply, SIGNAL(finished()), SLOT(trackSearchSlot())); connect(reply, SIGNAL(finished()), SLOT(trackSearchSlot()));
} }
bool MusixMatchPlugin::isValidTrackData(const QString &caller, const QVariant& data, Tomahawk::InfoSystem::InfoCustomDataHash &customData) bool MusixMatchPlugin::isValidTrackData(const QString &caller, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData)
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if (data.isNull() || !data.isValid() || !data.canConvert<Tomahawk::InfoSystem::InfoCustomDataHash>()) if (data.isNull() || !data.isValid() || !data.canConvert<Tomahawk::InfoSystem::InfoCustomData>())
{ {
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData); emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData);
emit finished(caller, Tomahawk::InfoSystem::InfoTrackLyrics); emit finished(caller, Tomahawk::InfoSystem::InfoTrackLyrics);
qDebug() << "MusixMatchPlugin::isValidTrackData: Data null, invalid, or can't convert"; qDebug() << "MusixMatchPlugin::isValidTrackData: Data null, invalid, or can't convert";
return false; return false;
} }
InfoCustomDataHash hash = data.value<Tomahawk::InfoSystem::InfoCustomDataHash>(); InfoCustomData hash = data.value<Tomahawk::InfoSystem::InfoCustomData>();
if (hash["trackName"].toString().isEmpty() ) if (hash["trackName"].toString().isEmpty() )
{ {
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData); emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData);
@@ -104,7 +104,7 @@ void MusixMatchPlugin::trackSearchSlot()
QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() ); QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
if (!oldReply) if (!oldReply)
{ {
emit info(QString(), Tomahawk::InfoSystem::InfoTrackLyrics, QVariant(), QVariant(), Tomahawk::InfoSystem::InfoCustomDataHash()); emit info(QString(), Tomahawk::InfoSystem::InfoTrackLyrics, QVariant(), QVariant(), Tomahawk::InfoSystem::InfoCustomData());
return; return;
} }
QDomDocument doc; QDomDocument doc;
@@ -113,7 +113,7 @@ void MusixMatchPlugin::trackSearchSlot()
QDomNodeList domNodeList = doc.elementsByTagName("track_id"); QDomNodeList domNodeList = doc.elementsByTagName("track_id");
if (domNodeList.isEmpty()) if (domNodeList.isEmpty())
{ {
emit info(oldReply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics, oldReply->property("origData"), QVariant(), oldReply->property("customData").value<Tomahawk::InfoSystem::InfoCustomDataHash>()); emit info(oldReply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics, oldReply->property("origData"), QVariant(), oldReply->property("customData").value<Tomahawk::InfoSystem::InfoCustomData>());
emit finished(oldReply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics); emit finished(oldReply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics);
return; return;
} }
@@ -135,7 +135,7 @@ void MusixMatchPlugin::trackLyricsSlot()
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() ); QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
if (!reply) if (!reply)
{ {
emit info(QString(), Tomahawk::InfoSystem::InfoTrackLyrics, QVariant(), QVariant(), Tomahawk::InfoSystem::InfoCustomDataHash()); emit info(QString(), Tomahawk::InfoSystem::InfoTrackLyrics, QVariant(), QVariant(), Tomahawk::InfoSystem::InfoCustomData());
return; return;
} }
QDomDocument doc; QDomDocument doc;
@@ -143,12 +143,12 @@ void MusixMatchPlugin::trackLyricsSlot()
QDomNodeList domNodeList = doc.elementsByTagName("lyrics_body"); QDomNodeList domNodeList = doc.elementsByTagName("lyrics_body");
if (domNodeList.isEmpty()) if (domNodeList.isEmpty())
{ {
emit info(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics, reply->property("origData"), QVariant(), reply->property("customData").value<Tomahawk::InfoSystem::InfoCustomDataHash>()); emit info(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics, reply->property("origData"), QVariant(), reply->property("customData").value<Tomahawk::InfoSystem::InfoCustomData>());
emit finished(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics); emit finished(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics);
return; return;
} }
QString lyrics = domNodeList.at(0).toElement().text(); QString lyrics = domNodeList.at(0).toElement().text();
qDebug() << "Emitting lyrics: " << lyrics; qDebug() << "Emitting lyrics: " << lyrics;
emit info(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics, reply->property("origData"), QVariant(lyrics), reply->property("customData").value<Tomahawk::InfoSystem::InfoCustomDataHash>()); emit info(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics, reply->property("origData"), QVariant(lyrics), reply->property("customData").value<Tomahawk::InfoSystem::InfoCustomData>());
emit finished(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics); emit finished(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics);
} }

View File

@@ -36,10 +36,10 @@ public:
MusixMatchPlugin(QObject *parent); MusixMatchPlugin(QObject *parent);
virtual ~MusixMatchPlugin(); virtual ~MusixMatchPlugin();
void getInfo(const QString &caller, const InfoType type, const QVariant &data, InfoCustomDataHash customData); void getInfo(const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData);
private: private:
bool isValidTrackData( const QString &caller, const QVariant& data, InfoCustomDataHash &customData ); bool isValidTrackData( const QString &caller, const QVariant& data, InfoCustomData &customData );
public slots: public slots:
void trackSearchSlot(); void trackSearchSlot();

View File

@@ -37,12 +37,26 @@ InfoPlugin::InfoPlugin(QObject *parent)
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
InfoSystem *system = qobject_cast< InfoSystem* >( parent ); InfoSystem *system = qobject_cast< InfoSystem* >( parent );
if( system ) if( system )
{
QObject::connect(
this,
SIGNAL( getCachedInfo( Tomahawk::InfoSystem::InfoCacheCriteria, QString, Tomahawk::InfoSystem::InfoType, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
system->getCache(),
SLOT( getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria, QString, Tomahawk::InfoSystem::InfoType, QVariant, Tomahawk::InfoSystem::InfoCustomData ) )
);
QObject::connect( QObject::connect(
system->getCache(), system->getCache(),
SIGNAL( notInCache( QHash< QString, QString >, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash ) ), SIGNAL( notInCache( Tomahawk::InfoSystem::InfoCacheCriteria, QString, Tomahawk::InfoSystem::InfoType, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
this, this,
SLOT( notInCacheSlot( QHash< QString, QString >, QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash ) ) SLOT( notInCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria, QString, Tomahawk::InfoSystem::InfoType, QVariant, Tomahawk::InfoSystem::InfoCustomData ) )
); );
QObject::connect(
this,
SIGNAL( updateCache( Tomahawk::InfoSystem::InfoCacheCriteria, Tomahawk::InfoSystem::InfoType, QVariant ) ),
system->getCache(),
SLOT( updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria, Tomahawk::InfoSystem::InfoType, QVariant ) )
);
}
} }
@@ -50,32 +64,44 @@ InfoSystem::InfoSystem(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
qRegisterMetaType<QMap< QString, QMap< QString, QString > > >("Tomahawk::InfoSystem::InfoGenericMap"); qRegisterMetaType< QMap< QString, QMap< QString, QString > > >( "Tomahawk::InfoSystem::InfoGenericMap" );
qRegisterMetaType<QHash<QString, QVariant > >("Tomahawk::InfoSystem::InfoCustomDataHash"); qRegisterMetaType< QHash< QString, QVariant > >( "Tomahawk::InfoSystem::InfoCustomData" );
qRegisterMetaType< QHash< QString, QString > >( "Tomahawk::InfoSystem::InfoCacheCriteria" );
qRegisterMetaType< Tomahawk::InfoSystem::InfoType >( "Tomahawk::InfoSystem::InfoType" );
m_infoSystemCacheThreadController = new QThread( this ); m_infoSystemCacheThreadController = new QThread( this );
m_cache = new InfoSystemCache(); m_cache = new InfoSystemCache();
m_cache->moveToThread( m_infoSystemCacheThreadController ); m_cache->moveToThread( m_infoSystemCacheThreadController );
m_infoSystemCacheThreadController->start( QThread::IdlePriority ); m_infoSystemCacheThreadController->start( QThread::IdlePriority );
InfoPluginPtr enptr(new EchoNestPlugin(this)); InfoPluginPtr enptr( new EchoNestPlugin( this ) );
m_plugins.append(enptr); m_plugins.append( enptr );
InfoPluginPtr mmptr(new MusixMatchPlugin(this)); InfoPluginPtr mmptr( new MusixMatchPlugin( this ) );
m_plugins.append(mmptr); m_plugins.append( mmptr );
InfoPluginPtr lfmptr(new LastFmPlugin(this)); InfoPluginPtr lfmptr( new LastFmPlugin( this ) );
m_plugins.append(lfmptr); m_plugins.append( lfmptr );
Q_FOREACH( InfoPluginPtr plugin, m_plugins ) Q_FOREACH( InfoPluginPtr plugin, m_plugins )
{ {
connect(plugin.data(), SIGNAL(info(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash)), connect(
this, SLOT(infoSlot(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash)), Qt::UniqueConnection); plugin.data(),
connect(plugin.data(), SIGNAL(finished(QString, Tomahawk::InfoSystem::InfoType)), SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
this, SLOT(finishedSlot(QString, Tomahawk::InfoSystem::InfoType)), Qt::UniqueConnection); this,
SLOT( infoSlot( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
Qt::UniqueConnection
);
connect(
plugin.data(),
SIGNAL( finished( QString, Tomahawk::InfoSystem::InfoType ) ),
this,
SLOT( finishedSlot( QString, Tomahawk::InfoSystem::InfoType ) ), Qt::UniqueConnection
);
} }
connect(m_cache, SIGNAL(info(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash)), connect( m_cache, SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
this, SLOT(infoSlot(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash)), Qt::UniqueConnection); this, SLOT( infoSlot( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ), Qt::UniqueConnection );
connect(m_cache, SIGNAL(finished(QString, Tomahawk::InfoSystem::InfoType)), connect( m_cache, SIGNAL( finished( QString, Tomahawk::InfoSystem::InfoType ) ),
this, SLOT(finishedSlot(QString, Tomahawk::InfoSystem::InfoType)), Qt::UniqueConnection); this, SLOT( finishedSlot( QString, Tomahawk::InfoSystem::InfoType ) ), Qt::UniqueConnection );
} }
InfoSystem::~InfoSystem() InfoSystem::~InfoSystem()
@@ -125,7 +151,7 @@ QLinkedList< InfoPluginPtr > InfoSystem::determineOrderedMatches(const InfoType
return providers; return providers;
} }
void InfoSystem::getInfo(const QString &caller, const InfoType type, const QVariant& data, InfoCustomDataHash customData) void InfoSystem::getInfo(const QString &caller, const InfoType type, const QVariant& data, InfoCustomData customData)
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QLinkedList< InfoPluginPtr > providers = determineOrderedMatches(type); QLinkedList< InfoPluginPtr > providers = determineOrderedMatches(type);
@@ -149,13 +175,13 @@ void InfoSystem::getInfo(const QString &caller, const InfoType type, const QVari
ptr.data()->getInfo(caller, type, data, customData); ptr.data()->getInfo(caller, type, data, customData);
} }
void InfoSystem::getInfo(const QString &caller, const InfoMap &input, InfoCustomDataHash customData) void InfoSystem::getInfo(const QString &caller, const InfoMap &input, InfoCustomData customData)
{ {
Q_FOREACH( InfoType type, input.keys() ) Q_FOREACH( InfoType type, input.keys() )
getInfo(caller, type, input[type], customData); getInfo(caller, type, input[type], customData);
} }
void InfoSystem::infoSlot(QString target, InfoType type, QVariant input, QVariant output, InfoCustomDataHash customData) void InfoSystem::infoSlot(QString target, InfoType type, QVariant input, QVariant output, InfoCustomData customData)
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
qDebug() << "current count in dataTracker is " << m_dataTracker[target][type]; qDebug() << "current count in dataTracker is " << m_dataTracker[target][type];

View File

@@ -0,0 +1,34 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtDebug>
#include "infosystemcache.h"
void
Tomahawk::InfoSystem::InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
{
qDebug() << Q_FUNC_INFO;
emit notInCache( criteria, caller, type, input, customData );
}
void
Tomahawk::InfoSystem::InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output )
{
qDebug() << Q_FUNC_INFO;
}

View File

@@ -47,10 +47,14 @@ public:
} }
signals: signals:
void notInCache( QHash< QString, QString > criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ); void notInCache( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ); void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void finished( QString, Tomahawk::InfoSystem::InfoType ); void finished( QString, Tomahawk::InfoSystem::InfoType );
public slots:
void getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
void updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output );
}; };
} //namespace InfoSystem } //namespace InfoSystem

View File

@@ -39,8 +39,8 @@ Scrobbler::Scrobbler( QObject* parent )
SLOT( engineTick( unsigned int ) ), Qt::QueuedConnection ); SLOT( engineTick( unsigned int ) ), Qt::QueuedConnection );
connect( TomahawkApp::instance()->infoSystem(), connect( TomahawkApp::instance()->infoSystem(),
SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash ) ), SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
SLOT( infoSystemInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash ) ) ); SLOT( infoSystemInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ) );
connect( TomahawkApp::instance()->infoSystem(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); connect( TomahawkApp::instance()->infoSystem(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
} }
@@ -63,7 +63,7 @@ Scrobbler::trackStarted( const Tomahawk::result_ptr& track )
scrobble(); scrobble();
} }
Tomahawk::InfoSystem::InfoCustomDataHash trackInfo; Tomahawk::InfoSystem::InfoCustomData trackInfo;
trackInfo["title"] = QVariant::fromValue< QString >( track->track() ); trackInfo["title"] = QVariant::fromValue< QString >( track->track() );
trackInfo["artist"] = QVariant::fromValue< QString >( track->artist()->name() ); trackInfo["artist"] = QVariant::fromValue< QString >( track->artist()->name() );
@@ -71,7 +71,7 @@ Scrobbler::trackStarted( const Tomahawk::result_ptr& track )
trackInfo["duration"] = QVariant::fromValue< uint >( track->duration() ); trackInfo["duration"] = QVariant::fromValue< uint >( track->duration() );
TomahawkApp::instance()->infoSystem()->getInfo( TomahawkApp::instance()->infoSystem()->getInfo(
s_infoIdentifier, Tomahawk::InfoSystem::InfoMiscSubmitNowPlaying, s_infoIdentifier, Tomahawk::InfoSystem::InfoMiscSubmitNowPlaying,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomDataHash >( trackInfo ), Tomahawk::InfoSystem::InfoCustomDataHash() ); QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomData >( trackInfo ), Tomahawk::InfoSystem::InfoCustomData() );
m_scrobblePoint = ScrobblePoint( track->duration() / 2 ); m_scrobblePoint = ScrobblePoint( track->duration() / 2 );
} }
@@ -119,11 +119,11 @@ Scrobbler::scrobble()
TomahawkApp::instance()->infoSystem()->getInfo( TomahawkApp::instance()->infoSystem()->getInfo(
s_infoIdentifier, Tomahawk::InfoSystem::InfoMiscSubmitScrobble, s_infoIdentifier, Tomahawk::InfoSystem::InfoMiscSubmitScrobble,
QVariant(), Tomahawk::InfoSystem::InfoCustomDataHash() ); QVariant(), Tomahawk::InfoSystem::InfoCustomData() );
} }
void void
Scrobbler::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ) Scrobbler::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData )
{ {
if ( caller == s_infoIdentifier ) if ( caller == s_infoIdentifier )
{ {

View File

@@ -45,7 +45,7 @@ public slots:
void trackStopped(); void trackStopped();
void engineTick( unsigned int secondsElapsed ); void engineTick( unsigned int secondsElapsed );
void infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData ); void infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void infoSystemFinished( QString target ); void infoSystemFinished( QString target );
private: private:

View File

@@ -67,8 +67,8 @@ XMPPBot::XMPPBot(QObject *parent)
SLOT(newTrackSlot(const Tomahawk::result_ptr &))); SLOT(newTrackSlot(const Tomahawk::result_ptr &)));
connect(TomahawkApp::instance()->infoSystem(), connect(TomahawkApp::instance()->infoSystem(),
SIGNAL(info(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash)), SIGNAL(info(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData)),
SLOT(infoReturnedSlot(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomDataHash))); SLOT(infoReturnedSlot(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData)));
connect(TomahawkApp::instance()->infoSystem(), SIGNAL(finished(QString)), SLOT(infoFinishedSlot(QString))); connect(TomahawkApp::instance()->infoSystem(), SIGNAL(finished(QString)), SLOT(infoFinishedSlot(QString)));
@@ -215,10 +215,10 @@ void XMPPBot::handleMessage(const Message& msg, MessageSession* session)
infoMap[InfoArtistFamiliarity] = m_currTrack.data()->artist()->name(); infoMap[InfoArtistFamiliarity] = m_currTrack.data()->artist()->name();
if (token == "lyrics") if (token == "lyrics")
{ {
InfoCustomDataHash myhash; InfoCustomData myhash;
myhash["trackName"] = QVariant::fromValue<QString>(m_currTrack.data()->track()); myhash["trackName"] = QVariant::fromValue<QString>(m_currTrack.data()->track());
myhash["artistName"] = QVariant::fromValue<QString>(m_currTrack.data()->artist()->name()); myhash["artistName"] = QVariant::fromValue<QString>(m_currTrack.data()->artist()->name());
infoMap[InfoTrackLyrics] = QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomDataHash>(myhash); infoMap[InfoTrackLyrics] = QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>(myhash);
} }
} }
@@ -235,12 +235,12 @@ void XMPPBot::handleMessage(const Message& msg, MessageSession* session)
QString waitMsg("Please wait..."); QString waitMsg("Please wait...");
Message retMsg(Message::Chat, JID(originatingJid.toStdString()), waitMsg.toStdString()); Message retMsg(Message::Chat, JID(originatingJid.toStdString()), waitMsg.toStdString());
m_client.data()->send(retMsg); m_client.data()->send(retMsg);
Tomahawk::InfoSystem::InfoCustomDataHash hash; Tomahawk::InfoSystem::InfoCustomData hash;
hash["XMPPBotSendToJID"] = originatingJid; hash["XMPPBotSendToJID"] = originatingJid;
TomahawkApp::instance()->infoSystem()->getInfo(s_infoIdentifier, infoMap, hash); TomahawkApp::instance()->infoSystem()->getInfo(s_infoIdentifier, infoMap, hash);
} }
void XMPPBot::infoReturnedSlot(QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData) void XMPPBot::infoReturnedSlot(QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData)
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
@@ -364,13 +364,13 @@ void XMPPBot::infoReturnedSlot(QString caller, Tomahawk::InfoSystem::InfoType ty
{ {
qDebug() << "Lyrics requested"; qDebug() << "Lyrics requested";
if (!output.canConvert<QString>() || if (!output.canConvert<QString>() ||
!input.canConvert<Tomahawk::InfoSystem::InfoCustomDataHash>() !input.canConvert<Tomahawk::InfoSystem::InfoCustomData>()
) )
{ {
qDebug() << "Variants failed to be valid"; qDebug() << "Variants failed to be valid";
break; break;
} }
InfoCustomDataHash inHash = input.value<InfoCustomDataHash>(); InfoCustomData inHash = input.value<InfoCustomData>();
QString artist = inHash["artistName"].toString(); QString artist = inHash["artistName"].toString();
QString track = inHash["trackName"].toString(); QString track = inHash["trackName"].toString();
QString lyrics = output.toString(); QString lyrics = output.toString();

View File

@@ -66,7 +66,7 @@ public:
public slots: public slots:
virtual void newTrackSlot(const Tomahawk::result_ptr &track); virtual void newTrackSlot(const Tomahawk::result_ptr &track);
virtual void infoReturnedSlot(QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomDataHash customData); virtual void infoReturnedSlot(QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData);
virtual void infoFinishedSlot(QString caller); virtual void infoFinishedSlot(QString caller);
protected: protected: