mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +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:
@@ -20,6 +20,10 @@
|
|||||||
#include <echonest/Artist.h>
|
#include <echonest/Artist.h>
|
||||||
#include <echonest/ArtistTypes.h>
|
#include <echonest/ArtistTypes.h>
|
||||||
|
|
||||||
|
#include "utils/tomahawkutils.h"
|
||||||
|
|
||||||
|
#include <QNetworkConfiguration>
|
||||||
|
|
||||||
using namespace Tomahawk::InfoSystem;
|
using namespace Tomahawk::InfoSystem;
|
||||||
using namespace Echonest;
|
using namespace Echonest;
|
||||||
|
|
||||||
@@ -44,8 +48,22 @@ EchoNestPlugin::namChangedSlot( QNetworkAccessManager *nam )
|
|||||||
if( !nam )
|
if( !nam )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
|
QNetworkAccessManager* currNam = Echonest::Config::instance()->nam();
|
||||||
Echonest::Config::instance()->setNetworkAccessManager( 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 );
|
||||||
|
m_nam = QWeakPointer< QNetworkAccessManager >( currNam );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
#include <QNetworkConfiguration>
|
||||||
|
|
||||||
#include "album.h"
|
#include "album.h"
|
||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
@@ -93,10 +94,30 @@ void
|
|||||||
LastFmPlugin::namChangedSlot( QNetworkAccessManager *nam )
|
LastFmPlugin::namChangedSlot( QNetworkAccessManager *nam )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
if( !nam )
|
|
||||||
|
if ( !nam )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
|
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 );
|
||||||
|
|
||||||
settingsChanged(); // to get the scrobbler set up
|
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" ) )
|
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) || !hash.contains( "duration" ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qDebug() << "LastFmPlugin::nowPlaying valid criteria hash";
|
|
||||||
m_track = lastfm::MutableTrack();
|
m_track = lastfm::MutableTrack();
|
||||||
m_track.stamp();
|
m_track.stamp();
|
||||||
|
|
||||||
@@ -350,6 +370,14 @@ LastFmPlugin::coverArtReturned()
|
|||||||
if ( redir.isEmpty() )
|
if ( redir.isEmpty() )
|
||||||
{
|
{
|
||||||
QByteArray ba = reply->readAll();
|
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 )
|
foreach ( const QUrl& url, m_badUrls )
|
||||||
{
|
{
|
||||||
if ( reply->url().toString().startsWith( url.toString() ) )
|
if ( reply->url().toString().startsWith( url.toString() ) )
|
||||||
@@ -409,12 +437,19 @@ LastFmPlugin::artistImagesReturned()
|
|||||||
if ( redir.isEmpty() )
|
if ( redir.isEmpty() )
|
||||||
{
|
{
|
||||||
QByteArray ba = reply->readAll();
|
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 )
|
foreach ( const QUrl& url, m_badUrls )
|
||||||
{
|
{
|
||||||
if ( reply->url().toString().startsWith( url.toString() ) )
|
if ( reply->url().toString().startsWith( url.toString() ) )
|
||||||
ba = QByteArray();
|
ba = QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
InfoCustomData returnedData;
|
InfoCustomData returnedData;
|
||||||
returnedData["imgbytes"] = ba;
|
returnedData["imgbytes"] = ba;
|
||||||
returnedData["url"] = reply->url().toString();
|
returnedData["url"] = reply->url().toString();
|
||||||
|
@@ -165,7 +165,9 @@ InfoSystemCache::getCachedInfoSlot( const Tomahawk::InfoSystem::InfoCriteriaHash
|
|||||||
emit info( caller, type, input, output, customData );
|
emit info( caller, type, input, output, customData );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
emit info( caller, type, input, QVariant( *(m_dataCache[criteriaHashVal]) ), customData );
|
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 )
|
AlbumModel::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData )
|
||||||
{
|
{
|
||||||
Q_UNUSED( customData );
|
Q_UNUSED( customData );
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO << " with caller " << caller;
|
||||||
|
|
||||||
if ( caller != s_tmInfoIdentifier ||
|
if ( caller != s_tmInfoIdentifier ||
|
||||||
( type != Tomahawk::InfoSystem::InfoAlbumCoverArt && type != Tomahawk::InfoSystem::InfoArtistImages ) )
|
( 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::InfoCriteriaHash pptr = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
|
||||||
Tomahawk::InfoSystem::InfoCustomData returnedData = output.value< Tomahawk::InfoSystem::InfoCustomData >();
|
Tomahawk::InfoSystem::InfoCustomData returnedData = output.value< Tomahawk::InfoSystem::InfoCustomData >();
|
||||||
const QByteArray ba = returnedData["imgbytes"].toByteArray();
|
const QByteArray ba = returnedData["imgbytes"].toByteArray();
|
||||||
|
qDebug() << "ba.length = " << ba.length();
|
||||||
if ( ba.length() )
|
if ( ba.length() )
|
||||||
{
|
{
|
||||||
QPixmap pm;
|
QPixmap pm;
|
||||||
pm.loadFromData( ba );
|
pm.loadFromData( ba );
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
qlonglong p = pptr["pptr"].toLongLong( &ok );
|
qlonglong p = pptr["pptr"].toLongLong( &ok );
|
||||||
TreeModelItem* ai = reinterpret_cast<TreeModelItem*>(p);
|
TreeModelItem* ai = reinterpret_cast<TreeModelItem*>(p);
|
||||||
|
@@ -204,6 +204,14 @@ TomahawkApp::init()
|
|||||||
new TomahawkSettings( this );
|
new TomahawkSettings( this );
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
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();
|
TomahawkUtils::NetworkProxyFactory* proxyFactory = new TomahawkUtils::NetworkProxyFactory();
|
||||||
|
|
||||||
if( s->proxyType() != QNetworkProxy::NoProxy &&
|
if( s->proxyType() != QNetworkProxy::NoProxy &&
|
||||||
@@ -212,19 +220,14 @@ TomahawkApp::init()
|
|||||||
qDebug() << "Setting proxy to saved values";
|
qDebug() << "Setting proxy to saved values";
|
||||||
QNetworkProxy proxy( static_cast<QNetworkProxy::ProxyType>( s->proxyType() ), s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() );
|
QNetworkProxy proxy( static_cast<QNetworkProxy::ProxyType>( s->proxyType() ), s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() );
|
||||||
proxyFactory->setProxy( proxy );
|
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() )
|
if ( !s->proxyNoProxyHosts().isEmpty() )
|
||||||
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) );
|
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) );
|
||||||
TomahawkUtils::NetworkProxyFactory::setApplicationProxyFactory( proxyFactory );
|
|
||||||
|
|
||||||
#ifdef LIBLASTFM_FOUND
|
TomahawkUtils::setProxyFactory( proxyFactory );
|
||||||
qDebug() << "Setting NAM.";
|
|
||||||
TomahawkUtils::setNam( lastfm::nam() );
|
|
||||||
#else
|
|
||||||
qDebug() << "Setting NAM.";
|
|
||||||
TomahawkUtils::setNam( new QNetworkAccessManager() );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Echonest::Config::instance()->setAPIKey( "JRIHWEP6GPOER2QQ6" );
|
Echonest::Config::instance()->setAPIKey( "JRIHWEP6GPOER2QQ6" );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user