1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-22 05:33:32 +02:00

Modify pushInfo interface to allow flags. These flags can be coded to

add extra common information for all consuming plugins. So far, a
shorturl flag has been added, making a short url available to all
plugins. I wasn't able to check this on OSX, so it might need a small
amount of touching up.
This commit is contained in:
Jeff Mitchell
2012-04-04 21:37:34 -04:00
parent 5fc54a7e4c
commit 8ba61f5496
27 changed files with 247 additions and 129 deletions

View File

@@ -127,13 +127,14 @@ LastFmPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
void void
LastFmPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input ) LastFmPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
Q_UNUSED( caller ) Q_UNUSED( caller )
Q_UNUSED( pushFlags )
switch ( type ) switch ( type )
{ {
case InfoSubmitNowPlaying: case InfoSubmitNowPlaying:
nowPlaying( input ); nowPlaying( pushInfoPair.second );
break; break;
case InfoSubmitScrobble: case InfoSubmitScrobble:
@@ -142,7 +143,7 @@ LastFmPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoTy
case InfoLove: case InfoLove:
case InfoUnLove: case InfoUnLove:
sendLoveSong( type, input ); sendLoveSong( type, pushInfoPair.second );
break; break;
default: default:

View File

@@ -62,7 +62,7 @@ protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data ); virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags );
private: private:
void fetchCoverArt( Tomahawk::InfoSystem::InfoRequestData requestData ); void fetchCoverArt( Tomahawk::InfoSystem::InfoRequestData requestData );

View File

@@ -57,8 +57,11 @@ Tomahawk::InfoSystem::XmppInfoPlugin::~XmppInfoPlugin()
void void
Tomahawk::InfoSystem::XmppInfoPlugin::pushInfo(QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input) Tomahawk::InfoSystem::XmppInfoPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
Q_UNUSED( caller )
Q_UNUSED( pushFlags )
tDebug() << Q_FUNC_INFO << m_sipPlugin->m_client->jid().full(); tDebug() << Q_FUNC_INFO << m_sipPlugin->m_client->jid().full();
if( m_sipPlugin->m_account->configuration().value("publishtracks").toBool() == false ) if( m_sipPlugin->m_account->configuration().value("publishtracks").toBool() == false )
@@ -72,8 +75,7 @@ Tomahawk::InfoSystem::XmppInfoPlugin::pushInfo(QString caller, Tomahawk::InfoSys
case InfoNowPlaying: case InfoNowPlaying:
case InfoNowResumed: case InfoNowResumed:
m_pauseTimer.stop(); m_pauseTimer.stop();
if ( input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) audioStarted( pushInfoPair );
audioStarted( input.value< Tomahawk::InfoSystem::InfoStringHash >() );
break; break;
case InfoNowPaused: case InfoNowPaused:
m_pauseTimer.start( PAUSE_TIMEOUT * 1000 ); m_pauseTimer.start( PAUSE_TIMEOUT * 1000 );
@@ -91,18 +93,29 @@ Tomahawk::InfoSystem::XmppInfoPlugin::pushInfo(QString caller, Tomahawk::InfoSys
void void
Tomahawk::InfoSystem::XmppInfoPlugin::audioStarted(const Tomahawk::InfoSystem::InfoStringHash& info) Tomahawk::InfoSystem::XmppInfoPlugin::audioStarted( const Tomahawk::InfoSystem::PushInfoPair &pushInfoPair )
{ {
if ( !pushInfoPair.second.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
{
tDebug() << Q_FUNC_INFO << "did not find an infostringhash";
return;
}
Tomahawk::InfoSystem::InfoStringHash info = pushInfoPair.second.value< Tomahawk::InfoSystem::InfoStringHash >();
tDebug() << Q_FUNC_INFO << m_sipPlugin->m_client->jid().full() << info; tDebug() << Q_FUNC_INFO << m_sipPlugin->m_client->jid().full() << info;
Jreen::Tune::Ptr tune( new Jreen::Tune() ); Jreen::Tune::Ptr tune( new Jreen::Tune() );
tune->setTitle( info.value( "title" ) ); tune->setTitle( info.value( "title" ) );
tune->setArtist( info.value( "artist" ) ); tune->setArtist( info.value( "artist" ) );
tune->setLength( info.value("duration").toInt() ); tune->setLength( info.value("duration").toInt() );
tune->setTrack( info.value("albumpos") ); tune->setTrack( info.value("albumpos") );
tune->setUri( GlobalActionManager::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) ) ); if ( pushInfoPair.first.contains( "shorturl" ) )
tune->setUri( pushInfoPair.first[ "shorturl" ].toUrl() );
else
tune->setUri( GlobalActionManager::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) ) );
tDebug() << Q_FUNC_INFO << "Setting URI of " << tune->uri().toString();
//TODO: provide a rating once available in Tomahawk //TODO: provide a rating once available in Tomahawk
tune->setRating( 10 ); tune->setRating( 10 );

View File

@@ -47,11 +47,11 @@ namespace Tomahawk {
void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
protected slots: protected slots:
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ); void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags );
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
private slots: private slots:
void audioStarted( const Tomahawk::InfoSystem::InfoStringHash& info ); void audioStarted( const Tomahawk::InfoSystem::PushInfoPair& pushInfoPair );
void audioStopped(); void audioStopped();
void audioPaused(); void audioPaused();

