2 Copyright (C) 2015-2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "lib/config.h"
22 #include "lib/send_kdm_email_job.h"
23 #include "dkdm_output_panel.h"
24 #include "kdm_timing_panel.h"
25 #include "confirm_kdm_email_dialog.h"
27 #include "name_format_editor.h"
28 #include "check_box.h"
29 #include "dcpomatic_button.h"
30 #include <dcp/exceptions.h>
31 #include <dcp/types.h>
32 #ifdef DCPOMATIC_USE_OWN_PICKER
33 #include "dir_picker_ctrl.h"
35 #include <wx/filepicker.h>
37 #include <wx/stdpaths.h>
44 using boost::shared_ptr;
45 using boost::function;
48 DKDMOutputPanel::DKDMOutputPanel (wxWindow* parent)
49 : wxPanel (parent, wxID_ANY)
51 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, 0);
52 table->AddGrowableCol (1);
54 add_label_to_sizer (table, this, _("Filename format"), true, 0, wxALIGN_TOP | wxTOP | wxLEFT | wxRIGHT);
55 dcp::NameFormat::Map titles;
56 titles['f'] = wx_to_std (_("film name"));
57 titles['b'] = wx_to_std (_("from date/time"));
58 titles['e'] = wx_to_std (_("to date/time"));
59 dcp::NameFormat::Map ex;
61 ex['b'] = "2012/03/15 12:30";
62 ex['e'] = "2012/03/22 02:30";
63 _filename_format = new NameFormatEditor (this, Config::instance()->dkdm_filename_format(), titles, ex, ".xml");
64 table->Add (_filename_format->panel(), 1, wxEXPAND);
66 _write_to = new CheckBox (this, _("Write to"));
67 table->Add (_write_to, 1, wxEXPAND);
69 #ifdef DCPOMATIC_USE_OWN_PICKER
70 _folder = new DirPickerCtrl (this);
72 _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
75 boost::optional<boost::filesystem::path> path = Config::instance()->default_kdm_directory ();
77 _folder->SetPath (std_to_wx (path->string ()));
79 _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
82 table->Add (_folder, 1, wxEXPAND);
84 _email = new CheckBox (this, _("Send by email"));
85 table->Add (_email, 1, wxEXPAND);
88 _write_to->Bind (wxEVT_CHECKBOX, boost::bind(&DKDMOutputPanel::setup_sensitivity, this));
89 _email->Bind (wxEVT_CHECKBOX, boost::bind(&DKDMOutputPanel::setup_sensitivity, this));
96 DKDMOutputPanel::setup_sensitivity ()
98 _folder->Enable (_write_to->GetValue());
102 pair<shared_ptr<Job>, int>
103 DKDMOutputPanel::make (
104 list<KDMWithMetadataPtr> kdms, string name, function<bool (boost::filesystem::path)> confirm_overwrite
107 /* Decide whether to proceed */
111 if (_email->GetValue()) {
113 if (Config::instance()->mail_server().empty()) {
115 error_dialog (this, _("You must set up a mail server in Preferences before you can send emails."));
118 bool kdms_with_no_email = false;
119 BOOST_FOREACH (KDMWithMetadataPtr i, kdms) {
120 if (i->emails().empty()) {
121 kdms_with_no_email = true;
125 if (proceed && kdms_with_no_email && !confirm_dialog (
127 _("You have selected some cinemas that have no configured email address. Do you want to continue?")
132 if (proceed && Config::instance()->confirm_kdm_email()) {
134 BOOST_FOREACH (KDMWithMetadataPtr const& i, kdms) {
135 BOOST_FOREACH (string j, i->emails()) {
136 emails.push_back (j);
140 if (!emails.empty ()) {
141 ConfirmKDMEmailDialog* d = new ConfirmKDMEmailDialog (this, emails);
142 if (d->ShowModal() == wxID_CANCEL) {
150 return make_pair (shared_ptr<Job>(), 0);
153 Config::instance()->set_dkdm_filename_format (_filename_format->get());
159 written = write_files (
162 _filename_format->get(),
166 if (_email->GetValue ()) {
168 new SendKDMEmailJob (
170 _filename_format->get(),
171 _filename_format->get(),
177 } catch (dcp::NotEncryptedError& e) {
178 error_dialog (this, _("CPL's content is not encrypted."));
179 } catch (exception& e) {
180 error_dialog (this, std_to_wx(e.what()));
182 error_dialog (this, _("An unknown exception occurred."));
185 return make_pair (job, written);
189 boost::filesystem::path
190 DKDMOutputPanel::directory () const
192 return wx_to_std (_folder->GetPath ());