Line 0
Link Here
|
|
|
1 |
--- src/collection/collectionmodel.cpp.orig 2020-05-16 18:39:26 UTC |
2 |
+++ src/collection/collectionmodel.cpp |
3 |
@@ -119,12 +119,14 @@ CollectionModel::CollectionModel(CollectionBackend *ba |
4 |
} |
5 |
|
6 |
QIcon nocover = IconLoader::Load("cdcase"); |
7 |
- no_cover_icon_ = nocover.pixmap(nocover.availableSizes().last()).scaled(kPrettyCoverSize, kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
8 |
- //no_cover_icon_ = QPixmap(":/pictures/noalbumart.png").scaled(kPrettyCoverSize, kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
9 |
+ if (!nocover.isNull()) { |
10 |
+ no_cover_icon_ = nocover.pixmap(nocover.availableSizes().last()).scaled(kPrettyCoverSize, kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
11 |
+ } |
12 |
|
13 |
- if (sIconCache == nullptr) { |
14 |
+ if (app_ && !sIconCache) { |
15 |
sIconCache = new QNetworkDiskCache(this); |
16 |
sIconCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/" + kPixmapDiskCacheDir); |
17 |
+ connect(app_, SIGNAL(ClearPixmapDiskCache()), SLOT(ClearDiskCache())); |
18 |
} |
19 |
|
20 |
connect(backend_, SIGNAL(SongsDiscovered(SongList)), SLOT(SongsDiscovered(SongList))); |
21 |
@@ -139,8 +141,6 @@ CollectionModel::CollectionModel(CollectionBackend *ba |
22 |
backend_->UpdateTotalArtistCountAsync(); |
23 |
backend_->UpdateTotalAlbumCountAsync(); |
24 |
|
25 |
- connect(app_, SIGNAL(ClearPixmapDiskCache()), SLOT(ClearDiskCache())); |
26 |
- |
27 |
ReloadSettings(); |
28 |
|
29 |
} |
30 |
@@ -189,7 +189,9 @@ void CollectionModel::ReloadSettings() { |
31 |
|
32 |
QPixmapCache::setCacheLimit(MaximumCacheSize(&s, CollectionSettingsPage::kSettingsCacheSize, CollectionSettingsPage::kSettingsCacheSizeUnit, CollectionSettingsPage::kSettingsCacheSizeDefault) / 1024); |
33 |
|
34 |
- sIconCache->setMaximumCacheSize(MaximumCacheSize(&s, CollectionSettingsPage::kSettingsDiskCacheSize, CollectionSettingsPage::kSettingsDiskCacheSizeUnit, CollectionSettingsPage::kSettingsDiskCacheSizeDefault)); |
35 |
+ if (sIconCache) { |
36 |
+ sIconCache->setMaximumCacheSize(MaximumCacheSize(&s, CollectionSettingsPage::kSettingsDiskCacheSize, CollectionSettingsPage::kSettingsDiskCacheSizeUnit, CollectionSettingsPage::kSettingsDiskCacheSizeDefault)); |
37 |
+ } |
38 |
|
39 |
s.endGroup(); |
40 |
|
41 |
@@ -510,7 +512,7 @@ void CollectionModel::SongsDeleted(const SongList &son |
42 |
// Remove from pixmap cache |
43 |
const QString cache_key = AlbumIconPixmapCacheKey(ItemToIndex(node)); |
44 |
QPixmapCache::remove(cache_key); |
45 |
- if (use_disk_cache_) sIconCache->remove(QUrl(cache_key)); |
46 |
+ if (use_disk_cache_ && sIconCache) sIconCache->remove(QUrl(cache_key)); |
47 |
if (pending_cache_keys_.contains(cache_key)) { |
48 |
pending_cache_keys_.remove(cache_key); |
49 |
} |
50 |
@@ -585,7 +587,7 @@ QVariant CollectionModel::AlbumIcon(const QModelIndex |
51 |
} |
52 |
|
53 |
// Try to load it from the disk cache |
54 |
- if (use_disk_cache_) { |
55 |
+ if (use_disk_cache_ && sIconCache) { |
56 |
std::unique_ptr<QIODevice> cache(sIconCache->data(QUrl(cache_key))); |
57 |
if (cache) { |
58 |
QImage cached_image; |
59 |
@@ -637,7 +639,7 @@ void CollectionModel::AlbumCoverLoaded(const quint64 i |
60 |
} |
61 |
|
62 |
// If we have a valid cover not already in the disk cache |
63 |
- if (use_disk_cache_) { |
64 |
+ if (use_disk_cache_ && sIconCache) { |
65 |
std::unique_ptr<QIODevice> cached_img(sIconCache->data(QUrl(cache_key))); |
66 |
if (!cached_img && !result.image_scaled.isNull()) { |
67 |
QNetworkCacheMetaData item_metadata; |
68 |
@@ -1556,6 +1558,7 @@ int CollectionModel::MaximumCacheSize(QSettings *s, co |
69 |
} while (unit > 0); |
70 |
|
71 |
return size; |
72 |
+ |
73 |
} |
74 |
|
75 |
void CollectionModel::GetChildSongs(CollectionItem *item, QList<QUrl> *urls, SongList *songs, QSet<int> *song_ids) const { |
76 |
@@ -1686,7 +1689,7 @@ void CollectionModel::TotalAlbumCountUpdatedSlot(const |
77 |
} |
78 |
|
79 |
void CollectionModel::ClearDiskCache() { |
80 |
- sIconCache->clear(); |
81 |
+ if (sIconCache) sIconCache->clear(); |
82 |
} |
83 |
|
84 |
QDataStream &operator<<(QDataStream &s, const CollectionModel::Grouping &g) { |