From 619373c2e511fff94dd8826530ac5b0ef2f08fd8 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Tue, 10 Apr 2012 18:16:14 -0400 Subject: [PATCH] Make lastfm/xmpp info plugins more robust --- src/accounts/lastfm/LastFmAccount.cpp | 12 ++++++------ src/accounts/twitter/twitteraccount.cpp | 3 --- src/accounts/xmpp/sip/xmppsip.cpp | 11 +++++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/accounts/lastfm/LastFmAccount.cpp b/src/accounts/lastfm/LastFmAccount.cpp index 1561d49db..61de6bec7 100644 --- a/src/accounts/lastfm/LastFmAccount.cpp +++ b/src/accounts/lastfm/LastFmAccount.cpp @@ -54,8 +54,6 @@ LastFmAccountFactory::icon() const LastFmAccount::LastFmAccount( const QString& accountId ) : CustomAtticaAccount( accountId ) { - m_infoPlugin = QWeakPointer< LastFmPlugin >( new LastFmPlugin( this ) ); - setAccountFriendlyName( "Last.Fm" ); m_icon.load( RESPATH "images/lastfm-icon.png" ); @@ -84,7 +82,8 @@ LastFmAccount::LastFmAccount( const QString& accountId ) LastFmAccount::~LastFmAccount() { if ( m_infoPlugin ) - m_infoPlugin.data()->deleteLater(); + Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin() ); + delete m_resolver.data(); } @@ -167,9 +166,10 @@ LastFmAccount::icon() const InfoPluginPtr LastFmAccount::infoPlugin() { - if ( m_infoPlugin ) - return InfoPluginPtr( m_infoPlugin.data() ); - return InfoPluginPtr(); + if ( m_infoPlugin.isNull() ) + m_infoPlugin = QWeakPointer< LastFmPlugin >( new LastFmPlugin( this ) ); + + return InfoPluginPtr( m_infoPlugin.data() ); } bool diff --git a/src/accounts/twitter/twitteraccount.cpp b/src/accounts/twitter/twitteraccount.cpp index fca1b9932..da1fb2467 100644 --- a/src/accounts/twitter/twitteraccount.cpp +++ b/src/accounts/twitter/twitteraccount.cpp @@ -105,11 +105,8 @@ Tomahawk::InfoSystem::InfoPluginPtr TwitterAccount::infoPlugin() { if ( m_twitterInfoPlugin.isNull() ) - { m_twitterInfoPlugin = QWeakPointer< Tomahawk::InfoSystem::TwitterInfoPlugin >( new Tomahawk::InfoSystem::TwitterInfoPlugin( this ) ); - return Tomahawk::InfoSystem::InfoPluginPtr( m_twitterInfoPlugin.data() ); - } return Tomahawk::InfoSystem::InfoPluginPtr( m_twitterInfoPlugin.data() ); } diff --git a/src/accounts/xmpp/sip/xmppsip.cpp b/src/accounts/xmpp/sip/xmppsip.cpp index 698db7613..45e81d369 100644 --- a/src/accounts/xmpp/sip/xmppsip.cpp +++ b/src/accounts/xmpp/sip/xmppsip.cpp @@ -176,6 +176,9 @@ XmppSipPlugin::~XmppSipPlugin() InfoSystem::InfoPluginPtr XmppSipPlugin::infoPlugin() { + if ( m_infoPlugin.isNull() ) + m_infoPlugin = QWeakPointer< Tomahawk::InfoSystem::XmppInfoPlugin >( new Tomahawk::InfoSystem::XmppInfoPlugin( this ) ); + return InfoSystem::InfoPluginPtr( m_infoPlugin.data() ); } @@ -270,11 +273,8 @@ XmppSipPlugin::onConnect() m_roster->load(); // load XmppInfoPlugin - if( !m_infoPlugin ) - { - m_infoPlugin = QWeakPointer< Tomahawk::InfoSystem::XmppInfoPlugin >( new Tomahawk::InfoSystem::XmppInfoPlugin( this ) ); + if( infoPlugin() ) InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() ); - } //FIXME: this implementation is totally broken atm, so it's disabled to avoid harm :P // join MUC with bare jid as nickname @@ -338,6 +338,9 @@ XmppSipPlugin::onDisconnect( Jreen::Client::DisconnectReason reason ) { handlePeerStatus(peer, Jreen::Presence::Unavailable); } + + if ( !m_infoPlugin.isNull() ) + Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin() ); }