Hand-apply c165ea8ccadf5bb8c4401a23bb2e998fabdc8a9b from master.
[dcpomatic.git] / src / wx / content_panel.cc
index 23b531b47e6d5c59acaacad3afd7f85a123443d1..30c03538b05ee4512ca69229b3d0c0655acb9898 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -35,6 +35,7 @@
 #include "subtitle_panel.h"
 #include "timing_panel.h"
 #include "timeline_dialog.h"
+#include "image_sequence_dialog.h"
 
 using std::list;
 using std::string;
@@ -69,8 +70,8 @@ ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr<Film> f)
                _add_file->SetToolTip (_("Add video, image or sound files to the film."));
                b->Add (_add_file, 0, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
                
-               _add_folder = new wxButton (_panel, wxID_ANY, _("Add image\nsequence..."));
-               _add_folder->SetToolTip (_("Add a directory of image files which will be used as a moving image sequence."));
+               _add_folder = new wxButton (_panel, wxID_ANY, _("Add folder..."));
+               _add_folder->SetToolTip (_("Add a folder of image files (which will be used as a moving image sequence) or a DCP."));
                b->Add (_add_folder, 1, wxEXPAND | wxALL, DCPOMATIC_BUTTON_STACK_GAP);
                
                _remove = new wxButton (_panel, wxID_ANY, _("Remove"));
@@ -257,28 +258,54 @@ void
 ContentPanel::add_folder_clicked ()
 {
        wxDirDialog* d = new wxDirDialog (_panel, _("Choose a folder"), wxT (""), wxDD_DIR_MUST_EXIST);
-       int const r = d->ShowModal ();
+       int r = d->ShowModal ();
+       boost::filesystem::path const path (wx_to_std (d->GetPath ()));
        d->Destroy ();
        
        if (r != wxID_OK) {
                return;
        }
 
-       shared_ptr<Content> content;
-       
-       try {
-               content.reset (new ImageContent (_film, boost::filesystem::path (wx_to_std (d->GetPath ()))));
-       } catch (...) {
+       /* Guess if this is a DCP or a set of images: read the first ten filenames and if they
+          are all valid image files we assume it is a set of images.
+       */
+
+       bool is_dcp = false;
+       int read = 0;
+       for (boost::filesystem::directory_iterator i(path); i != boost::filesystem::directory_iterator() && read < 10; ++i, ++read) {
+               if (!boost::filesystem::is_regular_file (i->path()) || !valid_image_file (i->path())) {
+                       is_dcp = true;
+               }
+       }
+
+       if (is_dcp) {
                try {
-                       content.reset (new DCPContent (_film, boost::filesystem::path (wx_to_std (d->GetPath ()))));
+                       shared_ptr<DCPContent> content (new DCPContent (_film, path));
+                       _film->examine_and_add_content (content);
                } catch (...) {
-                       error_dialog (_panel, _("Could not find any images nor a DCP in that folder"));
+                       error_dialog (_panel, _("Could not find a DCP in that folder."));
+               }
+       } else {
+               
+               ImageSequenceDialog* e = new ImageSequenceDialog (_panel);
+               r = e->ShowModal ();
+               float const frame_rate = e->frame_rate ();
+               e->Destroy ();
+
+               if (r != wxID_OK) {
                        return;
                }
-       }
 
-       if (content) {
-               _film->examine_and_add_content (content);
+               shared_ptr<Content> content;
+               
+               try {
+                       shared_ptr<ImageContent> content (new ImageContent (_film, path));
+                       content->set_video_frame_rate (frame_rate);
+                       _film->examine_and_add_content (content);
+               } catch (...) {
+                       error_dialog (_panel, _("Could not find any images in that folder"));
+                       return;
+               }
        }
 }
 
@@ -308,7 +335,7 @@ ContentPanel::timeline_clicked ()
 void
 ContentPanel::right_click (wxListEvent& ev)
 {
-       _menu->popup (_film, selected (), ev.GetPoint ());
+       _menu->popup (_film, selected (), TimelineContentViewList (), ev.GetPoint ());
 }
 
 /** Set up broad sensitivity based on the type of content that is selected */
@@ -339,6 +366,7 @@ ContentPanel::set_film (shared_ptr<Film> f)
        _film = f;
 
        film_changed (Film::CONTENT);
+       film_changed (Film::AUDIO_CHANNELS);
        selection_changed ();
 }