1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 19:30:21 +02:00

Remove all the QNAM-fuckery, since echonest and liblastfm are probably

good now.

(Note: will be pushing the change to liblastfm to libechonest as well)
This commit is contained in:
Jeff Mitchell
2011-11-07 13:52:10 -05:00
parent f542e97a70
commit 475633c328
28 changed files with 65 additions and 334 deletions

View File

@@ -52,17 +52,6 @@ RoviPlugin::~RoviPlugin()
}
void
RoviPlugin::namChangedSlot( QNetworkAccessManager* nam )
{
if ( !nam )
return;
m_nam = nam;
}
void
RoviPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{
@@ -194,7 +183,7 @@ RoviPlugin::makeRequest( QUrl url )
url.addEncodedQueryItem( "sig", generateSig() );
qDebug() << "Rovi request url:" << url.toString();
return m_nam->get( QNetworkRequest( url ) );
return TomahawkUtils::nam()->get( QNetworkRequest( url ) );
}

View File

@@ -39,7 +39,6 @@ public:
virtual ~RoviPlugin();
protected:
virtual void namChangedSlot( QNetworkAccessManager* nam );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant )
@@ -54,8 +53,6 @@ private:
QNetworkReply* makeRequest( QUrl url );
QByteArray generateSig() const;
QNetworkAccessManager* m_nam;
QByteArray m_apiKey;
QByteArray m_secret;
};

View File