View File

@@ -148,7 +148,8 @@ AudioEngine::play()
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowResumed, s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowResumed,
QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ) ); QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ),
Tomahawk::InfoSystem::PushNoFlag );
} }
} }
else else
@@ -164,7 +165,7 @@ AudioEngine::pause()
m_mediaObject->pause(); m_mediaObject->pause();
emit paused(); emit paused();
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowPaused, QVariant() ); Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowPaused, QVariant(), Tomahawk::InfoSystem::PushNoFlag );
} }
@@ -199,7 +200,7 @@ AudioEngine::stop()
map[ Tomahawk::InfoSystem::InfoNotifyUser ] = QVariant::fromValue< QVariantMap >( stopInfo ); map[ Tomahawk::InfoSystem::InfoNotifyUser ] = QVariant::fromValue< QVariantMap >( stopInfo );
} }
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( s_aeInfoIdentifier, map ); Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( s_aeInfoIdentifier, map, Tomahawk::InfoSystem::PushNoFlag );
} }
@@ -332,7 +333,8 @@ AudioEngine::sendWaitingNotificationSlot() const
retryInfo["message"] = QString( "The current track could not be resolved. Tomahawk will pick back up with the next resolvable track from this source." ); retryInfo["message"] = QString( "The current track could not be resolved. Tomahawk will pick back up with the next resolvable track from this source." );
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNotifyUser, s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNotifyUser,
QVariant::fromValue< QVariantMap >( retryInfo ) ); QVariant::fromValue< QVariantMap >( retryInfo ),
Tomahawk::InfoSystem::PushNoFlag );
} }
@@ -354,6 +356,7 @@ AudioEngine::sendNowPlayingNotification()
void void
AudioEngine::onNowPlayingInfoReady() AudioEngine::onNowPlayingInfoReady()
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
if ( m_currentTrack.isNull() || if ( m_currentTrack.isNull() ||
m_currentTrack->track().isNull() || m_currentTrack->track().isNull() ||
m_currentTrack->artist().isNull() ) m_currentTrack->artist().isNull() )
@@ -379,7 +382,8 @@ AudioEngine::onNowPlayingInfoReady()
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNotifyUser, s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNotifyUser,
QVariant::fromValue< QVariantMap >( playInfo ) ); QVariant::fromValue< QVariantMap >( playInfo ),
Tomahawk::InfoSystem::PushNoFlag );
} }
@@ -474,7 +478,8 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
s_aeInfoIdentifier, s_aeInfoIdentifier,
Tomahawk::InfoSystem::InfoNowPlaying, Tomahawk::InfoSystem::InfoNowPlaying,
QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ) ); QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ),
Tomahawk::InfoSystem::PushShortUrlFlag );
} }
} }
} }

View File

@@ -123,12 +123,12 @@ GlobalActionManager::openLink( const QString& title, const QString& artist, cons
void void
GlobalActionManager::shortenLink( const QUrl& url ) GlobalActionManager::shortenLink( const QUrl& url, const QVariantMap &callbackMap )
{ {
if ( QThread::currentThread() != thread() ) if ( QThread::currentThread() != thread() )
{ {
qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO; qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO;
QMetaObject::invokeMethod( this, "shortenLink", Qt::QueuedConnection, Q_ARG( QUrl, url ) ); QMetaObject::invokeMethod( this, "shortenLink", Qt::QueuedConnection, Q_ARG( QUrl, url ), Q_ARG( QVariantMap, callbackMap ) );
return; return;
} }
@@ -136,6 +136,8 @@ GlobalActionManager::shortenLink( const QUrl& url )
request.setUrl( url ); request.setUrl( url );
QNetworkReply *reply = TomahawkUtils::nam()->get( request ); QNetworkReply *reply = TomahawkUtils::nam()->get( request );
if ( !callbackMap.empty() )
reply->setProperty( "callbackMap", callbackMap );
connect( reply, SIGNAL( finished() ), SLOT( shortenLinkRequestFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( shortenLinkRequestFinished() ) );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) ); connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) );
} }
@@ -894,10 +896,14 @@ GlobalActionManager::shortenLinkRequestFinished()
// NOTE: this should never happen // NOTE: this should never happen
if( !reply ) if( !reply )
{ {
emit shortLinkReady( QUrl( "" ), QUrl( "" ) ); emit shortLinkReady( QUrl( "" ), QUrl( "" ), QVariantMap() );
return; return;
} }
QVariantMap callbackMap;
if ( reply->property( "callbackMap" ).canConvert< QVariantMap >() && !reply->property( "callbackMap" ).toMap().isEmpty() )
callbackMap = reply->property( "callbackMap" ).toMap();
// Check for the redirect attribute, as this should be the shortened link // Check for the redirect attribute, as this should be the shortened link
QVariant urlVariant = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ); QVariant urlVariant = reply->attribute( QNetworkRequest::RedirectionTargetAttribute );
@@ -926,9 +932,9 @@ GlobalActionManager::shortenLinkRequestFinished()
else else
{ {
if ( !error ) if ( !error )
emit shortLinkReady( longUrl, shortUrl ); emit shortLinkReady( longUrl, shortUrl, callbackMap );
else else
emit shortLinkReady( longUrl, longUrl ); emit shortLinkReady( longUrl, longUrl, callbackMap );
} }
reply->deleteLater(); reply->deleteLater();
@@ -946,12 +952,15 @@ GlobalActionManager::shortenLinkRequestError( QNetworkReply::NetworkError error
// NOTE: this should never happen // NOTE: this should never happen
if( !reply ) if( !reply )
{ {
emit shortLinkReady( QUrl( "" ), QUrl( "" ) ); emit shortLinkReady( QUrl( "" ), QUrl( "" ), QVariantMap() );
return; return;
} }
QVariantMap callbackMap;
if ( reply->property( "callbackMap" ).canConvert< QVariantMap >() && !reply->property( "callbackMap" ).toMap().isEmpty() )
callbackMap = reply->property( "callbackMap" ).toMap();
reply->deleteLater(); reply->deleteLater();
emit shortLinkReady( QUrl( "" ), QUrl( "" ) ); emit shortLinkReady( QUrl( "" ), QUrl( "" ), callbackMap );
} }

