@@ -558,7 +558,7 @@ void CollectionModel::SongsDeleted(const SongList &songs) {
|
|||||||
// Remove from pixmap cache
|
// Remove from pixmap cache
|
||||||
const QString cache_key = AlbumIconPixmapCacheKey(ItemToIndex(node));
|
const QString cache_key = AlbumIconPixmapCacheKey(ItemToIndex(node));
|
||||||
QPixmapCache::remove(cache_key);
|
QPixmapCache::remove(cache_key);
|
||||||
if (use_disk_cache_ && sIconCache) sIconCache->remove(QUrl(cache_key));
|
if (use_disk_cache_ && sIconCache) sIconCache->remove(AlbumIconPixmapDiskCacheKey(cache_key));
|
||||||
if (pending_cache_keys_.contains(cache_key)) {
|
if (pending_cache_keys_.contains(cache_key)) {
|
||||||
pending_cache_keys_.remove(cache_key);
|
pending_cache_keys_.remove(cache_key);
|
||||||
}
|
}
|
||||||
@@ -613,6 +613,12 @@ QString CollectionModel::AlbumIconPixmapCacheKey(const QModelIndex &idx) const {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QUrl CollectionModel::AlbumIconPixmapDiskCacheKey(const QString &cache_key) const {
|
||||||
|
|
||||||
|
return QUrl(QUrl::toPercentEncoding(cache_key));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
QVariant CollectionModel::AlbumIcon(const QModelIndex &idx) {
|
QVariant CollectionModel::AlbumIcon(const QModelIndex &idx) {
|
||||||
|
|
||||||
CollectionItem *item = IndexToItem(idx);
|
CollectionItem *item = IndexToItem(idx);
|
||||||
@@ -628,10 +634,10 @@ QVariant CollectionModel::AlbumIcon(const QModelIndex &idx) {
|
|||||||
|
|
||||||
// Try to load it from the disk cache
|
// Try to load it from the disk cache
|
||||||
if (use_disk_cache_ && sIconCache) {
|
if (use_disk_cache_ && sIconCache) {
|
||||||
std::unique_ptr<QIODevice> cache(sIconCache->data(QUrl(cache_key)));
|
std::unique_ptr<QIODevice> disk_cache_img(sIconCache->data(AlbumIconPixmapDiskCacheKey(cache_key)));
|
||||||
if (cache) {
|
if (disk_cache_img) {
|
||||||
QImage cached_image;
|
QImage cached_image;
|
||||||
if (cached_image.load(cache.get(), "XPM")) {
|
if (cached_image.load(disk_cache_img.get(), "XPM")) {
|
||||||
QPixmapCache::insert(cache_key, QPixmap::fromImage(cached_image));
|
QPixmapCache::insert(cache_key, QPixmap::fromImage(cached_image));
|
||||||
return QPixmap::fromImage(cached_image);
|
return QPixmap::fromImage(cached_image);
|
||||||
}
|
}
|
||||||
@@ -682,15 +688,16 @@ void CollectionModel::AlbumCoverLoaded(const quint64 id, AlbumCoverLoaderResultP
|
|||||||
|
|
||||||
// If we have a valid cover not already in the disk cache
|
// If we have a valid cover not already in the disk cache
|
||||||
if (use_disk_cache_ && sIconCache && result->success && !result->image_scaled.isNull()) {
|
if (use_disk_cache_ && sIconCache && result->success && !result->image_scaled.isNull()) {
|
||||||
std::unique_ptr<QIODevice> cached_img(sIconCache->data(QUrl(cache_key)));
|
const QUrl disk_cache_key = AlbumIconPixmapDiskCacheKey(cache_key);
|
||||||
if (!cached_img) {
|
std::unique_ptr<QIODevice> disk_cache_img(sIconCache->data(disk_cache_key));
|
||||||
QNetworkCacheMetaData item_metadata;
|
if (!disk_cache_img) {
|
||||||
item_metadata.setSaveToDisk(true);
|
QNetworkCacheMetaData disk_cache_metadata;
|
||||||
item_metadata.setUrl(QUrl(cache_key));
|
disk_cache_metadata.setSaveToDisk(true);
|
||||||
QIODevice *cache = sIconCache->prepare(item_metadata);
|
disk_cache_metadata.setUrl(disk_cache_key);
|
||||||
if (cache) {
|
QIODevice *device_iconcache = sIconCache->prepare(disk_cache_metadata);
|
||||||
result->image_scaled.save(cache, "XPM");
|
if (device_iconcache) {
|
||||||
sIconCache->insert(cache);
|
result->image_scaled.save(device_iconcache, "XPM");
|
||||||
|
sIconCache->insert(device_iconcache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,6 +267,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
|
|||||||
// Helpers
|
// Helpers
|
||||||
static bool IsCompilationArtistNode(const CollectionItem *node) { return node == node->parent->compilation_artist_node_; }
|
static bool IsCompilationArtistNode(const CollectionItem *node) { return node == node->parent->compilation_artist_node_; }
|
||||||
QString AlbumIconPixmapCacheKey(const QModelIndex &idx) const;
|
QString AlbumIconPixmapCacheKey(const QModelIndex &idx) const;
|
||||||
|
QUrl AlbumIconPixmapDiskCacheKey(const QString &cache_key) const;
|
||||||
QVariant AlbumIcon(const QModelIndex &idx);
|
QVariant AlbumIcon(const QModelIndex &idx);
|
||||||
QVariant data(const CollectionItem *item, const int role) const;
|
QVariant data(const CollectionItem *item, const int role) const;
|
||||||
bool CompareItems(const CollectionItem *a, const CollectionItem *b) const;
|
bool CompareItems(const CollectionItem *a, const CollectionItem *b) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user