1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-19 04:11:46 +02:00

Rename some values and make slots and other functions use const values,

for sanity checking
This commit is contained in:
Jeff Mitchell
2011-04-19 16:36:01 -04:00
parent edaabc0ae6
commit 248e3e7a4a
10 changed files with 155 additions and 131 deletions

View File

@@ -39,22 +39,23 @@ EchoNestPlugin::~EchoNestPlugin()
qDebug() << Q_FUNC_INFO;
}
void EchoNestPlugin::getInfo(const QString &caller, const InfoType type, const QVariant& data, InfoCustomData customData)
void
EchoNestPlugin::getInfo(const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData)
{
switch (type)
{
case Tomahawk::InfoSystem::InfoArtistBiography:
return getArtistBiography(caller, data, customData);
return getArtistBiography(caller, input, customData);
case Tomahawk::InfoSystem::InfoArtistFamiliarity:
return getArtistFamiliarity(caller, data, customData);
return getArtistFamiliarity(caller, input, customData);
case Tomahawk::InfoSystem::InfoArtistHotttness:
return getArtistHotttnesss(caller, data, customData);
return getArtistHotttnesss(caller, input, customData);
case Tomahawk::InfoSystem::InfoArtistTerms:
return getArtistTerms(caller, data, customData);
return getArtistTerms(caller, input, customData);
case Tomahawk::InfoSystem::InfoTrackEnergy:
return getSongProfile(caller, data, customData, "energy");
return getSongProfile(caller, input, customData, "energy");
case Tomahawk::InfoSystem::InfoMiscTopTerms:
return getMiscTopTerms(caller, data, customData);
return getMiscTopTerms(caller, input, customData);
default:
{
emit info(caller, Tomahawk::InfoSystem::InfoNoInfo, QVariant(), QVariant(), customData);
@@ -63,82 +64,88 @@ void EchoNestPlugin::getInfo(const QString &caller, const InfoType type, const Q
}
}
void EchoNestPlugin::getSongProfile(const QString &caller, const QVariant& data, InfoCustomData &customData, const QString &item)
void
EchoNestPlugin::getSongProfile(const QString &caller, const QVariant &input, const InfoCustomData &customData, const QString &item)
{
//WARNING: Totally not implemented yet
Q_UNUSED( item );
if( !isValidTrackData( caller, data, customData ) )
if( !isValidTrackData( caller, input, customData ) )
return;
// Track track( data.toString() );
// Artist artist( customData.data()->property("artistName").toString() );
// Track track( input.toString() );
// Artist artist( customData.input()->property("artistName").toString() );
// reply->setProperty("artist", QVariant::fromValue<Artist>(artist));
// reply->setProperty( "data", data );
// reply->setProperty( "input", input );
// m_replyMap[reply] = customData;
// connect(reply, SIGNAL(finished()), SLOT(getArtistBiographySlot()));
}
void EchoNestPlugin::getArtistBiography(const QString &caller, const QVariant& data, InfoCustomData &customData)
void
EchoNestPlugin::getArtistBiography(const QString &caller, const QVariant &input, const InfoCustomData &customData)
{
if( !isValidArtistData( caller, data, customData ) )
if( !isValidArtistData( caller, input, customData ) )
return;
Echonest::Artist artist( data.toString() );
Echonest::Artist artist( input.toString() );
QNetworkReply *reply = artist.fetchBiographies();
reply->setProperty("artist", QVariant::fromValue<Echonest::Artist>(artist));
reply->setProperty( "data", data );
reply->setProperty( "input", input );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
connect(reply, SIGNAL(finished()), SLOT(getArtistBiographySlot()));
}
void EchoNestPlugin::getArtistFamiliarity(const QString &caller, const QVariant& data, InfoCustomData &customData)
void
EchoNestPlugin::getArtistFamiliarity(const QString &caller, const QVariant &input, const InfoCustomData &customData)
{
if( !isValidArtistData( caller, data, customData ) )
if( !isValidArtistData( caller, input, customData ) )
return;
qDebug() << "Fetching artist familiarity!" << data;
Echonest::Artist artist( data.toString() );
qDebug() << "Fetching artist familiarity!" << input;
Echonest::Artist artist( input.toString() );
QNetworkReply* reply = artist.fetchFamiliarity();
reply->setProperty( "artist", QVariant::fromValue<Echonest::Artist>(artist));
reply->setProperty( "data", data );
reply->setProperty( "input", input );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
connect(reply, SIGNAL(finished()), SLOT(getArtistFamiliaritySlot()));
}
void EchoNestPlugin::getArtistHotttnesss(const QString &caller, const QVariant& data, InfoCustomData &customData)
void
EchoNestPlugin::getArtistHotttnesss(const QString &caller, const QVariant &input, const InfoCustomData &customData)
{
if( !isValidArtistData( caller, data, customData ) )
if( !isValidArtistData( caller, input, customData ) )
return;
Echonest::Artist artist( data.toString() );
Echonest::Artist artist( input.toString() );
QNetworkReply* reply = artist.fetchHotttnesss();
reply->setProperty( "artist", QVariant::fromValue<Echonest::Artist>(artist));
reply->setProperty( "data", data );
reply->setProperty( "input", input );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
connect(reply, SIGNAL(finished()), SLOT(getArtistHotttnesssSlot()));
}
void EchoNestPlugin::getArtistTerms(const QString &caller, const QVariant& data, InfoCustomData &customData)
void
EchoNestPlugin::getArtistTerms(const QString &caller, const QVariant &input, const InfoCustomData &customData)
{
if( !isValidArtistData( caller, data, customData ) )
if( !isValidArtistData( caller, input, customData ) )
return;
Echonest::Artist artist( data.toString() );
Echonest::Artist artist( input.toString() );
QNetworkReply* reply = artist.fetchTerms( Echonest::Artist::Weight );
reply->setProperty( "artist", QVariant::fromValue<Echonest::Artist>(artist));
reply->setProperty( "data", data );
reply->setProperty( "input", input );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
connect(reply, SIGNAL(finished()), SLOT(getArtistTermsSlot()));
}
void EchoNestPlugin::getMiscTopTerms(const QString &caller, const QVariant& data, InfoCustomData& customData)
void
EchoNestPlugin::getMiscTopTerms(const QString &caller, const QVariant &input, const InfoCustomData& customData)
{
Q_UNUSED( data );
Q_UNUSED( input );
QNetworkReply* reply = Echonest::Artist::topTerms( 20 );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
@@ -146,7 +153,8 @@ void EchoNestPlugin::getMiscTopTerms(const QString &caller, const QVariant& data
}
void EchoNestPlugin::getArtistBiographySlot()
void
EchoNestPlugin::getArtistBiographySlot()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
Echonest::Artist artist = artistFromReply( reply );
@@ -162,35 +170,38 @@ void EchoNestPlugin::getArtistBiographySlot()
biographyMap[biography.site()]["attribution"] = biography.license().url.toString();
}
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistBiography, reply->property( "data" ), QVariant::fromValue<Tomahawk::InfoSystem::InfoGenericMap>(biographyMap), m_replyMap[reply] );
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistBiography, reply->property( "input" ), QVariant::fromValue<Tomahawk::InfoSystem::InfoGenericMap>(biographyMap), m_replyMap[reply] );
m_replyMap.remove(reply);
m_callerMap.remove(reply);
reply->deleteLater();
}
void EchoNestPlugin::getArtistFamiliaritySlot()
void
EchoNestPlugin::getArtistFamiliaritySlot()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
Echonest::Artist artist = artistFromReply( reply );
qreal familiarity = artist.familiarity();
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistFamiliarity, reply->property( "data" ), familiarity, m_replyMap[reply] );
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistFamiliarity, reply->property( "input" ), familiarity, m_replyMap[reply] );
m_replyMap.remove(reply);
m_callerMap.remove(reply);
reply->deleteLater();
}
void EchoNestPlugin::getArtistHotttnesssSlot()
void
EchoNestPlugin::getArtistHotttnesssSlot()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
Echonest::Artist artist = artistFromReply( reply );
qreal hotttnesss = artist.hotttnesss();
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistHotttness, reply->property( "data" ), hotttnesss, m_replyMap[reply] );
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistHotttness, reply->property( "input" ), hotttnesss, m_replyMap[reply] );
m_replyMap.remove(reply);
m_callerMap.remove(reply);
reply->deleteLater();
}
void EchoNestPlugin::getArtistTermsSlot()
void
EchoNestPlugin::getArtistTermsSlot()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
Echonest::Artist artist = artistFromReply( reply );
@@ -202,13 +213,14 @@ void EchoNestPlugin::getArtistTermsSlot()
termMap[ "frequency" ] = QString::number(term.frequency());
termsMap[ term.name() ] = termMap;
}
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistTerms, reply->property( "data" ), QVariant::fromValue<Tomahawk::InfoSystem::InfoGenericMap>(termsMap), m_replyMap[reply] );
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistTerms, reply->property( "input" ), QVariant::fromValue<Tomahawk::InfoSystem::InfoGenericMap>(termsMap), m_replyMap[reply] );
m_replyMap.remove(reply);
m_callerMap.remove(reply);
reply->deleteLater();
}
void EchoNestPlugin::getMiscTopSlot()
void
EchoNestPlugin::getMiscTopSlot()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
TermList terms = Echonest::Artist::parseTopTerms( reply );
@@ -225,14 +237,15 @@ void EchoNestPlugin::getMiscTopSlot()
reply->deleteLater();
}
bool EchoNestPlugin::isValidArtistData(const QString &caller, const QVariant& data, InfoCustomData &customData)
bool
EchoNestPlugin::isValidArtistData(const QString &caller, const QVariant &input, const InfoCustomData &customData)
{
if (data.isNull() || !data.isValid() || !data.canConvert<QString>())
if (input.isNull() || !input.isValid() || !input.canConvert<QString>())
{
emit info(caller, Tomahawk::InfoSystem::InfoNoInfo, QVariant(), QVariant(), customData);
return false;
}
QString artistName = data.toString();
QString artistName = input.toString();
if (artistName.isEmpty() )
{
emit info(caller, Tomahawk::InfoSystem::InfoNoInfo, QVariant(), QVariant(), customData);
@@ -241,14 +254,15 @@ bool EchoNestPlugin::isValidArtistData(const QString &caller, const QVariant& da
return true;
}
bool EchoNestPlugin::isValidTrackData(const QString &caller, const QVariant& data, InfoCustomData &customData)
bool
EchoNestPlugin::isValidTrackData(const QString &caller, const QVariant &input, const InfoCustomData &customData)
{
if (data.isNull() || !data.isValid() || !data.canConvert<QString>())
if (input.isNull() || !input.isValid() || !input.canConvert<QString>())
{
emit info(caller, Tomahawk::InfoSystem::InfoNoInfo, QVariant(), QVariant(), customData);
return false;
}
QString trackName = data.toString();
QString trackName = input.toString();
if (trackName.isEmpty() )
{
emit info(caller, Tomahawk::InfoSystem::InfoNoInfo, QVariant(), QVariant(), customData);
@@ -260,7 +274,8 @@ bool EchoNestPlugin::isValidTrackData(const QString &caller, const QVariant& dat
return true;
}
Artist EchoNestPlugin::artistFromReply(QNetworkReply* reply)
Artist
EchoNestPlugin::artistFromReply(QNetworkReply* reply)
{
Echonest::Artist artist = reply->property("artist").value<Echonest::Artist>();
try {

View File

@@ -42,18 +42,19 @@ public:
EchoNestPlugin(QObject *parent);
virtual ~EchoNestPlugin();
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData );
protected slots:
virtual void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData );
private:
void getSongProfile( const QString &caller, const QVariant &data, InfoCustomData &customData, const QString &item = QString() );
void getArtistBiography ( const QString &caller, const QVariant &data, InfoCustomData &customData );
void getArtistFamiliarity( const QString &caller, const QVariant &data, InfoCustomData &customData );
void getArtistHotttnesss( const QString &caller, const QVariant &data, InfoCustomData &customData );
void getArtistTerms( const QString &caller, const QVariant &data, InfoCustomData &customData );
void getMiscTopTerms( const QString &caller, const QVariant &data, InfoCustomData &customData );
void getSongProfile( const QString &caller, const QVariant &input, const InfoCustomData &customData, const QString &item = QString() );
void getArtistBiography ( const QString &caller, const QVariant &input, const InfoCustomData &customData );
void getArtistFamiliarity( const QString &caller, const QVariant &input, const InfoCustomData &customData );
void getArtistHotttnesss( const QString &caller, const QVariant &input, const InfoCustomData &customData );
void getArtistTerms( const QString &caller, const QVariant &input, const InfoCustomData &customData );
void getMiscTopTerms( const QString &caller, const QVariant &input, const InfoCustomData &customData );
bool isValidArtistData( const QString &caller, const QVariant& data, InfoCustomData& customData );
bool isValidTrackData( const QString &caller, const QVariant& data, InfoCustomData& customData );
bool isValidArtistData( const QString &caller, const QVariant &input, const InfoCustomData& customData );
bool isValidTrackData( const QString &caller, const QVariant &input, const InfoCustomData& customData );
Echonest::Artist artistFromReply( QNetworkReply* );
private slots:

View File

@@ -95,54 +95,54 @@ LastFmPlugin::~LastFmPlugin()
void
LastFmPlugin::dataError( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData )
LastFmPlugin::dataError( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData )
{
emit info( caller, type, data, QVariant(), customData );
emit info( caller, type, input, QVariant(), customData );
return;
}
void
LastFmPlugin::getInfo( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData customData )
LastFmPlugin::getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData )
{
qDebug() << Q_FUNC_INFO;
switch ( type )
{
case InfoMiscSubmitNowPlaying:
nowPlaying( caller, type, data, customData );
nowPlaying( caller, type, input, customData );
break;
case InfoMiscSubmitScrobble:
scrobble( caller, type, data, customData );
scrobble( caller, type, input, customData );
break;
case InfoArtistImages:
fetchArtistImages( caller, type, data, customData );
fetchArtistImages( caller, type, input, customData );
break;
case InfoAlbumCoverArt:
fetchCoverArt( caller, type, data, customData );
fetchCoverArt( caller, type, input, customData );
break;
default:
dataError( caller, type, data, customData );
dataError( caller, type, input, customData );
}
}
void
LastFmPlugin::nowPlaying( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData )
LastFmPlugin::nowPlaying( const QString &caller, const InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData )
{
if ( !data.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() || !m_scrobbler )
if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() || !m_scrobbler )
{
dataError( caller, type, data, customData );
dataError( caller, type, input, customData );
return;
}
InfoCriteriaHash hash = data.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
InfoCriteriaHash hash = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) || !hash.contains( "duration" ) )
{
dataError( caller, type, data, customData );
dataError( caller, type, input, customData );
return;
}
@@ -157,18 +157,18 @@ LastFmPlugin::nowPlaying( const QString &caller, const InfoType type, const QVar
m_track.setSource( lastfm::Track::Player );
m_scrobbler->nowPlaying( m_track );
emit info( caller, type, data, QVariant(), customData );
emit info( caller, type, input, QVariant(), customData );
}
void
LastFmPlugin::scrobble( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData )
LastFmPlugin::scrobble( const QString &caller, const InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData )
{
Q_ASSERT( QThread::currentThread() == thread() );
if ( !m_scrobbler || m_track.isNull() )
{
dataError( caller, type, data, customData );
dataError( caller, type, input, customData );
return;
}
@@ -176,23 +176,23 @@ LastFmPlugin::scrobble( const QString &caller, const InfoType type, const QVaria
m_scrobbler->cache( m_track );
m_scrobbler->submit();
emit info( caller, type, data, QVariant(), customData );
emit info( caller, type, input, QVariant(), customData );
}
void
LastFmPlugin::fetchCoverArt( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData )
LastFmPlugin::fetchCoverArt( const QString &caller, const InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData )
{
qDebug() << Q_FUNC_INFO;
if ( !data.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
{
dataError( caller, type, data, customData );
dataError( caller, type, input, customData );
return;
}
InfoCriteriaHash hash = data.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
InfoCriteriaHash hash = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
if ( !hash.contains( "artist" ) || !hash.contains( "album" ) )
{
dataError( caller, type, data, customData );
dataError( caller, type, input, customData );
return;
}
@@ -200,35 +200,35 @@ LastFmPlugin::fetchCoverArt( const QString &caller, const InfoType type, const Q
criteria["artist"] = hash["artist"];
criteria["album"] = hash["album"];
emit getCachedInfo( criteria, 2419200000, caller, type, data, customData );
emit getCachedInfo( criteria, 2419200000, caller, type, input, customData );
}
void
LastFmPlugin::fetchArtistImages( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData )
LastFmPlugin::fetchArtistImages( const QString &caller, const InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData )
{
qDebug() << Q_FUNC_INFO;
if ( !data.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
{
dataError( caller, type, data, customData );
dataError( caller, type, input, customData );
return;
}
InfoCriteriaHash hash = data.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
InfoCriteriaHash hash = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
if ( !hash.contains( "artist" ) )
{
dataError( caller, type, data, customData );
dataError( caller, type, input, customData );
return;
}
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
criteria["artist"] = hash["artist"];
emit getCachedInfo( criteria, 2419200000, caller, type, data, customData );
emit getCachedInfo( criteria, 2419200000, caller, type, input, customData );
}
void
LastFmPlugin::notInCacheSlot( QHash<QString, QString> criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
LastFmPlugin::notInCacheSlot( const QHash<QString, QString> criteria, const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData )
{
qDebug() << Q_FUNC_INFO;

View File

@@ -43,8 +43,6 @@ public:
LastFmPlugin( QObject *parent );
virtual ~LastFmPlugin();
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData );
public slots:
void settingsChanged();
@@ -52,17 +50,19 @@ public slots:
void coverArtReturned();
void artistImagesReturned();
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
protected slots:
virtual void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData );
virtual void notInCacheSlot( const Tomahawk::InfoSystem::InfoCriteriaHash criteria, const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData );
private:
void fetchCoverArt( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData );
void fetchArtistImages( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData );
void fetchCoverArt( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData );
void fetchArtistImages( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData );
void createScrobbler();
void scrobble( const QString &caller, const InfoType type, const QVariant& data, InfoCustomData &customData );
void nowPlaying( const QString &caller, const InfoType type, const QVariant& data, InfoCustomData &customData );
void scrobble( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData );
void nowPlaying( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData );
void dataError( const QString &caller, const InfoType type, const QVariant& data, InfoCustomData &customData );
void dataError( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData );
lastfm::MutableTrack m_track;
lastfm::Audioscrobbler* m_scrobbler;

View File

@@ -42,17 +42,18 @@ MusixMatchPlugin::~MusixMatchPlugin()
qDebug() << Q_FUNC_INFO;
}
void MusixMatchPlugin::getInfo(const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData customData)
void
MusixMatchPlugin::getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData )
{
qDebug() << Q_FUNC_INFO;
if( !isValidTrackData(caller, data, customData) || !data.canConvert<Tomahawk::InfoSystem::InfoCustomData>())
if( !isValidTrackData(caller, input, customData) || !input.canConvert<Tomahawk::InfoSystem::InfoCustomData>())
return;
Tomahawk::InfoSystem::InfoCustomData hash = data.value<Tomahawk::InfoSystem::InfoCustomData>();
Tomahawk::InfoSystem::InfoCustomData hash = input.value<Tomahawk::InfoSystem::InfoCustomData>();
QString artist = hash["artistName"].toString();
QString track = hash["trackName"].toString();
if( artist.isEmpty() || track.isEmpty() )
{
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData);
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, input, QVariant(), customData);
return;
}
qDebug() << "artist is " << artist << ", track is " << track;
@@ -63,38 +64,40 @@ void MusixMatchPlugin::getInfo(const QString &caller, const InfoType type, const
url.addQueryItem("q_track", track);
QNetworkReply* reply = TomahawkUtils::nam()->get(QNetworkRequest(url));
reply->setProperty("customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>(customData));
reply->setProperty("origData", data);
reply->setProperty("origData", input);
reply->setProperty("caller", caller);
connect(reply, SIGNAL(finished()), SLOT(trackSearchSlot()));
}
bool MusixMatchPlugin::isValidTrackData(const QString &caller, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData)
bool
MusixMatchPlugin::isValidTrackData( const QString &caller, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData )
{
qDebug() << Q_FUNC_INFO;
if (data.isNull() || !data.isValid() || !data.canConvert<Tomahawk::InfoSystem::InfoCustomData>())
if (input.isNull() || !input.isValid() || !input.canConvert<Tomahawk::InfoSystem::InfoCustomData>())
{
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData);
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, input, QVariant(), customData);
qDebug() << "MusixMatchPlugin::isValidTrackData: Data null, invalid, or can't convert";
return false;
}
InfoCustomData hash = data.value<Tomahawk::InfoSystem::InfoCustomData>();
InfoCustomData hash = input.value<Tomahawk::InfoSystem::InfoCustomData>();
if (hash["trackName"].toString().isEmpty() )
{
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData);
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, input, QVariant(), customData);
qDebug() << "MusixMatchPlugin::isValidTrackData: Track name is empty";
return false;
}
if (hash["artistName"].toString().isEmpty() )
{
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData);
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, input, QVariant(), customData);
qDebug() << "MusixMatchPlugin::isValidTrackData: No artist name found";
return false;
}
return true;
}
void MusixMatchPlugin::trackSearchSlot()
void
MusixMatchPlugin::trackSearchSlot()
{
qDebug() << Q_FUNC_INFO;
QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
@@ -124,7 +127,8 @@ void MusixMatchPlugin::trackSearchSlot()
connect(newReply, SIGNAL(finished()), SLOT(trackLyricsSlot()));
}
void MusixMatchPlugin::trackLyricsSlot()
void
MusixMatchPlugin::trackLyricsSlot()
{
qDebug() << Q_FUNC_INFO;
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );

