Make jump-to-first-subtitle also work with DCP subs.
[dcpomatic.git] / src / wx / content_panel.cc
index db29ed74a1fee6d2bcaf37c9de725b19fc1de5c0..69dd724266abfc35a780f141833587c2853bd13a 100644 (file)
@@ -36,6 +36,8 @@
 #include "lib/content_factory.h"
 #include "lib/cross.h"
 #include "lib/dcp_content.h"
+#include "lib/dcp_subtitle_content.h"
+#include "lib/dcp_subtitle_decoder.h"
 #include "lib/dcpomatic_log.h"
 #include "lib/ffmpeg_content.h"
 #include "lib/image_content.h"
 #include "lib/string_text_file_content.h"
 #include "lib/text_content.h"
 #include "lib/video_content.h"
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 #include <wx/display.h>
 #include <wx/listctrl.h>
 #include <wx/notebook.h>
 #include <wx/wx.h>
+LIBDCP_ENABLE_WARNINGS
 #include <boost/filesystem.hpp>
 
 
@@ -82,7 +87,7 @@ ContentPanel::ContentPanel (wxNotebook* n, shared_ptr<Film> film, weak_ptr<FilmV
        _splitter = new LimitedSplitter (n);
        _top_panel = new wxPanel (_splitter);
 
-       _menu = new ContentMenu (_splitter);
+       _menu = new ContentMenu (_splitter, _film_viewer);
 
        {
                auto s = new wxBoxSizer (wxHORIZONTAL);
@@ -297,20 +302,27 @@ ContentPanel::check_selection ()
        }
 
        optional<DCPTime> go_to;
-       for (auto i: selected()) {
-               DCPTime p;
-               p = i->position();
-               if (dynamic_pointer_cast<StringTextFileContent>(i) && i->paths_valid()) {
-                       /* Rather special case; if we select a text subtitle file jump to its
-                          first subtitle.
-                       */
-                       StringTextFile ts (dynamic_pointer_cast<StringTextFileContent>(i));
-                       if (ts.first()) {
-                               p += DCPTime(ts.first().get(), _film->active_frame_rate_change(i->position()));
+       for (auto content: selected()) {
+               if (content->paths_valid()) {
+                       auto position = content->position();
+                       if (auto text_content = dynamic_pointer_cast<StringTextFileContent>(content)) {
+                               /* Rather special case; if we select a text subtitle file jump to its
+                                  first subtitle.
+                               */
+                               StringTextFile ts(text_content);
+                               if (auto first = ts.first()) {
+                                       position += DCPTime(first.get(), _film->active_frame_rate_change(content->position()));
+                               }
+                       } else if (auto dcp_content = dynamic_pointer_cast<DCPSubtitleContent>(content)) {
+                               /* Do the same for DCP subtitles */
+                               DCPSubtitleDecoder ts(_film, dcp_content);
+                               if (auto first = ts.first()) {
+                                       position += DCPTime(first.get(), _film->active_frame_rate_change(content->position()));
+                               }
+                       }
+                       if (!go_to || position < go_to.get()) {
+                               go_to = position;
                        }
-               }
-               if (!go_to || p < go_to.get()) {
-                       go_to = p;
                }
        }