Load XSPF title as playlist name

This commit is contained in:
Jonas Kvinge
2025-01-04 04:52:17 +01:00
parent e2a928f2dc
commit bf98633f16
25 changed files with 87 additions and 53 deletions

View File

@@ -1180,7 +1180,11 @@ void Playlist::InsertSongs(const SongList &songs, const int pos, const bool play
InsertSongItems<SongPlaylistItem>(songs, pos, play_now, enqueue, enqueue_next);
}
void Playlist::InsertSongsOrCollectionItems(const SongList &songs, const int pos, const bool play_now, const bool enqueue, const bool enqueue_next) {
void Playlist::InsertSongsOrCollectionItems(const SongList &songs, const QString &playlist_name, const int pos, const bool play_now, const bool enqueue, const bool enqueue_next) {
if (!playlist_name.isEmpty()) {
Q_EMIT Rename(id_, playlist_name);
}
PlaylistItemPtrList items;
for (const Song &song : songs) {
@@ -1201,6 +1205,7 @@ void Playlist::InsertSongsOrCollectionItems(const SongList &songs, const int pos
}
}
}
InsertItems(items, pos, play_now, enqueue, enqueue_next);
}

View File

@@ -226,7 +226,7 @@ class Playlist : public QAbstractListModel {
void InsertItems(const PlaylistItemPtrList &itemsIn, const int pos = -1, const bool play_now = false, const bool enqueue = false, const bool enqueue_next = false);
void InsertCollectionItems(const SongList &songs, const int pos = -1, const bool play_now = false, const bool enqueue = false, const bool enqueue_next = false);
void InsertSongs(const SongList &songs, const int pos = -1, const bool play_now = false, const bool enqueue = false, const bool enqueue_next = false);
void InsertSongsOrCollectionItems(const SongList &songs, const int pos = -1, const bool play_now = false, const bool enqueue = false, const bool enqueue_next = false);
void InsertSongsOrCollectionItems(const SongList &songs, const QString &playlist_name = QString(), const int pos = -1, const bool play_now = false, const bool enqueue = false, const bool enqueue_next = false);
void InsertSmartPlaylist(PlaylistGeneratorPtr gen, const int pos = -1, const bool play_now = false, const bool enqueue = false, const bool enqueue_next = false);
void InsertStreamingItems(StreamingServicePtr service, const SongList &songs, const int pos = -1, const bool play_now = false, const bool enqueue = false, const bool enqueue_next = false);
void InsertRadioItems(const SongList &songs, const int pos = -1, const bool play_now = false, const bool enqueue = false, const bool enqueue_next = false);
@@ -327,6 +327,8 @@ class Playlist : public QAbstractListModel {
// Signals that the queue has changed, meaning that the remaining queued items should update their position.
void QueueChanged();
void Rename(const int id, const QString &name);
private:
void SetCurrentIsPaused(const bool paused);
int NextVirtualIndex(int i, const bool ignore_repeat_track) const;

View File

@@ -298,7 +298,7 @@ PlaylistItemPtr PlaylistBackend::RestoreCueData(PlaylistItemPtr item, SharedPtr<
return item;
}
SongList song_list;
SongList songs;
{
QMutexLocker locker(&state->mutex_);
@@ -306,16 +306,16 @@ PlaylistItemPtr PlaylistBackend::RestoreCueData(PlaylistItemPtr item, SharedPtr<
QFile cue_file(cue_path);
if (!cue_file.open(QIODevice::ReadOnly)) return item;
song_list = cue_parser.Load(&cue_file, cue_path, QDir(cue_path.section(u'/', 0, -2)));
songs = cue_parser.Load(&cue_file, cue_path, QDir(cue_path.section(u'/', 0, -2))).songs;
cue_file.close();
state->cached_cues_[cue_path] = song_list;
state->cached_cues_[cue_path] = songs;
}
else {
song_list = state->cached_cues_[cue_path];
songs = state->cached_cues_[cue_path];
}
}
for (const Song &from_list : std::as_const(song_list)) {
for (const Song &from_list : std::as_const(songs)) {
if (from_list.url().toEncoded() == song.url().toEncoded() && from_list.beginning_nanosec() == song.beginning_nanosec()) {
// We found a matching section; replace the input item with a new one containing CUE metadata
return make_shared<SongPlaylistItem>(from_list);

View File

@@ -166,6 +166,7 @@ Playlist *PlaylistManager::AddPlaylist(const int id, const QString &name, const
QObject::connect(ret, &Playlist::EditingFinished, this, &PlaylistManager::EditingFinished);
QObject::connect(ret, &Playlist::Error, this, &PlaylistManager::Error);
QObject::connect(ret, &Playlist::PlayRequested, this, &PlaylistManager::PlayRequested);
QObject::connect(ret, &Playlist::Rename, this, &PlaylistManager::Rename);
QObject::connect(playlist_container_->view(), &PlaylistView::ColumnAlignmentChanged, ret, &Playlist::SetColumnAlignment);
QObject::connect(&*current_albumcover_loader_, &CurrentAlbumCoverLoader::AlbumCoverLoaded, ret, &Playlist::AlbumCoverLoaded);
@@ -208,7 +209,7 @@ void PlaylistManager::Load(const QString &filename) {
QFileInfo fileinfo(filename);
int id = playlist_backend_->CreatePlaylist(fileinfo.completeBaseName(), QString());
const int id = playlist_backend_->CreatePlaylist(fileinfo.completeBaseName(), QString());
if (id == -1) {
Q_EMIT Error(tr("Couldn't create playlist"));

View File

@@ -54,7 +54,7 @@ SongLoaderInserter::SongLoaderInserter(const SharedPtr<TaskManager> task_manager
SongLoaderInserter::~SongLoaderInserter() { qDeleteAll(pending_); }
void SongLoaderInserter::Load(Playlist *destination, int row, bool play_now, bool enqueue, bool enqueue_next, const QList<QUrl> &urls) {
void SongLoaderInserter::Load(Playlist *destination, const int row, const bool play_now, const bool enqueue, const bool enqueue_next, const QList<QUrl> &urls) {
destination_ = destination;
row_ = row;
@@ -69,15 +69,16 @@ void SongLoaderInserter::Load(Playlist *destination, int row, bool play_now, boo
for (const QUrl &url : urls) {
SongLoader *loader = new SongLoader(url_handlers_, collection_backend_, tagreader_client_, this);
SongLoader::Result ret = loader->Load(url);
const SongLoader::Result result = loader->Load(url);
if (ret == SongLoader::Result::BlockingLoadRequired) {
if (result == SongLoader::Result::BlockingLoadRequired) {
pending_.append(loader);
continue;
}
if (ret == SongLoader::Result::Success) {
if (result == SongLoader::Result::Success) {
songs_ << loader->songs();
playlist_name_ = loader->playlist_name();
}
else {
const QStringList errors = loader->errors();
@@ -101,7 +102,7 @@ void SongLoaderInserter::Load(Playlist *destination, int row, bool play_now, boo
// First, we add tracks (without metadata) into the playlist
// In the meantime, MusicBrainz will be queried to get songs' metadata.
// AudioCDTagsLoaded will be called next, and playlist's items will be updated.
void SongLoaderInserter::LoadAudioCD(Playlist *destination, int row, bool play_now, bool enqueue, bool enqueue_next) {
void SongLoaderInserter::LoadAudioCD(Playlist *destination, const int row, const bool play_now, const bool enqueue, const bool enqueue_next) {
destination_ = destination;
row_ = row;
@@ -113,8 +114,8 @@ void SongLoaderInserter::LoadAudioCD(Playlist *destination, int row, bool play_n
QObject::connect(loader, &SongLoader::AudioCDTracksLoadFinished, this, [this, loader]() { AudioCDTracksLoadFinished(loader); });
QObject::connect(loader, &SongLoader::LoadAudioCDFinished, this, &SongLoaderInserter::AudioCDTagsLoaded);
qLog(Info) << "Loading audio CD...";
SongLoader::Result ret = loader->LoadAudioCD();
if (ret == SongLoader::Result::Error) {
const SongLoader::Result result = loader->LoadAudioCD();
if (result == SongLoader::Result::Error) {
if (loader->errors().isEmpty())
Q_EMIT Error(tr("Error while loading audio CD."));
else {
@@ -166,7 +167,7 @@ void SongLoaderInserter::InsertSongs() {
// Insert songs (that haven't been completely loaded) to allow user to see and play them while not loaded completely
if (destination_) {
destination_->InsertSongsOrCollectionItems(songs_, row_, play_now_, enqueue_, enqueue_next_);
destination_->InsertSongsOrCollectionItems(songs_, playlist_name_, row_, play_now_, enqueue_, enqueue_next_);
}
}
@@ -180,10 +181,10 @@ void SongLoaderInserter::AsyncLoad() {
bool first_loaded = false;
for (int i = 0; i < pending_.count(); ++i) {
SongLoader *loader = pending_.value(i);
SongLoader::Result res = loader->LoadFilenamesBlocking();
const SongLoader::Result result = loader->LoadFilenamesBlocking();
task_manager_->SetTaskProgress(async_load_id, ++async_progress);
if (res == SongLoader::Result::Error) {
if (result == SongLoader::Result::Error) {
const QStringList errors = loader->errors();
for (const QString &error : errors) {
Q_EMIT Error(error);
@@ -199,6 +200,7 @@ void SongLoaderInserter::AsyncLoad() {
}
songs_ << loader->songs();
playlist_name_ = loader->playlist_name();
}
task_manager_->SetTaskFinished(async_load_id);

View File

@@ -52,8 +52,8 @@ class SongLoaderInserter : public QObject {
~SongLoaderInserter() override;
void Load(Playlist *destination, int row, bool play_now, bool enqueue, bool enqueue_next, const QList<QUrl> &urls);
void LoadAudioCD(Playlist *destination, int row, bool play_now, bool enqueue, bool enqueue_next);
void Load(Playlist *destination, const int row, const bool play_now, const bool enqueue, const bool enqueue_next, const QList<QUrl> &urls);
void LoadAudioCD(Playlist *destination, const int row, const bool play_now, const bool enqueue, const bool enqueue_next);
Q_SIGNALS:
void Error(const QString &message);
@@ -82,6 +82,7 @@ class SongLoaderInserter : public QObject {
bool enqueue_next_;
SongList songs_;
QString playlist_name_;
QList<SongLoader*> pending_;
};