View File

@@ -34,19 +34,19 @@ class MusixMatchPlugin : public InfoPlugin
Q_OBJECT
public:
MusixMatchPlugin(QObject *parent);
MusixMatchPlugin( QObject *parent );
virtual ~MusixMatchPlugin();
void getInfo(const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData);
private:
bool isValidTrackData( const QString &caller, const QVariant& data, InfoCustomData &customData );
public slots:
void trackSearchSlot();
void trackLyricsSlot();
protected slots:
virtual void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData );
private:
bool isValidTrackData( const QString &caller, const QVariant &input, const InfoCustomData &customData );
QString m_apiKey;
};

View File

@@ -148,7 +148,7 @@ QLinkedList< InfoPluginPtr > InfoSystem::determineOrderedMatches(const InfoType
return providers;
}
void InfoSystem::getInfo(const QString &caller, const InfoType type, const QVariant& data, InfoCustomData customData)
void InfoSystem::getInfo(const QString &caller, const InfoType type, const QVariant& input, InfoCustomData customData)
{
qDebug() << Q_FUNC_INFO;
QLinkedList< InfoPluginPtr > providers = determineOrderedMatches(type);
@@ -169,7 +169,7 @@ void InfoSystem::getInfo(const QString &caller, const InfoType type, const QVari
m_dataTracker[caller][type] = m_dataTracker[caller][type] + 1;
qDebug() << "current count in dataTracker for type" << type << "is" << m_dataTracker[caller][type];
ptr.data()->getInfo(caller, type, data, customData);
QMetaObject::invokeMethod( ptr.data(), "getInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ), Q_ARG( Tomahawk::InfoSystem::InfoCustomData, customData ) );
}
void InfoSystem::getInfo(const QString &caller, const InfoMap &input, InfoCustomData customData)

View File

@@ -111,17 +111,17 @@ public:
qDebug() << Q_FUNC_INFO;
}
virtual void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData ) = 0;
signals:
void getCachedInfo( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
void updateCache( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64, 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 );
public slots:
protected slots:
virtual void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant data, const Tomahawk::InfoSystem::InfoCustomData customData ) = 0;
//FIXME: Make pure virtual when everything supports it
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
virtual void notInCacheSlot( const Tomahawk::InfoSystem::InfoCriteriaHash criteria, const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData )
{
Q_UNUSED( criteria );
Q_UNUSED( caller );
@@ -132,6 +132,10 @@ public slots:
protected:
InfoType m_type;
private:
friend class InfoSystem;
friend class InfoSystemCache;
};
typedef QWeakPointer< InfoPlugin > InfoPluginPtr;
@@ -148,7 +152,7 @@ public:
void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &types );
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData );
void getInfo( const QString &caller, const InfoType type, const QVariant &input, InfoCustomData customData );
void getInfo( const QString &caller, const InfoMap &input, InfoCustomData customData );
InfoSystemCache* getCache() { return m_cache; }
@@ -158,7 +162,7 @@ signals:
void finished( QString target );
public slots:
void infoSlot( QString target, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void infoSlot( const QString target, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const QVariant output, const Tomahawk::InfoSystem::InfoCustomData customData );
private:
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;

View File

@@ -98,7 +98,7 @@ InfoSystemCache::syncTimerFired()
void
InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
InfoSystemCache::getCachedInfoSlot( const Tomahawk::InfoSystem::InfoCriteriaHash criteria, const qint64 newMaxAge, const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData )
{
qDebug() << Q_FUNC_INFO;
if ( !m_dataCache.contains( type ) || !m_dataCache[type].contains( criteria ) )
@@ -110,7 +110,7 @@ InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCriteriaHash crite
if ( m_cacheRemainingToLoad > 0 )
{
qDebug() << "Cache not fully loaded, punting request for a bit";
QMetaObject::invokeMethod( this, "getCachedInfoSlot", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoCriteriaHash, criteria ), Q_ARG( qint64, newMaxAge ), Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( Tomahawk::InfoSystem::InfoCustomData, customData ) );
QMetaObject::invokeMethod( this, "getCachedInfoSlot", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoCriteriaHash, criteria ), Q_ARG( qint64, newMaxAge ), Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ), Q_ARG( Tomahawk::InfoSystem::InfoCustomData, customData ) );
return;
}
@@ -143,7 +143,7 @@ InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCriteriaHash crite
void
InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output )
InfoSystemCache::updateCacheSlot( const Tomahawk::InfoSystem::InfoCriteriaHash criteria, const qint64 maxAge, const Tomahawk::InfoSystem::InfoType type, const QVariant output )
{
qDebug() << Q_FUNC_INFO;
QHash< InfoCriteriaHash, QVariant > typedatacache = m_dataCache[type];
@@ -160,7 +160,7 @@ InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteri
void
InfoSystemCache::loadCache( Tomahawk::InfoSystem::InfoType type, const QString &cacheDir )
InfoSystemCache::loadCache( const Tomahawk::InfoSystem::InfoType type, const QString cacheDir )
{
qDebug() << Q_FUNC_INFO;
@@ -210,7 +210,7 @@ InfoSystemCache::loadCache( Tomahawk::InfoSystem::InfoType type, const QString &
void
InfoSystemCache::saveCache( Tomahawk::InfoSystem::InfoType type, const QString &cacheDir )
InfoSystemCache::saveCache( const Tomahawk::InfoSystem::InfoType type, const QString cacheDir )
{
qDebug() << Q_FUNC_INFO;
QDir dir( cacheDir );

View File

@@ -46,13 +46,13 @@ signals:
void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
public slots:
void getCachedInfoSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
void updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output );
void getCachedInfoSlot( const Tomahawk::InfoSystem::InfoCriteriaHash criteria, const qint64 newMaxAge, const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData );
void updateCacheSlot( const Tomahawk::InfoSystem::InfoCriteriaHash criteria, const qint64 maxAge, const Tomahawk::InfoSystem::InfoType type, const QVariant output );
private slots:
void syncTimerFired();
void loadCache( Tomahawk::InfoSystem::InfoType type, const QString &cacheDir );
void saveCache( Tomahawk::InfoSystem::InfoType type, const QString &cacheDir );
void loadCache( const Tomahawk::InfoSystem::InfoType type, const QString cacheDir );
void saveCache( const Tomahawk::InfoSystem::InfoType type, const QString cacheDir );
private:
QHash< InfoType, QHash< InfoCriteriaHash, QVariant > > m_dataCache;