diff --git a/src/accounts/xmpp/sip/XmppSip.cpp b/src/accounts/xmpp/sip/XmppSip.cpp index 69881c7b5..e8cea0c18 100644 --- a/src/accounts/xmpp/sip/XmppSip.cpp +++ b/src/accounts/xmpp/sip/XmppSip.cpp @@ -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 } diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index d286b9d11..ffbb249ab 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -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 diff --git a/src/libtomahawk/sip/PeerInfo.cpp b/src/libtomahawk/sip/PeerInfo.cpp index 2bf3db7d9..8e25795bc 100644 --- a/src/libtomahawk/sip/PeerInfo.cpp +++ b/src/libtomahawk/sip/PeerInfo.cpp @@ -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 ) ) diff --git a/src/libtomahawk/sip/PeerInfo.h b/src/libtomahawk/sip/PeerInfo.h index d15486229..4fe9b1794 100644 --- a/src/libtomahawk/sip/PeerInfo.h +++ b/src/libtomahawk/sip/PeerInfo.h @@ -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;