mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Add ability to query all sources with a getInfo call. Watch out for finished() :-)
This commit is contained in:
@@ -120,15 +120,15 @@ InfoSystem::newNam() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InfoSystem::getInfo( const InfoRequestData &requestData, uint timeoutMillis )
|
InfoSystem::getInfo( const InfoRequestData &requestData, uint timeoutMillis, bool allSources )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ), Q_ARG( uint, timeoutMillis ) );
|
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ), Q_ARG( uint, timeoutMillis ), Q_ARG( bool, allSources ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InfoSystem::getInfo( const QString &caller, const InfoTypeMap &inputMap, const QVariantMap &customData, const InfoTimeoutMap &timeoutMap )
|
InfoSystem::getInfo( const QString &caller, const InfoTypeMap &inputMap, const QVariantMap &customData, const InfoTimeoutMap &timeoutMap, bool allSources )
|
||||||
{
|
{
|
||||||
InfoRequestData requestData;
|
InfoRequestData requestData;
|
||||||
requestData.caller = caller;
|
requestData.caller = caller;
|
||||||
@@ -137,7 +137,7 @@ InfoSystem::getInfo( const QString &caller, const InfoTypeMap &inputMap, const Q
|
|||||||
{
|
{
|
||||||
requestData.type = type;
|
requestData.type = type;
|
||||||
requestData.input = inputMap[ type ];
|
requestData.input = inputMap[ type ];
|
||||||
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ), Q_ARG( uint, ( timeoutMap.contains( type ) ? timeoutMap[ type ] : 0 ) ) );
|
QMetaObject::invokeMethod( m_worker.data(), "getInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ), Q_ARG( uint, ( timeoutMap.contains( type ) ? timeoutMap[ type ] : 0 ) ), Q_ARG( bool, allSources ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -201,9 +201,9 @@ public:
|
|||||||
InfoSystem( QObject *parent );
|
InfoSystem( QObject *parent );
|
||||||
~InfoSystem();
|
~InfoSystem();
|
||||||
|
|
||||||
void getInfo( const InfoRequestData &requestData, uint timeoutMillis = 0 );
|
void getInfo( const InfoRequestData &requestData, uint timeoutMillis = 0, bool allSources = false );
|
||||||
//WARNING: if changing timeoutMillis above, also change in below function in .cpp file
|
//WARNING: if changing timeoutMillis above, also change in below function in .cpp file
|
||||||
void getInfo( const QString &caller, const InfoTypeMap &inputMap, const QVariantMap &customData, const InfoTimeoutMap &timeoutMap = InfoTimeoutMap() );
|
void getInfo( const QString &caller, const InfoTypeMap &inputMap, const QVariantMap &customData, const InfoTimeoutMap &timeoutMap = InfoTimeoutMap(), bool allSources = false );
|
||||||
void pushInfo( const QString &caller, const InfoType type, const QVariant &input );
|
void pushInfo( const QString &caller, const InfoType type, const QVariant &input );
|
||||||
void pushInfo( const QString &caller, const InfoTypeMap &input );
|
void pushInfo( const QString &caller, const InfoTypeMap &input );
|
||||||
|
|
||||||
|
@@ -153,12 +153,12 @@ InfoSystemWorker::registerInfoTypes( const InfoPluginPtr &plugin, const QSet< In
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QLinkedList< InfoPluginPtr >
|
QList< InfoPluginPtr >
|
||||||
InfoSystemWorker::determineOrderedMatches( const InfoType type ) const
|
InfoSystemWorker::determineOrderedMatches( const InfoType type ) const
|
||||||
{
|
{
|
||||||
//Dummy function for now that returns the various items in the QSet; at some point this will
|
//Dummy function for now that returns the various items in the QSet; at some point this will
|
||||||
//probably need to support ordering based on the data source
|
//probably need to support ordering based on the data source
|
||||||
QLinkedList< InfoPluginPtr > providers;
|
QList< InfoPluginPtr > providers;
|
||||||
Q_FOREACH( InfoPluginPtr ptr, m_infoGetMap[type] )
|
Q_FOREACH( InfoPluginPtr ptr, m_infoGetMap[type] )
|
||||||
providers << ptr;
|
providers << ptr;
|
||||||
return providers;
|
return providers;
|
||||||
@@ -166,11 +166,11 @@ InfoSystemWorker::determineOrderedMatches( const InfoType type ) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis )
|
InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis, bool allSources )
|
||||||
{
|
{
|
||||||
// qDebug() << Q_FUNC_INFO;
|
// qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
QLinkedList< InfoPluginPtr > providers = determineOrderedMatches( requestData.type );
|
QList< InfoPluginPtr > providers = determineOrderedMatches( requestData.type );
|
||||||
if ( providers.isEmpty() )
|
if ( providers.isEmpty() )
|
||||||
{
|
{
|
||||||
emit info( requestData, QVariant() );
|
emit info( requestData, QVariant() );
|
||||||
@@ -178,33 +178,42 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, ui
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InfoPluginPtr ptr = providers.first();
|
if ( !allSources )
|
||||||
if ( !ptr )
|
providers = QList< InfoPluginPtr >( providers.mid( 0, 1 ) );
|
||||||
|
|
||||||
|
bool foundOne = false;
|
||||||
|
foreach ( InfoPluginPtr ptr, providers )
|
||||||
|
{
|
||||||
|
if ( !ptr )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foundOne = true;
|
||||||
|
uint requestId = ++m_nextRequest;
|
||||||
|
m_requestSatisfiedMap[ requestId ] = false;
|
||||||
|
if ( timeoutMillis != 0 )
|
||||||
|
{
|
||||||
|
qint64 currMs = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
m_timeRequestMapper.insert( currMs + timeoutMillis, requestId );
|
||||||
|
}
|
||||||
|
// qDebug() << "Assigning request with requestId" << requestId << "and type" << requestData.type;
|
||||||
|
m_dataTracker[ requestData.caller ][ requestData.type ] = m_dataTracker[ requestData.caller ][ requestData.type ] + 1;
|
||||||
|
// qDebug() << "Current count in dataTracker for target" << requestData.caller << "and type" << requestData.type << "is" << m_dataTracker[ requestData.caller ][ requestData.type ];
|
||||||
|
|
||||||
|
InfoRequestData* data = new InfoRequestData;
|
||||||
|
data->caller = requestData.caller;
|
||||||
|
data->type = requestData.type;
|
||||||
|
data->input = requestData.input;
|
||||||
|
data->customData = requestData.customData;
|
||||||
|
m_savedRequestMap[ requestId ] = data;
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod( ptr.data(), "getInfo", Qt::QueuedConnection, Q_ARG( uint, requestId ), Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !foundOne )
|
||||||
{
|
{
|
||||||
emit info( requestData, QVariant() );
|
emit info( requestData, QVariant() );
|
||||||
checkFinished( requestData.caller );
|
checkFinished( requestData.caller );
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint requestId = ++m_nextRequest;
|
|
||||||
m_requestSatisfiedMap[ requestId ] = false;
|
|
||||||
if ( timeoutMillis != 0 )
|
|
||||||
{
|
|
||||||
qint64 currMs = QDateTime::currentMSecsSinceEpoch();
|
|
||||||
m_timeRequestMapper.insert( currMs + timeoutMillis, requestId );
|
|
||||||
}
|
|
||||||
// qDebug() << "Assigning request with requestId" << requestId << "and type" << requestData.type;
|
|
||||||
m_dataTracker[ requestData.caller ][ requestData.type ] = m_dataTracker[ requestData.caller ][ requestData.type ] + 1;
|
|
||||||
// qDebug() << "Current count in dataTracker for target" << requestData.caller << "and type" << requestData.type << "is" << m_dataTracker[ requestData.caller ][ requestData.type ];
|
|
||||||
|
|
||||||
InfoRequestData* data = new InfoRequestData;
|
|
||||||
data->caller = requestData.caller;
|
|
||||||
data->type = requestData.type;
|
|
||||||
data->input = requestData.input;
|
|
||||||
data->customData = requestData.customData;
|
|
||||||
m_savedRequestMap[ requestId ] = data;
|
|
||||||
|
|
||||||
QMetaObject::invokeMethod( ptr.data(), "getInfo", Qt::QueuedConnection, Q_ARG( uint, requestId ), Q_ARG( Tomahawk::InfoSystem::InfoRequestData, requestData ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -21,13 +21,13 @@
|
|||||||
|
|
||||||
#include "infosystem/infosystem.h"
|
#include "infosystem/infosystem.h"
|
||||||
|
|
||||||
#include <QNetworkAccessManager>
|
#include <QtNetwork/QNetworkAccessManager>
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QtDebug>
|
#include <QtCore/QtDebug>
|
||||||
#include <QtCore/QMap>
|
#include <QtCore/QMap>
|
||||||
#include <QtCore/QWeakPointer>
|
#include <QtCore/QWeakPointer>
|
||||||
#include <QtCore/QSet>
|
#include <QtCore/QSet>
|
||||||
#include <QtCore/QLinkedList>
|
#include <QtCore/QList>
|
||||||
#include <QtCore/QVariant>
|
#include <QtCore/QVariant>
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > cache );
|
void init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > cache );
|
||||||
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis );
|
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis, bool allSources );
|
||||||
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
|
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
|
||||||
|
|
||||||
void infoSlot( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
void infoSlot( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||||
@@ -76,13 +76,13 @@ private:
|
|||||||
QHash< uint, bool > m_requestSatisfiedMap;
|
QHash< uint, bool > m_requestSatisfiedMap;
|
||||||
QHash< uint, InfoRequestData* > m_savedRequestMap;
|
QHash< uint, InfoRequestData* > m_savedRequestMap;
|
||||||
|
|
||||||
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
QList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
||||||
|
|
||||||
// For now, statically instantiate plugins; this is just somewhere to keep them
|
// For now, statically instantiate plugins; this is just somewhere to keep them
|
||||||
QLinkedList< InfoPluginPtr > m_plugins;
|
QList< InfoPluginPtr > m_plugins;
|
||||||
|
|
||||||
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoGetMap;
|
QMap< InfoType, QList< InfoPluginPtr > > m_infoGetMap;
|
||||||
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoPushMap;
|
QMap< InfoType, QList< InfoPluginPtr > > m_infoPushMap;
|
||||||
|
|
||||||
QWeakPointer< QNetworkAccessManager> m_nam;
|
QWeakPointer< QNetworkAccessManager> m_nam;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user