diff --git a/src/libtomahawk/infosystem/infosystem.cpp b/src/libtomahawk/infosystem/infosystem.cpp index 973be3844..787e5fdee 100644 --- a/src/libtomahawk/infosystem/infosystem.cpp +++ b/src/libtomahawk/infosystem/infosystem.cpp @@ -120,15 +120,15 @@ InfoSystem::newNam() const void -InfoSystem::getInfo( const InfoRequestData &requestData, uint timeoutMillis ) +InfoSystem::getInfo( const InfoRequestData &requestData, uint timeoutMillis, bool allSources ) { 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 -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; requestData.caller = caller; @@ -137,7 +137,7 @@ InfoSystem::getInfo( const QString &caller, const InfoTypeMap &inputMap, const Q { requestData.type = 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 ) ); } } diff --git a/src/libtomahawk/infosystem/infosystem.h b/src/libtomahawk/infosystem/infosystem.h index c918970cb..87366ec4a 100644 --- a/src/libtomahawk/infosystem/infosystem.h +++ b/src/libtomahawk/infosystem/infosystem.h @@ -201,9 +201,9 @@ public: InfoSystem( QObject *parent ); ~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 - 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 InfoTypeMap &input ); diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index 7b11ded1f..b868503cf 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -153,12 +153,12 @@ InfoSystemWorker::registerInfoTypes( const InfoPluginPtr &plugin, const QSet< In } -QLinkedList< InfoPluginPtr > +QList< InfoPluginPtr > InfoSystemWorker::determineOrderedMatches( const InfoType type ) const { //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 - QLinkedList< InfoPluginPtr > providers; + QList< InfoPluginPtr > providers; Q_FOREACH( InfoPluginPtr ptr, m_infoGetMap[type] ) providers << ptr; return providers; @@ -166,11 +166,11 @@ InfoSystemWorker::determineOrderedMatches( const InfoType type ) const void -InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis ) +InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, uint timeoutMillis, bool allSources ) { // qDebug() << Q_FUNC_INFO; - QLinkedList< InfoPluginPtr > providers = determineOrderedMatches( requestData.type ); + QList< InfoPluginPtr > providers = determineOrderedMatches( requestData.type ); if ( providers.isEmpty() ) { emit info( requestData, QVariant() ); @@ -178,33 +178,42 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, ui return; } - InfoPluginPtr ptr = providers.first(); - if ( !ptr ) + if ( !allSources ) + 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() ); 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 ) ); } diff --git a/src/libtomahawk/infosystem/infosystemworker.h b/src/libtomahawk/infosystem/infosystemworker.h index dd0de2b54..419c74b2e 100644 --- a/src/libtomahawk/infosystem/infosystemworker.h +++ b/src/libtomahawk/infosystem/infosystemworker.h @@ -21,13 +21,13 @@ #include "infosystem/infosystem.h" -#include +#include #include #include #include #include #include -#include +#include #include #include @@ -57,7 +57,7 @@ signals: public slots: 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 infoSlot( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); @@ -76,13 +76,13 @@ private: QHash< uint, bool > m_requestSatisfiedMap; 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 - QLinkedList< InfoPluginPtr > m_plugins; + QList< InfoPluginPtr > m_plugins; - QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoGetMap; - QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoPushMap; + QMap< InfoType, QList< InfoPluginPtr > > m_infoGetMap; + QMap< InfoType, QList< InfoPluginPtr > > m_infoPushMap; QWeakPointer< QNetworkAccessManager> m_nam;