1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-25 10:19:41 +01:00

Add avatar support to controlconnection, source and sourcetreeview.

This commit is contained in:
Dominik Schmidt 2011-04-20 20:30:04 +02:00
parent def3e3d868
commit 47fd7b8285
6 changed files with 29 additions and 3 deletions

View File

@ -23,6 +23,7 @@
#include "database/databasecommand_collectionstats.h"
#include "dbsyncconnection.h"
#include "sourcelist.h"
#include <sip/SipHandler.h>
#define TCP_TIMEOUT 600
@ -120,6 +121,10 @@ ControlConnection::registerSource()
Source* source = (Source*) sender();
Q_UNUSED( source )
Q_ASSERT( source == m_source.data() );
qDebug() << Q_FUNC_INFO << "Setting avatar ... " << name() << !SipHandler::instance()->avatar( name() ).isNull();
source->setAvatar( SipHandler::instance()->avatar( name() ) );
// .. but we'll use the shared pointer we've already made:
m_registered = true;

View File

@ -44,6 +44,8 @@ public:
DBSyncConnection* dbSyncConnection();
Tomahawk::source_ptr source() const { return m_source; }
protected:
virtual void setup();

View File

@ -57,7 +57,9 @@ signals:
void peerOnline( const QString& );
void peerOffline( const QString& );
void msgReceived( const QString& from, const QString& msg );
void avatarReceived ( const QString& from, const QPixmap& avatar);
void addMenu( QMenu* menu );
void removeMenu( QMenu* menu );
};

View File

@ -107,6 +107,16 @@ Source::friendlyName() const
return m_friendlyname;
}
void Source::setAvatar(const QPixmap& avatar)
{
m_avatar = avatar;
}
const QPixmap Source::avatar() const
{
return m_avatar;
}
void
Source::addCollection( const collection_ptr& c )

View File

@ -54,6 +54,8 @@ public:
QString userName() const { return m_username; }
QString friendlyName() const;
void setFriendlyName( const QString& fname ) { m_friendlyname = fname; }
void setAvatar(const QPixmap &avatar);
const QPixmap avatar() const;
collection_ptr collection() const;
void addCollection( const Tomahawk::collection_ptr& c );
@ -116,6 +118,8 @@ private:
QString m_textStatus;
ControlConnection* m_cc;
QPixmap m_avatar;
};
};

View File

@ -537,17 +537,20 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
SourceTreeItem* sti = SourcesModel::indexToTreeItem( index );
bool status = !( !sti || sti->source().isNull() || !sti->source()->isOnline() );
QPixmap avatar( RESPATH "images/user-avatar.png" );
QString tracks;
int figWidth = 0;
if ( status )
if ( status && sti && !sti->source().isNull() )
{
tracks = QString::number( sti->source()->trackCount() );
figWidth = painter->fontMetrics().width( tracks );
if ( !sti->source()->avatar().isNull() )
avatar = sti->source()->avatar();
}
QRect iconRect = option.rect.adjusted( 4, 6, -option.rect.width() + option.rect.height() - 12 + 4, -6 );
painter->drawPixmap( iconRect, QPixmap( RESPATH "images/user-avatar.png" ).scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) );
painter->drawPixmap( iconRect, avatar.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) );
if ( ( option.state & QStyle::State_Selected ) == QStyle::State_Selected )
{