@@ -52,6 +52,22 @@ ChartsPlugin::ChartsPlugin()
m_chartResources << "billboard" << "itunes" << "rdio" << "wearehunted";
m_supportedGetTypes << InfoChart << InfoChartCapabilities;
/// Then get each chart from resource
/// We want to prepopulate the breadcrumb to fetch them before they are asked for
if ( !m_chartResources.isEmpty() && m_allChartsMap.isEmpty() )
{
tDebug() << "ChartsPlugin: InfoChart fetching possible resources";
foreach ( QVariant resource, m_chartResources )
{
QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
tDebug() << "fetching:" << url;
connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) );
m_chartsFetchJobs++;
}
}
}
@@ -61,38 +77,6 @@ ChartsPlugin::~ChartsPlugin()
}
void
ChartsPlugin::namChangedSlot( QNetworkAccessManager *nam )
{
tDebug() << "ChartsPlugin: namChangedSLot";
qDebug() << Q_FUNC_INFO;
if( !nam )
return;
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
/// Then get each chart from resource
/// We want to prepopulate the breadcrumb to fetch them before they are asked for
if ( !m_chartResources.isEmpty() && m_nam && m_allChartsMap.isEmpty() )
{
tDebug() << "ChartsPlugin: InfoChart fetching possible resources";
foreach ( QVariant resource, m_chartResources )
{
QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) );
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
tDebug() << "fetching:" << url;
connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) );
m_chartsFetchJobs++;
}
}
}
void
ChartsPlugin::dataError( Tomahawk::InfoSystem::InfoRequestData requestData )
{
@@ -202,14 +186,6 @@ ChartsPlugin::fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData requ
void
ChartsPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
{
if ( !m_nam.data() )
{
tLog() << "Have a null QNAM, uh oh";
emit info( requestData, QVariant() );
return;
}
switch ( requestData.type )
{
case InfoChart:
@@ -218,7 +194,7 @@ ChartsPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSy
QUrl url = QUrl( QString( CHART_URL "source/%1/chart/%2" ).arg( criteria["chart_source"] ).arg( criteria["chart_id"] ) );
qDebug() << Q_FUNC_INFO << "Getting chart url" << url;
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );

View File

@@ -53,7 +53,6 @@ public:
public slots:
void chartReturned();
void chartTypes();
void namChangedSlot( QNetworkAccessManager *nam );
protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );

View File

@@ -37,35 +37,12 @@ EchoNestPlugin::EchoNestPlugin()
m_supportedGetTypes << Tomahawk::InfoSystem::InfoArtistBiography << Tomahawk::InfoSystem::InfoArtistFamiliarity << Tomahawk::InfoSystem::InfoArtistHotttness << Tomahawk::InfoSystem::InfoArtistTerms << Tomahawk::InfoSystem::InfoMiscTopTerms;
}
EchoNestPlugin::~EchoNestPlugin()
{
qDebug() << Q_FUNC_INFO;
}
void
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;
}
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 );
}
void
EchoNestPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
@@ -92,6 +69,7 @@ EchoNestPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
}
}
void
EchoNestPlugin::getSongProfile( const Tomahawk::InfoSystem::InfoRequestData &requestData, const QString &item )
{
@@ -109,6 +87,7 @@ EchoNestPlugin::getSongProfile( const Tomahawk::InfoSystem::InfoRequestData &req
// connect(reply, SIGNAL(finished()), SLOT(getArtistBiographySlot()));
}
void
EchoNestPlugin::getArtistBiography( const Tomahawk::InfoSystem::InfoRequestData &requestData )
{
@@ -122,6 +101,7 @@ EchoNestPlugin::getArtistBiography( const Tomahawk::InfoSystem::InfoRequestData
connect( reply, SIGNAL( finished() ), SLOT( getArtistBiographySlot() ) );
}
void
EchoNestPlugin::getArtistFamiliarity( const Tomahawk::InfoSystem::InfoRequestData &requestData )
{
@@ -136,6 +116,7 @@ EchoNestPlugin::getArtistFamiliarity( const Tomahawk::InfoSystem::InfoRequestDat
connect( reply, SIGNAL( finished() ), SLOT( getArtistFamiliaritySlot() ) );
}
void
EchoNestPlugin::getArtistHotttnesss( const Tomahawk::InfoSystem::InfoRequestData &requestData )
{
@@ -149,6 +130,7 @@ EchoNestPlugin::getArtistHotttnesss( const Tomahawk::InfoSystem::InfoRequestData
connect( reply, SIGNAL( finished() ), SLOT( getArtistHotttnesssSlot() ) );
}
void
EchoNestPlugin::getArtistTerms( const Tomahawk::InfoSystem::InfoRequestData &requestData )
{
@@ -162,6 +144,7 @@ EchoNestPlugin::getArtistTerms( const Tomahawk::InfoSystem::InfoRequestData &req
connect( reply, SIGNAL( finished() ), SLOT( getArtistTermsSlot() ) );
}
void
EchoNestPlugin::getMiscTopTerms( const Tomahawk::InfoSystem::InfoRequestData &requestData )
{
@@ -194,6 +177,7 @@ EchoNestPlugin::getArtistBiographySlot()
reply->deleteLater();
}
void
EchoNestPlugin::getArtistFamiliaritySlot()
{
@@ -205,6 +189,7 @@ EchoNestPlugin::getArtistFamiliaritySlot()
reply->deleteLater();
}
void
EchoNestPlugin::getArtistHotttnesssSlot()
{
@@ -216,6 +201,7 @@ EchoNestPlugin::getArtistHotttnesssSlot()
reply->deleteLater();
}
void
EchoNestPlugin::getArtistTermsSlot()
{
@@ -234,6 +220,7 @@ EchoNestPlugin::getArtistTermsSlot()
reply->deleteLater();
}
void
EchoNestPlugin::getMiscTopSlot()
{
@@ -251,6 +238,7 @@ EchoNestPlugin::getMiscTopSlot()
reply->deleteLater();
}
bool
EchoNestPlugin::isValidArtistData( const Tomahawk::InfoSystem::InfoRequestData &requestData )
{
@@ -268,6 +256,7 @@ EchoNestPlugin::isValidArtistData( const Tomahawk::InfoSystem::InfoRequestData &
return true;
}
bool
EchoNestPlugin::isValidTrackData( const Tomahawk::InfoSystem::InfoRequestData &requestData )
{
@@ -290,6 +279,7 @@ EchoNestPlugin::isValidTrackData( const Tomahawk::InfoSystem::InfoRequestData &r
return true;
}
Artist
EchoNestPlugin::artistFromReply( QNetworkReply* reply )
{

View File

@@ -61,9 +61,6 @@ protected slots:
Q_UNUSED( requestData );
}
public slots:
void namChangedSlot( QNetworkAccessManager *nam );
private:
void getSongProfile( const Tomahawk::InfoSystem::InfoRequestData &requestData, const QString &item = QString() );
void getArtistBiography( const Tomahawk::InfoSystem::InfoRequestData &requestData );

View File

@@ -102,20 +102,6 @@ hypemPlugin::~hypemPlugin()
}
void
hypemPlugin::namChangedSlot( QNetworkAccessManager *nam )
{
tDebug() << "hypemPlugin: namChangedSLot";
qDebug() << Q_FUNC_INFO;
if( !nam )
return;
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
}
void
hypemPlugin::dataError( Tomahawk::InfoSystem::InfoRequestData requestData )
{
@@ -207,14 +193,6 @@ hypemPlugin::fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData reque
void
hypemPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
{
if ( !m_nam.data() )
{
tLog() << "Have a null QNAM, uh oh";
emit info( requestData, QVariant() );
return;
}
switch ( requestData.type )
{
case InfoChart:
@@ -224,7 +202,7 @@ hypemPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSys
QUrl url = QUrl( QString( HYPEM_URL "%1/%2" ).arg( criteria["chart_id"].toLower() ).arg(HYPEM_END_URL) );
qDebug() << Q_FUNC_INFO << "Getting chart url" << url;
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );
return;

View File

@@ -53,7 +53,6 @@ public:
public slots:
void chartReturned();
void chartTypes();
void namChangedSlot( QNetworkAccessManager *nam );
protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
@@ -82,8 +81,6 @@ private:
QList< InfoRequestData > m_cachedRequests;
QHash< QString, QString > m_cachedCountries;
QWeakPointer< QNetworkAccessManager > m_nam;
};
}

View File

@@ -94,34 +94,6 @@ LastFmPlugin::~LastFmPlugin()
}
void
LastFmPlugin::namChangedSlot( QNetworkAccessManager *nam )
{
if ( !nam )
return;
TomahawkUtils::NetworkProxyFactory* oldProxyFactory = dynamic_cast< TomahawkUtils::NetworkProxyFactory* >( nam->proxyFactory() );
if ( !oldProxyFactory )
{
tLog() << Q_FUNC_INFO << "Could not get old proxyFactory!";
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();
newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() );
QNetworkProxy newProxy( oldProxyFactory->proxy() );
newProxyFactory->setProxy( newProxy );
currNam->setProxyFactory( newProxyFactory );
settingsChanged(); // to get the scrobbler set up
}
void
LastFmPlugin::dataError( Tomahawk::InfoSystem::InfoRequestData requestData )
{

View File

@@ -53,8 +53,6 @@ public slots:
void topTracksReturned();
void chartReturned();
void namChangedSlot( QNetworkAccessManager *nam );
protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );

View File

@@ -41,15 +41,6 @@ MusicBrainzPlugin::~MusicBrainzPlugin()
}
void
MusicBrainzPlugin::namChangedSlot( QNetworkAccessManager *nam )
{
if ( !nam )
return;
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
}
void
MusicBrainzPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{
@@ -107,7 +98,7 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
QString requestString( "http://musicbrainz.org/ws/2/artist" );
QUrl url( requestString );
url.addQueryItem( "query", criteria["artist"] );
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
connect( reply, SIGNAL( finished() ), SLOT( artistSearchSlot() ) );
@@ -119,7 +110,7 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
QString requestString( "http://musicbrainz.org/ws/2/artist" );
QUrl url( requestString );
url.addQueryItem( "query", criteria["artist"] );
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
connect( reply, SIGNAL( finished() ), SLOT( albumSearchSlot() ) );
@@ -182,7 +173,7 @@ MusicBrainzPlugin::artistSearchSlot()
QUrl url( requestString );
url.addQueryItem( "artist", artist_id );
QNetworkReply* newReply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
connect( newReply, SIGNAL( finished() ), SLOT( albumFoundSlot() ) );
}
@@ -209,7 +200,7 @@ MusicBrainzPlugin::albumSearchSlot()
QUrl url( requestString );
url.addQueryItem( "artist", artist_id );
QNetworkReply* newReply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
connect( newReply, SIGNAL( finished() ), SLOT( tracksSearchSlot() ) );
}
@@ -252,7 +243,7 @@ MusicBrainzPlugin::tracksSearchSlot()
QString requestString = QString( "http://musicbrainz.org/ws/2/release/%1?inc=recordings" ).arg( release_id );
QUrl url( requestString );
QNetworkReply* newReply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
connect( newReply, SIGNAL( finished() ), SLOT( tracksFoundSlot() ) );
}

View File

@@ -38,9 +38,6 @@ public:
MusicBrainzPlugin();
virtual ~MusicBrainzPlugin();
public slots:
void namChangedSlot( QNetworkAccessManager *nam );
protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( InfoStringHash criteria, InfoRequestData requestData );
@@ -63,8 +60,6 @@ private slots:
private:
bool isValidTrackData( Tomahawk::InfoSystem::InfoRequestData requestData );
QWeakPointer< QNetworkAccessManager > m_nam;
};
}

