Use cxml::NodePtr.
[dcpomatic.git] / src / lib / content.cc
index 9508144913bc5af335358d54b1e20e806381898e..a41261998671d3083f54c3fd5c921ddeba7de89e 100644 (file)
 #include "ui_signaller.h"
 
 using std::string;
+using std::stringstream;
 using std::set;
 using boost::shared_ptr;
 using boost::lexical_cast;
 
-int const ContentProperty::POSITION = 400;
-int const ContentProperty::LENGTH = 401;
-int const ContentProperty::TRIM_START = 402;
-int const ContentProperty::TRIM_END = 403;
+int const ContentProperty::PATH = 400;
+int const ContentProperty::POSITION = 401;
+int const ContentProperty::LENGTH = 402;
+int const ContentProperty::TRIM_START = 403;
+int const ContentProperty::TRIM_END = 404;
 
 Content::Content (shared_ptr<const Film> f, Time p)
        : _film (f)
@@ -71,6 +73,7 @@ void
 Content::as_xml (xmlpp::Node* node) const
 {
        boost::mutex::scoped_lock lm (_mutex);
+       
        node->add_child("Path")->add_child_text (_path.string());
        node->add_child("Digest")->add_child_text (_digest);
        node->add_child("Position")->add_child_text (lexical_cast<string> (_position));
@@ -79,16 +82,20 @@ Content::as_xml (xmlpp::Node* node) const
 }
 
 void
-Content::examine (shared_ptr<Job>)
+Content::examine (shared_ptr<Job> job)
 {
+       boost::mutex::scoped_lock lm (_mutex);
+       boost::filesystem::path p = _path;
+       lm.unlock ();
+       
        string d;
-       if (boost::filesystem::is_regular_file (_path)) {
-               d = md5_digest (_path);
+       if (boost::filesystem::is_regular_file (p)) {
+               d = md5_digest (p);
        } else {
-               d = md5_digest_directory (_path);
+               d = md5_digest_directory (p, job);
        }
-       
-       boost::mutex::scoped_lock lm (_mutex);
+
+       lm.lock ();
        _digest = d;
 }
 
@@ -146,7 +153,7 @@ Content::clone () const
        xmlpp::Document doc;
        xmlpp::Node* node = doc.create_root_node ("Content");
        as_xml (node);
-       return content_factory (film, shared_ptr<cxml::Node> (new cxml::Node (node)));
+       return content_factory (film, cxml::NodePtr(new cxml::Node (node)));
 }
 
 string
@@ -158,7 +165,7 @@ Content::technical_summary () const
 Time
 Content::length_after_trim () const
 {
-       return full_length () - _trim_start - _trim_end;
+       return full_length() - trim_start() - trim_end();
 }
 
 /** @param t A time relative to the start of this content (not the position).
@@ -169,3 +176,34 @@ Content::trimmed (Time t) const
 {
        return (t < trim_start() || t > (full_length() - trim_end ()));
 }
+
+/** @return string which includes everything about how this content affects
+ *  its playlist.
+ */
+string
+Content::identifier () const
+{
+       stringstream s;
+       
+       s << Content::digest()
+         << "_" << position()
+         << "_" << trim_start()
+         << "_" << trim_end();
+
+       return s.str ();
+}
+
+bool
+Content::path_valid () const
+{
+       return boost::filesystem::exists (_path);
+}
+
+void
+Content::set_path (boost::filesystem::path path)
+{
+       _path = path;
+       signal_changed (ContentProperty::PATH);
+}
+
+