+ if (_write_flat->GetValue()) {
+ Config::instance()->set_last_kdm_write_type (Config::KDM_WRITE_FLAT);
+ } else if (_write_folder->GetValue()) {
+ Config::instance()->set_last_kdm_write_type (Config::KDM_WRITE_FOLDER);
+ } else if (_write_zip->GetValue()) {
+ Config::instance()->set_last_kdm_write_type (Config::KDM_WRITE_ZIP);
+ }
+}
+
+
+pair<shared_ptr<Job>, int>
+KDMOutputPanel::make (
+ list<KDMWithMetadataPtr> kdms, string name, function<bool (boost::filesystem::path)> confirm_overwrite
+ )
+{
+ auto const cinema_kdms = collect (kdms);
+
+ /* Decide whether to proceed */
+
+ bool proceed = true;
+
+ if (_email->GetValue ()) {
+
+ if (Config::instance()->mail_server().empty ()) {
+ proceed = false;
+ error_dialog (this, _("You must set up a mail server in Preferences before you can send emails."));
+ }
+
+ bool const cinemas_with_no_email = std::any_of(
+ cinema_kdms.begin(), cinema_kdms.end(),
+ [](list<KDMWithMetadataPtr> const& list) { return list.front()->emails().empty(); }
+ );
+
+ if (proceed && cinemas_with_no_email && !confirm_dialog (
+ this,
+ _("You have selected some cinemas that have no configured email address. Do you want to continue?")
+ )) {
+ proceed = false;
+ }
+
+ if (proceed && Config::instance()->confirm_kdm_email ()) {
+ list<string> emails;
+ for (auto const& i: cinema_kdms) {
+ for (auto j: i.front()->emails()) {
+ emails.push_back (j);
+ }
+ }
+
+ if (!emails.empty ()) {
+ auto d = new ConfirmKDMEmailDialog (this, emails);
+ if (d->ShowModal() == wxID_CANCEL) {
+ proceed = false;
+ }
+ }
+ }
+ }
+
+ if (!proceed) {
+ return {};
+ }
+
+ Config::instance()->set_kdm_filename_format (_filename_format->get ());
+
+ int written = 0;
+ shared_ptr<Job> job;
+
+ try {
+
+ if (_write_to->GetValue()) {
+ if (_write_flat->GetValue()) {
+ written = write_files (
+ kdms,
+ directory(),
+ _filename_format->get(),
+ confirm_overwrite
+ );
+ } else if (_write_folder->GetValue()) {
+ written = write_directories (
+ collect (kdms),
+ directory(),
+ _container_name_format->get(),
+ _filename_format->get(),
+ confirm_overwrite
+ );
+ } else if (_write_zip->GetValue()) {
+ written = write_zip_files (
+ collect (kdms),
+ directory(),
+ _container_name_format->get(),
+ _filename_format->get(),
+ confirm_overwrite
+ );
+ }
+ }
+
+ if (_email->GetValue ()) {
+ job.reset (
+ new SendKDMEmailJob (
+ cinema_kdms,
+ _container_name_format->get(),
+ _filename_format->get(),
+ name
+ )
+ );
+ }
+
+ } catch (dcp::NotEncryptedError& e) {
+ error_dialog (this, _("CPL's content is not encrypted."));
+ } catch (exception& e) {
+ error_dialog (this, std_to_wx(e.what()));
+ } catch (...) {
+ error_dialog (this, _("An unknown exception occurred."));
+ }
+
+ return make_pair (job, written);