diff --git a/src/accounts/xmpp/sip/XmppSip.cpp b/src/accounts/xmpp/sip/XmppSip.cpp index d08debfc2..68f71ad83 100644 --- a/src/accounts/xmpp/sip/XmppSip.cpp +++ b/src/accounts/xmpp/sip/XmppSip.cpp @@ -272,6 +272,8 @@ XmppSipPlugin::disconnectPlugin() emit stateChanged( m_state ); m_client->disconnectFromServer( true ); + + setAllPeersOffline(); } diff --git a/src/accounts/zeroconf/Zeroconf.cpp b/src/accounts/zeroconf/Zeroconf.cpp index 349765127..15f8e10d2 100644 --- a/src/accounts/zeroconf/Zeroconf.cpp +++ b/src/accounts/zeroconf/Zeroconf.cpp @@ -106,6 +106,8 @@ ZeroconfPlugin::disconnectPlugin() delete m_zeroconf; m_zeroconf = 0; + + setAllPeersOffline(); } diff --git a/src/libtomahawk/network/ControlConnection.cpp b/src/libtomahawk/network/ControlConnection.cpp index 0f7294c7a..c156496e2 100644 --- a/src/libtomahawk/network/ControlConnection.cpp +++ b/src/libtomahawk/network/ControlConnection.cpp @@ -280,6 +280,22 @@ ControlConnection::addPeerInfo( const peerinfo_ptr& peerInfo ) } +void +ControlConnection::removePeerInfo( const peerinfo_ptr& peerInfo ) +{ + peerInfoDebug( peerInfo ) << "Remove peer from control connection:" << name(); + Q_ASSERT( peerInfo->controlConnection() == this ); + Q_ASSERT( m_peerInfos.contains( peerInfo ) ); + + m_peerInfos.remove( peerInfo ); + + if ( m_peerInfos.isEmpty() ) + { + shutdown( true ); + } +} + + const QSet< peerinfo_ptr > ControlConnection::peerInfos() const { diff --git a/src/libtomahawk/network/ControlConnection.h b/src/libtomahawk/network/ControlConnection.h index 91cbf60eb..470f92cc2 100644 --- a/src/libtomahawk/network/ControlConnection.h +++ b/src/libtomahawk/network/ControlConnection.h @@ -49,6 +49,7 @@ public: Tomahawk::source_ptr source() const; void addPeerInfo( const Tomahawk::peerinfo_ptr& peerInfo ); + void removePeerInfo( const Tomahawk::peerinfo_ptr& peerInfo ); const QSet< Tomahawk::peerinfo_ptr > peerInfos() const; protected: diff --git a/src/libtomahawk/sip/PeerInfo.cpp b/src/libtomahawk/sip/PeerInfo.cpp index 6bdafb575..27355f69e 100644 --- a/src/libtomahawk/sip/PeerInfo.cpp +++ b/src/libtomahawk/sip/PeerInfo.cpp @@ -176,7 +176,13 @@ PeerInfo::setStatus( PeerInfo::Status status ) m_status = status; if( status == Online ) + { announce(); + } + else if( status == Offline && controlConnection() ) + { + controlConnection()->removePeerInfo( weakRef().toStrongRef() ); + } // we need this to update the DiagnosticsDialog on new peers // if we ever happen to have a central PeerInfo manager object diff --git a/src/libtomahawk/sip/SipPlugin.cpp b/src/libtomahawk/sip/SipPlugin.cpp index a71b52e80..cc74cf456 100644 --- a/src/libtomahawk/sip/SipPlugin.cpp +++ b/src/libtomahawk/sip/SipPlugin.cpp @@ -95,3 +95,12 @@ SipPlugin::peersOnline() const return result; } + + +void SipPlugin::setAllPeersOffline() +{ + foreach( const Tomahawk::peerinfo_ptr& peerInfo, peersOnline() ) + { + peerInfo->setStatus( Tomahawk::PeerInfo::Offline ); + } +} diff --git a/src/libtomahawk/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h index 0a500bf16..83e315624 100644 --- a/src/libtomahawk/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -85,6 +85,8 @@ signals: #endif protected: + void setAllPeersOffline(); + Tomahawk::Accounts::Account *m_account; };