From d939b4cf29b021d89c731011bb6239115690aabc Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sun, 27 May 2012 19:10:39 +0100 Subject: [PATCH] Remove playlist moodbars from the cache if they have been removed from the model, and make the disk cache bigger --- src/moodbar/moodbaritemdelegate.cpp | 23 +++++++++++++++++++++++ src/moodbar/moodbaritemdelegate.h | 2 ++ src/moodbar/moodbarloader.cpp | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/moodbar/moodbaritemdelegate.cpp b/src/moodbar/moodbaritemdelegate.cpp index a17bebcd9..b70ac2ef3 100644 --- a/src/moodbar/moodbaritemdelegate.cpp +++ b/src/moodbar/moodbaritemdelegate.cpp @@ -108,12 +108,27 @@ QPixmap MoodbarItemDelegate::PixmapForIndex( return QPixmap(); } +bool MoodbarItemDelegate::RemoveFromCacheIfIndexesInvalid(const QUrl& url, Data* data) { + foreach (const QPersistentModelIndex& index, data->indexes_) { + if (index.isValid()) { + return false; + } + } + + data_.remove(url); + return true; +} + void MoodbarItemDelegate::DataLoaded( const QUrl& url, MoodbarPipeline* pipeline) { Data* data = data_[url]; if (!data) { return; } + if (RemoveFromCacheIfIndexesInvalid(url, data)) { + return; + } + if (!pipeline->success()) { data->state_ = Data::State_CannotLoad; return; @@ -146,6 +161,10 @@ void MoodbarItemDelegate::ColorsLoaded( return; } + if (RemoveFromCacheIfIndexesInvalid(url, data)) { + return; + } + data->colors_ = watcher->result(); // Load the image next. @@ -173,6 +192,10 @@ void MoodbarItemDelegate::ImageLoaded(const QUrl& url, QFutureWatcher* w return; } + if (RemoveFromCacheIfIndexesInvalid(url, data)) { + return; + } + QImage image(watcher->result()); // If the desired size changed then don't even bother converting the image diff --git a/src/moodbar/moodbaritemdelegate.h b/src/moodbar/moodbaritemdelegate.h index 1edbe1e27..a8e6cf923 100644 --- a/src/moodbar/moodbaritemdelegate.h +++ b/src/moodbar/moodbaritemdelegate.h @@ -70,6 +70,8 @@ private: void StartLoadingColors(const QUrl& url, const QByteArray& bytes, Data* data); void StartLoadingImage(const QUrl& url, Data* data); + bool RemoveFromCacheIfIndexesInvalid(const QUrl& url, Data* data); + private: Application* app_; QCache data_; diff --git a/src/moodbar/moodbarloader.cpp b/src/moodbar/moodbarloader.cpp index d84e5465b..032078d8d 100644 --- a/src/moodbar/moodbarloader.cpp +++ b/src/moodbar/moodbarloader.cpp @@ -36,7 +36,7 @@ MoodbarLoader::MoodbarLoader(QObject* parent) save_alongside_originals_(false) { cache_->setCacheDirectory(Utilities::GetConfigPath(Utilities::Path_MoodbarCache)); - cache_->setMaximumCacheSize(1024 * 1024); // 1MB - enough for 333 moodbars + cache_->setMaximumCacheSize(10 * 1024 * 1024); // 10MB - enough for 3333 moodbars } MoodbarLoader::~MoodbarLoader() {