1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-07 01:22:49 +02:00

Fix broken proxying. Not sure when it broke but this is a more robust

solution considering that both lastfm and echonest manager their own
nams. See notes; liblastfm may be problematic on Windows and Mac.
This commit is contained in:
Jeff Mitchell 2011-06-27 15:00:25 -04:00
parent e983742c9b
commit bb6da0daa9
6 changed files with 77 additions and 19 deletions

@ -20,6 +20,10 @@
#include <echonest/Artist.h>
#include <echonest/ArtistTypes.h>
#include "utils/tomahawkutils.h"
#include <QNetworkConfiguration>
using namespace Tomahawk::InfoSystem;
using namespace Echonest;
@ -43,9 +47,23 @@ EchoNestPlugin::namChangedSlot( QNetworkAccessManager *nam )
qDebug() << Q_FUNC_INFO;
if( !nam )
return;
QNetworkAccessManager* currNam = Echonest::Config::instance()->nam();
TomahawkUtils::NetworkProxyFactory* oldProxyFactory = dynamic_cast< TomahawkUtils::NetworkProxyFactory* >( nam->proxyFactory() );
if ( !oldProxyFactory )
{
qDebug() << "Could not get old proxyFactory!";
return;
}
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
Echonest::Config::instance()->setNetworkAccessManager( nam );
currNam->setConfiguration( nam->configuration() );
currNam->setNetworkAccessible( nam->networkAccessible() );
TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() );
newProxyFactory->setProxy( oldProxyFactory->proxy() );
currNam->setProxyFactory( newProxyFactory );
m_nam = QWeakPointer< QNetworkAccessManager >( currNam );
}
void

