Use FileGroup in FFmpeg.
[dcpomatic.git] / src / lib / content.cc
index 44b52a4715597a68025a9052f939756573d2f5ba..16069b7a7967b52a1200c40d241e2a6e91ff20eb 100644 (file)
 #include "ui_signaller.h"
 
 using std::string;
+using std::stringstream;
 using std::set;
+using std::cout;
 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)
+       : _film (f)
+       , _position (0)
+       , _trim_start (0)
+       , _trim_end (0)
+       , _change_signals_frequent (false)
+{
+
+}
 
 Content::Content (shared_ptr<const Film> f, Time p)
        : _film (f)
@@ -47,20 +60,19 @@ Content::Content (shared_ptr<const Film> f, Time p)
 
 Content::Content (shared_ptr<const Film> f, boost::filesystem::path p)
        : _film (f)
-       , _path (p)
        , _position (0)
        , _trim_start (0)
        , _trim_end (0)
        , _change_signals_frequent (false)
 {
-
+       _paths.push_back (p);
 }
 
 Content::Content (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
        : _film (f)
        , _change_signals_frequent (false)
 {
-       _path = node->string_child ("Path");
+       _paths.push_back (node->string_child ("Path"));
        _digest = node->string_child ("Digest");
        _position = node->number_child<Time> ("Position");
        _trim_start = node->number_child<Time> ("TrimStart");
@@ -72,7 +84,7 @@ 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("Path")->add_child_text (_paths.front().string());
        node->add_child("Digest")->add_child_text (_digest);
        node->add_child("Position")->add_child_text (lexical_cast<string> (_position));
        node->add_child("TrimStart")->add_child_text (lexical_cast<string> (_trim_start));
@@ -80,17 +92,17 @@ 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;
+       boost::filesystem::path p = _paths.front ();
        lm.unlock ();
        
        string d;
        if (boost::filesystem::is_regular_file (p)) {
                d = md5_digest (p);
        } else {
-               d = md5_digest_directory (p);
+               d = md5_digest_directory (p, job);
        }
 
        lm.lock ();
@@ -151,13 +163,13 @@ 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
 Content::technical_summary () const
 {
-       return String::compose ("%1 %2 %3", path(), digest(), position());
+       return String::compose ("%1 %2 %3", path_summary(), digest(), position());
 }
 
 Time
@@ -174,3 +186,46 @@ 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 (_paths.front ());
+}
+
+void
+Content::set_path (boost::filesystem::path path)
+{
+       _paths.clear ();
+       _paths.push_back (path);
+       signal_changed (ContentProperty::PATH);
+}
+
+string
+Content::path_summary () const
+{
+       /* XXX: should handle multiple paths more gracefully */
+
+       string s = path(0).filename().string ();
+       if (number_of_paths() > 1) {
+               s += " ...";
+       }
+
+       return s;
+}