diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-05-09 21:33:56 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-05-25 01:30:31 +0200 |
| commit | 1e6484e0fe9e3fa090ef58e17433333a5378043c (patch) | |
| tree | 5bbb2e4efa39c5aee1d93bd618e5805b38ceb39f /src/lib | |
| parent | 00706c7d9ded27a537af4e8182e67b460ec316bc (diff) | |
Improve save-template dialog and always use a default template.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/config.cc | 19 | ||||
| -rw-r--r-- | src/lib/config.h | 3 | ||||
| -rw-r--r-- | src/lib/film.cc | 18 | ||||
| -rw-r--r-- | src/lib/film.h | 2 |
4 files changed, 38 insertions, 4 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index 879c29279..1269206ee 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -1385,6 +1385,13 @@ Config::set_dkdm_recipients_file(boost::filesystem::path file) void +Config::save_default_template(shared_ptr<const Film> film) const +{ + film->write_template(write_path("default.xml")); +} + + +void Config::save_template (shared_ptr<const Film> film, string name) const { film->write_template (template_write_path(name)); @@ -1420,6 +1427,18 @@ Config::template_read_path (string name) const boost::filesystem::path +Config::default_template_read_path() const +{ + if (!boost::filesystem::exists(read_path("default.xml"))) { + auto film = std::make_shared<const Film>(optional<boost::filesystem::path>()); + save_default_template(film); + } + + return read_path("default.xml"); +} + + +boost::filesystem::path Config::template_write_path (string name) const { return write_path("templates") / tidy_for_filename (name); diff --git a/src/lib/config.h b/src/lib/config.h index 1a59f4bad..b8dab9a44 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -1268,10 +1268,13 @@ public: void copy_and_link (boost::filesystem::path new_file) const; bool have_write_permission () const; + void save_default_template(std::shared_ptr<const Film> film) const; void save_template (std::shared_ptr<const Film> film, std::string name) const; bool existing_template (std::string name) const; + /** @return Template names (not including the default) */ std::vector<std::string> templates() const; boost::filesystem::path template_read_path (std::string name) const; + boost::filesystem::path default_template_read_path() const; void rename_template (std::string old_name, std::string new_name) const; void delete_template (std::string name) const; diff --git a/src/lib/film.cc b/src/lib/film.cc index b25228ff9..32c236d36 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -153,6 +153,14 @@ int const Film::current_state_version = 38; /** Construct a Film object in a given directory. * + * Some initial values are taken from the Config object, and usually then overwritten + * by reading in the default template. Setting up things like _dcp_content_type in + * this constructor is useful so that if people configured such things in old versions + * they are used when the first default template is written by Config + * + * At some point these config entries can be removed, and this constructor could + * perhaps read the default template itself. + * * @param dir Film directory. */ @@ -1953,10 +1961,14 @@ Film::content_summary (DCPTimePeriod period) const } void -Film::use_template (string name) +Film::use_template(optional<string> name) { - _template_film.reset (new Film (optional<boost::filesystem::path>())); - _template_film->read_metadata (Config::instance()->template_read_path(name)); + _template_film = std::make_shared<Film>(optional<boost::filesystem::path>()); + if (name) { + _template_film->read_metadata(Config::instance()->template_read_path(*name)); + } else { + _template_film->read_metadata(Config::instance()->default_template_read_path()); + } _use_isdcf_name = _template_film->_use_isdcf_name; _dcp_content_type = _template_film->_dcp_content_type; _container = _template_film->_container; diff --git a/src/lib/film.h b/src/lib/film.h index baac7c4fe..d71435566 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -136,7 +136,7 @@ public: boost::filesystem::path file (boost::filesystem::path f) const; boost::filesystem::path dir (boost::filesystem::path d, bool create = true) const; - void use_template (std::string name); + void use_template(boost::optional<std::string> name); std::list<std::string> read_metadata (boost::optional<boost::filesystem::path> path = boost::optional<boost::filesystem::path> ()); void write_metadata (); void write_metadata (boost::filesystem::path path) const; |
