Quell config-save warning when we're only trying to save history.
[dcpomatic.git] / src / tools / dcpomatic_player.cc
index 3be884e035676c8fca9ee4f74966caf12c01cd86..c20c3cbd88d5490aab84ab5b7cccb046804e8a42 100644 (file)
@@ -47,6 +47,8 @@
 #include "lib/server.h"
 #include "lib/dcpomatic_socket.h"
 #include "lib/scoped_temporary.h"
+#include "lib/monitor_checker.h"
+#include <dcp/dcp.h>
 #include <wx/wx.h>
 #include <wx/stdpaths.h>
 #include <wx/splash.h>
@@ -135,7 +137,7 @@ public:
                SetIcon (wxIcon (std_to_wx ("id")));
 #endif
 
-               _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this));
+               _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
                update_from_config ();
 
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
@@ -194,10 +196,21 @@ public:
 
                UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
                _controls->SPLChanged.connect (boost::bind(&DOMFrame::set_spl, this, _1));
-
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+               MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
+               MonitorChecker::instance()->run ();
+#endif
                setup_screen ();
        }
 
+       void monitor_checker_state_changed ()
+       {
+               if (!MonitorChecker::instance()->ok()) {
+                       error_dialog (this, _("The required display devices are not connected correctly."));
+                       _viewer->stop ();
+               }
+       }
+
        void setup_main_sizer (Config::PlayerMode mode)
        {
                wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
@@ -212,6 +225,12 @@ public:
 
        bool playback_permitted ()
        {
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+               if (!MonitorChecker::instance()->ok()) {
+                       error_dialog (this, _("The required display devices are not connected correctly."));
+                       return false;
+               }
+#endif
                if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
                        return true;
                }
@@ -294,8 +313,12 @@ public:
 
        void load_dcp (boost::filesystem::path dir)
        {
+               dcp::DCP dcp (dir);
+               dcp.read ();
                list<SPLEntry> spl;
-               spl.push_back (SPLEntry(dir));
+               BOOST_FOREACH (shared_ptr<dcp::CPL> j, dcp.cpls()) {
+                       spl.push_back (SPLEntry(j, dir));
+               }
                set_spl (spl);
                Config::instance()->add_to_player_history (dir);
        }
@@ -329,15 +352,15 @@ public:
                        return optional<dcp::EncryptedKDM>();
                }
                for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
-                       if (file_size(i->path()) < MAX_KDM_SIZE) {
-                               try {
+                       try {
+                               if (file_size(i->path()) < MAX_KDM_SIZE) {
                                        dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
                                        if (kdm.cpl_id() == dcp->cpl()) {
                                                return kdm;
                                        }
-                               } catch (std::exception& e) {
-                                       /* Hey well */
                                }
+                       } catch (std::exception& e) {
+                               /* Hey well */
                        }
                }
                return optional<dcp::EncryptedKDM>();
@@ -360,13 +383,14 @@ public:
                /* Start off as Flat */
                _film->set_container (Ratio::from_id("185"));
 
-               DCPTime position;
+               /* Put 1 frame of black at the start so when we seek to 0 we don't see anything */
+               DCPTime position = DCPTime::from_frames(1, _film->video_frame_rate());
                shared_ptr<DCPContent> first;
 
                BOOST_FOREACH (SPLEntry i, spl) {
                        shared_ptr<DCPContent> dcp;
                        try {
-                               dcp.reset (new DCPContent (_film, i.dcp));
+                               dcp.reset (new DCPContent (_film, i.directory));
                        } catch (boost::filesystem::filesystem_error& e) {
                                error_dialog (this, _("Could not load DCP"), std_to_wx (e.what()));
                                return;
@@ -424,7 +448,7 @@ public:
                        _info->triggered_update ();
 
                        set_menu_sensitivity ();
-                       _controls->log (wxString::Format(_("Load DCP %s"), i.dcp.filename().string().c_str()));
+                       _controls->log (wxString::Format(_("Load DCP %s"), i.directory.filename().string().c_str()));
                }
 
                wxMenuItemList old = _cpl_menu->GetMenuItems();
@@ -811,19 +835,21 @@ private:
                _update_news_requested = false;
        }
 
-       void config_changed ()
+       void config_changed (Config::Property prop)
        {
                /* Instantly save any config changes when using the player GUI */
                try {
                        Config::instance()->write_config();
                } catch (FileError& e) {
-                       error_dialog (
-                               this,
-                               wxString::Format(
-                                       _("Could not write to config file at %s.  Your changes have not been saved."),
-                                       std_to_wx(e.file().string())
-                                       )
-                               );
+                       if (prop != Config::HISTORY) {
+                               error_dialog (
+                                       this,
+                                       wxString::Format(
+                                               _("Could not write to config file at %s.  Your changes have not been saved."),
+                                               std_to_wx(e.file().string())
+                                               )
+                                       );
+                       }
                } catch (exception& e) {
                        error_dialog (
                                this,