From 3f48e93a89a01eac79ecca993f1b7e583275521e Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Tue, 28 Jun 2011 13:59:11 -0400 Subject: [PATCH] Show album covers in notifications when playing a track instead of the source image. Need to implement some sort of timeout for getInfo. --- src/libtomahawk/audio/audioengine.cpp | 95 ++++++++++++++++++++++----- src/libtomahawk/audio/audioengine.h | 8 ++- 2 files changed, 87 insertions(+), 16 deletions(-) diff --git a/src/libtomahawk/audio/audioengine.cpp b/src/libtomahawk/audio/audioengine.cpp index dd5a910b4..a9dad2dcf 100644 --- a/src/libtomahawk/audio/audioengine.cpp +++ b/src/libtomahawk/audio/audioengine.cpp @@ -26,7 +26,6 @@ #include "database/database.h" #include "database/databasecommand_logplayback.h" -#include "infosystem/infosystem.h" #include "network/servent.h" #include "album.h" @@ -53,6 +52,7 @@ AudioEngine::AudioEngine() , m_timeElapsed( 0 ) , m_expectStop( false ) , m_waitingOnNewTrack( false ) + , m_infoSystemConnected( false ) { s_instance = this; qDebug() << "Init AudioEngine"; @@ -248,6 +248,79 @@ AudioEngine::sendWaitingNotification() const } +void +AudioEngine::sendNowPlayingNotification() +{ + qDebug() << Q_FUNC_INFO; + + if ( ! m_infoSystemConnected ) + { + connect( Tomahawk::InfoSystem::InfoSystem::instance(), + SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ), + SLOT( infoSystemInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ) ); + + connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); + + m_infoSystemConnected = true; + } + + Tomahawk::InfoSystem::InfoCriteriaHash trackInfo; + trackInfo["artist"] = m_currentTrack->album()->artist()->name(); + trackInfo["album"] = m_currentTrack->album()->name(); + + Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( + s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoAlbumCoverArt, + QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ), Tomahawk::InfoSystem::InfoCustomData() ); +} + + +void +AudioEngine::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData ) +{ + qDebug() << Q_FUNC_INFO; + Q_UNUSED( input ); + Q_UNUSED( customData ); + + if ( caller != s_aeInfoIdentifier || + ( type != Tomahawk::InfoSystem::InfoAlbumCoverArt ) ) + { + qDebug() << Q_FUNC_INFO << " not desgined for us, caller is " << caller; + return; + } + + Tomahawk::InfoSystem::InfoCustomData playInfo; + playInfo["message"] = QString( "Tomahawk is playing \"%1\" by %2 on album %3." ) + .arg( m_currentTrack->track() ) + .arg( m_currentTrack->artist()->name() ) + .arg( m_currentTrack->album()->name() ); + if ( !output.isNull() && output.isValid() ) + { + qDebug() << Q_FUNC_INFO << " output is valid"; + Tomahawk::InfoSystem::InfoCustomData returnedData = output.value< Tomahawk::InfoSystem::InfoCustomData >(); + const QByteArray ba = returnedData["imgbytes"].toByteArray(); + qDebug() << "ba.length = " << ba.length(); + if ( ba.length() ) + { + QPixmap pm; + pm.loadFromData( ba ); + playInfo["image"] = QVariant( pm.toImage() ); + } + } + + Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( + s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNotifyUser, + QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomData >( playInfo ) ); +} + + +void +AudioEngine::infoSystemFinished( QString caller ) +{ + Q_UNUSED( caller ); + qDebug() << Q_FUNC_INFO; +} + + void AudioEngine::onTrackAboutToFinish() { @@ -319,26 +392,18 @@ 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::InfoTypeMap map; - Tomahawk::InfoSystem::InfoCriteriaHash trackInfo; trackInfo["title"] = m_currentTrack->track(); trackInfo["artist"] = m_currentTrack->artist()->name(); trackInfo["album"] = m_currentTrack->album()->name(); - map[ Tomahawk::InfoSystem::InfoNowPlaying ] = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ); - + if ( TomahawkSettings::instance()->verboseNotifications() ) - { - Tomahawk::InfoSystem::InfoCustomData playInfo; - playInfo["message"] = QString( "Tomahawk is playing \"%1\" by %2 on album %3." ) - .arg( m_currentTrack->track() ) - .arg( m_currentTrack->artist()->name() ) - .arg( m_currentTrack->album()->name() ); - playInfo["image"] = QVariant( m_currentTrack->collection()->source()->avatar().toImage() ); - map[ Tomahawk::InfoSystem::InfoNotifyUser ] = QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomData >( playInfo ); - } + sendNowPlayingNotification(); - Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( s_aeInfoIdentifier, map ); + Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( + s_aeInfoIdentifier, + Tomahawk::InfoSystem::InfoNowPlaying, + QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ) ); } } diff --git a/src/libtomahawk/audio/audioengine.h b/src/libtomahawk/audio/audioengine.h index dea60d648..bdc8ee705 100644 --- a/src/libtomahawk/audio/audioengine.h +++ b/src/libtomahawk/audio/audioengine.h @@ -25,6 +25,8 @@ #include #include +#include "infosystem/infosystem.h" + #include "result.h" #include "typedefs.h" @@ -85,6 +87,9 @@ public slots: void playlistNextTrackReady(); + void infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData ); + void infoSystemFinished( QString caller ); + signals: void loading( const Tomahawk::result_ptr& track ); void started( const Tomahawk::result_ptr& track ); @@ -118,6 +123,7 @@ private: bool isHttpResult( const QString& ) const; bool isLocalResult( const QString& ) const; void sendWaitingNotification() const; + void sendNowPlayingNotification(); bool m_isPlayingHttp; QSharedPointer m_input; @@ -133,8 +139,8 @@ private: unsigned int m_timeElapsed; bool m_expectStop; - bool m_waitingOnNewTrack; + bool m_infoSystemConnected; static AudioEngine* s_instance; };