From 6c69aa482253eb518a23812696e040abd6ca75e0 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Fri, 7 Jun 2013 19:41:48 +0200 Subject: [PATCH] Dpointerize PeerInfo --- src/libtomahawk/sip/PeerInfo.cpp | 63 ++++++++++++++++---------------- src/libtomahawk/sip/PeerInfo.h | 28 ++++---------- src/libtomahawk/sip/PeerInfo_p.h | 61 +++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 53 deletions(-) create mode 100644 src/libtomahawk/sip/PeerInfo_p.h diff --git a/src/libtomahawk/sip/PeerInfo.cpp b/src/libtomahawk/sip/PeerInfo.cpp index 047e46830..405174e4d 100644 --- a/src/libtomahawk/sip/PeerInfo.cpp +++ b/src/libtomahawk/sip/PeerInfo.cpp @@ -17,7 +17,8 @@ * along with Tomahawk. If not, see . */ -#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& sipInfos ) { - m_sipInfos = sipInfos; + d_func()->sipInfos = sipInfos; tLog() << "id:" << id() << "info changed" << sipInfos; emit sipInfoChanged(); @@ -289,21 +288,21 @@ PeerInfo::setSipInfos( const QList& sipInfos ) const QList 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; } diff --git a/src/libtomahawk/sip/PeerInfo.h b/src/libtomahawk/sip/PeerInfo.h index 74fd52c7c..12ffbf703 100644 --- a/src/libtomahawk/sip/PeerInfo.h +++ b/src/libtomahawk/sip/PeerInfo.h @@ -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 #include - #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 m_sipInfos; - QString m_friendlyName; - QString m_versionString; - QVariant m_data; - mutable QPixmap* m_avatar; mutable QPixmap* m_fancyAvatar; diff --git a/src/libtomahawk/sip/PeerInfo_p.h b/src/libtomahawk/sip/PeerInfo_p.h new file mode 100644 index 000000000..78187672e --- /dev/null +++ b/src/libtomahawk/sip/PeerInfo_p.h @@ -0,0 +1,61 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, Dominik Schmidt + * Copyright 2013, Uwe L. Korn + * + * 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 . + */ + +#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 sipInfos; + QString friendlyName; + QString versionString; + QVariant data; +}; + +} + +#endif // PEERINFO_P_H