1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 08:19:42 +01:00

Fix setting of own avatar in sip plugins

This commit is contained in:
Dominik Schmidt 2013-01-27 22:38:31 +01:00
parent c706d7b983
commit ca0162735e
4 changed files with 57 additions and 19 deletions

View File

@ -1019,8 +1019,7 @@ XmppSipPlugin::onNewAvatar( const QString& jid )
if ( jid == m_client->jid().bare() )
{
// own avatar
emit avatarReceived( m_avatarManager->avatar( jid ) );
PeerInfo::getSelf( this, PeerInfo::AutoCreate )->setAvatar( m_avatarManager->avatar( jid ) );
}
#endif
}

View File

@ -88,8 +88,15 @@ Source::setControlConnection( ControlConnection* cc )
const QSet<peerinfo_ptr>
Source::peerInfos() const
{
if( controlConnection() )
if ( controlConnection() )
{
return controlConnection()->peerInfos();
}
else if ( this == SourceList::instance()->getLocal().data() )
{
return PeerInfo::getAllSelf().toSet();
}
return QSet< Tomahawk::peerinfo_ptr >();
}
@ -135,24 +142,20 @@ Source::friendlyName() const
QPixmap
Source::avatar( TomahawkUtils::ImageMode style, const QSize& size )
{
if( controlConnection() )
// tLog() << "****************************************************************************************";
// tLog() << peerInfos().count() << "PEERS FOR " << friendlyName();
QPixmap result;
foreach( const peerinfo_ptr& peerInfo, peerInfos() )
{
// tLog() << "****************************************************************************************";
// tLog() << controlConnection()->peerInfos().count() << "PEERS FOR " << friendlyName();
QPixmap result;
foreach( const peerinfo_ptr& peerInfo, controlConnection()->peerInfos() )
// peerInfoDebug(peerInfo) << !peerInfo->avatar().isNull();
if( !peerInfo.isNull() && !peerInfo->avatar( style, size ).isNull() )
{
// peerInfoDebug(peerInfo);
if( !peerInfo.isNull() && !peerInfo->avatar( style, size ).isNull() )
{
result = peerInfo->avatar( style, size );
}
result = peerInfo->avatar( style, size );
break;
}
// tLog() << "****************************************************************************************";
return result;
}
return QPixmap();
// tLog() << "****************************************************************************************";
return result;
}
#endif

View File

@ -31,6 +31,7 @@ namespace Tomahawk
{
QHash< QString, peerinfo_ptr > PeerInfo::s_peersByCacheKey = QHash< QString, peerinfo_ptr >();
QHash< SipPlugin*, peerinfo_ptr > PeerInfo::s_selfPeersBySipPlugin = QHash< SipPlugin*, peerinfo_ptr >();
inline QString
peerCacheKey( SipPlugin* plugin, const QString& peerId )
@ -38,9 +39,39 @@ peerCacheKey( SipPlugin* plugin, const QString& peerId )
return QString( "%1\t\t%2" ).arg( (quintptr) plugin ).arg( peerId );
}
Tomahawk::peerinfo_ptr
PeerInfo::getSelf( SipPlugin* parent, PeerInfo::GetOptions options )
{
if ( s_selfPeersBySipPlugin.keys().contains( parent ) )
{
return s_selfPeersBySipPlugin.value( parent );
}
// if AutoCreate isn't enabled nothing to do here
if( ! ( options & AutoCreate ) )
{
return peerinfo_ptr();
}
peerinfo_ptr selfPeer( new PeerInfo( parent, "local peerinfo don't use this id for anything" ) );
selfPeer->setWeakRef( selfPeer.toWeakRef() );
// parent->setSelfPeer( selfPeer );
s_selfPeersBySipPlugin.insert( parent, selfPeer );
return selfPeer;
}
QList< Tomahawk::peerinfo_ptr >
PeerInfo::getAllSelf()
{
return s_selfPeersBySipPlugin.values();
}
Tomahawk::peerinfo_ptr
PeerInfo::get(SipPlugin* parent, const QString& id, GetOptions options )
PeerInfo::get( SipPlugin* parent, const QString& id, GetOptions options )
{
const QString key = peerCacheKey( parent, id );
if ( s_peersByCacheKey.contains( key ) )

View File

@ -63,7 +63,10 @@ public:
Local
};
static Tomahawk::peerinfo_ptr get( SipPlugin* parent, const QString& id, GetOptions options = None);
static Tomahawk::peerinfo_ptr getSelf( SipPlugin* parent, GetOptions options = None );
static QList< Tomahawk::peerinfo_ptr > getAllSelf();
static Tomahawk::peerinfo_ptr get( SipPlugin* parent, const QString& id, GetOptions options = None );
static QList< Tomahawk::peerinfo_ptr > getAll();
virtual ~PeerInfo();
@ -111,6 +114,8 @@ private:
void announce();
static QHash< QString, peerinfo_ptr > s_peersByCacheKey;
static QHash< SipPlugin*, peerinfo_ptr > s_selfPeersBySipPlugin;
QWeakPointer< Tomahawk::PeerInfo > m_ownRef;
QPointer< ControlConnection > m_controlConnection;