From fb9069320ed08530c589bf13205c6deee6195bb6 Mon Sep 17 00:00:00 2001 From: Alejandro Wainzinger Date: Sat, 7 May 2011 12:03:52 -0700 Subject: [PATCH] Build AdiumPlugin, now a pushInfo-using InfoPlugin. --- src/libtomahawk/CMakeLists.txt | 14 +++- src/libtomahawk/audio/audioengine.cpp | 11 +++ .../infosystem/infoplugins/adiumplugin.cpp | 68 +++++++++++-------- .../infosystem/infoplugins/adiumplugin.h | 16 +++-- src/libtomahawk/infosystem/infosystem.cpp | 1 + src/libtomahawk/infosystem/infosystem.h | 4 +- .../infosystem/infosystemworker.cpp | 3 + 7 files changed, 82 insertions(+), 35 deletions(-) diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 3e1d9e258..3ebd0a70f 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -382,7 +382,17 @@ ENDIF( WIN32 ) IF( APPLE ) FIND_LIBRARY( COREAUDIO_LIBRARY CoreAudio ) FIND_LIBRARY( COREFOUNDATION_LIBRARY CoreFoundation ) - MARK_AS_ADVANCED( COREAUDIO_LIBRARY COREFOUNDATION_LIBRARY ) + FIND_LIBRARY( FOUNDATION_LIBRARY Foundation ) + FIND_LIBRARY( SCRIPTINGBRIDGE_LIBRARY ScriptingBridge ) + MARK_AS_ADVANCED( COREAUDIO_LIBRARY COREFOUNDATION_LIBRARY FOUNDATION_LIBRARY SCRIPTINGBRIDGE_LIBRARY ) + + SET( libSources ${libSources} + infosystem/infoplugins/adium.mm + infosystem/infoplugins/adiumplugin.cpp ) + + SET( libHeaders ${libHeaders} + infosystem/infoplugins/adium.h + infosystem/infoplugins/adiumplugin.h ) SET( OS_SPECIFIC_LINK_LIBRARIES ${OS_SPECIFIC_LINK_LIBRARIES} @@ -391,6 +401,8 @@ IF( APPLE ) # System ${COREAUDIO_LIBRARY} ${COREFOUNDATION_LIBRARY} + ${FOUNDATION_LIBRARY} + ${SCRIPTINGBRIDGE_LIBRARY} ) ENDIF( APPLE ) diff --git a/src/libtomahawk/audio/audioengine.cpp b/src/libtomahawk/audio/audioengine.cpp index 657c38c7a..6e4def041 100644 --- a/src/libtomahawk/audio/audioengine.cpp +++ b/src/libtomahawk/audio/audioengine.cpp @@ -24,10 +24,12 @@ #include "database/database.h" #include "database/databasecommand_logplayback.h" +#include "infosystem/infosystem.h" #include "network/servent.h" AudioEngine* AudioEngine::s_instance = 0; +static QString s_aeInfoIdentifier = QString( "AUDIOENGINE" ); AudioEngine* AudioEngine::instance() @@ -217,6 +219,15 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result ) DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( m_currentTrack, DatabaseCommand_LogPlayback::Started ); Database::instance()->enqueue( QSharedPointer(cmd) ); + + Tomahawk::InfoSystem::InfoCriteriaHash trackInfo; + + trackInfo["title"] = m_currentTrack->track(); + trackInfo["artist"] = m_currentTrack->artist()->name(); + Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( + s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowPlaying, + QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ) ); + } } diff --git a/src/libtomahawk/infosystem/infoplugins/adiumplugin.cpp b/src/libtomahawk/infosystem/infoplugins/adiumplugin.cpp index acb36d30e..bc910f403 100644 --- a/src/libtomahawk/infosystem/infoplugins/adiumplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/adiumplugin.cpp @@ -18,6 +18,7 @@ #include +#include "infosystem/infosystemworker.h" #include "artist.h" #include "result.h" @@ -37,30 +38,15 @@ static void setStatus(const QString &status) using namespace Tomahawk::InfoSystem; -AdiumPlugin::AdiumPlugin(QObject *parent) +AdiumPlugin::AdiumPlugin( InfoSystemWorker* parent ) : InfoPlugin(parent) { /** No supported types since the plugin pushes info, doesn't get any */ qDebug() << Q_FUNC_INFO; - QSet< InfoType > supportedTypes; - InfoSystem *system = qobject_cast< InfoSystem* >(parent); - system->registerInfoTypes(this, supportedTypes); + QSet< InfoType > supportedGetTypes, supportedPushTypes; + supportedPushTypes << InfoNowPlaying; + parent->registerInfoTypes( this, supportedGetTypes, supportedPushTypes ); - /** Connect to audio state signals. - TODO: Move this into InfoSystem? There could end up being many plugins - connected to audio state signals. */ - - connect( system, SIGNAL( audioStarted( const Tomahawk::result_ptr& ) ), - SLOT( audioStarted( const Tomahawk::result_ptr& ) ) ); - connect( system, SIGNAL( audioFinished( const Tomahawk::result_ptr& ) ), - SLOT( audioFinished( const Tomahawk::result_ptr& ) ) ); - connect( system, SIGNAL( audioStopped() ), - SLOT( audioStopped() ) ); - connect( system, SIGNAL( audioPaused() ), - SLOT( audioPaused() ) ); - connect( system, SIGNAL( audioResumed( const Tomahawk::result_ptr& ) ), - SLOT( audioResumed( const Tomahawk::result_ptr& ) ) ); - } AdiumPlugin::~AdiumPlugin() @@ -69,7 +55,8 @@ AdiumPlugin::~AdiumPlugin() setStatus( "" ); } -void AdiumPlugin::getInfo(const QString &caller, const InfoType type, const QVariant& data, InfoCustomData customData) +void +AdiumPlugin::getInfo( const QString caller, const InfoType type, const QVariant data, InfoCustomData customData ) { switch (type) { @@ -81,19 +68,44 @@ void AdiumPlugin::getInfo(const QString &caller, const InfoType type, const QVar } } -/** Audio state slots */ - -void AdiumPlugin::audioStarted( const Tomahawk::result_ptr& track ) +void +AdiumPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input ) { qDebug() << Q_FUNC_INFO; + + switch ( type ) + { + case InfoNowPlaying: + audioStarted( input ); + break; + + default: + return; + } +} + +/** Audio state slots */ +void AdiumPlugin::audioStarted( const QVariant &input ) +//void AdiumPlugin::audioStarted( const Tomahawk::result_ptr& track ) +{ + qDebug() << Q_FUNC_INFO; + + if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() ) + return; + + InfoCriteriaHash hash = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); + if ( !hash.contains( "title" ) || !hash.contains( "artist" ) ) + return; + QString nowPlaying = ""; - nowPlaying.append( track->track() ); + nowPlaying.append( hash["title"] ); nowPlaying.append(" - "); - nowPlaying.append(track->artist()->name()); + nowPlaying.append( hash["artist"] ); setStatus( nowPlaying ); } -void AdiumPlugin::audioFinished( const Tomahawk::result_ptr& track ) +void +AdiumPlugin::audioFinished( const QVariant &input ) { //qDebug() << Q_FUNC_INFO; } @@ -112,10 +124,10 @@ void AdiumPlugin::audioPaused() setStatus( "Paused" ); } -void AdiumPlugin::audioResumed( const Tomahawk::result_ptr& track ) +void AdiumPlugin::audioResumed( const QVariant &input ) { qDebug() << Q_FUNC_INFO; // TODO: audio resumed, so push update status to Adium with playing track - this->audioStarted( track ); + audioStarted( input ); } diff --git a/src/libtomahawk/infosystem/infoplugins/adiumplugin.h b/src/libtomahawk/infosystem/infoplugins/adiumplugin.h index 604432ab1..f67f2126f 100644 --- a/src/libtomahawk/infosystem/infoplugins/adiumplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/adiumplugin.h @@ -22,6 +22,7 @@ #include "infosystem/infosystem.h" #include +#include namespace Tomahawk { @@ -32,17 +33,22 @@ class AdiumPlugin : public InfoPlugin Q_OBJECT public: - AdiumPlugin( QObject *parent ); + AdiumPlugin( InfoSystemWorker *parent ); virtual ~AdiumPlugin(); - void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData ); +protected slots: + void getInfo( const QString caller, const InfoType type, const QVariant data, InfoCustomData customData ); + void pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input ); public slots: - void audioStarted( const Tomahawk::result_ptr& track ); - void audioFinished( const Tomahawk::result_ptr& track ); + void audioStarted( const QVariant &input ); + void audioFinished( const QVariant &input ); void audioStopped(); void audioPaused(); - void audioResumed( const Tomahawk::result_ptr& track ); + void audioResumed( const QVariant &input ); + + void namChangedSlot() {} // unused + void notInCacheSlot( const Tomahawk::InfoSystem::InfoCriteriaHash criteria, const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData ) {} // unused }; diff --git a/src/libtomahawk/infosystem/infosystem.cpp b/src/libtomahawk/infosystem/infosystem.cpp index e42edda5b..4dbddeee4 100644 --- a/src/libtomahawk/infosystem/infosystem.cpp +++ b/src/libtomahawk/infosystem/infosystem.cpp @@ -25,6 +25,7 @@ #include "infoplugins/echonestplugin.h" #include "infoplugins/musixmatchplugin.h" #include "infoplugins/lastfmplugin.h" +#include "infoplugins/adiumplugin.h" namespace Tomahawk { diff --git a/src/libtomahawk/infosystem/infosystem.h b/src/libtomahawk/infosystem/infosystem.h index f4fe24871..b03b4e2cd 100644 --- a/src/libtomahawk/infosystem/infosystem.h +++ b/src/libtomahawk/infosystem/infosystem.h @@ -92,7 +92,9 @@ enum InfoType { // as items are saved in cache, mark them here to not change the InfoSubmitNowPlaying = 46, InfoSubmitScrobble = 47, - InfoNoInfo = 48 + InfoNowPlaying = 48, + + InfoNoInfo = 49 }; typedef QMap< InfoType, QVariant > InfoMap; diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index 4b376a932..99a6e190e 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -26,6 +26,7 @@ #include "infoplugins/echonestplugin.h" #include "infoplugins/musixmatchplugin.h" #include "infoplugins/lastfmplugin.h" +#include "infoplugins/adiumplugin.h" #include "lastfm/NetworkAccessManager" @@ -61,6 +62,8 @@ void InfoSystemWorker::init() m_plugins.append( mmptr ); InfoPluginPtr lfmptr( new LastFmPlugin( this ) ); m_plugins.append( lfmptr ); + InfoPluginPtr admptr( new AdiumPlugin( this ) ); + m_plugins.append( admptr ); InfoSystemCache *cache = InfoSystem::instance()->getCache();