diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index 00fe429f0..cd625a06b 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -31,9 +31,11 @@ #include "database/Database.h" #include +#include #include "utils/Logger.h" #include "utils/TomahawkUtilsGui.h" +#include "utils/TomahawkCache.h" #include "database/DatabaseCommand_SocialAction.h" using namespace Tomahawk; @@ -125,12 +127,35 @@ Source::setAvatar( const QPixmap& avatar ) { delete m_avatar; m_avatar = new QPixmap( avatar ); + m_fancyAvatar = 0; + + QByteArray ba; + QBuffer buffer( &ba ); + buffer.open( QIODevice::WriteOnly ); + avatar.save( &buffer, "PNG" ); + + tDebug() << Q_FUNC_INFO << friendlyName() << m_username << ba.count(); + TomahawkUtils::Cache::instance()->putData( "Sources", 7776000000 /* 90 days */, m_username, ba ); } QPixmap Source::avatar( AvatarStyle style, const QSize& size ) const { + if ( !m_avatar ) + { + m_avatar = new QPixmap(); + QByteArray ba = TomahawkUtils::Cache::instance()->getData( "Sources", m_username ).toByteArray(); + + if ( ba.count() ) + m_avatar->loadFromData( ba ); + if ( m_avatar->isNull() ) + { + delete m_avatar; + m_avatar = 0; + } + } + if ( style == FancyStyle && m_avatar && !m_fancyAvatar ) m_fancyAvatar = new QPixmap( TomahawkUtils::createAvatarFrame( QPixmap( *m_avatar ) ) ); diff --git a/src/libtomahawk/Source.h b/src/libtomahawk/Source.h index 1c3dc82ee..cd45bbc83 100644 --- a/src/libtomahawk/Source.h +++ b/src/libtomahawk/Source.h @@ -157,7 +157,7 @@ private: QList< QSharedPointer > m_cmds; int m_commandCount; - QPixmap* m_avatar; + mutable QPixmap* m_avatar; mutable QPixmap* m_fancyAvatar; mutable QHash< int, QPixmap > m_coverCache;