Add load button for SPL.
authorCarl Hetherington <cth@carlh.net>
Tue, 9 Oct 2018 22:08:22 +0000 (23:08 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 9 Oct 2018 22:08:22 +0000 (23:08 +0100)
src/lib/config.cc
src/lib/config.h
src/wx/controls.cc
src/wx/controls.h

index eb13112d2556d101533cdea9e85d5a575be41274..ede0b1059d4284ff5d1ff274fa9f2bfe0cc3eab9 100644 (file)
@@ -175,6 +175,7 @@ Config::set_defaults ()
        _player_watermark_theatre = "";
        _player_watermark_period = 1;
        _player_watermark_duration = 50;
+       _allow_spl_editing = true;
 #endif
 
        _allowed_dcp_frame_rates.clear ();
@@ -525,6 +526,7 @@ try
        BOOST_FOREACH (cxml::ConstNodePtr i, f.node_children("RequiredMonitor")) {
                _required_monitors.push_back(Monitor(i));
        }
+       _allow_spl_editing = f.optional_bool_child("AllowSPLEditing").get_value_or(true);
 #endif
 
        /* Replace any cinemas from config.xml with those from the configured file */
@@ -934,6 +936,7 @@ Config::write_config () const
        BOOST_FOREACH (Monitor i, _required_monitors) {
                i.as_xml(root->add_child("RequiredMonitor"));
        }
+       root->add_child("AllowSPLEditing")->add_child_text(_allow_spl_editing ? "1" : "0");
 #endif
 
        try {
index baf446df318738c1176a7bc4188b9ddb1a961881..a313e43425bc002481d4f501d18d26f0eb12d126 100644 (file)
@@ -519,6 +519,10 @@ public:
        std::vector<Monitor> required_monitors () const {
                return _required_monitors;
        }
+
+       bool allow_spl_editing () const {
+               return _allow_spl_editing;
+       }
 #endif
 
        /* SET (mostly) */
@@ -999,6 +1003,10 @@ public:
        void set_required_monitors (std::vector<Monitor> monitors) {
                maybe_set (_required_monitors, monitors);
        }
+
+       void set_allow_spl_editing (bool s) {
+               maybe_set (_allow_spl_editing, s);
+       }
 #endif
 
        void changed (Property p = OTHER);
@@ -1203,6 +1211,7 @@ private:
        /** watermark duration in milliseconds */
        int _player_watermark_duration;
        std::vector<Monitor> _required_monitors;
+       bool _allow_spl_editing;
 #endif
 
        static int const _current_version;
index 753014c4665bde18e188a1cf04cd7332a11d2640..eb70726d014e1be6400c9cfbf8d33899ad2a6fb0 100644 (file)
@@ -103,6 +103,10 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
        wxBoxSizer* buttons_sizer = new wxBoxSizer (wxVERTICAL);
        _add_button = new wxButton(this, wxID_ANY, _("Add"));
        buttons_sizer->Add (_add_button);
+       _save_button = new wxButton(this, wxID_ANY, _("Save..."));
+       buttons_sizer->Add (_save_button);
+       _load_button = new wxButton(this, wxID_ANY, _("Load..."));
+       buttons_sizer->Add (_load_button);
        e_sizer->Add (buttons_sizer, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
 
        _v_sizer->Add (e_sizer, 1, wxEXPAND);
@@ -113,6 +117,8 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
        _cpl->Show (false);
        _spl_view->Show (false);
        _add_button->Show (false);
+       _save_button->Show (false);
+       _load_button->Show (false);
        _log->Show (false);
 
        wxBoxSizer* h_sizer = new wxBoxSizer (wxHORIZONTAL);
@@ -169,6 +175,8 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
                _jump_to_selected->SetValue (Config::instance()->jump_to_selected ());
        }
        _add_button->Bind       (wxEVT_BUTTON,              boost::bind(&Controls::add_clicked, this));
+       _save_button->Bind      (wxEVT_BUTTON,              boost::bind(&Controls::save_clicked, this));
+       _load_button->Bind      (wxEVT_BUTTON,              boost::bind(&Controls::load_clicked, this));
 
        _viewer->PositionChanged.connect (boost::bind(&Controls::position_changed, this));
        _viewer->Started.connect (boost::bind(&Controls::started, this));
@@ -186,6 +194,7 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
                );
 
        _config_changed_connection = Config::instance()->Changed.connect (bind(&Controls::config_changed, this, _1));
+       config_changed (Config::OTHER);
 }
 
 void
@@ -199,11 +208,47 @@ Controls::add_clicked ()
        setup_sensitivity ();
 }
 
+void
+Controls::save_clicked ()
+{
+       wxFileDialog* d = new wxFileDialog (
+               this, _("Select playlist file"), wxEmptyString, wxEmptyString, wxT ("XML files (*.xml)|*.xml"),
+               wxFD_SAVE | wxFD_OVERWRITE_PROMPT
+               );
+
+       if (d->ShowModal() == wxID_OK) {
+               _spl.as_xml (boost::filesystem::path(wx_to_std(d->GetPath())));
+       }
+
+       d->Destroy ();
+}
+
+void
+Controls::load_clicked ()
+{
+       wxFileDialog* d = new wxFileDialog (
+               this, _("Select playlist file"), wxEmptyString, wxEmptyString, wxT ("XML files (*.xml)|*.xml")
+               );
+
+       if (d->ShowModal() == wxID_OK) {
+               _spl = SPL (boost::filesystem::path(wx_to_std(d->GetPath())));
+               _spl_view->DeleteAllItems ();
+               BOOST_FOREACH (SPLEntry i, _spl.playlist) {
+                       add_cpl_to_list (i.cpl, _spl_view);
+               }
+               SPLChanged (_spl);
+       }
+
+       d->Destroy ();
+}
+
 void
 Controls::config_changed (int property)
 {
        if (property == Config::PLAYER_DCP_DIRECTORY) {
                update_dcp_directory ();
+       } else {
+               setup_sensitivity ();
        }
 }
 
@@ -444,7 +489,8 @@ Controls::setup_sensitivity ()
                _eye->Enable (c && _film->three_d ());
        }
 
-       _add_button->Enable (static_cast<bool>(selected_cpl()));
+       _add_button->Enable (Config::instance()->allow_spl_editing() && static_cast<bool>(selected_cpl()));
+       _save_button->Enable (Config::instance()->allow_spl_editing());
 }
 
 optional<Controls::CPL>
@@ -522,6 +568,8 @@ Controls::show_extended_player_controls (bool s)
        _spl_view->Show (s);
        _log->Show (s);
        _add_button->Show (s);
+       _save_button->Show (s);
+       _load_button->Show (s);
        _v_sizer->Layout ();
 }
 
index fd8178435e253c7ffbb51f2f712019357e32a250..09e942e1c8589b5dd3627a09137d75b38a06dded 100644 (file)
@@ -94,6 +94,8 @@ private:
        void stop_clicked ();
 #endif
        void add_clicked ();
+       void save_clicked ();
+       void load_clicked ();
        void add_cpl_to_list (boost::shared_ptr<dcp::CPL> cpl, wxListCtrl* list);
 
        boost::shared_ptr<Film> _film;
@@ -110,6 +112,8 @@ private:
        wxListCtrl* _spl_view;
        wxTextCtrl* _log;
        wxButton* _add_button;
+       wxButton* _save_button;
+       wxButton* _load_button;
        std::vector<CPL> _cpls;
        wxSlider* _slider;
        wxButton* _rewind_button;