1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-03 20:57:52 +02:00

Revamp how the plugins interact with the infosystemworker

This commit is contained in:
Jeff Mitchell
2011-05-03 18:00:14 -04:00
parent de28596438
commit 7f26f34fdd
10 changed files with 133 additions and 86 deletions

View File

@@ -25,16 +25,11 @@ using namespace Echonest;
// for internal neatness // for internal neatness
EchoNestPlugin::EchoNestPlugin(InfoSystemWorker *parent) EchoNestPlugin::EchoNestPlugin()
: InfoPlugin(parent) : InfoPlugin()
, m_infoSystemWorker( parent )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QSet< InfoType > supportedTypes; m_supportedGetTypes << Tomahawk::InfoSystem::InfoArtistBiography << Tomahawk::InfoSystem::InfoArtistFamiliarity << Tomahawk::InfoSystem::InfoArtistHotttness << Tomahawk::InfoSystem::InfoArtistTerms << Tomahawk::InfoSystem::InfoMiscTopTerms;
supportedTypes << Tomahawk::InfoSystem::InfoArtistBiography << Tomahawk::InfoSystem::InfoArtistFamiliarity << Tomahawk::InfoSystem::InfoArtistHotttness << Tomahawk::InfoSystem::InfoArtistTerms << Tomahawk::InfoSystem::InfoMiscTopTerms;
parent->registerInfoTypes( this, supportedTypes, QSet< InfoType>() );
connect( parent, SIGNAL( namChanged() ), SLOT( namChangedSlot() ) );
} }
EchoNestPlugin::~EchoNestPlugin() EchoNestPlugin::~EchoNestPlugin()
@@ -43,10 +38,14 @@ EchoNestPlugin::~EchoNestPlugin()
} }
void void
EchoNestPlugin::namChangedSlot() EchoNestPlugin::namChangedSlot( QNetworkAccessManager *nam )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
Echonest::Config::instance()->setNetworkAccessManager( m_infoSystemWorker->nam() ); if( !nam )
return;
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
Echonest::Config::instance()->setNetworkAccessManager( nam );
} }
void void

View File

@@ -40,7 +40,7 @@ class EchoNestPlugin : public InfoPlugin
Q_OBJECT Q_OBJECT
public: public:
EchoNestPlugin( InfoSystemWorker *parent ); EchoNestPlugin();
virtual ~EchoNestPlugin(); virtual ~EchoNestPlugin();
protected slots: protected slots:
@@ -63,7 +63,7 @@ protected slots:
} }
public slots: public slots:
void namChangedSlot(); void namChangedSlot( QNetworkAccessManager *nam );
private: private:
void getSongProfile( const QString &caller, const QVariant &input, const InfoCustomData &customData, const QString &item = QString() ); void getSongProfile( const QString &caller, const QVariant &input, const InfoCustomData &customData, const QString &item = QString() );
@@ -87,7 +87,7 @@ private slots:
private: private:
QHash< QNetworkReply*, InfoCustomData > m_replyMap; QHash< QNetworkReply*, InfoCustomData > m_replyMap;
QHash< QNetworkReply*, QString > m_callerMap; QHash< QNetworkReply*, QString > m_callerMap;
InfoSystemWorker* m_infoSystemWorker; QWeakPointer< QNetworkAccessManager > m_nam;
}; };
} }

View File

