mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Support resolver icons
This commit is contained in:
@@ -41,8 +41,58 @@ AtticaManager::AtticaManager( QObject* parent )
|
|||||||
|
|
||||||
// resolvers
|
// resolvers
|
||||||
m_manager.addProviderFile( QUrl( "http://bakery.tomahawk-player.org:10480/resolvers/providers.xml" ) );
|
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
|
Content::List
|
||||||
AtticaManager::resolvers() const
|
AtticaManager::resolvers() const
|
||||||
{
|
{
|
||||||
@@ -99,8 +149,41 @@ AtticaManager::resolversList( BaseJob* j )
|
|||||||
|
|
||||||
m_resolvers = job->itemList();
|
m_resolvers = job->itemList();
|
||||||
m_resolverStates = TomahawkSettings::instance()->atticaResolverStates();
|
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
|
void
|
||||||
AtticaManager::installResolver( const Content& resolver )
|
AtticaManager::installResolver( const Content& resolver )
|
||||||
{
|
{
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include <attica/provider.h>
|
#include <attica/provider.h>
|
||||||
#include <attica/providermanager.h>
|
#include <attica/providermanager.h>
|
||||||
#include <attica/content.h>
|
#include <attica/content.h>
|
||||||
|
#include <QPixmap>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class AtticaManager : public QObject
|
class AtticaManager : public QObject
|
||||||
@@ -53,13 +54,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
explicit AtticaManager ( QObject* parent = 0 );
|
explicit AtticaManager ( QObject* parent = 0 );
|
||||||
virtual ~AtticaManager() {}
|
virtual ~AtticaManager();
|
||||||
|
|
||||||
#ifdef LIBATTICA_FOUND
|
#ifdef LIBATTICA_FOUND
|
||||||
bool resolversLoaded() const;
|
bool resolversLoaded() const;
|
||||||
|
|
||||||
Attica::Content::List resolvers() const;
|
Attica::Content::List resolvers() const;
|
||||||
ResolverState resolverState( const Attica::Content& resolver ) 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 installResolver( const Attica::Content& resolver );
|
||||||
void uninstallResolver( const Attica::Content& resolver );
|
void uninstallResolver( const Attica::Content& resolver );
|
||||||
@@ -79,6 +81,9 @@ private slots:
|
|||||||
void resolverDownloadFinished( Attica::BaseJob* );
|
void resolverDownloadFinished( Attica::BaseJob* );
|
||||||
void payloadFetched();
|
void payloadFetched();
|
||||||
|
|
||||||
|
void loadPixmapsFromCache();
|
||||||
|
void savePixmapsToCache();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString extractPayload( const QString& filename, const QString& resolverId ) const;
|
QString extractPayload( const QString& filename, const QString& resolverId ) const;
|
||||||
void doResolverRemove( const QString& id ) const;
|
void doResolverRemove( const QString& id ) const;
|
||||||
@@ -88,10 +93,14 @@ private:
|
|||||||
|
|
||||||
Attica::Provider m_resolverProvider;
|
Attica::Provider m_resolverProvider;
|
||||||
Attica::Content::List m_resolvers;
|
Attica::Content::List m_resolvers;
|
||||||
|
QHash<QString, QPixmap> m_resolversIconCache;
|
||||||
|
|
||||||
StateHash m_resolverStates;
|
StateHash m_resolverStates;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static AtticaManager* s_instance;
|
static AtticaManager* s_instance;
|
||||||
|
public slots:
|
||||||
|
void resolverIconFetched();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ATTICAMANAGER_H
|
#endif // ATTICAMANAGER_H
|
||||||
|
@@ -76,7 +76,7 @@ GetNewStuffModel::data( const QModelIndex& index, int role ) const
|
|||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return resolver.name();
|
return resolver.name();
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return QVariant::fromValue< QPixmap >( QPixmap( RESPATH "images/delegate-add.png" ) );
|
return QVariant::fromValue< QPixmap >( AtticaManager::instance()->iconForResolver( resolver ) );
|
||||||
case DownloadUrlRole:
|
case DownloadUrlRole:
|
||||||
// TODO
|
// TODO
|
||||||
return QUrl();
|
return QUrl();
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
|
||||||
#include <attica/content.h>
|
#include <attica/content.h>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
class GetNewStuffModel: public QAbstractListModel
|
class GetNewStuffModel: public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user