1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-22 08:52:12 +02:00

Make things a little safer and also try setting an explicit nam configuration on liblastfm2 in settings dialog to see if that fixes the Mac problem

This commit is contained in:
Jeff Mitchell 2011-07-23 13:15:20 -04:00
parent 287990ca96
commit a9e3b716f2
3 changed files with 30 additions and 5 deletions
src
libtomahawk
infosystem/infoplugins/generic
utils
settingsdialog.cpp

@ -98,7 +98,6 @@ LastFmPlugin::namChangedSlot( QNetworkAccessManager *nam )
if ( !nam )
return;
QNetworkAccessManager* currNam = lastfm::nam();
TomahawkUtils::NetworkProxyFactory* oldProxyFactory = dynamic_cast< TomahawkUtils::NetworkProxyFactory* >( nam->proxyFactory() );
if ( !oldProxyFactory )
@ -107,6 +106,10 @@ LastFmPlugin::namChangedSlot( QNetworkAccessManager *nam )
return;
}
//WARNING: there's a chance liblastfm2 will clobber the application proxy factory it if it constructs a nam due to the below call
//but it is unsafe to re-set it here
QNetworkAccessManager* currNam = lastfm::nam();
currNam->setConfiguration( nam->configuration() );
currNam->setNetworkAccessible( nam->networkAccessible() );
TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
@ -114,8 +117,6 @@ LastFmPlugin::namChangedSlot( QNetworkAccessManager *nam )
QNetworkProxy newProxy( oldProxyFactory->proxy() );
newProxyFactory->setProxy( newProxy );
currNam->setProxyFactory( newProxyFactory );
//FIXME: on Mac/Win as liblastfm's network access manager also sets its overriding application proxy
//may have to do a QNetworkProxy::setApplicationProxy and clobber our own factory to override it
settingsChanged(); // to get the scrobbler set up
}

@ -425,8 +425,6 @@ NetworkProxyFactory::setProxy( const QNetworkProxy& proxy )
NetworkProxyFactory*
proxyFactory()
{
// Don't use this anywhere! It's provided here for access reasons, but QNAM deletes this at will!
if ( !s_proxyFactory )
s_proxyFactory = new NetworkProxyFactory();
@ -440,6 +438,15 @@ setProxyFactory( NetworkProxyFactory* factory )
Q_ASSERT( factory );
s_proxyFactory = factory;
NetworkProxyFactory::setApplicationProxyFactory( s_proxyFactory );
//nam takes ownership so set a copy, not the global one
if ( s_nam )
{
TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
newProxyFactory->setNoProxyHosts( factory->noProxyHosts() );
QNetworkProxy newProxy( factory->proxy() );
newProxyFactory->setProxy( newProxy );
s_nam.data()->setProxyFactory( newProxyFactory );
}
}

@ -23,6 +23,7 @@
#include <QDesktopServices>
#include <QFileDialog>
#include <QMessageBox>
#include <QNetworkConfiguration>
#include <QNetworkProxy>
#include <QVBoxLayout>
#include <QSizeGrip>
@ -404,6 +405,22 @@ SettingsDialog::testLastFmLogin()
query[ "method" ] = "auth.getMobileSession";
query[ "username" ] = ui->lineEditLastfmUsername->text().toLower();
query[ "authToken" ] = authToken;
TomahawkUtils::NetworkProxyFactory* oldProxyFactory = TomahawkUtils::proxyFactory();
QNetworkAccessManager* nam = TomahawkUtils::nam();
//WARNING: there's a chance liblastfm2 will clobber the application proxy factory it if it constructs a nam due to the below call
//but it is unsafe to re-set it here
QNetworkAccessManager* currNam = lastfm::nam();
currNam->setConfiguration( nam->configuration() );
currNam->setNetworkAccessible( nam->networkAccessible() );
TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() );
QNetworkProxy newProxy( oldProxyFactory->proxy() );
newProxyFactory->setProxy( newProxy );
currNam->setProxyFactory( newProxyFactory );
QNetworkReply* authJob = lastfm::ws::post( query );
connect( authJob, SIGNAL( finished() ), SLOT( onLastFmFinished() ) );