mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
* Cache avatar instead of trying to get it from the cache over and over.
This commit is contained in:
@@ -57,6 +57,7 @@ Source::Source( int id, const QString& nodeId )
|
|||||||
, m_id( id )
|
, m_id( id )
|
||||||
, m_updateIndexWhenSynced( false )
|
, m_updateIndexWhenSynced( false )
|
||||||
, m_state( DBSyncConnection::UNKNOWN )
|
, m_state( DBSyncConnection::UNKNOWN )
|
||||||
|
, m_avatarLoaded( false )
|
||||||
, m_cc( 0 )
|
, m_cc( 0 )
|
||||||
, m_commandCount( 0 )
|
, m_commandCount( 0 )
|
||||||
{
|
{
|
||||||
@@ -251,33 +252,31 @@ Source::friendlyNamesLessThan( const QString& first, const QString& second )
|
|||||||
QPixmap
|
QPixmap
|
||||||
Source::avatar( TomahawkUtils::ImageMode style, const QSize& size )
|
Source::avatar( TomahawkUtils::ImageMode style, const QSize& size )
|
||||||
{
|
{
|
||||||
// tLog() << "****************************************************************************************";
|
|
||||||
// tLog() << peerInfos().count() << "PEERS FOR " << friendlyName();
|
|
||||||
QPixmap result;
|
|
||||||
foreach ( const peerinfo_ptr& peerInfo, peerInfos() )
|
foreach ( const peerinfo_ptr& peerInfo, peerInfos() )
|
||||||
{
|
{
|
||||||
// peerInfoDebug(peerInfo) << !peerInfo->avatar().isNull();
|
if ( peerInfo && !peerInfo->avatar( style, size ).isNull() )
|
||||||
if ( !peerInfo.isNull() && !peerInfo->avatar( style, size ).isNull() )
|
|
||||||
{
|
{
|
||||||
result = peerInfo->avatar( style, size );
|
return peerInfo->avatar( style, size );
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
QPixmap avatar;
|
||||||
// Hint: We store the avatar for each xmpp peer using its contactId, the dbFriendlyName is a contactId of a peer
|
avatar.loadFromData( avatarBuffer );
|
||||||
QByteArray avatarBuffer = TomahawkUtils::Cache::instance()->getData( "Sources", dbFriendlyName() ).toByteArray();
|
avatarBuffer.clear();
|
||||||
if ( !avatarBuffer.isNull() )
|
|
||||||
{
|
m_avatar = QPixmap( TomahawkUtils::createRoundedImage( avatar, QSize( 0, 0 ) ) );
|
||||||
QPixmap avatar;
|
|
||||||
avatar.loadFromData( avatarBuffer );
|
|
||||||
avatarBuffer.clear();
|
|
||||||
result = QPixmap( TomahawkUtils::createRoundedImage( avatar, QSize( 0, 0 ) ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// tLog() << "****************************************************************************************";
|
|
||||||
return result;
|
return m_avatar;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -70,13 +70,11 @@ public:
|
|||||||
QString friendlyName() const;
|
QString friendlyName() const;
|
||||||
void setFriendlyName( const QString& fname );
|
void setFriendlyName( const QString& fname );
|
||||||
|
|
||||||
|
|
||||||
// fallback when the normal friendlyname from cache is not available
|
// fallback when the normal friendlyname from cache is not available
|
||||||
// this is usually the jabber id or whatever was used when first connected
|
// this is usually the jabber id or whatever was used when first connected
|
||||||
QString dbFriendlyName() const;
|
QString dbFriendlyName() const;
|
||||||
void setDbFriendlyName( const QString& dbFriendlyName );
|
void setDbFriendlyName( const QString& dbFriendlyName );
|
||||||
|
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() );
|
QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() );
|
||||||
#endif
|
#endif
|
||||||
@@ -173,6 +171,9 @@ private:
|
|||||||
DBSyncConnection::State m_state;
|
DBSyncConnection::State m_state;
|
||||||
QTimer m_currentTrackTimer;
|
QTimer m_currentTrackTimer;
|
||||||
|
|
||||||
|
QPixmap m_avatar;
|
||||||
|
bool m_avatarLoaded;
|
||||||
|
|
||||||
QPointer<ControlConnection> m_cc;
|
QPointer<ControlConnection> m_cc;
|
||||||
QList< QSharedPointer<DatabaseCommand> > m_cmds;
|
QList< QSharedPointer<DatabaseCommand> > m_cmds;
|
||||||
int m_commandCount;
|
int m_commandCount;
|
||||||
|
Reference in New Issue
Block a user