mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2024-12-14 09:44:51 +01:00
Fix broken context albums
This commit is contained in:
parent
1a643bfa8c
commit
3d06d68196
@ -197,6 +197,8 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
|
|||||||
const CollectionModel::Grouping GetGroupBy() const { return group_by_; }
|
const CollectionModel::Grouping GetGroupBy() const { return group_by_; }
|
||||||
void SetGroupBy(const CollectionModel::Grouping g);
|
void SetGroupBy(const CollectionModel::Grouping g);
|
||||||
|
|
||||||
|
static QString ContainerKey(const GroupBy type, const Song &song);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void TotalSongCountUpdated(int count);
|
void TotalSongCountUpdated(int count);
|
||||||
void TotalArtistCountUpdated(int count);
|
void TotalArtistCountUpdated(int count);
|
||||||
@ -259,9 +261,8 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
|
|||||||
CollectionItem *InitItem(const GroupBy type, const bool signal, CollectionItem *parent, const int container_level);
|
CollectionItem *InitItem(const GroupBy type, const bool signal, CollectionItem *parent, const int container_level);
|
||||||
void FinishItem(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, CollectionItem *item);
|
void FinishItem(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, CollectionItem *item);
|
||||||
|
|
||||||
static QString ContainerKey(const GroupBy type, const Song &song) ;
|
static QString DividerKey(const GroupBy type, CollectionItem *item);
|
||||||
static QString DividerKey(const GroupBy type, CollectionItem *item) ;
|
static QString DividerDisplayText(const GroupBy type, const QString &key);
|
||||||
static QString DividerDisplayText(const GroupBy type, const QString &key) ;
|
|
||||||
|
|
||||||
// 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_; }
|
||||||
|
@ -84,20 +84,12 @@ void ContextAlbumsModel::AddSongs(const SongList &songs) {
|
|||||||
|
|
||||||
for (const Song &song : songs) {
|
for (const Song &song : songs) {
|
||||||
if (song_nodes_.contains(song.id())) continue;
|
if (song_nodes_.contains(song.id())) continue;
|
||||||
|
|
||||||
// Before we can add each song we need to make sure the required container items already exist in the tree.
|
|
||||||
|
|
||||||
// Find parent containers in the tree
|
|
||||||
CollectionItem *container = root_;
|
CollectionItem *container = root_;
|
||||||
|
QString key = CollectionModel::ContainerKey(CollectionModel::GroupBy_Album, song);
|
||||||
// Does it exist already?
|
if (!container_nodes_.contains(key)) {
|
||||||
if (!container_nodes_.contains(song.album())) {
|
container_nodes_.insert(key, ItemFromSong(CollectionItem::Type_Container, true, container, song, 0));
|
||||||
// Create the container
|
|
||||||
container_nodes_[song.album()] = ItemFromSong(CollectionItem::Type_Container, true, container, song, 0);
|
|
||||||
}
|
}
|
||||||
container = container_nodes_[song.album()];
|
container = container_nodes_[key];
|
||||||
|
|
||||||
// We've gone all the way down to the deepest level and everything was already lazy loaded, so now we have to create the song in the container.
|
|
||||||
song_nodes_[song.id()] = ItemFromSong(CollectionItem::Type_Song, true, container, song, -1);
|
song_nodes_[song.id()] = ItemFromSong(CollectionItem::Type_Song, true, container, song, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +129,7 @@ QVariant ContextAlbumsModel::AlbumIcon(const QModelIndex &idx) {
|
|||||||
SongList songs = GetChildSongs(idx);
|
SongList songs = GetChildSongs(idx);
|
||||||
if (!songs.isEmpty()) {
|
if (!songs.isEmpty()) {
|
||||||
const quint64 id = app_->album_cover_loader()->LoadImageAsync(cover_loader_options_, songs.first());
|
const quint64 id = app_->album_cover_loader()->LoadImageAsync(cover_loader_options_, songs.first());
|
||||||
pending_art_[id] = ItemAndCacheKey(item, cache_key);
|
pending_art_.insert(id, ItemAndCacheKey(item, cache_key));
|
||||||
pending_cache_keys_.insert(cache_key);
|
pending_cache_keys_.insert(cache_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +147,9 @@ void ContextAlbumsModel::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoad
|
|||||||
if (!item) return;
|
if (!item) return;
|
||||||
|
|
||||||
const QString &cache_key = item_and_cache_key.second;
|
const QString &cache_key = item_and_cache_key.second;
|
||||||
pending_cache_keys_.remove(cache_key);
|
if (pending_cache_keys_.contains(cache_key)) {
|
||||||
|
pending_cache_keys_.remove(cache_key);
|
||||||
|
}
|
||||||
|
|
||||||
// Insert this image in the cache.
|
// Insert this image in the cache.
|
||||||
if (!result.success || result.image_scaled.isNull() || result.type == AlbumCoverLoaderResult::Type_ManuallyUnset) {
|
if (!result.success || result.image_scaled.isNull() || result.type == AlbumCoverLoaderResult::Type_ManuallyUnset) {
|
||||||
@ -272,9 +266,17 @@ CollectionItem *ContextAlbumsModel::ItemFromSong(CollectionItem::Type item_type,
|
|||||||
item->container_level = container_level;
|
item->container_level = container_level;
|
||||||
item->lazy_loaded = true;
|
item->lazy_loaded = true;
|
||||||
|
|
||||||
if (item->key.isEmpty()) item->key = s.album();
|
if (item_type == CollectionItem::Type_Container) {
|
||||||
item->display_text = CollectionModel::TextOrUnknown(item->key);
|
item->key = CollectionModel::ContainerKey(CollectionModel::GroupBy_Album, s);
|
||||||
item->sort_text = CollectionModel::SortTextForArtist(item->key);
|
item->display_text = CollectionModel::TextOrUnknown(s.album());
|
||||||
|
item->sort_text = CollectionModel::SortTextForArtist(s.album());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
item->key = s.album() + " " + s.title();
|
||||||
|
item->display_text = CollectionModel::TextOrUnknown(s.title());
|
||||||
|
item->sort_text = CollectionModel::SortTextForSong(s);
|
||||||
|
item->metadata = s;
|
||||||
|
}
|
||||||
|
|
||||||
if (signal) endInsertRows();
|
if (signal) endInsertRows();
|
||||||
|
|
||||||
@ -339,13 +341,14 @@ bool ContextAlbumsModel::CompareItems(const CollectionItem *a, const CollectionI
|
|||||||
void ContextAlbumsModel::GetChildSongs(CollectionItem *item, QList<QUrl> *urls, SongList *songs, QSet<int> *song_ids) const {
|
void ContextAlbumsModel::GetChildSongs(CollectionItem *item, QList<QUrl> *urls, SongList *songs, QSet<int> *song_ids) const {
|
||||||
|
|
||||||
switch (item->type) {
|
switch (item->type) {
|
||||||
case CollectionItem::Type_Container: {
|
case CollectionItem::Type_Container:{
|
||||||
|
|
||||||
QList<CollectionItem*> children = item->children;
|
QList<CollectionItem*> children = item->children;
|
||||||
std::sort(children.begin(), children.end(), std::bind(&ContextAlbumsModel::CompareItems, this, std::placeholders::_1, std::placeholders::_2));
|
std::sort(children.begin(), children.end(), std::bind(&ContextAlbumsModel::CompareItems, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
|
|
||||||
for (CollectionItem *child : children)
|
for (CollectionItem *child : children) {
|
||||||
GetChildSongs(child, urls, songs, song_ids);
|
GetChildSongs(child, urls, songs, song_ids);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user