1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-09-01 18:04:05 +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 )
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 )

View File

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

View File

@@ -22,6 +22,7 @@
#include "infosystem/infosystem.h"
#include <QObject>
#include <QVariant>
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
};

View File

@@ -25,6 +25,7 @@
#include "infoplugins/echonestplugin.h"
#include "infoplugins/musixmatchplugin.h"
#include "infoplugins/lastfmplugin.h"
#include "infoplugins/adiumplugin.h"
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,
InfoSubmitScrobble = 47,
InfoNoInfo = 48
InfoNowPlaying = 48,
InfoNoInfo = 49
};
typedef QMap< InfoType, QVariant > InfoMap;

View File

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