2 Copyright (C) 2017-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "compose.hpp"
23 #include "dkdm_wrapper.h"
24 #include "dcpomatic_assert.h"
25 #include <dcp/warnings.h>
26 LIBDCP_DISABLE_WARNINGS
27 #include <libxml++/libxml++.h>
28 LIBDCP_ENABLE_WARNINGS
33 using std::shared_ptr;
34 using std::make_shared;
35 using std::dynamic_pointer_cast;
39 DKDMBase::read (cxml::ConstNodePtr node)
41 if (node->name() == "DKDM") {
42 return make_shared<DKDM>(dcp::EncryptedKDM(node->content()));
43 } else if (node->name() == "DKDMGroup") {
44 auto name = node->optional_string_attribute("Name");
46 name = node->string_attribute("name");
48 auto group = make_shared<DKDMGroup>(*name);
49 for (auto i: node->node_children()) {
50 if (auto c = read(i)) {
64 return String::compose ("%1 (%2)", _dkdm.content_title_text(), _dkdm.cpl_id());
69 DKDM::as_xml (xmlpp::Element* node) const
71 node->add_child("DKDM")->add_child_text (_dkdm.as_xml ());
76 DKDMGroup::as_xml (xmlpp::Element* node) const
78 auto f = node->add_child("DKDMGroup");
79 f->set_attribute("name", _name);
80 for (auto i: _children) {
87 DKDMGroup::add (shared_ptr<DKDMBase> child, shared_ptr<DKDM> previous)
89 DCPOMATIC_ASSERT (child);
91 auto i = find (_children.begin(), _children.end(), previous);
92 if (i != _children.end()) {
95 _children.insert (i, child);
97 _children.push_back (child);
99 child->set_parent (dynamic_pointer_cast<DKDMGroup>(shared_from_this()));
104 DKDMGroup::remove (shared_ptr<DKDMBase> child)
106 for (auto i = _children.begin(); i != _children.end(); ++i) {
109 child->set_parent (shared_ptr<DKDMGroup>());
112 auto g = dynamic_pointer_cast<DKDMGroup> (*i);
121 DKDMGroup::contains(string dkdm_id) const
123 for (auto child: _children) {
124 if (auto child_group = dynamic_pointer_cast<DKDMGroup>(child)) {
125 if (child_group->contains(dkdm_id)) {
128 } else if (auto child_dkdm = dynamic_pointer_cast<DKDM>(child)) {
129 if (child_dkdm->dkdm().id() == dkdm_id) {
140 DKDMGroup::contains_dkdm() const
142 for (auto child: _children) {
143 if (child->contains_dkdm()) {