Handle errors in subtitle XML better (#1209).
[dcpomatic.git] / src / tools / dcpomatic_player.cc
index 4388ebbc3cce90949e1bba7a3fa88672181b7b61..d42320bfdd383c527af1a0170c15fd41e288306a 100644 (file)
@@ -28,6 +28,7 @@
 #include "lib/job.h"
 #include "lib/video_content.h"
 #include "lib/subtitle_content.h"
+#include "lib/ratio.h"
 #include "wx/wx_signal_manager.h"
 #include "wx/wx_util.h"
 #include "wx/about_dialog.h"
@@ -127,12 +128,21 @@ public:
                wxPanel* overall_panel = new wxPanel (this, wxID_ANY);
 
                _viewer = new FilmViewer (overall_panel, false, false);
+               _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
                _info = new PlayerInformation (overall_panel, _viewer);
                wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
                main_sizer->Add (_viewer, 1, wxEXPAND | wxALL, 6);
                main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
                overall_panel->SetSizer (main_sizer);
 
+#ifdef __WXOSX__
+               wxAcceleratorEntry* accel = new wxAcceleratorEntry[1];
+               accel[0].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
+               wxAcceleratorTable accel_table (1, accel);
+               SetAcceleratorTable (accel_table);
+               delete[] accel;
+#endif
+
                UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
        }
 
@@ -140,12 +150,20 @@ public:
        {
                _viewer->set_dcp_decode_reduction (reduction);
                _info->triggered_update ();
+               Config::instance()->set_decode_reduction (reduction);
        }
 
        void load_dcp (boost::filesystem::path dir)
        {
                _film.reset (new Film (optional<boost::filesystem::path>()));
-               shared_ptr<DCPContent> dcp (new DCPContent (_film, dir));
+               shared_ptr<DCPContent> dcp;
+               try {
+                       dcp.reset (new DCPContent (_film, dir));
+               } catch (boost::filesystem::filesystem_error& e) {
+                       error_dialog (this, _("Could not load DCP"), std_to_wx (e.what()));
+                       return;
+               }
+
                _film->examine_and_add_content (dcp, true);
 
                JobManager* jm = JobManager::instance ();
@@ -163,7 +181,7 @@ public:
 
                shared_ptr<Job> last = jm->get().back();
                if (last->finished_in_error()) {
-                       error_dialog (this, std_to_wx (last->error_summary()) + ".\n");
+                       error_dialog(this, std_to_wx(last->error_summary()) + ".\n", std_to_wx(last->error_details()));
                        return;
                }
 
@@ -171,6 +189,11 @@ public:
                        dcp->subtitle->set_use (true);
                }
 
+               Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
+               if (r) {
+                       _film->set_container(r);
+               }
+
                _viewer->set_film (_film);
                _viewer->set_position (DCPTime ());
                _info->triggered_update ();
@@ -209,10 +232,11 @@ private:
 #endif
 
                wxMenu* view = new wxMenu;
-               view->AppendRadioItem (ID_view_scale_appropriate, _("Set decode resolution to match display"));
-               view->AppendRadioItem (ID_view_scale_full, _("Decode at full resolution"));
-               view->AppendRadioItem (ID_view_scale_half, _("Decode at half resolution"));
-               view->AppendRadioItem (ID_view_scale_quarter, _("Decode at quarter resolution"));
+               optional<int> c = Config::instance()->decode_reduction();
+               view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
+               view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
+               view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
+               view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
 
                wxMenu* tools = new wxMenu;
                tools->Append (ID_tools_check_for_updates, _("Check for updates"));
@@ -287,6 +311,10 @@ private:
                        DCPOMATIC_ASSERT (dcp);
                        dcp->add_ov (wx_to_std(c->GetPath()));
                        dcp->examine (shared_ptr<Job>());
+                       /* Maybe we just gained some subtitles */
+                       if (dcp->subtitle) {
+                               dcp->subtitle->set_use (true);
+                       }
                }
 
                c->Destroy ();