1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 09:04:33 +02:00

Do not re-save duplicated avatars, as jreen spams us with avatars and we constantly save them to disk

This commit is contained in:
Leo Franchi
2012-11-18 11:00:40 -05:00
parent 7fe1f88431
commit aeefdf9770
3 changed files with 13 additions and 18 deletions

View File

@@ -132,15 +132,22 @@ Source::friendlyName() const
void void
Source::setAvatar( const QPixmap& avatar ) Source::setAvatar( const QPixmap& avatar )
{ {
delete m_avatar;
m_avatar = new QPixmap( avatar );
m_fancyAvatar = 0;
QByteArray ba; QByteArray ba;
QBuffer buffer( &ba ); QBuffer buffer( &ba );
buffer.open( QIODevice::WriteOnly ); buffer.open( QIODevice::WriteOnly );
avatar.save( &buffer, "PNG" ); avatar.save( &buffer, "PNG" );
// Check if the avatar is different by comparing a hash of the first 4096 bytes
const QByteArray hash = QCryptographicHash::hash( ba.left( 4096 ), QCryptographicHash::Sha1 );
if ( m_avatarHash == hash )
return;
else
m_avatarHash = hash;
delete m_avatar;
m_avatar = new QPixmap( avatar );
m_fancyAvatar = 0;
TomahawkUtils::Cache::instance()->putData( "Sources", 7776000000 /* 90 days */, m_username, ba ); TomahawkUtils::Cache::instance()->putData( "Sources", 7776000000 /* 90 days */, m_username, ba );
m_avatarUpdated = true; m_avatarUpdated = true;
} }

View File

@@ -163,6 +163,7 @@ private:
mutable QPixmap* m_avatar; mutable QPixmap* m_avatar;
mutable QPixmap* m_fancyAvatar; mutable QPixmap* m_fancyAvatar;
mutable QByteArray m_avatarHash;
mutable QHash< AvatarStyle, QHash< int, QPixmap > > m_coverCache; mutable QHash< AvatarStyle, QHash< int, QPixmap > > m_coverCache;
Tomahawk::playlistinterface_ptr m_playlistInterface; Tomahawk::playlistinterface_ptr m_playlistInterface;

View File

@@ -221,34 +221,21 @@ SipHandler::onAvatarReceived( const QString& from, const QPixmap& avatar )
// qDebug() << Q_FUNC_INFO << "setting avatar on source for" << from; // qDebug() << Q_FUNC_INFO << "setting avatar on source for" << from;
if ( avatar.isNull() ) if ( avatar.isNull() )
{ {
// qDebug() << Q_FUNC_INFO << "got null pixmap, not adding anything";
return; return;
} }
m_usernameAvatars.insert( from, avatar ); m_usernameAvatars.insert( from, avatar );
//
//Tomahawk::source_ptr source = ->source();
ControlConnection *conn = Servent::instance()->lookupControlConnection( from ); ControlConnection *conn = Servent::instance()->lookupControlConnection( from );
if( conn ) if( conn )
{ {
// qDebug() << Q_FUNC_INFO << from << "got control connection";
Tomahawk::source_ptr source = conn->source(); Tomahawk::source_ptr source = conn->source();
if( source ) if( source )
{ {
// qDebug() << Q_FUNC_INFO << from << "got source, setting avatar"; // qDebug() << Q_FUNC_INFO << from << "got source, setting avatar on source:" << source->friendlyName();
source->setAvatar( avatar ); source->setAvatar( avatar );
} }
else
{
// qDebug() << Q_FUNC_INFO << from << "no source found, not setting avatar";
}
}
else
{
// qDebug() << Q_FUNC_INFO << from << "no control connection setup yet";
} }
} }