Remove all use of add_child() from xmlpp.
[dcpomatic.git] / src / lib / dkdm_wrapper.cc
index 532bbb314f9a4ba9aa5c089097b8cc6bceafcf91..4c7838a8d0ceba65cb5768c017ef7944e6c1edac 100644 (file)
@@ -41,7 +41,11 @@ DKDMBase::read (cxml::ConstNodePtr node)
        if (node->name() == "DKDM") {
                return make_shared<DKDM>(dcp::EncryptedKDM(node->content()));
        } else if (node->name() == "DKDMGroup") {
-               auto group = make_shared<DKDMGroup>(node->string_attribute("Name"));
+               auto name = node->optional_string_attribute("Name");
+               if (!name) {
+                       name = node->string_attribute("name");
+               }
+               auto group = make_shared<DKDMGroup>(*name);
                for (auto i: node->node_children()) {
                        if (auto c = read(i)) {
                                group->add (c);
@@ -62,17 +66,17 @@ DKDM::name () const
 
 
 void
-DKDM::as_xml (xmlpp::Element* node) const
+DKDM::as_xml(xmlpp::Element* element) const
 {
-       node->add_child("DKDM")->add_child_text (_dkdm.as_xml ());
+       cxml::add_text_child(element, "DKDM", _dkdm.as_xml());
 }
 
 
 void
-DKDMGroup::as_xml (xmlpp::Element* node) const
+DKDMGroup::as_xml(xmlpp::Element* element) const
 {
-       auto f = node->add_child("DKDMGroup");
-       f->set_attribute ("Name", _name);
+       auto f = cxml::add_child(element, "DKDMGroup");
+       f->set_attribute("name", _name);
        for (auto i: _children) {
                i->as_xml (f);
        }
@@ -111,3 +115,35 @@ DKDMGroup::remove (shared_ptr<DKDMBase> child)
                }
        }
 }
+
+
+bool
+DKDMGroup::contains(string dkdm_id) const
+{
+       for (auto child: _children) {
+               if (auto child_group = dynamic_pointer_cast<DKDMGroup>(child)) {
+                       if (child_group->contains(dkdm_id)) {
+                               return true;
+                       }
+               } else if (auto child_dkdm = dynamic_pointer_cast<DKDM>(child)) {
+                       if (child_dkdm->dkdm().id() == dkdm_id) {
+                               return true;
+                       }
+               }
+       }
+
+       return false;
+}
+
+
+bool
+DKDMGroup::contains_dkdm() const
+{
+       for (auto child: _children) {
+               if (child->contains_dkdm()) {
+                       return true;
+               }
+       }
+
+       return false;
+}