View File

@@ -56,7 +56,7 @@ public:
void savePlaylistToFile( const Tomahawk::playlist_ptr& playlist, const QString& filename ); void savePlaylistToFile( const Tomahawk::playlist_ptr& playlist, const QString& filename );
public slots: public slots:
void shortenLink( const QUrl& url ); void shortenLink( const QUrl& url, const QVariantMap &callbackMap = QVariantMap() );
bool parseTomahawkLink( const QString& link ); bool parseTomahawkLink( const QString& link );
void waitingForResolved( bool ); void waitingForResolved( bool );
@@ -67,7 +67,7 @@ public slots:
void handlePlayTrack( const Tomahawk::query_ptr& qry ); void handlePlayTrack( const Tomahawk::query_ptr& qry );
signals: signals:
void shortLinkReady( QUrl longUrl, QUrl shortUrl ) const; void shortLinkReady( QUrl longUrl, QUrl shortUrl, QVariantMap callbackMap ) const;
private slots: private slots:
void shortenLinkRequestFinished(); void shortenLinkRequestFinished();

View File

@@ -42,8 +42,13 @@ public:
protected: protected:
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant ) virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{} {
Q_UNUSED( caller )
Q_UNUSED( type)
Q_UNUSED( pushInfoPair )
Q_UNUSED( pushFlags )
}
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );

View File

@@ -60,11 +60,12 @@ protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data ) virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
Q_UNUSED( caller ) Q_UNUSED( caller )
Q_UNUSED( type ) Q_UNUSED( type)
Q_UNUSED( data ) Q_UNUSED( pushInfoPair )
Q_UNUSED( pushFlags )
} }
private: private:

View File

@@ -49,11 +49,12 @@ public:
protected slots: protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant data ) virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
Q_UNUSED( caller ); Q_UNUSED( caller )
Q_UNUSED( type ); Q_UNUSED( type)
Q_UNUSED( data ); Q_UNUSED( pushInfoPair )
Q_UNUSED( pushFlags )
} }
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData )

View File

@@ -58,11 +58,12 @@ public slots:
protected slots: protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input ) virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
Q_UNUSED( caller ) Q_UNUSED( caller )
Q_UNUSED( type) Q_UNUSED( type)
Q_UNUSED( input ) Q_UNUSED( pushInfoPair )
Q_UNUSED( pushFlags )
} }

View File

@@ -43,11 +43,12 @@ protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( InfoStringHash criteria, InfoRequestData requestData ); virtual void notInCacheSlot( InfoStringHash criteria, InfoRequestData requestData );
virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data ) virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
Q_UNUSED( caller ); Q_UNUSED( caller )
Q_UNUSED( type ); Q_UNUSED( type)
Q_UNUSED( data ); Q_UNUSED( pushInfoPair )
Q_UNUSED( pushFlags )
} }

View File

@@ -46,11 +46,12 @@ public slots:
protected slots: protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data ) virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
Q_UNUSED( caller ); Q_UNUSED( caller )
Q_UNUSED( type ); Q_UNUSED( type)
Q_UNUSED( data ); Q_UNUSED( pushInfoPair )
Q_UNUSED( pushFlags )
} }
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData )

View File

