mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-25 02:09:48 +01:00
Support resolver icons
This commit is contained in:
parent
dbb9d14deb
commit
d2bd6b8744
@ -41,8 +41,58 @@ AtticaManager::AtticaManager( QObject* parent )
|
||||
|
||||
// resolvers
|
||||
m_manager.addProviderFile( QUrl( "http://bakery.tomahawk-player.org:10480/resolvers/providers.xml" ) );
|
||||
QTimer::singleShot( 0, this, SLOT( loadPixmapsFromCache() ) );
|
||||
}
|
||||
|
||||
AtticaManager::~AtticaManager()
|
||||
{
|
||||
savePixmapsToCache();
|
||||
}
|
||||
|
||||
void
|
||||
AtticaManager::loadPixmapsFromCache()
|
||||
{
|
||||
QDir cacheDir = TomahawkUtils::appDataDir();
|
||||
if ( !cacheDir.cd( "atticacache" ) ) // doesn't exist, no cache
|
||||
return;
|
||||
|
||||
foreach ( const QString& file, cacheDir.entryList( QStringList() << "*.png", QDir::Files | QDir::NoSymLinks ) )
|
||||
{
|
||||
// load all the pixmaps
|
||||
QFileInfo info( file );
|
||||
QPixmap icon( cacheDir.absoluteFilePath( file ) );
|
||||
m_resolversIconCache[ info.baseName() ] = icon;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AtticaManager::savePixmapsToCache()
|
||||
{
|
||||
QDir cacheDir = TomahawkUtils::appDataDir();
|
||||
if ( !cacheDir.cd( "atticacache" ) ) // doesn't exist, create
|
||||
{
|
||||
cacheDir.mkdir( "atticacache" );
|
||||
cacheDir.cd( "atticache" );
|
||||
}
|
||||
|
||||
foreach( const QString& id, m_resolversIconCache.keys() )
|
||||
{
|
||||
const QString filename = cacheDir.absoluteFilePath( QString( "%1.png" ).arg( id ) );
|
||||
if ( !m_resolversIconCache[ id ].save( filename ) )
|
||||
{
|
||||
tLog() << "Failed to open cache file for writing:" << filename;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap
|
||||
AtticaManager::iconForResolver( const Content& resolver )
|
||||
{
|
||||
return m_resolversIconCache.value( resolver.id(), QPixmap() );
|
||||
}
|
||||
|
||||
|
||||
Content::List
|
||||
AtticaManager::resolvers() const
|
||||
{
|
||||
@ -99,8 +149,41 @@ AtticaManager::resolversList( BaseJob* j )
|
||||
|
||||
m_resolvers = job->itemList();
|
||||
m_resolverStates = TomahawkSettings::instance()->atticaResolverStates();
|
||||
|
||||
// load icon cache from disk, and fetch any we are missing
|
||||
foreach ( Content resolver, m_resolvers )
|
||||
{
|
||||
if ( !m_resolversIconCache.contains( resolver.id() ) && !resolver.icons().isEmpty() )
|
||||
{
|
||||
QNetworkReply* fetch = TomahawkUtils::nam()->get( QNetworkRequest( resolver.icons().first().url() ) );
|
||||
fetch->setProperty( "resolverId", resolver.id() );
|
||||
|
||||
connect( fetch, SIGNAL( finished() ), this, SLOT( resolverIconFetched() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AtticaManager::resolverIconFetched()
|
||||
{
|
||||
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
|
||||
Q_ASSERT( reply );
|
||||
|
||||
const QString resolverId = reply->property( "resolverId" ).toString();
|
||||
|
||||
if ( !reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
tLog() << "Failed to fetch resolver icon image:" << reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray data = reply->readAll();
|
||||
QPixmap icon;
|
||||
icon.loadFromData( data );
|
||||
m_resolversIconCache[ resolverId ] = icon;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AtticaManager::installResolver( const Content& resolver )
|
||||
{
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <attica/provider.h>
|
||||
#include <attica/providermanager.h>
|
||||
#include <attica/content.h>
|
||||
#include <QPixmap>
|
||||
#endif
|
||||
|
||||
class AtticaManager : public QObject
|
||||
@ -53,13 +54,14 @@ public:
|
||||
}
|
||||
|
||||
explicit AtticaManager ( QObject* parent = 0 );
|
||||
virtual ~AtticaManager() {}
|
||||
virtual ~AtticaManager();
|
||||
|
||||
#ifdef LIBATTICA_FOUND
|
||||
bool resolversLoaded() const;
|
||||
|
||||
Attica::Content::List resolvers() const;
|
||||
ResolverState resolverState( const Attica::Content& resolver ) const;
|
||||
QPixmap iconForResolver( const Attica::Content& id ); // Looks up in icon cache
|
||||
|
||||
void installResolver( const Attica::Content& resolver );
|
||||
void uninstallResolver( const Attica::Content& resolver );
|
||||
@ -79,6 +81,9 @@ private slots:
|
||||
void resolverDownloadFinished( Attica::BaseJob* );
|
||||
void payloadFetched();
|
||||
|
||||
void loadPixmapsFromCache();
|
||||
void savePixmapsToCache();
|
||||
|
||||
private:
|
||||
QString extractPayload( const QString& filename, const QString& resolverId ) const;
|
||||
void doResolverRemove( const QString& id ) const;
|
||||
@ -88,10 +93,14 @@ private:
|
||||
|
||||
Attica::Provider m_resolverProvider;
|
||||
Attica::Content::List m_resolvers;
|
||||
QHash<QString, QPixmap> m_resolversIconCache;
|
||||
|
||||
StateHash m_resolverStates;
|
||||
#endif
|
||||
|
||||
static AtticaManager* s_instance;
|
||||
public slots:
|
||||
void resolverIconFetched();
|
||||
};
|
||||
|
||||
#endif // ATTICAMANAGER_H
|
||||
|
@ -76,7 +76,7 @@ GetNewStuffModel::data( const QModelIndex& index, int role ) const
|
||||
case Qt::DisplayRole:
|
||||
return resolver.name();
|
||||
case Qt::DecorationRole:
|
||||
return QVariant::fromValue< QPixmap >( QPixmap( RESPATH "images/delegate-add.png" ) );
|
||||
return QVariant::fromValue< QPixmap >( AtticaManager::instance()->iconForResolver( resolver ) );
|
||||
case DownloadUrlRole:
|
||||
// TODO
|
||||
return QUrl();
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <QModelIndex>
|
||||
|
||||
#include <attica/content.h>
|
||||
#include <QPixmap>
|
||||
|
||||
class GetNewStuffModel: public QAbstractListModel
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user