From 3523609cad2bd10a756f33c4dd4c07987be1e677 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 3 Nov 2011 16:43:53 -0400 Subject: [PATCH] Don't always emit a new nam for plugins when it hasn't actually changed --- .../infosystem/infosystemworker.cpp | 20 +++++++++++++------ src/libtomahawk/utils/tomahawkutils.cpp | 9 +++++++++ src/libtomahawk/utils/tomahawkutils.h | 2 ++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index 324a9bdb5..6252861ec 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -361,18 +361,26 @@ InfoSystemWorker::nam() const void InfoSystemWorker::newNam() { -// qDebug() << Q_FUNC_INFO << " begin"; - QNetworkAccessManager *oldNam = TomahawkUtils::nam(); if ( oldNam && oldNam->thread() == thread() ) { -// qDebug() << Q_FUNC_INFO << "Using old nam as it's the same thread (GUI) as me"; - m_nam = QWeakPointer< QNetworkAccessManager >( oldNam ); - emit namChanged( m_nam.data() ); + if ( m_nam.data() != oldNam ) + { + m_nam = QWeakPointer< QNetworkAccessManager >( oldNam ); + emit namChanged( m_nam.data() ); + } return; } -// qDebug() << Q_FUNC_INFO << "No nam exists, or it's a different thread, creating a new one"; + if ( + oldNam && + !m_nam.isNull() && + oldNam->configuration() == m_nam.data()->configuration() && + oldNam->networkAccessible() == m_nam.data()->networkAccessible() && + oldNam->proxyFactory() == m_nam.data()->proxyFactory() + ) + return; + QNetworkAccessManager* newNam; #ifdef LIBLASTFM_FOUND newNam = new lastfm::NetworkAccessManager( this ); diff --git a/src/libtomahawk/utils/tomahawkutils.cpp b/src/libtomahawk/utils/tomahawkutils.cpp index b4e64fedc..3797557da 100644 --- a/src/libtomahawk/utils/tomahawkutils.cpp +++ b/src/libtomahawk/utils/tomahawkutils.cpp @@ -513,6 +513,15 @@ NetworkProxyFactory::setProxy( const QNetworkProxy& proxy ) } +bool NetworkProxyFactory::operator==( const NetworkProxyFactory& other ) +{ + if ( m_noProxyHosts != other.m_noProxyHosts or m_proxy != other.m_proxy ) + return false; + + return true; +} + + NetworkProxyFactory* proxyFactory() { diff --git a/src/libtomahawk/utils/tomahawkutils.h b/src/libtomahawk/utils/tomahawkutils.h index e8bcd23ce..924045a1d 100644 --- a/src/libtomahawk/utils/tomahawkutils.h +++ b/src/libtomahawk/utils/tomahawkutils.h @@ -65,6 +65,8 @@ namespace TomahawkUtils void setProxy( const QNetworkProxy &proxy ); QNetworkProxy proxy() { return m_proxy; } + bool operator==( const NetworkProxyFactory &other ); + private: QStringList m_noProxyHosts; QNetworkProxy m_proxy;