View File

@@ -42,21 +42,11 @@ MusixMatchPlugin::~MusixMatchPlugin()
qDebug() << Q_FUNC_INFO;
}
void
MusixMatchPlugin::namChangedSlot( QNetworkAccessManager *nam )
{
qDebug() << Q_FUNC_INFO;
if( !nam )
return;
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
}
void
MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{
qDebug() << Q_FUNC_INFO;
if( !isValidTrackData( requestData ) || !requestData.input.canConvert< QVariantMap >() || m_nam.isNull() || requestData.type != Tomahawk::InfoSystem::InfoTrackLyrics )
if( !isValidTrackData( requestData ) || !requestData.input.canConvert< QVariantMap >() || requestData.type != Tomahawk::InfoSystem::InfoTrackLyrics )
return;
QVariantMap hash = requestData.input.value< QVariantMap >();
QString artist = hash["artistName"].toString();
@@ -72,7 +62,7 @@ MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
url.addQueryItem( "apikey", m_apiKey );
url.addQueryItem( "q_artist", artist );
url.addQueryItem( "q_track", track );
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
connect( reply, SIGNAL( finished() ), SLOT( trackSearchSlot() ) );
@@ -126,7 +116,7 @@ MusixMatchPlugin::trackSearchSlot()
QUrl url( requestString );
url.addQueryItem( "apikey", m_apiKey );
url.addQueryItem( "track_id", track_id );
QNetworkReply* newReply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
connect( newReply, SIGNAL( finished() ), SLOT( trackLyricsSlot() ) );
}