@@ -58,11 +58,12 @@ public slots:
protected slots: protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input ) virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
Q_UNUSED( caller ) Q_UNUSED( caller )
Q_UNUSED( type) Q_UNUSED( type)
Q_UNUSED( input ) Q_UNUSED( pushInfoPair )
Q_UNUSED( pushFlags )
} }
private: private:

View File

@@ -74,9 +74,6 @@ AdiumPlugin::AdiumPlugin()
m_pauseTimer->setSingleShot( true ); m_pauseTimer->setSingleShot( true );
connect( m_pauseTimer, SIGNAL( timeout() ), connect( m_pauseTimer, SIGNAL( timeout() ),
this, SLOT( clearStatus() ) ); this, SLOT( clearStatus() ) );
connect( GlobalActionManager::instance(), SIGNAL( shortLinkReady( QUrl, QUrl ) ),
SLOT( shortLinkReady( QUrl, QUrl ) ) );
} }
@@ -87,33 +84,6 @@ AdiumPlugin::~AdiumPlugin()
setStatus( "" ); setStatus( "" );
} }
void
AdiumPlugin::shortLinkReady( QUrl longUrl, QUrl shortUrl )
{
// The URL we received is either from a previous track, or not requested by us
if( longUrl != m_currentLongUrl )
return;
// Build the core of the now-playing string
QString nowPlaying = "";
nowPlaying.append( m_currentArtist );
nowPlaying.append(" - ");
nowPlaying.append( m_currentTitle );
nowPlaying.replace( "\"", "\\\"" ); // Escape quotes, or Applescript gets confused
// We failed to get the short URL, just update the status with the metadata
if( ( longUrl.toString() == "" ) )
{
setStatus( nowPlaying );
return;
}
// Add the short URL
nowPlaying.append( " " );
nowPlaying.append( shortUrl.toEncoded() );
setStatus( nowPlaying );
}
void void
AdiumPlugin::clearStatus() AdiumPlugin::clearStatus()
@@ -131,7 +101,7 @@ AdiumPlugin::settingsChanged()
void void
AdiumPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ) AdiumPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
@@ -141,13 +111,13 @@ AdiumPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVar
switch ( type ) switch ( type )
{ {
case InfoNowPlaying: case InfoNowPlaying:
audioStarted( input ); audioStarted( pushInfoPair );
break; break;
case InfoNowPaused: case InfoNowPaused:
audioPaused(); audioPaused();
return; return;
case InfoNowResumed: case InfoNowResumed:
audioResumed( input ); audioResumed( pushInfoPair );
break; break;
case InfoNowStopped: case InfoNowStopped:
audioStopped(); audioStopped();
@@ -164,14 +134,15 @@ AdiumPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVar
/** Audio state slots */ /** Audio state slots */
void void
AdiumPlugin::audioStarted( const QVariant &input ) AdiumPlugin::audioStarted( const Tomahawk::InfoSystem::PushInfoPair pushInfoPair )
{ {
qDebug() << Q_FUNC_INFO; if ( !pushInfoPair.second.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
if ( !input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
return; return;
InfoStringHash hash = input.value< Tomahawk::InfoSystem::InfoStringHash >(); Tomahawk::InfoSystem::InfoStringHash hash = pushInfoPair.second.value< Tomahawk::InfoSystem::InfoStringHash >();
qDebug() << Q_FUNC_INFO;
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) ) if ( !hash.contains( "title" ) || !hash.contains( "artist" ) )
return; return;
@@ -179,24 +150,29 @@ AdiumPlugin::audioStarted( const QVariant &input )
m_currentArtist = hash["artist"]; m_currentArtist = hash["artist"];
// Request a short URL // Request a short URL
m_currentLongUrl = openLinkFromHash( hash ); m_currentLongUrl = GlobalActionManager::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) );
GlobalActionManager::instance()->shortenLink( m_currentLongUrl );
}
QUrl QUrl shortUrl = m_currentLongUrl;
AdiumPlugin::openLinkFromHash( const Tomahawk::InfoSystem::InfoStringHash& hash ) const if ( pushInfoPair.first.contains( "shortUrl" ) )
{ shortUrl = pushInfoPair.first[ "shortUrl" ].toUrl();
QString title, artist, album;
QString nowPlaying = "";
nowPlaying.append( m_currentArtist );
nowPlaying.append(" - ");
nowPlaying.append( m_currentTitle );
nowPlaying.replace( "\"", "\\\"" ); // Escape quotes, or Applescript gets confused
if( !hash.isEmpty() && hash.contains( "title" ) && hash.contains( "artist" ) ) // We failed to get the short URL, just update the status with the metadata
if( ( m_currentLongUrl.toString() == "" ) )
{ {
title = hash["title"]; setStatus( nowPlaying );
artist = hash["artist"]; return;
if( hash.contains( "album" ) )
album = hash["album"];
} }
return GlobalActionManager::instance()->openLink( title, artist, album ); // Add the short URL
nowPlaying.append( " " );
nowPlaying.append( shortUrl.toEncoded() );
setStatus( nowPlaying );
} }
void void
@@ -220,9 +196,9 @@ AdiumPlugin::audioPaused()
} }
void void
AdiumPlugin::audioResumed( const QVariant &input ) AdiumPlugin::audioResumed( const Tomahawk::InfoSystem::PushInfoPair pushInfoPair )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
audioStarted( input ); audioStarted( pushInfoPair );
} }

