1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 00:09:47 +01:00

* Cache avatar instead of trying to get it from the cache over and over.

This commit is contained in:
Christian Muehlhaeuser 2013-06-05 20:46:22 +02:00
parent 7053c50067
commit cac24eacd3
2 changed files with 22 additions and 22 deletions

View File

@ -57,6 +57,7 @@ Source::Source( int id, const QString& nodeId )
, m_id( id )
, m_updateIndexWhenSynced( false )
, m_state( DBSyncConnection::UNKNOWN )
, m_avatarLoaded( false )
, m_cc( 0 )
, m_commandCount( 0 )
{
@ -251,33 +252,31 @@ Source::friendlyNamesLessThan( const QString& first, const QString& second )
QPixmap
Source::avatar( TomahawkUtils::ImageMode style, const QSize& size )
{
// tLog() << "****************************************************************************************";
// tLog() << peerInfos().count() << "PEERS FOR " << friendlyName();
QPixmap result;
foreach ( const peerinfo_ptr& peerInfo, peerInfos() )
{
// peerInfoDebug(peerInfo) << !peerInfo->avatar().isNull();
if ( !peerInfo.isNull() && !peerInfo->avatar( style, size ).isNull() )
if ( peerInfo && !peerInfo->avatar( style, size ).isNull() )
{
result = peerInfo->avatar( style, size );
break;
return peerInfo->avatar( style, size );
}
}
if ( result.isNull() )
if ( m_avatarLoaded )
return m_avatar;
// Try to get the avatar from the cache
// Hint: We store the avatar for each xmpp peer using its contactId, the dbFriendlyName is a contactId of a peer
m_avatarLoaded = true;
QByteArray avatarBuffer = TomahawkUtils::Cache::instance()->getData( "Sources", dbFriendlyName() ).toByteArray();
if ( !avatarBuffer.isNull() )
{
// Try to get the avatar from the cache
// Hint: We store the avatar for each xmpp peer using its contactId, the dbFriendlyName is a contactId of a peer
QByteArray avatarBuffer = TomahawkUtils::Cache::instance()->getData( "Sources", dbFriendlyName() ).toByteArray();
if ( !avatarBuffer.isNull() )
{
QPixmap avatar;
avatar.loadFromData( avatarBuffer );
avatarBuffer.clear();
result = QPixmap( TomahawkUtils::createRoundedImage( avatar, QSize( 0, 0 ) ) );
}
QPixmap avatar;
avatar.loadFromData( avatarBuffer );
avatarBuffer.clear();
m_avatar = QPixmap( TomahawkUtils::createRoundedImage( avatar, QSize( 0, 0 ) ) );
}
// tLog() << "****************************************************************************************";
return result;
return m_avatar;
}
#endif

View File

@ -70,13 +70,11 @@ public:
QString friendlyName() const;
void setFriendlyName( const QString& fname );
// fallback when the normal friendlyname from cache is not available
// this is usually the jabber id or whatever was used when first connected
QString dbFriendlyName() const;
void setDbFriendlyName( const QString& dbFriendlyName );
#ifndef ENABLE_HEADLESS
QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() );
#endif
@ -173,6 +171,9 @@ private:
DBSyncConnection::State m_state;
QTimer m_currentTrackTimer;
QPixmap m_avatar;
bool m_avatarLoaded;
QPointer<ControlConnection> m_cc;
QList< QSharedPointer<DatabaseCommand> > m_cmds;
int m_commandCount;