View File

@@ -42,8 +42,6 @@ public slots:
void trackSearchSlot();
void trackLyricsSlot();
void namChangedSlot( QNetworkAccessManager *nam );
protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
@@ -64,8 +62,6 @@ private:
bool isValidTrackData( Tomahawk::InfoSystem::InfoRequestData requestData );
QString m_apiKey;
QWeakPointer< QNetworkAccessManager > m_nam;
};
}

View File

@@ -47,26 +47,7 @@ SpotifyPlugin::SpotifyPlugin()
m_supportedGetTypes << InfoChart << InfoChartCapabilities;
}
SpotifyPlugin::~SpotifyPlugin()
{
qDebug() << Q_FUNC_INFO;
}
void
SpotifyPlugin::namChangedSlot( QNetworkAccessManager *nam )
{
tDebug() << "SpotifyPlugin: namChangedSLot";
qDebug() << Q_FUNC_INFO;
if( !nam )
return;
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
// we never need to re-fetch
// we never need to re-fetch
if ( !m_allChartsMap.isEmpty() )
return;
@@ -74,7 +55,7 @@ SpotifyPlugin::namChangedSlot( QNetworkAccessManager *nam )
tDebug() << "SpotifyPlugin: InfoChart fetching possible resources";
QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/charts" ) );
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
tDebug() << Q_FUNC_INFO << "fetching:" << url;
connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) );
m_chartsFetchJobs++;
@@ -82,6 +63,12 @@ SpotifyPlugin::namChangedSlot( QNetworkAccessManager *nam )
}
SpotifyPlugin::~SpotifyPlugin()
{
qDebug() << Q_FUNC_INFO;
}
void
SpotifyPlugin::dataError( Tomahawk::InfoSystem::InfoRequestData requestData )
{
@@ -164,14 +151,6 @@ SpotifyPlugin::fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData req
void
SpotifyPlugin::notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
{
if ( !m_nam.data() )
{
tLog() << Q_FUNC_INFO << "Have a null QNAM, uh oh";
emit info( requestData, QVariant() );
return;
}
switch ( requestData.type )
{
@@ -181,7 +160,7 @@ SpotifyPlugin::notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, To
QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/%1/" ).arg( criteria["chart_id"] ) );
qDebug() << Q_FUNC_INFO << "Getting chart url" << url;
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );
return;

View File

@@ -53,7 +53,6 @@ public:
public slots:
void chartReturned();
void chartTypes();
void namChangedSlot( QNetworkAccessManager *nam );
protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
@@ -70,7 +69,6 @@ private:
QVariantMap m_allChartsMap;
uint m_chartsFetchJobs;
QList< InfoRequestData > m_cachedRequests;
QWeakPointer< QNetworkAccessManager > m_nam;
};
}

