mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-09-02 02:12:47 +02:00
Move nam() out of TomahawkUtils.h
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "sip/HatchetSip.h"
|
#include "sip/HatchetSip.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
#include "utils/NetworkAccessManager.cpp"
|
||||||
|
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@@ -243,7 +244,7 @@ HatchetAccount::loginWithPassword( const QString& username, const QString& passw
|
|||||||
|
|
||||||
QNetworkRequest req( QUrl( c_loginServer + "/auth/credentials") );
|
QNetworkRequest req( QUrl( c_loginServer + "/auth/credentials") );
|
||||||
req.setHeader( QNetworkRequest::ContentTypeHeader, "application/json; charset=utf-8" );
|
req.setHeader( QNetworkRequest::ContentTypeHeader, "application/json; charset=utf-8" );
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->post( req, msgJson );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->post( req, msgJson );
|
||||||
|
|
||||||
NewClosure( reply, SIGNAL( finished() ), this, SLOT( onPasswordLoginFinished( QNetworkReply*, const QString& ) ), reply, username );
|
NewClosure( reply, SIGNAL( finished() ), this, SLOT( onPasswordLoginFinished( QNetworkReply*, const QString& ) ), reply, username );
|
||||||
}
|
}
|
||||||
@@ -264,7 +265,7 @@ HatchetAccount::fetchAccessTokens( const QString& type )
|
|||||||
tLog() << "Fetching access tokens";
|
tLog() << "Fetching access tokens";
|
||||||
QNetworkRequest req( QUrl( c_accessTokenServer + "/tokens/" + type + "?authtoken=" + authToken() ) );
|
QNetworkRequest req( QUrl( c_accessTokenServer + "/tokens/" + type + "?authtoken=" + authToken() ) );
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), this, SLOT( onFetchAccessTokensFinished() ) );
|
connect( reply, SIGNAL( finished() ), this, SLOT( onFetchAccessTokensFinished() ) );
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
#include "sip/PeerInfo.h"
|
#include "sip/PeerInfo.h"
|
||||||
|
#include "utils/NetworkProxyFactory.h"
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "TomahawkVersion.h"
|
#include "TomahawkVersion.h"
|
||||||
@@ -604,7 +605,7 @@ XmppSipPlugin::configurationChanged()
|
|||||||
void
|
void
|
||||||
XmppSipPlugin::setupClientHelper()
|
XmppSipPlugin::setupClientHelper()
|
||||||
{
|
{
|
||||||
m_client->setProxyFactory( TomahawkUtils::proxyFactory( true ) );
|
m_client->setProxyFactory( Tomahawk::Utils::proxyFactory( true ) );
|
||||||
Jreen::JID jid = Jreen::JID( m_currentUsername );
|
Jreen::JID jid = Jreen::JID( m_currentUsername );
|
||||||
m_client->setJID( jid );
|
m_client->setJID( jid );
|
||||||
m_client->setPassword( m_currentPassword );
|
m_client->setPassword( m_currentPassword );
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/TomahawkCache.h"
|
#include "utils/TomahawkCache.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
|
||||||
#include <qjson/parser.h>
|
#include <qjson/parser.h>
|
||||||
@@ -280,7 +281,7 @@ ChartsPlugin::fetchChartSourcesList( bool fetchOnlySourceList )
|
|||||||
|
|
||||||
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
reply->setProperty( "only_source_list", fetchOnlySourceList );
|
reply->setProperty( "only_source_list", fetchOnlySourceList );
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( chartSourcesList() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( chartSourcesList() ) );
|
||||||
@@ -376,7 +377,7 @@ ChartsPlugin::fetchSource(const QString& source)
|
|||||||
QUrl url = QUrl( QString( CHART_URL "charts/%1" ).arg( source ) );
|
QUrl url = QUrl( QString( CHART_URL "charts/%1" ).arg( source ) );
|
||||||
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
reply->setProperty( "chart_source", source );
|
reply->setProperty( "chart_source", source );
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << "fetching:" << url;
|
tDebug() << Q_FUNC_INFO << "fetching:" << url;
|
||||||
@@ -422,7 +423,7 @@ ChartsPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData, con
|
|||||||
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetching: " << url;
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetching: " << url;
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <qjson/parser.h>
|
#include <qjson/parser.h>
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ DiscogsPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requestD
|
|||||||
|
|
||||||
QNetworkRequest req( url );
|
QNetworkRequest req( url );
|
||||||
req.setRawHeader( "User-Agent", "TomahawkPlayer/1.0 +http://tomahawk-player.org" );
|
req.setRawHeader( "User-Agent", "TomahawkPlayer/1.0 +http://tomahawk-player.org" );
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
||||||
|
|
||||||
NewClosure( reply, SIGNAL( finished() ), this, SLOT( albumSearchSlot( Tomahawk::InfoSystem::InfoRequestData, QNetworkReply* ) ), requestData, reply );
|
NewClosure( reply, SIGNAL( finished() ), this, SLOT( albumSearchSlot( Tomahawk::InfoSystem::InfoRequestData, QNetworkReply* ) ), requestData, reply );
|
||||||
break;
|
break;
|
||||||
@@ -136,7 +137,7 @@ DiscogsPlugin::albumSearchSlot( const InfoRequestData &requestData, QNetworkRepl
|
|||||||
QNetworkRequest req( url );
|
QNetworkRequest req( url );
|
||||||
req.setRawHeader( "User-Agent", "TomahawkPlayer/1.0 +http://tomahawk-player.org" );
|
req.setRawHeader( "User-Agent", "TomahawkPlayer/1.0 +http://tomahawk-player.org" );
|
||||||
|
|
||||||
QNetworkReply* reply2 = TomahawkUtils::nam()->get( req );
|
QNetworkReply* reply2 = Tomahawk::Utils::nam()->get( req );
|
||||||
NewClosure( reply2, SIGNAL( finished() ), this, SLOT( albumInfoSlot( Tomahawk::InfoSystem::InfoRequestData, QNetworkReply* ) ), requestData, reply2 );
|
NewClosure( reply2, SIGNAL( finished() ), this, SLOT( albumInfoSlot( Tomahawk::InfoSystem::InfoRequestData, QNetworkReply* ) ), requestData, reply2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,10 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "EchonestPlugin.h"
|
#include "EchonestPlugin.h"
|
||||||
#include <echonest/ArtistTypes.h>
|
|
||||||
|
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
|
#include <echonest/ArtistTypes.h>
|
||||||
|
|
||||||
#include <QNetworkConfiguration>
|
#include <QNetworkConfiguration>
|
||||||
|
|
||||||
@@ -50,7 +52,7 @@ EchonestPlugin::~EchonestPlugin()
|
|||||||
void
|
void
|
||||||
EchonestPlugin::init()
|
EchonestPlugin::init()
|
||||||
{
|
{
|
||||||
Echonest::Config::instance()->setNetworkAccessManager( TomahawkUtils::nam() );
|
Echonest::Config::instance()->setNetworkAccessManager( Tomahawk::Utils::nam() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "infosystem/InfoSystemWorker.h"
|
#include "infosystem/InfoSystemWorker.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
|
||||||
#define HYPEM_URL "http://hypem.com/playlist/"
|
#define HYPEM_URL "http://hypem.com/playlist/"
|
||||||
@@ -204,7 +205,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) );
|
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;
|
qDebug() << Q_FUNC_INFO << "Getting chart url" << url;
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );
|
||||||
return;
|
return;
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QDomDocument>
|
#include <QDomDocument>
|
||||||
@@ -110,7 +111,7 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
|||||||
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
|
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << url.toString();
|
tDebug() << Q_FUNC_INFO << url.toString();
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( gotReleaseGroupsSlot() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( gotReleaseGroupsSlot() ) );
|
||||||
@@ -130,7 +131,7 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
|||||||
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
|
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << url.toString();
|
tDebug() << Q_FUNC_INFO << url.toString();
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( gotReleasesSlot() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( gotReleasesSlot() ) );
|
||||||
@@ -236,7 +237,7 @@ MusicBrainzPlugin::gotReleasesSlot()
|
|||||||
TomahawkUtils::urlAddQueryItem( url, "inc", "recordings" );
|
TomahawkUtils::urlAddQueryItem( url, "inc", "recordings" );
|
||||||
tDebug() << Q_FUNC_INFO << url.toString();
|
tDebug() << Q_FUNC_INFO << url.toString();
|
||||||
|
|
||||||
QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* newReply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
|
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
|
||||||
connect( newReply, SIGNAL( finished() ), SLOT( gotRecordingsSlot() ) );
|
connect( newReply, SIGNAL( finished() ), SLOT( gotRecordingsSlot() ) );
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QDomDocument>
|
#include <QDomDocument>
|
||||||
@@ -68,7 +69,7 @@ MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
|||||||
TomahawkUtils::urlAddQueryItem( url, "q_artist", artist );
|
TomahawkUtils::urlAddQueryItem( url, "q_artist", artist );
|
||||||
TomahawkUtils::urlAddQueryItem( url, "q_track", track );
|
TomahawkUtils::urlAddQueryItem( url, "q_track", track );
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( trackSearchSlot() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( trackSearchSlot() ) );
|
||||||
@@ -128,7 +129,7 @@ MusixMatchPlugin::trackSearchSlot()
|
|||||||
TomahawkUtils::urlAddQueryItem( url, "apikey", m_apiKey );
|
TomahawkUtils::urlAddQueryItem( url, "apikey", m_apiKey );
|
||||||
TomahawkUtils::urlAddQueryItem( url, "track_id", track_id );
|
TomahawkUtils::urlAddQueryItem( url, "track_id", track_id );
|
||||||
|
|
||||||
QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* newReply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
|
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
|
||||||
connect( newReply, SIGNAL( finished() ), SLOT( trackLyricsSlot() ) );
|
connect( newReply, SIGNAL( finished() ), SLOT( trackLyricsSlot() ) );
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/TomahawkCache.h"
|
#include "utils/TomahawkCache.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <qjson/parser.h>
|
#include <qjson/parser.h>
|
||||||
#include <qjson/serializer.h>
|
#include <qjson/serializer.h>
|
||||||
@@ -268,7 +269,7 @@ NewReleasesPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
|||||||
|
|
||||||
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest ( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest ( url ) );
|
||||||
reply->setProperty( "only_source_list", true );
|
reply->setProperty( "only_source_list", true );
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetching:" << url;
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetching:" << url;
|
||||||
@@ -401,7 +402,7 @@ NewReleasesPlugin::fetchAllNRSources()
|
|||||||
|
|
||||||
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
reply->setProperty( "nr_source", source[ "nr_source" ] );
|
reply->setProperty( "nr_source", source[ "nr_source" ] );
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << "fetching:" << url;
|
tDebug() << Q_FUNC_INFO << "fetching:" << url;
|
||||||
@@ -423,7 +424,7 @@ NewReleasesPlugin::fetchNR( InfoRequestData requestData, const QString& source,
|
|||||||
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetching: " << url;
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetching: " << url;
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
|
|
||||||
connect ( reply, SIGNAL( finished() ), SLOT( nrReturned() ) );
|
connect ( reply, SIGNAL( finished() ), SLOT( nrReturned() ) );
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include "RoviPlugin.h"
|
#include "RoviPlugin.h"
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <qjson/parser.h>
|
#include <qjson/parser.h>
|
||||||
|
|
||||||
@@ -183,7 +184,7 @@ RoviPlugin::makeRequest( QUrl url )
|
|||||||
TomahawkUtils::urlAddQueryItem( url, "sig", generateSig() );
|
TomahawkUtils::urlAddQueryItem( url, "sig", generateSig() );
|
||||||
|
|
||||||
qDebug() << "Rovi request url:" << url.toString();
|
qDebug() << "Rovi request url:" << url.toString();
|
||||||
return TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
return Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
#include "CountryUtils.h"
|
#include "CountryUtils.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
|
||||||
@@ -147,7 +148,7 @@ SpotifyPlugin::notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, To
|
|||||||
QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/%1/" ).arg( criteria["chart_id"] ) );
|
QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/%1/" ).arg( criteria["chart_id"] ) );
|
||||||
qDebug() << Q_FUNC_INFO << "Getting chart url" << url;
|
qDebug() << Q_FUNC_INFO << "Getting chart url" << url;
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );
|
||||||
return;
|
return;
|
||||||
@@ -164,7 +165,7 @@ SpotifyPlugin::notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, To
|
|||||||
tDebug() << "SpotifyPlugin: InfoChart fetching possible resources";
|
tDebug() << "SpotifyPlugin: InfoChart fetching possible resources";
|
||||||
|
|
||||||
QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/charts" ) );
|
QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/charts" ) );
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
tDebug() << Q_FUNC_INFO << "fetching:" << url;
|
tDebug() << Q_FUNC_INFO << "fetching:" << url;
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) );
|
||||||
m_chartsFetchJobs++;
|
m_chartsFetchJobs++;
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include "accounts/AccountManager.h"
|
#include "accounts/AccountManager.h"
|
||||||
#include "utils/BinaryInstallerHelper.h"
|
#include "utils/BinaryInstallerHelper.h"
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <attica/downloaditem.h>
|
#include <attica/downloaditem.h>
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ AtticaManager::AtticaManager( QObject* parent )
|
|||||||
// m_manager.addProviderFile( QUrl( "http://bakery.tomahawk-player.org/resolvers/providers.xml" ) );
|
// m_manager.addProviderFile( QUrl( "http://bakery.tomahawk-player.org/resolvers/providers.xml" ) );
|
||||||
|
|
||||||
const QString url = QString( "%1/resolvers/providers.xml?version=%2" ).arg( hostname() ).arg( TomahawkUtils::appFriendlyVersion() );
|
const QString url = QString( "%1/resolvers/providers.xml?version=%2" ).arg( hostname() ).arg( TomahawkUtils::appFriendlyVersion() );
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( QUrl( url ) ) );
|
||||||
NewClosure( reply, SIGNAL( finished() ), this, SLOT( providerFetched( QNetworkReply* ) ), reply );
|
NewClosure( reply, SIGNAL( finished() ), this, SLOT( providerFetched( QNetworkReply* ) ), reply );
|
||||||
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( providerError( QNetworkReply::NetworkError ) ) );
|
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( providerError( QNetworkReply::NetworkError ) ) );
|
||||||
|
|
||||||
@@ -103,7 +104,7 @@ AtticaManager::fetchMissingIcons()
|
|||||||
|
|
||||||
if ( !m_resolverStates.value( resolver.id() ).pixmap && !resolver.icons().isEmpty() && !resolver.icons().first().url().isEmpty() )
|
if ( !m_resolverStates.value( resolver.id() ).pixmap && !resolver.icons().isEmpty() && !resolver.icons().first().url().isEmpty() )
|
||||||
{
|
{
|
||||||
QNetworkReply* fetch = TomahawkUtils::nam()->get( QNetworkRequest( resolver.icons().first().url() ) );
|
QNetworkReply* fetch = Tomahawk::Utils::nam()->get( QNetworkRequest( resolver.icons().first().url() ) );
|
||||||
fetch->setProperty( "resolverId", resolver.id() );
|
fetch->setProperty( "resolverId", resolver.id() );
|
||||||
|
|
||||||
connect( fetch, SIGNAL( finished() ), this, SLOT( resolverIconFetched() ) );
|
connect( fetch, SIGNAL( finished() ), this, SLOT( resolverIconFetched() ) );
|
||||||
@@ -550,7 +551,7 @@ void AtticaManager::doInstallResolver( const Content& resolver, bool autoCreate,
|
|||||||
QUrl url( QString( "%1/resolvers/v1/content/download/%2/1" ).arg( hostname() ).arg( resolver.id() ) );
|
QUrl url( QString( "%1/resolvers/v1/content/download/%2/1" ).arg( hostname() ).arg( resolver.id() ) );
|
||||||
|
|
||||||
TomahawkUtils::urlAddQueryItem( url, "tomahawkversion", TomahawkUtils::appFriendlyVersion() );
|
TomahawkUtils::urlAddQueryItem( url, "tomahawkversion", TomahawkUtils::appFriendlyVersion() );
|
||||||
QNetworkReply* r = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* r = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
NewClosure( r, SIGNAL( finished() ), this, SLOT( resolverDownloadFinished( QNetworkReply* ) ), r );
|
NewClosure( r, SIGNAL( finished() ), this, SLOT( resolverDownloadFinished( QNetworkReply* ) ), r );
|
||||||
r->setProperty( "resolverId", resolver.id() );
|
r->setProperty( "resolverId", resolver.id() );
|
||||||
r->setProperty( "createAccount", autoCreate );
|
r->setProperty( "createAccount", autoCreate );
|
||||||
@@ -611,7 +612,7 @@ AtticaManager::resolverDownloadFinished ( QNetworkReply *j )
|
|||||||
tLog() << "Found overridden signature in binary download:" << sig;
|
tLog() << "Found overridden signature in binary download:" << sig;
|
||||||
signature = sig;
|
signature = sig;
|
||||||
}
|
}
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
||||||
connect( reply, SIGNAL( finished() ), this, SLOT( payloadFetched() ) );
|
connect( reply, SIGNAL( finished() ), this, SLOT( payloadFetched() ) );
|
||||||
reply->setProperty( "resolverId", j->property( "resolverId" ) );
|
reply->setProperty( "resolverId", j->property( "resolverId" ) );
|
||||||
reply->setProperty( "createAccount", j->property( "createAccount" ) );
|
reply->setProperty( "createAccount", j->property( "createAccount" ) );
|
||||||
|
@@ -124,6 +124,8 @@ set( libGuiSources
|
|||||||
utils/SharedTimeLine.cpp
|
utils/SharedTimeLine.cpp
|
||||||
utils/ResultUrlChecker.cpp
|
utils/ResultUrlChecker.cpp
|
||||||
utils/NetworkReply.cpp
|
utils/NetworkReply.cpp
|
||||||
|
utils/NetworkProxyFactory.cpp
|
||||||
|
utils/NetworkAccessManager.cpp
|
||||||
|
|
||||||
widgets/AnimatedCounterLabel.cpp
|
widgets/AnimatedCounterLabel.cpp
|
||||||
widgets/BasicHeader.cpp
|
widgets/BasicHeader.cpp
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/XspfLoader.h"
|
#include "utils/XspfLoader.h"
|
||||||
#include "utils/XspfGenerator.h"
|
#include "utils/XspfGenerator.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
#include "widgets/SearchWidget.h"
|
#include "widgets/SearchWidget.h"
|
||||||
|
|
||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
@@ -157,7 +158,7 @@ GlobalActionManager::shortenLink( const QUrl& url, const QVariant& callbackObj )
|
|||||||
request.setUrl( url );
|
request.setUrl( url );
|
||||||
|
|
||||||
qDebug() << "Doing lookup:" << url.toEncoded();
|
qDebug() << "Doing lookup:" << url.toEncoded();
|
||||||
QNetworkReply *reply = TomahawkUtils::nam()->get( request );
|
QNetworkReply *reply = Tomahawk::Utils::nam()->get( request );
|
||||||
if ( callbackObj.isValid() )
|
if ( callbackObj.isValid() )
|
||||||
reply->setProperty( "callbackobj", callbackObj );
|
reply->setProperty( "callbackobj", callbackObj );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( shortenLinkRequestFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( shortenLinkRequestFinished() ) );
|
||||||
@@ -245,7 +246,7 @@ GlobalActionManager::getShortLink( const playlist_ptr& pl )
|
|||||||
const QUrl url( QString( "%1/p/").arg( hostname() ) );
|
const QUrl url( QString( "%1/p/").arg( hostname() ) );
|
||||||
QNetworkRequest req( url );
|
QNetworkRequest req( url );
|
||||||
req.setHeader( QNetworkRequest::ContentTypeHeader, QString( "multipart/form-data; boundary=%1" ).arg( QString::fromLatin1( boundary ) ) );
|
req.setHeader( QNetworkRequest::ContentTypeHeader, QString( "multipart/form-data; boundary=%1" ).arg( QString::fromLatin1( boundary ) ) );
|
||||||
QNetworkReply *reply = TomahawkUtils::nam()->post( req, data );
|
QNetworkReply *reply = Tomahawk::Utils::nam()->post( req, data );
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( postShortenFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( postShortenFinished() ) );
|
||||||
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) );
|
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) );
|
||||||
|
@@ -19,8 +19,6 @@
|
|||||||
#include "LastFmConfig.h"
|
#include "LastFmConfig.h"
|
||||||
#include "ui_LastFmConfig.h"
|
#include "ui_LastFmConfig.h"
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
|
||||||
|
|
||||||
#include "LastFmAccount.h"
|
#include "LastFmAccount.h"
|
||||||
#include "database/Database.h"
|
#include "database/Database.h"
|
||||||
#include "database/DatabaseCommand_LogPlayback.h"
|
#include "database/DatabaseCommand_LogPlayback.h"
|
||||||
@@ -29,12 +27,15 @@
|
|||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <lastfm/ws.h>
|
#include <lastfm/ws.h>
|
||||||
#include <lastfm/User.h>
|
#include <lastfm/User.h>
|
||||||
#include <lastfm/XmlQuery.h>
|
#include <lastfm/XmlQuery.h>
|
||||||
#include <lastfm/Track.h>
|
#include <lastfm/Track.h>
|
||||||
|
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
using namespace Tomahawk::Accounts;
|
using namespace Tomahawk::Accounts;
|
||||||
|
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ LastFmConfig::testLogin()
|
|||||||
query[ "authToken" ] = authToken;
|
query[ "authToken" ] = authToken;
|
||||||
|
|
||||||
// ensure they have up-to-date settings
|
// ensure they have up-to-date settings
|
||||||
lastfm::setNetworkAccessManager( TomahawkUtils::nam() );
|
lastfm::setNetworkAccessManager( Tomahawk::Utils::nam() );
|
||||||
|
|
||||||
QNetworkReply* authJob = lastfm::ws::post( query );
|
QNetworkReply* authJob = lastfm::ws::post( query );
|
||||||
|
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include "accounts/lastfm/LastFmAccount.h"
|
#include "accounts/lastfm/LastFmAccount.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <lastfm/ws.h>
|
#include <lastfm/ws.h>
|
||||||
#include <lastfm/XmlQuery.h>
|
#include <lastfm/XmlQuery.h>
|
||||||
@@ -64,7 +65,7 @@ LastFmInfoPlugin::init()
|
|||||||
lastfm::ws::ApiKey = "7194b85b6d1f424fe1668173a78c0c4a";
|
lastfm::ws::ApiKey = "7194b85b6d1f424fe1668173a78c0c4a";
|
||||||
lastfm::ws::SharedSecret = "ba80f1df6d27ae63e9cb1d33ccf2052f";
|
lastfm::ws::SharedSecret = "ba80f1df6d27ae63e9cb1d33ccf2052f";
|
||||||
lastfm::ws::Username = m_account.data()->username();
|
lastfm::ws::Username = m_account.data()->username();
|
||||||
lastfm::setNetworkAccessManager( TomahawkUtils::nam() );
|
lastfm::setNetworkAccessManager( Tomahawk::Utils::nam() );
|
||||||
|
|
||||||
m_pw = m_account.data()->password();
|
m_pw = m_account.data()->password();
|
||||||
|
|
||||||
@@ -411,7 +412,7 @@ LastFmInfoPlugin::fetchAlbumInfo( Tomahawk::InfoSystem::InfoRequestData requestD
|
|||||||
void
|
void
|
||||||
LastFmInfoPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
|
LastFmInfoPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||||
{
|
{
|
||||||
if ( !TomahawkUtils::nam() )
|
if ( !Tomahawk::Utils::nam() )
|
||||||
{
|
{
|
||||||
tLog() << "Have a null QNAM, uh oh";
|
tLog() << "Have a null QNAM, uh oh";
|
||||||
emit info( requestData, QVariant() );
|
emit info( requestData, QVariant() );
|
||||||
@@ -761,7 +762,7 @@ LastFmInfoPlugin::artistInfoReturned()
|
|||||||
imgurl = artist.imageUrl( lastfm::AbstractType::LargeImage );
|
imgurl = artist.imageUrl( lastfm::AbstractType::LargeImage );
|
||||||
|
|
||||||
QNetworkRequest req( imgurl );
|
QNetworkRequest req( imgurl );
|
||||||
QNetworkReply* newReply = TomahawkUtils::nam()->get( req );
|
QNetworkReply* newReply = Tomahawk::Utils::nam()->get( req );
|
||||||
newReply->setProperty( "requestData", reply->property( "requestData" ) );
|
newReply->setProperty( "requestData", reply->property( "requestData" ) );
|
||||||
connect( newReply, SIGNAL( finished() ), SLOT( coverArtReturned() ) );
|
connect( newReply, SIGNAL( finished() ), SLOT( coverArtReturned() ) );
|
||||||
}
|
}
|
||||||
@@ -786,7 +787,7 @@ LastFmInfoPlugin::albumInfoReturned()
|
|||||||
imgurl = QUrl( lfm["album"]["image size=large"].text() );
|
imgurl = QUrl( lfm["album"]["image size=large"].text() );
|
||||||
|
|
||||||
QNetworkRequest req( imgurl );
|
QNetworkRequest req( imgurl );
|
||||||
QNetworkReply* newReply = TomahawkUtils::nam()->get( req );
|
QNetworkReply* newReply = Tomahawk::Utils::nam()->get( req );
|
||||||
newReply->setProperty( "requestData", reply->property( "requestData" ) );
|
newReply->setProperty( "requestData", reply->property( "requestData" ) );
|
||||||
connect( newReply, SIGNAL( finished() ), SLOT( coverArtReturned() ) );
|
connect( newReply, SIGNAL( finished() ), SLOT( coverArtReturned() ) );
|
||||||
}
|
}
|
||||||
@@ -833,7 +834,7 @@ LastFmInfoPlugin::coverArtReturned()
|
|||||||
{
|
{
|
||||||
// Follow HTTP redirect
|
// Follow HTTP redirect
|
||||||
QNetworkRequest req( redir );
|
QNetworkRequest req( redir );
|
||||||
QNetworkReply* newReply = TomahawkUtils::nam()->get( req );
|
QNetworkReply* newReply = Tomahawk::Utils::nam()->get( req );
|
||||||
newReply->setProperty( "requestData", reply->property( "requestData" ) );
|
newReply->setProperty( "requestData", reply->property( "requestData" ) );
|
||||||
connect( newReply, SIGNAL( finished() ), SLOT( coverArtReturned() ) );
|
connect( newReply, SIGNAL( finished() ), SLOT( coverArtReturned() ) );
|
||||||
}
|
}
|
||||||
@@ -877,7 +878,7 @@ LastFmInfoPlugin::artistImagesReturned()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( !TomahawkUtils::nam() )
|
if ( !Tomahawk::Utils::nam() )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Uh oh, nam is null";
|
tLog() << Q_FUNC_INFO << "Uh oh, nam is null";
|
||||||
emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
|
emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
|
||||||
@@ -885,7 +886,7 @@ LastFmInfoPlugin::artistImagesReturned()
|
|||||||
}
|
}
|
||||||
// Follow HTTP redirect
|
// Follow HTTP redirect
|
||||||
QNetworkRequest req( redir );
|
QNetworkRequest req( redir );
|
||||||
QNetworkReply* newReply = TomahawkUtils::nam()->get( req );
|
QNetworkReply* newReply = Tomahawk::Utils::nam()->get( req );
|
||||||
newReply->setProperty( "requestData", reply->property( "requestData" ) );
|
newReply->setProperty( "requestData", reply->property( "requestData" ) );
|
||||||
connect( newReply, SIGNAL( finished() ), SLOT( artistImagesReturned() ) );
|
connect( newReply, SIGNAL( finished() ), SLOT( artistImagesReturned() ) );
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include "SpotifyAccount.h"
|
#include "SpotifyAccount.h"
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <qjson/parser.h>
|
#include <qjson/parser.h>
|
||||||
|
|
||||||
@@ -144,7 +145,7 @@ SpotifyInfoPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
|||||||
QUrl lookupUrl( "http://ws.spotify.com/search/1/album.json" );
|
QUrl lookupUrl( "http://ws.spotify.com/search/1/album.json" );
|
||||||
TomahawkUtils::urlAddQueryItem( lookupUrl, "q", QString( "%1 %2" ).arg( artist ).arg( album ) );
|
TomahawkUtils::urlAddQueryItem( lookupUrl, "q", QString( "%1 %2" ).arg( artist ).arg( album ) );
|
||||||
|
|
||||||
QNetworkReply * reply = TomahawkUtils::nam()->get( QNetworkRequest( lookupUrl ) );
|
QNetworkReply * reply = Tomahawk::Utils::nam()->get( QNetworkRequest( lookupUrl ) );
|
||||||
NewClosure( reply, SIGNAL( finished() ), this, SLOT( albumIdLookupFinished( QNetworkReply*, Tomahawk::InfoSystem::InfoRequestData ) ), reply, requestData );
|
NewClosure( reply, SIGNAL( finished() ), this, SLOT( albumIdLookupFinished( QNetworkReply*, Tomahawk::InfoSystem::InfoRequestData ) ), reply, requestData );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -234,7 +235,7 @@ SpotifyInfoPlugin::albumIdLookupFinished( QNetworkReply* reply, const InfoReques
|
|||||||
QUrl lookupUrl( QString( "http://spotikea.tomahawk-player.org/browse/%1" ).arg( id ) );
|
QUrl lookupUrl( QString( "http://spotikea.tomahawk-player.org/browse/%1" ).arg( id ) );
|
||||||
|
|
||||||
|
|
||||||
QNetworkReply * reply = TomahawkUtils::nam()->get( QNetworkRequest( lookupUrl ) );
|
QNetworkReply * reply = Tomahawk::Utils::nam()->get( QNetworkRequest( lookupUrl ) );
|
||||||
NewClosure( reply, SIGNAL( finished() ), this, SLOT( albumContentsLookupFinished( QNetworkReply*, Tomahawk::InfoSystem::InfoRequestData ) ), reply, requestData );
|
NewClosure( reply, SIGNAL( finished() ), this, SLOT( albumContentsLookupFinished( QNetworkReply*, Tomahawk::InfoSystem::InfoRequestData ) ), reply, requestData );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include "AclRegistry.h"
|
#include "AclRegistry.h"
|
||||||
#include "BufferIoDevice.h"
|
#include "BufferIoDevice.h"
|
||||||
@@ -183,7 +184,7 @@ Servent::startListening( QHostAddress ha, bool upnp, int port, Tomahawk::Network
|
|||||||
d->externalPort = externalPort;
|
d->externalPort = externalPort;
|
||||||
if ( autoDetectExternalIp )
|
if ( autoDetectExternalIp )
|
||||||
{
|
{
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( "http://toma.hk/?stat=1" ) ) );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( QUrl( "http://toma.hk/?stat=1" ) ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( ipDetected() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( ipDetected() ) );
|
||||||
// Not emitting ready here as we are not done.
|
// Not emitting ready here as we are not done.
|
||||||
}
|
}
|
||||||
@@ -1385,7 +1386,7 @@ Servent::httpIODeviceFactory( const Tomahawk::result_ptr& result,
|
|||||||
boost::function< void ( QSharedPointer< QIODevice >& ) > callback )
|
boost::function< void ( QSharedPointer< QIODevice >& ) > callback )
|
||||||
{
|
{
|
||||||
QNetworkRequest req( result->url() );
|
QNetworkRequest req( result->url() );
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
||||||
|
|
||||||
//boost::functions cannot accept temporaries as parameters
|
//boost::functions cannot accept temporaries as parameters
|
||||||
QSharedPointer< QIODevice > sp = QSharedPointer< QIODevice >( reply, &QObject::deleteLater );
|
QSharedPointer< QIODevice > sp = QSharedPointer< QIODevice >( reply, &QObject::deleteLater );
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
#include "TomahawkVersion.h"
|
#include "TomahawkVersion.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -873,7 +874,7 @@ JSResolver::loadCollections()
|
|||||||
{
|
{
|
||||||
QNetworkRequest req( iconUrl );
|
QNetworkRequest req( iconUrl );
|
||||||
tDebug() << "Creating a QNetworkReply with url:" << req.url().toString();
|
tDebug() << "Creating a QNetworkReply with url:" << req.url().toString();
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
||||||
reply->setProperty( "collectionName", collection->name() );
|
reply->setProperty( "collectionName", collection->name() );
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ),
|
connect( reply, SIGNAL( finished() ),
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include "resolvers/ScriptEngine.h"
|
#include "resolvers/ScriptEngine.h"
|
||||||
#include "network/Servent.h"
|
#include "network/Servent.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "JSResolver_p.h"
|
#include "JSResolver_p.h"
|
||||||
@@ -446,7 +447,7 @@ JSResolverHelper::returnStreamUrl( const QString& streamUrl, boost::function< vo
|
|||||||
QUrl url = QUrl::fromEncoded( streamUrl.toUtf8() );
|
QUrl url = QUrl::fromEncoded( streamUrl.toUtf8() );
|
||||||
QNetworkRequest req( url );
|
QNetworkRequest req( url );
|
||||||
tDebug() << "Creating a QNetowrkReply with url:" << req.url().toString();
|
tDebug() << "Creating a QNetowrkReply with url:" << req.url().toString();
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
||||||
|
|
||||||
//boost::functions cannot accept temporaries as parameters
|
//boost::functions cannot accept temporaries as parameters
|
||||||
sp = QSharedPointer< QIODevice >( reply, &QObject::deleteLater );
|
sp = QSharedPointer< QIODevice >( reply, &QObject::deleteLater );
|
||||||
|
@@ -30,6 +30,9 @@
|
|||||||
#include "accounts/AccountConfigWidget.h"
|
#include "accounts/AccountConfigWidget.h"
|
||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
#include "utils/NetworkProxyFactory.h"
|
||||||
|
|
||||||
|
|
||||||
#include <QtEndian>
|
#include <QtEndian>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -57,7 +60,7 @@ ScriptResolver::ScriptResolver( const QString& exe )
|
|||||||
|
|
||||||
startProcess();
|
startProcess();
|
||||||
|
|
||||||
if ( !TomahawkUtils::nam() )
|
if ( !Tomahawk::Utils::nam() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// set the name to the binary, if we launch properly we'll get the name the resolver reports
|
// set the name to the binary, if we launch properly we'll get the name the resolver reports
|
||||||
@@ -136,7 +139,7 @@ ScriptResolver::sendConfig()
|
|||||||
|
|
||||||
m_configSent = true;
|
m_configSent = true;
|
||||||
|
|
||||||
TomahawkUtils::NetworkProxyFactory* factory = dynamic_cast<TomahawkUtils::NetworkProxyFactory*>( TomahawkUtils::nam()->proxyFactory() );
|
Tomahawk::Utils::NetworkProxyFactory* factory = dynamic_cast<Tomahawk::Utils::NetworkProxyFactory*>( Tomahawk::Utils::nam()->proxyFactory() );
|
||||||
QNetworkProxy proxy = factory->proxy();
|
QNetworkProxy proxy = factory->proxy();
|
||||||
QString proxyType = ( proxy.type() == QNetworkProxy::Socks5Proxy ? "socks5" : "none" );
|
QString proxyType = ( proxy.type() == QNetworkProxy::Socks5Proxy ? "socks5" : "none" );
|
||||||
m.insert( "proxytype", proxyType );
|
m.insert( "proxytype", proxyType );
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -133,7 +134,7 @@ GroovesharkParser::lookupGroovesharkPlaylist( const QString& linkRaw )
|
|||||||
QString hash = QCA::arrayToHex( resultArray.toByteArray() );
|
QString hash = QCA::arrayToHex( resultArray.toByteArray() );
|
||||||
QUrl url = QUrl( base_url + hash );
|
QUrl url = QUrl( base_url + hash );
|
||||||
|
|
||||||
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->post( QNetworkRequest( url ), data ) );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->post( QNetworkRequest( url ), data ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( groovesharkLookupFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( groovesharkLookupFinished() ) );
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
@@ -150,7 +151,7 @@ GroovesharkParser::lookupGroovesharkTrack( const QString& track )
|
|||||||
{
|
{
|
||||||
tLog() << "Parsing Grooveshark Track Page:" << track;
|
tLog() << "Parsing Grooveshark Track Page:" << track;
|
||||||
|
|
||||||
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( QUrl( track ) ) ) );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( QNetworkRequest( QUrl( track ) ) ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( trackPageFetchFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( trackPageFetchFinished() ) );
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
// Forward Declarations breaking QSharedPointer
|
// Forward Declarations breaking QSharedPointer
|
||||||
#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 )
|
#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
@@ -112,7 +113,7 @@ ItunesParser::lookupItunesUri( const QString& link )
|
|||||||
url = QUrl( QString( "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=%1&entity=song" ).arg( ( trackId.isEmpty() ? id : trackId ) ) );
|
url = QUrl( QString( "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=%1&entity=song" ).arg( ( trackId.isEmpty() ? id : trackId ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( url ) ) );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( QNetworkRequest( url ) ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( itunesResponseLookupFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( itunesResponseLookupFinished() ) );
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include "Playlist.h"
|
#include "Playlist.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
@@ -61,8 +62,8 @@ JSPFLoader::load( const QUrl& url )
|
|||||||
{
|
{
|
||||||
QNetworkRequest request( url );
|
QNetworkRequest request( url );
|
||||||
|
|
||||||
Q_ASSERT( TomahawkUtils::nam() != 0 );
|
Q_ASSERT( Tomahawk::Utils::nam() != 0 );
|
||||||
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( request ) );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( request ) );
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( networkLoadFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( networkLoadFinished() ) );
|
||||||
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( networkError( QNetworkReply::NetworkError ) ) );
|
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( networkError( QNetworkReply::NetworkError ) ) );
|
||||||
|
278
src/libtomahawk/utils/NetworkAccessManager.cpp
Normal file
278
src/libtomahawk/utils/NetworkAccessManager.cpp
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||||
|
* Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "NetworkAccessManager.h"
|
||||||
|
|
||||||
|
#include "NetworkProxyFactory.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
// TODO: get rid of this here!
|
||||||
|
#include "TomahawkSettings.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <QMutex>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QThread>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QNetworkConfiguration>
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
|
||||||
|
static QMutex s_noProxyHostsMutex;
|
||||||
|
static QStringList s_noProxyHosts;
|
||||||
|
|
||||||
|
NetworkProxyFactory::NetworkProxyFactory( const NetworkProxyFactory& other )
|
||||||
|
{
|
||||||
|
m_proxy = QNetworkProxy( other.m_proxy );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList< QNetworkProxy >
|
||||||
|
NetworkProxyFactory::queryProxy( const QNetworkProxyQuery& query )
|
||||||
|
{
|
||||||
|
//tDebug() << Q_FUNC_INFO << "query hostname is" << query.peerHostName() << ", proxy host is" << m_proxy.hostName();
|
||||||
|
|
||||||
|
QList< QNetworkProxy > proxies;
|
||||||
|
QString hostname = query.peerHostName();
|
||||||
|
s_noProxyHostsMutex.lock();
|
||||||
|
if ( !hostname.isEmpty() && s_noProxyHosts.contains( hostname ) )
|
||||||
|
proxies << QNetworkProxy::NoProxy << systemProxyForQuery( query );
|
||||||
|
else if ( m_proxy.hostName().isEmpty() || TomahawkSettings::instance()->proxyType() == QNetworkProxy::NoProxy )
|
||||||
|
proxies << systemProxyForQuery( query );
|
||||||
|
else
|
||||||
|
proxies << m_proxy << systemProxyForQuery( query );
|
||||||
|
s_noProxyHostsMutex.unlock();
|
||||||
|
return proxies;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkProxyFactory::setNoProxyHosts( const QStringList& hosts )
|
||||||
|
{
|
||||||
|
QStringList newList;
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "No-proxy hosts:" << hosts;
|
||||||
|
foreach ( const QString& host, hosts )
|
||||||
|
{
|
||||||
|
QString munge = host.simplified();
|
||||||
|
newList << munge;
|
||||||
|
//TODO: wildcard support
|
||||||
|
}
|
||||||
|
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "New no-proxy hosts:" << newList;
|
||||||
|
|
||||||
|
s_noProxyHostsMutex.lock();
|
||||||
|
s_noProxyHosts = newList;
|
||||||
|
s_noProxyHostsMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkProxyFactory::setProxy( const QNetworkProxy& proxy )
|
||||||
|
{
|
||||||
|
m_proxyChanged = false;
|
||||||
|
if ( m_proxy != proxy )
|
||||||
|
m_proxyChanged = true;
|
||||||
|
|
||||||
|
m_proxy = proxy;
|
||||||
|
QFlags< QNetworkProxy::Capability > proxyCaps;
|
||||||
|
proxyCaps |= QNetworkProxy::TunnelingCapability;
|
||||||
|
proxyCaps |= QNetworkProxy::ListeningCapability;
|
||||||
|
if ( TomahawkSettings::instance()->proxyDns() )
|
||||||
|
proxyCaps |= QNetworkProxy::HostNameLookupCapability;
|
||||||
|
|
||||||
|
m_proxy.setCapabilities( proxyCaps );
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Proxy using host" << proxy.hostName() << "and port" << proxy.port();
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "setting proxy to use proxy DNS?" << (TomahawkSettings::instance()->proxyDns() ? "true" : "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NetworkProxyFactory&
|
||||||
|
NetworkProxyFactory::operator=( const NetworkProxyFactory& rhs )
|
||||||
|
{
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
||||||
|
if ( this != &rhs )
|
||||||
|
{
|
||||||
|
m_proxy = QNetworkProxy( rhs.m_proxy );
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool NetworkProxyFactory::operator==( const NetworkProxyFactory& other ) const
|
||||||
|
{
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
||||||
|
if ( m_proxy != other.m_proxy )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QMap< QThread*, QNetworkAccessManager* > s_threadNamHash;
|
||||||
|
static QMap< QThread*, NetworkProxyFactory* > s_threadProxyFactoryHash;
|
||||||
|
static QMutex s_namAccessMutex;
|
||||||
|
|
||||||
|
NetworkProxyFactory*
|
||||||
|
proxyFactory( bool makeClone, bool noMutexLocker )
|
||||||
|
{
|
||||||
|
// Don't lock if being called from nam()
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
||||||
|
QMutex otherMutex;
|
||||||
|
QMutexLocker locker( noMutexLocker ? &otherMutex : &s_namAccessMutex );
|
||||||
|
|
||||||
|
if ( !makeClone )
|
||||||
|
{
|
||||||
|
if ( s_threadProxyFactoryHash.contains( QThread::currentThread() ) )
|
||||||
|
return s_threadProxyFactoryHash[ QThread::currentThread() ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a new proxy factory for this thread
|
||||||
|
NetworkProxyFactory *newProxyFactory = new NetworkProxyFactory();
|
||||||
|
if ( s_threadProxyFactoryHash.contains( QCoreApplication::instance()->thread() ) )
|
||||||
|
{
|
||||||
|
NetworkProxyFactory *mainProxyFactory = s_threadProxyFactoryHash[ QCoreApplication::instance()->thread() ];
|
||||||
|
*newProxyFactory = *mainProxyFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !makeClone )
|
||||||
|
s_threadProxyFactoryHash[ QThread::currentThread() ] = newProxyFactory;
|
||||||
|
|
||||||
|
return newProxyFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
setProxyFactory( NetworkProxyFactory* factory, bool noMutexLocker )
|
||||||
|
{
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
||||||
|
Q_ASSERT( factory );
|
||||||
|
// Don't lock if being called from setNam()
|
||||||
|
QMutex otherMutex;
|
||||||
|
QMutexLocker locker( noMutexLocker ? &otherMutex : &s_namAccessMutex );
|
||||||
|
|
||||||
|
if ( !s_threadProxyFactoryHash.contains( QCoreApplication::instance()->thread() ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( QThread::currentThread() == QCoreApplication::instance()->thread() )
|
||||||
|
{
|
||||||
|
foreach ( QThread* thread, s_threadProxyFactoryHash.keys() )
|
||||||
|
{
|
||||||
|
if ( thread != QThread::currentThread() )
|
||||||
|
{
|
||||||
|
NetworkProxyFactory *currFactory = s_threadProxyFactoryHash[ thread ];
|
||||||
|
*currFactory = *factory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QNetworkProxyFactory::setApplicationProxyFactory( factory );
|
||||||
|
}
|
||||||
|
|
||||||
|
*s_threadProxyFactoryHash[ QThread::currentThread() ] = *factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QNetworkAccessManager*
|
||||||
|
nam()
|
||||||
|
{
|
||||||
|
QMutexLocker locker( &s_namAccessMutex );
|
||||||
|
if ( s_threadNamHash.contains( QThread::currentThread() ) )
|
||||||
|
{
|
||||||
|
//tDebug() << Q_FUNC_INFO << "Found current thread in nam hash";
|
||||||
|
return s_threadNamHash[ QThread::currentThread() ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !s_threadNamHash.contains( QCoreApplication::instance()->thread() ) )
|
||||||
|
{
|
||||||
|
if ( QThread::currentThread() == QCoreApplication::instance()->thread() )
|
||||||
|
{
|
||||||
|
setNam( new QNetworkAccessManager(), true );
|
||||||
|
return s_threadNamHash[ QThread::currentThread() ];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Found gui thread in nam hash";
|
||||||
|
|
||||||
|
// Create a nam for this thread based on the main thread's settings but with its own proxyfactory
|
||||||
|
QNetworkAccessManager *mainNam = s_threadNamHash[ QCoreApplication::instance()->thread() ];
|
||||||
|
QNetworkAccessManager* newNam = new QNetworkAccessManager();
|
||||||
|
|
||||||
|
newNam->setConfiguration( QNetworkConfiguration( mainNam->configuration() ) );
|
||||||
|
newNam->setNetworkAccessible( mainNam->networkAccessible() );
|
||||||
|
newNam->setProxyFactory( proxyFactory( false, true ) );
|
||||||
|
|
||||||
|
s_threadNamHash[ QThread::currentThread() ] = newNam;
|
||||||
|
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "created new nam for thread" << QThread::currentThread();
|
||||||
|
//QNetworkProxy proxy = dynamic_cast< NetworkProxyFactory* >( newNam->proxyFactory() )->proxy();
|
||||||
|
//tDebug() << Q_FUNC_INFO << "reply proxy properties:" << proxy.type() << proxy.hostName() << proxy.port();
|
||||||
|
|
||||||
|
return newNam;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
setNam( QNetworkAccessManager* nam, bool noMutexLocker )
|
||||||
|
{
|
||||||
|
Q_ASSERT( nam );
|
||||||
|
// Don't lock if being called from nam()()
|
||||||
|
QMutex otherMutex;
|
||||||
|
QMutexLocker locker( noMutexLocker ? &otherMutex : &s_namAccessMutex );
|
||||||
|
if ( !s_threadNamHash.contains( QCoreApplication::instance()->thread() ) &&
|
||||||
|
QThread::currentThread() == QCoreApplication::instance()->thread() )
|
||||||
|
{
|
||||||
|
tDebug( LOGVERBOSE ) << "creating initial gui thread (" << QCoreApplication::instance()->thread() << ") nam";
|
||||||
|
// Should only get here on first initialization of the nam
|
||||||
|
TomahawkSettings *s = TomahawkSettings::instance();
|
||||||
|
NetworkProxyFactory* proxyFactory = new NetworkProxyFactory();
|
||||||
|
if ( s->proxyType() != QNetworkProxy::NoProxy && !s->proxyHost().isEmpty() )
|
||||||
|
{
|
||||||
|
tDebug( LOGVERBOSE ) << "Setting proxy to saved values";
|
||||||
|
QNetworkProxy proxy( s->proxyType(), s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() );
|
||||||
|
proxyFactory->setProxy( proxy );
|
||||||
|
//FIXME: Jreen is broke without this
|
||||||
|
//QNetworkProxy::setApplicationProxy( proxy );
|
||||||
|
s_noProxyHostsMutex.lock();
|
||||||
|
if ( !s->proxyNoProxyHosts().isEmpty() && s_noProxyHosts.isEmpty() )
|
||||||
|
{
|
||||||
|
s_noProxyHostsMutex.unlock();
|
||||||
|
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s_noProxyHostsMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkProxyFactory::setApplicationProxyFactory( proxyFactory );
|
||||||
|
nam->setProxyFactory( proxyFactory );
|
||||||
|
s_threadNamHash[ QThread::currentThread() ] = nam;
|
||||||
|
s_threadProxyFactoryHash[ QThread::currentThread() ] = proxyFactory;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
s_threadNamHash[ QThread::currentThread() ] = nam;
|
||||||
|
|
||||||
|
if ( QThread::currentThread() == QCoreApplication::instance()->thread() )
|
||||||
|
setProxyFactory( dynamic_cast< NetworkProxyFactory* >( nam->proxyFactory() ), true );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
38
src/libtomahawk/utils/NetworkAccessManager.h
Normal file
38
src/libtomahawk/utils/NetworkAccessManager.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||||
|
* Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TOMAHAWK_UTILS_NETWORKACCESSMANAGER_H
|
||||||
|
#define TOMAHAWK_UTILS_NETWORKACCESSMANAGER_H
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
class QNetworkAccessManager;
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
DLLEXPORT QNetworkAccessManager* nam();
|
||||||
|
DLLEXPORT void setNam( QNetworkAccessManager* nam, bool noMutexLocker = false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_UTILS_NETWORKACCESSMANAGER_H
|
24
src/libtomahawk/utils/NetworkProxyFactory.cpp
Normal file
24
src/libtomahawk/utils/NetworkProxyFactory.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||||
|
* Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "NetworkProxyFactory.h"
|
||||||
|
|
||||||
|
//MAJORHACK: all implementation in NetworkAccessManager.cpp even for NetworkProxyFactory.h because they share private s_* vars :C
|
67
src/libtomahawk/utils/NetworkProxyFactory.h
Normal file
67
src/libtomahawk/utils/NetworkProxyFactory.h
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||||
|
* Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TOMAHAWK_UTILS_NETWORKPROXYFACTORY_H
|
||||||
|
#define TOMAHAWK_UTILS_NETWORKPROXYFACTORY_H
|
||||||
|
|
||||||
|
#include <QNetworkProxyFactory>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
class DLLEXPORT NetworkProxyFactory : public QNetworkProxyFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NetworkProxyFactory()
|
||||||
|
: m_proxy( QNetworkProxy::NoProxy )
|
||||||
|
, m_proxyChanged( false )
|
||||||
|
{}
|
||||||
|
|
||||||
|
NetworkProxyFactory( const NetworkProxyFactory &other );
|
||||||
|
virtual ~NetworkProxyFactory() {}
|
||||||
|
|
||||||
|
virtual QList< QNetworkProxy > queryProxy( const QNetworkProxyQuery & query = QNetworkProxyQuery() );
|
||||||
|
|
||||||
|
virtual void setNoProxyHosts( const QStringList &hosts );
|
||||||
|
virtual QStringList noProxyHosts() const { return m_noProxyHosts; }
|
||||||
|
virtual void setProxy( const QNetworkProxy &proxy );
|
||||||
|
virtual QNetworkProxy proxy() { return m_proxy; }
|
||||||
|
|
||||||
|
virtual NetworkProxyFactory& operator=( const NetworkProxyFactory &rhs );
|
||||||
|
virtual bool operator==( const NetworkProxyFactory &other ) const;
|
||||||
|
bool changed() const { return m_proxyChanged; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QStringList m_noProxyHosts;
|
||||||
|
QNetworkProxy m_proxy;
|
||||||
|
bool m_proxyChanged;
|
||||||
|
};
|
||||||
|
|
||||||
|
DLLEXPORT void setProxyFactory( NetworkProxyFactory* factory, bool noMutexLocker = false );
|
||||||
|
DLLEXPORT NetworkProxyFactory* proxyFactory( bool makeClone = false, bool noMutexLocker = false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_UTILS_NETWORKPROXYFACTORY_H
|
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ NetworkReply::load( const QUrl& url )
|
|||||||
m_url = url;
|
m_url = url;
|
||||||
QNetworkRequest request( url );
|
QNetworkRequest request( url );
|
||||||
|
|
||||||
Q_ASSERT( TomahawkUtils::nam() != 0 );
|
Q_ASSERT( Tomahawk::Utils::nam() != 0 );
|
||||||
|
|
||||||
QNetworkAccessManager::Operation op = m_reply->operation();
|
QNetworkAccessManager::Operation op = m_reply->operation();
|
||||||
m_reply->deleteLater();
|
m_reply->deleteLater();
|
||||||
@@ -70,11 +71,11 @@ NetworkReply::load( const QUrl& url )
|
|||||||
switch ( op )
|
switch ( op )
|
||||||
{
|
{
|
||||||
case QNetworkAccessManager::HeadOperation:
|
case QNetworkAccessManager::HeadOperation:
|
||||||
m_reply = TomahawkUtils::nam()->head( request );
|
m_reply = Tomahawk::Utils::nam()->head( request );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
m_reply = TomahawkUtils::nam()->get( request );
|
m_reply = Tomahawk::Utils::nam()->get( request );
|
||||||
}
|
}
|
||||||
|
|
||||||
connect( m_reply, SIGNAL( finished() ), SLOT( networkLoadFinished() ) );
|
connect( m_reply, SIGNAL( finished() ), SLOT( networkLoadFinished() ) );
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
|
|
||||||
#include <qjson/parser.h>
|
#include <qjson/parser.h>
|
||||||
@@ -130,7 +131,7 @@ RdioParser::fetchObjectsFromUrl( const QString& url, DropJob::DropType type )
|
|||||||
QNetworkRequest request = generateRequest( "getObjectFromUrl", cleanedUrl, params, &data );
|
QNetworkRequest request = generateRequest( "getObjectFromUrl", cleanedUrl, params, &data );
|
||||||
|
|
||||||
request.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) );
|
request.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) );
|
||||||
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->post( request, data ) );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->post( request, data ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( rdioReturned() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( rdioReturned() ) );
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include "Result.h"
|
#include "Result.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ ResultUrlChecker::check()
|
|||||||
if ( url.isEmpty() || !url.toString().startsWith( "http" ) )
|
if ( url.isEmpty() || !url.toString().startsWith( "http" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->head( QNetworkRequest( url ) ) );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->head( QNetworkRequest( url ) ) );
|
||||||
m_replies.insert( reply, result );
|
m_replies.insert( reply, result );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( headFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( headFinished() ) );
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -78,7 +79,7 @@ ShortenedLinkParser::lookupUrl( const QString& url )
|
|||||||
if ( cleaned.contains( "/#/s/" ) )
|
if ( cleaned.contains( "/#/s/" ) )
|
||||||
cleaned.replace( "/#", "" );
|
cleaned.replace( "/#", "" );
|
||||||
|
|
||||||
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( QUrl( cleaned ) ) ) );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( QNetworkRequest( QUrl( cleaned ) ) ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( lookupFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( lookupFinished() ) );
|
||||||
|
|
||||||
m_queries.insert( reply );
|
m_queries.insert( reply );
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -175,7 +176,7 @@ SpotifyParser::lookupSpotifyBrowse( const QString& link )
|
|||||||
url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1/%2" ).arg( m_browseUri )
|
url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1/%2" ).arg( m_browseUri )
|
||||||
.arg ( m_limit ) );
|
.arg ( m_limit ) );
|
||||||
|
|
||||||
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( url ) ) );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( QNetworkRequest( url ) ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( spotifyBrowseFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( spotifyBrowseFinished() ) );
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
@@ -204,7 +205,7 @@ SpotifyParser::lookupTrack( const QString& link )
|
|||||||
|
|
||||||
QUrl url = QUrl( QString( "http://ws.spotify.com/lookup/1/.json?uri=%1" ).arg( uri ) );
|
QUrl url = QUrl( QString( "http://ws.spotify.com/lookup/1/.json?uri=%1" ).arg( uri ) );
|
||||||
|
|
||||||
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( url ) ) );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( QNetworkRequest( url ) ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( spotifyTrackLookupFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( spotifyTrackLookupFinished() ) );
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
|
@@ -428,243 +428,6 @@ levenshtein( const QString& source, const QString& target )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static QMutex s_noProxyHostsMutex;
|
|
||||||
static QStringList s_noProxyHosts;
|
|
||||||
|
|
||||||
NetworkProxyFactory::NetworkProxyFactory( const NetworkProxyFactory& other )
|
|
||||||
{
|
|
||||||
m_proxy = QNetworkProxy( other.m_proxy );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QList< QNetworkProxy >
|
|
||||||
NetworkProxyFactory::queryProxy( const QNetworkProxyQuery& query )
|
|
||||||
{
|
|
||||||
//tDebug() << Q_FUNC_INFO << "query hostname is" << query.peerHostName() << ", proxy host is" << m_proxy.hostName();
|
|
||||||
|
|
||||||
QList< QNetworkProxy > proxies;
|
|
||||||
QString hostname = query.peerHostName();
|
|
||||||
s_noProxyHostsMutex.lock();
|
|
||||||
if ( !hostname.isEmpty() && s_noProxyHosts.contains( hostname ) )
|
|
||||||
proxies << QNetworkProxy::NoProxy << systemProxyForQuery( query );
|
|
||||||
else if ( m_proxy.hostName().isEmpty() || TomahawkSettings::instance()->proxyType() == QNetworkProxy::NoProxy )
|
|
||||||
proxies << systemProxyForQuery( query );
|
|
||||||
else
|
|
||||||
proxies << m_proxy << systemProxyForQuery( query );
|
|
||||||
s_noProxyHostsMutex.unlock();
|
|
||||||
return proxies;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
NetworkProxyFactory::setNoProxyHosts( const QStringList& hosts )
|
|
||||||
{
|
|
||||||
QStringList newList;
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "No-proxy hosts:" << hosts;
|
|
||||||
foreach ( const QString& host, hosts )
|
|
||||||
{
|
|
||||||
QString munge = host.simplified();
|
|
||||||
newList << munge;
|
|
||||||
//TODO: wildcard support
|
|
||||||
}
|
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "New no-proxy hosts:" << newList;
|
|
||||||
|
|
||||||
s_noProxyHostsMutex.lock();
|
|
||||||
s_noProxyHosts = newList;
|
|
||||||
s_noProxyHostsMutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
NetworkProxyFactory::setProxy( const QNetworkProxy& proxy )
|
|
||||||
{
|
|
||||||
m_proxyChanged = false;
|
|
||||||
if ( m_proxy != proxy )
|
|
||||||
m_proxyChanged = true;
|
|
||||||
|
|
||||||
m_proxy = proxy;
|
|
||||||
QFlags< QNetworkProxy::Capability > proxyCaps;
|
|
||||||
proxyCaps |= QNetworkProxy::TunnelingCapability;
|
|
||||||
proxyCaps |= QNetworkProxy::ListeningCapability;
|
|
||||||
if ( TomahawkSettings::instance()->proxyDns() )
|
|
||||||
proxyCaps |= QNetworkProxy::HostNameLookupCapability;
|
|
||||||
|
|
||||||
m_proxy.setCapabilities( proxyCaps );
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Proxy using host" << proxy.hostName() << "and port" << proxy.port();
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "setting proxy to use proxy DNS?" << (TomahawkSettings::instance()->proxyDns() ? "true" : "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NetworkProxyFactory&
|
|
||||||
NetworkProxyFactory::operator=( const NetworkProxyFactory& rhs )
|
|
||||||
{
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
|
||||||
if ( this != &rhs )
|
|
||||||
{
|
|
||||||
m_proxy = QNetworkProxy( rhs.m_proxy );
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool NetworkProxyFactory::operator==( const NetworkProxyFactory& other ) const
|
|
||||||
{
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
|
||||||
if ( m_proxy != other.m_proxy )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QMap< QThread*, QNetworkAccessManager* > s_threadNamHash;
|
|
||||||
static QMap< QThread*, NetworkProxyFactory* > s_threadProxyFactoryHash;
|
|
||||||
static QMutex s_namAccessMutex;
|
|
||||||
|
|
||||||
NetworkProxyFactory*
|
|
||||||
proxyFactory( bool makeClone, bool noMutexLocker )
|
|
||||||
{
|
|
||||||
// Don't lock if being called from nam()
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
|
||||||
QMutex otherMutex;
|
|
||||||
QMutexLocker locker( noMutexLocker ? &otherMutex : &s_namAccessMutex );
|
|
||||||
|
|
||||||
if ( !makeClone )
|
|
||||||
{
|
|
||||||
if ( s_threadProxyFactoryHash.contains( QThread::currentThread() ) )
|
|
||||||
return s_threadProxyFactoryHash[ QThread::currentThread() ];
|
|
||||||
}
|
|
||||||
|
|
||||||
// create a new proxy factory for this thread
|
|
||||||
TomahawkUtils::NetworkProxyFactory *newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
|
|
||||||
if ( s_threadProxyFactoryHash.contains( QCoreApplication::instance()->thread() ) )
|
|
||||||
{
|
|
||||||
TomahawkUtils::NetworkProxyFactory *mainProxyFactory = s_threadProxyFactoryHash[ QCoreApplication::instance()->thread() ];
|
|
||||||
*newProxyFactory = *mainProxyFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !makeClone )
|
|
||||||
s_threadProxyFactoryHash[ QThread::currentThread() ] = newProxyFactory;
|
|
||||||
|
|
||||||
return newProxyFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
setProxyFactory( NetworkProxyFactory* factory, bool noMutexLocker )
|
|
||||||
{
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
|
||||||
Q_ASSERT( factory );
|
|
||||||
// Don't lock if being called from setNam()
|
|
||||||
QMutex otherMutex;
|
|
||||||
QMutexLocker locker( noMutexLocker ? &otherMutex : &s_namAccessMutex );
|
|
||||||
|
|
||||||
if ( !s_threadProxyFactoryHash.contains( QCoreApplication::instance()->thread() ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( QThread::currentThread() == QCoreApplication::instance()->thread() )
|
|
||||||
{
|
|
||||||
foreach ( QThread* thread, s_threadProxyFactoryHash.keys() )
|
|
||||||
{
|
|
||||||
if ( thread != QThread::currentThread() )
|
|
||||||
{
|
|
||||||
TomahawkUtils::NetworkProxyFactory *currFactory = s_threadProxyFactoryHash[ thread ];
|
|
||||||
*currFactory = *factory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QNetworkProxyFactory::setApplicationProxyFactory( factory );
|
|
||||||
}
|
|
||||||
|
|
||||||
*s_threadProxyFactoryHash[ QThread::currentThread() ] = *factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QNetworkAccessManager*
|
|
||||||
nam()
|
|
||||||
{
|
|
||||||
QMutexLocker locker( &s_namAccessMutex );
|
|
||||||
if ( s_threadNamHash.contains( QThread::currentThread() ) )
|
|
||||||
{
|
|
||||||
//tDebug() << Q_FUNC_INFO << "Found current thread in nam hash";
|
|
||||||
return s_threadNamHash[ QThread::currentThread() ];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !s_threadNamHash.contains( QCoreApplication::instance()->thread() ) )
|
|
||||||
{
|
|
||||||
if ( QThread::currentThread() == QCoreApplication::instance()->thread() )
|
|
||||||
{
|
|
||||||
setNam( new QNetworkAccessManager(), true );
|
|
||||||
return s_threadNamHash[ QThread::currentThread() ];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Found gui thread in nam hash";
|
|
||||||
|
|
||||||
// Create a nam for this thread based on the main thread's settings but with its own proxyfactory
|
|
||||||
QNetworkAccessManager *mainNam = s_threadNamHash[ QCoreApplication::instance()->thread() ];
|
|
||||||
QNetworkAccessManager* newNam = new QNetworkAccessManager();
|
|
||||||
|
|
||||||
newNam->setConfiguration( QNetworkConfiguration( mainNam->configuration() ) );
|
|
||||||
newNam->setNetworkAccessible( mainNam->networkAccessible() );
|
|
||||||
newNam->setProxyFactory( proxyFactory( false, true ) );
|
|
||||||
|
|
||||||
s_threadNamHash[ QThread::currentThread() ] = newNam;
|
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "created new nam for thread" << QThread::currentThread();
|
|
||||||
//QNetworkProxy proxy = dynamic_cast< TomahawkUtils::NetworkProxyFactory* >( newNam->proxyFactory() )->proxy();
|
|
||||||
//tDebug() << Q_FUNC_INFO << "reply proxy properties:" << proxy.type() << proxy.hostName() << proxy.port();
|
|
||||||
|
|
||||||
return newNam;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
setNam( QNetworkAccessManager* nam, bool noMutexLocker )
|
|
||||||
{
|
|
||||||
Q_ASSERT( nam );
|
|
||||||
// Don't lock if being called from nam()()
|
|
||||||
QMutex otherMutex;
|
|
||||||
QMutexLocker locker( noMutexLocker ? &otherMutex : &s_namAccessMutex );
|
|
||||||
if ( !s_threadNamHash.contains( QCoreApplication::instance()->thread() ) &&
|
|
||||||
QThread::currentThread() == QCoreApplication::instance()->thread() )
|
|
||||||
{
|
|
||||||
tDebug( LOGVERBOSE ) << "creating initial gui thread (" << QCoreApplication::instance()->thread() << ") nam";
|
|
||||||
// Should only get here on first initialization of the nam
|
|
||||||
TomahawkSettings *s = TomahawkSettings::instance();
|
|
||||||
TomahawkUtils::NetworkProxyFactory* proxyFactory = new TomahawkUtils::NetworkProxyFactory();
|
|
||||||
if ( s->proxyType() != QNetworkProxy::NoProxy && !s->proxyHost().isEmpty() )
|
|
||||||
{
|
|
||||||
tDebug( LOGVERBOSE ) << "Setting proxy to saved values";
|
|
||||||
QNetworkProxy proxy( s->proxyType(), s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() );
|
|
||||||
proxyFactory->setProxy( proxy );
|
|
||||||
//FIXME: Jreen is broke without this
|
|
||||||
//QNetworkProxy::setApplicationProxy( proxy );
|
|
||||||
s_noProxyHostsMutex.lock();
|
|
||||||
if ( !s->proxyNoProxyHosts().isEmpty() && s_noProxyHosts.isEmpty() )
|
|
||||||
{
|
|
||||||
s_noProxyHostsMutex.unlock();
|
|
||||||
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
s_noProxyHostsMutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkProxyFactory::setApplicationProxyFactory( proxyFactory );
|
|
||||||
nam->setProxyFactory( proxyFactory );
|
|
||||||
s_threadNamHash[ QThread::currentThread() ] = nam;
|
|
||||||
s_threadProxyFactoryHash[ QThread::currentThread() ] = proxyFactory;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_threadNamHash[ QThread::currentThread() ] = nam;
|
|
||||||
|
|
||||||
if ( QThread::currentThread() == QCoreApplication::instance()->thread() )
|
|
||||||
setProxyFactory( dynamic_cast< TomahawkUtils::NetworkProxyFactory* >( nam->proxyFactory() ), true );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
newerVersion( const QString& oldVersion, const QString& newVersion )
|
newerVersion( const QString& oldVersion, const QString& newVersion )
|
||||||
{
|
{
|
||||||
|
@@ -138,33 +138,6 @@ namespace TomahawkUtils
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class DLLEXPORT NetworkProxyFactory : public QNetworkProxyFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NetworkProxyFactory()
|
|
||||||
: m_proxy( QNetworkProxy::NoProxy )
|
|
||||||
, m_proxyChanged( false )
|
|
||||||
{}
|
|
||||||
|
|
||||||
NetworkProxyFactory( const NetworkProxyFactory &other );
|
|
||||||
virtual ~NetworkProxyFactory() {}
|
|
||||||
|
|
||||||
virtual QList< QNetworkProxy > queryProxy( const QNetworkProxyQuery & query = QNetworkProxyQuery() );
|
|
||||||
|
|
||||||
virtual void setNoProxyHosts( const QStringList &hosts );
|
|
||||||
virtual QStringList noProxyHosts() const { return m_noProxyHosts; }
|
|
||||||
virtual void setProxy( const QNetworkProxy &proxy );
|
|
||||||
virtual QNetworkProxy proxy() { return m_proxy; }
|
|
||||||
|
|
||||||
virtual NetworkProxyFactory& operator=( const NetworkProxyFactory &rhs );
|
|
||||||
virtual bool operator==( const NetworkProxyFactory &other ) const;
|
|
||||||
bool changed() const { return m_proxyChanged; }
|
|
||||||
private:
|
|
||||||
QStringList m_noProxyHosts;
|
|
||||||
QNetworkProxy m_proxy;
|
|
||||||
bool m_proxyChanged;
|
|
||||||
};
|
|
||||||
|
|
||||||
DLLEXPORT bool headless();
|
DLLEXPORT bool headless();
|
||||||
DLLEXPORT void setHeadless( bool headless );
|
DLLEXPORT void setHeadless( bool headless );
|
||||||
|
|
||||||
@@ -185,10 +158,6 @@ namespace TomahawkUtils
|
|||||||
DLLEXPORT bool newerVersion( const QString& oldVersion, const QString& newVersion );
|
DLLEXPORT bool newerVersion( const QString& oldVersion, const QString& newVersion );
|
||||||
DLLEXPORT int levenshtein( const QString& source, const QString& target );
|
DLLEXPORT int levenshtein( const QString& source, const QString& target );
|
||||||
|
|
||||||
DLLEXPORT NetworkProxyFactory* proxyFactory( bool makeClone = false, bool noMutexLocker = false );
|
|
||||||
DLLEXPORT void setProxyFactory( TomahawkUtils::NetworkProxyFactory* factory, bool noMutexLocker = false );
|
|
||||||
DLLEXPORT QNetworkAccessManager* nam();
|
|
||||||
DLLEXPORT void setNam( QNetworkAccessManager* nam, bool noMutexLocker = false );
|
|
||||||
DLLEXPORT quint64 infosystemRequestId();
|
DLLEXPORT quint64 infosystemRequestId();
|
||||||
|
|
||||||
DLLEXPORT QString md5( const QByteArray& data );
|
DLLEXPORT QString md5( const QByteArray& data );
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include "Pipeline.h"
|
#include "Pipeline.h"
|
||||||
#include "Playlist.h"
|
#include "Playlist.h"
|
||||||
@@ -102,8 +103,8 @@ XSPFLoader::load( const QUrl& url )
|
|||||||
m_url = url;
|
m_url = url;
|
||||||
QNetworkRequest request( url );
|
QNetworkRequest request( url );
|
||||||
|
|
||||||
Q_ASSERT( TomahawkUtils::nam() != 0 );
|
Q_ASSERT( Tomahawk::Utils::nam() != 0 );
|
||||||
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( request ) );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( request ) );
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( networkLoadFinished() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( networkLoadFinished() ) );
|
||||||
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( networkError( QNetworkReply::NetworkError ) ) );
|
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( networkError( QNetworkReply::NetworkError ) ) );
|
||||||
|
@@ -54,6 +54,8 @@
|
|||||||
#include "jobview/JobStatusView.h"
|
#include "jobview/JobStatusView.h"
|
||||||
#include "jobview/JobStatusModel.h"
|
#include "jobview/JobStatusModel.h"
|
||||||
#include "jobview/ErrorStatusMessage.h"
|
#include "jobview/ErrorStatusMessage.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
#include "utils/NetworkProxyFactory.h"
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@@ -290,7 +292,7 @@ SettingsDialog::saveSettings()
|
|||||||
|
|
||||||
m_collectionWidgetUi->dirTree->cleanup();
|
m_collectionWidgetUi->dirTree->cleanup();
|
||||||
|
|
||||||
TomahawkUtils::NetworkProxyFactory* proxyFactory = TomahawkUtils::proxyFactory();
|
Tomahawk::Utils::NetworkProxyFactory* proxyFactory = Tomahawk::Utils::proxyFactory();
|
||||||
if ( !m_advancedWidgetUi->enableProxyCheckBox->isChecked() )
|
if ( !m_advancedWidgetUi->enableProxyCheckBox->isChecked() )
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << "Got NoProxy selected";
|
tDebug() << Q_FUNC_INFO << "Got NoProxy selected";
|
||||||
|
@@ -50,6 +50,7 @@
|
|||||||
#include "EchonestCatalogSynchronizer.h"
|
#include "EchonestCatalogSynchronizer.h"
|
||||||
#include "database/DatabaseImpl.h"
|
#include "database/DatabaseImpl.h"
|
||||||
#include "network/Msg.h"
|
#include "network/Msg.h"
|
||||||
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
#include "accounts/lastfm/LastFmAccount.h"
|
#include "accounts/lastfm/LastFmAccount.h"
|
||||||
#include "accounts/spotify/SpotifyAccount.h"
|
#include "accounts/spotify/SpotifyAccount.h"
|
||||||
@@ -198,7 +199,7 @@ TomahawkApp::init()
|
|||||||
|
|
||||||
tDebug( LOGINFO ) << "Setting NAM.";
|
tDebug( LOGINFO ) << "Setting NAM.";
|
||||||
// Cause the creation of the nam, but don't need to address it directly, so prevent warning
|
// Cause the creation of the nam, but don't need to address it directly, so prevent warning
|
||||||
Q_UNUSED( TomahawkUtils::nam() );
|
Q_UNUSED( Tomahawk::Utils::nam() );
|
||||||
|
|
||||||
m_audioEngine = QPointer<AudioEngine>( new AudioEngine );
|
m_audioEngine = QPointer<AudioEngine>( new AudioEngine );
|
||||||
|
|
||||||
@@ -617,7 +618,7 @@ TomahawkApp::onInfoSystemReady()
|
|||||||
|
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
TomahawkSettings* s = TomahawkSettings::instance();
|
||||||
|
|
||||||
Echonest::Config::instance()->setNetworkAccessManager( TomahawkUtils::nam() );
|
Echonest::Config::instance()->setNetworkAccessManager( Tomahawk::Utils::nam() );
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
EchonestGenerator::setupCatalogs();
|
EchonestGenerator::setupCatalogs();
|
||||||
|
|
||||||
@@ -687,7 +688,7 @@ TomahawkApp::onInfoSystemReady()
|
|||||||
GlobalActionManager::instance();
|
GlobalActionManager::instance();
|
||||||
|
|
||||||
// check if our spotify playlist api server is up and running, and enable spotify playlist drops if so
|
// check if our spotify playlist api server is up and running, and enable spotify playlist drops if so
|
||||||
QNetworkReply* r = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( SPOTIFY_PLAYLIST_API_URL "/pong" ) ) );
|
QNetworkReply* r = Tomahawk::Utils::nam()->get( QNetworkRequest( QUrl( SPOTIFY_PLAYLIST_API_URL "/pong" ) ) );
|
||||||
connect( r, SIGNAL( finished() ), this, SLOT( spotifyApiCheckFinished() ) );
|
connect( r, SIGNAL( finished() ), this, SLOT( spotifyApiCheckFinished() ) );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -443,8 +443,8 @@ TomahawkWindow::setupUpdateCheck()
|
|||||||
updaterUrl.setUrl( "http://download.tomahawk-player.org/sparklewin" );
|
updaterUrl.setUrl( "http://download.tomahawk-player.org/sparklewin" );
|
||||||
|
|
||||||
qtsparkle::Updater* updater = new qtsparkle::Updater( updaterUrl, this );
|
qtsparkle::Updater* updater = new qtsparkle::Updater( updaterUrl, this );
|
||||||
Q_ASSERT( TomahawkUtils::nam() != 0 );
|
Q_ASSERT( Tomahawk::Utils::nam() != 0 );
|
||||||
updater->SetNetworkAccessManager( TomahawkUtils::nam() );
|
updater->SetNetworkAccessManager( Tomahawk::Utils::nam() );
|
||||||
updater->SetVersion( TomahawkUtils::appFriendlyVersion() );
|
updater->SetVersion( TomahawkUtils::appFriendlyVersion() );
|
||||||
|
|
||||||
connect( ActionCollection::instance()->getAction( "checkForUpdates" ), SIGNAL( triggered() ),
|
connect( ActionCollection::instance()->getAction( "checkForUpdates" ), SIGNAL( triggered() ),
|
||||||
|
Reference in New Issue
Block a user