Add $CINEMA_SHORT_NAME variable in KDM emails.
[dcpomatic.git] / src / lib / kdm_with_metadata.cc
index fbd2e4bd49e7d417849159c46653a67c978d2416..857fdca2c01c9590373c4fa286fd641cb0bf3562 100644 (file)
 */
 
 
-#include "kdm_with_metadata.h"
 #include "cinema.h"
-#include "screen.h"
-#include "util.h"
-#include "zipper.h"
 #include "config.h"
+#include "cross.h"
 #include "dcpomatic_log.h"
 #include "emailer.h"
-#include <boost/function.hpp>
-#include <boost/function.hpp>
+#include "kdm_with_metadata.h"
+#include "screen.h"
+#include "util.h"
+#include "zipper.h"
 
 #include "i18n.h"
 
 
-using std::string;
 using std::cout;
+using std::function;
 using std::list;
 using std::shared_ptr;
+using std::string;
 using boost::optional;
-using boost::function;
 
 
 int
@@ -46,7 +45,7 @@ write_files (
        list<KDMWithMetadataPtr> kdms,
        boost::filesystem::path directory,
        dcp::NameFormat name_format,
-       boost::function<bool (boost::filesystem::path)> confirm_overwrite
+       std::function<bool (boost::filesystem::path)> confirm_overwrite
        )
 {
        int written = 0;
@@ -67,7 +66,7 @@ write_files (
 
        /* Write KDMs to the specified directory */
        for (auto i: kdms) {
-               auto out = directory / careful_string_filter(name_format.get(i->name_values(), ".xml"));
+               auto out = fix_long_path(directory / careful_string_filter(name_format.get(i->name_values(), ".xml")));
                if (!boost::filesystem::exists (out) || confirm_overwrite (out)) {
                        i->kdm_as_xml (out);
                        ++written;
@@ -147,7 +146,7 @@ write_directories (
        int written = 0;
 
        for (auto const& i: kdms) {
-               boost::filesystem::path path = directory;
+               auto path = directory;
                path /= container_name_format.get(i.front()->name_values(), "", "s");
                if (!boost::filesystem::exists (path) || confirm_overwrite (path)) {
                        boost::filesystem::create_directories (path);
@@ -197,7 +196,7 @@ write_zip_files (
  *  @param cpl_name Name of the CPL that the KDMs are for.
  */
 void
-email (
+send_emails (
        list<list<KDMWithMetadataPtr>> kdms,
        dcp::NameFormat container_name_format,
        dcp::NameFormat filename_format,
@@ -221,21 +220,21 @@ email (
                zip_file /= container_name_format.get(i.front()->name_values(), ".zip");
                make_zip_file (i, zip_file, filename_format);
 
-               auto subject = config->kdm_subject();
-               boost::algorithm::replace_all (subject, "$CPL_NAME", cpl_name);
-               boost::algorithm::replace_all (subject, "$START_TIME", i.front()->get('b').get_value_or(""));
-               boost::algorithm::replace_all (subject, "$END_TIME", i.front()->get('e').get_value_or(""));
-               boost::algorithm::replace_all (subject, "$CINEMA_NAME", i.front()->get('c').get_value_or(""));
+               auto substitute_variables = [cpl_name, i](string target) {
+                       boost::algorithm::replace_all (target, "$CPL_NAME", cpl_name);
+                       boost::algorithm::replace_all (target, "$START_TIME", i.front()->get('b').get_value_or(""));
+                       boost::algorithm::replace_all (target, "$END_TIME", i.front()->get('e').get_value_or(""));
+                       boost::algorithm::replace_all (target, "$CINEMA_NAME", i.front()->get('c').get_value_or(""));
+                       boost::algorithm::replace_all (target, "$CINEMA_SHORT_NAME", i.front()->get('c').get_value_or("").substr(0, 14));
+                       return target;
+               };
 
-               auto body = config->kdm_email();
-               boost::algorithm::replace_all (body, "$CPL_NAME", cpl_name);
-               boost::algorithm::replace_all (body, "$START_TIME", i.front()->get('b').get_value_or(""));
-               boost::algorithm::replace_all (body, "$END_TIME", i.front()->get('e').get_value_or(""));
-               boost::algorithm::replace_all (body, "$CINEMA_NAME", i.front()->get('c').get_value_or(""));
+               auto subject = substitute_variables(config->kdm_subject());
+               auto body = substitute_variables(config->kdm_email());
 
                string screens;
                for (auto j: i) {
-                       auto screen_name = j->get('n');
+                       auto screen_name = j->get('s');
                        if (screen_name) {
                                screens += *screen_name + ", ";
                        }