mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-01 20:06:53 +01:00
Move playlist loading off the GUI thread.
This commit is contained in:
parent
812a91214e
commit
f5449b9f8d
@ -116,9 +116,8 @@ SongLoader::Result SongLoader::LoadLocal() {
|
||||
qDebug() << "Parsing using" << parser->name();
|
||||
|
||||
// It's a playlist!
|
||||
file.reset();
|
||||
songs_ = parser->Load(&file, QFileInfo(filename).path());
|
||||
return Success;
|
||||
QtConcurrent::run(this, &SongLoader::LoadPlaylist, parser, filename);
|
||||
return WillLoadAsync;
|
||||
}
|
||||
|
||||
// Not a playlist, so just assume it's a song
|
||||
@ -129,6 +128,13 @@ SongLoader::Result SongLoader::LoadLocal() {
|
||||
return Success;
|
||||
}
|
||||
|
||||
void SongLoader::LoadPlaylist(ParserBase* parser, const QString& filename) {
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
songs_ = parser->Load(&file, QFileInfo(filename).path());
|
||||
emit LoadFinished(true);
|
||||
}
|
||||
|
||||
static bool CompareSongs(const Song& left, const Song& right) {
|
||||
// Order by artist, album, disc, track
|
||||
if (left.artist() < right.artist()) return true;
|
||||
|
@ -71,6 +71,7 @@ private:
|
||||
|
||||
Result LoadLocal();
|
||||
void LoadLocalDirectory(const QString& filename);
|
||||
void LoadPlaylist(ParserBase* parser, const QString& filename);
|
||||
|
||||
void AddAsRawStream();
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "playlist.h"
|
||||
#include "playlistbackend.h"
|
||||
#include "playlistmanager.h"
|
||||
#include "core/songloader.h"
|
||||
#include "core/utilities.h"
|
||||
#include "library/librarybackend.h"
|
||||
#include "library/libraryplaylistitem.h"
|
||||
@ -99,16 +100,37 @@ void PlaylistManager::New(const QString& name, const SongList& songs) {
|
||||
}
|
||||
|
||||
void PlaylistManager::Load(const QString& filename) {
|
||||
SongList songs = parser_->Load(filename);
|
||||
QUrl url = QUrl::fromLocalFile(filename);
|
||||
SongLoader* loader = new SongLoader(this);
|
||||
connect(loader, SIGNAL(LoadFinished(bool)), SLOT(LoadFinished(bool)));
|
||||
SongLoader::Result result = loader->Load(url);
|
||||
QFileInfo info(filename);
|
||||
|
||||
if (songs.isEmpty()) {
|
||||
if (result == SongLoader::Error ||
|
||||
(result == SongLoader::Success && loader->songs().isEmpty())) {
|
||||
emit Error(tr("The playlist '%1' was empty or could not be loaded.").arg(
|
||||
info.completeBaseName()));
|
||||
delete loader;
|
||||
return;
|
||||
}
|
||||
|
||||
New(info.baseName(), songs);
|
||||
if (result == SongLoader::Success) {
|
||||
New(info.baseName(), loader->songs());
|
||||
delete loader;
|
||||
}
|
||||
}
|
||||
|
||||
void PlaylistManager::LoadFinished(bool success) {
|
||||
SongLoader* loader = qobject_cast<SongLoader*>(sender());
|
||||
loader->deleteLater();
|
||||
QString localfile = loader->url().toLocalFile();
|
||||
QFileInfo info(localfile);
|
||||
if (!success || loader->songs().isEmpty()) {
|
||||
emit Error(tr("The playlist '%1' was empty or could not be loaded.").arg(
|
||||
info.completeBaseName()));
|
||||
}
|
||||
|
||||
New(info.baseName(), loader->songs());
|
||||
}
|
||||
|
||||
void PlaylistManager::Save(int id, const QString& filename) {
|
||||
|
@ -99,6 +99,7 @@ signals:
|
||||
private slots:
|
||||
void UpdateSummaryText();
|
||||
void SongsDiscovered(const SongList& songs);
|
||||
void LoadFinished(bool success);
|
||||
|
||||
private:
|
||||
Playlist* AddPlaylist(int id, const QString& name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user