From 2e921c6584b5c3dcf41845fb7255b1e4b078887e Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Fri, 5 Jun 2020 23:49:22 -0700 Subject: [PATCH] organise: Add a tag override mechanism to OrganiseFormat Add a method to set override tag values when formatting a song name. The use case for this is transcoding where the extension will change. --- src/core/organiseformat.cpp | 6 +++--- src/core/organiseformat.h | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/organiseformat.cpp b/src/core/organiseformat.cpp index 2dcddeb25..844e64400 100644 --- a/src/core/organiseformat.cpp +++ b/src/core/organiseformat.cpp @@ -179,9 +179,9 @@ QString OrganiseFormat::ParseBlock(QString block, const Song& song, QString OrganiseFormat::TagValue(const QString& tag, const Song& song) const { QString value; - // TODO(sobkas): What about nice switch statement? - - if (tag == "title") + if (tag_overrides_.contains(tag)) + value = tag_overrides_.value(tag); + else if (tag == "title") value = song.title(); else if (tag == "album") value = song.album(); diff --git a/src/core/organiseformat.h b/src/core/organiseformat.h index 77005794c..4fd95f61c 100644 --- a/src/core/organiseformat.h +++ b/src/core/organiseformat.h @@ -48,6 +48,11 @@ class OrganiseFormat { void set_replace_spaces(bool v) { replace_spaces_ = v; } void set_replace_the(bool v) { replace_the_ = v; } + void add_tag_override(const QString& tag, const QString& v) { + tag_overrides_[tag] = v; + } + void reset_tag_overrides() { tag_overrides_.clear(); } + bool IsValid() const; QString GetFilenameForSong(const Song& song) const; @@ -77,6 +82,8 @@ class OrganiseFormat { bool* any_empty = nullptr) const; QString TagValue(const QString& tag, const Song& song) const; + QMap tag_overrides_; + QString format_; bool replace_non_ascii_; bool replace_spaces_;