mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-03 12:47:31 +01:00
Coding style fixes for async song load.
This commit is contained in:
parent
0d199be5a7
commit
a056a87c8e
@ -113,10 +113,10 @@ SongLoader::Result SongLoader::Load(const QUrl& url) {
|
||||
url_ = PodcastUrlLoader::FixPodcastUrl(url_);
|
||||
|
||||
preload_func_ = std::bind(&SongLoader::LoadRemote, this);
|
||||
return WillLoadAsync;
|
||||
return BlockingLoadRequired;
|
||||
}
|
||||
|
||||
void SongLoader::PreLoad() {
|
||||
void SongLoader::LoadFilenamesBlocking() {
|
||||
if (preload_func_) {
|
||||
preload_func_();
|
||||
}
|
||||
@ -243,7 +243,7 @@ void SongLoader::AudioCDTagsLoaded(
|
||||
song.set_url(QUrl(QString("cdda://%1").arg(track_number++)));
|
||||
songs_ << song;
|
||||
}
|
||||
emit LoadFinished(true);
|
||||
emit LoadAudioCDFinished(true);
|
||||
}
|
||||
|
||||
SongLoader::Result SongLoader::LoadLocal(const QString& filename) {
|
||||
@ -273,7 +273,7 @@ SongLoader::Result SongLoader::LoadLocal(const QString& filename) {
|
||||
// It's not in the database, load it asynchronously.
|
||||
preload_func_ =
|
||||
std::bind(&SongLoader::LoadLocalAsync, this, filename);
|
||||
return WillLoadAsync;
|
||||
return BlockingLoadRequired;
|
||||
}
|
||||
|
||||
void SongLoader::LoadLocalAsync(const QString& filename) {
|
||||
@ -327,7 +327,7 @@ void SongLoader::LoadLocalAsync(const QString& filename) {
|
||||
if (song.is_valid()) songs_ << song;
|
||||
}
|
||||
|
||||
void SongLoader::EffectiveSongsLoad() {
|
||||
void SongLoader::LoadMetadataBlocking() {
|
||||
for (int i = 0; i < songs_.size(); i++) {
|
||||
EffectiveSongLoad(&songs_[i]);
|
||||
}
|
||||
@ -438,7 +438,7 @@ void SongLoader::StopTypefind() {
|
||||
AddAsRawStream();
|
||||
}
|
||||
|
||||
emit LoadFinished(success_);
|
||||
emit LoadRemoteFinished();
|
||||
}
|
||||
|
||||
void SongLoader::LoadRemote() {
|
||||
@ -489,7 +489,7 @@ void SongLoader::LoadRemote() {
|
||||
gst_object_unref(pad);
|
||||
|
||||
QEventLoop loop;
|
||||
loop.connect(this, SIGNAL(LoadFinished(bool)), SLOT(quit()));
|
||||
loop.connect(this, SIGNAL(LoadRemoteFinished()), SLOT(quit()));
|
||||
|
||||
// Start "playing"
|
||||
gst_element_set_state(pipeline.get(), GST_STATE_PLAYING);
|
||||
|
@ -45,7 +45,7 @@ class SongLoader : public QObject {
|
||||
QObject* parent = nullptr);
|
||||
~SongLoader();
|
||||
|
||||
enum Result { Success, Error, WillLoadAsync, };
|
||||
enum Result { Success, Error, BlockingLoadRequired, };
|
||||
|
||||
static const int kDefaultTimeout;
|
||||
|
||||
@ -56,17 +56,21 @@ class SongLoader : public QObject {
|
||||
void set_timeout(int msec) { timeout_ = msec; }
|
||||
|
||||
// If Success is returned the songs are fully loaded. If WillLoadAsync is
|
||||
// returned PreLoad() needs to be called next.
|
||||
// returned LoadFilenamesBlocking() needs to be called next.
|
||||
Result Load(const QUrl& url);
|
||||
// Loads the files with only filenames (blocking) and emits LoadFinished().
|
||||
void PreLoad();
|
||||
// Completely load songs (blocking) previously loaded with PreLoad().
|
||||
void EffectiveSongsLoad();
|
||||
void EffectiveSongLoad(Song* song);
|
||||
// Loads the files with only filenames. When finished, songs() contains a
|
||||
// complete list of all Song objects, but without metadata. This method is
|
||||
// blocking, do not call it from the UI thread.
|
||||
void LoadFilenamesBlocking();
|
||||
// Completely load songs previously loaded with LoadFilenamesBlocking(). When
|
||||
// finished, the Song objects in songs() contain metadata now. This method is
|
||||
// blocking, do not call it from the UI thread.
|
||||
void LoadMetadataBlocking();
|
||||
Result LoadAudioCD();
|
||||
|
||||
signals:
|
||||
void LoadFinished(bool success);
|
||||
void LoadAudioCDFinished(bool success);
|
||||
void LoadRemoteFinished();
|
||||
|
||||
private slots:
|
||||
void Timeout();
|
||||
@ -79,6 +83,7 @@ signals:
|
||||
|
||||
Result LoadLocal(const QString& filename);
|
||||
void LoadLocalAsync(const QString& filename);
|
||||
void EffectiveSongLoad(Song* song);
|
||||
Result LoadLocalPartial(const QString& filename);
|
||||
void LoadLocalDirectory(const QString& filename);
|
||||
void LoadPlaylist(ParserBase* parser, const QString& filename);
|
||||
|
@ -162,7 +162,10 @@ void PlaylistManager::Load(const QString& filename) {
|
||||
|
||||
int id = playlist_backend_->CreatePlaylist(info.baseName(), QString());
|
||||
|
||||
if (id == -1) qFatal("Couldn't create playlist");
|
||||
if (id == -1) {
|
||||
emit Error(tr("Couldn't create playlist"));
|
||||
return;
|
||||
}
|
||||
|
||||
Playlist* playlist = AddPlaylist(id, info.baseName(), QString(), QString(), false);
|
||||
|
||||
|
@ -53,7 +53,7 @@ void SongLoaderInserter::Load(Playlist* destination, int row, bool play_now,
|
||||
|
||||
SongLoader::Result ret = loader->Load(url);
|
||||
|
||||
if (ret == SongLoader::WillLoadAsync) {
|
||||
if (ret == SongLoader::BlockingLoadRequired) {
|
||||
pending_.append(loader);
|
||||
continue;
|
||||
}
|
||||
@ -85,7 +85,7 @@ void SongLoaderInserter::LoadAudioCD(Playlist* destination, int row,
|
||||
enqueue_ = enqueue;
|
||||
|
||||
SongLoader* loader = new SongLoader(library_, player_, this);
|
||||
connect(loader, SIGNAL(LoadFinished(bool)), SLOT(AudioCDTagsLoaded(bool)));
|
||||
connect(loader, SIGNAL(LoadAudioCDFinished(bool)), SLOT(AudioCDTagsLoaded(bool)));
|
||||
qLog(Info) << "Loading audio CD...";
|
||||
SongLoader::Result ret = loader->LoadAudioCD();
|
||||
if (ret == SongLoader::Error) {
|
||||
@ -126,7 +126,7 @@ void SongLoaderInserter::AsyncLoad() {
|
||||
task_manager_->SetTaskProgress(async_load_id, async_progress,
|
||||
pending_.count());
|
||||
for (SongLoader* loader : pending_) {
|
||||
loader->PreLoad();
|
||||
loader->LoadFilenamesBlocking();
|
||||
task_manager_->SetTaskProgress(async_load_id, ++async_progress);
|
||||
songs_ << loader->songs();
|
||||
}
|
||||
@ -139,7 +139,7 @@ void SongLoaderInserter::AsyncLoad() {
|
||||
task_manager_->SetTaskProgress(async_load_id, async_progress, songs_.count());
|
||||
SongList songs;
|
||||
for (SongLoader* loader : pending_) {
|
||||
loader->EffectiveSongsLoad();
|
||||
loader->LoadMetadataBlocking();
|
||||
songs << loader->songs();
|
||||
task_manager_->SetTaskProgress(async_load_id, songs.count());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user