Revert "Odd const fix."
[dcpomatic.git] / src / wx / subtitle_panel.cc
index 31b4e96ac3cf8083809d0a41af5d9ec6a8b75362..4efc4eee426f6be0916751dac236ba95c724b5a6 100644 (file)
@@ -34,6 +34,7 @@
 #include "lib/dcp_subtitle_decoder.h"
 #include "lib/dcp_content.h"
 #include "lib/subtitle_content.h"
+#include "lib/decoder_factory.h"
 #include <wx/spinctrl.h>
 #include <boost/foreach.hpp>
 
@@ -235,35 +236,41 @@ SubtitlePanel::setup_sensitivity ()
        int any_subs = 0;
        int ffmpeg_subs = 0;
        int text_subs = 0;
-       int dcp_subs = 0;
        int image_subs = 0;
        ContentList sel = _parent->selected_subtitle ();
        BOOST_FOREACH (shared_ptr<Content> i, sel) {
+               /* These are the content types that could include subtitles */
                shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
                shared_ptr<const TextSubtitleContent> sc = boost::dynamic_pointer_cast<const TextSubtitleContent> (i);
                shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
                if (fc) {
                        if (fc->subtitle) {
+                               DCPOMATIC_ASSERT (fc->subtitle_stream());
+                               /* This content has some subtitles; check the selected stream to decide what type */
+                               if (fc->subtitle_stream()->has_text()) {
+                                       ++text_subs;
+                               } else if (fc->subtitle_stream()->has_image()) {
+                                       ++image_subs;
+                               }
                                ++ffmpeg_subs;
                                ++any_subs;
                        }
-               } else if (sc) {
+               } else if (sc || dsc) {
+                       /* XXX: in the future there could be bitmap subs from DCPs */
                        ++text_subs;
                        ++any_subs;
-               } else if (dsc) {
-                       ++dcp_subs;
-                       ++any_subs;
-               } else {
-                       ++any_subs;
                }
+       }
 
-               if (i->subtitle->has_image_subtitles ()) {
-                       ++image_subs;
+       if (image_subs) {
+               BOOST_FOREACH (shared_ptr<Content> i, sel) {
                        /* We must burn image subtitles at the moment */
                        i->subtitle->set_burn (true);
                }
        }
 
+       /* Decide whether we can reference these subs */
+
        shared_ptr<DCPContent> dcp;
        if (sel.size() == 1) {
                dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
@@ -275,6 +282,7 @@ SubtitlePanel::setup_sensitivity ()
 
        bool const reference = _reference->GetValue ();
 
+       /* Set up sensitivity */
        _use->Enable (!reference && any_subs > 0);
        bool const use = _use->GetValue ();
        _burn->Enable (!reference && any_subs > 0 && use && image_subs == 0);
@@ -284,9 +292,9 @@ SubtitlePanel::setup_sensitivity ()
        _y_scale->Enable (!reference && any_subs > 0 && use);
        _language->Enable (!reference && any_subs > 0 && use);
        _stream->Enable (!reference && ffmpeg_subs == 1);
-       _subtitle_view_button->Enable (!reference && (text_subs == 1 || dcp_subs == 1));
-       _fonts_dialog_button->Enable (!reference && (text_subs == 1 || dcp_subs == 1));
-       _appearance_dialog_button->Enable (!reference && (ffmpeg_subs == 1 || text_subs == 1));
+       _subtitle_view_button->Enable (!reference && text_subs == 1);
+       _fonts_dialog_button->Enable (!reference && text_subs == 1);
+       _appearance_dialog_button->Enable (!reference);
 }
 
 void
@@ -378,17 +386,7 @@ SubtitlePanel::subtitle_view_clicked ()
        ContentList c = _parent->selected_subtitle ();
        DCPOMATIC_ASSERT (c.size() == 1);
 
-       shared_ptr<Decoder> decoder;
-
-       shared_ptr<TextSubtitleContent> sr = dynamic_pointer_cast<TextSubtitleContent> (c.front ());
-       if (sr) {
-               decoder.reset (new TextSubtitleDecoder (sr));
-       }
-
-       shared_ptr<DCPSubtitleContent> dc = dynamic_pointer_cast<DCPSubtitleContent> (c.front ());
-       if (dc) {
-               decoder.reset (new DCPSubtitleDecoder (dc));
-       }
+       shared_ptr<Decoder> decoder = decoder_factory (c.front(), _parent->film()->log(), false);
 
        if (decoder) {
                _subtitle_view = new SubtitleView (this, _parent->film(), decoder, c.front()->position ());
@@ -433,15 +431,33 @@ SubtitlePanel::appearance_dialog_clicked ()
        ContentList c = _parent->selected_subtitle ();
        DCPOMATIC_ASSERT (c.size() == 1);
 
-       shared_ptr<TextSubtitleContent> sr = dynamic_pointer_cast<TextSubtitleContent> (c.front ());
-       if (sr) {
-               TextSubtitleAppearanceDialog* d = new TextSubtitleAppearanceDialog (this, sr);
+       bool text = false;
+       bool image = false;
+
+       if (
+               dynamic_pointer_cast<TextSubtitleContent> (c.front()) ||
+               dynamic_pointer_cast<DCPContent> (c.front()) ||
+               dynamic_pointer_cast<DCPSubtitleContent> (c.front())) {
+
+               text = true;
+       }
+
+       shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c.front());
+       if (fc) {
+               if (fc->subtitle_stream()->has_text()) {
+                       text = true;
+               } else if (fc->subtitle_stream()->has_image()) {
+                       image = true;
+               }
+       }
+
+       if (text) {
+               TextSubtitleAppearanceDialog* d = new TextSubtitleAppearanceDialog (this, c.front()->subtitle);
                if (d->ShowModal () == wxID_OK) {
                        d->apply ();
                }
                d->Destroy ();
-       } else {
-               shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c.front ());
+       } else if (image) {
                DCPOMATIC_ASSERT (fc);
                ImageSubtitleColourDialog* d = new ImageSubtitleColourDialog (this, fc, fc->subtitle_stream ());
                if (d->ShowModal() == wxID_OK) {