View File

@@ -47,7 +47,7 @@ protected slots:
Q_UNUSED( requestData ); Q_UNUSED( requestData );
} }
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ); void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags );
public slots: public slots:
virtual void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) virtual void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
@@ -57,19 +57,15 @@ public slots:
} }
private slots: private slots:
void shortLinkReady( QUrl longUrl, QUrl shortUrl );
void clearStatus(); void clearStatus();
void settingsChanged(); void settingsChanged();
private: private:
void audioStarted( const QVariant &input ); void audioStarted( const Tomahawk::InfoSystem::PushInfoPair pushInfoPair );
void audioFinished( const QVariant &input ); void audioFinished( const QVariant &input );
void audioStopped(); void audioStopped();
void audioPaused(); void audioPaused();
void audioResumed( const QVariant &input ); void audioResumed( const Tomahawk::InfoSystem::PushInfoPair pushInfoPair );
QUrl openLinkFromHash( const InfoStringHash& hash ) const;
bool m_active; bool m_active;
QString m_beforeStatus; QString m_beforeStatus;

View File

@@ -63,10 +63,12 @@ FdoNotifyPlugin::~FdoNotifyPlugin()
} }
void void
FdoNotifyPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant pushData ) FdoNotifyPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
Q_UNUSED( caller ); Q_UNUSED( caller );
Q_UNUSED( pushFlags );
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QVariant pushData = pushInfoPair.second;
if ( type != Tomahawk::InfoSystem::InfoNotifyUser || !pushData.canConvert< QVariantMap >() ) if ( type != Tomahawk::InfoSystem::InfoNotifyUser || !pushData.canConvert< QVariantMap >() )
{ {
qDebug() << Q_FUNC_INFO << " not the right type or could not convert the hash"; qDebug() << Q_FUNC_INFO << " not the right type or could not convert the hash";

View File

@@ -42,7 +42,7 @@ protected slots:
Q_UNUSED( requestData ); Q_UNUSED( requestData );
} }
virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant pushData ); virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
{ {

View File

@@ -469,16 +469,17 @@ MprisPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
void void
MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ) MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
Q_UNUSED( caller ); Q_UNUSED( caller );
Q_UNUSED( pushFlags );
bool isPlayingInfo = false; bool isPlayingInfo = false;
switch ( type ) switch ( type )
{ {
case InfoNowPlaying: case InfoNowPlaying:
isPlayingInfo = true; isPlayingInfo = true;
audioStarted( input ); audioStarted( pushInfoPair.second );
break; break;
case InfoNowPaused: case InfoNowPaused:
isPlayingInfo = true; isPlayingInfo = true;
@@ -486,7 +487,7 @@ MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVar
break; break;
case InfoNowResumed: case InfoNowResumed:
isPlayingInfo = true; isPlayingInfo = true;
audioResumed( input ); audioResumed( pushInfoPair.second );
break; break;
case InfoNowStopped: case InfoNowStopped:
isPlayingInfo = true; isPlayingInfo = true;

View File

@@ -141,7 +141,7 @@ public slots:
protected slots: protected slots:
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ); void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags );
private slots: private slots:
void stateChanged( AudioState newState, AudioState oldState ); void stateChanged( AudioState newState, AudioState oldState );

View File

@@ -172,23 +172,24 @@ InfoSystem::getInfo( const QString &caller, const QVariantMap &customData, const
bool bool
InfoSystem::pushInfo( const QString &caller, const InfoType type, const QVariant& input ) InfoSystem::pushInfo( const QString &caller, const InfoType type, const QVariant& input, const PushInfoFlags pushFlags )
{ {
tDebug() << Q_FUNC_INFO; tDebug() << Q_FUNC_INFO << "type is " << type;
if ( !m_inited || !m_infoSystemWorkerThreadController->worker() ) if ( !m_inited || !m_infoSystemWorkerThreadController->worker() )
{ {
init(); init();
return false; return false;
} }
QMetaObject::invokeMethod( m_infoSystemWorkerThreadController->worker(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ) ); PushInfoPair currPair( QVariantMap(), input );
QMetaObject::invokeMethod( m_infoSystemWorkerThreadController->worker(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( Tomahawk::InfoSystem::PushInfoPair, currPair ), Q_ARG( Tomahawk::InfoSystem::PushInfoFlags, pushFlags ) );
return true; return true;
} }
bool bool
InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input ) InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input, const PushInfoFlags pushFlags )
{ {
if ( !m_inited || !m_infoSystemWorkerThreadController->worker() ) if ( !m_inited || !m_infoSystemWorkerThreadController->worker() )
{ {
@@ -197,7 +198,10 @@ InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input )
} }
Q_FOREACH( InfoType type, input.keys() ) Q_FOREACH( InfoType type, input.keys() )
QMetaObject::invokeMethod( m_infoSystemWorkerThreadController->worker(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input[ type ] ) ); {
PushInfoPair currPair( QVariantMap(), input[ type ] );
QMetaObject::invokeMethod( m_infoSystemWorkerThreadController->worker(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( Tomahawk::InfoSystem::PushInfoPair, currPair ), Q_ARG( Tomahawk::InfoSystem::PushInfoFlags, pushFlags ) );
}
return true; return true;
} }

View File

@@ -44,6 +44,11 @@ namespace InfoSystem {
class InfoSystemCache; class InfoSystemCache;
class InfoSystemWorker; class InfoSystemWorker;
enum PushInfoFlags { // must be powers of 2
PushNoFlag = 1,
PushShortUrlFlag = 2
};
enum InfoType { // as items are saved in cache, mark them here to not change them enum InfoType { // as items are saved in cache, mark them here to not change them
InfoNoInfo = 0, //WARNING: *ALWAYS* keep this first! InfoNoInfo = 0, //WARNING: *ALWAYS* keep this first!
InfoTrackID = 1, InfoTrackID = 1,
@@ -162,6 +167,7 @@ struct InfoRequestData {
typedef QMap< InfoType, QVariant > InfoTypeMap; typedef QMap< InfoType, QVariant > InfoTypeMap;
typedef QMap< InfoType, uint > InfoTimeoutMap; typedef QMap< InfoType, uint > InfoTimeoutMap;
typedef QHash< QString, QString > InfoStringHash; typedef QHash< QString, QString > InfoStringHash;
typedef QPair< QVariantMap, QVariant > PushInfoPair;
class DLLEXPORT InfoPlugin : public QObject class DLLEXPORT InfoPlugin : public QObject
{ {
@@ -183,7 +189,7 @@ signals:
protected slots: protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) = 0; virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) = 0;
virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data ) = 0; virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair pushInfoPair, Tomahawk::InfoSystem::PushInfoFlags pushFlags ) = 0;
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) = 0; virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) = 0;
protected: protected:
@@ -240,8 +246,8 @@ public:
bool getInfo( const InfoRequestData &requestData ); bool getInfo( const InfoRequestData &requestData );
//WARNING: if changing timeoutMillis above, also change in below function in .cpp file //WARNING: if changing timeoutMillis above, also change in below function in .cpp file
bool getInfo( const QString &caller, const QVariantMap &customData, const InfoTypeMap &inputMap, const InfoTimeoutMap &timeoutMap = InfoTimeoutMap(), bool allSources = false ); bool getInfo( const QString &caller, const QVariantMap &customData, const InfoTypeMap &inputMap, const InfoTimeoutMap &timeoutMap = InfoTimeoutMap(), bool allSources = false );
bool pushInfo( const QString &caller, const InfoType type, const QVariant &input ); bool pushInfo( const QString &caller, const InfoType type, const QVariant &input, const PushInfoFlags pushFlags );
bool pushInfo( const QString &caller, const InfoTypeMap &input ); bool pushInfo( const QString &caller, const InfoTypeMap &input, const PushInfoFlags pushFlags );
public slots: public slots:
// InfoSystem takes ownership of InfoPlugins // InfoSystem takes ownership of InfoPlugins
@@ -292,6 +298,9 @@ inline uint qHash( Tomahawk::InfoSystem::InfoStringHash hash )
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoRequestData ); Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoRequestData );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoStringHash ); Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoStringHash );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::PushInfoPair );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::PushInfoFlags );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoType );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoSystemCache* ); Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoSystemCache* );
Q_DECLARE_METATYPE( QList< Tomahawk::InfoSystem::InfoStringHash > ); Q_DECLARE_METATYPE( QList< Tomahawk::InfoSystem::InfoStringHash > );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoPlugin* ); Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoPlugin* );

