mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-30 11:04:57 +01:00
Delete the divider entries properly from the library when deleting songs, and move songs to "Various artists" correctly.
This commit is contained in:
parent
b5b61a2e0e
commit
43a8b89732
@ -148,12 +148,9 @@ LibraryItem* Library::CreateArtistNode(bool signal, const QString& name) {
|
||||
endInsertRows();
|
||||
|
||||
if (!name.isEmpty()) {
|
||||
QChar divider_char = ret->sort_text[0];
|
||||
QChar divider_char = DividerChar(ret->sort_text);
|
||||
|
||||
if (divider_char.isDigit())
|
||||
divider_char = '0';
|
||||
|
||||
if (!divider_nodes_.contains(divider_char)) {
|
||||
if (!divider_char.isNull() && !divider_nodes_.contains(divider_char)) {
|
||||
if (signal)
|
||||
beginInsertRows(ItemToIndex(parent), parent->children.count(), parent->children.count());
|
||||
|
||||
@ -161,7 +158,7 @@ LibraryItem* Library::CreateArtistNode(bool signal, const QString& name) {
|
||||
new LibraryItem(LibraryItem::Type_Divider, QString(divider_char), root_);
|
||||
divider->lazy_loaded = true;
|
||||
|
||||
if (divider_char.isDigit())
|
||||
if (divider_char == '0')
|
||||
divider->display_text = "0-9";
|
||||
|
||||
divider_nodes_[divider_char] = divider;
|
||||
@ -174,6 +171,17 @@ LibraryItem* Library::CreateArtistNode(bool signal, const QString& name) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
QChar Library::DividerChar(const QString& sort_text) const {
|
||||
if (sort_text.isEmpty())
|
||||
return QChar();
|
||||
|
||||
QChar ret = sort_text[0];
|
||||
if (ret.isDigit())
|
||||
return '0';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
LibraryItem* Library::CreateAlbumNode(bool signal, const QString& name,
|
||||
LibraryItem* parent, bool compilation,
|
||||
const QString& art_automatic,
|
||||
@ -280,29 +288,34 @@ void Library::SongsDeleted(const SongList& songs) {
|
||||
|
||||
if (song.is_compilation())
|
||||
compilation_artist_node_ = NULL;
|
||||
else {
|
||||
else
|
||||
artist_nodes_.remove(song.artist());
|
||||
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete now-empty dividers
|
||||
foreach (const Song& song, songs) {
|
||||
QString sort_text(SortTextForArtist(song.artist()));
|
||||
if (!sort_text.isEmpty() && divider_nodes_.contains(sort_text[0])) {
|
||||
QChar c(sort_text[0]);
|
||||
QChar divider_char(DividerChar(sort_text));
|
||||
if (!divider_char.isNull() && !sort_text.isEmpty() &&
|
||||
divider_nodes_.contains(divider_char)) {
|
||||
bool found = false;
|
||||
foreach (LibraryItem* artist_node, artist_nodes_.values()) {
|
||||
if (artist_node->sort_text.startsWith(c)) {
|
||||
if (artist_node->sort_text.startsWith(divider_char)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
root_->Delete(divider_nodes_[c]->row);
|
||||
divider_nodes_.remove(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int row = divider_nodes_[divider_char]->row;
|
||||
beginRemoveRows(ItemToIndex(root_), row, row);
|
||||
root_->Delete(row);
|
||||
endRemoveRows();
|
||||
divider_nodes_.remove(divider_char);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ class Library : public SimpleTreeModel<LibraryItem> {
|
||||
QVariant data(const LibraryItem* item, int role) const;
|
||||
|
||||
bool CompareItems(const LibraryItem* a, const LibraryItem* b) const;
|
||||
QChar DividerChar(const QString& sort_text) const;
|
||||
|
||||
private:
|
||||
EngineBase* engine_;
|
||||
|
@ -542,7 +542,8 @@ void LibraryBackend::UpdateCompilations() {
|
||||
QSqlQuery find_songs("SELECT ROWID, " + QString(Song::kColumnSpec) + " FROM songs"
|
||||
" WHERE album = :album AND sampler = :sampler", db);
|
||||
|
||||
SongList updated_songs;
|
||||
SongList deleted_songs;
|
||||
SongList added_songs;
|
||||
|
||||
db.transaction();
|
||||
|
||||
@ -556,23 +557,23 @@ void LibraryBackend::UpdateCompilations() {
|
||||
|
||||
if (info.artists.count() > info.directories.count()) {
|
||||
if (info.has_not_samplers)
|
||||
UpdateCompilations(find_songs, update, updated_songs, album, 1);
|
||||
UpdateCompilations(find_songs, update, deleted_songs, added_songs, album, 1);
|
||||
} else {
|
||||
if (info.has_samplers)
|
||||
UpdateCompilations(find_songs, update, updated_songs, album, 0);
|
||||
UpdateCompilations(find_songs, update, deleted_songs, added_songs, album, 0);
|
||||
}
|
||||
}
|
||||
|
||||
db.commit();
|
||||
|
||||
if (!updated_songs.isEmpty()) {
|
||||
emit SongsDeleted(updated_songs);
|
||||
emit SongsDiscovered(updated_songs);
|
||||
if (!deleted_songs.isEmpty()) {
|
||||
emit SongsDeleted(deleted_songs);
|
||||
emit SongsDiscovered(added_songs);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryBackend::UpdateCompilations(QSqlQuery& find_songs, QSqlQuery& update,
|
||||
SongList& updated_songs,
|
||||
SongList& deleted_songs, SongList& added_songs,
|
||||
const QString& album, int sampler) {
|
||||
// Get songs that were already in that album, so we can tell the model
|
||||
// they've been updated
|
||||
@ -582,8 +583,9 @@ void LibraryBackend::UpdateCompilations(QSqlQuery& find_songs, QSqlQuery& update
|
||||
while (find_songs.next()) {
|
||||
Song song;
|
||||
song.InitFromQuery(find_songs);
|
||||
deleted_songs << song;
|
||||
song.set_sampler(true);
|
||||
updated_songs << song;
|
||||
added_songs << song;
|
||||
}
|
||||
|
||||
// Mark this album
|
||||
@ -710,7 +712,8 @@ void LibraryBackend::ForceCompilation(const QString& artist, const QString& albu
|
||||
|
||||
// Update the songs
|
||||
QString sql("UPDATE songs SET forced_compilation_on = :forced_compilation_on,"
|
||||
" forced_compilation_off = :forced_compilation_off"
|
||||
" forced_compilation_off = :forced_compilation_off,"
|
||||
" effective_compilation = ((compilation OR sampler OR :forced_compilation_on) AND NOT :forced_compilation_off) + 0"
|
||||
" WHERE album = :album");
|
||||
if (!artist.isEmpty())
|
||||
sql += " AND artist = :artist";
|
||||
|
@ -98,7 +98,7 @@ class LibraryBackend : public QObject {
|
||||
bool CheckErrors(const QSqlError& error);
|
||||
|
||||
void UpdateCompilations(QSqlQuery& find_songs, QSqlQuery& update,
|
||||
SongList& updated_songs,
|
||||
SongList& deleted_songs, SongList& added_songs,
|
||||
const QString& album, int sampler);
|
||||
AlbumList GetAlbums(const QString& artist, bool compilation = false,
|
||||
const QueryOptions& opt = QueryOptions());
|
||||
|
Loading…
x
Reference in New Issue
Block a user