@ -21,6 +21,7 @@
#include <QDir>
#include <QSettings>
#include <QCryptographicHash>
#include <QNetworkConfiguration>
#include "album.h"
#include "typedefs.h"
@ -93,10 +94,30 @@ void
LastFmPlugin::namChangedSlot( QNetworkAccessManager *nam )
{
qDebug() << Q_FUNC_INFO;
if( !nam )
if ( !nam )
return;
QNetworkAccessManager* currNam = lastfm::nam();
TomahawkUtils::NetworkProxyFactory* oldProxyFactory = dynamic_cast< TomahawkUtils::NetworkProxyFactory* >( nam->proxyFactory() );
if ( !oldProxyFactory )
{
qDebug() << "Could not get old proxyFactory!";
return;
}
currNam->setConfiguration( nam->configuration() );
currNam->setNetworkAccessible( nam->networkAccessible() );
TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() );
newProxyFactory->setProxy( oldProxyFactory->proxy() );
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
m_nam = QWeakPointer< QNetworkAccessManager >( currNam );
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
settingsChanged(); // to get the scrobbler set up
}
@ -172,7 +193,6 @@ LastFmPlugin::nowPlaying( const QVariant &input )
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) || !hash.contains( "duration" ) )
return;
qDebug() << "LastFmPlugin::nowPlaying valid criteria hash";
m_track = lastfm::MutableTrack();
m_track.stamp();
@ -350,6 +370,14 @@ LastFmPlugin::coverArtReturned()
if ( redir.isEmpty() )
{
QByteArray ba = reply->readAll();
if ( ba.isNull() || !ba.length() )
{
qDebug() << "Uh oh, null byte array";
InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt());
InfoCustomData customData = reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
emit info( reply->property( "caller" ).toString(), type, reply->property( "origData" ), QVariant(), customData );
return;
}
foreach ( const QUrl& url, m_badUrls )
{
if ( reply->url().toString().startsWith( url.toString() ) )
@ -409,12 +437,19 @@ LastFmPlugin::artistImagesReturned()
if ( redir.isEmpty() )
{
QByteArray ba = reply->readAll();
if ( ba.isNull() || !ba.length() )
{
qDebug() << "Uh oh, null byte array";
InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt());
InfoCustomData customData = reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
emit info( reply->property( "caller" ).toString(), type, reply->property( "origData" ), QVariant(), customData );
return;
}
foreach ( const QUrl& url, m_badUrls )
{
if ( reply->url().toString().startsWith( url.toString() ) )
ba = QByteArray();
}
InfoCustomData returnedData;
returnedData["imgbytes"] = ba;
returnedData["url"] = reply->url().toString();

@ -159,13 +159,15 @@ InfoSystemCache::getCachedInfoSlot( const Tomahawk::InfoSystem::InfoCriteriaHash
if ( !m_dataCache.contains( criteriaHashVal ) )
{
QSettings cachedSettings( fileLocationHash[criteriaHashVal], QSettings::IniFormat );
QVariant output = cachedSettings.value( "data" );
QVariant output = cachedSettings.value( "data" );
m_dataCache.insert( criteriaHashVal, new QVariant( output ) );
emit info( caller, type, input, output, customData );
}
else
{
emit info( caller, type, input, QVariant( *(m_dataCache[criteriaHashVal]) ), customData );
}
}

@ -314,7 +314,7 @@ void
AlbumModel::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData )
{
Q_UNUSED( customData );
qDebug() << Q_FUNC_INFO;
qDebug() << Q_FUNC_INFO << " with caller " << caller;
if ( caller != s_tmInfoIdentifier ||
( type != Tomahawk::InfoSystem::InfoAlbumCoverArt && type != Tomahawk::InfoSystem::InfoArtistImages ) )

@ -602,11 +602,11 @@ TreeModel::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type,
Tomahawk::InfoSystem::InfoCriteriaHash pptr = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
Tomahawk::InfoSystem::InfoCustomData returnedData = output.value< Tomahawk::InfoSystem::InfoCustomData >();
const QByteArray ba = returnedData["imgbytes"].toByteArray();
qDebug() << "ba.length = " << ba.length();
if ( ba.length() )
{
QPixmap pm;
pm.loadFromData( ba );
bool ok;
qlonglong p = pptr["pptr"].toLongLong( &ok );
TreeModelItem* ai = reinterpret_cast<TreeModelItem*>(p);

@ -204,6 +204,14 @@ TomahawkApp::init()
new TomahawkSettings( this );
TomahawkSettings* s = TomahawkSettings::instance();
#ifdef LIBLASTFM_FOUND
qDebug() << "Setting NAM.";
TomahawkUtils::setNam( lastfm::nam() );
#else
qDebug() << "Setting NAM.";
TomahawkUtils::setNam( new QNetworkAccessManager() );
#endif
TomahawkUtils::NetworkProxyFactory* proxyFactory = new TomahawkUtils::NetworkProxyFactory();
if( s->proxyType() != QNetworkProxy::NoProxy &&
@ -212,20 +220,15 @@ TomahawkApp::init()
qDebug() << "Setting proxy to saved values";
QNetworkProxy proxy( static_cast<QNetworkProxy::ProxyType>( s->proxyType() ), s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() );
proxyFactory->setProxy( proxy );
//TODO: On Windows and Mac because liblastfm sets an application level proxy it may override our factory, so may need to explicitly do
//a QNetworkProxy::setApplicationProxy with our own proxy (but then also overriding our own factory :-( )
}
if ( !s->proxyNoProxyHosts().isEmpty() )
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) );
TomahawkUtils::NetworkProxyFactory::setApplicationProxyFactory( proxyFactory );
#ifdef LIBLASTFM_FOUND
qDebug() << "Setting NAM.";
TomahawkUtils::setNam( lastfm::nam() );
#else
qDebug() << "Setting NAM.";
TomahawkUtils::setNam( new QNetworkAccessManager() );
#endif
TomahawkUtils::setProxyFactory( proxyFactory );
Echonest::Config::instance()->setAPIKey( "JRIHWEP6GPOER2QQ6" );
m_audioEngine = QWeakPointer<AudioEngine>( new AudioEngine );