From 3af985b798b5460b4a48caa1af44ab3d3c34e914 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 22 Apr 2013 11:27:32 +0200 Subject: [PATCH] * Only keep one temporary cover art image. --- src/libtomahawk/audio/AudioEngine.cpp | 15 +++++++-------- src/libtomahawk/audio/AudioEngine.h | 3 +++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libtomahawk/audio/AudioEngine.cpp b/src/libtomahawk/audio/AudioEngine.cpp index fd6a0b447..5814b0a27 100644 --- a/src/libtomahawk/audio/AudioEngine.cpp +++ b/src/libtomahawk/audio/AudioEngine.cpp @@ -45,7 +45,6 @@ #include #include #include -#include using namespace Tomahawk; @@ -72,6 +71,7 @@ AudioEngine::AudioEngine() , m_expectStop( false ) , m_waitingOnNewTrack( false ) , m_state( Stopped ) + , m_coverTempFile( 0 ) { s_instance = this; tDebug() << "Init AudioEngine"; @@ -395,24 +395,23 @@ AudioEngine::onNowPlayingInfoReady( const Tomahawk::InfoSystem::InfoType type ) { playInfo["cover"] = cover; - QTemporaryFile* coverTempFile = new QTemporaryFile( QDir::toNativeSeparators( QDir::tempPath() + "/" + m_currentTrack->artist()->name() + "_" + m_currentTrack->album()->name() + "_tomahawk_cover.png" ) ); - if ( !coverTempFile->open() ) + delete m_coverTempFile; + m_coverTempFile = new QTemporaryFile( QDir::toNativeSeparators( QDir::tempPath() + "/" + m_currentTrack->artist()->name() + "_" + m_currentTrack->album()->name() + "_tomahawk_cover.png" ) ); + if ( !m_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" ) ) + if ( cover.save( m_coverTempFile, "PNG" ) ) { - tDebug() << Q_FUNC_INFO << "Saving cover image to:" << QFileInfo( *coverTempFile ).absoluteFilePath(); - playInfo["coveruri"] = QFileInfo( *coverTempFile ).absoluteFilePath(); + tDebug() << Q_FUNC_INFO << "Saving cover image to:" << QFileInfo( *m_coverTempFile ).absoluteFilePath(); + playInfo["coveruri"] = QFileInfo( *m_coverTempFile ).absoluteFilePath(); } else tDebug() << Q_FUNC_INFO << "Failed to save cover image!"; } - delete coverTempFile; } else tDebug() << Q_FUNC_INFO << "Cover from query is null!"; diff --git a/src/libtomahawk/audio/AudioEngine.h b/src/libtomahawk/audio/AudioEngine.h index 99d22c0a6..444fef465 100644 --- a/src/libtomahawk/audio/AudioEngine.h +++ b/src/libtomahawk/audio/AudioEngine.h @@ -35,6 +35,7 @@ #include #include #include +#include class DLLEXPORT AudioEngine : public QObject @@ -178,6 +179,8 @@ private: uint_fast8_t m_underrunCount; bool m_underrunNotified; + QTemporaryFile* m_coverTempFile; + static AudioEngine* s_instance; };