From fbe2784c136fa1550815babfce89589f66b35a29 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 29 Jul 2016 16:21:40 +0100 Subject: [PATCH] Simplification of name format stuff. --- cscript | 2 +- src/lib/cinema_kdms.cc | 20 ++++++++++---------- src/lib/kdm_name_format.cc | 15 ++++++++++----- src/lib/screen_kdm.cc | 4 ++-- src/lib/send_kdm_email_job.cc | 2 +- src/lib/util.cc | 8 ++++---- src/tools/dcpomatic_kdm.cc | 6 +++--- src/tools/dcpomatic_kdm_cli.cc | 6 +++--- src/wx/config_dialog.cc | 12 +++++++----- src/wx/kdm_dialog.cc | 6 +++--- src/wx/kdm_output_panel.cc | 21 +++++++++++++-------- src/wx/name_format_editor.h | 19 +++++++------------ 12 files changed, 64 insertions(+), 57 deletions(-) diff --git a/cscript b/cscript index 1081f661d..2ce672385 100644 --- a/cscript +++ b/cscript @@ -237,7 +237,7 @@ def dependencies(target): ffmpeg_options = {} return (('ffmpeg-cdist', '1d4a1a4', ffmpeg_options), - ('libdcp', 'e02bf26'), + ('libdcp', '7e9ad08'), ('libsub', '067c21c')) def configure_options(target): diff --git a/src/lib/cinema_kdms.cc b/src/lib/cinema_kdms.cc index cbfad4bb3..c50578734 100644 --- a/src/lib/cinema_kdms.cc +++ b/src/lib/cinema_kdms.cc @@ -53,7 +53,7 @@ CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, KDMNameFormat name_ list > kdm_strings; - name_values["cinema"] = cinema->name; + name_values['c'] = cinema->name; BOOST_FOREACH (ScreenKDM const & i, screen_kdms) { shared_ptr kdm (new string (i.kdm.as_xml ())); @@ -64,7 +64,7 @@ CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, KDMNameFormat name_ throw runtime_error ("could not create ZIP source"); } - name_values["screen"] = i.screen->name; + name_values['s'] = i.screen->name; string const name = name_format.get(name_values) + ".xml"; if (zip_add (zip, name.c_str(), source) == -1) { throw runtime_error ("failed to add KDM to ZIP archive"); @@ -124,11 +124,11 @@ CinemaKDMs::write_zip_files ( ) { /* No specific screen */ - name_values["screen"] = ""; + name_values['s'] = ""; BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) { boost::filesystem::path path = directory; - name_values["cinema"] = i.cinema->name; + name_values['c'] = i.cinema->name; path /= name_format.get(name_values) + ".zip"; i.make_zip_file (path, name_format, name_values); } @@ -153,11 +153,11 @@ CinemaKDMs::email ( } /* No specific screen */ - name_values["screen"] = ""; + name_values['s'] = ""; BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) { - name_values["cinema"] = i.cinema->name; + name_values['c'] = i.cinema->name; boost::filesystem::path zip_file = boost::filesystem::temp_directory_path (); zip_file /= boost::filesystem::unique_path().string() + ".zip"; @@ -165,14 +165,14 @@ CinemaKDMs::email ( string subject = config->kdm_subject(); boost::algorithm::replace_all (subject, "$CPL_NAME", cpl_name); - boost::algorithm::replace_all (subject, "$START_TIME", name_values["from"]); - boost::algorithm::replace_all (subject, "$END_TIME", name_values["to"]); + boost::algorithm::replace_all (subject, "$START_TIME", name_values['f']); + boost::algorithm::replace_all (subject, "$END_TIME", name_values['t']); boost::algorithm::replace_all (subject, "$CINEMA_NAME", i.cinema->name); string body = config->kdm_email().c_str(); boost::algorithm::replace_all (body, "$CPL_NAME", cpl_name); - boost::algorithm::replace_all (body, "$START_TIME", name_values["from"]); - boost::algorithm::replace_all (body, "$END_TIME", name_values["to"]); + boost::algorithm::replace_all (body, "$START_TIME", name_values['f']); + boost::algorithm::replace_all (body, "$END_TIME", name_values['t']); boost::algorithm::replace_all (body, "$CINEMA_NAME", i.cinema->name); locked_stringstream screens; diff --git a/src/lib/kdm_name_format.cc b/src/lib/kdm_name_format.cc index fe4a3fc62..bf17acbf1 100644 --- a/src/lib/kdm_name_format.cc +++ b/src/lib/kdm_name_format.cc @@ -25,9 +25,14 @@ using std::string; KDMNameFormat::KDMNameFormat (string specification) : NameFormat (specification) { - add ("film_name", 'f', "film name"); - add ("cinema", 'c', "cinema"); - add ("screen", 's', "screen"); - add ("from", 'b', "from date/time"); - add ("to", 'e', "to date/time"); + /* film name */ + add ('f'); + /* cinema */ + add ('c'); + /* screen */ + add ('s'); + /* from date/time */ + add ('b'); + /* to date/time */ + add ('e'); } diff --git a/src/lib/screen_kdm.cc b/src/lib/screen_kdm.cc index 22081fc81..3290d2a68 100644 --- a/src/lib/screen_kdm.cc +++ b/src/lib/screen_kdm.cc @@ -39,8 +39,8 @@ ScreenKDM::write_files (list screen_kdms, boost::filesystem::path dir { /* Write KDMs to the specified directory */ BOOST_FOREACH (ScreenKDM const & i, screen_kdms) { - name_values["cinema"] = i.screen->cinema->name; - name_values["screen"] = i.screen->name; + name_values['c'] = i.screen->cinema->name; + name_values['s'] = i.screen->name; boost::filesystem::path out = directory / (name_format.get(name_values) + ".xml"); i.kdm.as_xml (out); } diff --git a/src/lib/send_kdm_email_job.cc b/src/lib/send_kdm_email_job.cc index 3bf1887f4..e4b20167e 100644 --- a/src/lib/send_kdm_email_job.cc +++ b/src/lib/send_kdm_email_job.cc @@ -51,7 +51,7 @@ SendKDMEmailJob::SendKDMEmailJob ( string SendKDMEmailJob::name () const { - dcp::NameFormat::Map::const_iterator i = _name_values.find ("film_name"); + dcp::NameFormat::Map::const_iterator i = _name_values.find ('f'); if (i == _name_values.end() || i->second.empty ()) { return _("Email KDMs"); } diff --git a/src/lib/util.cc b/src/lib/util.cc index 09f32dfda..59974c24c 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -620,8 +620,8 @@ string video_asset_filename (shared_ptr asset) { dcp::NameFormat::Map values; - values["type"] = "j2c"; - values["id"] = asset->id(); + values['t'] = "j2c"; + values['i'] = asset->id(); return Config::instance()->dcp_filename_format().get(values) + ".mxf"; } @@ -629,8 +629,8 @@ string audio_asset_filename (shared_ptr asset) { dcp::NameFormat::Map values; - values["type"] = "pcm"; - values["id"] = asset->id(); + values['t'] = "pcm"; + values['i'] = asset->id(); return Config::instance()->dcp_filename_format().get(values) + ".mxf"; } diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc index 01f8ef0a3..362d8105f 100644 --- a/src/tools/dcpomatic_kdm.cc +++ b/src/tools/dcpomatic_kdm.cc @@ -298,9 +298,9 @@ private: } dcp::NameFormat::Map name_values; - name_values["film_name"] = decrypted.content_title_text(); - name_values["from"] = dcp::LocalTime(_timing->from()).date() + " " + dcp::LocalTime(_timing->from()).time_of_day(); - name_values["to"] = dcp::LocalTime(_timing->until()).date() + " " + dcp::LocalTime(_timing->until()).time_of_day(); + name_values['f'] = decrypted.content_title_text(); + name_values['b'] = dcp::LocalTime(_timing->from()).date() + " " + dcp::LocalTime(_timing->from()).time_of_day(); + name_values['e'] = dcp::LocalTime(_timing->until()).date() + " " + dcp::LocalTime(_timing->until()).time_of_day(); if (_output->write_to()) { ScreenKDM::write_files (screen_kdms, _output->directory(), _output->name_format(), name_values); diff --git a/src/tools/dcpomatic_kdm_cli.cc b/src/tools/dcpomatic_kdm_cli.cc index 38808596e..de89a9c7c 100644 --- a/src/tools/dcpomatic_kdm_cli.cc +++ b/src/tools/dcpomatic_kdm_cli.cc @@ -285,9 +285,9 @@ int main (int argc, char* argv[]) } dcp::NameFormat::Map values; - values["film_name"] = film->name(); - values["from"] = dcp::LocalTime(valid_from.get()).date() + " " + dcp::LocalTime(valid_from.get()).time_of_day(); - values["to"] = dcp::LocalTime(valid_to.get()).date() + " " + dcp::LocalTime(valid_to.get()).time_of_day(); + values['f'] = film->name(); + values['b'] = dcp::LocalTime(valid_from.get()).date() + " " + dcp::LocalTime(valid_from.get()).time_of_day(); + values['e'] = dcp::LocalTime(valid_to.get()).date() + " " + dcp::LocalTime(valid_to.get()).time_of_day(); try { list screen_kdms = film->make_kdms ( diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index c82956c60..a68f4576d 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -1410,11 +1410,13 @@ private: table->Add (m, 0, flags, DCPOMATIC_SIZER_Y_GAP); } - _dcp_filename_format = new NameFormatEditor (_panel, Config::instance()->dcp_filename_format()); - dcp::NameFormat::Map example; - example["type"] = "j2c"; - example["id"] = "eb1c112c-ca3c-4ae6-9263-c6714ff05d64"; - _dcp_filename_format->set_example (example); + dcp::NameFormat::Map titles; + titles['t'] = "type (j2c/pcm/sub/cpl/pkl)"; + titles['i'] = "unique ID"; + dcp::NameFormat::Map examples; + examples['t'] = "j2c"; + examples['i'] = "eb1c112c-ca3c-4ae6-9263-c6714ff05d64"; + _dcp_filename_format = new NameFormatEditor (_panel, Config::instance()->dcp_filename_format(), titles, examples); table->Add (_dcp_filename_format->panel(), 1, wxEXPAND | wxALL); #ifdef __WXOSX__ diff --git a/src/wx/kdm_dialog.cc b/src/wx/kdm_dialog.cc index cd018686e..ef7912ee3 100644 --- a/src/wx/kdm_dialog.cc +++ b/src/wx/kdm_dialog.cc @@ -134,9 +134,9 @@ KDMDialog::make_clicked () ); dcp::NameFormat::Map name_values; - name_values["film_name"] = film->name(); - name_values["from"] = dcp::LocalTime(_timing->from()).date() + " " + dcp::LocalTime(_timing->from()).time_of_day(); - name_values["to"] = dcp::LocalTime(_timing->until()).date() + " " + dcp::LocalTime(_timing->until()).time_of_day(); + name_values['f'] = film->name(); + name_values['b'] = dcp::LocalTime(_timing->from()).date() + " " + dcp::LocalTime(_timing->from()).time_of_day(); + name_values['e'] = dcp::LocalTime(_timing->until()).date() + " " + dcp::LocalTime(_timing->until()).time_of_day(); if (_output->write_to ()) { ScreenKDM::write_files ( diff --git a/src/wx/kdm_output_panel.cc b/src/wx/kdm_output_panel.cc index 1d9e56f4b..4efb9fb27 100644 --- a/src/wx/kdm_output_panel.cc +++ b/src/wx/kdm_output_panel.cc @@ -46,7 +46,7 @@ KDMOutputPanel::KDMOutputPanel (wxWindow* parent, bool interop) _type->SetSelection (0); { - int flags = wxALIGN_TOP | wxTOP | wxLEFT; + int flags = wxALIGN_TOP | wxTOP | wxLEFT | wxRIGHT; wxString t = _("Filename format"); #ifdef __WXOSX__ flags |= wxALIGN_RIGHT; @@ -56,14 +56,19 @@ KDMOutputPanel::KDMOutputPanel (wxWindow* parent, bool interop) table->Add (m, 0, flags, DCPOMATIC_SIZER_Y_GAP); } - _filename_format = new NameFormatEditor (this, Config::instance()->kdm_filename_format()); + dcp::NameFormat::Map titles; + titles['f'] = "film name"; + titles['c'] = "cinema"; + titles['s'] = "screen"; + titles['b'] = "from date/time"; + titles['e'] = "to date/time"; dcp::NameFormat::Map ex; - ex["film_name"] = "Bambi"; - ex["cinema"] = "Lumière"; - ex["screen"] = "Screen 1"; - ex["from"] = "2012/03/15 12:30"; - ex["to"] = "2012/03/22 02:30"; - _filename_format->set_example (ex); + ex['f'] = "Bambi"; + ex['c'] = "Lumière"; + ex['s'] = "Screen 1"; + ex['b'] = "2012/03/15 12:30"; + ex['e'] = "2012/03/22 02:30"; + _filename_format = new NameFormatEditor (this, Config::instance()->kdm_filename_format(), titles, ex); table->Add (_filename_format->panel(), 1, wxEXPAND); _write_to = new wxRadioButton (this, wxID_ANY, _("Write to")); diff --git a/src/wx/name_format_editor.h b/src/wx/name_format_editor.h index 1ca4c0b71..0f4682127 100644 --- a/src/wx/name_format_editor.h +++ b/src/wx/name_format_editor.h @@ -30,19 +30,20 @@ template class NameFormatEditor { public: - NameFormatEditor (wxWindow* parent, T name) + NameFormatEditor (wxWindow* parent, T name, dcp::NameFormat::Map titles, dcp::NameFormat::Map examples) : _panel (new wxPanel (parent)) , _example (new wxStaticText (_panel, wxID_ANY, "")) , _sizer (new wxBoxSizer (wxVERTICAL)) , _specification (new wxTextCtrl (_panel, wxID_ANY, "")) , _name (name) + , _examples (examples) { _sizer->Add (_specification, 0, wxEXPAND, DCPOMATIC_SIZER_Y_GAP); _sizer->Add (_example, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP); _panel->SetSizer (_sizer); - BOOST_FOREACH (dcp::NameFormat::Component c, name.components ()) { - wxStaticText* t = new wxStaticText (_panel, wxID_ANY, std_to_wx (String::compose ("%%%1 %2", c.placeholder, c.title))); + BOOST_FOREACH (char c, name.components ()) { + wxStaticText* t = new wxStaticText (_panel, wxID_ANY, std_to_wx (String::compose ("%%%1 %2", c, titles[c]))); _sizer->Add (t); wxFont font = t->GetFont(); font.SetStyle (wxFONTSTYLE_ITALIC); @@ -57,16 +58,10 @@ public: update_example (); } - wxPanel* panel () const - { + wxPanel* panel () const { return _panel; } - void set_example (dcp::NameFormat::Map v) { - _example_values = v; - update_example (); - } - T get () const { return _name; } @@ -85,7 +80,7 @@ private: { _name.set_specification (wx_to_std (_specification->GetValue ())); - wxString example = wxString::Format (_("e.g. %s"), _name.get (_example_values)); + wxString example = wxString::Format (_("e.g. %s"), _name.get (_examples)); wxString wrapped; for (size_t i = 0; i < example.Length(); ++i) { if (i > 0 && (i % 30) == 0) { @@ -103,7 +98,7 @@ private: wxTextCtrl* _specification; T _name; - dcp::NameFormat::Map _example_values; + dcp::NameFormat::Map _examples; }; #endif -- 2.30.2