Rest of src/lib/*.h tidying.
[dcpomatic.git] / src / wx / content_menu.cc
index 3cf9f23dcf636f2544fe7edf1668bb2fcee524b4..a1d412b62ea6344a61c3e6d6d1b5b20aeb266e36 100644 (file)
 #include "lib/job_manager.h"
 #include "lib/exceptions.h"
 #include "lib/dcp_content.h"
+#include "lib/ffmpeg_content.h"
 #include <wx/wx.h>
 #include <wx/dirdlg.h>
 
 using std::cout;
 using std::vector;
+using std::exception;
 using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
@@ -91,9 +93,9 @@ ContentMenu::popup (weak_ptr<Film> film, ContentList c, TimelineContentViewList
                        ++n;
                }
        }
-       
+
        _join->Enable (n > 1);
-       
+
        _find_missing->Enable (_content.size() == 1 && !_content.front()->paths_valid ());
        _properties->Enable (_content.size() == 1);
        _re_examine->Enable (!_content.empty ());
@@ -104,7 +106,7 @@ ContentMenu::popup (weak_ptr<Film> film, ContentList c, TimelineContentViewList
        } else {
                _kdm->Enable (false);
        }
-       
+
        _remove->Enable (!_content.empty ());
        _parent->PopupMenu (_menu, p);
 }
@@ -115,7 +117,7 @@ ContentMenu::repeat ()
        if (_content.empty ()) {
                return;
        }
-               
+
        RepeatDialog* d = new RepeatDialog (_parent);
        if (d->ShowModal() != wxID_OK) {
                d->Destroy ();
@@ -186,7 +188,7 @@ ContentMenu::remove ()
                        if (!fc) {
                                continue;
                        }
-                       
+
                        shared_ptr<TimelineVideoContentView> video;
                        shared_ptr<TimelineAudioContentView> audio;
 
@@ -228,33 +230,38 @@ ContentMenu::find_missing ()
        if (!film) {
                return;
        }
-       
+
        shared_ptr<Content> content;
 
        /* XXX: a bit nasty */
        shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (_content.front ());
-       if (ic && !ic->still ()) {
+       shared_ptr<DCPContent> dc = dynamic_pointer_cast<DCPContent> (_content.front ());
+
+       int r = wxID_CANCEL;
+       boost::filesystem::path path;
+
+       if ((ic && !ic->still ()) || dc) {
                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 ImageContent (film, boost::filesystem::path (wx_to_std (d->GetPath ()))));
-               }
+               r = d->ShowModal ();
+               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 ()));
-               }
+               r = d->ShowModal ();
+               path = wx_to_std (d->GetPath ());
                d->Destroy ();
        }
 
+       if (r == wxID_OK) {
+               content = content_factory (film, path);
+       }
+
        if (!content) {
                return;
        }
 
        shared_ptr<Job> j (new ExamineContentJob (film, content));
-       
+
        _job_connection = j->Finished.connect (
                bind (
                        &ContentMenu::maybe_found_missing,
@@ -264,7 +271,7 @@ ContentMenu::find_missing ()
                        boost::weak_ptr<Content> (content)
                        )
                );
-       
+
        JobManager::instance()->add (j);
 }
 
@@ -308,16 +315,23 @@ ContentMenu::kdm ()
        DCPOMATIC_ASSERT (!_content.empty ());
        shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (_content.front ());
        DCPOMATIC_ASSERT (dcp);
-       
+
        wxFileDialog* d = new wxFileDialog (_parent, _("Select KDM"));
-               
+
        if (d->ShowModal() == wxID_OK) {
-               dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()))));
+               try {
+                       dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()))));
+               } catch (exception& e) {
+                       error_dialog (_parent, wxString::Format (_("Could not load KDM (%s)"), e.what ()));
+                       d->Destroy ();
+                       return;
+               }
+
                shared_ptr<Film> film = _film.lock ();
                DCPOMATIC_ASSERT (film);
                film->examine_content (dcp);
        }
-       
+
        d->Destroy ();
 }