Make the async load of folders thread-safe
This commit is contained in:
parent
631924bdd1
commit
fdad2bd706
|
@ -308,15 +308,10 @@ void SongLoader::EffectiveSongsLoad() {
|
|||
continue;
|
||||
}
|
||||
|
||||
LibraryQuery query;
|
||||
query.SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec);
|
||||
query.AddWhere("filename", song.url().toEncoded());
|
||||
|
||||
if (library_->ExecQuery(&query) && query.Next()) {
|
||||
// we may have many results when the file has many sections
|
||||
do {
|
||||
song.InitFromQuery(query, true);
|
||||
} while(query.Next());
|
||||
// First, try to get the song from the library
|
||||
Song library_song = library_->GetSongByUrl(song.url());
|
||||
if (library_song.is_valid()) {
|
||||
song = library_song;
|
||||
} else {
|
||||
// it's a normal media file
|
||||
QString filename = song.url().toLocalFile();
|
||||
|
|
|
@ -972,7 +972,7 @@ void Playlist::UpdateItems(const SongList& songs) {
|
|||
foreach (const Song& song, songs) {
|
||||
// Update current items list
|
||||
for (int i=0; i<items_.size(); i++) {
|
||||
PlaylistItemPtr item = items_[i];
|
||||
PlaylistItemPtr& item = items_[i];
|
||||
if (item->Metadata().url() == song.url() &&
|
||||
(item->Metadata().filetype() == Song::Type_Unknown ||
|
||||
// Stream may change and may need to be updated too
|
||||
|
@ -1730,7 +1730,7 @@ void Playlist::RemoveDeletedSongs() {
|
|||
Song song = item->Metadata();
|
||||
|
||||
if(!song.is_stream() && !QFile::exists(song.url().toLocalFile())) {
|
||||
rows_to_remove.append(row);
|
||||
rows_to_remove.append(row);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,6 @@ class Playlist : public QAbstractListModel {
|
|||
const SongList& songs, int pos = -1, bool play_now = false, bool enqueue = false);
|
||||
// Removes items with given indices from the playlist. This operation is not undoable.
|
||||
void RemoveItemsWithoutUndo (const QList<int>& indices);
|
||||
void UpdateItems (const SongList& songs);
|
||||
|
||||
// If this playlist contains the current item, this method will apply the "valid" flag on it.
|
||||
// If the "valid" flag is false, the song will be greyed out. Otherwise the grey color will
|
||||
|
@ -265,6 +264,7 @@ class Playlist : public QAbstractListModel {
|
|||
void ClearStreamMetadata();
|
||||
void SetStreamMetadata(const QUrl& url, const Song& song);
|
||||
void ItemChanged(PlaylistItemPtr item);
|
||||
void UpdateItems(const SongList& songs);
|
||||
|
||||
void Clear();
|
||||
void Shuffle();
|
||||
|
|
|
@ -49,6 +49,8 @@ void SongLoaderInserter::Load(Playlist *destination,
|
|||
enqueue_ = enqueue;
|
||||
|
||||
connect(destination, SIGNAL(destroyed()), SLOT(DestinationDestroyed()));
|
||||
connect(this, SIGNAL(EffectiveLoadFinished(const SongList&)),
|
||||
destination, SLOT(UpdateItems(const SongList&)));
|
||||
|
||||
foreach (const QUrl& url, urls) {
|
||||
SongLoader* loader = new SongLoader(library_, this);
|
||||
|
@ -105,6 +107,7 @@ void SongLoaderInserter::LoadAudioCD(Playlist *destination,
|
|||
void SongLoaderInserter::DestinationDestroyed() {
|
||||
destination_ = NULL;
|
||||
}
|
||||
|
||||
void SongLoaderInserter::AudioCDTagsLoaded(bool success) {
|
||||
SongLoader* loader = qobject_cast<SongLoader*>(sender());
|
||||
if (!loader || !destination_)
|
||||
|
@ -152,9 +155,7 @@ void SongLoaderInserter::EffectiveLoad() {
|
|||
foreach (SongLoader* loader, pending_async_) {
|
||||
loader->EffectiveSongsLoad();
|
||||
task_manager_->SetTaskProgress(async_load_id_, ++async_progress_);
|
||||
if (destination_) {
|
||||
destination_->UpdateItems(loader->songs());
|
||||
}
|
||||
emit EffectiveLoadFinished(loader->songs());
|
||||
}
|
||||
task_manager_->SetTaskFinished(async_load_id_);
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
|
||||
signals:
|
||||
void Error(const QString& message);
|
||||
void EffectiveLoadFinished(const SongList& songs);
|
||||
|
||||
private slots:
|
||||
void PendingLoadFinished(bool success);
|
||||
|
|
Loading…
Reference in New Issue