Support download of KDMs from a web service in swaroop profile.
[dcpomatic.git] / src / tools / dcpomatic_player.cc
index 3be947cc623bcdec3637ed5488733ba12f7c628c..8329f1d8655393df71e50d8dd8bc16d3ef38b86d 100644 (file)
@@ -31,6 +31,7 @@
 #include "lib/cross.h"
 #include "lib/config.h"
 #include "lib/util.h"
+#include "lib/internet.h"
 #include "lib/update_checker.h"
 #include "lib/compose.hpp"
 #include "lib/dcp_content.h"
@@ -45,6 +46,7 @@
 #include "lib/examine_content_job.h"
 #include "lib/server.h"
 #include "lib/dcpomatic_socket.h"
+#include "lib/scoped_temporary.h"
 #include <wx/wx.h>
 #include <wx/stdpaths.h>
 #include <wx/splash.h>
@@ -161,7 +163,7 @@ public:
                _overall_panel = new wxPanel (this, wxID_ANY);
 
                _viewer.reset (new FilmViewer (_overall_panel));
-               _controls = new Controls (_overall_panel, _viewer, false, false, false);
+               _controls = new Controls (_overall_panel, _viewer, false);
                _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, _1));
@@ -191,6 +193,8 @@ public:
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
 
                UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
+               _controls->DCPDirectorySelected.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
+               _controls->DCPEjected.connect (boost::bind(&DOMFrame::eject_dcp, this));
 
                setup_screen ();
        }
@@ -289,6 +293,13 @@ public:
                Config::instance()->set_decode_reduction (reduction);
        }
 
+       void eject_dcp ()
+       {
+               _film.reset (new Film (optional<boost::filesystem::path>()));
+               _viewer->set_film (_film);
+               _info->triggered_update ();
+       }
+
        void load_dcp (boost::filesystem::path dir)
        {
                _film.reset (new Film (optional<boost::filesystem::path>()));
@@ -306,6 +317,50 @@ public:
                        return;
                }
 
+               /* The DCP has been examined and loaded */
+
+               optional<boost::filesystem::path> kdm_dir = Config::instance()->player_kdm_directory();
+               if (dcp->needs_kdm() && kdm_dir) {
+                       /* Look for a KDM */
+
+                       optional<dcp::EncryptedKDM> kdm;
+
+                       ScopedTemporary temp;
+                       string url = Config::instance()->kdm_server_url();
+                       boost::algorithm::replace_all (url, "{CPL}", "%1");
+                       if (dcp->cpl() && !get_from_url(String::compose(url, *dcp->cpl()), false, temp)) {
+                               try {
+                                       kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
+                                       if (kdm->cpl_id() != dcp->cpl()) {
+                                               kdm = boost::none;
+                                       }
+                               } catch (std::exception& e) {
+                                       /* Hey well */
+                               }
+                       }
+
+                       if (!kdm) {
+                               using namespace boost::filesystem;
+                               for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
+                                       if (file_size(i->path()) < MAX_KDM_SIZE) {
+                                               try {
+                                                       kdm = dcp::EncryptedKDM(dcp::file_to_string(i->path()));
+                                                       if (kdm->cpl_id() == dcp->cpl()) {
+                                                               break;
+                                                       }
+                                               } catch (std::exception& e) {
+                                                       /* Hey well */
+                                               }
+                                       }
+                               }
+                       }
+
+                       if (kdm) {
+                               dcp->add_kdm (*kdm);
+                               dcp->examine (shared_ptr<Job>());
+                       }
+               }
+
                setup_from_dcp (dcp);
 
                if (dcp->three_d()) {
@@ -335,6 +390,8 @@ public:
                        j->Check(!dcp->cpl() || i->id() == *dcp->cpl());
                        ++id;
                }
+
+               _controls->log (wxString::Format(_("Load DCP %s"), dir.filename().string().c_str()));
        }
 
 private:
@@ -576,6 +633,7 @@ private:
        void setup_screen ()
        {
                _controls->Show (_mode != Config::PLAYER_MODE_FULL);
+               _controls->show_extended_player_controls (_mode == Config::PLAYER_MODE_DUAL);
                _info->Show (_mode != Config::PLAYER_MODE_FULL);
                _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
                ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);