2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/thread/mutex.hpp>
21 #include <libxml++/libxml++.h>
22 #include <libcxml/cxml.h>
25 #include "content_factory.h"
26 #include "ui_signaller.h"
30 using boost::shared_ptr;
31 using boost::lexical_cast;
33 int const ContentProperty::POSITION = 400;
34 int const ContentProperty::LENGTH = 401;
35 int const ContentProperty::TRIM_START = 402;
36 int const ContentProperty::TRIM_END = 403;
38 Content::Content (shared_ptr<const Film> f, Time p)
43 , _change_signals_frequent (false)
48 Content::Content (shared_ptr<const Film> f, boost::filesystem::path p)
54 , _change_signals_frequent (false)
59 Content::Content (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
61 , _change_signals_frequent (false)
63 _path = node->string_child ("Path");
64 _digest = node->string_child ("Digest");
65 _position = node->number_child<Time> ("Position");
66 _trim_start = node->number_child<Time> ("TrimStart");
67 _trim_end = node->number_child<Time> ("TrimEnd");
71 Content::as_xml (xmlpp::Node* node) const
73 boost::mutex::scoped_lock lm (_mutex);
74 node->add_child("Path")->add_child_text (_path.string());
75 node->add_child("Digest")->add_child_text (_digest);
76 node->add_child("Position")->add_child_text (lexical_cast<string> (_position));
77 node->add_child("TrimStart")->add_child_text (lexical_cast<string> (_trim_start));
78 node->add_child("TrimEnd")->add_child_text (lexical_cast<string> (_trim_end));
82 Content::examine (shared_ptr<Job>)
85 if (boost::filesystem::is_regular_file (_path)) {
86 d = md5_digest (_path);
88 d = md5_digest_directory (_path);
91 boost::mutex::scoped_lock lm (_mutex);
96 Content::signal_changed (int p)
99 ui_signaller->emit (boost::bind (boost::ref (Changed), shared_from_this (), p, _change_signals_frequent));
104 Content::set_position (Time p)
107 boost::mutex::scoped_lock lm (_mutex);
111 signal_changed (ContentProperty::POSITION);
115 Content::set_trim_start (Time t)
118 boost::mutex::scoped_lock lm (_mutex);
122 signal_changed (ContentProperty::TRIM_START);
126 Content::set_trim_end (Time t)
129 boost::mutex::scoped_lock lm (_mutex);
133 signal_changed (ContentProperty::TRIM_END);
138 Content::clone () const
140 shared_ptr<const Film> film = _film.lock ();
142 return shared_ptr<Content> ();
145 /* This is a bit naughty, but I can't think of a compelling reason not to do it ... */
147 xmlpp::Node* node = doc.create_root_node ("Content");
149 return content_factory (film, shared_ptr<cxml::Node> (new cxml::Node (node)));
153 Content::technical_summary () const
155 return String::compose ("%1 %2 %3", path(), digest(), position());
159 Content::length_after_trim () const
161 return full_length () - _trim_start - _trim_end;
164 /** @param t A time relative to the start of this content (not the position).
165 * @return true if this time is trimmed by our trim settings.
168 Content::trimmed (Time t) const
170 return (t < trim_start() || t > (full_length() - trim_end ()));