diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index f99f146a6..c20cb0cfa 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -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 ); diff --git a/src/libtomahawk/accounts/ResolverAccount.cpp b/src/libtomahawk/accounts/ResolverAccount.cpp index 890ac75a3..501add13f 100644 --- a/src/libtomahawk/accounts/ResolverAccount.cpp +++ b/src/libtomahawk/accounts/ResolverAccount.cpp @@ -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 ) ); } diff --git a/src/libtomahawk/infosystem/infosystem.cpp b/src/libtomahawk/infosystem/infosystem.cpp index 019a69a50..a16e28ecc 100644 --- a/src/libtomahawk/infosystem/infosystem.cpp +++ b/src/libtomahawk/infosystem/infosystem.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2012 Leo Franchi * * 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 ) { diff --git a/src/libtomahawk/infosystem/infosystem.h b/src/libtomahawk/infosystem/infosystem.h index 077821882..1b9b5f988 100644 --- a/src/libtomahawk/infosystem/infosystem.h +++ b/src/libtomahawk/infosystem/infosystem.h @@ -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 diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index 4a54d5cda..25947e223 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2012 Leo Franchi * * 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 ) ) + ); } diff --git a/src/libtomahawk/infosystem/infosystemworker.h b/src/libtomahawk/infosystem/infosystemworker.h index 45634c6a2..bf530114f 100644 --- a/src/libtomahawk/infosystem/infosystemworker.h +++ b/src/libtomahawk/infosystem/infosystemworker.h @@ -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;