diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-12-22 17:02:43 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-01-28 02:01:58 +0100 |
| commit | 1889bd28b5e5fcef7607b26f184ceba3f3076b2c (patch) | |
| tree | f659b81b5eac00138c035fb2f8621ac7aa882b2c /src/lib | |
| parent | e9285246f543248eec88627ce61a3ccafd6f3ac2 (diff) | |
Remember whether Content or DCP is selected in a new ui.xml state file.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/film.cc | 51 | ||||
| -rw-r--r-- | src/lib/film.h | 7 |
2 files changed, 58 insertions, 0 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc index 871ec76b8..c56cd36df 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -114,6 +114,7 @@ using namespace dcpomatic; static constexpr char metadata_file[] = "metadata.xml"; +static constexpr char ui_state_file[] = "ui.xml"; /* 5 -> 6 @@ -2231,3 +2232,53 @@ Film::set_territory_type(TerritoryType 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) { + root->add_child(state.first)->add_child_text(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 (...) {} +} diff --git a/src/lib/film.h b/src/lib/film.h index 43a41ad45..036bbed7e 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -434,6 +434,10 @@ public: void add_ffoc_lfoc (Markers& markers) const; + void set_ui_state(std::string key, std::string value); + boost::optional<std::string> ui_state(std::string key) const; + void read_ui_state(); + /** Emitted when some property has of the Film is about to change or has changed */ mutable boost::signals2::signal<void (ChangeType, FilmProperty)> Change; @@ -477,6 +481,7 @@ private: void check_settings_consistency (); void maybe_set_container_and_resolution (); void set_dirty (bool dirty); + void write_ui_state() const; /** Log to write to */ std::shared_ptr<Log> _log; @@ -562,6 +567,8 @@ private: */ bool _tolerant; + std::map<std::string, std::string> _ui_state; + mutable boost::mutex _info_file_mutex; boost::signals2::scoped_connection _playlist_change_connection; |
