mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 23:57:34 +02:00
Push album covers through MPRIS.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QImage>
|
||||||
#include <QtDBus/QtDBus>
|
#include <QtDBus/QtDBus>
|
||||||
|
|
||||||
#include "audio/audioengine.h"
|
#include "audio/audioengine.h"
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
#include "tomahawksettings.h"
|
#include "tomahawksettings.h"
|
||||||
#include "globalactionmanager.h"
|
#include "globalactionmanager.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
#include "utils/tomahawkutils.h"
|
||||||
|
|
||||||
#include "mprisplugin.h"
|
#include "mprisplugin.h"
|
||||||
#include "mprispluginrootadaptor.h"
|
#include "mprispluginrootadaptor.h"
|
||||||
@@ -34,6 +36,8 @@
|
|||||||
|
|
||||||
using namespace Tomahawk::InfoSystem;
|
using namespace Tomahawk::InfoSystem;
|
||||||
|
|
||||||
|
static QString s_mpInfoIdentifier = QString( "MPRISPLUGIN" );
|
||||||
|
|
||||||
MprisPlugin::MprisPlugin()
|
MprisPlugin::MprisPlugin()
|
||||||
: InfoPlugin()
|
: InfoPlugin()
|
||||||
{
|
{
|
||||||
@@ -62,12 +66,30 @@ MprisPlugin::MprisPlugin()
|
|||||||
connect( playlist->object(), SIGNAL( trackCountChanged( unsigned int ) ),
|
connect( playlist->object(), SIGNAL( trackCountChanged( unsigned int ) ),
|
||||||
SLOT( onTrackCountChanged( unsigned int ) ) );
|
SLOT( onTrackCountChanged( unsigned int ) ) );
|
||||||
|
|
||||||
|
// We store the currently playing track's cover in a temporary file
|
||||||
|
// for the mpris:artUrl property.
|
||||||
|
m_coverTempFile = new QTemporaryFile( "tomahawk_curtrack_cover.png" );
|
||||||
|
if( !m_coverTempFile->open() )
|
||||||
|
{
|
||||||
|
qDebug() << "WARNING: could not write temporary file for cover art!";
|
||||||
|
}
|
||||||
|
m_coverTempFile->close();
|
||||||
|
|
||||||
|
// Connect to the InfoSystem (we need to get album covers via getInfo)
|
||||||
|
|
||||||
|
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
||||||
|
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||||
|
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
|
||||||
|
|
||||||
|
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MprisPlugin::~MprisPlugin()
|
MprisPlugin::~MprisPlugin()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
delete m_coverTempFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// org.mpris.MediaPlayer2
|
// org.mpris.MediaPlayer2
|
||||||
@@ -225,9 +247,11 @@ MprisPlugin::metadata() const
|
|||||||
{
|
{
|
||||||
metadataMap.insert( "mpris:trackid", QString( "/track/" ) + track->id().replace( "-", "" ) );
|
metadataMap.insert( "mpris:trackid", QString( "/track/" ) + track->id().replace( "-", "" ) );
|
||||||
metadataMap.insert( "mpris:length", track->duration() );
|
metadataMap.insert( "mpris:length", track->duration() );
|
||||||
|
metadataMap.insert( "mpris:artUrl", QFileInfo( *m_coverTempFile ).absoluteFilePath() );
|
||||||
metadataMap.insert( "xesam:album", track->album()->name() );
|
metadataMap.insert( "xesam:album", track->album()->name() );
|
||||||
metadataMap.insert( "xesam:artist", track->artist()->name() );
|
metadataMap.insert( "xesam:artist", track->artist()->name() );
|
||||||
metadataMap.insert( "xesam:title", track->track() );
|
metadataMap.insert( "xesam:title", track->track() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadataMap;
|
return metadataMap;
|
||||||
@@ -436,11 +460,25 @@ MprisPlugin::audioStarted( const QVariant &input )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
InfoCriteriaHash hash = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
|
InfoCriteriaHash hash = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
|
||||||
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) )
|
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_playbackStatus = "Playing";
|
m_playbackStatus = "Playing";
|
||||||
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata");
|
//notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata");
|
||||||
|
|
||||||
|
// Need to fetch the album cover
|
||||||
|
|
||||||
|
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
|
||||||
|
trackInfo["artist"] = hash["artist"];
|
||||||
|
trackInfo["album"] = hash["album"];
|
||||||
|
|
||||||
|
Tomahawk::InfoSystem::InfoRequestData requestData;
|
||||||
|
requestData.caller = s_mpInfoIdentifier;
|
||||||
|
requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
|
||||||
|
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo );
|
||||||
|
requestData.customData = QVariantMap();
|
||||||
|
|
||||||
|
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||||
|
|
||||||
//hash["artist"];
|
//hash["artist"];
|
||||||
//hash["title"];
|
//hash["title"];
|
||||||
@@ -512,6 +550,57 @@ MprisPlugin::onTrackCountChanged( unsigned int tracks )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MprisPlugin::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
||||||
|
{
|
||||||
|
if ( requestData.caller != s_mpInfoIdentifier || requestData.type != Tomahawk::InfoSystem::InfoAlbumCoverArt )
|
||||||
|
{
|
||||||
|
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !output.canConvert< QVariantMap >() )
|
||||||
|
{
|
||||||
|
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
|
||||||
|
tDebug( LOGINFO ) << "Cannot convert fetched art from a QByteArray";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap returnedData = output.value< QVariantMap >();
|
||||||
|
const QByteArray ba = returnedData["imgbytes"].toByteArray();
|
||||||
|
if ( ba.length() )
|
||||||
|
{
|
||||||
|
QImage image;
|
||||||
|
image.loadFromData( ba );
|
||||||
|
if( image.save( QFileInfo( *m_coverTempFile ).absoluteFilePath(), "PNG" ) )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << "Image saving successful, notifying";
|
||||||
|
qDebug() << "Saving to: " << QFileInfo( *m_coverTempFile ).absoluteFilePath();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qDebug() << Q_FUNC_INFO << " failed to save image!";
|
||||||
|
|
||||||
|
/*
|
||||||
|
if( m_coverTempFile->open() )
|
||||||
|
{
|
||||||
|
QTextStream out( m_coverTempFile );
|
||||||
|
out << ba;
|
||||||
|
m_coverTempFile->close();
|
||||||
|
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MprisPlugin::infoSystemFinished( QString target )
|
||||||
|
{
|
||||||
|
Q_UNUSED( target );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MprisPlugin::notifyPropertyChanged( const QString& interface,
|
MprisPlugin::notifyPropertyChanged( const QString& interface,
|
||||||
const QString& propertyName )
|
const QString& propertyName )
|
||||||
|
@@ -150,6 +150,9 @@ private slots:
|
|||||||
void onPlaylistChanged( Tomahawk::PlaylistInterface* playlist);
|
void onPlaylistChanged( Tomahawk::PlaylistInterface* playlist);
|
||||||
void onTrackCountChanged( unsigned int tracks );
|
void onTrackCountChanged( unsigned int tracks );
|
||||||
|
|
||||||
|
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||||
|
void infoSystemFinished( QString target );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Get Info
|
// Get Info
|
||||||
|
|
||||||
@@ -163,6 +166,7 @@ private:
|
|||||||
// DBus
|
// DBus
|
||||||
void notifyPropertyChanged( const QString& interface, const QString& propertyName );
|
void notifyPropertyChanged( const QString& interface, const QString& propertyName );
|
||||||
QString m_playbackStatus;
|
QString m_playbackStatus;
|
||||||
|
QTemporaryFile *m_coverTempFile;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user