1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-02-26 04:43:06 +01:00

Make init methods for all infoplugins to solve issues with network traffic before they're in the right thread

This commit is contained in:
Jeff Mitchell 2012-05-23 12:31:00 -04:00
parent 91024493ee
commit d7a925d110
25 changed files with 97 additions and 33 deletions

View File

@ -75,7 +75,6 @@ LastFmAccount::LastFmAccount( const QString& accountId )
{
infoPlugin().data()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() );
QMetaObject::invokeMethod( infoPlugin().data(), "init", Qt::QueuedConnection );
}
}

View File

@ -51,7 +51,6 @@ public:
virtual ~LastFmInfoPlugin();
public slots:
void init();
void settingsChanged();
void onAuthenticated();
@ -63,6 +62,7 @@ public slots:
void similarTracksReturned();
protected slots:
virtual void init();
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );

View File

@ -130,7 +130,6 @@ TwitterAccount::authenticateSlot()
{
infoPlugin().data()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() );
QMetaObject::invokeMethod( infoPlugin().data(), "init", Qt::QueuedConnection );
}
}

View File

@ -44,7 +44,6 @@ namespace Tomahawk {
virtual ~TwitterInfoPlugin();
public slots:
void init();
void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
{
Q_UNUSED( criteria );
@ -52,6 +51,7 @@ namespace Tomahawk {
}
protected slots:
void init();
void pushInfo( Tomahawk::InfoSystem::InfoPushData pushData );
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{

View File

@ -42,10 +42,10 @@ namespace Tomahawk {
void publishTune( QUrl url, Tomahawk::InfoSystem::InfoStringHash trackInfo );
public slots:
void init();
void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
protected slots:
void init();
void pushInfo( Tomahawk::InfoSystem::InfoPushData pushData );
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );

View File

@ -293,7 +293,6 @@ XmppSipPlugin::onConnect()
{
infoPlugin().data()->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() );
Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin() );
QMetaObject::invokeMethod( infoPlugin().data(), "init", Qt::QueuedConnection );
}
//FIXME: this implementation is totally broken atm, so it's disabled to avoid harm :P

View File

@ -52,8 +52,23 @@ ChartsPlugin::ChartsPlugin()
: InfoPlugin()
, m_chartsFetchJobs( 0 )
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << QThread::currentThread();
/// If you add resource, update version aswell
m_chartVersion = "2.3";
m_supportedGetTypes << InfoChart << InfoChartCapabilities;
}
ChartsPlugin::~ChartsPlugin()
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << QThread::currentThread();
}
void
ChartsPlugin::init()
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << QThread::currentThread();
QVariantList source_qvarlist = TomahawkUtils::Cache::instance()->getData( "ChartsPlugin", "chart_sources" ).toList();
foreach( const QVariant & source, source_qvarlist ) {
m_chartResources.append( source.toString() );
@ -63,14 +78,6 @@ ChartsPlugin::ChartsPlugin()
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "total sources" << m_chartResources.size() << source_qvarlist.size();
if( m_chartResources.size() == 0 )
fetchChartSourcesList( true );
m_supportedGetTypes << InfoChart << InfoChartCapabilities;
}
ChartsPlugin::~ChartsPlugin()
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
}
@ -219,7 +226,7 @@ ChartsPlugin::fetchChartSourcesList( bool fetchOnlySourceList )
reply->setProperty( "only_source_list", fetchOnlySourceList );
tDebug() << "fetching:" << url;
tDebug() << Q_FUNC_INFO << "fetching:" << url;
connect( reply, SIGNAL( finished() ), SLOT( chartSourcesList() ) );
}
@ -227,7 +234,7 @@ ChartsPlugin::fetchChartSourcesList( bool fetchOnlySourceList )
void
ChartsPlugin::chartSourcesList()
{
tDebug( LOGVERBOSE ) << "Got chart sources list";
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Got chart sources list";
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
if ( reply->error() == QNetworkReply::NoError )
@ -239,7 +246,7 @@ ChartsPlugin::chartSourcesList()
if ( !ok )
{
tLog() << "Failed to parse sources" << p.errorString() << "On line" << p.errorLine();
tLog() << Q_FUNC_INFO << "Failed to parse sources" << p.errorString() << "On line" << p.errorLine();
return;
}
@ -253,6 +260,8 @@ ChartsPlugin::chartSourcesList()
if( !reply->property("only_source_list" ).toBool() )
fetchAllChartSources();
}
else
tDebug() << Q_FUNC_INFO << "Encountered error fetching chart sources list";
}
void ChartsPlugin::fetchAllChartSources()
@ -266,7 +275,7 @@ void ChartsPlugin::fetchAllChartSources()
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "chart_source", source);
tDebug() << "fetching:" << url;
tDebug() << Q_FUNC_INFO << "fetching:" << url;
connect( reply, SIGNAL( finished() ), SLOT( chartsList() ) );
m_chartsFetchJobs++;
@ -291,7 +300,7 @@ void ChartsPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData
void
ChartsPlugin::chartsList()
{
tDebug( LOGVERBOSE ) << "Got chart list result";
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Got chart list result";
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
if ( reply->error() == QNetworkReply::NoError )

View File

@ -55,6 +55,7 @@ public:
ChartType chartType() const { return m_chartType; }
protected slots:
virtual void init();
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );

