Implement disk caching of album art (#360)
* Implement disk caching of album art This includes a button to clear the cache in the settings, as requested. Closes #358 * Make the cache size defaults match * Implement the review by jonaski * Fix more problems with the PR
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "collection/collectiondirectorymodel.h"
|
||||
#include "collectionsettingspage.h"
|
||||
@@ -43,6 +44,13 @@
|
||||
#include "ui_collectionsettingspage.h"
|
||||
|
||||
const char *CollectionSettingsPage::kSettingsGroup = "Collection";
|
||||
const char *CollectionSettingsPage::kSettingsCacheSize = "cache_size";
|
||||
const char *CollectionSettingsPage::kSettingsCacheSizeUnit = "cache_size_unit";
|
||||
const char *CollectionSettingsPage::kSettingsDiskCacheEnable = "disk_cache_enable";
|
||||
const char *CollectionSettingsPage::kSettingsDiskCacheSize = "disk_cache_size";
|
||||
const char *CollectionSettingsPage::kSettingsDiskCacheSizeUnit = "disk_cache_size_unit";
|
||||
|
||||
const QStringList CollectionSettingsPage::cacheUnitNames = { "KB", "MB", "GB", "TB" };
|
||||
|
||||
CollectionSettingsPage::CollectionSettingsPage(SettingsDialog *dialog)
|
||||
: SettingsPage(dialog),
|
||||
@@ -91,6 +99,14 @@ void CollectionSettingsPage::CurrentRowChanged(const QModelIndex& index) {
|
||||
ui_->remove->setEnabled(index.isValid());
|
||||
}
|
||||
|
||||
void CollectionSettingsPage::DiskCacheEnable(int state) {
|
||||
bool checked = state == Qt::Checked;
|
||||
ui_->button_disk_cache->setEnabled(checked);
|
||||
ui_->label_disk_cache_size->setEnabled(checked);
|
||||
ui_->spinbox_disk_cache_size->setEnabled(checked);
|
||||
ui_->combobox_disk_cache_size->setEnabled(checked);
|
||||
}
|
||||
|
||||
void CollectionSettingsPage::Load() {
|
||||
|
||||
if (!initialised_model_) {
|
||||
@@ -130,6 +146,20 @@ void CollectionSettingsPage::Load() {
|
||||
ui_->checkbox_cover_lowercase->setChecked(s.value("cover_lowercase", true).toBool());
|
||||
ui_->checkbox_cover_replace_spaces->setChecked(s.value("cover_replace_spaces", true).toBool());
|
||||
|
||||
ui_->spinbox_cache_size->setValue(s.value(kSettingsCacheSize, 80).toInt());
|
||||
ui_->combobox_cache_size->addItems(cacheUnitNames);
|
||||
ui_->combobox_cache_size->setCurrentIndex(s.value(kSettingsCacheSizeUnit, (int) CacheSizeUnit_MB).toInt());
|
||||
ui_->checkbox_disk_cache->setChecked(s.value(kSettingsDiskCacheEnable, false).toBool());
|
||||
ui_->label_disk_cache_size->setEnabled(ui_->checkbox_disk_cache->isChecked());
|
||||
ui_->spinbox_disk_cache_size->setEnabled(ui_->checkbox_disk_cache->isChecked());
|
||||
ui_->spinbox_disk_cache_size->setValue(s.value(kSettingsDiskCacheSize, 80).toInt());
|
||||
ui_->combobox_disk_cache_size->setEnabled(ui_->checkbox_disk_cache->isChecked());
|
||||
ui_->combobox_disk_cache_size->addItems(cacheUnitNames);
|
||||
ui_->combobox_disk_cache_size->setCurrentIndex(s.value(kSettingsDiskCacheSizeUnit, (int) CacheSizeUnit_MB).toInt());
|
||||
|
||||
connect(ui_->checkbox_disk_cache, SIGNAL(stateChanged(int)), SLOT(DiskCacheEnable(int)));
|
||||
connect(ui_->button_disk_cache, SIGNAL(clicked()), dialog()->app(), SIGNAL(ClearPixmapDiskCache()));
|
||||
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
@@ -161,6 +191,12 @@ void CollectionSettingsPage::Save() {
|
||||
s.setValue("cover_lowercase", ui_->checkbox_cover_lowercase->isChecked());
|
||||
s.setValue("cover_replace_spaces", ui_->checkbox_cover_replace_spaces->isChecked());
|
||||
|
||||
s.setValue(kSettingsCacheSize, ui_->spinbox_cache_size->value());
|
||||
s.setValue(kSettingsCacheSizeUnit, ui_->combobox_cache_size->currentIndex());
|
||||
s.setValue(kSettingsDiskCacheEnable, ui_->checkbox_disk_cache->isChecked());
|
||||
s.setValue(kSettingsDiskCacheSize, ui_->spinbox_disk_cache_size->value());
|
||||
s.setValue(kSettingsDiskCacheSizeUnit, ui_->combobox_disk_cache_size->currentIndex());
|
||||
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,18 @@ public:
|
||||
~CollectionSettingsPage();
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
static const char *kSettingsCacheSize;
|
||||
static const char *kSettingsCacheSizeUnit;
|
||||
static const char *kSettingsDiskCacheEnable;
|
||||
static const char *kSettingsDiskCacheSize;
|
||||
static const char *kSettingsDiskCacheSizeUnit;
|
||||
|
||||
enum CacheSizeUnit {
|
||||
CacheSizeUnit_KB,
|
||||
CacheSizeUnit_MB,
|
||||
CacheSizeUnit_GB,
|
||||
CacheSizeUnit_TB,
|
||||
};
|
||||
|
||||
enum SaveCover {
|
||||
SaveCover_Hash = 1,
|
||||
@@ -53,11 +65,14 @@ private slots:
|
||||
void Remove();
|
||||
|
||||
void CurrentRowChanged(const QModelIndex &index);
|
||||
void DiskCacheEnable(int state);
|
||||
void CoverSaveInAlbumDirChanged();
|
||||
|
||||
private:
|
||||
Ui_CollectionSettingsPage *ui_;
|
||||
bool initialised_model_;
|
||||
|
||||
static const QStringList cacheUnitNames;
|
||||
};
|
||||
|
||||
#endif // COLLECTIONSETTINGSPAGE_H
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>509</width>
|
||||
<height>746</height>
|
||||
<height>913</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -249,6 +249,99 @@ If there are no matches then it will use the largest image in the directory.</st
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="albumArtGroupBox">
|
||||
<property name="title">
|
||||
<string>Album art cache</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_cache_size">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinbox_cache_size">
|
||||
<property name="maximum">
|
||||
<number>1048576</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="combobox_cache_size">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkbox_disk_cache">
|
||||
<property name="text">
|
||||
<string>Enable Disk Cache</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_disk_cache">
|
||||
<property name="text">
|
||||
<string>Clear Disk Cache</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_disk_cache_size">
|
||||
<property name="text">
|
||||
<string>Disk Cache Size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinbox_disk_cache_size">
|
||||
<property name="maximum">
|
||||
<number>1048576</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="combobox_disk_cache_size">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user