1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

Massive cleanup of echonest plugin, also some cleanup for lastfmplugin. Hope I didn't break anything. :-)

This commit is contained in:
Jeff Mitchell
2011-06-28 09:00:16 -04:00
parent bb6da0daa9
commit 07d9360a65
9 changed files with 54 additions and 55 deletions

View File

@@ -147,7 +147,7 @@ AudioEngine::stop()
setCurrentTrack( Tomahawk::result_ptr() );
emit stopped();
Tomahawk::InfoSystem::InfoMap map;
Tomahawk::InfoSystem::InfoTypeMap map;
map[ Tomahawk::InfoSystem::InfoNowStopped ] = QVariant();
if ( m_waitingOnNewTrack )
@@ -319,7 +319,7 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( m_currentTrack, DatabaseCommand_LogPlayback::Started );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
Tomahawk::InfoSystem::InfoMap map;
Tomahawk::InfoSystem::InfoTypeMap map;
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
trackInfo["title"] = m_currentTrack->track();

View File

@@ -63,7 +63,6 @@ EchoNestPlugin::namChangedSlot( QNetworkAccessManager *nam )
newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() );
newProxyFactory->setProxy( oldProxyFactory->proxy() );
currNam->setProxyFactory( newProxyFactory );
m_nam = QWeakPointer< QNetworkAccessManager >( currNam );
}
void
@@ -116,10 +115,10 @@ EchoNestPlugin::getArtistBiography(const QString &caller, const QVariant &input,
Echonest::Artist artist( input.toString() );
QNetworkReply *reply = artist.fetchBiographies();
reply->setProperty("artist", QVariant::fromValue<Echonest::Artist>(artist));
reply->setProperty( "artist", QVariant::fromValue< Echonest::Artist >( artist ) );
reply->setProperty( "input", input );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
reply->setProperty( "customData", customData );
reply->setProperty( "caller", caller );
connect(reply, SIGNAL(finished()), SLOT(getArtistBiographySlot()));
}
@@ -134,8 +133,8 @@ EchoNestPlugin::getArtistFamiliarity(const QString &caller, const QVariant &inpu
QNetworkReply* reply = artist.fetchFamiliarity();
reply->setProperty( "artist", QVariant::fromValue<Echonest::Artist>(artist));
reply->setProperty( "input", input );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
reply->setProperty( "customData", customData );
reply->setProperty( "caller", caller );
connect(reply, SIGNAL(finished()), SLOT(getArtistFamiliaritySlot()));
}
@@ -149,8 +148,8 @@ EchoNestPlugin::getArtistHotttnesss(const QString &caller, const QVariant &input
QNetworkReply* reply = artist.fetchHotttnesss();
reply->setProperty( "artist", QVariant::fromValue<Echonest::Artist>(artist));
reply->setProperty( "input", input );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
reply->setProperty( "customData", customData );
reply->setProperty( "caller", caller );
connect(reply, SIGNAL(finished()), SLOT(getArtistHotttnesssSlot()));
}
@@ -164,9 +163,9 @@ EchoNestPlugin::getArtistTerms(const QString &caller, const QVariant &input, con
QNetworkReply* reply = artist.fetchTerms( Echonest::Artist::Weight );
reply->setProperty( "artist", QVariant::fromValue<Echonest::Artist>(artist));
reply->setProperty( "input", input );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
connect(reply, SIGNAL(finished()), SLOT(getArtistTermsSlot()));
reply->setProperty( "customData", customData );
reply->setProperty( "caller", caller );
connect(reply, SIGNAL( finished() ), SLOT( getArtistTermsSlot() ) );
}
void
@@ -174,9 +173,9 @@ EchoNestPlugin::getMiscTopTerms(const QString &caller, const QVariant &input, co
{
Q_UNUSED( input );
QNetworkReply* reply = Echonest::Artist::topTerms( 20 );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
connect( reply,SIGNAL(finished()), SLOT( getMiscTopSlot()));
reply->setProperty( "customData", customData );
reply->setProperty( "caller", caller );
connect( reply, SIGNAL( finished() ), SLOT( getMiscTopSlot() ) );
}
@@ -197,9 +196,11 @@ EchoNestPlugin::getArtistBiographySlot()
biographyMap[biography.site()]["attribution"] = biography.license().url.toString();
}
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);
emit info( reply->property( "caller" ).toString(),
Tomahawk::InfoSystem::InfoArtistBiography,
reply->property( "input" ),
QVariant::fromValue< Tomahawk::InfoSystem::InfoGenericMap >( biographyMap ),
reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >() );
reply->deleteLater();
}
@@ -209,9 +210,11 @@ 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( "input" ), familiarity, m_replyMap[reply] );
m_replyMap.remove(reply);
m_callerMap.remove(reply);
emit info( reply->property( "caller" ).toString(),
Tomahawk::InfoSystem::InfoArtistFamiliarity,
reply->property( "input" ),
familiarity,
reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >() );
reply->deleteLater();
}
@@ -221,9 +224,11 @@ 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( "input" ), hotttnesss, m_replyMap[reply] );
m_replyMap.remove(reply);
m_callerMap.remove(reply);
emit info( reply->property( "caller" ).toString(),
Tomahawk::InfoSystem::InfoArtistHotttness,
reply->property( "input" ),
hotttnesss,
reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >() );
reply->deleteLater();
}
@@ -240,9 +245,11 @@ EchoNestPlugin::getArtistTermsSlot()
termMap[ "frequency" ] = QString::number(term.frequency());
termsMap[ term.name() ] = termMap;
}
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);
emit info( reply->property( "caller" ).toString(),
Tomahawk::InfoSystem::InfoArtistTerms,
reply->property( "input" ),
QVariant::fromValue< Tomahawk::InfoSystem::InfoGenericMap >( termsMap ),
reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >() );
reply->deleteLater();
}
@@ -258,9 +265,11 @@ EchoNestPlugin::getMiscTopSlot()
termMap[ "frequency" ] = QString::number( term.frequency() );
termsMap[ term.name().toLower() ] = termMap;
}
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoMiscTopTerms, QVariant(), QVariant::fromValue<Tomahawk::InfoSystem::InfoGenericMap>(termsMap), m_replyMap[reply] );
m_replyMap.remove(reply);
m_callerMap.remove(reply);
emit info( reply->property( "caller" ).toString(),
Tomahawk::InfoSystem::InfoMiscTopTerms,
QVariant(),
QVariant::fromValue< Tomahawk::InfoSystem::InfoGenericMap >( termsMap ),
reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >() );
reply->deleteLater();
}

