From 26a1f9c00c6a5c44c2819e79c0d9d9bb18ad5abc Mon Sep 17 00:00:00 2001 From: vanhofen Date: Fri, 25 May 2018 00:58:24 +0200 Subject: [PATCH] audioplayer: remove all covers when playback is stopped or title is changed Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/1c67a575be74a2bfad044c437b2f23e672c2cdae Author: vanhofen Date: 2018-05-25 (Fri, 25 May 2018) Origin message was: ------------------ - audioplayer: remove all covers when playback is stopped or title is changed ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/gui/audioplayer.cpp | 34 +++++++++++++++++++++++++++++----- src/gui/audioplayer.h | 2 ++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/gui/audioplayer.cpp b/src/gui/audioplayer.cpp index d91becad8..c18f01eb6 100644 --- a/src/gui/audioplayer.cpp +++ b/src/gui/audioplayer.cpp @@ -71,6 +71,7 @@ extern CPictureViewer * g_PicViewer; #include #include #include +#include #include #include @@ -2091,11 +2092,7 @@ void CAudioPlayerGui::stop() if (CAudioPlayer::getInstance()->getState() != CBaseDec::STOP) CAudioPlayer::getInstance()->stop(); - if (m_stationlogo) - { - unlink(m_cover.c_str()); - m_stationlogo = false; - } + cleanupCovers(); if (m_streamripper_active) { @@ -2168,6 +2165,8 @@ void CAudioPlayerGui::play(unsigned int pos) unsigned int old_current = m_current; unsigned int old_selected = m_selected; + cleanupCovers(); + m_current = pos; if (g_settings.audioplayer_follow) m_selected = pos; @@ -2927,3 +2926,28 @@ std::string CAudioPlayerGui::absPath2Rel(const std::string& fromDir, res = res + relFilepath; return res; } + +void CAudioPlayerGui::cleanupCovers() +{ + if (access(COVERDIR, F_OK) == 0) + { + struct dirent **coverlist; + int n = scandir(COVERDIR, &coverlist, 0, alphasort); + if (n > -1) + { + while (n--) + { + const char *coverfile = coverlist[n]->d_name; + if (strcmp(coverfile, ".") == 0 || strcmp(coverfile, "..") == 0) + continue; + printf("[audioplayer] removing cover %s/%s\n", COVERDIR, coverfile); + unlink(((std::string)COVERDIR + "/" + coverfile).c_str()); + free(coverlist[n]); + } + free(coverlist); + } + } + + m_cover.clear(); + m_stationlogo = false; +} diff --git a/src/gui/audioplayer.h b/src/gui/audioplayer.h index f61706e65..e5c6f41c5 100644 --- a/src/gui/audioplayer.h +++ b/src/gui/audioplayer.h @@ -234,6 +234,8 @@ class CAudioPlayerGui : public CMenuTarget */ bool askToOverwriteFile(const std::string& filename); + void cleanupCovers(); + bool openFilebrowser(void); bool openSCbrowser(void); bool clearPlaylist(void);