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();
|
qDebug() << "Parsing using" << parser->name();
|
||||||
|
|
||||||
// It's a playlist!
|
// It's a playlist!
|
||||||
file.reset();
|
QtConcurrent::run(this, &SongLoader::LoadPlaylist, parser, filename);
|
||||||
songs_ = parser->Load(&file, QFileInfo(filename).path());
|
return WillLoadAsync;
|
||||||
return Success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not a playlist, so just assume it's a song
|
// Not a playlist, so just assume it's a song
|
||||||
@ -129,6 +128,13 @@ SongLoader::Result SongLoader::LoadLocal() {
|
|||||||
return Success;
|
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) {
|
static bool CompareSongs(const Song& left, const Song& right) {
|
||||||
// Order by artist, album, disc, track
|
// Order by artist, album, disc, track
|
||||||
if (left.artist() < right.artist()) return true;
|
if (left.artist() < right.artist()) return true;
|
||||||
|
@ -71,6 +71,7 @@ private:
|
|||||||
|
|
||||||
Result LoadLocal();
|
Result LoadLocal();
|
||||||
void LoadLocalDirectory(const QString& filename);
|
void LoadLocalDirectory(const QString& filename);
|
||||||
|
void LoadPlaylist(ParserBase* parser, const QString& filename);
|
||||||
|
|
||||||
void AddAsRawStream();
|
void AddAsRawStream();
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "playlist.h"
|
#include "playlist.h"
|
||||||
#include "playlistbackend.h"
|
#include "playlistbackend.h"
|
||||||
#include "playlistmanager.h"
|
#include "playlistmanager.h"
|
||||||
|
#include "core/songloader.h"
|
||||||
#include "core/utilities.h"
|
#include "core/utilities.h"
|
||||||
#include "library/librarybackend.h"
|
#include "library/librarybackend.h"
|
||||||
#include "library/libraryplaylistitem.h"
|
#include "library/libraryplaylistitem.h"
|
||||||
@ -99,16 +100,37 @@ void PlaylistManager::New(const QString& name, const SongList& songs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PlaylistManager::Load(const QString& filename) {
|
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);
|
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(
|
emit Error(tr("The playlist '%1' was empty or could not be loaded.").arg(
|
||||||
info.completeBaseName()));
|
info.completeBaseName()));
|
||||||
|
delete loader;
|
||||||
return;
|
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) {
|
void PlaylistManager::Save(int id, const QString& filename) {
|
||||||
|
@ -99,6 +99,7 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
void UpdateSummaryText();
|
void UpdateSummaryText();
|
||||||
void SongsDiscovered(const SongList& songs);
|
void SongsDiscovered(const SongList& songs);
|
||||||
|
void LoadFinished(bool success);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Playlist* AddPlaylist(int id, const QString& name);
|
Playlist* AddPlaylist(int id, const QString& name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user