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

Download binary resolver listing

This commit is contained in:
Leo Franchi 2012-05-04 14:13:57 -04:00
parent b75a575f51
commit 7adb3fc737
4 changed files with 93 additions and 14 deletions

View File

@ -42,11 +42,13 @@ AtticaManager* AtticaManager::s_instance = 0;
AtticaManager::AtticaManager( QObject* parent )
: QObject( parent )
, m_resolverJobsLoaded( 0 )
{
connect( &m_manager, SIGNAL( providerAdded( Attica::Provider ) ), this, SLOT( providerAdded( Attica::Provider ) ) );
// 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" ) );
m_manager.addProviderFile( QUrl( "http://localhost/resolvers/providers.xml" ) );
qRegisterMetaType< Attica::Content >( "Attica::Content" );
}
@ -250,9 +252,32 @@ AtticaManager::providerAdded( const Provider& provider )
if ( provider.name() == "Tomahawk Resolvers" )
{
m_resolverProvider = provider;
m_resolvers.clear();
m_resolverStates = TomahawkSettingsGui::instanceGui()->atticaResolverStates();
ListJob<Category>* job = m_resolverProvider.requestCategories();
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), this, SLOT( categoriesReturned( Attica::BaseJob* ) ) );
job->start();
}
}
void
AtticaManager::categoriesReturned( BaseJob* j )
{
ListJob< Category >* job = static_cast< ListJob< Category >* >( j );
Category::List categories = job->itemList();
foreach ( const Category& category, categories )
{
ListJob< Content >* job = m_resolverProvider.searchContents( Category::List() << category, QString(), Provider::Downloads, 0, 50 );
if ( category.name() == "Resolver" )
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), this, SLOT( resolversList( Attica::BaseJob* ) ) );
else if ( category.name() == "BinaryResolver" )
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), this, SLOT( binaryResolversList( Attica::BaseJob* ) ) );
ListJob< Content >* job = m_resolverProvider.searchContents( Category::List(), QString(), Provider::Downloads, 0, 30 );
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), this, SLOT( resolversList( Attica::BaseJob* ) ) );
job->start();
}
}
@ -263,8 +288,7 @@ AtticaManager::resolversList( BaseJob* j )
{
ListJob< Content >* job = static_cast< ListJob< Content >* >( j );
m_resolvers = job->itemList();
m_resolverStates = TomahawkSettingsGui::instanceGui()->atticaResolverStates();
m_resolvers.append( job->itemList() );
// Sanity check. if any resolvers are installed that don't exist on the hd, remove them.
foreach ( const QString& rId, m_resolverStates.keys() )
@ -272,6 +296,9 @@ AtticaManager::resolversList( BaseJob* j )
if ( m_resolverStates[ rId ].state == Installed ||
m_resolverStates[ rId ].state == NeedsUpgrade )
{
if ( m_resolverStates[ rId ].binary )
continue;
// Guess location on disk
QDir dir( QString( "%1/atticaresolvers/%2" ).arg( TomahawkUtils::appDataDir().absolutePath() ).arg( rId ) );
if ( !dir.exists() )
@ -303,7 +330,49 @@ AtticaManager::resolversList( BaseJob* j )
syncServerData();
emit resolversLoaded( m_resolvers );
if ( ++m_resolverJobsLoaded == 2 )
emit resolversLoaded( m_resolvers );
}
void
AtticaManager::binaryResolversList( BaseJob* j )
{
ListJob< Content >* job = static_cast< ListJob< Content >* >( j );
Content::List binaryResolvers = job->itemList();
// NOTE: No binary support for linux distros
QString platform;
#ifdef Q_OS_MAC
platform = "osx";
#elif Q_OS_WIN
platform = "win";
#endif
// NOTE HACK
// At the moment we are going to assume that all binary resolvers also have an associated full-fledged Tomahawk Account
// like SpotifyAccount.
foreach ( const Content& c, binaryResolvers )
{
if ( !c.attribute( "typeid" ).isEmpty() && c.attribute( "typeid" ) == platform )
{
// We have a binary resolver for this platform
m_resolvers.append( c );
if ( !m_resolverStates.contains( c.id() ) )
{
Resolver r;
r.binary = true;
m_resolverStates.insert( c.id(), r );
}
}
}
if ( ++m_resolverJobsLoaded == 2 )
emit resolversLoaded( m_resolvers );
}

View File

@ -51,13 +51,14 @@ public:
int userRating; // 0-100
ResolverState state;
QPixmap* pixmap;
bool binary;
// internal
bool pixmapDirty;
Resolver( const QString& v, const QString& path, int userR, ResolverState s )
: version( v ), scriptPath( path ), userRating( userR ), state( s ), pixmap( 0 ), pixmapDirty( false ) {}
Resolver() : userRating( -1 ), state( Uninstalled ), pixmap( 0 ), pixmapDirty( false ) {}
Resolver( const QString& v, const QString& path, int userR, ResolverState s, bool resolver )
: version( v ), scriptPath( path ), userRating( userR ), state( s ), pixmap( 0 ), binary( false ), pixmapDirty( false ) {}
Resolver() : userRating( -1 ), state( Uninstalled ), pixmap( 0 ), binary( false ), pixmapDirty( false ) {}
};
typedef QHash< QString, AtticaManager::Resolver > StateHash;
@ -111,7 +112,9 @@ signals:
private slots:
void providerAdded( const Attica::Provider& );
void categoriesReturned( Attica::BaseJob* );
void resolversList( Attica::BaseJob* );
void binaryResolversList( Attica::BaseJob* );
void resolverDownloadFinished( Attica::BaseJob* );
void payloadFetched();
@ -131,6 +134,7 @@ private:
Attica::Content::List m_resolvers;
StateHash m_resolverStates;
int m_resolverJobsLoaded;
QMap< QString, Tomahawk::Accounts::Account* > m_customAccounts;
static AtticaManager* s_instance;

View File

@ -30,7 +30,7 @@
#include "DllMacro.h"
#define TOMAHAWK_SETTINGS_VERSION 10
#define TOMAHAWK_SETTINGS_VERSION 11
/**
* Convenience wrapper around QSettings for tomahawk-specific config

View File

@ -30,7 +30,7 @@ inline QDataStream& operator<<(QDataStream& out, const AtticaManager::StateHash&
foreach( const QString& key, states.keys() )
{
AtticaManager::Resolver resolver = states[ key ];
out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state << resolver.userRating;
out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state << resolver.userRating << resolver.binary;
}
return out;
}
@ -38,19 +38,25 @@ inline QDataStream& operator<<(QDataStream& out, const AtticaManager::StateHash&
inline QDataStream& operator>>(QDataStream& in, AtticaManager::StateHash& states)
{
quint32 count = 0, version = 0;
in >> version;
quint32 count = 0, configVersion = 0;
in >> configVersion;
in >> count;
for ( uint i = 0; i < count; i++ )
{
QString key, version, scriptPath;
qint32 state, userRating;
bool binary = false;
in >> key;
in >> version;
in >> scriptPath;
in >> state;
in >> userRating;
states[ key ] = AtticaManager::Resolver( version, scriptPath, userRating, (AtticaManager::ResolverState)state );
if ( configVersion > 10 )
{
// V11 includes 'bool binary' flag
in >> binary;
}
states[ key ] = AtticaManager::Resolver( version, scriptPath, userRating, (AtticaManager::ResolverState)state, binary );
}
return in;
}