Very basic player logging.
[dcpomatic.git] / src / tools / dcpomatic_player.cc
index 10b75b03dae170f85527fd511a9b632df94f0160..7a7e5ac16a8d55e6bd5ba79f179642f313d24987 100644 (file)
@@ -162,6 +162,9 @@ public:
                _viewer.reset (new FilmViewer (_overall_panel));
                _controls = new Controls (_overall_panel, _viewer);
                _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
+               _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
+               _viewer->Started.connect (bind(&DOMFrame::playback_started, this));
+               _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this));
                _info = new PlayerInformation (_overall_panel, _viewer);
                wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
                main_sizer->Add (_viewer->panel(), 1, wxEXPAND);
@@ -197,10 +200,73 @@ public:
                setup_screen ();
        }
 
+       bool playback_permitted ()
+       {
+               if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
+                       return true;
+               }
+
+               bool ok = true;
+               BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
+                       shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
+                       if (d && !d->kdm_timing_window_valid()) {
+                               ok = false;
+                       }
+               }
+
+               if (!ok) {
+                       error_dialog (this, _("The KDM does not allow playback of this content at this time."));
+               }
+
+               return ok;
+       }
+
+       void playback_started ()
+       {
+               optional<boost::filesystem::path> log = Config::instance()->player_log_file();
+               if (!log) {
+                       return;
+               }
+
+               shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
+               DCPOMATIC_ASSERT (dcp);
+               DCPExaminer ex (dcp);
+               shared_ptr<dcp::CPL> playing_cpl;
+               BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
+                       if (!dcp->cpl() || i->id() == *dcp->cpl()) {
+                               playing_cpl = i;
+                       }
+               }
+               DCPOMATIC_ASSERT (playing_cpl)
+
+               FILE* f = fopen_boost(*log, "a");
+               fprintf (
+                       f,
+                       "%s playback-started %s %s\n",
+                       dcp::LocalTime().as_string().c_str(),
+                       dcp->directories().front().string().c_str(),
+                       playing_cpl->annotation_text().c_str()
+                       );
+               fclose (f);
+       }
+
+       void playback_stopped ()
+       {
+               optional<boost::filesystem::path> log = Config::instance()->player_log_file();
+               if (!log) {
+                       return;
+               }
+
+               FILE* f = fopen_boost(*log, "a");
+               fprintf (f, "%s playback-stopped\n", dcp::LocalTime().as_string().c_str());
+               fclose (f);
+       }
+
        void set_decode_reduction (optional<int> reduction)
        {
                _viewer->set_dcp_decode_reduction (reduction);
                _info->triggered_update ();
+               _cinema_dialog->triggered_update ();
                Config::instance()->set_decode_reduction (reduction);
        }
 
@@ -230,6 +296,7 @@ public:
                _viewer->set_film (_film);
                _viewer->seek (DCPTime(), true);
                _info->triggered_update ();
+               _cinema_dialog->triggered_update ();
 
                Config::instance()->add_to_player_history (dir);
 
@@ -378,6 +445,7 @@ private:
 
                c->Destroy ();
                _info->triggered_update ();
+               _cinema_dialog->triggered_update ();
        }
 
        void file_add_kdm ()
@@ -400,6 +468,7 @@ private:
 
                d->Destroy ();
                _info->triggered_update ();
+               _cinema_dialog->triggered_update ();
        }
 
        void file_history (wxCommandEvent& event)
@@ -416,6 +485,7 @@ private:
                _viewer->set_film (shared_ptr<Film>());
                _film.reset ();
                _info->triggered_update ();
+               _cinema_dialog->triggered_update ();
                set_menu_sensitivity ();
        }
 
@@ -480,8 +550,9 @@ private:
                if (_mode == Config::PLAYER_MODE_DUAL) {
                        _cinema_dialog->Show ();
                        if (wxDisplay::GetCount() > 1) {
-                               this->Move (0, 0);
-                               _cinema_dialog->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
+                               this->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
+                               /* (0, 0) doesn't seem to work for some strange reason */
+                               _cinema_dialog->Move (8, 8);
                        }
                }
        }