1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-25 02:09:48 +01:00

* InfoSystem now emits ready() when init is done.

This commit is contained in:
Christian Muehlhaeuser 2013-06-07 11:54:48 +02:00
parent 9e89e4aa4c
commit 13ae09218d
3 changed files with 26 additions and 20 deletions

View File

@ -80,6 +80,7 @@ InfoPlugin::setFriendlyName( const QString& friendlyName )
m_friendlyName = friendlyName;
}
const QString
InfoPlugin::friendlyName() const
{
@ -99,7 +100,7 @@ InfoSystem::instance()
}
InfoSystem::InfoSystem( QObject *parent )
InfoSystem::InfoSystem( QObject* parent )
: QObject( parent )
, m_inited( false )
, m_infoSystemCacheThreadController( 0 )
@ -121,7 +122,7 @@ InfoSystem::InfoSystem( QObject *parent )
InfoSystem::~InfoSystem()
{
tDebug() << Q_FUNC_INFO << " beginning";
tDebug() << Q_FUNC_INFO << "beginning";
if ( m_infoSystemWorkerThreadController )
{
@ -131,9 +132,9 @@ InfoSystem::~InfoSystem()
delete m_infoSystemWorkerThreadController;
m_infoSystemWorkerThreadController = 0;
}
tDebug() << Q_FUNC_INFO << " done deleting worker";
tDebug() << Q_FUNC_INFO << "done deleting worker";
if( m_infoSystemCacheThreadController )
if ( m_infoSystemCacheThreadController )
{
m_infoSystemCacheThreadController->quit();
m_infoSystemCacheThreadController->wait( 60000 );
@ -142,7 +143,7 @@ InfoSystem::~InfoSystem()
m_infoSystemCacheThreadController = 0;
}
tDebug() << Q_FUNC_INFO << " done deleting cache";
tDebug() << Q_FUNC_INFO << "done deleting cache";
}
@ -182,11 +183,12 @@ InfoSystem::init()
QMetaObject::invokeMethod( worker, "init", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoSystemCache*, cache ) );
m_inited = true;
emit ready();
}
bool
InfoSystem::getInfo( const InfoRequestData &requestData )
InfoSystem::getInfo( const InfoRequestData& requestData )
{
//qDebug() << Q_FUNC_INFO;
if ( !m_inited || !m_infoSystemWorkerThreadController->worker() )
@ -200,7 +202,7 @@ InfoSystem::getInfo( const InfoRequestData &requestData )
bool
InfoSystem::getInfo( const QString &caller, const QVariantMap &customData, const InfoTypeMap &inputMap, const InfoTimeoutMap &timeoutMap, bool allSources )
InfoSystem::getInfo( const QString& caller, const QVariantMap& customData, const InfoTypeMap& inputMap, const InfoTimeoutMap& timeoutMap, bool allSources )
{
if ( !m_inited || !m_infoSystemWorkerThreadController->worker() )
{
@ -211,7 +213,7 @@ InfoSystem::getInfo( const QString &caller, const QVariantMap &customData, const
requestData.caller = caller;
requestData.customData = customData;
requestData.allSources = allSources;
Q_FOREACH( InfoType type, inputMap.keys() )
foreach ( InfoType type, inputMap.keys() )
{
requestData.type = type;
requestData.input = inputMap[ type ];
@ -241,7 +243,7 @@ InfoSystem::pushInfo( InfoPushData pushData )
bool
InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input, const PushInfoFlags pushFlags )
InfoSystem::pushInfo( const QString& caller, const InfoTypeMap& input, const PushInfoFlags pushFlags )
{
if ( !m_inited || !m_infoSystemWorkerThreadController->worker() )
{
@ -249,7 +251,7 @@ InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input, const Pus
return false;
}
Q_FOREACH( InfoType type, input.keys() )
foreach ( InfoType type, input.keys() )
{
InfoPushData pushData( caller, type, input[ type ], pushFlags );
pushData.infoPair = PushInfoPair( QVariantMap(), pushData.input );
@ -341,7 +343,7 @@ InfoSystem::workerThread() const
}
InfoSystemCacheThread::InfoSystemCacheThread( QObject *parent )
InfoSystemCacheThread::InfoSystemCacheThread( QObject* parent )
: QThread( parent )
{
tDebug() << Q_FUNC_INFO;
@ -373,26 +375,29 @@ InfoSystemCacheThread::cache() const
}
InfoSystemWorkerThread::InfoSystemWorkerThread( QObject *parent )
InfoSystemWorkerThread::InfoSystemWorkerThread( QObject* parent )
: QThread( parent )
{
tDebug() << Q_FUNC_INFO;
}
InfoSystemWorkerThread::~InfoSystemWorkerThread()
{
tDebug() << Q_FUNC_INFO;
}
void
InfoSystemWorkerThread::InfoSystemWorkerThread::run()
{
m_worker = QPointer< InfoSystemWorker >( new InfoSystemWorker() );
exec();
if( !m_worker.isNull() )
if ( !m_worker.isNull() )
delete m_worker.data();
}
InfoSystemWorker*
InfoSystemWorkerThread::worker() const
{
@ -401,7 +406,6 @@ InfoSystemWorkerThread::worker() const
return m_worker.data();
}
} //namespace InfoSystem
} //namespace Tomahawk

View File

@ -65,7 +65,7 @@ struct DLLEXPORT InfoRequestData {
InfoRequestData();
InfoRequestData( const quint64 rId, const QString &callr, const Tomahawk::InfoSystem::InfoType typ, const QVariant &inputvar, const QVariantMap &custom );
InfoRequestData( const quint64 rId, const QString& callr, const Tomahawk::InfoSystem::InfoType typ, const QVariant& inputvar, const QVariantMap& custom );
private:
void init( const QString& callr, const InfoType typ, const QVariant& inputvar, const QVariantMap& custom);
@ -87,7 +87,7 @@ struct InfoPushData {
, infoPair( Tomahawk::InfoSystem::PushInfoPair( QVariantMap(), QVariant() ) )
{}
InfoPushData( const QString &callr, const Tomahawk::InfoSystem::InfoType typ, const QVariant &inputvar, const Tomahawk::InfoSystem::PushInfoFlags pflags )
InfoPushData( const QString& callr, const Tomahawk::InfoSystem::InfoType typ, const QVariant& inputvar, const Tomahawk::InfoSystem::PushInfoFlags pflags )
: caller( callr )
, type( typ )
, input( inputvar )
@ -152,7 +152,7 @@ class DLLEXPORT InfoSystemCacheThread : public QThread
Q_OBJECT
public:
InfoSystemCacheThread( QObject *parent );
InfoSystemCacheThread( QObject* parent );
virtual ~InfoSystemCacheThread();
void run();
@ -170,7 +170,7 @@ class DLLEXPORT InfoSystemWorkerThread : public QThread
Q_OBJECT
public:
InfoSystemWorkerThread( QObject *parent );
InfoSystemWorkerThread( QObject* parent );
virtual ~InfoSystemWorkerThread();
void run();
@ -196,7 +196,7 @@ public:
bool getInfo( const InfoRequestData& requestData );
//WARNING: if changing timeoutMillis above, also change in below function in .cpp file
bool getInfo( const QString &caller, const QVariantMap& customData, const InfoTypeMap& inputMap, const InfoTimeoutMap& timeoutMap = InfoTimeoutMap(), bool allSources = false );
bool getInfo( const QString& caller, const QVariantMap& customData, const InfoTypeMap& inputMap, const InfoTimeoutMap& timeoutMap = InfoTimeoutMap(), bool allSources = false );
bool pushInfo( InfoPushData pushData );
bool pushInfo( const QString& caller, const InfoTypeMap& input, const PushInfoFlags pushFlags );
@ -214,6 +214,7 @@ signals:
void info( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void finished( QString target );
void finished( QString target, Tomahawk::InfoSystem::InfoType type );
void ready();
void updatedSupportedGetTypes( Tomahawk::InfoSystem::InfoTypeSet supportedTypes );
void updatedSupportedPushTypes( Tomahawk::InfoSystem::InfoTypeSet supportedTypes );

View File

@ -43,6 +43,7 @@ namespace InfoSystem
InfoSystemWorker::InfoSystemWorker()
: QObject()
, m_cache( 0 )
{
tDebug() << Q_FUNC_INFO;
@ -128,7 +129,7 @@ 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 );
emit updatedSupportedGetTypes( QSet< InfoType >::fromList( m_infoGetMap.keys() ) );