1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-14 01:54:07 +02:00

TWK-711: Some attica resolver icon fixes and optimizations. Don't write too much to disk

This commit is contained in:
Leo Franchi
2012-03-01 23:32:56 -05:00
parent c9b0c92450
commit f79ed86b57
2 changed files with 20 additions and 6 deletions

View File

@@ -76,9 +76,12 @@ AtticaManager::loadPixmapsFromCache()
} }
QPixmap* icon = new QPixmap( cacheDir.absoluteFilePath( file ) ); QPixmap* icon = new QPixmap( cacheDir.absoluteFilePath( file ) );
if ( !icon->isNull() )
{
m_resolverStates[ info.baseName() ].pixmap = icon; m_resolverStates[ info.baseName() ].pixmap = icon;
} }
} }
}
void void
@@ -93,14 +96,21 @@ AtticaManager::savePixmapsToCache()
foreach( const QString& id, m_resolverStates.keys() ) foreach( const QString& id, m_resolverStates.keys() )
{ {
if ( !m_resolverStates[ id ].pixmap ) if ( !m_resolverStates[ id ].pixmap || !m_resolverStates[ id ].pixmapDirty )
continue; continue;
const QString filename = cacheDir.absoluteFilePath( QString( "%1.png" ).arg( id ) ); const QString filename = cacheDir.absoluteFilePath( QString( "%1.png" ).arg( id ) );
if ( !m_resolverStates[ id ].pixmap->save( filename ) ) QFile f( filename );
if ( !f.open( QIODevice::WriteOnly ) )
{ {
tLog() << "Failed to open cache file for writing:" << filename; tLog() << "Failed to open cache file for writing:" << filename;
continue; }
else
{
if ( !m_resolverStates[ id ].pixmap->save( &f ) )
{
tLog() << "Failed to save pixmap into opened file for writing:" << filename;
}
} }
} }
} }
@@ -247,6 +257,7 @@ AtticaManager::resolverIconFetched()
QPixmap* icon = new QPixmap; QPixmap* icon = new QPixmap;
icon->loadFromData( data ); icon->loadFromData( data );
m_resolverStates[ resolverId ].pixmap = icon; m_resolverStates[ resolverId ].pixmap = icon;
m_resolverStates[ resolverId ].pixmapDirty = true;
} }

View File

@@ -52,9 +52,12 @@ public:
ResolverState state; ResolverState state;
QPixmap* pixmap; QPixmap* pixmap;
// internal
bool pixmapDirty;
Resolver( const QString& v, const QString& path, int userR, ResolverState s ) Resolver( const QString& v, const QString& path, int userR, ResolverState s )
: version( v ), scriptPath( path ), userRating( userR ), state( s ), pixmap( 0 ) {} : version( v ), scriptPath( path ), userRating( userR ), state( s ), pixmap( 0 ), pixmapDirty( false ) {}
Resolver() : userRating( -1 ), state( Uninstalled ), pixmap( 0 ) {} Resolver() : userRating( -1 ), state( Uninstalled ), pixmap( 0 ), pixmapDirty( false ) {}
}; };
typedef QHash< QString, AtticaManager::Resolver > StateHash; typedef QHash< QString, AtticaManager::Resolver > StateHash;