diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-03-07 23:33:03 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-03-07 23:33:03 +0100 |
| commit | 04b5957318df591f56e0a5d39720df143dc8230d (patch) | |
| tree | d241c7d2008e2dad80c989ea2539998b11b12717 /src | |
| parent | 9bebb9724c5b7f254e3cea62a5cdb3c5e0e8571e (diff) | |
Fix screen name order in KDM emails.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/kdm_with_metadata.cc | 9 | ||||
| -rw-r--r-- | src/lib/util.cc | 28 | ||||
| -rw-r--r-- | src/lib/util.h | 1 |
3 files changed, 33 insertions, 5 deletions
diff --git a/src/lib/kdm_with_metadata.cc b/src/lib/kdm_with_metadata.cc index 971eeac76..f7ff84435 100644 --- a/src/lib/kdm_with_metadata.cc +++ b/src/lib/kdm_with_metadata.cc @@ -238,14 +238,13 @@ send_emails ( auto subject = substitute_variables(config->kdm_subject()); auto body = substitute_variables(config->kdm_email()); - string screens; + vector<string> screens; for (auto kdm: kdms_for_cinema) { - auto screen_name = kdm->get('s'); - if (screen_name) { - screens += *screen_name + ", "; + if (auto screen_name = kdm->get('s')) { + screens.push_back(*screen_name); } } - boost::algorithm::replace_all (body, "$SCREENS", screens.substr (0, screens.length() - 2)); + boost::algorithm::replace_all(body, "$SCREENS", screen_names_to_string(screens)); auto emails = first->emails(); std::copy(extra_addresses.begin(), extra_addresses.end(), std::back_inserter(emails)); diff --git a/src/lib/util.cc b/src/lib/util.cc index 7f6e9da5a..fe6602de3 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1123,3 +1123,31 @@ word_wrap(string input, int columns) return output; } + +string +screen_names_to_string(vector<string> names) +{ + if (names.empty()) { + return {}; + } + + auto number = [](string const& s) { + return s.find_first_not_of("0123456789") == string::npos; + }; + + if (std::find_if(names.begin(), names.end(), [number](string const& s) { return !number(s); }) == names.end()) { + std::sort(names.begin(), names.end(), [](string const& a, string const& b) { + return dcp::raw_convert<int>(a) < dcp::raw_convert<int>(b); + }); + } else { + std::sort(names.begin(), names.end()); + } + + string result; + for (auto const& name: names) { + result += name + ", "; + } + + return result.substr(0, result.length() - 2); +} + diff --git a/src/lib/util.h b/src/lib/util.h index b92869b25..fd6fd6164 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -97,5 +97,6 @@ extern std::string error_details(boost::system::error_code ec); extern bool contains_assetmap(boost::filesystem::path dir); extern std::string word_wrap(std::string input, int columns); extern void capture_ffmpeg_logs(); +extern std::string screen_names_to_string(std::vector<std::string> names); #endif |
