Simplify NameFormat stuff.
authorCarl Hetherington <cth@carlh.net>
Sun, 31 Jul 2016 23:48:15 +0000 (00:48 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 31 Jul 2016 23:48:15 +0000 (00:48 +0100)
19 files changed:
cscript
src/lib/cinema_kdms.cc
src/lib/cinema_kdms.h
src/lib/config.cc
src/lib/config.h
src/lib/kdm_filename_format.cc [deleted file]
src/lib/kdm_filename_format.h [deleted file]
src/lib/screen_kdm.cc
src/lib/screen_kdm.h
src/lib/send_kdm_email_job.cc
src/lib/send_kdm_email_job.h
src/lib/wscript
src/wx/config_dialog.cc
src/wx/kdm_dialog.h
src/wx/kdm_output_panel.cc
src/wx/kdm_output_panel.h
src/wx/name_format_editor.h
src/wx/wscript
test/file_naming_test.cc

diff --git a/cscript b/cscript
index 5d0c949e8f6e319808d7e26c11fc7c35fa9fb467..be695e24499894d81f859a310e900b8d4452f0b2 100644 (file)
--- a/cscript
+++ b/cscript
@@ -237,7 +237,7 @@ def dependencies(target):
         ffmpeg_options = {}
 
     return (('ffmpeg-cdist', '1d4a1a4', ffmpeg_options),
-            ('libdcp', 'f3fb557'),
+            ('libdcp', 'd46f968'),
             ('libsub', '067c21c'))
 
 def configure_options(target):
index 78e7c5ace6f2c3f12daeda4a50f6c319d88a1583..299cdf94e5d94dcf075a312a11d21c6315f5059e 100644 (file)
@@ -27,7 +27,6 @@
 #include "emailer.h"
 #include "compose.hpp"
 #include "log.h"
-#include "kdm_filename_format.h"
 #include <zip.h>
 #include <boost/foreach.hpp>
 
@@ -40,7 +39,7 @@ using std::runtime_error;
 using boost::shared_ptr;
 
 void
-CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, KDMFilenameFormat name_format, dcp::NameFormat::Map name_values) const
+CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) const
 {
        int error;
        struct zip* zip = zip_open (zip_file.string().c_str(), ZIP_CREATE | ZIP_EXCL, &error);
@@ -119,7 +118,7 @@ void
 CinemaKDMs::write_zip_files (
        list<CinemaKDMs> cinema_kdms,
        boost::filesystem::path directory,
-       KDMFilenameFormat name_format,
+       dcp::NameFormat name_format,
        dcp::NameFormat::Map name_values
        )
 {
@@ -140,7 +139,7 @@ CinemaKDMs::write_zip_files (
 void
 CinemaKDMs::email (
        list<CinemaKDMs> cinema_kdms,
-       KDMFilenameFormat name_format,
+       dcp::NameFormat name_format,
        dcp::NameFormat::Map name_values,
        string cpl_name,
        shared_ptr<Log> log
index 826b938066f1c13aa98f8aca3b7bb9542e15116c..e29fa5cbdc8037a1032f7e0de6a26aee4bde15c1 100644 (file)
@@ -27,20 +27,20 @@ class Log;
 class CinemaKDMs
 {
 public:
-       void make_zip_file (boost::filesystem::path zip_file, KDMFilenameFormat name_format, dcp::NameFormat::Map name_values) const;
+       void make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) const;
 
        static std::list<CinemaKDMs> collect (std::list<ScreenKDM> kdms);
 
        static void write_zip_files (
                std::list<CinemaKDMs> cinema_kdms,
                boost::filesystem::path directory,
-               KDMFilenameFormat name_format,
+               dcp::NameFormat name_format,
                dcp::NameFormat::Map name_values
                );
 
        static void email (
                std::list<CinemaKDMs> cinema_kdms,
-               KDMFilenameFormat name_format,
+               dcp::NameFormat name_format,
                dcp::NameFormat::Map name_values,
                std::string cpl_name,
                boost::shared_ptr<Log> log
index d332c805a9b2752c67c0621565975bde843a4c7e..5dbbd692e60b50fcdbdf77043fd375a7a393b227 100644 (file)
@@ -30,8 +30,7 @@
 #include "util.h"
 #include "cross.h"
 #include "raw_convert.h"
-#include "kdm_filename_format.h"
-#include <dcp/filename_format.h>
+#include <dcp/name_format.h>
 #include <dcp/colour_matrix.h>
 #include <dcp/certificate_chain.h>
 #include <libcxml/cxml.h>
@@ -110,8 +109,8 @@ Config::set_defaults ()
 #endif
        _cinemas_file = path ("cinemas.xml");
        _show_hints_before_make_dcp = true;
-       _kdm_filename_format = KDMFilenameFormat ("KDM %f %c %s");
-       _dcp_filename_format = dcp::FilenameFormat ("%t_%i");
+       _kdm_filename_format = dcp::NameFormat ("KDM %f %c %s");
+       _dcp_filename_format = dcp::NameFormat ("%t_%i");
 
        _allowed_dcp_frame_rates.clear ();
        _allowed_dcp_frame_rates.push_back (24);
@@ -294,8 +293,8 @@ try
 
        _cinemas_file = f.optional_string_child("CinemasFile").get_value_or (path ("cinemas.xml").string ());
        _show_hints_before_make_dcp = f.optional_bool_child("ShowHintsBeforeMakeDCP").get_value_or (true);
-       _kdm_filename_format = KDMFilenameFormat (f.optional_string_child("KDMFilenameFormat").get_value_or ("KDM %f %c %s"));
-       _dcp_filename_format = dcp::FilenameFormat (f.optional_string_child("DCPFilenameFormat").get_value_or ("%t_%i.mxf"));
+       _kdm_filename_format = dcp::NameFormat (f.optional_string_child("KDMFilenameFormat").get_value_or ("KDM %f %c %s"));
+       _dcp_filename_format = dcp::NameFormat (f.optional_string_child("DCPFilenameFormat").get_value_or ("%t_%i.mxf"));
 
        /* Replace any cinemas from config.xml with those from the configured file */
        if (boost::filesystem::exists (_cinemas_file)) {
index 0de71be512fb4447b95a6e776dcd2c2088356c47..3a03084621d82f5c97cb6fc882c304cb5b581c3b 100644 (file)
@@ -26,9 +26,8 @@
 #define DCPOMATIC_CONFIG_H
 
 #include "isdcf_metadata.h"
-#include "kdm_filename_format.h"
 #include "types.h"
-#include <dcp/filename_format.h>
+#include <dcp/name_format.h>
 #include <dcp/certificate_chain.h>
 #include <dcp/encrypted_kdm.h>
 #include <boost/shared_ptr.hpp>
@@ -268,11 +267,11 @@ public:
                return _show_hints_before_make_dcp;
        }
 
-       KDMFilenameFormat kdm_filename_format () const {
+       dcp::NameFormat kdm_filename_format () const {
                return _kdm_filename_format;
        }
 
-       dcp::FilenameFormat dcp_filename_format () const {
+       dcp::NameFormat dcp_filename_format () const {
                return _dcp_filename_format;
        }
 
@@ -483,11 +482,11 @@ public:
                maybe_set (_show_hints_before_make_dcp, s);
        }
 
-       void set_kdm_filename_format (KDMFilenameFormat n) {
+       void set_kdm_filename_format (dcp::NameFormat n) {
                maybe_set (_kdm_filename_format, n);
        }
 
-       void set_dcp_filename_format (dcp::FilenameFormat n) {
+       void set_dcp_filename_format (dcp::NameFormat n) {
                maybe_set (_dcp_filename_format, n);
        }
 
@@ -602,8 +601,8 @@ private:
        std::vector<dcp::EncryptedKDM> _dkdms;
        boost::filesystem::path _cinemas_file;
        bool _show_hints_before_make_dcp;
-       KDMFilenameFormat _kdm_filename_format;
-       dcp::FilenameFormat _dcp_filename_format;
+       dcp::NameFormat _kdm_filename_format;
+       dcp::NameFormat _dcp_filename_format;
 
        /** Singleton instance, or 0 */
        static Config* _instance;
diff --git a/src/lib/kdm_filename_format.cc b/src/lib/kdm_filename_format.cc
deleted file mode 100644 (file)
index 20e8298..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
-
-    This file is part of DCP-o-matic.
-
-    DCP-o-matic is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    DCP-o-matic is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include "kdm_filename_format.h"
-
-using std::string;
-
-KDMFilenameFormat::KDMFilenameFormat (string specification)
-       : NameFormat (specification)
-{
-       /* 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/kdm_filename_format.h b/src/lib/kdm_filename_format.h
deleted file mode 100644 (file)
index b96ac34..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
-
-    This file is part of DCP-o-matic.
-
-    DCP-o-matic is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    DCP-o-matic is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef DCPOMATIC_KDM_FILENAME_FORMAT
-#define DCPOMATIC_KDM_FILENAME_FORMAT
-
-#include <dcp/name_format.h>
-
-class KDMFilenameFormat : public dcp::NameFormat
-{
-public:
-       KDMFilenameFormat () {}
-       KDMFilenameFormat (std::string specification);
-};
-
-#endif
index 9cb83162215f5d840d7e2be963a9087ab74e968f..129e64aeee5b7e88de8bcccd512cdfa8b98c796d 100644 (file)
@@ -35,7 +35,7 @@ operator== (ScreenKDM const & a, ScreenKDM const & b)
 }
 
 void
-ScreenKDM::write_files (list<ScreenKDM> screen_kdms, boost::filesystem::path directory, KDMFilenameFormat name_format, dcp::NameFormat::Map name_values)
+ScreenKDM::write_files (list<ScreenKDM> screen_kdms, boost::filesystem::path directory, dcp::NameFormat name_format, dcp::NameFormat::Map name_values)
 {
        /* Write KDMs to the specified directory */
        BOOST_FOREACH (ScreenKDM const & i, screen_kdms) {
index 227526449a3b18abe8ec4a5b6a7a715535677e40..60486c2593d5481ecadbbbd45df9847833e4d16b 100644 (file)
@@ -21,8 +21,8 @@
 #ifndef DCPOMATIC_SCREEN_KDM_H
 #define DCPOMATIC_SCREEN_KDM_H
 
-#include "kdm_filename_format.h"
 #include <dcp/encrypted_kdm.h>
+#include <dcp/name_format.h>
 #include <boost/shared_ptr.hpp>
 
 class Screen;
@@ -38,7 +38,7 @@ public:
 
        static void write_files (
                std::list<ScreenKDM> screen_kdms, boost::filesystem::path directory,
-               KDMFilenameFormat name_format, dcp::NameFormat::Map name_values
+               dcp::NameFormat name_format, dcp::NameFormat::Map name_values
                );
 
        boost::shared_ptr<Screen> screen;
index b06704545ab4e2321f7018938c20952770f15cd5..6429394625c5df51aeabb4cbf6b18806fc2b88f9 100644 (file)
@@ -33,7 +33,7 @@ using boost::shared_ptr;
 /** @param log Log to write to, or 0 */
 SendKDMEmailJob::SendKDMEmailJob (
        list<CinemaKDMs> cinema_kdms,
-       KDMFilenameFormat name_format,
+       dcp::NameFormat name_format,
        dcp::NameFormat::Map name_values,
        string cpl_name,
        shared_ptr<Log> log
index 17b2db89c9fae430cddb29fc21f833b6dd8948d5..c2916f69d02a14f2d0522fb280e0e5cfe3468d6e 100644 (file)
@@ -19,8 +19,8 @@
 */
 
 #include "job.h"
-#include "kdm_filename_format.h"
 #include <dcp/types.h>
+#include <dcp/name_format.h>
 #include <boost/filesystem.hpp>
 
 class Screen;
@@ -32,7 +32,7 @@ class SendKDMEmailJob : public Job
 public:
        SendKDMEmailJob (
                std::list<CinemaKDMs> cinema_kdms,
-               KDMFilenameFormat name_format,
+               dcp::NameFormat name_format,
                dcp::NameFormat::Map name_values,
                std::string cpl_name,
                boost::shared_ptr<Log> log
@@ -43,7 +43,7 @@ public:
        void run ();
 
 private:
-       KDMFilenameFormat _name_format;
+       dcp::NameFormat _name_format;
        dcp::NameFormat::Map _name_values;
        std::string _cpl_name;
        std::list<CinemaKDMs> _cinema_kdms;
index 6e937c26f39ca14de4466cdcb647d8f5f0b88251..9883f31d6a6636407502170b26237632340cfeeb 100644 (file)
@@ -94,7 +94,6 @@ sources = """
           job.cc
           job_manager.cc
           json_server.cc
-          kdm_filename_format.cc
           log.cc
           log_entry.cc
           magick_image_proxy.cc
index 10ee7c79a275face2b8b3f5f5186b627d8bccfc3..3f3565122c67e06b8b388e8dbabdc80f093d93b4 100644 (file)
@@ -1420,7 +1420,7 @@ private:
                examples['i'] = "eb1c112c-ca3c-4ae6-9263-c6714ff05d64";
                examples['r'] = "1";
                examples['n'] = "4";
-               _dcp_filename_format = new NameFormatEditor<dcp::FilenameFormat> (_panel, Config::instance()->dcp_filename_format(), titles, examples);
+               _dcp_filename_format = new NameFormatEditor (_panel, Config::instance()->dcp_filename_format(), titles, examples);
                table->Add (_dcp_filename_format->panel(), 1, wxEXPAND | wxALL);
 
 #ifdef __WXOSX__
@@ -1550,7 +1550,7 @@ private:
        wxSpinCtrl* _maximum_j2k_bandwidth;
        wxCheckBox* _allow_any_dcp_frame_rate;
        wxCheckBox* _only_servers_encode;
-       NameFormatEditor<dcp::FilenameFormat>* _dcp_filename_format;
+       NameFormatEditor* _dcp_filename_format;
        wxCheckBox* _log_general;
        wxCheckBox* _log_warning;
        wxCheckBox* _log_error;
index 07b998224dba662a33583f95d83e4896d1826619..a76c2a14f9e26d46bb899ca1118a48e51a8ab123 100644 (file)
@@ -19,7 +19,6 @@
 */
 
 #include "wx_util.h"
-#include "lib/kdm_filename_format.h"
 #include <dcp/types.h>
 #include <wx/wx.h>
 #include <boost/shared_ptr.hpp>
index 2808357d49ebac986a876b1d781f408914cacc65..537cf66523fd1c5d0704bcbef286e5f99d1624af 100644 (file)
@@ -68,7 +68,7 @@ KDMOutputPanel::KDMOutputPanel (wxWindow* parent, bool interop)
        ex['s'] = "Screen 1";
        ex['b'] = "2012/03/15 12:30";
        ex['e'] = "2012/03/22 02:30";
-       _filename_format = new NameFormatEditor<KDMFilenameFormat> (this, Config::instance()->kdm_filename_format(), titles, ex);
+       _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"));
@@ -126,7 +126,7 @@ KDMOutputPanel::save_kdm_name_format () const
        Config::instance()->set_kdm_filename_format (name_format ());
 }
 
-KDMFilenameFormat
+dcp::NameFormat
 KDMOutputPanel::name_format () const
 {
        return _filename_format->get ();
index ee6a94e6857d68ba795557e297651eefb1201b63..efc9c0c9307e578d5d34cfcecfcb32415bff13d7 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "wx_util.h"
 #include "name_format_editor.h"
-#include "lib/kdm_filename_format.h"
 #include <dcp/types.h>
 #include <wx/wx.h>
 #include <boost/filesystem.hpp>
@@ -36,14 +35,14 @@ public:
        boost::filesystem::path directory () const;
        bool write_to () const;
        dcp::Formulation formulation () const;
-       KDMFilenameFormat name_format () const;
+       dcp::NameFormat name_format () const;
 
        void setup_sensitivity ();
        void save_kdm_name_format () const;
 
 private:
        wxChoice* _type;
-       NameFormatEditor<KDMFilenameFormat>* _filename_format;
+       NameFormatEditor* _filename_format;
        wxRadioButton* _write_to;
 #ifdef DCPOMATIC_USE_OWN_PICKER
        DirPickerCtrl* _folder;
index 71295807fda83b7be874448e172494f32b02d1a5..204de76d3a943d6f438d8b9b2ad6026002284d0a 100644 (file)
 #include <dcp/name_format.h>
 #include <wx/wx.h>
 #include <boost/foreach.hpp>
+#include <boost/signals2.hpp>
 
-template <class T>
 class NameFormatEditor
 {
 public:
-       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 (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);
-                       font.SetPointSize (font.GetPointSize() - 1);
-                       t->SetFont (font);
-                       t->SetForegroundColour (wxColour (0, 0, 204));
-               }
-
-               _specification->SetValue (std_to_wx (_name.specification ()));
-               _specification->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&NameFormatEditor::changed, this));
-
-               update_example ();
-       }
+       NameFormatEditor (wxWindow* parent, dcp::NameFormat name, dcp::NameFormat::Map titles, dcp::NameFormat::Map examples);
 
        wxPanel* panel () const {
                return _panel;
        }
 
-       T get () const {
+       dcp::NameFormat get () const {
                return _name;
        }
 
@@ -70,34 +44,15 @@ public:
 
 private:
 
-       void changed ()
-       {
-               update_example ();
-               Changed ();
-       }
-
-       virtual void update_example ()
-       {
-               _name.set_specification (wx_to_std (_specification->GetValue ()));
-
-               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 % 40) == 0) {
-                               wrapped += "\n";
-                       }
-                       wrapped += example[i];
-               }
-
-               _example->SetLabel (wrapped);
-       }
+       void changed ();
+       void update_example ();
 
        wxPanel* _panel;
        wxStaticText* _example;
        wxSizer* _sizer;
        wxTextCtrl* _specification;
 
-       T _name;
+       dcp::NameFormat _name;
        dcp::NameFormat::Map _examples;
 };
 
index bb56ee5b85fc3cf23f0be81bf106c192085eca72..ee77e6c20b5c9eba1e3a840d1c79437145d66622 100644 (file)
@@ -68,6 +68,7 @@ sources = """
           key_dialog.cc
           make_chain_dialog.cc
           move_to_dialog.cc
+          name_format_editor.cc
           new_film_dialog.cc
           playhead_to_timecode_dialog.cc
           playhead_to_frame_dialog.cc
index 4c2b0af471ed97c0d135d284d91f70beb2d1b3b4..5bc2e6dd4116009b9dc617a7177ee37aa3030362 100644 (file)
@@ -29,8 +29,8 @@ using boost::shared_ptr;
 
 BOOST_AUTO_TEST_CASE (file_naming_test)
 {
-       dcp::FilenameFormat nf ("%c");
-       Config::instance()->set_dcp_filename_format (dcp::FilenameFormat ("%c"));
+       dcp::NameFormat nf ("%c");
+       Config::instance()->set_dcp_filename_format (dcp::NameFormat ("%c"));
        shared_ptr<Film> film = new_test_film ("file_naming_test");
        film->set_name ("file_naming_test");
        film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));