View File

@@ -31,6 +31,7 @@
#include "infoplugins/generic/spotifyPlugin.h" #include "infoplugins/generic/spotifyPlugin.h"
#include "infoplugins/generic/musicbrainzPlugin.h" #include "infoplugins/generic/musicbrainzPlugin.h"
#include "infoplugins/generic/hypemPlugin.h" #include "infoplugins/generic/hypemPlugin.h"
#include "globalactionmanager.h"
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include "utils/logger.h" #include "utils/logger.h"
@@ -78,6 +79,7 @@ void
InfoSystemWorker::init( Tomahawk::InfoSystem::InfoSystemCache* cache ) InfoSystemWorker::init( Tomahawk::InfoSystem::InfoSystemCache* cache )
{ {
tDebug() << Q_FUNC_INFO; tDebug() << Q_FUNC_INFO;
m_shortLinksWaiting = 0;
m_cache = cache; m_cache = cache;
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
addInfoPlugin( new EchoNestPlugin() ); addInfoPlugin( new EchoNestPlugin() );
@@ -216,18 +218,97 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
void void
InfoSystemWorker::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ) InfoSystemWorker::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair input, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{ {
// qDebug() << Q_FUNC_INFO; tDebug() << Q_FUNC_INFO << "type is " << type;
if ( pushFlags != PushNoFlag )
{
if ( pushFlags & PushShortUrlFlag )
{
pushFlags = Tomahawk::InfoSystem::PushInfoFlags( pushFlags & ~PushShortUrlFlag );
QMetaObject::invokeMethod( this, "getShortUrl", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( Tomahawk::InfoSystem::PushInfoPair, input ), Q_ARG( Tomahawk::InfoSystem::PushInfoFlags, pushFlags ) );
return;
}
}
Q_FOREACH( InfoPluginPtr ptr, m_infoPushMap[ type ] ) Q_FOREACH( InfoPluginPtr ptr, m_infoPushMap[ type ] )
{ {
if( ptr ) if( ptr )
QMetaObject::invokeMethod( ptr.data(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input ) ); QMetaObject::invokeMethod( ptr.data(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( Tomahawk::InfoSystem::PushInfoPair, input ), Q_ARG( Tomahawk::InfoSystem::PushInfoFlags, pushFlags ) );
} }
} }
void
InfoSystemWorker::getShortUrl( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair input, Tomahawk::InfoSystem::PushInfoFlags pushFlags )
{
tDebug() << Q_FUNC_INFO << "type is " << type;
if ( !input.second.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
{
QMetaObject::invokeMethod( this, "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( Tomahawk::InfoSystem::PushInfoPair, input ), Q_ARG( Tomahawk::InfoSystem::PushInfoFlags, pushFlags ) );
return;
}
Tomahawk::InfoSystem::InfoStringHash hash = input.second.value< Tomahawk::InfoSystem::InfoStringHash >();
if ( hash.isEmpty() || !hash.contains( "title" ) || !hash.contains( "artist" ) )
{
QMetaObject::invokeMethod( this, "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( Tomahawk::InfoSystem::PushInfoPair, input ), Q_ARG( Tomahawk::InfoSystem::PushInfoFlags, pushFlags ) );
return;
}
QString title, artist, album;
title = hash[ "title" ];
artist = hash[ "artist" ];
if( hash.contains( "album" ) )
album = hash[ "album" ];
QUrl longUrl = GlobalActionManager::instance()->openLink( title, artist, album );
QVariantMap callbackMap;
callbackMap[ "caller" ] = caller;
callbackMap[ "type" ] = QVariant::fromValue< Tomahawk::InfoSystem::InfoType >( type );
callbackMap[ "pushinfopair" ] = QVariant::fromValue< Tomahawk::InfoSystem::PushInfoPair >( input );
callbackMap[ "pushflags" ] = QVariant::fromValue< Tomahawk::InfoSystem::PushInfoFlags >( pushFlags );
GlobalActionManager::instance()->shortenLink( longUrl, callbackMap );
connect( GlobalActionManager::instance(), SIGNAL( shortLinkReady( QUrl, QUrl, QVariantMap ) ), this, SLOT( shortLinkReady( QUrl, QUrl, QVariantMap ) ), Qt::UniqueConnection );
m_shortLinksWaiting++;
}
void
InfoSystemWorker::shortLinkReady( QUrl longUrl, QUrl shortUrl, QVariantMap callbackMap )
{
tDebug() << Q_FUNC_INFO << "long url = " << longUrl << ", shortUrl = " << shortUrl;
m_shortLinksWaiting--;
if ( !m_shortLinksWaiting )
disconnect( GlobalActionManager::instance(), SIGNAL( shortLinkReady( QUrl, QUrl, QVariantMap ) ) );
if ( callbackMap.isEmpty() || !callbackMap.contains( "caller" ) || !callbackMap.contains( "type" ) || !callbackMap.contains( "pushinfopair" ) || !callbackMap.contains( "pushflags" ) )
{
tDebug() << Q_FUNC_INFO << "callback map was empty, cannot continue";
return;
}
QString caller = callbackMap[ "caller" ].toString();
Tomahawk::InfoSystem::InfoType type = callbackMap[ "type" ].value< Tomahawk::InfoSystem::InfoType >();
Tomahawk::InfoSystem::PushInfoPair pushInfoPair = callbackMap[ "pushinfopair" ].value< Tomahawk::InfoSystem::PushInfoPair >();
Tomahawk::InfoSystem::PushInfoFlags pushFlags = callbackMap[ "pushflags" ].value< Tomahawk::InfoSystem::PushInfoFlags >();
if ( !shortUrl.isEmpty() && longUrl != shortUrl )
{
QVariantMap flagProps = pushInfoPair.first;
flagProps[ "shorturl" ] = shortUrl;
pushInfoPair.first = flagProps;
}
tDebug() << Q_FUNC_INFO << "pushInfoPair first is: " << pushInfoPair.first.keys();
QMetaObject::invokeMethod( this, "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( Tomahawk::InfoSystem::PushInfoPair, pushInfoPair ), Q_ARG( Tomahawk::InfoSystem::PushInfoFlags, pushFlags ) );
}
void void
InfoSystemWorker::infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) InfoSystemWorker::infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{ {

View File

@@ -59,11 +59,15 @@ signals:
public slots: public slots:
void init( Tomahawk::InfoSystem::InfoSystemCache* cache ); void init( Tomahawk::InfoSystem::InfoSystemCache* cache );
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair input, Tomahawk::InfoSystem::PushInfoFlags pushFlags );
void infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void addInfoPlugin( Tomahawk::InfoSystem::InfoPlugin* plugin ); void addInfoPlugin( Tomahawk::InfoSystem::InfoPlugin* plugin );
void getShortUrl( QString caller, Tomahawk::InfoSystem::InfoType type, Tomahawk::InfoSystem::PushInfoPair input, Tomahawk::InfoSystem::PushInfoFlags pushFlags );
void shortLinkReady( QUrl longUrl, QUrl shortUrl, QVariantMap callbackMap );
private slots: private slots:
void checkTimeoutsTimerFired(); void checkTimeoutsTimerFired();
@@ -88,6 +92,8 @@ private:
QMap< InfoType, QList< InfoPluginPtr > > m_infoPushMap; QMap< InfoType, QList< InfoPluginPtr > > m_infoPushMap;
QTimer m_checkTimeoutsTimer; QTimer m_checkTimeoutsTimer;
quint64 m_shortLinksWaiting;
}; };
} }

View File

@@ -589,7 +589,8 @@ Query::setLoved( bool loved )
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
id(), Tomahawk::InfoSystem::InfoLove, id(), Tomahawk::InfoSystem::InfoLove,
QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ) ); QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ),
Tomahawk::InfoSystem::PushNoFlag );
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( q, QString( "Love" ), loved ? QString( "true" ) : QString( "false" ) ); DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( q, QString( "Love" ), loved ? QString( "true" ) : QString( "false" ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );

View File

@@ -88,7 +88,8 @@ Scrobbler::trackStarted( const Tomahawk::result_ptr& track )
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
s_scInfoIdentifier, Tomahawk::InfoSystem::InfoSubmitNowPlaying, s_scInfoIdentifier, Tomahawk::InfoSystem::InfoSubmitNowPlaying,
QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ) ); QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo ),
Tomahawk::InfoSystem::PushNoFlag );
// liblastfm forces 0-length tracks to scrobble after 4 minutes, stupid. // liblastfm forces 0-length tracks to scrobble after 4 minutes, stupid.
if ( track->duration() == 0 ) if ( track->duration() == 0 )
@@ -140,7 +141,7 @@ Scrobbler::scrobble()
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
s_scInfoIdentifier, Tomahawk::InfoSystem::InfoSubmitScrobble, s_scInfoIdentifier, Tomahawk::InfoSystem::InfoSubmitScrobble,
QVariant() ); QVariant(), Tomahawk::InfoSystem::PushNoFlag );
} }