View File

@@ -160,11 +160,6 @@ AdiumPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVar
m_pauseTimer->stop();
}
void
AdiumPlugin::namChangedSlot( QNetworkAccessManager* nam )
{
Q_UNUSED( nam )
}
/** Audio state slots */
void

View File

@@ -49,8 +49,6 @@ protected slots:
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
public slots:
void namChangedSlot( QNetworkAccessManager* nam );
virtual void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
{
Q_UNUSED( criteria );

View File

@@ -35,8 +35,6 @@ public:
FdoNotifyPlugin();
virtual ~FdoNotifyPlugin();
virtual void namChangedSlot( QNetworkAccessManager* ) {}
protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{

View File

@@ -117,8 +117,6 @@ public:
void setVolume( double value );
public slots:
void namChangedSlot( QNetworkAccessManager* /*nam*/ ) {} // unused
virtual void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
{
Q_UNUSED( criteria );

View File

@@ -72,8 +72,6 @@ InfoSystem::InfoSystem( QObject *parent )
QMetaObject::invokeMethod( m_worker.data(), "init", Qt::QueuedConnection, Q_ARG( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >, m_cache ) );
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( newNam() ) );
connect( m_cache.data(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
m_worker.data(), SLOT( infoSlot( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
@@ -115,14 +113,6 @@ InfoSystem::~InfoSystem()
}
void
InfoSystem::newNam() const
{
qDebug() << Q_FUNC_INFO;
QMetaObject::invokeMethod( m_worker.data(), "newNam", Qt::QueuedConnection );
}
void
InfoSystem::getInfo( const InfoRequestData &requestData )
{

View File

@@ -185,8 +185,6 @@ protected slots:
virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data ) = 0;
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) = 0;
virtual void namChangedSlot( QNetworkAccessManager *nam ) = 0;
protected:
InfoType m_type;
QSet< InfoType > m_supportedGetTypes;
@@ -251,9 +249,6 @@ signals:
void finished( QString target );
void finished( QString target, Tomahawk::InfoSystem::InfoType type );
public slots:
void newNam() const;
private:
QWeakPointer< InfoSystemCache > m_cache;
QWeakPointer< InfoSystemWorker > m_worker;

View File

@@ -141,15 +141,7 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac
cache.data(),
SLOT( updateCacheSlot( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) )
);
connect(
this,
SIGNAL( namChanged( QNetworkAccessManager* ) ),
plugin.data(),
SLOT( namChangedSlot( QNetworkAccessManager* ) )
);
}
QMetaObject::invokeMethod( this, "newNam" );
}
@@ -348,73 +340,6 @@ InfoSystemWorker::checkTimeoutsTimerFired()
}
QNetworkAccessManager*
InfoSystemWorker::nam() const
{
if ( m_nam.isNull() )
return 0;
return m_nam.data();
}
void
InfoSystemWorker::newNam()
{
QNetworkAccessManager *oldNam = TomahawkUtils::nam();
if ( oldNam && oldNam->thread() == thread() )
{
if ( m_nam.data() != oldNam )
{
m_nam = QWeakPointer< QNetworkAccessManager >( oldNam );
emit namChanged( m_nam.data() );
}
return;
}
if
(
oldNam &&
!m_nam.isNull() &&
oldNam->configuration() == m_nam.data()->configuration() &&
oldNam->networkAccessible() == m_nam.data()->networkAccessible()
)
{
TomahawkUtils::NetworkProxyFactory fac1 = *( dynamic_cast< TomahawkUtils::NetworkProxyFactory * >( oldNam->proxyFactory() ) );
TomahawkUtils::NetworkProxyFactory fac2 = *( dynamic_cast< TomahawkUtils::NetworkProxyFactory * >( m_nam.data()->proxyFactory() ) );
if ( fac1 == fac2 )
return;
}
QNetworkAccessManager* newNam;
#ifdef LIBLASTFM_FOUND
newNam = new lastfm::NetworkAccessManager( this );
#else
newNam = new QNetworkAccessManager( this );
#endif
if ( !m_nam.isNull() )
delete m_nam.data();
if ( !oldNam )
oldNam = new QNetworkAccessManager();
TomahawkUtils::NetworkProxyFactory* oldProxyFactory = TomahawkUtils::proxyFactory();
if ( !oldProxyFactory )
oldProxyFactory = new TomahawkUtils::NetworkProxyFactory();
newNam->setConfiguration( oldNam->configuration() );
newNam->setNetworkAccessible( oldNam->networkAccessible() );
TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() );
newProxyFactory->setProxy( oldProxyFactory->proxy() );
newNam->setProxyFactory( newProxyFactory );
m_nam = QWeakPointer< QNetworkAccessManager >( newNam );
emit namChanged( m_nam.data() );
//FIXME: Currently leaking nam/proxyfactory above -- how to change in a thread-safe way?
}
} //namespace InfoSystem
} //namespace Tomahawk

