1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02: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:
Leo Franchi
2012-02-18 18:15:13 -05:00
parent 443c554b36
commit 3e81405086
6 changed files with 89 additions and 81 deletions

View File

@@ -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 );

View File

@@ -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 ) );
}

View File

@@ -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
@@ -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 )
{

View File

@@ -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 );
@@ -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

View File

@@ -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 ) )
);
}

View File

@@ -37,6 +37,8 @@ namespace Tomahawk {
namespace InfoSystem {
class InfoSystemCache;
class DLLEXPORT InfoSystemWorker : public QObject
{
@@ -47,7 +49,6 @@ 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 );
@@ -61,6 +62,7 @@ public slots:
void infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void addInfoPlugin( InfoPlugin* plugin );
private slots:
void checkTimeoutsTimerFired();
@@ -74,6 +76,9 @@ private:
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;