mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
* Use cache for source avatars.
This commit is contained in:
@@ -31,9 +31,11 @@
|
|||||||
#include "database/Database.h"
|
#include "database/Database.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QBuffer>
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
|
#include "utils/TomahawkCache.h"
|
||||||
#include "database/DatabaseCommand_SocialAction.h"
|
#include "database/DatabaseCommand_SocialAction.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
@@ -125,12 +127,35 @@ Source::setAvatar( const QPixmap& avatar )
|
|||||||
{
|
{
|
||||||
delete m_avatar;
|
delete m_avatar;
|
||||||
m_avatar = new QPixmap( 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
|
QPixmap
|
||||||
Source::avatar( AvatarStyle style, const QSize& size ) const
|
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 )
|
if ( style == FancyStyle && m_avatar && !m_fancyAvatar )
|
||||||
m_fancyAvatar = new QPixmap( TomahawkUtils::createAvatarFrame( QPixmap( *m_avatar ) ) );
|
m_fancyAvatar = new QPixmap( TomahawkUtils::createAvatarFrame( QPixmap( *m_avatar ) ) );
|
||||||
|
|
||||||
|
@@ -157,7 +157,7 @@ private:
|
|||||||
QList< QSharedPointer<DatabaseCommand> > m_cmds;
|
QList< QSharedPointer<DatabaseCommand> > m_cmds;
|
||||||
int m_commandCount;
|
int m_commandCount;
|
||||||
|
|
||||||
QPixmap* m_avatar;
|
mutable QPixmap* m_avatar;
|
||||||
mutable QPixmap* m_fancyAvatar;
|
mutable QPixmap* m_fancyAvatar;
|
||||||
mutable QHash< int, QPixmap > m_coverCache;
|
mutable QHash< int, QPixmap > m_coverCache;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user