View File

@ -39,7 +39,6 @@ EchonestPlugin::EchonestPlugin()
{
qDebug() << Q_FUNC_INFO;
m_supportedGetTypes << Tomahawk::InfoSystem::InfoArtistBiography << Tomahawk::InfoSystem::InfoArtistFamiliarity << Tomahawk::InfoSystem::InfoArtistHotttness << Tomahawk::InfoSystem::InfoArtistTerms << Tomahawk::InfoSystem::InfoMiscTopTerms;
Echonest::Config::instance()->setNetworkAccessManager( TomahawkUtils::nam() );
}
@ -49,6 +48,13 @@ EchonestPlugin::~EchonestPlugin()
}
void
EchonestPlugin::init()
{
Echonest::Config::instance()->setNetworkAccessManager( TomahawkUtils::nam() );
}
void
EchonestPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{

View File

@ -45,6 +45,8 @@ public:
virtual ~EchonestPlugin();
protected slots:
virtual void init();
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )

View File

@ -95,8 +95,6 @@ HypemPlugin::HypemPlugin()
<< "Techno"
<< "Punk"
<< "New wave";
chartTypes();
}
@ -108,6 +106,13 @@ HypemPlugin::~HypemPlugin()
}
void
HypemPlugin::init()
{
chartTypes();
}
void
HypemPlugin::dataError( Tomahawk::InfoSystem::InfoRequestData requestData )
{

View File

@ -58,6 +58,7 @@ public slots:
void chartTypes();
protected slots:
virtual void init();
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )

View File

@ -42,6 +42,7 @@ public:
virtual ~MusicBrainzPlugin();
protected slots:
virtual void init() {}
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( InfoStringHash criteria, InfoRequestData requestData );

View File

@ -46,6 +46,7 @@ public slots:
void trackLyricsSlot();
protected slots:
virtual void init() {}
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )

View File