View File

@@ -54,8 +54,6 @@ signals:
void finished( QString target );
void finished( QString target, Tomahawk::InfoSystem::InfoType type );
void namChanged( QNetworkAccessManager* );
public slots:
void init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > cache );
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
@@ -63,8 +61,6 @@ public slots:
void infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void newNam();
private slots:
void checkTimeoutsTimerFired();
@@ -84,8 +80,6 @@ private:
QMap< InfoType, QList< InfoPluginPtr > > m_infoGetMap;
QMap< InfoType, QList< InfoPluginPtr > > m_infoPushMap;
QWeakPointer< QNetworkAccessManager> m_nam;
QTimer m_checkTimeoutsTimer;
};

View File

@@ -539,7 +539,7 @@ setProxyFactory( NetworkProxyFactory* factory )
s_proxyFactory = factory;
NetworkProxyFactory::setApplicationProxyFactory( s_proxyFactory );
//nam takes ownership so set a copy, not the global one
if ( s_nam )
if ( !s_nam.isNull() )
{
TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
newProxyFactory->setNoProxyHosts( factory->noProxyHosts() );

View File

@@ -415,21 +415,9 @@ SettingsDialog::testLastFmLogin()
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 );
// ensure they have up-to-date settings
lastfm::setNetworkAccessManager( TomahawkUtils::nam() );
QNetworkReply* authJob = lastfm::ws::post( query );
connect( authJob, SIGNAL( finished() ), SLOT( onLastFmFinished() ) );

View File

@@ -159,10 +159,12 @@ TomahawkApp::init()
TomahawkSettings* s = TomahawkSettings::instance();
tDebug( LOGINFO ) << "Setting NAM.";
#ifdef LIBLASTFM_FOUND
TomahawkUtils::setNam( lastfm::nam() );
#else
#ifndef LIBLASTFM_FOUND
TomahawkUtils::setNam( new QNetworkAccessManager() );
#else
TomahawkUtils::setNam( lastfm::nam() );
//Ensure that liblastfm2 won't delete the nam out from under us, even though they created it
lastfm::setNetworkAccessManager( TomahawkUtils::nam() );
#endif
TomahawkUtils::NetworkProxyFactory* proxyFactory = new TomahawkUtils::NetworkProxyFactory();
@@ -178,6 +180,7 @@ TomahawkApp::init()
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) );
TomahawkUtils::setProxyFactory( proxyFactory );
m_audioEngine = QWeakPointer<AudioEngine>( new AudioEngine );
m_scanManager = QWeakPointer<ScanManager>( new ScanManager( this ) );

View File

@@ -160,7 +160,12 @@ lastfm::setNetworkAccessManager( QNetworkAccessManager* nam )
oldNam = threadNamHash[thread];
if ( oldNam == nam )
{
// If we're being passed back our own NAM, assume they want to
// ensure that we don't delete it out from under them
ourNamSet.remove( thread );
return;
}
threadNamHash[thread] = nam;
ourNamSet.remove( thread );