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

* Fixed TWK-641: don't write empty album covers in InfoSystem.

This commit is contained in:
Christian Muehlhaeuser
2012-03-02 01:55:28 +01:00
parent 11cf2c78d8
commit c77be81e5b
2 changed files with 123 additions and 112 deletions

View File

@@ -42,8 +42,6 @@ MprisPlugin::MprisPlugin()
: InfoPlugin()
, m_coverTempFile( 0 )
{
qDebug() << Q_FUNC_INFO;
// init
m_playbackStatus = "Stopped";
@@ -68,8 +66,10 @@ MprisPlugin::MprisPlugin()
// When a track is added or removed, CanGoNext updated signal is sent
Tomahawk::playlistinterface_ptr playlist = AudioEngine::instance()->playlist();
if ( !playlist.isNull() )
{
connect( playlist.data(), SIGNAL( trackCountChanged( unsigned int ) ),
SLOT( onTrackCountChanged( unsigned int ) ) );
}
// Connect to AudioEngine's seeked signal
connect( AudioEngine::instance(), SIGNAL( seeked( qint64 ) ),
@@ -81,52 +81,55 @@ MprisPlugin::MprisPlugin()
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( finished( QString ) ),
SLOT( infoSystemFinished( QString ) ) );
}
MprisPlugin::~MprisPlugin()
{
qDebug() << Q_FUNC_INFO;
delete m_coverTempFile;
}
// org.mpris.MediaPlayer2
bool
MprisPlugin::canQuit() const
{
qDebug() << Q_FUNC_INFO;
return true;
}
bool
MprisPlugin::canRaise() const
{
qDebug() << Q_FUNC_INFO;
return false;
}
bool
MprisPlugin::hasTrackList() const
{
qDebug() << Q_FUNC_INFO;
return false;
}
QString
MprisPlugin::identity() const
{
return QString( "Tomahawk" );
}
QString
MprisPlugin::desktopEntry() const
{
return QString( "tomahawk" );
}
QStringList
MprisPlugin::supportedUriSchemes() const
{
@@ -135,23 +138,27 @@ MprisPlugin::supportedUriSchemes() const
return uriSchemes;
}
QStringList
MprisPlugin::supportedMimeTypes() const
{
return QStringList();
}
void
MprisPlugin::Raise()
{
}
void
MprisPlugin::Quit()
{
QApplication::quit();
}
// org.mpris.MediaPlayer2.Player
bool
@@ -160,24 +167,28 @@ MprisPlugin::canControl() const
return true;
}
bool
MprisPlugin::canGoNext() const
{
return AudioEngine::instance()->canGoNext();
}
bool
MprisPlugin::canGoPrevious() const
{
return AudioEngine::instance()->canGoPrevious();
}
bool
MprisPlugin::canPause() const
{
return AudioEngine::instance()->currentTrack();
}
bool
MprisPlugin::canPlay() const
{
@@ -186,6 +197,7 @@ MprisPlugin::canPlay() const
return AudioEngine::instance()->currentTrack() || ( !p.isNull() && p->trackCount() );
}
bool
MprisPlugin::canSeek() const
{
@@ -196,6 +208,7 @@ MprisPlugin::canSeek() const
}
QString
MprisPlugin::loopStatus() const
{
@@ -215,13 +228,14 @@ MprisPlugin::loopStatus() const
return "None";
break;
default:
return QString("None");
return "None";
break;
}
return QString( "None" );
}
void
MprisPlugin::setLoopStatus( const QString& value )
{
@@ -236,12 +250,14 @@ MprisPlugin::setLoopStatus( const QString &value )
p->setRepeatMode( PlaylistInterface::NoRepeat );
}
double
MprisPlugin::maximumRate() const
{
return 1.0;
}
QVariantMap
MprisPlugin::metadata() const
{
@@ -258,7 +274,9 @@ MprisPlugin::metadata() const
// Only return art if tempfile exists, and if its name contains the same "artist_album_tomahawk_cover.png"
if ( m_coverTempFile && m_coverTempFile->exists() &&
m_coverTempFile->fileName().contains( track->artist()->name() + "_" + track->album()->name() + "_tomahawk_cover.png" ) )
{
metadataMap.insert( "mpris:artUrl", QString( QUrl::fromLocalFile( QFileInfo( *m_coverTempFile ).absoluteFilePath() ).toEncoded() ) );
}
else
{
// Need to fetch the album cover
@@ -280,18 +298,21 @@ MprisPlugin::metadata() const
return metadataMap;
}
double
MprisPlugin::minimumRate() const
{
return 1.0;
}
QString
MprisPlugin::playbackStatus() const
{
return m_playbackStatus;
}
qlonglong
MprisPlugin::position() const
{
@@ -299,18 +320,21 @@ MprisPlugin::position() const
return (qlonglong) ( AudioEngine::instance()->currentTime() * 1000 );
}
double
MprisPlugin::rate() const
{
return 1.0;
}
void
MprisPlugin::setRate( double value )
{
Q_UNUSED( value );
}
bool
MprisPlugin::shuffle() const
{
@@ -320,6 +344,7 @@ MprisPlugin::shuffle() const
return p->shuffled();
}
void
MprisPlugin::setShuffle( bool value )
{
@@ -329,24 +354,28 @@ MprisPlugin::setShuffle( bool value )
return p->setShuffled( value );
}
double
MprisPlugin::volume() const
{
return AudioEngine::instance()->volume();
}
void
MprisPlugin::setVolume( double value )
{
AudioEngine::instance()->setVolume( value );
}
void
MprisPlugin::Next()
{
AudioEngine::instance()->next();
}
void
MprisPlugin::OpenUri( const QString& Uri )
{
@@ -356,40 +385,42 @@ MprisPlugin::OpenUri( const QString &Uri )
GlobalActionManager::instance()->openSpotifyLink( Uri );
}
void
MprisPlugin::Pause()
{
AudioEngine::instance()->pause();
}
void
MprisPlugin::Play()
{
AudioEngine::instance()->play();
}
void
MprisPlugin::PlayPause()
{
AudioEngine::instance()->playPause();
}
void
MprisPlugin::Previous()
{
AudioEngine::instance()->previous();
}
void
MprisPlugin::Seek( qlonglong Offset )
{
qDebug() << Q_FUNC_INFO;
if ( !canSeek() )
return;
qlonglong seekTime = position() + Offset;
qDebug() << "seekTime: " << seekTime;
if ( seekTime < 0 )
AudioEngine::instance()->seek( 0 );
else if ( seekTime > AudioEngine::instance()->currentTrackTotalTime()*1000 )
@@ -400,50 +431,46 @@ MprisPlugin::Seek( qlonglong Offset )
}
void
MprisPlugin::SetPosition( const QDBusObjectPath& TrackId, qlonglong Position )
{
qDebug() << Q_FUNC_INFO;
if ( !canSeek() )
return;
qDebug() << "path: " << TrackId.path();
qDebug() << "position: " << Position;
if ( TrackId.path() != QString( "/track/" ) + AudioEngine::instance()->currentTrack()->id().replace( "-", "" ) )
return;
if ( ( Position < 0) || ( Position > AudioEngine::instance()->currentTrackTotalTime()*1000 ) )
return;
qDebug() << "seeking to: " << Position/1000 << "ms";
AudioEngine::instance()->seek( (qint64) (Position / 1000 ) );
}
void
MprisPlugin::Stop()
{
AudioEngine::instance()->stop();
}
// InfoPlugin Methods
void
MprisPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{
Q_UNUSED( requestData );
qDebug() << Q_FUNC_INFO;
return;
}
void
MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input )
{
Q_UNUSED( caller );
qDebug() << Q_FUNC_INFO;
bool isPlayingInfo = false;
switch ( type )
@@ -471,9 +498,9 @@ MprisPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVar
if ( isPlayingInfo )
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "PlaybackStatus" );
}
void
MprisPlugin::stateChanged( AudioState newState, AudioState oldState )
{
@@ -481,12 +508,11 @@ MprisPlugin::stateChanged( AudioState newState, AudioState oldState )
Q_UNUSED( oldState );
}
/** Audio state slots */
void
MprisPlugin::audioStarted( const QVariant& input )
{
qDebug() << Q_FUNC_INFO;
if ( !input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
return;
@@ -496,41 +522,37 @@ MprisPlugin::audioStarted( const QVariant &input )
m_playbackStatus = "Playing";
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
//hash["artist"];
//hash["title"];
//QString nowPlaying = "";
//qDebug() << "nowPlaying: " << nowPlaying;
}
void
MprisPlugin::audioFinished( const QVariant& input )
{
Q_UNUSED( input );
//qDebug() << Q_FUNC_INFO;
}
void
MprisPlugin::audioStopped()
{
qDebug() << Q_FUNC_INFO;
m_playbackStatus = "Stopped";
}
void
MprisPlugin::audioPaused()
{
qDebug() << Q_FUNC_INFO;
m_playbackStatus = "Paused";
}
void
MprisPlugin::audioResumed( const QVariant& input )
{
qDebug() << Q_FUNC_INFO;
audioStarted( input );
}
void
MprisPlugin::onVolumeChanged( int volume )
{
@@ -538,21 +560,16 @@ MprisPlugin::onVolumeChanged( int volume )
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Volume" );
}
void
MprisPlugin::onPlaylistChanged( Tomahawk::playlistinterface_ptr playlist )
{
qDebug() << Q_FUNC_INFO;
disconnect( this, SLOT( onTrackCountChanged( unsigned int ) ) );
qDebug() << "disconnected";
if( !playlist.isNull() )
qDebug() << "playlist not null";
if ( !playlist.isNull() )
connect( playlist.data(), SIGNAL( trackCountChanged( unsigned int ) ),
SLOT( onTrackCountChanged( unsigned int ) ) );
qDebug() << "connected new playlist";
// Notify relevant changes
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "LoopStatus" );
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Shuffle" );
@@ -560,6 +577,7 @@ MprisPlugin::onPlaylistChanged( Tomahawk::playlistinterface_ptr playlist )
onTrackCountChanged( 0 );
}
void
MprisPlugin::onTrackCountChanged( unsigned int tracks )
{
@@ -569,6 +587,7 @@ MprisPlugin::onTrackCountChanged( unsigned int tracks )
}
void
MprisPlugin::onSeeked( qint64 ms )
{
@@ -576,6 +595,7 @@ MprisPlugin::onTrackCountChanged( unsigned int tracks )
emit Seeked( us );
}
void
MprisPlugin::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{
@@ -613,40 +633,32 @@ MprisPlugin::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData,
// delete the old tempfile and make new one, to avoid caching of filename by mpris clients
if ( m_coverTempFile )
{
delete m_coverTempFile;
m_coverTempFile = new QTemporaryFile( QDir::toNativeSeparators(
QDir::tempPath() + "/" + hash["artist"] + "_" + hash["album"] + "_tomahawk_cover.png" ) );
m_coverTempFile = 0;
}
if ( image.isNull() )
return;
m_coverTempFile = new QTemporaryFile( QDir::toNativeSeparators( QDir::tempPath() + "/" + hash["artist"] + "_" + hash["album"] + "_tomahawk_cover.png" ) );
if ( !m_coverTempFile->open() )
{
qDebug() << "WARNING: could not write temporary file for cover art!";
}
// Finally, save the image to the new temp file
//if( image.save( QFileInfo( *m_coverTempFile ).absoluteFilePath(), "PNG" ) )
if ( image.save( m_coverTempFile, "PNG" ) )
{
qDebug() << Q_FUNC_INFO << "Image saving successful, notifying";
qDebug() << "Saving to: " << QFileInfo( *m_coverTempFile ).absoluteFilePath();
qDebug() << "Saving cover image to:" << QFileInfo( *m_coverTempFile ).absoluteFilePath();
m_coverTempFile->close();
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
}
else
{
qDebug() << Q_FUNC_INFO << " failed to save image!";
tDebug() << Q_FUNC_INFO << "failed to save cover image!";
m_coverTempFile->close();
}
/*
if( m_coverTempFile->open() )
{
QTextStream out( m_coverTempFile );
out << ba;
m_coverTempFile->close();
notifyPropertyChanged( "org.mpris.MediaPlayer2.Player", "Metadata" );
}
*/
}
}
@@ -657,9 +669,9 @@ MprisPlugin::infoSystemFinished( QString target )
Q_UNUSED( target );
}
void
MprisPlugin::notifyPropertyChanged( const QString& interface,
const QString& propertyName )
MprisPlugin::notifyPropertyChanged( const QString& interface, const QString& propertyName )
{
QDBusMessage signal = QDBusMessage::createSignal(
"/org/mpris/MediaPlayer2",

View File

@@ -138,7 +138,6 @@ public slots:
void SetPosition( const QDBusObjectPath& TrackId, qlonglong Position );
void Stop();
protected slots:
void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input );