View File

@@ -83,11 +83,6 @@ private slots:
void getArtistHotttnesssSlot();
void getArtistTermsSlot();
void getMiscTopSlot();
private:
QHash< QNetworkReply*, InfoCustomData > m_replyMap;
QHash< QNetworkReply*, QString > m_callerMap;
QWeakPointer< QNetworkAccessManager > m_nam;
};
}

View File

@@ -115,9 +115,6 @@ LastFmPlugin::namChangedSlot( QNetworkAccessManager *nam )
currNam->setProxyFactory( newProxyFactory );
//FIXME: on Mac/Win as liblastfm's network access manager also sets its overriding application proxy
//may have to do a QNetworkProxy::setApplicationProxy and clobber our own factory to override it
m_nam = QWeakPointer< QNetworkAccessManager >( currNam );
settingsChanged(); // to get the scrobbler set up
}
@@ -309,7 +306,7 @@ LastFmPlugin::notInCacheSlot( const QHash<QString, QString> criteria, const QStr
{
qDebug() << Q_FUNC_INFO;
if ( m_nam.isNull() )
if ( !lastfm::nam() )
{
qDebug() << "Have a null QNAM, uh oh";
emit info( caller, type, input, QVariant(), customData );
@@ -325,7 +322,7 @@ LastFmPlugin::notInCacheSlot( const QHash<QString, QString> criteria, const QStr
QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=album.imageredirect&artist=%1&album=%2&autocorrect=1&size=large&api_key=7a90f6672a04b809ee309af169f34b8b";
QNetworkRequest req( imgurl.arg( artistName ).arg( albumName ) );
QNetworkReply* reply = m_nam.data()->get( req );
QNetworkReply* reply = lastfm::nam()->get( req );
reply->setProperty( "customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>( customData ) );
reply->setProperty( "origData", input );
reply->setProperty( "caller", caller );
@@ -341,7 +338,7 @@ LastFmPlugin::notInCacheSlot( const QHash<QString, QString> criteria, const QStr
QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=artist.imageredirect&artist=%1&autocorrect=1&size=medium&api_key=7a90f6672a04b809ee309af169f34b8b";
QNetworkRequest req( imgurl.arg( artistName ) );
QNetworkReply* reply = m_nam.data()->get( req );
QNetworkReply* reply = lastfm::nam()->get( req );
reply->setProperty( "customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>( customData ) );
reply->setProperty( "origData", input );
reply->setProperty( "caller", caller );
@@ -406,7 +403,7 @@ LastFmPlugin::coverArtReturned()
}
else
{
if ( m_nam.isNull() )
if ( !lastfm::nam() )
{
qDebug() << "Uh oh, nam is null";
InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt());
@@ -416,7 +413,7 @@ LastFmPlugin::coverArtReturned()
}
// Follow HTTP redirect
QNetworkRequest req( redir );
QNetworkReply* newReply = m_nam.data()->get( req );
QNetworkReply* newReply = lastfm::nam()->get( req );
newReply->setProperty( "origData", reply->property( "origData" ) );
newReply->setProperty( "customData", reply->property( "customData" ) );
newReply->setProperty( "caller", reply->property( "caller" ) );
@@ -465,7 +462,7 @@ LastFmPlugin::artistImagesReturned()
}
else
{
if ( m_nam.isNull() )
if ( !lastfm::nam() )
{
qDebug() << "Uh oh, nam is null";
InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt());
@@ -475,7 +472,7 @@ LastFmPlugin::artistImagesReturned()
}
// Follow HTTP redirect
QNetworkRequest req( redir );
QNetworkReply* newReply = m_nam.data()->get( req );
QNetworkReply* newReply = lastfm::nam()->get( req );
newReply->setProperty( "origData", reply->property( "origData" ) );
newReply->setProperty( "customData", reply->property( "customData" ) );
newReply->setProperty( "caller", reply->property( "caller" ) );

View File

@@ -74,8 +74,6 @@ private:
QString m_pw;
QList< QUrl > m_badUrls;
QWeakPointer< QNetworkAccessManager > m_nam;
};
}

View File

@@ -127,7 +127,7 @@ InfoSystem::getInfo( const QString &caller, const InfoType type, const QVariant&
void
InfoSystem::getInfo( const QString &caller, const InfoMap &input, InfoCustomData customData )
InfoSystem::getInfo( const QString &caller, const InfoTypeMap &input, InfoCustomData customData )
{
Q_FOREACH( InfoType type, input.keys() )
getInfo( caller, type, input[type], customData );
@@ -144,7 +144,7 @@ InfoSystem::pushInfo( const QString &caller, const InfoType type, const QVariant
void
InfoSystem::pushInfo( const QString &caller, const InfoMap &input )
InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input )
{
Q_FOREACH( InfoType type, input.keys() )
pushInfo( caller, type, input[type] );

View File

@@ -107,7 +107,7 @@ enum InfoType { // as items are saved in cache, mark them here to not change the
InfoNotifyUser = 55
};
typedef QMap< InfoType, QVariant > InfoMap;
typedef QMap< InfoType, QVariant > InfoTypeMap;
typedef QMap< QString, QMap< QString, QString > > InfoGenericMap;
typedef QHash< QString, QVariant > InfoCustomData;
typedef QHash< QString, QString > InfoCriteriaHash;
@@ -159,9 +159,9 @@ public:
~InfoSystem();
void getInfo( const QString &caller, const InfoType type, const QVariant &input, InfoCustomData customData );
void getInfo( const QString &caller, const InfoMap &input, InfoCustomData customData );
void getInfo( const QString &caller, const InfoTypeMap &input, InfoCustomData customData );
void pushInfo( const QString &caller, const InfoType type, const QVariant &input );
void pushInfo( const QString &caller, const InfoMap &input );
void pushInfo( const QString &caller, const InfoTypeMap &input );
signals:
void info( QString caller, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );

View File

@@ -201,7 +201,7 @@ void XMPPBot::handleMessage(const Message& msg, MessageSession* session)
return;
}
InfoMap infoMap;
InfoTypeMap infoMap;
Q_FOREACH(QString token, tokens)
{
if (token == "biography")

View File

@@ -87,7 +87,7 @@ private slots:
private:
QWeakPointer<XMPPBotClient> m_client;
Tomahawk::result_ptr m_currTrack;
Tomahawk::InfoSystem::InfoMap m_currInfoMap;
Tomahawk::InfoSystem::InfoTypeMap m_currInfoMap;
QString m_currReturnMessage;
QString m_currReturnJid;
};