1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-09-02 18:33:16 +02:00

Build AdiumPlugin, now a pushInfo-using InfoPlugin.

This commit is contained in:
Alejandro Wainzinger
2011-05-07 12:03:52 -07:00
parent ccc4db2270
commit fb9069320e
7 changed files with 82 additions and 35 deletions

View File

@@ -382,7 +382,17 @@ ENDIF( WIN32 )
IF( APPLE ) IF( APPLE )
FIND_LIBRARY( COREAUDIO_LIBRARY CoreAudio ) FIND_LIBRARY( COREAUDIO_LIBRARY CoreAudio )
FIND_LIBRARY( COREFOUNDATION_LIBRARY CoreFoundation ) 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 SET( OS_SPECIFIC_LINK_LIBRARIES
${OS_SPECIFIC_LINK_LIBRARIES} ${OS_SPECIFIC_LINK_LIBRARIES}
@@ -391,6 +401,8 @@ IF( APPLE )
# System # System
${COREAUDIO_LIBRARY} ${COREAUDIO_LIBRARY}
${COREFOUNDATION_LIBRARY} ${COREFOUNDATION_LIBRARY}
${FOUNDATION_LIBRARY}
${SCRIPTINGBRIDGE_LIBRARY}
) )
ENDIF( APPLE ) ENDIF( APPLE )

View File

@@ -24,10 +24,12 @@
#include "database/database.h" #include "database/database.h"
#include "database/databasecommand_logplayback.h" #include "database/databasecommand_logplayback.h"
#include "infosystem/infosystem.h"
#include "network/servent.h" #include "network/servent.h"
AudioEngine* AudioEngine::s_instance = 0; AudioEngine* AudioEngine::s_instance = 0;
static QString s_aeInfoIdentifier = QString( "AUDIOENGINE" );
AudioEngine* AudioEngine*
AudioEngine::instance() AudioEngine::instance()
@@ -217,6 +219,15 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( m_currentTrack, DatabaseCommand_LogPlayback::Started ); DatabaseCommand_LogPlayback* cmd = new DatabaseCommand_LogPlayback( m_currentTrack, DatabaseCommand_LogPlayback::Started );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(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 ) );
} }
} }

View File

@@ -18,6 +18,7 @@
#include <string.h> #include <string.h>
#include "infosystem/infosystemworker.h"
#include "artist.h" #include "artist.h"
#include "result.h" #include "result.h"
@@ -37,30 +38,15 @@ static void setStatus(const QString &status)
using namespace Tomahawk::InfoSystem; using namespace Tomahawk::InfoSystem;
AdiumPlugin::AdiumPlugin(QObject *parent) AdiumPlugin::AdiumPlugin( InfoSystemWorker* parent )
: InfoPlugin(parent) : InfoPlugin(parent)
{ {
/** No supported types since the plugin pushes info, doesn't get any */ /** No supported types since the plugin pushes info, doesn't get any */
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QSet< InfoType > supportedTypes; QSet< InfoType > supportedGetTypes, supportedPushTypes;
InfoSystem *system = qobject_cast< InfoSystem* >(parent); supportedPushTypes << InfoNowPlaying;
system->registerInfoTypes(this, supportedTypes); 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() AdiumPlugin::~AdiumPlugin()
@@ -69,7 +55,8 @@ AdiumPlugin::~AdiumPlugin()
setStatus( "" ); 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) switch (type)
{ {
@@ -81,19 +68,44 @@ void AdiumPlugin::getInfo(const QString &caller, const InfoType type, const QVar
} }
} }
/** Audio state slots */ void
AdiumPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input )
void AdiumPlugin::audioStarted( const Tomahawk::result_ptr& track )
{ {
qDebug() << Q_FUNC_INFO; 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 = ""; QString nowPlaying = "";
nowPlaying.append( track->track() ); nowPlaying.append( hash["title"] );
nowPlaying.append(" - "); nowPlaying.append(" - ");
nowPlaying.append(track->artist()->name()); nowPlaying.append( hash["artist"] );
setStatus( nowPlaying ); setStatus( nowPlaying );
} }
void AdiumPlugin::audioFinished( const Tomahawk::result_ptr& track ) void
AdiumPlugin::audioFinished( const QVariant &input )
{ {
//qDebug() << Q_FUNC_INFO; //qDebug() << Q_FUNC_INFO;
} }
@@ -112,10 +124,10 @@ void AdiumPlugin::audioPaused()
setStatus( "Paused" ); setStatus( "Paused" );
} }
void AdiumPlugin::audioResumed( const Tomahawk::result_ptr& track ) void AdiumPlugin::audioResumed( const QVariant &input )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
// TODO: audio resumed, so push update status to Adium with playing track // TODO: audio resumed, so push update status to Adium with playing track
this->audioStarted( track ); audioStarted( input );
} }

View File

@@ -22,6 +22,7 @@
#include "infosystem/infosystem.h" #include "infosystem/infosystem.h"
#include <QObject> #include <QObject>
#include <QVariant>
namespace Tomahawk { namespace Tomahawk {
@@ -32,17 +33,22 @@ class AdiumPlugin : public InfoPlugin
Q_OBJECT Q_OBJECT
public: public:
AdiumPlugin( QObject *parent ); AdiumPlugin( InfoSystemWorker *parent );
virtual ~AdiumPlugin(); 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: public slots:
void audioStarted( const Tomahawk::result_ptr& track ); void audioStarted( const QVariant &input );
void audioFinished( const Tomahawk::result_ptr& track ); void audioFinished( const QVariant &input );
void audioStopped(); void audioStopped();
void audioPaused(); 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
}; };

View File

@@ -25,6 +25,7 @@
#include "infoplugins/echonestplugin.h" #include "infoplugins/echonestplugin.h"
#include "infoplugins/musixmatchplugin.h" #include "infoplugins/musixmatchplugin.h"
#include "infoplugins/lastfmplugin.h" #include "infoplugins/lastfmplugin.h"
#include "infoplugins/adiumplugin.h"
namespace Tomahawk namespace Tomahawk
{ {

View File

@@ -92,7 +92,9 @@ enum InfoType { // as items are saved in cache, mark them here to not change the
InfoSubmitNowPlaying = 46, InfoSubmitNowPlaying = 46,
InfoSubmitScrobble = 47, InfoSubmitScrobble = 47,
InfoNoInfo = 48 InfoNowPlaying = 48,
InfoNoInfo = 49
}; };
typedef QMap< InfoType, QVariant > InfoMap; typedef QMap< InfoType, QVariant > InfoMap;

View File

@@ -26,6 +26,7 @@
#include "infoplugins/echonestplugin.h" #include "infoplugins/echonestplugin.h"
#include "infoplugins/musixmatchplugin.h" #include "infoplugins/musixmatchplugin.h"
#include "infoplugins/lastfmplugin.h" #include "infoplugins/lastfmplugin.h"
#include "infoplugins/adiumplugin.h"
#include "lastfm/NetworkAccessManager" #include "lastfm/NetworkAccessManager"
@@ -61,6 +62,8 @@ void InfoSystemWorker::init()
m_plugins.append( mmptr ); m_plugins.append( mmptr );
InfoPluginPtr lfmptr( new LastFmPlugin( this ) ); InfoPluginPtr lfmptr( new LastFmPlugin( this ) );
m_plugins.append( lfmptr ); m_plugins.append( lfmptr );
InfoPluginPtr admptr( new AdiumPlugin( this ) );
m_plugins.append( admptr );
InfoSystemCache *cache = InfoSystem::instance()->getCache(); InfoSystemCache *cache = InfoSystem::instance()->getCache();