mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 15:29:42 +01:00
Add ability to add infoplugins to infosystem
also, add infoplugins from accounts that support them, and clean up adding new info plugins in infoworker
This commit is contained in:
parent
443c554b36
commit
3e81405086
@ -291,7 +291,14 @@ AccountManager::addAccount( Account* account )
|
||||
if ( account->types() & Accounts::SipType )
|
||||
m_accountsByAccountType[ Accounts::SipType ].append( account );
|
||||
if ( account->types() & Accounts::InfoType )
|
||||
{
|
||||
m_accountsByAccountType[ Accounts::InfoType ].append( account );
|
||||
|
||||
if ( account->infoPlugin() )
|
||||
{
|
||||
InfoSystem::InfoSystem::instance()->addInfoPlugin( account->infoPlugin() );
|
||||
}
|
||||
}
|
||||
if ( account->types() & Accounts::ResolverType )
|
||||
m_accountsByAccountType[ Accounts::ResolverType ].append( account );
|
||||
|
||||
|
@ -67,13 +67,13 @@ ResolverAccount::ResolverAccount( const QString& accountId )
|
||||
// We should have a valid saved path
|
||||
Q_ASSERT( !path.isEmpty() );
|
||||
|
||||
m_resolver = qobject_cast< ExternalResolverGui* >( Pipeline::instance()->addScriptResolver( path, enabled() ) );
|
||||
connect( m_resolver, SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
|
||||
m_resolver = QWeakPointer< ExternalResolverGui >( qobject_cast< ExternalResolverGui* >( Pipeline::instance()->addScriptResolver( path, enabled() ) ) );
|
||||
connect( m_resolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
|
||||
|
||||
// What resolver do we have here? Should only be types that are 'real' resolvers
|
||||
Q_ASSERT ( m_resolver );
|
||||
Q_ASSERT ( !m_resolver.isNull() );
|
||||
|
||||
setAccountFriendlyName( m_resolver->name() );
|
||||
setAccountFriendlyName( m_resolver.data()->name() );
|
||||
setTypes( AccountType( ResolverType ) );
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -111,17 +112,17 @@ InfoSystem::init()
|
||||
|
||||
connect( cache, SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||
worker, SLOT( infoSlot( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
|
||||
|
||||
|
||||
connect( worker, SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||
this, SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
|
||||
|
||||
|
||||
connect( worker, SIGNAL( finished( QString ) ), this, SIGNAL( finished( QString ) ), Qt::UniqueConnection );
|
||||
|
||||
|
||||
connect( worker, SIGNAL( finished( QString, Tomahawk::InfoSystem::InfoType ) ),
|
||||
this, SIGNAL( finished( QString, Tomahawk::InfoSystem::InfoType ) ), Qt::UniqueConnection );
|
||||
|
||||
QMetaObject::invokeMethod( worker, "init", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoSystemCache*, cache ) );
|
||||
|
||||
|
||||
m_inited = true;
|
||||
}
|
||||
|
||||
@ -195,6 +196,13 @@ InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InfoSystem::addInfoPlugin( InfoPlugin* plugin )
|
||||
{
|
||||
QMetaObject::invokeMethod( m_infoSystemWorkerThreadController->worker(), "addInfoPlugin", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoPlugin*, plugin ) );
|
||||
}
|
||||
|
||||
|
||||
InfoSystemCacheThread::InfoSystemCacheThread( QObject *parent )
|
||||
: QThread( parent )
|
||||
{
|
||||
|
@ -134,7 +134,7 @@ struct InfoRequestData {
|
||||
QVariantMap customData;
|
||||
uint timeoutMillis;
|
||||
bool allSources;
|
||||
|
||||
|
||||
InfoRequestData()
|
||||
: requestId( TomahawkUtils::infosystemRequestId() )
|
||||
, internalId( TomahawkUtils::infosystemRequestId() )
|
||||
@ -145,7 +145,7 @@ struct InfoRequestData {
|
||||
, timeoutMillis( 10000 )
|
||||
, allSources( false )
|
||||
{}
|
||||
|
||||
|
||||
InfoRequestData( const quint64 rId, const QString &callr, const Tomahawk::InfoSystem::InfoType typ, const QVariant &inputvar, const QVariantMap &custom )
|
||||
: requestId( rId )
|
||||
, internalId( TomahawkUtils::infosystemRequestId() )
|
||||
@ -242,6 +242,9 @@ public:
|
||||
bool pushInfo( const QString &caller, const InfoType type, const QVariant &input );
|
||||
bool pushInfo( const QString &caller, const InfoTypeMap &input );
|
||||
|
||||
// InfoSystem takes ownership of InfoPlugins
|
||||
void addInfoPlugin( InfoPlugin* plugin );
|
||||
|
||||
signals:
|
||||
void info( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
void finished( QString target );
|
||||
@ -249,7 +252,7 @@ signals:
|
||||
|
||||
private slots:
|
||||
void init();
|
||||
|
||||
|
||||
private:
|
||||
bool m_inited;
|
||||
InfoSystemCacheThread* m_infoSystemCacheThreadController;
|
||||
@ -289,5 +292,6 @@ Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoRequestData );
|
||||
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoStringHash );
|
||||
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoSystemCache* );
|
||||
Q_DECLARE_METATYPE( QList< Tomahawk::InfoSystem::InfoStringHash > );
|
||||
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoPlugin* );
|
||||
|
||||
#endif // TOMAHAWK_INFOSYSTEM_H
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -27,7 +28,6 @@
|
||||
#include "infoplugins/generic/musixmatchplugin.h"
|
||||
#include "infoplugins/generic/chartsplugin.h"
|
||||
#include "infoplugins/generic/spotifyPlugin.h"
|
||||
#include "infoplugins/generic/lastfmplugin.h"
|
||||
#include "infoplugins/generic/musicbrainzPlugin.h"
|
||||
#include "infoplugins/generic/hypemPlugin.h"
|
||||
#include "utils/tomahawkutils.h"
|
||||
@ -41,7 +41,6 @@
|
||||
#include "infoplugins/unix/mprisplugin.h"
|
||||
#endif
|
||||
|
||||
#include "lastfm/NetworkAccessManager"
|
||||
#include "infoplugins/generic/RoviPlugin.h"
|
||||
|
||||
namespace Tomahawk
|
||||
@ -78,71 +77,56 @@ void
|
||||
InfoSystemWorker::init( Tomahawk::InfoSystem::InfoSystemCache* cache )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
m_cache = cache;
|
||||
#ifndef ENABLE_HEADLESS
|
||||
InfoPluginPtr enptr( new EchoNestPlugin() );
|
||||
m_plugins.append( enptr );
|
||||
registerInfoTypes( enptr, enptr.data()->supportedGetTypes(), enptr.data()->supportedPushTypes() );
|
||||
InfoPluginPtr mmptr( new MusixMatchPlugin() );
|
||||
m_plugins.append( mmptr );
|
||||
registerInfoTypes( mmptr, mmptr.data()->supportedGetTypes(), mmptr.data()->supportedPushTypes() );
|
||||
InfoPluginPtr mbptr( new MusicBrainzPlugin() );
|
||||
m_plugins.append( mbptr );
|
||||
registerInfoTypes( mbptr, mbptr.data()->supportedGetTypes(), mbptr.data()->supportedPushTypes() );
|
||||
InfoPluginPtr lfmptr( new LastFmPlugin() );
|
||||
m_plugins.append( lfmptr );
|
||||
registerInfoTypes( lfmptr, lfmptr.data()->supportedGetTypes(), lfmptr.data()->supportedPushTypes() );
|
||||
InfoPluginPtr sptr( new ChartsPlugin() );
|
||||
m_plugins.append( sptr );
|
||||
registerInfoTypes( sptr, sptr.data()->supportedGetTypes(), sptr.data()->supportedPushTypes() );
|
||||
InfoPluginPtr roviptr( new RoviPlugin() );
|
||||
m_plugins.append( roviptr );
|
||||
registerInfoTypes( roviptr, roviptr.data()->supportedGetTypes(), roviptr.data()->supportedPushTypes() );
|
||||
InfoPluginPtr spotptr( new SpotifyPlugin() );
|
||||
m_plugins.append( spotptr );
|
||||
registerInfoTypes( spotptr, spotptr.data()->supportedGetTypes(), spotptr.data()->supportedPushTypes() );
|
||||
InfoPluginPtr hypeptr( new hypemPlugin() );
|
||||
m_plugins.append( hypeptr );
|
||||
registerInfoTypes( hypeptr, hypeptr.data()->supportedGetTypes(), hypeptr.data()->supportedPushTypes() );
|
||||
addInfoPlugin( new EchoNestPlugin() );
|
||||
addInfoPlugin( new MusixMatchPlugin() );
|
||||
addInfoPlugin( new MusicBrainzPlugin() );
|
||||
addInfoPlugin( new ChartsPlugin() );
|
||||
addInfoPlugin( new RoviPlugin() );
|
||||
addInfoPlugin( new SpotifyPlugin() );
|
||||
addInfoPlugin( new hypemPlugin() );
|
||||
#endif
|
||||
|
||||
#ifdef Q_WS_MAC
|
||||
InfoPluginPtr admptr( new AdiumPlugin() );
|
||||
m_plugins.append( admptr );
|
||||
registerInfoTypes( admptr, admptr.data()->supportedGetTypes(), admptr.data()->supportedPushTypes() );
|
||||
#endif
|
||||
#ifndef ENABLE_HEADLESS
|
||||
#ifdef Q_WS_X11
|
||||
InfoPluginPtr fdonotifyptr( new FdoNotifyPlugin() );
|
||||
m_plugins.append( fdonotifyptr );
|
||||
registerInfoTypes( fdonotifyptr, fdonotifyptr.data()->supportedGetTypes(), fdonotifyptr.data()->supportedPushTypes() );
|
||||
InfoPluginPtr mprisptr( new MprisPlugin() );
|
||||
m_plugins.append( mprisptr );
|
||||
registerInfoTypes( mprisptr, mprisptr.data()->supportedGetTypes(), mprisptr.data()->supportedPushTypes() );
|
||||
#endif
|
||||
#ifdef Q_WS_MAC
|
||||
addInfoPlugin( new AdiumPlugin() );
|
||||
#endif
|
||||
Q_FOREACH( InfoPluginPtr plugin, m_plugins )
|
||||
{
|
||||
connect(
|
||||
plugin.data(),
|
||||
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||
this,
|
||||
SLOT( infoSlot( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||
Qt::UniqueConnection
|
||||
);
|
||||
#ifndef ENABLE_HEADLESS
|
||||
#ifdef Q_WS_X11
|
||||
addInfoPlugin( new FdoNotifyPlugin() );
|
||||
addInfoPlugin( new MprisPlugin() );
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
connect(
|
||||
plugin.data(),
|
||||
SIGNAL( getCachedInfo( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoRequestData ) ),
|
||||
cache,
|
||||
SLOT( getCachedInfoSlot( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoRequestData ) )
|
||||
);
|
||||
connect(
|
||||
plugin.data(),
|
||||
SIGNAL( updateCache( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) ),
|
||||
cache,
|
||||
SLOT( updateCacheSlot( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) )
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
InfoSystemWorker::addInfoPlugin( InfoPlugin* plugin )
|
||||
{
|
||||
InfoPluginPtr weakptr( plugin );
|
||||
m_plugins.append( weakptr );
|
||||
registerInfoTypes( weakptr, weakptr.data()->supportedGetTypes(), weakptr.data()->supportedPushTypes() );
|
||||
|
||||
connect(
|
||||
plugin,
|
||||
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||
this,
|
||||
SLOT( infoSlot( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||
Qt::UniqueConnection
|
||||
);
|
||||
|
||||
connect(
|
||||
plugin,
|
||||
SIGNAL( getCachedInfo( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoRequestData ) ),
|
||||
m_cache,
|
||||
SLOT( getCachedInfoSlot( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoRequestData ) )
|
||||
);
|
||||
connect(
|
||||
plugin,
|
||||
SIGNAL( updateCache( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) ),
|
||||
m_cache,
|
||||
SLOT( updateCacheSlot( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,7 +37,9 @@ namespace Tomahawk {
|
||||
|
||||
namespace InfoSystem {
|
||||
|
||||
|
||||
class InfoSystemCache;
|
||||
|
||||
|
||||
class DLLEXPORT InfoSystemWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -47,33 +49,36 @@ public:
|
||||
~InfoSystemWorker();
|
||||
|
||||
void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &getTypes, const QSet< InfoType > &pushTypes );
|
||||
QNetworkAccessManager* nam() const;
|
||||
|
||||
|
||||
signals:
|
||||
void info( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
void finished( QString target );
|
||||
void finished( QString target, Tomahawk::InfoSystem::InfoType type );
|
||||
|
||||
|
||||
public slots:
|
||||
void init( Tomahawk::InfoSystem::InfoSystemCache* cache );
|
||||
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
|
||||
|
||||
void infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
|
||||
|
||||
void addInfoPlugin( InfoPlugin* plugin );
|
||||
private slots:
|
||||
void checkTimeoutsTimerFired();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void checkFinished( const Tomahawk::InfoSystem::InfoRequestData &target );
|
||||
QList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
||||
|
||||
|
||||
QHash< QString, QHash< InfoType, int > > m_dataTracker;
|
||||
QMultiMap< qint64, quint64 > m_timeRequestMapper;
|
||||
QHash< uint, bool > m_requestSatisfiedMap;
|
||||
QHash< uint, InfoRequestData* > m_savedRequestMap;
|
||||
|
||||
|
||||
// NOTE Cache object lives in a different thread, do not call methods on it directly
|
||||
InfoSystemCache* m_cache;
|
||||
|
||||
// For now, statically instantiate plugins; this is just somewhere to keep them
|
||||
QList< InfoPluginPtr > m_plugins;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user