Fix a crash when loading a local directory that contains other directories or playlists.
This commit is contained in:
parent
e95c4979f8
commit
d0699e0bb5
@ -97,7 +97,7 @@ SongLoader::Result SongLoader::LoadLocal(const QString& filename, bool block) {
|
|||||||
// inside right away.
|
// inside right away.
|
||||||
if (QFileInfo(filename).isDir()) {
|
if (QFileInfo(filename).isDir()) {
|
||||||
if (!block) {
|
if (!block) {
|
||||||
QtConcurrent::run(this, &SongLoader::LoadLocalDirectory, filename);
|
QtConcurrent::run(this, &SongLoader::LoadLocalDirectoryAndEmit, filename);
|
||||||
return WillLoadAsync;
|
return WillLoadAsync;
|
||||||
} else {
|
} else {
|
||||||
LoadLocalDirectory(filename);
|
LoadLocalDirectory(filename);
|
||||||
@ -124,7 +124,7 @@ SongLoader::Result SongLoader::LoadLocal(const QString& filename, bool block) {
|
|||||||
|
|
||||||
// It's a playlist!
|
// It's a playlist!
|
||||||
if (!block) {
|
if (!block) {
|
||||||
QtConcurrent::run(this, &SongLoader::LoadPlaylist, parser, filename);
|
QtConcurrent::run(this, &SongLoader::LoadPlaylistAndEmit, parser, filename);
|
||||||
return WillLoadAsync;
|
return WillLoadAsync;
|
||||||
} else {
|
} else {
|
||||||
LoadPlaylist(parser, filename);
|
LoadPlaylist(parser, filename);
|
||||||
@ -149,11 +149,15 @@ SongLoader::Result SongLoader::LoadLocal(const QString& filename, bool block) {
|
|||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SongLoader::LoadPlaylistAndEmit(ParserBase* parser, const QString& filename) {
|
||||||
|
LoadPlaylist(parser, filename);
|
||||||
|
emit LoadFinished(true);
|
||||||
|
}
|
||||||
|
|
||||||
void SongLoader::LoadPlaylist(ParserBase* parser, const QString& filename) {
|
void SongLoader::LoadPlaylist(ParserBase* parser, const QString& filename) {
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
songs_ = parser->Load(&file, QFileInfo(filename).path());
|
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) {
|
||||||
@ -167,6 +171,11 @@ static bool CompareSongs(const Song& left, const Song& right) {
|
|||||||
return left.track() < right.track();
|
return left.track() < right.track();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SongLoader::LoadLocalDirectoryAndEmit(const QString& filename) {
|
||||||
|
LoadLocalDirectory(filename);
|
||||||
|
emit LoadFinished(true);
|
||||||
|
}
|
||||||
|
|
||||||
void SongLoader::LoadLocalDirectory(const QString& filename) {
|
void SongLoader::LoadLocalDirectory(const QString& filename) {
|
||||||
QDirIterator it(filename, QDir::Files | QDir::NoDotAndDotDot | QDir::Readable,
|
QDirIterator it(filename, QDir::Files | QDir::NoDotAndDotDot | QDir::Readable,
|
||||||
QDirIterator::Subdirectories);
|
QDirIterator::Subdirectories);
|
||||||
@ -177,8 +186,6 @@ void SongLoader::LoadLocalDirectory(const QString& filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
qStableSort(songs_.begin(), songs_.end(), CompareSongs);
|
qStableSort(songs_.begin(), songs_.end(), CompareSongs);
|
||||||
|
|
||||||
emit LoadFinished(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SongLoader::AddAsRawStream() {
|
void SongLoader::AddAsRawStream() {
|
||||||
|
@ -73,6 +73,8 @@ private:
|
|||||||
Result LoadLocal(const QString& filename, bool block = false);
|
Result LoadLocal(const QString& filename, bool block = false);
|
||||||
void LoadLocalDirectory(const QString& filename);
|
void LoadLocalDirectory(const QString& filename);
|
||||||
void LoadPlaylist(ParserBase* parser, const QString& filename);
|
void LoadPlaylist(ParserBase* parser, const QString& filename);
|
||||||
|
void LoadLocalDirectoryAndEmit(const QString& filename);
|
||||||
|
void LoadPlaylistAndEmit(ParserBase* parser, const QString& filename);
|
||||||
|
|
||||||
void AddAsRawStream();
|
void AddAsRawStream();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user