2 Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "content_panel.h"
23 #include "video_panel.h"
24 #include "audio_panel.h"
25 #include "subtitle_panel.h"
26 #include "timing_panel.h"
27 #include "timeline_dialog.h"
28 #include "image_sequence_dialog.h"
29 #include "film_viewer.h"
30 #include "lib/audio_content.h"
31 #include "lib/subtitle_content.h"
32 #include "lib/video_content.h"
33 #include "lib/ffmpeg_content.h"
34 #include "lib/content_factory.h"
35 #include "lib/image_content.h"
36 #include "lib/dcp_content.h"
37 #include "lib/case_insensitive_sorter.h"
38 #include "lib/playlist.h"
40 #include <wx/notebook.h>
41 #include <wx/listctrl.h>
42 #include <boost/filesystem.hpp>
43 #include <boost/foreach.hpp>
51 using boost::shared_ptr;
52 using boost::weak_ptr;
53 using boost::dynamic_pointer_cast;
54 using boost::optional;
56 ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr<Film> film, FilmViewer* viewer)
57 : _timeline_dialog (0)
60 , _film_viewer (viewer)
61 , _generally_sensitive (true)
63 _panel = new wxPanel (n);
64 _sizer = new wxBoxSizer (wxVERTICAL);
65 _panel->SetSizer (_sizer);
67 _menu = new ContentMenu (_panel);
70 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
72 _content = new wxListCtrl (_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER);
73 _content->DragAcceptFiles (true);
74 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
76 _content->InsertColumn (0, wxT(""));
77 _content->SetColumnWidth (0, 512);
79 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
81 _add_file = new wxButton (_panel, wxID_ANY, _("Add file(s)..."));
82 _add_file->SetToolTip (_("Add video, image, sound or subtitle files to the film."));
83 b->Add (_add_file, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
85 _add_folder = new wxButton (_panel, wxID_ANY, _("Add folder..."));
86 _add_folder->SetToolTip (_("Add a folder of image files (which will be used as a moving image sequence) or a folder of sound files."));
87 b->Add (_add_folder, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
89 _add_dcp = new wxButton (_panel, wxID_ANY, _("Add DCP..."));
90 _add_dcp->SetToolTip (_("Add a DCP."));
91 b->Add (_add_dcp, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
93 _remove = new wxButton (_panel, wxID_ANY, _("Remove"));
94 _remove->SetToolTip (_("Remove the selected piece of content from the film."));
95 b->Add (_remove, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
97 _earlier = new wxButton (_panel, wxID_ANY, _("Earlier"));
98 _earlier->SetToolTip (_("Move the selected piece of content earlier in the film."));
99 b->Add (_earlier, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
101 _later = new wxButton (_panel, wxID_ANY, _("Later"));
102 _later->SetToolTip (_("Move the selected piece of content later in the film."));
103 b->Add (_later, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
105 _timeline = new wxButton (_panel, wxID_ANY, _("Timeline..."));
106 _timeline->SetToolTip (_("Open the timeline for the film."));
107 b->Add (_timeline, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
109 s->Add (b, 0, wxALL, 4);
111 _sizer->Add (s, 0, wxEXPAND | wxALL, 6);
114 _notebook = new wxNotebook (_panel, wxID_ANY);
115 _sizer->Add (_notebook, 1, wxEXPAND | wxTOP, 6);
117 _video_panel = new VideoPanel (this);
118 _panels.push_back (_video_panel);
119 _audio_panel = new AudioPanel (this);
120 _panels.push_back (_audio_panel);
121 _subtitle_panel = new SubtitlePanel (this);
122 _panels.push_back (_subtitle_panel);
123 _timing_panel = new TimingPanel (this, _film_viewer);
124 _panels.push_back (_timing_panel);
126 _content->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind (&ContentPanel::selection_changed, this));
127 _content->Bind (wxEVT_LIST_ITEM_DESELECTED, boost::bind (&ContentPanel::selection_changed, this));
128 _content->Bind (wxEVT_LIST_ITEM_RIGHT_CLICK, boost::bind (&ContentPanel::right_click, this, _1));
129 _content->Bind (wxEVT_DROP_FILES, boost::bind (&ContentPanel::files_dropped, this, _1));
130 _add_file->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::add_file_clicked, this));
131 _add_folder->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::add_folder_clicked, this));
132 _add_dcp->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::add_dcp_clicked, this));
133 _remove->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::remove_clicked, this, false));
134 _earlier->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::earlier_clicked, this));
135 _later->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::later_clicked, this));
136 _timeline->Bind (wxEVT_BUTTON, boost::bind (&ContentPanel::timeline_clicked, this));
140 ContentPanel::selected ()
145 s = _content->GetNextItem (s, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
150 if (s < int (_film->content().size ())) {
151 sel.push_back (_film->content()[s]);
159 ContentPanel::selected_video ()
163 BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
173 ContentPanel::selected_audio ()
177 BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
187 ContentPanel::selected_subtitle ()
191 BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
201 ContentPanel::selected_ffmpeg ()
203 FFmpegContentList sc;
205 BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
206 shared_ptr<FFmpegContent> t = dynamic_pointer_cast<FFmpegContent> (i);
216 ContentPanel::film_changed (Film::Property p)
220 case Film::CONTENT_ORDER:
227 BOOST_FOREACH (ContentSubPanel* i, _panels) {
233 ContentPanel::selection_changed ()
235 if (_last_selected == selected()) {
236 /* This was triggered by a re-build of the view but the selection
237 did not really change.
242 _last_selected = selected ();
244 setup_sensitivity ();
246 BOOST_FOREACH (ContentSubPanel* i, _panels) {
247 i->content_selection_changed ();
250 optional<DCPTime> go_to;
251 BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
252 if (!go_to || i->position() < go_to.get()) {
253 go_to = i->position ();
258 _film_viewer->set_position (go_to.get ());
261 if (_timeline_dialog) {
262 _timeline_dialog->set_selection (selected ());
267 ContentPanel::add_file_clicked ()
269 /* This method is also called when Ctrl-A is pressed, so check that our notebook page
272 if (_parent->GetCurrentPage() != _panel) {
276 /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
277 non-Latin filenames or paths.
279 wxFileDialog* d = new wxFileDialog (
281 _("Choose a file or files"),
284 wxT ("All files|*.*|Subtitle files|*.srt;*.xml|Audio files|*.wav;*.w64;*.flac;*.aif;*.aiff"),
285 wxFD_MULTIPLE | wxFD_CHANGE_DIR
288 int const r = d->ShowModal ();
297 list<boost::filesystem::path> path_list;
298 for (unsigned int i = 0; i < paths.GetCount(); ++i) {
299 path_list.push_back (wx_to_std (paths[i]));
301 add_files (path_list);
307 ContentPanel::add_folder_clicked ()
309 wxDirDialog* d = new wxDirDialog (_panel, _("Choose a folder"), wxT (""), wxDD_DIR_MUST_EXIST);
310 int r = d->ShowModal ();
311 boost::filesystem::path const path (wx_to_std (d->GetPath ()));
318 list<shared_ptr<Content> > content;
321 content = content_factory (_film, path);
322 } catch (exception& e) {
323 error_dialog (_parent, e.what());
327 if (content.empty ()) {
328 error_dialog (_parent, _("No content found in this folder."));
332 BOOST_FOREACH (shared_ptr<Content> i, content) {
333 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (i);
335 ImageSequenceDialog* e = new ImageSequenceDialog (_panel);
337 float const frame_rate = e->frame_rate ();
344 ic->set_video_frame_rate (frame_rate);
347 _film->examine_and_add_content (i);
352 ContentPanel::add_dcp_clicked ()
354 wxDirDialog* d = new wxDirDialog (_panel, _("Choose a DCP folder"), wxT (""), wxDD_DIR_MUST_EXIST);
355 int r = d->ShowModal ();
356 boost::filesystem::path const path (wx_to_std (d->GetPath ()));
364 _film->examine_and_add_content (shared_ptr<Content> (new DCPContent (_film, path)));
365 } catch (exception& e) {
366 error_dialog (_parent, e.what());
370 /** @return true if this remove "click" should be ignored */
372 ContentPanel::remove_clicked (bool hotkey)
374 /* If the method was called because Delete was pressed check that our notebook page
375 is visible and that the content list is focussed.
377 if (hotkey && (_parent->GetCurrentPage() != _panel || !_content->HasFocus())) {
381 BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
382 _film->remove_content (i);
385 selection_changed ();
390 ContentPanel::timeline_clicked ()
392 if (_timeline_dialog) {
393 _timeline_dialog->Destroy ();
394 _timeline_dialog = 0;
397 _timeline_dialog = new TimelineDialog (this, _film);
398 _timeline_dialog->Show ();
402 ContentPanel::right_click (wxListEvent& ev)
404 _menu->popup (_film, selected (), TimelineContentViewList (), ev.GetPoint ());
407 /** Set up broad sensitivity based on the type of content that is selected */
409 ContentPanel::setup_sensitivity ()
411 _add_file->Enable (_generally_sensitive);
412 _add_folder->Enable (_generally_sensitive);
413 _add_dcp->Enable (_generally_sensitive);
415 ContentList selection = selected ();
416 ContentList video_selection = selected_video ();
417 ContentList audio_selection = selected_audio ();
419 _remove->Enable (!selection.empty() && _generally_sensitive);
420 _earlier->Enable (selection.size() == 1 && _generally_sensitive);
421 _later->Enable (selection.size() == 1 && _generally_sensitive);
422 _timeline->Enable (!_film->content().empty() && _generally_sensitive);
424 _video_panel->Enable (video_selection.size() > 0 && _generally_sensitive);
425 _audio_panel->Enable (audio_selection.size() > 0 && _generally_sensitive);
426 _subtitle_panel->Enable (selection.size() == 1 && selection.front()->subtitle && _generally_sensitive);
427 _timing_panel->Enable (_generally_sensitive);
431 ContentPanel::set_film (shared_ptr<Film> film)
433 _audio_panel->set_film (film);
437 film_changed (Film::CONTENT);
438 film_changed (Film::AUDIO_CHANNELS);
439 selection_changed ();
440 setup_sensitivity ();
444 ContentPanel::set_general_sensitivity (bool s)
446 _generally_sensitive = s;
448 _content->Enable (s);
449 _add_file->Enable (s);
450 _add_folder->Enable (s);
451 _add_dcp->Enable (s);
453 _earlier->Enable (s);
455 _timeline->Enable (s);
457 /* Set the panels in the content notebook */
458 BOOST_FOREACH (ContentSubPanel* i, _panels) {
464 ContentPanel::earlier_clicked ()
466 ContentList sel = selected ();
467 if (sel.size() == 1) {
468 _film->move_content_earlier (sel.front ());
469 selection_changed ();
474 ContentPanel::later_clicked ()
476 ContentList sel = selected ();
477 if (sel.size() == 1) {
478 _film->move_content_later (sel.front ());
479 selection_changed ();
484 ContentPanel::set_selection (weak_ptr<Content> wc)
486 ContentList content = _film->content ();
487 for (size_t i = 0; i < content.size(); ++i) {
488 if (content[i] == wc.lock ()) {
489 _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
491 _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
497 ContentPanel::set_selection (ContentList cl)
499 ContentList content = _film->content ();
500 for (size_t i = 0; i < content.size(); ++i) {
501 if (find(cl.begin(), cl.end(), content[i]) != cl.end()) {
502 _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
504 _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
510 ContentPanel::film_content_changed (int property)
513 property == ContentProperty::PATH ||
514 property == DCPContentProperty::NEEDS_ASSETS ||
515 property == DCPContentProperty::NEEDS_KDM ||
516 property == DCPContentProperty::NAME
522 BOOST_FOREACH (ContentSubPanel* i, _panels) {
523 i->film_content_changed (property);
528 ContentPanel::setup ()
530 ContentList content = _film->content ();
532 Content* selected_content = 0;
533 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
537 item.SetMask (wxLIST_MASK_DATA);
538 _content->GetItem (item);
539 selected_content = reinterpret_cast<Content*> (item.GetData ());
542 _content->DeleteAllItems ();
544 BOOST_FOREACH (shared_ptr<Content> i, content) {
545 int const t = _content->GetItemCount ();
546 bool const valid = i->paths_valid ();
547 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (i);
548 bool const needs_kdm = dcp && dcp->needs_kdm ();
549 bool const needs_assets = dcp && dcp->needs_assets ();
551 wxString s = std_to_wx (i->summary ());
554 s = _("MISSING: ") + s;
558 s = _("NEEDS KDM: ") + s;
562 s = _("NEEDS OV: ") + s;
568 item.SetData (i.get ());
569 _content->InsertItem (item);
571 if (i.get() == selected_content) {
572 _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
575 if (!valid || needs_kdm || needs_assets) {
576 _content->SetItemTextColour (t, *wxRED);
580 if (!selected_content && !content.empty ()) {
581 /* Select the item of content if none was selected before */
582 _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
587 ContentPanel::files_dropped (wxDropFilesEvent& event)
593 wxString* paths = event.GetFiles ();
594 list<boost::filesystem::path> path_list;
595 for (int i = 0; i < event.GetNumberOfFiles(); i++) {
596 path_list.push_back (wx_to_std (paths[i]));
599 add_files (path_list);
603 ContentPanel::add_files (list<boost::filesystem::path> paths)
605 /* It has been reported that the paths returned from e.g. wxFileDialog are not always sorted;
606 I can't reproduce that, but sort them anyway. Don't use ImageFilenameSorter as a normal
607 alphabetical sort is expected here.
610 paths.sort (CaseInsensitiveSorter ());
612 /* XXX: check for lots of files here and do something */
614 BOOST_FOREACH (boost::filesystem::path i, paths) {
615 BOOST_FOREACH (shared_ptr<Content> j, content_factory (_film, i)) {
616 _film->examine_and_add_content (j);