View File

@@ -442,6 +442,8 @@ TomahawkApp::registerMetaTypes()
qRegisterMetaType< Tomahawk::InfoSystem::InfoStringHash >( "Tomahawk::InfoSystem::InfoStringHash" ); qRegisterMetaType< Tomahawk::InfoSystem::InfoStringHash >( "Tomahawk::InfoSystem::InfoStringHash" );
qRegisterMetaType< Tomahawk::InfoSystem::InfoType >( "Tomahawk::InfoSystem::InfoType" ); qRegisterMetaType< Tomahawk::InfoSystem::InfoType >( "Tomahawk::InfoSystem::InfoType" );
qRegisterMetaType< Tomahawk::InfoSystem::PushInfoFlags >( "Tomahawk::InfoSystem::PushInfoFlags" );
qRegisterMetaType< Tomahawk::InfoSystem::PushInfoPair >( "Tomahawk::InfoSystem::PushInfoPair" );
qRegisterMetaType< Tomahawk::InfoSystem::InfoRequestData >( "Tomahawk::InfoSystem::InfoRequestData" ); qRegisterMetaType< Tomahawk::InfoSystem::InfoRequestData >( "Tomahawk::InfoSystem::InfoRequestData" );
qRegisterMetaType< Tomahawk::InfoSystem::InfoSystemCache* >( "Tomahawk::InfoSystem::InfoSystemCache*" ); qRegisterMetaType< Tomahawk::InfoSystem::InfoSystemCache* >( "Tomahawk::InfoSystem::InfoSystemCache*" );
qRegisterMetaType< Tomahawk::InfoSystem::InfoPlugin* >( "Tomahawk::InfoSystem::InfoPlugin*" ); qRegisterMetaType< Tomahawk::InfoSystem::InfoPlugin* >( "Tomahawk::InfoSystem::InfoPlugin*" );