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:
Gavin D. Howard
2020-02-07 15:18:18 -07:00
committed by GitHub
parent ab7b65a30b
commit 691f5d99ca
10 changed files with 254 additions and 16 deletions

View File

@@ -43,6 +43,7 @@
#include <QImage>
#include <QIcon>
#include <QPixmap>
#include <QNetworkDiskCache>
#include <QSettings>
#include "core/simpletreemodel.h"
@@ -69,7 +70,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
static const char *kSavedGroupingsSettingsGroup;
static const int kPrettyCoverSize;
static const int kPixmapCacheLimit;
static const char *kPixmapDiskCacheDir;
enum Role {
Role_Type = Qt::UserRole + 1,
@@ -162,6 +163,9 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
// Save the current grouping
void SaveGrouping(QString name);
// Reload settings.
void ReloadSettings();
// Utility functions for manipulating text
static QString TextOrUnknown(const QString &text);
static QString PrettyYearAlbum(const int year, const QString &album);
@@ -203,6 +207,7 @@ signals:
void TotalSongCountUpdatedSlot(int count);
void TotalArtistCountUpdatedSlot(int count);
void TotalAlbumCountUpdatedSlot(int count);
void ClearDiskCache();
// Called after ResetAsync
void ResetAsyncQueryFinished(QFuture<CollectionModel::QueryResult> future);
@@ -244,6 +249,7 @@ signals:
QVariant AlbumIcon(const QModelIndex &idx);
QVariant data(const CollectionItem *item, int role) const;
bool CompareItems(const CollectionItem *a, const CollectionItem *b) const;
int MaximumCacheSize(QSettings *s, const char *size_id, const char *size_unit_id) const;
private:
CollectionBackend *backend_;
@@ -274,10 +280,13 @@ signals:
QIcon playlists_dir_icon_;
QIcon playlist_icon_;
static QNetworkDiskCache *sIconCache;
int init_task_id_;
bool use_pretty_covers_;
bool show_dividers_;
bool use_disk_cache_;
AlbumCoverLoaderOptions cover_loader_options_;