@ -30,6 +30,16 @@ NewReleasesPlugin::NewReleasesPlugin()
{
m_nrVersion = "0";
m_supportedGetTypes << InfoNewReleaseCapabilities << InfoNewRelease;
}
NewReleasesPlugin::~NewReleasesPlugin()
{
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO;
}
void
NewReleasesPlugin::init()
{
QVariantList source_qvarlist = TomahawkUtils::Cache::instance()->getData( "NewReleasesPlugin", "nr_sources" ).toList();
foreach( const QVariant & source, source_qvarlist ) {
m_nrSources.append( source.toString() );
@ -41,11 +51,6 @@ NewReleasesPlugin::NewReleasesPlugin()
fetchNRSourcesList( true );
}
NewReleasesPlugin::~NewReleasesPlugin()
{
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO;
}
void NewReleasesPlugin::dataError ( InfoRequestData requestData )
{
emit info ( requestData, QVariant() );

View File

@ -44,6 +44,7 @@ public:
virtual ~NewReleasesPlugin();
protected slots:
virtual void init();
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );

View File

@ -43,6 +43,8 @@ public:
virtual ~RoviPlugin();
protected:
virtual void init() {}
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )

View File

@ -59,6 +59,7 @@ public slots:
void chartTypes();
protected slots:
virtual void init() {}
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )

View File

@ -39,6 +39,8 @@ public:
virtual ~FdoNotifyPlugin();
protected slots:
virtual void init() {}
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{
Q_UNUSED( requestData );

View File

@ -54,7 +54,17 @@ MprisPlugin::MprisPlugin()
// Types of pushInfo we care about
m_supportedPushTypes << InfoNowPlaying << InfoNowPaused << InfoNowResumed << InfoNowStopped;
}
MprisPlugin::~MprisPlugin()
{
}
void
MprisPlugin::init()
{
// DBus connection
new MprisPluginRootAdaptor( this );
new MprisPluginPlayerAdaptor( this );
@ -84,11 +94,6 @@ MprisPlugin::MprisPlugin()
}
MprisPlugin::~MprisPlugin()
{
}
// org.mpris.MediaPlayer2
bool

View File

@ -142,6 +142,8 @@ public slots:
void Stop();
protected slots:
virtual void init();
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{
Q_UNUSED( requestData );

View File

@ -44,6 +44,8 @@ public:
virtual ~AdiumPlugin();
protected slots:
virtual void init() {}
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{
Q_UNUSED( requestData );

View File

@ -101,6 +101,10 @@ class DLLEXPORT InfoPlugin : public QObject
Q_OBJECT
public:
/**
* @brief Creates the plugin. Do *not* perform any network-based setup tasks here; defer that to init(), which will be called automatically.
*
**/
InfoPlugin();
virtual ~InfoPlugin();
@ -115,6 +119,14 @@ signals:
void updateCache( Tomahawk::InfoSystem::InfoStringHash criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output );
protected slots:
/**
* @brief Called after the plugin has been moved to the appropriate thread. Do network-based setup tasks here.
*
* @return void
**/
virtual void init() = 0;
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) = 0;
virtual void pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) = 0;
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) = 0;

View File

@ -122,6 +122,8 @@ InfoSystemWorker::addInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin )
SLOT( updateCacheSlot( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) ),
Qt::QueuedConnection
);
QMetaObject::invokeMethod( plugin.data(), "init", Qt::QueuedConnection );
}

View File

@ -464,7 +464,10 @@ 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( TOMAHAWK_APPLICATION::instance()->thread() ) )
{
@ -476,6 +479,7 @@ nam()
else
return 0;
}
tDebug() << 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[ TOMAHAWK_APPLICATION::instance()->thread() ];
@ -487,7 +491,9 @@ nam()
s_threadNamHash[ QThread::currentThread() ] = newNam;
tDebug( LOGEXTRA ) << "created new nam for thread " << QThread::currentThread();
tDebug( LOGEXTRA ) << 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;
}
@ -524,6 +530,7 @@ setNam( QNetworkAccessManager* nam, bool noMutexLocker )
s_noProxyHostsMutex.unlock();
}
QNetworkProxyFactory::setApplicationProxyFactory( proxyFactory );
nam->setProxyFactory( proxyFactory );
s_threadNamHash[ QThread::currentThread() ] = nam;
s_threadProxyFactoryHash[ QThread::currentThread() ] = proxyFactory;