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);
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");
}
}
}
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 ();
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;
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);
}
}
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,
}
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
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);
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);
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;
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);
}
}
, 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;
using std::exception;
using std::list;
+using std::string;
using boost::shared_ptr;
using boost::bind;
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)