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

Dpointerize PeerInfo

This commit is contained in:
Uwe L. Korn 2013-06-07 19:41:48 +02:00
parent 72a54844d8
commit 6c69aa4822
3 changed files with 99 additions and 53 deletions

View File

@ -17,7 +17,8 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PeerInfo.h"
#include "PeerInfo_p.h"
#include "SipPlugin.h"
#include "utils/TomahawkCache.h"
#include "utils/TomahawkUtilsGui.h"
@ -112,10 +113,7 @@ PeerInfo::getAll()
PeerInfo::PeerInfo( SipPlugin* parent, const QString& id )
: QObject()
, m_parent( parent )
, m_type( External )
, m_id( id )
, m_status( Offline )
, d_ptr( new Tomahawk::PeerInfoPrivate ( this, parent, id ) )
, m_avatar( 0 )
, m_fancyAvatar( 0 )
{
@ -128,6 +126,7 @@ PeerInfo::~PeerInfo()
s_peersByCacheKey.remove( s_peersByCacheKey.key( weakRef() ) );
delete m_avatar;
delete m_fancyAvatar;
delete d_ptr;
}
@ -143,62 +142,62 @@ PeerInfo::announce()
QWeakPointer< PeerInfo >
PeerInfo::weakRef()
{
return m_ownRef;
return d_func()->ownRef;
}
void
PeerInfo::setWeakRef( QWeakPointer< PeerInfo > weakRef )
{
m_ownRef = weakRef;
d_func()->ownRef = weakRef;
}
void
PeerInfo::setControlConnection( ControlConnection* controlConnection )
{
m_controlConnection = controlConnection;
d_func()->controlConnection = controlConnection;
}
ControlConnection*
PeerInfo::controlConnection() const
{
return m_controlConnection;
return d_func()->controlConnection;
}
bool PeerInfo::hasControlConnection()
{
return !m_controlConnection.isNull();
return !d_func()->controlConnection.isNull();
}
void
PeerInfo::setType( Tomahawk::PeerInfo::Type type )
{
m_type = type;
d_func()->type = type;
}
PeerInfo::Type
PeerInfo::type() const
{
return m_type;
return d_func()->type;
}
const
QString PeerInfo::id() const
{
return m_id;
return d_func()->id;
}
SipPlugin*
PeerInfo::sipPlugin() const
{
return m_parent;
return d_func()->parent;
}
@ -219,30 +218,30 @@ PeerInfo::debugName() const
void
PeerInfo::setContactId ( const QString& contactId )
{
m_contactId = contactId;
d_func()->contactId = contactId;
}
const QString
PeerInfo::contactId() const
{
return m_contactId;
return d_func()->contactId;
}
const QString
PeerInfo::nodeId() const
{
Q_ASSERT( !m_sipInfos.isEmpty() );
Q_ASSERT( !d_func()->sipInfos.isEmpty() );
// All sip infos share the same nodeId
return m_sipInfos.first().nodeId();
return d_func()->sipInfos.first().nodeId();
}
const QString
PeerInfo::key() const
{
Q_ASSERT( !m_sipInfos.isEmpty() );
Q_ASSERT( !d_func()->sipInfos.isEmpty() );
// All sip infos share the same key
return m_sipInfos.first().key();
return d_func()->sipInfos.first().key();
}
@ -250,7 +249,7 @@ PeerInfo::key() const
void
PeerInfo::setStatus( PeerInfo::Status status )
{
m_status = status;
d_func()->status = status;
if ( status == Online )
{
@ -272,14 +271,14 @@ PeerInfo::setStatus( PeerInfo::Status status )
PeerInfo::Status
PeerInfo::status() const
{
return m_status;
return d_func()->status;
}
void
PeerInfo::setSipInfos( const QList<SipInfo>& sipInfos )
{
m_sipInfos = sipInfos;
d_func()->sipInfos = sipInfos;
tLog() << "id:" << id() << "info changed" << sipInfos;
emit sipInfoChanged();
@ -289,21 +288,21 @@ PeerInfo::setSipInfos( const QList<SipInfo>& sipInfos )
const QList<SipInfo>
PeerInfo::sipInfos() const
{
return m_sipInfos;
return d_func()->sipInfos;
}
void
PeerInfo::setFriendlyName( const QString& friendlyName )
{
m_friendlyName = friendlyName;
d_func()->friendlyName = friendlyName;
}
const QString
PeerInfo::friendlyName() const
{
return m_friendlyName;
return d_func()->friendlyName;
}
@ -387,27 +386,27 @@ PeerInfo::avatar( TomahawkUtils::ImageMode style, const QSize& size ) const
void
PeerInfo::setVersionString( const QString& versionString )
{
m_versionString = versionString;
d_func()->versionString = versionString;
}
const QString
PeerInfo::versionString() const
{
return m_versionString;
return d_func()->versionString;
}
void
PeerInfo::setData( const QVariant& data )
{
m_data = data;
d_func()->data = data;
}
const
QVariant PeerInfo::data() const
const QVariant
PeerInfo::data() const
{
return m_data;
return d_func()->data;
}

View File

@ -19,26 +19,23 @@
#ifndef PEERINFO_H
#define PEERINFO_H
#include "DllMacro.h"
#include "SipInfo.h"
#include "accounts/Account.h"
#include "utils/TomahawkUtils.h"
#include <QString>
#include <QPixmap>
#define peerInfoDebug(peerInfo) tDebug() << "PEERINFO:" << ( !peerInfo.isNull() ? peerInfo->debugName() : "Invalid PeerInfo" ).toLatin1().constData()
class SipPlugin;
class ControlConnection;
class SipPlugin;
class SipInfo;
namespace Tomahawk
{
class PeerInfoPrivate;
class DLLEXPORT PeerInfo : public QObject
{
Q_OBJECT
@ -129,23 +126,12 @@ private:
PeerInfo( SipPlugin* parent, const QString& id );
void announce();
Q_DECLARE_PRIVATE( Tomahawk::PeerInfo )
Tomahawk::PeerInfoPrivate* d_ptr;
static QHash< QString, peerinfo_wptr > s_peersByCacheKey;
static QHash< SipPlugin*, peerinfo_ptr > s_selfPeersBySipPlugin;
QWeakPointer< Tomahawk::PeerInfo > m_ownRef;
QPointer< ControlConnection > m_controlConnection;
SipPlugin* m_parent;
PeerInfo::Type m_type;
QString m_id;
QString m_contactId;
Status m_status;
QList<SipInfo> m_sipInfos;
QString m_friendlyName;
QString m_versionString;
QVariant m_data;
mutable QPixmap* m_avatar;
mutable QPixmap* m_fancyAvatar;

View File

@ -0,0 +1,61 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Dominik Schmidt <dev@dominik-schmidt.de>
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PEERINFO_P_H
#define PEERINFO_P_H
#include "PeerInfo.h"
namespace Tomahawk
{
class PeerInfoPrivate
{
public:
PeerInfoPrivate( PeerInfo* q, SipPlugin* parent, const QString& id )
: q_ptr ( q )
, parent( parent )
, type( PeerInfo::External )
, id( id )
, status( PeerInfo::Offline )
{
}
PeerInfo* q_ptr;
Q_DECLARE_PUBLIC ( PeerInfo )
private:
QWeakPointer< Tomahawk::PeerInfo > ownRef;
QPointer< ControlConnection > controlConnection;
SipPlugin* parent;
PeerInfo::Type type;
QString id;
QString contactId;
PeerInfo::Status status;
QList<SipInfo> sipInfos;
QString friendlyName;
QString versionString;
QVariant data;
};
}
#endif // PEERINFO_P_H