Remove playlist moodbars from the cache if they have been removed from the model, and make the disk cache bigger

This commit is contained in:
David Sansome 2012-05-27 19:10:39 +01:00
parent a2feaa61e7
commit d939b4cf29
3 changed files with 26 additions and 1 deletions

View File

@ -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<QImage>* w
return;
}
if (RemoveFromCacheIfIndexesInvalid(url, data)) {
return;
}
QImage image(watcher->result());
// If the desired size changed then don't even bother converting the image

View File

@ -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<QUrl, Data> data_;

View File

@ -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() {