1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-31 06:02:27 +02:00

Maybe fix cover temp file writing

This commit is contained in:
Jeff Mitchell 2012-04-11 09:55:48 -04:00
parent 7284a53d0f
commit 3ea581c4f8
2 changed files with 21 additions and 18 deletions

View File

@ -329,7 +329,7 @@ AudioEngine::sendNowPlayingNotification( const Tomahawk::InfoSystem::InfoType ty
{
_detail::Closure* closure = NewClosure( m_currentTrack->album().data(), SIGNAL( updated() ), const_cast< AudioEngine* >( this ), SLOT( onNowPlayingInfoReady( const Tomahawk::InfoSystem::InfoType ) ), type );
Q_UNUSED( closure );
m_currentTrack->album()->cover( QSize( 0, 0 ) );
m_currentTrack->album()->cover( QSize( 0, 0 ), true );
}
#endif
}
@ -354,26 +354,29 @@ AudioEngine::onNowPlayingInfoReady( const Tomahawk::InfoSystem::InfoType type )
#ifndef ENABLE_HEADLESS
QImage cover;
cover = m_currentTrack->album()->cover( QSize( 0, 0 ) ).toImage();
playInfo["cover"] = cover;
QTemporaryFile coverTempFile( QDir::toNativeSeparators( QDir::tempPath() + "/" + m_currentTrack->artist()->name() + "_" + m_currentTrack->album()->name() + "_tomahawk_cover.png" ) );
if ( !coverTempFile.open() )
if ( !cover.isNull() )
{
tDebug() << "WARNING: could not write temporary file for cover art!";
}
playInfo["cover"] = cover;
// Finally, save the image to the new temp file
if ( cover.save( &coverTempFile, "PNG" ) )
{
tDebug( LOGVERBOSE ) << "Saving cover image to:" << QFileInfo( coverTempFile ).absoluteFilePath();
coverTempFile.close();
playInfo["coveruri"] = QFileInfo( coverTempFile ).absoluteFilePath();
QTemporaryFile* coverTempFile = new QTemporaryFile( QDir::toNativeSeparators( QDir::tempPath() + "/" + m_currentTrack->artist()->name() + "_" + m_currentTrack->album()->name() + "_tomahawk_cover.png" ) );
if ( !coverTempFile->open() )
tDebug() << Q_FUNC_INFO << "WARNING: could not write temporary file for cover art!";
else
{
// Finally, save the image to the new temp file
coverTempFile->setAutoRemove( false );
if ( cover.save( coverTempFile, "PNG" ) )
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Saving cover image to:" << QFileInfo( *coverTempFile ).absoluteFilePath();
playInfo["coveruri"] = QFileInfo( *coverTempFile ).absoluteFilePath();
}
else
tDebug() << Q_FUNC_INFO << "failed to save cover image!";
}
delete coverTempFile;
}
else
{
tDebug() << Q_FUNC_INFO << "failed to save cover image!";
coverTempFile.close();
}
tDebug() << Q_FUNC_INFO << "Cover from album is null!";
#endif
}

View File

@ -146,7 +146,7 @@ FdoNotifyPlugin::nowPlaying( const QVariant &input )
arguments << QStringList(); //actions
QVariantMap dict;
dict["desktop-entry"] = QString( "tomahawk" );
if ( map.contains( "cover" ) && map[ "cover" ].canConvert< QImage >() )
if ( map.contains( "cover" ) && map[ "cover" ].canConvert< QImage >() && !map[ "cover" ].value< QImage >().isNull() )
dict[ "image_data" ] = ImageConverter::variantForImage( map[ "cover" ].value< QImage >() );
else
dict[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-128x128.png" ) );