#include <dcp/certificate_chain.h>
#include <dcp/cpl.h>
#include <dcp/decrypted_kdm.h>
+#include <dcp/filesystem.h>
#include <dcp/local_time.h>
#include <dcp/raw_convert.h>
#include <dcp/reel_asset.h>
static constexpr char metadata_file[] = "metadata.xml";
+static constexpr char ui_state_file[] = "ui.xml";
/* 5 -> 6
_playlist_length_change_connection = _playlist->LengthChange.connect (bind(&Film::playlist_length_change, this));
if (dir) {
- /* Make state.directory a complete path without ..s (where possible)
- (Code swiped from Adam Bowen on stackoverflow)
- XXX: couldn't/shouldn't this just be boost::filesystem::canonical?
- */
-
- boost::filesystem::path p (boost::filesystem::system_complete (dir.get()));
- boost::filesystem::path result;
- for (auto i: p) {
- if (i == "..") {
- boost::system::error_code ec;
- if (boost::filesystem::is_symlink(result, ec) || result.filename() == "..") {
- result /= i;
- } else {
- result = result.parent_path ();
- }
- } else if (i != ".") {
- result /= i;
- }
- }
-
- set_directory (result.make_preferred ());
+ set_directory(dcp::filesystem::weakly_canonical(*dir));
}
if (_directory) {
auto doc = make_shared<xmlpp::Document>();
auto root = doc->create_root_node ("Metadata");
- root->add_child("Version")->add_child_text (raw_convert<string> (current_state_version));
- auto last_write = root->add_child("LastWrittenBy");
+ cxml::add_text_child(root, "Version", raw_convert<string>(current_state_version));
+ auto last_write = cxml::add_child(root, "LastWrittenBy");
last_write->add_child_text (dcpomatic_version);
last_write->set_attribute("git", dcpomatic_git_commit);
- root->add_child("Name")->add_child_text (_name);
- root->add_child("UseISDCFName")->add_child_text (_use_isdcf_name ? "1" : "0");
+ cxml::add_text_child(root, "Name", _name);
+ cxml::add_text_child(root, "UseISDCFName", _use_isdcf_name ? "1" : "0");
if (_dcp_content_type) {
- root->add_child("DCPContentType")->add_child_text (_dcp_content_type->isdcf_name ());
+ cxml::add_text_child(root, "DCPContentType", _dcp_content_type->isdcf_name());
}
if (_container) {
- root->add_child("Container")->add_child_text (_container->id ());
- }
-
- root->add_child("Resolution")->add_child_text (resolution_to_string (_resolution));
- root->add_child("J2KBandwidth")->add_child_text (raw_convert<string> (_j2k_bandwidth));
- root->add_child("VideoFrameRate")->add_child_text (raw_convert<string> (_video_frame_rate));
- root->add_child("AudioFrameRate")->add_child_text(raw_convert<string>(_audio_frame_rate));
- root->add_child("ISDCFDate")->add_child_text (boost::gregorian::to_iso_string (_isdcf_date));
- root->add_child("AudioChannels")->add_child_text (raw_convert<string> (_audio_channels));
- root->add_child("ThreeD")->add_child_text (_three_d ? "1" : "0");
- root->add_child("Sequence")->add_child_text (_sequence ? "1" : "0");
- root->add_child("Interop")->add_child_text (_interop ? "1" : "0");
- root->add_child("LimitToSMPTEBv20")->add_child_text(_limit_to_smpte_bv20 ? "1" : "0");
- root->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
- root->add_child("Key")->add_child_text (_key.hex ());
- root->add_child("ContextID")->add_child_text (_context_id);
+ cxml::add_text_child(root, "Container", _container->id());
+ }
+
+ cxml::add_text_child(root, "Resolution", resolution_to_string(_resolution));
+ cxml::add_text_child(root, "J2KBandwidth", raw_convert<string>(_j2k_bandwidth));
+ cxml::add_text_child(root, "VideoFrameRate", raw_convert<string>(_video_frame_rate));
+ cxml::add_text_child(root, "AudioFrameRate", raw_convert<string>(_audio_frame_rate));
+ cxml::add_text_child(root, "ISDCFDate", boost::gregorian::to_iso_string(_isdcf_date));
+ cxml::add_text_child(root, "AudioChannels", raw_convert<string>(_audio_channels));
+ cxml::add_text_child(root, "ThreeD", _three_d ? "1" : "0");
+ cxml::add_text_child(root, "Sequence", _sequence ? "1" : "0");
+ cxml::add_text_child(root, "Interop", _interop ? "1" : "0");
+ cxml::add_text_child(root, "LimitToSMPTEBv20", _limit_to_smpte_bv20 ? "1" : "0");
+ cxml::add_text_child(root, "Encrypted", _encrypted ? "1" : "0");
+ cxml::add_text_child(root, "Key", _key.hex ());
+ cxml::add_text_child(root, "ContextID", _context_id);
if (_audio_processor) {
- root->add_child("AudioProcessor")->add_child_text (_audio_processor->id ());
+ cxml::add_text_child(root, "AudioProcessor", _audio_processor->id());
+ }
+ cxml::add_text_child(root, "ReelType", raw_convert<string>(static_cast<int> (_reel_type)));
+ cxml::add_text_child(root, "ReelLength", raw_convert<string>(_reel_length));
+ for (auto boundary: _custom_reel_boundaries) {
+ cxml::add_text_child(root, "CustomReelBoundary", raw_convert<string>(boundary.get()));
}
- root->add_child("ReelType")->add_child_text (raw_convert<string> (static_cast<int> (_reel_type)));
- root->add_child("ReelLength")->add_child_text (raw_convert<string> (_reel_length));
- root->add_child("ReencodeJ2K")->add_child_text (_reencode_j2k ? "1" : "0");
- root->add_child("UserExplicitVideoFrameRate")->add_child_text(_user_explicit_video_frame_rate ? "1" : "0");
+ cxml::add_text_child(root, "ReencodeJ2K", _reencode_j2k ? "1" : "0");
+ cxml::add_text_child(root, "UserExplicitVideoFrameRate", _user_explicit_video_frame_rate ? "1" : "0");
for (auto const& marker: _markers) {
- auto m = root->add_child("Marker");
- m->set_attribute("Type", dcp::marker_to_string(marker.first));
+ auto m = cxml::add_child(root, "Marker");
+ m->set_attribute("type", dcp::marker_to_string(marker.first));
m->add_child_text(raw_convert<string>(marker.second.get()));
}
for (auto i: _ratings) {
- i.as_xml (root->add_child("Rating"));
+ i.as_xml(cxml::add_child(root, "Rating"));
}
for (auto i: _content_versions) {
- root->add_child("ContentVersion")->add_child_text(i);
+ cxml::add_text_child(root, "ContentVersion", i);
}
- root->add_child("NameLanguage")->add_child_text(_name_language.to_string());
+ cxml::add_text_child(root, "NameLanguage", _name_language.to_string());
+ cxml::add_text_child(root, "TerritoryType", territory_type_to_string(_territory_type));
if (_release_territory) {
- root->add_child("ReleaseTerritory")->add_child_text(_release_territory->subtag());
+ cxml::add_text_child(root, "ReleaseTerritory", _release_territory->subtag());
}
if (_sign_language_video_language) {
- root->add_child("SignLanguageVideoLanguage")->add_child_text(_sign_language_video_language->to_string());
+ cxml::add_text_child(root, "SignLanguageVideoLanguage", _sign_language_video_language->to_string());
}
- root->add_child("VersionNumber")->add_child_text(raw_convert<string>(_version_number));
- root->add_child("Status")->add_child_text(dcp::status_to_string(_status));
+ cxml::add_text_child(root, "VersionNumber", raw_convert<string>(_version_number));
+ cxml::add_text_child(root, "Status", dcp::status_to_string(_status));
if (_chain) {
- root->add_child("Chain")->add_child_text(*_chain);
+ cxml::add_text_child(root, "Chain", *_chain);
}
if (_distributor) {
- root->add_child("Distributor")->add_child_text(*_distributor);
+ cxml::add_text_child(root, "Distributor", *_distributor);
}
if (_facility) {
- root->add_child("Facility")->add_child_text(*_facility);
+ cxml::add_text_child(root, "Facility", *_facility);
}
if (_studio) {
- root->add_child("Studio")->add_child_text(*_studio);
+ cxml::add_text_child(root, "Studio", *_studio);
}
- root->add_child("TempVersion")->add_child_text(_temp_version ? "1" : "0");
- root->add_child("PreRelease")->add_child_text(_pre_release ? "1" : "0");
- root->add_child("RedBand")->add_child_text(_red_band ? "1" : "0");
- root->add_child("TwoDVersionOfThreeD")->add_child_text(_two_d_version_of_three_d ? "1" : "0");
+ cxml::add_text_child(root, "TempVersion", _temp_version ? "1" : "0");
+ cxml::add_text_child(root, "PreRelease", _pre_release ? "1" : "0");
+ cxml::add_text_child(root, "RedBand", _red_band ? "1" : "0");
+ cxml::add_text_child(root, "TwoDVersionOfThreeD", _two_d_version_of_three_d ? "1" : "0");
if (_luminance) {
- root->add_child("LuminanceValue")->add_child_text(raw_convert<string>(_luminance->value()));
- root->add_child("LuminanceUnit")->add_child_text(dcp::Luminance::unit_to_string(_luminance->unit()));
+ cxml::add_text_child(root, "LuminanceValue", raw_convert<string>(_luminance->value()));
+ cxml::add_text_child(root, "LuminanceUnit", dcp::Luminance::unit_to_string(_luminance->unit()));
}
- root->add_child("UserExplicitContainer")->add_child_text(_user_explicit_container ? "1" : "0");
- root->add_child("UserExplicitResolution")->add_child_text(_user_explicit_resolution ? "1" : "0");
+ cxml::add_text_child(root, "UserExplicitContainer", _user_explicit_container ? "1" : "0");
+ cxml::add_text_child(root, "UserExplicitResolution", _user_explicit_resolution ? "1" : "0");
if (_audio_language) {
- root->add_child("AudioLanguage")->add_child_text(_audio_language->to_string());
+ cxml::add_text_child(root, "AudioLanguage", _audio_language->to_string());
}
- _playlist->as_xml (root->add_child ("Playlist"), with_content_paths);
+ _playlist->as_xml(cxml::add_child(root, "Playlist"), with_content_paths);
return doc;
}
Film::write_metadata ()
{
DCPOMATIC_ASSERT (directory());
- boost::filesystem::create_directories (directory().get());
+ dcp::filesystem::create_directories(directory().get());
auto const filename = file(metadata_file);
try {
metadata()->write_to_file_formatted(filename.string());
void
Film::write_template (boost::filesystem::path path) const
{
- boost::filesystem::create_directories (path.parent_path());
+ dcp::filesystem::create_directories(path.parent_path());
shared_ptr<xmlpp::Document> doc = metadata (false);
metadata(false)->write_to_file_formatted(path.string());
}
Film::read_metadata (optional<boost::filesystem::path> path)
{
if (!path) {
- if (boost::filesystem::exists (file ("metadata")) && !boost::filesystem::exists (file (metadata_file))) {
+ if (dcp::filesystem::exists(file("metadata")) && !dcp::filesystem::exists(file(metadata_file))) {
throw runtime_error (_("This film was created with an older version of DCP-o-matic, and unfortunately it cannot be loaded into this version. You will need to create a new Film, re-add your content and set it up again. Sorry!"));
}
path = file (metadata_file);
}
- if (!boost::filesystem::exists(*path)) {
+ if (!dcp::filesystem::exists(*path)) {
throw FileNotFoundError(*path);
}
cxml::Document f ("Metadata");
- f.read_file (path.get ());
+ f.read_file(dcp::filesystem::fix_long_path(path.get()));
_state_version = f.number_child<int> ("Version");
if (_state_version > current_state_version) {
} else if (_state_version < current_state_version) {
/* This is an older version; save a copy (if we haven't already) */
auto const older = path->parent_path() / String::compose("metadata.%1.xml", _state_version);
- if (!boost::filesystem::is_regular_file(older)) {
+ if (!dcp::filesystem::is_regular_file(older)) {
try {
- boost::filesystem::copy_file(*path, older);
+ dcp::filesystem::copy_file(*path, older);
} catch (...) {
/* Never mind; at least we tried */
}
_reel_type = static_cast<ReelType> (f.optional_number_child<int>("ReelType").get_value_or (static_cast<int>(ReelType::SINGLE)));
_reel_length = f.optional_number_child<int64_t>("ReelLength").get_value_or (2000000000);
+ for (auto boundary: f.node_children("CustomReelBoundary")) {
+ _custom_reel_boundaries.push_back(DCPTime(raw_convert<int64_t>(boundary->content())));
+ }
_reencode_j2k = f.optional_bool_child("ReencodeJ2K").get_value_or(false);
_user_explicit_video_frame_rate = f.optional_bool_child("UserExplicitVideoFrameRate").get_value_or(false);
for (auto i: f.node_children("Marker")) {
- _markers[dcp::marker_from_string(i->string_attribute("Type"))] = DCPTime(dcp::raw_convert<DCPTime::Type>(i->content()));
+ auto type = i->optional_string_attribute("Type");
+ if (!type) {
+ type = i->string_attribute("type");
+ }
+ _markers[dcp::marker_from_string(*type)] = DCPTime(dcp::raw_convert<DCPTime::Type>(i->content()));
}
for (auto i: f.node_children("Rating")) {
if (name_language) {
_name_language = dcp::LanguageTag (*name_language);
}
+ auto territory_type = f.optional_string_child("TerritoryType");
+ if (territory_type) {
+ _territory_type = string_to_territory_type(*territory_type);
+ }
auto release_territory = f.optional_string_child("ReleaseTerritory");
if (release_territory) {
_release_territory = dcp::LanguageTag::RegionSubtag (*release_territory);
}
_studio = isdcf->optional_string_child("Studio");
_facility = isdcf->optional_string_child("Facility");
- _temp_version = isdcf->optional_bool_child("TempVersion").get_value_or("false");
- _pre_release = isdcf->optional_bool_child("PreRelease").get_value_or("false");
- _red_band = isdcf->optional_bool_child("RedBand").get_value_or("false");
- _two_d_version_of_three_d = isdcf->optional_bool_child("TwoDVersionOfThreeD").get_value_or("false");
+ _temp_version = isdcf->optional_bool_child("TempVersion").get_value_or(false);
+ _pre_release = isdcf->optional_bool_child("PreRelease").get_value_or(false);
+ _red_band = isdcf->optional_bool_child("RedBand").get_value_or(false);
+ _two_d_version_of_three_d = isdcf->optional_bool_child("TwoDVersionOfThreeD").get_value_or(false);
_chain = isdcf->optional_string_child("Chain");
}
p /= d;
if (create) {
- boost::filesystem::create_directories (p);
+ dcp::filesystem::create_directories(p);
}
return p;
p /= _directory.get();
p /= f;
- boost::filesystem::create_directories (p.parent_path ());
+ dcp::filesystem::create_directories(p.parent_path());
return p;
}
pair<optional<dcp::LanguageTag>, vector<dcp::LanguageTag>>
-Film::subtitle_languages () const
+Film::subtitle_languages(bool* burnt_in) const
{
+ if (burnt_in) {
+ *burnt_in = true;
+ }
+
pair<optional<dcp::LanguageTag>, vector<dcp::LanguageTag>> result;
for (auto i: content()) {
- for (auto text: i->text) {
- if (text->use() && text->type() == TextType::OPEN_SUBTITLE && text->language()) {
- if (text->language_is_additional()) {
- result.second.push_back(text->language().get());
- } else {
- result.first = text->language().get();
+ auto dcp = dynamic_pointer_cast<DCPContent>(i);
+ for (auto const& text: i->text) {
+ auto const use = text->use() || (dcp && dcp->reference_text(TextType::OPEN_SUBTITLE));
+ if (use && text->type() == TextType::OPEN_SUBTITLE) {
+ if (!text->burn() && burnt_in) {
+ *burnt_in = false;
+ }
+ if (text->language()) {
+ if (text->language_is_additional()) {
+ result.second.push_back(text->language().get());
+ } else {
+ result.first = text->language().get();
+ }
}
}
}
if (dcp_content_type() && dcp_content_type()->libdcp_kind() != dcp::ContentKind::TRAILER) {
auto first_video = std::find_if(content_list.begin(), content_list.end(), [](shared_ptr<Content> c) { return static_cast<bool>(c->video); });
if (first_video != content_list.end()) {
- auto first_ratio = lrintf((*first_video)->video->scaled_size(frame_size()).ratio() * 100);
- auto container_ratio = lrintf(container()->ratio() * 100);
- if (first_ratio != container_ratio) {
- isdcf_name += "-" + dcp::raw_convert<string>(first_ratio);
+ if (auto scaled_size = (*first_video)->video->scaled_size(frame_size())) {
+ auto first_ratio = lrintf(scaled_size->ratio() * 100);
+ auto container_ratio = lrintf(container()->ratio() * 100);
+ if (first_ratio != container_ratio) {
+ isdcf_name += "-" + dcp::raw_convert<string>(first_ratio);
+ }
}
}
}
isdcf_name += "_" + to_upper (audio_language);
- auto burnt_in = true;
- for (auto i: content_list) {
- for (auto text: i->text) {
- if (text->type() == TextType::OPEN_SUBTITLE && text->use() && !text->burn()) {
- burnt_in = false;
- }
- }
- }
-
- auto sub_langs = subtitle_languages();
+ bool burnt_in;
+ auto sub_langs = subtitle_languages(&burnt_in);
auto ccap_langs = closed_caption_languages();
if (sub_langs.first && sub_langs.first->language()) {
auto lang = entry_for_language(*sub_langs.first);
isdcf_name += "-XX";
}
- if (_release_territory) {
+ if (_territory_type == TerritoryType::INTERNATIONAL_TEXTED) {
+ isdcf_name += "_INT-TD";
+ } else if (_territory_type == TerritoryType::INTERNATIONAL_TEXTLESS) {
+ isdcf_name += "_INT-TL";
+ } else if (_release_territory) {
auto territory = _release_territory->subtag();
isdcf_name += "_" + to_upper (territory);
if (!_ratings.empty()) {
_reel_length = r;
}
+
+void
+Film::set_custom_reel_boundaries(vector<DCPTime> boundaries)
+{
+ FilmChangeSignaller ch(this, FilmProperty::CUSTOM_REEL_BOUNDARIES);
+ std::sort(boundaries.begin(), boundaries.end());
+ _custom_reel_boundaries = std::move(boundaries);
+}
+
+
void
Film::set_reencode_j2k (bool r)
{
vector<CPLSummary> out;
auto const dir = directory().get();
- for (auto const& item: boost::filesystem::directory_iterator(dir)) {
+ for (auto const& item: dcp::filesystem::directory_iterator(dir)) {
if (
- boost::filesystem::is_directory(item) &&
- item.path().leaf() != "j2c" && item.path().leaf() != "video" && item.path().leaf() != "info" && item.path().leaf() != "analysis"
+ dcp::filesystem::is_directory(item) &&
+ item.path().filename() != "j2c" && item.path().filename() != "video" && item.path().filename() != "info" && item.path().filename() != "analysis"
) {
try {
maybe_set_container_and_resolution ();
if (c->atmos) {
- set_audio_channels (14);
+ if (_audio_channels < 14) {
+ set_audio_channels(14);
+ }
set_interop (false);
}
}
}
}
- if (video) {
+ if (video && video->size()) {
/* This is the only piece of video content in this Film. Use it to make a guess for
* DCP container size and resolution, unless the user has already explicitly set these
* things.
*/
if (!_user_explicit_container) {
- if (video->size().ratio() > 2.3) {
+ if (video->size()->ratio() > 2.3) {
set_container (Ratio::from_id("239"), false);
} else {
set_container (Ratio::from_id("185"), false);
}
if (!_user_explicit_resolution) {
- if (video->size_after_crop().width > 2048 || video->size_after_crop().height > 1080) {
+ if (video->size_after_crop()->width > 2048 || video->size_after_crop()->height > 1080) {
set_resolution (Resolution::FOUR_K, false);
} else {
set_resolution (Resolution::TWO_K, false);
if (change_made) {
Message (_("DCP-o-matic had to change your settings for referring to DCPs as OV. Please review those settings to make sure they are what you want."));
}
+
+ if (reel_type() == ReelType::CUSTOM) {
+ auto boundaries = custom_reel_boundaries();
+ auto too_late = std::find_if(boundaries.begin(), boundaries.end(), [this](dcpomatic::DCPTime const& time) {
+ return time >= length();
+ });
+
+ if (too_late != boundaries.end()) {
+ if (std::distance(too_late, boundaries.end()) > 1) {
+ Message(_("DCP-o-matic had to remove some of your custom reel boundaries as they no longer lie within the film."));
+ } else {
+ Message(_("DCP-o-matic had to remove one of your custom reel boundaries as it no longer lies within the film."));
+ }
+ boundaries.erase(too_late, boundaries.end());
+ set_custom_reel_boundaries(boundaries);
+ }
+ }
}
void
for (auto i: content()) {
if (i->video) {
- dcp::Size s = i->video->scaled_size (frame);
- active.width = max(active.width, s.width);
- active.height = max(active.height, s.height);
+ if (auto s = i->video->scaled_size(frame)) {
+ active.width = max(active.width, s->width);
+ active.height = max(active.height, s->height);
+ }
}
}
if (f) {
f.close();
boost::system::error_code ec;
- boost::filesystem::create_hard_link (test, test2, ec);
+ dcp::filesystem::create_hard_link(test, test2, ec);
if (ec) {
can_hard_link = false;
}
- boost::filesystem::remove (test);
- boost::filesystem::remove (test2);
+ dcp::filesystem::remove(test);
+ dcp::filesystem::remove(test2);
}
- auto s = boost::filesystem::space (internal_video_asset_dir ());
+ auto s = dcp::filesystem::space(internal_video_asset_dir());
required = double (required_disk_space ()) / 1073741824.0f;
if (!can_hard_link) {
required *= 2;
/* XXX */
}
-list<DCPTimePeriod>
+
+vector<DCPTimePeriod>
Film::reels () const
{
- list<DCPTimePeriod> p;
+ vector<DCPTimePeriod> periods;
auto const len = length();
switch (reel_type ()) {
case ReelType::SINGLE:
- p.push_back (DCPTimePeriod (DCPTime (), len));
+ periods.emplace_back(DCPTime(), len);
break;
case ReelType::BY_VIDEO_CONTENT:
{
for (auto t: split_points) {
if (last && (t - *last) >= DCPTime::from_seconds(1)) {
/* Period from *last to t is long enough; use it and start a new one */
- p.push_back (DCPTimePeriod(*last, t));
+ periods.emplace_back(*last, t);
last = t;
} else if (!last) {
/* That was the first time, so start a new period */
}
}
- if (!p.empty()) {
- p.back().to = split_points.back();
+ if (!periods.empty()) {
+ periods.back().to = split_points.back();
}
break;
}
Frame const reel_in_frames = max(_reel_length / ((j2k_bandwidth() / video_frame_rate()) / 8), static_cast<Frame>(video_frame_rate()));
while (current < len) {
DCPTime end = min (len, current + DCPTime::from_frames (reel_in_frames, video_frame_rate ()));
- p.push_back (DCPTimePeriod (current, end));
+ periods.emplace_back(current, end);
current = end;
}
break;
}
+ case ReelType::CUSTOM:
+ {
+ DCPTimePeriod current;
+ for (auto boundary: _custom_reel_boundaries) {
+ current.to = boundary;
+ periods.push_back(current);
+ current.from = boundary;
+ }
+ current.to = len;
+ periods.push_back(current);
+ break;
+ }
}
- return p;
+ return periods;
}
+
/** @param period A period within the DCP
* @return Name of the content which most contributes to the given period.
*/
InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path path, bool read)
: _lock (mutex)
- , _file (path, read ? "rb" : (boost::filesystem::exists(path) ? "r+b" : "wb"))
+ , _file(path, read ? "rb" : (dcp::filesystem::exists(path) ? "r+b" : "wb"))
{
if (!_file) {
- throw OpenFileError (path, errno, read ? OpenFileError::READ : (boost::filesystem::exists(path) ? OpenFileError::READ_WRITE : OpenFileError::WRITE));
+ throw OpenFileError(path, errno, read ? OpenFileError::READ : (dcp::filesystem::exists(path) ? OpenFileError::READ_WRITE : OpenFileError::WRITE));
}
}
return our_micro < micro;
}
+
+void
+Film::set_territory_type(TerritoryType type)
+{
+ FilmChangeSignaller ch(this, FilmProperty::TERRITORY_TYPE);
+ _territory_type = type;
+}
+
+
+void
+Film::set_ui_state(string key, string value)
+{
+ _ui_state[key] = value;
+ write_ui_state();
+}
+
+
+boost::optional<std::string>
+Film::ui_state(string key) const
+{
+ auto iter = _ui_state.find(key);
+ if (iter == _ui_state.end()) {
+ return {};
+ }
+
+ return iter->second;
+}
+
+
+void
+Film::write_ui_state() const
+{
+ auto doc = make_shared<xmlpp::Document>();
+ auto root = doc->create_root_node("UI");
+
+ for (auto state: _ui_state) {
+ cxml::add_text_child(root, state.first, state.second);
+ }
+
+ try {
+ doc->write_to_file_formatted(dcp::filesystem::fix_long_path(file(ui_state_file)).string());
+ } catch (...) {}
+}
+
+
+void
+Film::read_ui_state()
+{
+ try {
+ cxml::Document xml("UI");
+ xml.read_file(dcp::filesystem::fix_long_path(file(ui_state_file)));
+ for (auto node: xml.node_children()) {
+ if (!node->is_text()) {
+ _ui_state[node->name()] = node->content();
+ }
+ }
+ } catch (...) {}
+}