Move code to create DCPContent or (non-still) ImageContent into content_factory().
authorCarl Hetherington <cth@carlh.net>
Wed, 29 Jul 2015 19:54:27 +0000 (20:54 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 29 Jul 2015 19:54:27 +0000 (20:54 +0100)
src/lib/content_factory.cc
src/wx/content_panel.cc

index 3c65b43129a14a23d62628a8f14a1911495b4ec8..c61889363fda9a62837c15acd51b4c85f0b20fc1 100644 (file)
@@ -66,9 +66,9 @@ content_factory (shared_ptr<const Film> film, cxml::NodePtr node, int version, l
        return content;
 }
 
-/** Create a Content object from a file, depending on its extension.
+/** Create a Content object from a file or directory.
  *  @param film Film that the content will be in.
- *  @param path File's path.
+ *  @param path File or directory.
  *  @return Content object.
  */
 shared_ptr<Content>
@@ -76,23 +76,45 @@ content_factory (shared_ptr<const Film> film, boost::filesystem::path path)
 {
        shared_ptr<Content> content;
 
-       string ext = path.extension().string ();
-       transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
-
-       if (valid_image_file (path)) {
-               content.reset (new ImageContent (film, path));
-       } else if (SndfileContent::valid_file (path)) {
-               content.reset (new SndfileContent (film, path));
-       } else if (ext == ".srt") {
-               content.reset (new SubRipContent (film, path));
-       } else if (ext == ".xml") {
-               content.reset (new DCPSubtitleContent (film, path));
-       } else if (ext == ".mxf" && dcp::SMPTESubtitleAsset::valid_mxf (path)) {
-               content.reset (new DCPSubtitleContent (film, path));
-       }
-
-       if (!content) {
-               content.reset (new FFmpegContent (film, path));
+       if (boost::filesystem::is_directory (path)) {
+               /* 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) {
+                       content.reset (new DCPContent (film, path));
+               } else {
+                       content.reset (new ImageContent (film, path));
+               }
+
+       } else {
+
+               string ext = path.extension().string ();
+               transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+
+               if (valid_image_file (path)) {
+                       content.reset (new ImageContent (film, path));
+               } else if (SndfileContent::valid_file (path)) {
+                       content.reset (new SndfileContent (film, path));
+               } else if (ext == ".srt") {
+                       content.reset (new SubRipContent (film, path));
+               } else if (ext == ".xml") {
+                       content.reset (new DCPSubtitleContent (film, path));
+               } else if (ext == ".mxf" && dcp::SMPTESubtitleAsset::valid_mxf (path)) {
+                       content.reset (new DCPSubtitleContent (film, path));
+               }
+
+               if (!content) {
+                       content.reset (new FFmpegContent (film, path));
+               }
        }
 
        return content;
index 32ca3e4945c592ae6871879dd1b0177cb449b289..65fdf588cefb8f2faa7884ffa1dd99eb49733766 100644 (file)
@@ -278,27 +278,10 @@ ContentPanel::add_folder_clicked ()
                return;
        }
 
-       /* 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 {
-                       shared_ptr<DCPContent> content (new DCPContent (_film, path));
-                       _film->examine_and_add_content (content);
-               } catch (...) {
-                       error_dialog (_panel, _("Could not find a DCP nor a set of images in that folder."));
-               }
-       } else {
+       shared_ptr<Content> content = content_factory (_film, path);
 
+       shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (content);
+       if (ic) {
                ImageSequenceDialog* e = new ImageSequenceDialog (_panel);
                r = e->ShowModal ();
                float const frame_rate = e->frame_rate ();
@@ -308,17 +291,10 @@ ContentPanel::add_folder_clicked ()
                        return;
                }
 
-               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;
-               }
+               ic->set_video_frame_rate (frame_rate);
        }
+
+       _film->examine_and_add_content (content);
 }
 
 void