mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-25 02:09:48 +01:00
Use a new QNAM in the thread to avoid reparenting problems
This commit is contained in:
parent
37b9dea002
commit
dfc518cedc
@ -27,6 +27,7 @@ using namespace Echonest;
|
||||
|
||||
EchoNestPlugin::EchoNestPlugin(InfoSystemWorker *parent)
|
||||
: InfoPlugin(parent)
|
||||
, m_infoSystemWorker( parent )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QSet< InfoType > supportedTypes;
|
||||
|
@ -68,6 +68,7 @@ private slots:
|
||||
private:
|
||||
QHash< QNetworkReply*, InfoCustomData > m_replyMap;
|
||||
QHash< QNetworkReply*, QString > m_callerMap;
|
||||
InfoSystemWorker* m_infoSystemWorker;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ LastFmPlugin::LastFmPlugin( InfoSystemWorker* parent )
|
||||
: InfoPlugin(parent)
|
||||
, m_scrobbler( 0 )
|
||||
, m_authJob( 0 )
|
||||
, m_infoSystemWorker( parent )
|
||||
{
|
||||
QSet< InfoType > supportedTypes;
|
||||
supportedTypes << InfoMiscSubmitScrobble << InfoMiscSubmitNowPlaying << InfoAlbumCoverArt << InfoArtistImages;
|
||||
@ -241,7 +242,7 @@ LastFmPlugin::notInCacheSlot( const QHash<QString, QString> criteria, const QStr
|
||||
|
||||
QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=album.imageredirect&artist=%1&album=%2&autocorrect=1&size=medium&api_key=7a90f6672a04b809ee309af169f34b8b";
|
||||
QNetworkRequest req( imgurl.arg( artistName ).arg( albumName ) );
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
|
||||
QNetworkReply* reply = m_infoSystemWorker->nam()->get( req );
|
||||
reply->setProperty( "customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>( customData ) );
|
||||
reply->setProperty( "origData", input );
|
||||
reply->setProperty( "caller", caller );
|
||||
@ -257,7 +258,7 @@ LastFmPlugin::notInCacheSlot( const QHash<QString, QString> criteria, const QStr
|
||||
|
||||
QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=artist.imageredirect&artist=%1&autocorrect=1&size=medium&api_key=7a90f6672a04b809ee309af169f34b8b";
|
||||
QNetworkRequest req( imgurl.arg( artistName ) );
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
|
||||
QNetworkReply* reply = m_infoSystemWorker->nam()->get( req );
|
||||
reply->setProperty( "customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>( customData ) );
|
||||
reply->setProperty( "origData", input );
|
||||
reply->setProperty( "caller", caller );
|
||||
@ -312,7 +313,7 @@ LastFmPlugin::coverArtReturned()
|
||||
{
|
||||
// Follow HTTP redirect
|
||||
QNetworkRequest req( redir );
|
||||
QNetworkReply* newReply = TomahawkUtils::nam()->get( req );
|
||||
QNetworkReply* newReply = m_infoSystemWorker->nam()->get( req );
|
||||
newReply->setProperty( "origData", reply->property( "origData" ) );
|
||||
newReply->setProperty( "customData", reply->property( "customData" ) );
|
||||
newReply->setProperty( "caller", reply->property( "caller" ) );
|
||||
@ -362,7 +363,7 @@ LastFmPlugin::artistImagesReturned()
|
||||
{
|
||||
// Follow HTTP redirect
|
||||
QNetworkRequest req( redir );
|
||||
QNetworkReply* newReply = TomahawkUtils::nam()->get( req );
|
||||
QNetworkReply* newReply = m_infoSystemWorker->nam()->get( req );
|
||||
newReply->setProperty( "origData", reply->property( "origData" ) );
|
||||
newReply->setProperty( "customData", reply->property( "customData" ) );
|
||||
newReply->setProperty( "caller", reply->property( "caller" ) );
|
||||
|
@ -72,6 +72,8 @@ private:
|
||||
QList< QUrl > m_badUrls;
|
||||
|
||||
QNetworkReply* m_authJob;
|
||||
|
||||
InfoSystemWorker* m_infoSystemWorker;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ using namespace Tomahawk::InfoSystem;
|
||||
MusixMatchPlugin::MusixMatchPlugin(InfoSystemWorker *parent)
|
||||
: InfoPlugin(parent)
|
||||
, m_apiKey("61be4ea5aea7dd942d52b2f1311dd9fe")
|
||||
, m_infoSystemWorker( parent )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QSet< InfoType > supportedTypes;
|
||||
@ -62,7 +63,7 @@ MusixMatchPlugin::getInfo( const QString caller, const Tomahawk::InfoSystem::Inf
|
||||
url.addQueryItem("apikey", m_apiKey);
|
||||
url.addQueryItem("q_artist", artist);
|
||||
url.addQueryItem("q_track", track);
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get(QNetworkRequest(url));
|
||||
QNetworkReply* reply = m_infoSystemWorker->nam()->get(QNetworkRequest(url));
|
||||
reply->setProperty("customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>(customData));
|
||||
reply->setProperty("origData", input);
|
||||
reply->setProperty("caller", caller);
|
||||
@ -120,7 +121,7 @@ MusixMatchPlugin::trackSearchSlot()
|
||||
QUrl url(requestString);
|
||||
url.addQueryItem("apikey", m_apiKey);
|
||||
url.addQueryItem("track_id", track_id);
|
||||
QNetworkReply* newReply = TomahawkUtils::nam()->get(QNetworkRequest(url));
|
||||
QNetworkReply* newReply = m_infoSystemWorker->nam()->get(QNetworkRequest(url));
|
||||
newReply->setProperty("origData", oldReply->property("origData"));
|
||||
newReply->setProperty("customData", oldReply->property("customData"));
|
||||
newReply->setProperty("caller", oldReply->property("caller"));
|
||||
|
@ -49,6 +49,8 @@ private:
|
||||
bool isValidTrackData( const QString &caller, const QVariant &input, const InfoCustomData &customData );
|
||||
|
||||
QString m_apiKey;
|
||||
|
||||
InfoSystemWorker* m_infoSystemWorker;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include "infosystem.h"
|
||||
#include "tomahawksettings.h"
|
||||
#include "utils/tomahawkutils.h"
|
||||
#include "infosystemcache.h"
|
||||
#include "infoplugins/echonestplugin.h"
|
||||
@ -63,7 +64,11 @@ InfoSystem::InfoSystem(QObject *parent)
|
||||
m_worker = new InfoSystemWorker();
|
||||
m_worker->moveToThread( m_infoSystemWorkerThreadController );
|
||||
m_infoSystemWorkerThreadController->start();
|
||||
|
||||
|
||||
QMetaObject::invokeMethod( m_worker, "newNam", Qt::QueuedConnection );
|
||||
|
||||
connect( TomahawkSettings::instance(), SIGNAL( changed() ), m_worker, SLOT( newNam() ) );
|
||||
|
||||
connect( m_cache, SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
|
||||
this, SLOT( infoSlot( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ), Qt::UniqueConnection );
|
||||
|
||||
@ -118,7 +123,15 @@ InfoSystem::~InfoSystem()
|
||||
}
|
||||
|
||||
|
||||
void InfoSystem::getInfo(const QString &caller, const InfoType type, const QVariant& input, InfoCustomData customData)
|
||||
void
|
||||
InfoSystem::newNam() const
|
||||
{
|
||||
QMetaObject::invokeMethod( m_worker, "newNam", Qt::QueuedConnection );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InfoSystem::getInfo(const QString &caller, const InfoType type, const QVariant& input, InfoCustomData customData)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
@ -128,14 +141,16 @@ void InfoSystem::getInfo(const QString &caller, const InfoType type, const QVari
|
||||
}
|
||||
|
||||
|
||||
void InfoSystem::getInfo(const QString &caller, const InfoMap &input, InfoCustomData customData)
|
||||
void
|
||||
InfoSystem::getInfo(const QString &caller, const InfoMap &input, InfoCustomData customData)
|
||||
{
|
||||
Q_FOREACH( InfoType type, input.keys() )
|
||||
getInfo(caller, type, input[type], customData);
|
||||
}
|
||||
|
||||
|
||||
void InfoSystem::infoSlot(QString target, InfoType type, QVariant input, QVariant output, InfoCustomData customData)
|
||||
void
|
||||
InfoSystem::infoSlot(QString target, InfoType type, QVariant input, QVariant output, InfoCustomData customData)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
qDebug() << "current count in dataTracker is " << m_dataTracker[target][type];
|
||||
|
@ -153,7 +153,8 @@ public:
|
||||
void getInfo( const QString &caller, const InfoType type, const QVariant &input, InfoCustomData customData );
|
||||
void getInfo( const QString &caller, const InfoMap &input, InfoCustomData customData );
|
||||
|
||||
InfoSystemCache* getCache() { return m_cache; }
|
||||
InfoSystemCache* getCache() const { return m_cache; }
|
||||
void newNam() const;
|
||||
|
||||
signals:
|
||||
void info( QString caller, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
|
||||
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QNetworkConfiguration>
|
||||
#include <QNetworkProxy>
|
||||
|
||||
#include "infosystemworker.h"
|
||||
#include "utils/tomahawkutils.h"
|
||||
@ -32,6 +34,7 @@ namespace InfoSystem
|
||||
{
|
||||
|
||||
InfoSystemWorker::InfoSystemWorker()
|
||||
: m_nam( 0 )
|
||||
{
|
||||
InfoPluginPtr enptr( new EchoNestPlugin( this ) );
|
||||
m_plugins.append( enptr );
|
||||
@ -127,6 +130,38 @@ InfoSystemWorker::getInfo( QString caller, InfoType type, QVariant input, InfoCu
|
||||
QMetaObject::invokeMethod( ptr.data(), "getInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ), Q_ARG( Tomahawk::InfoSystem::InfoCustomData, customData ) );
|
||||
}
|
||||
|
||||
|
||||
QNetworkAccessManager*
|
||||
InfoSystemWorker::nam() const
|
||||
{
|
||||
return m_nam;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InfoSystemWorker::newNam()
|
||||
{
|
||||
QNetworkAccessManager *newNam = new QNetworkAccessManager( this );
|
||||
if ( m_nam )
|
||||
{
|
||||
delete m_nam;
|
||||
}
|
||||
QNetworkAccessManager *oldNam = TomahawkUtils::nam();
|
||||
if ( !oldNam )
|
||||
{
|
||||
m_nam = newNam;
|
||||
return;
|
||||
}
|
||||
newNam->setCache( oldNam->cache() );
|
||||
newNam->setConfiguration( oldNam->configuration() );
|
||||
newNam->setCookieJar( oldNam->cookieJar() );
|
||||
newNam->setNetworkAccessible( oldNam->networkAccessible() );
|
||||
newNam->setProxy( oldNam->proxy() );
|
||||
newNam->setProxyFactory( oldNam->proxyFactory() );
|
||||
m_nam = newNam;
|
||||
}
|
||||
|
||||
|
||||
} //namespace InfoSystem
|
||||
|
||||
} //namespace Tomahawk
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "infosystem/infosystem.h"
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QtDebug>
|
||||
#include <QtCore/QMap>
|
||||
@ -44,12 +45,14 @@ public:
|
||||
~InfoSystemWorker();
|
||||
|
||||
void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &types );
|
||||
QNetworkAccessManager* nam() const;
|
||||
|
||||
signals:
|
||||
void info( QString target, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
|
||||
|
||||
public slots:
|
||||
void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData );
|
||||
void newNam();
|
||||
|
||||
private:
|
||||
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
||||
@ -58,6 +61,8 @@ private:
|
||||
QLinkedList< InfoPluginPtr > m_plugins;
|
||||
|
||||
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoMap;
|
||||
|
||||
QNetworkAccessManager *m_nam;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -242,6 +242,7 @@ TomahawkApp::init()
|
||||
else
|
||||
TomahawkUtils::setProxy( new QNetworkProxy( QNetworkProxy::NoProxy ) );
|
||||
|
||||
m_infoSystem->newNam();
|
||||
|
||||
Echonest::Config::instance()->setAPIKey( "JRIHWEP6GPOER2QQ6" );
|
||||
Echonest::Config::instance()->setNetworkAccessManager( TomahawkUtils::nam() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user