@@ -41,18 +41,13 @@ md5( const QByteArray& src )
} }
LastFmPlugin::LastFmPlugin( InfoSystemWorker* parent ) LastFmPlugin::LastFmPlugin()
: InfoPlugin(parent) : InfoPlugin()
, m_scrobbler( 0 ) , m_scrobbler( 0 )
, m_authJob( 0 ) , m_authJob( 0 )
, m_infoSystemWorker( parent )
{ {
QSet< InfoType > supportedGetTypes, supportedPushTypes; m_supportedGetTypes << InfoAlbumCoverArt << InfoArtistImages;
supportedGetTypes << InfoAlbumCoverArt << InfoArtistImages; m_supportedPushTypes << InfoSubmitScrobble << InfoSubmitNowPlaying;
supportedPushTypes << InfoSubmitScrobble << InfoSubmitNowPlaying;
parent->registerInfoTypes( this, supportedGetTypes, supportedPushTypes );
connect( parent, SIGNAL( namChanged() ), SLOT( namChangedSlot() ) );
/* /*
Your API Key is 7194b85b6d1f424fe1668173a78c0c4a Your API Key is 7194b85b6d1f424fe1668173a78c0c4a
@@ -96,11 +91,13 @@ LastFmPlugin::~LastFmPlugin()
void void
LastFmPlugin::namChangedSlot() LastFmPlugin::namChangedSlot( QNetworkAccessManager *nam )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
qDebug() << Q_FUNC_INFO << " using nam " << m_infoSystemWorker->nam(); if( !nam )
lastfm::setNetworkAccessManager( m_infoSystemWorker->nam() ); return;
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
settingsChanged(); // to get the scrobbler set up settingsChanged(); // to get the scrobbler set up
} }
@@ -138,15 +135,15 @@ void
LastFmPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input ) LastFmPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
Q_UNUSED( caller )
switch ( type ) switch ( type )
{ {
case InfoSubmitNowPlaying: case InfoSubmitNowPlaying:
nowPlaying( caller, type, input ); nowPlaying( input );
break; break;
case InfoSubmitScrobble: case InfoSubmitScrobble:
scrobble( caller, type, input ); scrobble();
break; break;
default: default:
@@ -155,7 +152,7 @@ LastFmPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoTy
} }
void void
LastFmPlugin::nowPlaying( const QString &caller, const InfoType type, const QVariant &input ) LastFmPlugin::nowPlaying( const QVariant &input )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() || !m_scrobbler ) if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() || !m_scrobbler )
@@ -186,7 +183,7 @@ LastFmPlugin::nowPlaying( const QString &caller, const InfoType type, const QVar
void void
LastFmPlugin::scrobble( const QString &caller, const InfoType type, const QVariant &input ) LastFmPlugin::scrobble()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
//Q_ASSERT( QThread::currentThread() == thread() ); //Q_ASSERT( QThread::currentThread() == thread() );
@@ -252,6 +249,13 @@ LastFmPlugin::notInCacheSlot( const QHash<QString, QString> criteria, const QStr
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if ( m_nam.isNull() )
{
qDebug() << "Have a null QNAM, uh oh";
emit info( caller, type, input, QVariant(), customData );
return;
}
switch ( type ) switch ( type )
{ {
case InfoAlbumCoverArt: case InfoAlbumCoverArt:
@@ -261,7 +265,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"; 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 ) ); QNetworkRequest req( imgurl.arg( artistName ).arg( albumName ) );
QNetworkReply* reply = m_infoSystemWorker->nam()->get( req ); QNetworkReply* reply = m_nam.data()->get( req );
reply->setProperty( "customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>( customData ) ); reply->setProperty( "customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>( customData ) );
reply->setProperty( "origData", input ); reply->setProperty( "origData", input );
reply->setProperty( "caller", caller ); reply->setProperty( "caller", caller );
@@ -277,7 +281,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"; 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 ) ); QNetworkRequest req( imgurl.arg( artistName ) );
QNetworkReply* reply = m_infoSystemWorker->nam()->get( req ); QNetworkReply* reply = m_nam.data()->get( req );
reply->setProperty( "customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>( customData ) ); reply->setProperty( "customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>( customData ) );
reply->setProperty( "origData", input ); reply->setProperty( "origData", input );
reply->setProperty( "caller", caller ); reply->setProperty( "caller", caller );
@@ -288,7 +292,11 @@ LastFmPlugin::notInCacheSlot( const QHash<QString, QString> criteria, const QStr
} }
default: default:
{
qDebug() << "Couldn't figure out what to do with this type of request after cache miss"; qDebug() << "Couldn't figure out what to do with this type of request after cache miss";
emit info( caller, type, input, QVariant(), customData );
return;
}
} }
} }
@@ -330,9 +338,17 @@ LastFmPlugin::coverArtReturned()
} }
else else
{ {
if ( m_nam.isNull() )
{
qDebug() << "Uh oh, nam is null";
InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt());
InfoCustomData customData = reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
emit info( reply->property( "caller" ).toString(), type, reply->property( "origData" ), QVariant(), customData );
return;
}
// Follow HTTP redirect // Follow HTTP redirect
QNetworkRequest req( redir ); QNetworkRequest req( redir );
QNetworkReply* newReply = m_infoSystemWorker->nam()->get( req ); QNetworkReply* newReply = m_nam.data()->get( req );
newReply->setProperty( "origData", reply->property( "origData" ) ); newReply->setProperty( "origData", reply->property( "origData" ) );
newReply->setProperty( "customData", reply->property( "customData" ) ); newReply->setProperty( "customData", reply->property( "customData" ) );
newReply->setProperty( "caller", reply->property( "caller" ) ); newReply->setProperty( "caller", reply->property( "caller" ) );
@@ -363,15 +379,9 @@ LastFmPlugin::artistImagesReturned()
returnedData["imgbytes"] = ba; returnedData["imgbytes"] = ba;
returnedData["url"] = reply->url().toString(); returnedData["url"] = reply->url().toString();
InfoCustomData customData = reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt()); InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt());
emit info( InfoCustomData customData = reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
reply->property( "caller" ).toString(), emit info( reply->property( "caller" ).toString(), type, reply->property( "origData" ), returnedData, customData );
type,
reply->property( "origData" ),
returnedData,
customData
);
InfoCriteriaHash origData = reply->property( "origData" ).value< Tomahawk::InfoSystem::InfoCriteriaHash >(); InfoCriteriaHash origData = reply->property( "origData" ).value< Tomahawk::InfoSystem::InfoCriteriaHash >();
Tomahawk::InfoSystem::InfoCriteriaHash criteria; Tomahawk::InfoSystem::InfoCriteriaHash criteria;
@@ -380,9 +390,17 @@ LastFmPlugin::artistImagesReturned()
} }
else else
{ {
if ( m_nam.isNull() )
{
qDebug() << "Uh oh, nam is null";
InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt());
InfoCustomData customData = reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
emit info( reply->property( "caller" ).toString(), type, reply->property( "origData" ), QVariant(), customData );
return;
}
// Follow HTTP redirect // Follow HTTP redirect
QNetworkRequest req( redir ); QNetworkRequest req( redir );
QNetworkReply* newReply = m_infoSystemWorker->nam()->get( req ); QNetworkReply* newReply = m_nam.data()->get( req );
newReply->setProperty( "origData", reply->property( "origData" ) ); newReply->setProperty( "origData", reply->property( "origData" ) );
newReply->setProperty( "customData", reply->property( "customData" ) ); newReply->setProperty( "customData", reply->property( "customData" ) );
newReply->setProperty( "caller", reply->property( "caller" ) ); newReply->setProperty( "caller", reply->property( "caller" ) );

View File

@@ -41,7 +41,7 @@ class LastFmPlugin : public InfoPlugin
Q_OBJECT Q_OBJECT
public: public:
LastFmPlugin( InfoSystemWorker *parent ); LastFmPlugin();
virtual ~LastFmPlugin(); virtual ~LastFmPlugin();
public slots: public slots:
@@ -51,7 +51,7 @@ public slots:
void coverArtReturned(); void coverArtReturned();
void artistImagesReturned(); void artistImagesReturned();
void namChangedSlot(); void namChangedSlot( QNetworkAccessManager *nam );
protected slots: protected slots:
virtual void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData ); virtual void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData );
@@ -64,8 +64,8 @@ private:
void fetchArtistImages( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData ); void fetchArtistImages( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData );
void createScrobbler(); void createScrobbler();
void scrobble( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input ); void nowPlaying( const QVariant &input );
void nowPlaying( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input ); void scrobble();
void dataError( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData ); void dataError( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData );
@@ -77,7 +77,7 @@ private:
QNetworkReply* m_authJob; QNetworkReply* m_authJob;
InfoSystemWorker* m_infoSystemWorker; QWeakPointer< QNetworkAccessManager > m_nam;
}; };
} }

View File

@@ -27,15 +27,12 @@ using namespace Tomahawk::InfoSystem;
// for internal neatness // for internal neatness
MusixMatchPlugin::MusixMatchPlugin(InfoSystemWorker *parent) MusixMatchPlugin::MusixMatchPlugin()
: InfoPlugin(parent) : InfoPlugin()
, m_apiKey("61be4ea5aea7dd942d52b2f1311dd9fe") , m_apiKey("61be4ea5aea7dd942d52b2f1311dd9fe")
, m_infoSystemWorker( parent )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QSet< InfoType > supportedTypes; m_supportedGetTypes << Tomahawk::InfoSystem::InfoTrackLyrics;
supportedTypes << Tomahawk::InfoSystem::InfoTrackLyrics;
parent->registerInfoTypes( this, supportedTypes, QSet< InfoType>() );
} }
MusixMatchPlugin::~MusixMatchPlugin() MusixMatchPlugin::~MusixMatchPlugin()
@@ -43,11 +40,21 @@ MusixMatchPlugin::~MusixMatchPlugin()
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
} }
void
MusixMatchPlugin::namChangedSlot( QNetworkAccessManager *nam )
{
qDebug() << Q_FUNC_INFO;
if( !nam )
return;
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
}
void void
MusixMatchPlugin::getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData ) MusixMatchPlugin::getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if( !isValidTrackData(caller, input, customData) || !input.canConvert<Tomahawk::InfoSystem::InfoCustomData>()) if( !isValidTrackData(caller, input, customData) || !input.canConvert<Tomahawk::InfoSystem::InfoCustomData>() || m_nam.isNull() )
return; return;
Tomahawk::InfoSystem::InfoCustomData hash = input.value<Tomahawk::InfoSystem::InfoCustomData>(); Tomahawk::InfoSystem::InfoCustomData hash = input.value<Tomahawk::InfoSystem::InfoCustomData>();
QString artist = hash["artistName"].toString(); QString artist = hash["artistName"].toString();
@@ -63,7 +70,7 @@ MusixMatchPlugin::getInfo( const QString caller, const Tomahawk::InfoSystem::Inf
url.addQueryItem("apikey", m_apiKey); url.addQueryItem("apikey", m_apiKey);
url.addQueryItem("q_artist", artist); url.addQueryItem("q_artist", artist);
url.addQueryItem("q_track", track); url.addQueryItem("q_track", track);
QNetworkReply* reply = m_infoSystemWorker->nam()->get(QNetworkRequest(url)); QNetworkReply* reply = m_nam.data()->get(QNetworkRequest(url));
reply->setProperty("customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>(customData)); reply->setProperty("customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>(customData));
reply->setProperty("origData", input); reply->setProperty("origData", input);
reply->setProperty("caller", caller); reply->setProperty("caller", caller);
@@ -102,7 +109,7 @@ MusixMatchPlugin::trackSearchSlot()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() ); QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
if (!oldReply) if ( !oldReply || m_nam.isNull() )
{ {
emit info(QString(), Tomahawk::InfoSystem::InfoTrackLyrics, QVariant(), QVariant(), Tomahawk::InfoSystem::InfoCustomData()); emit info(QString(), Tomahawk::InfoSystem::InfoTrackLyrics, QVariant(), QVariant(), Tomahawk::InfoSystem::InfoCustomData());
return; return;
@@ -121,7 +128,7 @@ MusixMatchPlugin::trackSearchSlot()
QUrl url(requestString); QUrl url(requestString);
url.addQueryItem("apikey", m_apiKey); url.addQueryItem("apikey", m_apiKey);
url.addQueryItem("track_id", track_id); url.addQueryItem("track_id", track_id);
QNetworkReply* newReply = m_infoSystemWorker->nam()->get(QNetworkRequest(url)); QNetworkReply* newReply = m_nam.data()->get(QNetworkRequest(url));
newReply->setProperty("origData", oldReply->property("origData")); newReply->setProperty("origData", oldReply->property("origData"));
newReply->setProperty("customData", oldReply->property("customData")); newReply->setProperty("customData", oldReply->property("customData"));
newReply->setProperty("caller", oldReply->property("caller")); newReply->setProperty("caller", oldReply->property("caller"));

View File

@@ -35,13 +35,15 @@ class MusixMatchPlugin : public InfoPlugin
Q_OBJECT Q_OBJECT
public: public:
MusixMatchPlugin( InfoSystemWorker *parent ); MusixMatchPlugin();
virtual ~MusixMatchPlugin(); virtual ~MusixMatchPlugin();
public slots: public slots:
void trackSearchSlot(); void trackSearchSlot();
void trackLyricsSlot(); void trackLyricsSlot();
void namChangedSlot( QNetworkAccessManager *nam );
protected slots: protected slots:
virtual void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData ); virtual void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData );
@@ -66,7 +68,7 @@ private:
QString m_apiKey; QString m_apiKey;
InfoSystemWorker* m_infoSystemWorker; QWeakPointer< QNetworkAccessManager > m_nam;
}; };
} }

View File

@@ -32,12 +32,16 @@ namespace Tomahawk
namespace InfoSystem namespace InfoSystem
{ {
InfoPlugin::InfoPlugin( InfoSystemWorker *parent ) InfoPlugin::InfoPlugin()
:QObject( parent ) : QObject()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
} }
InfoPlugin::~InfoPlugin()
{
qDebug() << Q_FUNC_INFO;
}
InfoSystem* InfoSystem::s_instance = 0; InfoSystem* InfoSystem::s_instance = 0;

View File

@@ -31,6 +31,8 @@
#include "dllmacro.h" #include "dllmacro.h"
class QNetworkAccessManager;
namespace Tomahawk { namespace Tomahawk {
namespace InfoSystem { namespace InfoSystem {
@@ -105,12 +107,12 @@ class DLLEXPORT InfoPlugin : public QObject
Q_OBJECT Q_OBJECT
public: public:
InfoPlugin( InfoSystemWorker *parent ); InfoPlugin();
virtual ~InfoPlugin() virtual ~InfoPlugin();
{
qDebug() << Q_FUNC_INFO; QSet< InfoType > supportedGetTypes() const { return m_supportedGetTypes; }
} QSet< InfoType > supportedPushTypes() const { return m_supportedPushTypes; }
signals: signals:
void getCachedInfo( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData ); void getCachedInfo( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
@@ -123,8 +125,12 @@ protected slots:
virtual void pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant data ) = 0; virtual void pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant data ) = 0;
virtual void notInCacheSlot( const Tomahawk::InfoSystem::InfoCriteriaHash criteria, const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData ) = 0; virtual void notInCacheSlot( const Tomahawk::InfoSystem::InfoCriteriaHash criteria, const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData ) = 0;
virtual void namChangedSlot( QNetworkAccessManager *nam ) = 0;
protected: protected:
InfoType m_type; InfoType m_type;
QSet< InfoType > m_supportedGetTypes;
QSet< InfoType > m_supportedPushTypes;
private: private:
friend class InfoSystem; friend class InfoSystem;

View File

@@ -36,7 +36,6 @@ namespace InfoSystem
{ {
InfoSystemWorker::InfoSystemWorker() InfoSystemWorker::InfoSystemWorker()
: m_nam( 0 )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
} }
@@ -56,12 +55,15 @@ InfoSystemWorker::~InfoSystemWorker()
void InfoSystemWorker::init() void InfoSystemWorker::init()
{ {
InfoPluginPtr enptr( new EchoNestPlugin( this ) ); InfoPluginPtr enptr( new EchoNestPlugin() );
m_plugins.append( enptr ); m_plugins.append( enptr );
InfoPluginPtr mmptr( new MusixMatchPlugin( this ) ); registerInfoTypes( enptr, enptr.data()->supportedGetTypes(), enptr.data()->supportedPushTypes() );
InfoPluginPtr mmptr( new MusixMatchPlugin() );
m_plugins.append( mmptr ); m_plugins.append( mmptr );
InfoPluginPtr lfmptr( new LastFmPlugin( this ) ); registerInfoTypes( mmptr, mmptr.data()->supportedGetTypes(), mmptr.data()->supportedPushTypes() );
InfoPluginPtr lfmptr( new LastFmPlugin() );
m_plugins.append( lfmptr ); m_plugins.append( lfmptr );
registerInfoTypes( lfmptr, lfmptr.data()->supportedGetTypes(), lfmptr.data()->supportedPushTypes() );
InfoSystemCache *cache = InfoSystem::instance()->getCache(); InfoSystemCache *cache = InfoSystem::instance()->getCache();
@@ -93,6 +95,12 @@ void InfoSystemWorker::init()
cache, cache,
SLOT( updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) ) SLOT( updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) )
); );
connect(
this,
SIGNAL( namChanged( QNetworkAccessManger* ) ),
plugin.data(),
SLOT( namChangedSlot( QNetworkAccessManager* ) )
);
} }
QMetaObject::invokeMethod( this, "newNam" ); QMetaObject::invokeMethod( this, "newNam" );
@@ -160,7 +168,10 @@ InfoSystemWorker::pushInfo( const QString caller, const InfoType type, const QVa
QNetworkAccessManager* QNetworkAccessManager*
InfoSystemWorker::nam() const InfoSystemWorker::nam() const
{ {
return m_nam; if ( m_nam.isNull() )
return 0;
return m_nam.data();
} }
@@ -169,13 +180,12 @@ InfoSystemWorker::newNam()
{ {
qDebug() << Q_FUNC_INFO << " begin"; qDebug() << Q_FUNC_INFO << " begin";
Q_ASSERT( TomahawkUtils::nam() != 0 );
QNetworkAccessManager *oldNam = TomahawkUtils::nam(); QNetworkAccessManager *oldNam = TomahawkUtils::nam();
if ( oldNam && oldNam->thread() == thread() ) if ( oldNam && oldNam->thread() == thread() )
{ {
qDebug() << Q_FUNC_INFO << " returning old nam as it's the same thread as me"; qDebug() << Q_FUNC_INFO << " using old nam as it's the same thread as me";
m_nam = oldNam; m_nam = QWeakPointer< QNetworkAccessManager >( oldNam );
emit namChanged(); emit namChanged( m_nam.data() );
return; return;
} }
@@ -186,20 +196,21 @@ InfoSystemWorker::newNam()
#else #else
newNam = new QNetworkAccessManager( this ); newNam = new QNetworkAccessManager( this );
#endif #endif
if ( m_nam ) if ( !m_nam.isNull() )
delete m_nam; delete m_nam.data();
if ( !oldNam ) if ( !oldNam )
{ {
m_nam = newNam; m_nam = QWeakPointer< QNetworkAccessManager >( newNam );
return; return;
} }
newNam->setConfiguration( oldNam->configuration() ); newNam->setConfiguration( oldNam->configuration() );
newNam->setNetworkAccessible( oldNam->networkAccessible() ); newNam->setNetworkAccessible( oldNam->networkAccessible() );
newNam->setProxy( oldNam->proxy() ); newNam->setProxy( oldNam->proxy() );
m_nam = newNam; m_nam = QWeakPointer< QNetworkAccessManager >( newNam );
emit namChanged(); emit namChanged( m_nam.data() );
} }

View File

@@ -49,7 +49,7 @@ public:
signals: signals:
void info( QString target, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData ); void info( QString target, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void namChanged(); void namChanged( QNetworkAccessManager* );
public slots: public slots:
void init(); void init();
@@ -66,7 +66,7 @@ private:
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoGetMap; QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoGetMap;
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoPushMap; QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoPushMap;
QNetworkAccessManager *m_nam; QWeakPointer< QNetworkAccessManager> m_nam;
}; };
} }