summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-10-07 23:31:07 +0100
committerCarl Hetherington <cth@carlh.net>2015-10-09 13:45:00 +0100
commit2852855f19fadb6d7e43282e545a0bcaedc1a3f7 (patch)
tree91618c9da669ad68733e8b12c8fcf555a3e848c3 /src
parentfa8bdd16e1b3742e921b928708614613b6a21036 (diff)
Tweak naming of KDM emails and attachments.
Diffstat (limited to 'src')
-rw-r--r--src/lib/cinema_kdms.cc20
-rw-r--r--src/lib/cinema_kdms.h6
-rw-r--r--src/lib/emailer.cc16
-rw-r--r--src/lib/emailer.h11
-rw-r--r--src/lib/screen_kdm.cc9
-rw-r--r--src/lib/screen_kdm.h4
-rw-r--r--src/tools/dcpomatic_kdm.cc7
7 files changed, 42 insertions, 31 deletions
diff --git a/src/lib/cinema_kdms.cc b/src/lib/cinema_kdms.cc
index 9b839a354..9584a3f23 100644
--- a/src/lib/cinema_kdms.cc
+++ b/src/lib/cinema_kdms.cc
@@ -35,11 +35,8 @@ using std::cout;
using std::string;
using boost::shared_ptr;
-/** @param filename_first_part First part of name of KDM files inside the zip file
- * (perhaps the name of the film).
- */
void
-CinemaKDMs::make_zip_file (string filename_first_part, boost::filesystem::path zip_file) const
+CinemaKDMs::make_zip_file (string film_name, boost::filesystem::path zip_file) const
{
int error;
struct zip* zip = zip_open (zip_file.string().c_str(), ZIP_CREATE | ZIP_EXCL, &error);
@@ -61,7 +58,7 @@ CinemaKDMs::make_zip_file (string filename_first_part, boost::filesystem::path z
throw StringError ("could not create ZIP source");
}
- if (zip_add (zip, i.filename(filename_first_part).c_str(), source) == -1) {
+ if (zip_add (zip, i.filename(film_name).c_str(), source) == -1) {
throw StringError ("failed to add KDM to ZIP archive");
}
}
@@ -107,18 +104,18 @@ CinemaKDMs::collect (list<ScreenKDM> screen_kdms)
}
void
-CinemaKDMs::write_zip_files (string filename_first_part, list<CinemaKDMs> cinema_kdms, boost::filesystem::path directory)
+CinemaKDMs::write_zip_files (string film_name, list<CinemaKDMs> cinema_kdms, boost::filesystem::path directory)
{
BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) {
boost::filesystem::path path = directory;
path /= tidy_for_filename (i.cinema->name) + ".zip";
- i.make_zip_file (filename_first_part, path);
+ i.make_zip_file (film_name, path);
}
}
/* XXX: should probably get from/to from the KDMs themselves */
void
-CinemaKDMs::email (string filename_first_part, string cpl_name, list<CinemaKDMs> cinema_kdms, dcp::LocalTime from, dcp::LocalTime to, shared_ptr<Job> job)
+CinemaKDMs::email (string film_name, string cpl_name, list<CinemaKDMs> cinema_kdms, dcp::LocalTime from, dcp::LocalTime to, shared_ptr<Job> job)
{
Config* config = Config::instance ();
@@ -126,9 +123,7 @@ CinemaKDMs::email (string filename_first_part, string cpl_name, list<CinemaKDMs>
boost::filesystem::path zip_file = boost::filesystem::temp_directory_path ();
zip_file /= boost::filesystem::unique_path().string() + ".zip";
- i.make_zip_file (filename_first_part, zip_file);
-
- /* Send email */
+ i.make_zip_file (film_name, zip_file);
string subject = config->kdm_subject();
SafeStringStream start;
@@ -161,7 +156,8 @@ CinemaKDMs::email (string filename_first_part, string cpl_name, list<CinemaKDMs>
email.add_bcc (config->kdm_bcc ());
}
- email.add_attachment (zip_file, "application/zip");
+ string const name = tidy_for_filename(i.cinema->name) + "_" + tidy_for_filename(film_name) + ".zip";
+ email.add_attachment (zip_file, name, "application/zip");
email.send (job);
}
}
diff --git a/src/lib/cinema_kdms.h b/src/lib/cinema_kdms.h
index ecff32ff4..49f29cc42 100644
--- a/src/lib/cinema_kdms.h
+++ b/src/lib/cinema_kdms.h
@@ -25,12 +25,12 @@ class Job;
class CinemaKDMs
{
public:
- void make_zip_file (std::string name_first_part, boost::filesystem::path zip_file) const;
+ void make_zip_file (std::string film_name, boost::filesystem::path zip_file) const;
static std::list<CinemaKDMs> collect (std::list<ScreenKDM> kdms);
- static void write_zip_files (std::string filename_first_part, std::list<CinemaKDMs> cinema_kdms, boost::filesystem::path directory);
+ static void write_zip_files (std::string film_name, std::list<CinemaKDMs> cinema_kdms, boost::filesystem::path directory);
static void email (
- std::string filename_first_part,
+ std::string film_name,
std::string cpl_name,
std::list<CinemaKDMs> cinema_kdms,
dcp::LocalTime from,
diff --git a/src/lib/emailer.cc b/src/lib/emailer.cc
index 0febb56ab..0193f3605 100644
--- a/src/lib/emailer.cc
+++ b/src/lib/emailer.cc
@@ -61,9 +61,13 @@ Emailer::add_bcc (string bcc)
}
void
-Emailer::add_attachment (boost::filesystem::path attachment, string mime_type)
+Emailer::add_attachment (boost::filesystem::path file, string name, string mime_type)
{
- _attachments.push_back (make_pair (attachment, mime_type));
+ Attachment a;
+ a.file = file;
+ a.name = name;
+ a.mime_type = mime_type;
+ _attachments.push_back (a);
}
static size_t
@@ -129,18 +133,18 @@ Emailer::send (shared_ptr<Job> job)
email << _body;
- for (list<pair<boost::filesystem::path, string> >::const_iterator i = _attachments.begin(); i != _attachments.end(); ++i) {
+ BOOST_FOREACH (Attachment i, _attachments) {
email << "\r\n\r\n--" << boundary << "\r\n"
- << "Content-Type: " << i->second << "; name=" << i->first.leaf() << "\r\n"
+ << "Content-Type: " << i.mime_type << "; name=" << i.name << "\r\n"
<< "Content-Transfer-Encoding: Base64\r\n"
- << "Content-Disposition: attachment; filename=" << i->first.leaf() << "\r\n\r\n";
+ << "Content-Disposition: attachment; filename=" << i.name << "\r\n\r\n";
BIO* b64 = BIO_new (BIO_f_base64());
BIO* bio = BIO_new (BIO_s_mem());
bio = BIO_push (b64, bio);
- Data data (i->first);
+ Data data (i.file);
BIO_write (bio, data.data().get(), data.size());
(void) BIO_flush (bio);
diff --git a/src/lib/emailer.h b/src/lib/emailer.h
index 4b4d1f6f7..9e6fca5b0 100644
--- a/src/lib/emailer.h
+++ b/src/lib/emailer.h
@@ -27,7 +27,7 @@ public:
void add_cc (std::string cc);
void add_bcc (std::string bcc);
- void add_attachment (boost::filesystem::path attachment, std::string);
+ void add_attachment (boost::filesystem::path file, std::string name, std::string mime_type);
void send (boost::shared_ptr<Job> job);
@@ -44,7 +44,14 @@ private:
std::string _body;
std::list<std::string> _cc;
std::list<std::string> _bcc;
- std::list<std::pair<boost::filesystem::path, std::string> > _attachments;
+
+ struct Attachment {
+ boost::filesystem::path file;
+ std::string name;
+ std::string mime_type;
+ };
+
+ std::list<Attachment> _attachments;
std::string _email;
size_t _offset;
boost::scoped_array<char> _notes_buffer;
diff --git a/src/lib/screen_kdm.cc b/src/lib/screen_kdm.cc
index 60a81399d..bbe539801 100644
--- a/src/lib/screen_kdm.cc
+++ b/src/lib/screen_kdm.cc
@@ -33,19 +33,18 @@ operator== (ScreenKDM const & a, ScreenKDM const & b)
return a.screen == b.screen && a.kdm == b.kdm;
}
-/** @param first_part first part of the filename (perhaps the name of the film) */
string
-ScreenKDM::filename (string first_part) const
+ScreenKDM::filename (string film_name) const
{
- return tidy_for_filename (first_part) + "_" + tidy_for_filename (screen->cinema->name) + "_" + tidy_for_filename (screen->name) + ".kdm.xml";
+ return tidy_for_filename (film_name) + "_" + tidy_for_filename (screen->cinema->name) + "_" + tidy_for_filename (screen->name) + ".kdm.xml";
}
void
-ScreenKDM::write_files (string name_first_part, list<ScreenKDM> screen_kdms, boost::filesystem::path directory)
+ScreenKDM::write_files (string film_name, list<ScreenKDM> screen_kdms, boost::filesystem::path directory)
{
/* Write KDMs to the specified directory */
BOOST_FOREACH (ScreenKDM const & i, screen_kdms) {
- boost::filesystem::path out = directory / i.filename(name_first_part);
+ boost::filesystem::path out = directory / i.filename(film_name);
i.kdm.as_xml (out);
}
}
diff --git a/src/lib/screen_kdm.h b/src/lib/screen_kdm.h
index e2a16d3b7..6230ea091 100644
--- a/src/lib/screen_kdm.h
+++ b/src/lib/screen_kdm.h
@@ -34,9 +34,9 @@ public:
, kdm (k)
{}
- std::string filename (std::string first_part) const;
+ std::string filename (std::string film_name) const;
- static void write_files (std::string name_first_part, std::list<ScreenKDM> screen_kdms, boost::filesystem::path directory);
+ static void write_files (std::string film_name, std::list<ScreenKDM> screen_kdms, boost::filesystem::path directory);
boost::shared_ptr<Screen> screen;
dcp::EncryptedKDM kdm;
diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc
index bc58be914..351c61750 100644
--- a/src/tools/dcpomatic_kdm.cc
+++ b/src/tools/dcpomatic_kdm.cc
@@ -50,6 +50,7 @@
using std::exception;
using std::list;
+using std::string;
using boost::shared_ptr;
using boost::bind;
@@ -273,8 +274,12 @@ private:
wxString::Format (s, int(screen_kdms.size()), std_to_wx(_output->directory().string()).data())
);
} else {
+ string film_name = decrypted.annotation_text ();
+ if (film_name.empty ()) {
+ film_name = decrypted.content_title_text ();
+ }
shared_ptr<Job> job (new SendKDMEmailJob (
- decrypted.annotation_text(),
+ film_name,
decrypted.content_title_text(),
_timing->from(), _timing->until(),
CinemaKDMs::collect (screen_kdms)