Don't ever restructure or reset the library model when statistics on a song are changed.

This commit is contained in:
David Sansome 2010-10-17 19:34:45 +00:00
parent a13e0ba3f3
commit 0a42a9efb5
5 changed files with 17 additions and 10 deletions

View File

@ -810,8 +810,6 @@ void LibraryBackend::IncrementPlayCount(int id) {
QMutexLocker l(db_->Mutex());
QSqlDatabase db(db_->Connect());
Song old_song = GetSongById(id, db);
QSqlQuery q(QString("UPDATE %1 SET playcount = playcount + 1,"
" lastplayed = :now"
" WHERE ROWID = :id").arg(songs_table_), db);
@ -822,9 +820,7 @@ void LibraryBackend::IncrementPlayCount(int id) {
return;
Song new_song = GetSongById(id, db);
emit SongsDeleted(SongList() << old_song);
emit SongsDiscovered(SongList() << new_song);
emit SongsStatisticsChanged(SongList() << new_song);
}
void LibraryBackend::IncrementSkipCount(int id) {
@ -834,8 +830,6 @@ void LibraryBackend::IncrementSkipCount(int id) {
QMutexLocker l(db_->Mutex());
QSqlDatabase db(db_->Connect());
Song old_song = GetSongById(id, db);
QSqlQuery q(QString("UPDATE %1 SET skipcount = skipcount + 1"
" WHERE ROWID = :id").arg(songs_table_), db);
q.bindValue(":id", id);
@ -844,7 +838,5 @@ void LibraryBackend::IncrementSkipCount(int id) {
return;
Song new_song = GetSongById(id, db);
emit SongsDeleted(SongList() << old_song);
emit SongsDiscovered(SongList() << new_song);
emit SongsStatisticsChanged(SongList() << new_song);
}

View File

@ -154,6 +154,7 @@ class LibraryBackend : public LibraryBackendInterface {
void SongsDiscovered(const SongList& songs);
void SongsDeleted(const SongList& songs);
void SongsStatisticsChanged(const SongList& songs);
void TotalSongCountUpdated(int total);

View File

@ -52,6 +52,7 @@ LibraryModel::~LibraryModel() {
void LibraryModel::Init() {
connect(backend_, SIGNAL(SongsDiscovered(SongList)), SLOT(SongsDiscovered(SongList)));
connect(backend_, SIGNAL(SongsDeleted(SongList)), SLOT(SongsDeleted(SongList)));
connect(backend_, SIGNAL(SongsStatisticsChanged(SongList)), SLOT(SongsStatisticsChanged(SongList)));
connect(backend_, SIGNAL(TotalSongCountUpdated(int)), SIGNAL(TotalSongCountUpdated(int)));
backend_->UpdateTotalSongCountAsync();
@ -131,6 +132,17 @@ void LibraryModel::SongsDiscovered(const SongList& songs) {
}
}
void LibraryModel::SongsStatisticsChanged(const SongList& songs) {
// This is called if there was a minor change to the songs that will not
// normally require the library to be restructured. We can just update our
// internal cache of Song objects without worrying about resetting the model.
foreach (const Song& song, songs) {
if (song_nodes_.contains(song.id())) {
song_nodes_[song.id()]->metadata = song;
}
}
}
LibraryItem* LibraryModel::CreateCompilationArtistNode(bool signal, LibraryItem* parent) {
if (signal)
beginInsertRows(ItemToIndex(parent), parent->children.count(), parent->children.count());

View File

@ -117,6 +117,7 @@ class LibraryModel : public SimpleTreeModel<LibraryItem> {
// From LibraryBackend
void SongsDiscovered(const SongList& songs);
void SongsDeleted(const SongList& songs);
void SongsStatisticsChanged(const SongList& songs);
void Reset();
private:

View File

@ -52,6 +52,7 @@ void PlaylistManager::Init(LibraryBackend* library_backend,
sequence_ = sequence;
connect(library_backend_, SIGNAL(SongsDiscovered(SongList)), SLOT(SongsDiscovered(SongList)));
connect(library_backend_, SIGNAL(SongsStatisticsChanged(SongList)), SLOT(SongsDiscovered(SongList)));
foreach (const PlaylistBackend::Playlist& p, playlist_backend->GetAllPlaylists()) {
AddPlaylist(p.id, p.name);