+2013-10-22 Carl Hetherington <cth@carlh.net>
+
+ * Allow films to be loaded when content is missing,
+ and then that content can be re-found.
+
2013-10-21 Carl Hetherington <cth@carlh.net>
* Version 1.19 released.
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)
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);
+}
+
+
class ContentProperty
{
public:
+ static int const PATH;
static int const POSITION;
static int const LENGTH;
static int const TRIM_START;
virtual std::string identifier () const;
boost::shared_ptr<Content> clone () const;
+
+ void set_path (boost::filesystem::path);
boost::filesystem::path path () const {
boost::mutex::scoped_lock lm (_mutex);
return _path;
}
+ bool path_valid () const;
+
/** @return MD5 digest of the content's file(s) */
std::string digest () const {
boost::mutex::scoped_lock lm (_mutex);
#include "still_image_content.h"
#include "moving_image_content.h"
#include "sndfile_content.h"
+#include "util.h"
using std::string;
using boost::shared_ptr;
return content;
}
+
+shared_ptr<Content>
+content_factory (shared_ptr<const Film> film, boost::filesystem::path path)
+{
+ shared_ptr<Content> content;
+
+ if (valid_image_file (path)) {
+ content.reset (new StillImageContent (film, path));
+ } else if (SndfileContent::valid_file (path)) {
+ content.reset (new SndfileContent (film, path));
+ } else {
+ content.reset (new FFmpegContent (film, path));
+ }
+
+ return content;
+}
class Film;
extern boost::shared_ptr<Content> content_factory (boost::shared_ptr<const Film>, boost::shared_ptr<cxml::Node>);
+extern boost::shared_ptr<Content> content_factory (boost::shared_ptr<const Film>, boost::filesystem::path);
return _playlist->best_dcp_frame_rate ();
}
+bool
+Film::content_paths_valid () const
+{
+ return _playlist->content_paths_valid ();
+}
+
void
Film::playlist_content_changed (boost::weak_ptr<Content> c, int p)
{
/* Proxies for some Playlist methods */
ContentList content () const;
-
Time length () const;
bool has_subtitles () const;
OutputVideoFrame best_video_frame_rate () const;
+ bool content_paths_valid () const;
libdcp::KDM
make_kdm (
property == VideoContentProperty::VIDEO_RATIO
) {
+ Changed (frequent);
+
+ } else if (property == ContentProperty::PATH) {
+
Changed (frequent);
}
}
Changed ();
}
+
+bool
+Playlist::content_paths_valid () const
+{
+ for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+ if (!(*i)->path_valid ()) {
+ return false;
+ }
+ }
+
+ return true;
+}
void repeat (ContentList, int);
+ bool content_paths_valid () const;
+
mutable boost::signals2::signal<void ()> Changed;
/** Third parameter is true if signals are currently being emitted frequently */
mutable boost::signals2::signal<void (boost::weak_ptr<Content>, int, bool)> ContentChanged;
*/
#include <wx/wx.h>
+#include <wx/dirdlg.h>
#include "lib/playlist.h"
#include "lib/film.h"
+#include "lib/moving_image_content.h"
+#include "lib/content_factory.h"
+#include "lib/examine_content_job.h"
+#include "lib/job_manager.h"
#include "content_menu.h"
#include "repeat_dialog.h"
+#include "wx_util.h"
using std::cout;
using boost::shared_ptr;
+using boost::weak_ptr;
+using boost::dynamic_pointer_cast;
enum {
ID_repeat = 1,
+ ID_find_missing,
ID_remove
};
, _film (f)
, _parent (p)
{
- _menu->Append (ID_repeat, _("Repeat..."));
+ _repeat = _menu->Append (ID_repeat, _("Repeat..."));
+ _find_missing = _menu->Append (ID_find_missing, _("Find missing..."));
_menu->AppendSeparator ();
- _menu->Append (ID_remove, _("Remove"));
+ _remove = _menu->Append (ID_remove, _("Remove"));
- _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, &ContentMenu::repeat, this, ID_repeat);
- _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, &ContentMenu::remove, this, ID_remove);
+ _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&ContentMenu::repeat, this), ID_repeat);
+ _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&ContentMenu::find_missing, this), ID_find_missing);
+ _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&ContentMenu::remove, this), ID_remove);
}
ContentMenu::~ContentMenu ()
ContentMenu::popup (ContentList c, wxPoint p)
{
_content = c;
+ _repeat->Enable (!_content.empty ());
+ _find_missing->Enable (_content.size() == 1 && !_content.front()->path_valid ());
+ _remove->Enable (!_content.empty ());
_parent->PopupMenu (_menu, p);
}
void
-ContentMenu::repeat (wxCommandEvent &)
+ContentMenu::repeat ()
{
if (_content.empty ()) {
return;
}
- RepeatDialog d (_parent);
- d.ShowModal ();
+ RepeatDialog* d = new RepeatDialog (_parent);
+ if (d->ShowModal() != wxID_OK) {
+ d->Destroy ();
+ return;
+ }
shared_ptr<const Film> film = _film.lock ();
if (!film) {
return;
}
- film->playlist()->repeat (_content, d.number ());
- d.Destroy ();
+ film->playlist()->repeat (_content, d->number ());
+ d->Destroy ();
_content.clear ();
}
void
-ContentMenu::remove (wxCommandEvent &)
+ContentMenu::remove ()
{
if (_content.empty ()) {
return;
_content.clear ();
}
+void
+ContentMenu::find_missing ()
+{
+ if (_content.size() != 1) {
+ return;
+ }
+
+ shared_ptr<const Film> film = _film.lock ();
+ if (!film) {
+ return;
+ }
+
+ shared_ptr<Content> content;
+
+ /* XXX: a bit nasty */
+ if (dynamic_pointer_cast<MovingImageContent> (_content.front ())) {
+ wxDirDialog* d = new wxDirDialog (0, _("Choose a folder"), wxT (""), wxDD_DIR_MUST_EXIST);
+ int const r = d->ShowModal ();
+ if (r == wxID_OK) {
+ content.reset (new MovingImageContent (film, boost::filesystem::path (wx_to_std (d->GetPath ()))));
+ }
+ d->Destroy ();
+ } else {
+ wxFileDialog* d = new wxFileDialog (0, _("Choose a file"), wxT (""), wxT (""), wxT ("*.*"), wxFD_MULTIPLE);
+ int const r = d->ShowModal ();
+ if (r == wxID_OK) {
+ content = content_factory (film, wx_to_std (d->GetPath ()));
+ }
+ d->Destroy ();
+ }
+
+ if (!content) {
+ return;
+ }
+
+ shared_ptr<Job> j (new ExamineContentJob (film, content));
+
+ j->Finished.connect (
+ bind (
+ &ContentMenu::maybe_found_missing,
+ this,
+ boost::weak_ptr<Job> (j),
+ boost::weak_ptr<Content> (_content.front ()),
+ boost::weak_ptr<Content> (content)
+ )
+ );
+
+ JobManager::instance()->add (j);
+}
+
+void
+ContentMenu::maybe_found_missing (weak_ptr<Job> j, weak_ptr<Content> oc, weak_ptr<Content> nc)
+{
+ shared_ptr<Job> job = j.lock ();
+ if (!job || !job->finished_ok ()) {
+ return;
+ }
+
+ shared_ptr<Content> old_content = oc.lock ();
+ shared_ptr<Content> new_content = nc.lock ();
+ assert (old_content);
+ assert (new_content);
+
+ if (new_content->digest() != old_content->digest()) {
+ error_dialog (0, _("The content file(s) you specified are not the same as those that are missing. Either try again with the correct content file or remove the missing content."));
+ return;
+ }
+
+ old_content->set_path (new_content->path ());
+}
void popup (ContentList, wxPoint);
private:
- void repeat (wxCommandEvent &);
- void remove (wxCommandEvent &);
+ void repeat ();
+ void find_missing ();
+ void remove ();
+ void maybe_found_missing (boost::weak_ptr<Job>, boost::weak_ptr<Content>, boost::weak_ptr<Content>);
wxMenu* _menu;
boost::weak_ptr<Film> _film;
wxWindow* _parent;
ContentList _content;
+ wxMenuItem* _repeat;
+ wxMenuItem* _find_missing;
+ wxMenuItem* _remove;
};
#endif
#include "lib/sound_processor.h"
#include "lib/scaler.h"
#include "lib/playlist.h"
+#include "lib/content.h"
+#include "lib/content_factory.h"
#include "timecode.h"
#include "wx_util.h"
#include "film_editor.h"
if (property == FFmpegContentProperty::AUDIO_STREAM) {
setup_dcp_name ();
+ } else if (property == ContentProperty::PATH) {
+ setup_content ();
}
}
ContentList content = _film->content ();
for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
int const t = _content->GetItemCount ();
- _content->InsertItem (t, std_to_wx ((*i)->summary ()));
+ bool const valid = (*i)->path_valid ();
+
+ string s = (*i)->summary ();
+ if (!valid) {
+ s = _("MISSING: ") + s;
+ }
+
+ _content->InsertItem (t, std_to_wx (s));
+
if ((*i)->summary() == selected_summary) {
_content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
}
+
+ if (!valid) {
+ _content->SetItemTextColour (t, *wxRED);
+ }
}
if (selected_summary.empty () && !content.empty ()) {
/* XXX: check for lots of files here and do something */
for (unsigned int i = 0; i < paths.GetCount(); ++i) {
- boost::filesystem::path p (wx_to_std (paths[i]));
-
- shared_ptr<Content> c;
-
- if (valid_image_file (p)) {
- c.reset (new StillImageContent (_film, p));
- } else if (SndfileContent::valid_file (p)) {
- c.reset (new SndfileContent (_film, p));
- } else {
- c.reset (new FFmpegContent (_film, p));
- }
-
- _film->examine_and_add_content (c);
+ _film->examine_and_add_content (content_factory (_film, wx_to_std (paths[i])));
}
}
FilmEditor::content_right_click (wxListEvent& ev)
{
ContentList cl;
- cl.push_back (selected_content ());
+ if (selected_content ()) {
+ cl.push_back (selected_content ());
+ }
_menu.popup (cl, ev.GetPoint ());
}
_play_button->SetValue (false);
check_play_state ();
error_dialog (this, wxString::Format (_("Could not decode video for view (%s)"), std_to_wx(e.what()).data()));
+ } catch (OpenFileError& e) {
+ /* There was a problem opening a content file; we'll let this slide as it
+ probably means a missing content file, which we're already taking care of.
+ */
}
}