1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 21:57:41 +02:00

Do our own attica download fetching since we send the tomahawk version as well

This commit is contained in:
Leo Franchi
2012-06-29 17:04:46 -04:00
parent d786f5c13b
commit 900b836b1e
2 changed files with 58 additions and 23 deletions

View File

@@ -31,6 +31,9 @@
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QDir> #include <QDir>
#include <QTimer> #include <QTimer>
#include <QDomDocument>
#include <QDomElement>
#include <QDomNode>
#include "utils/Logger.h" #include "utils/Logger.h"
#include "accounts/ResolverAccount.h" #include "accounts/ResolverAccount.h"
@@ -64,7 +67,7 @@ AtticaManager::AtticaManager( QObject* parent )
// resolvers // resolvers
// m_manager.addProviderFile( QUrl( "http://bakery.tomahawk-player.org/resolvers/providers.xml" ) ); // m_manager.addProviderFile( QUrl( "http://bakery.tomahawk-player.org/resolvers/providers.xml" ) );
const QString url = QString( "http://bakery.tomahawk-player.org/resolvers/providers.xml?version=%1" ).arg( TomahawkUtils::appFriendlyVersion() ); const QString url = QString( "%1/resolvers/providers.xml?version=%2" ).arg( hostname() ).arg( TomahawkUtils::appFriendlyVersion() );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) ); QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) );
NewClosure( reply, SIGNAL( finished() ), this, SLOT( providerFetched( QNetworkReply* ) ), reply ); NewClosure( reply, SIGNAL( finished() ), this, SLOT( providerFetched( QNetworkReply* ) ), reply );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( providerError( QNetworkReply::NetworkError ) ) ); connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( providerError( QNetworkReply::NetworkError ) ) );
@@ -90,6 +93,12 @@ AtticaManager::~AtticaManager()
} }
QString
AtticaManager::hostname() const
{
return "http://bakery.tomahawk-player.org";
}
void void
AtticaManager::loadPixmapsFromCache() AtticaManager::loadPixmapsFromCache()
{ {
@@ -523,14 +532,15 @@ void AtticaManager::doInstallResolver( const Content& resolver, bool autoCreate,
m_resolverStates[ resolver.id() ].version = resolver.version(); m_resolverStates[ resolver.id() ].version = resolver.version();
emit resolverStateChanged( resolver.id() ); emit resolverStateChanged( resolver.id() );
ItemJob< DownloadItem >* job = m_resolverProvider.downloadLink( resolver.id() ); // ItemJob< DownloadItem >* job = m_resolverProvider.downloadLink( resolver.id() );
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), this, SLOT( resolverDownloadFinished( Attica::BaseJob* ) ) ); QUrl url( QString( "%1/resolvers/v1/content/download/%2/1" ).arg( hostname() ).arg( resolver.id() ) );
job->setProperty( "resolverId", resolver.id() ); url.addQueryItem( "tomahawkversion", TomahawkUtils::appFriendlyVersion() );
job->setProperty( "createAccount", autoCreate ); QNetworkReply* r = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
job->setProperty( "handler", QVariant::fromValue< QObject* >( handler ) ); NewClosure( r, SIGNAL( finished() ), this, SLOT( resolverDownloadFinished( QNetworkReply* ) ), r );
job->setProperty( "binarySignature", resolver.attribute("signature")); r->setProperty( "resolverId", resolver.id() );
r->setProperty( "createAccount", autoCreate );
job->start(); r->setProperty( "handler", QVariant::fromValue< QObject* >( handler ) );
r->setProperty( "binarySignature", resolver.attribute("signature"));
} }
@@ -552,25 +562,49 @@ AtticaManager::upgradeResolver( const Content& resolver )
void void
AtticaManager::resolverDownloadFinished ( BaseJob* j ) AtticaManager::resolverDownloadFinished ( QNetworkReply *j )
{ {
ItemJob< DownloadItem >* job = static_cast< ItemJob< DownloadItem >* >( j ); Q_ASSERT( j );
if ( !j )
return;
if ( job->metadata().error() == Attica::Metadata::NoError ) if ( j->error() == QNetworkReply::NoError )
{ {
DownloadItem item = job->result(); QDomDocument doc;
QUrl url = item.url(); doc.setContent( j );
// download the resolver itself :)
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); const QDomNodeList nodes = doc.documentElement().elementsByTagName( "downloadlink" );
connect( reply, SIGNAL( finished() ), this, SLOT( payloadFetched() ) ); if ( nodes.length() < 1 )
reply->setProperty( "resolverId", job->property( "resolverId" ) ); {
reply->setProperty( "createAccount", job->property( "createAccount" ) ); tLog() << "Found no download link for resolver:" << doc.toString();
reply->setProperty( "handler", job->property( "handler" ) ); return;
reply->setProperty( "binarySignature", job->property( "binarySignature" ) ); }
QUrl url( nodes.item( 0 ).toElement().text() );
// download the resolver itself :)
tDebug() << "Downloading resolver from url:" << url.toString();
const QDomNodeList signatures = doc.documentElement().elementsByTagName( "signature" );
// Use the original signature provided
QString signature = j->property( "binarySignature" ).toString();
if ( signatures.size() > 0 )
{
// THis download has an overriding signature. Take that one instead
const QString sig = signatures.item( 0 ).toElement().text();
tLog() << "Found overridden signature in binary download:" << sig;
signature = sig;
}
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
connect( reply, SIGNAL( finished() ), this, SLOT( payloadFetched() ) );
reply->setProperty( "resolverId", j->property( "resolverId" ) );
reply->setProperty( "createAccount", j->property( "createAccount" ) );
reply->setProperty( "handler", j->property( "handler" ) );
reply->setProperty( "binarySignature", signature );
} }
else else
{ {
tLog() << "Failed to do resolver download job!" << job->metadata().error(); tLog() << "Failed to do resolver download job!" << j->errorString() << j->error();
} }
} }

View File

@@ -132,7 +132,7 @@ private slots:
void categoriesReturned( Attica::BaseJob* ); void categoriesReturned( Attica::BaseJob* );
void resolversList( Attica::BaseJob* ); void resolversList( Attica::BaseJob* );
void binaryResolversList( Attica::BaseJob* ); void binaryResolversList( Attica::BaseJob* );
void resolverDownloadFinished( Attica::BaseJob* ); void resolverDownloadFinished( QNetworkReply* );
void payloadFetched(); void payloadFetched();
void loadPixmapsFromCache(); void loadPixmapsFromCache();
@@ -144,6 +144,7 @@ private slots:
private: private:
void doResolverRemove( const QString& id ) const; void doResolverRemove( const QString& id ) const;
void doInstallResolver( const Attica::Content& resolver, bool autoCreate, Tomahawk::Accounts::AtticaResolverAccount* handler ); void doInstallResolver( const Attica::Content& resolver, bool autoCreate, Tomahawk::Accounts::AtticaResolverAccount* handler );
QString hostname() const;
Attica::ProviderManager m_manager; Attica::ProviderManager m_manager;