diff --git a/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp index c5810440e..3ae3edfc4 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp @@ -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 ) ); } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.h b/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.h index 21c81c5a9..4d91caad8 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.h @@ -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; }; diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index a0b3f9475..1a5094cdb 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -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 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 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() ) ); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h index c44b88ccf..285420a14 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h @@ -53,7 +53,6 @@ public: public slots: void chartReturned(); void chartTypes(); - void namChangedSlot( QNetworkAccessManager *nam ); protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.cpp index 3d4b1e02b..2303a6d22 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.cpp @@ -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 ) { diff --git a/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.h index bd59193c8..73b7932de 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.h @@ -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 ); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp index dd6a4b7b1..a1df2b20c 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp @@ -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 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 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; diff --git a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h index a13c0299d..cbdfb000d 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h @@ -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; }; } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp index ed7681642..9d950ad9d 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp @@ -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 ) { diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h index fbd372e02..4850fb44c 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h @@ -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 ); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp index 8c0b3c2f4..12f96599e 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp @@ -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() ) ); } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.h b/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.h index 444b30809..5a2414cc0 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.h @@ -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; }; } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.cpp index 05811765a..48eec09bd 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.cpp @@ -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() ) ); } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.h index 40b1cc536..d0c437b77 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.h @@ -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; }; } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp index 245ceb593..3ce6cdb3a 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp @@ -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; diff --git a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h index 4a27d826c..e691d5aef 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h @@ -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; }; } diff --git a/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.cpp b/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.cpp index 20b907bcc..81626dcbd 100644 --- a/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.cpp @@ -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 diff --git a/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.h b/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.h index 5f12a510f..5c9d8b5c2 100644 --- a/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.h @@ -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 ); diff --git a/src/libtomahawk/infosystem/infoplugins/unix/fdonotifyplugin.h b/src/libtomahawk/infosystem/infoplugins/unix/fdonotifyplugin.h index d5fbc4759..da0e75c54 100644 --- a/src/libtomahawk/infosystem/infoplugins/unix/fdonotifyplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/unix/fdonotifyplugin.h @@ -35,8 +35,6 @@ public: FdoNotifyPlugin(); virtual ~FdoNotifyPlugin(); - virtual void namChangedSlot( QNetworkAccessManager* ) {} - protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) { diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h index 81d8d1507..2ba684808 100644 --- a/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h @@ -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 ); diff --git a/src/libtomahawk/infosystem/infosystem.cpp b/src/libtomahawk/infosystem/infosystem.cpp index 505aa2119..0ebac2411 100644 --- a/src/libtomahawk/infosystem/infosystem.cpp +++ b/src/libtomahawk/infosystem/infosystem.cpp @@ -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 ) { diff --git a/src/libtomahawk/infosystem/infosystem.h b/src/libtomahawk/infosystem/infosystem.h index 01be362e5..3a95520af 100644 --- a/src/libtomahawk/infosystem/infosystem.h +++ b/src/libtomahawk/infosystem/infosystem.h @@ -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; diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index b58394130..229c79536 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -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 diff --git a/src/libtomahawk/infosystem/infosystemworker.h b/src/libtomahawk/infosystem/infosystemworker.h index 3bcdd1b62..2368f28bf 100644 --- a/src/libtomahawk/infosystem/infosystemworker.h +++ b/src/libtomahawk/infosystem/infosystemworker.h @@ -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; }; diff --git a/src/libtomahawk/utils/tomahawkutils.cpp b/src/libtomahawk/utils/tomahawkutils.cpp index 3797557da..c56700ed6 100644 --- a/src/libtomahawk/utils/tomahawkutils.cpp +++ b/src/libtomahawk/utils/tomahawkutils.cpp @@ -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() ); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 676888071..0c75b151c 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -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() ) ); diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index c3c401ae4..d4e0c2add 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -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( new AudioEngine ); m_scanManager = QWeakPointer( new ScanManager( this ) ); diff --git a/thirdparty/liblastfm2/src/ws/ws.cpp b/thirdparty/liblastfm2/src/ws/ws.cpp index 956fa5adb..b2ad56860 100644 --- a/thirdparty/liblastfm2/src/ws/ws.cpp +++ b/thirdparty/liblastfm2/src/ws/ws.cpp @@ -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 );