From a85c82137ec26124ebefccb4aeebb96a3cdb8a4c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 29 Apr 2015 22:53:52 +0100 Subject: [PATCH] Hand-apply 62f8054d65a8bd31689fc0c977c1bb2385e71afa from master; config of encryption key. --- ChangeLog | 2 ++ TO_PORT | 1 - src/lib/film.cc | 7 +++++ src/lib/film.h | 10 +++--- src/wx/dcp_panel.cc | 38 +++++++++++++++++++++++ src/wx/dcp_panel.h | 3 ++ src/wx/key_dialog.cc | 73 ++++++++++++++++++++++++++++++++++++++++++++ src/wx/key_dialog.h | 36 ++++++++++++++++++++++ src/wx/timeline.cc | 8 ++--- src/wx/wscript | 1 + 10 files changed, 170 insertions(+), 9 deletions(-) create mode 100644 src/wx/key_dialog.cc create mode 100644 src/wx/key_dialog.h diff --git a/ChangeLog b/ChangeLog index 5c3522869..c989f549f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2015-04-29 Carl Hetherington + * Allow configuration of the encryption key (from master). + * Various fixes to bad timeline drag behaviour when snapping (from master). diff --git a/TO_PORT b/TO_PORT index 6b91701ad..d36b16b74 100644 --- a/TO_PORT +++ b/TO_PORT @@ -1,3 +1,2 @@ -8471ccb29ff258722ea27405dc10312e625c132d 4156be8147c324623b266bd59366ff8accb34778 937b382efbeb9b7151359b8feb535e95f99f397c diff --git a/src/lib/film.cc b/src/lib/film.cc index 7dbeaafe9..5e08ed997 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -881,6 +881,13 @@ Film::set_encrypted (bool e) signal_changed (ENCRYPTED); } +void +Film::set_key (dcp::Key key) +{ + _key = key; + signal_changed (KEY); +} + shared_ptr Film::playlist () const { diff --git a/src/lib/film.h b/src/lib/film.h index cca31d306..5eb4f17ed 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -133,10 +133,6 @@ public: dcp::Formulation formulation ) const; - dcp::Key key () const { - return _key; - } - int state_version () const { return _state_version; } @@ -157,6 +153,7 @@ public: RESOLUTION, SIGNED, ENCRYPTED, + KEY, J2K_BANDWIDTH, ISDCF_METADATA, VIDEO_FRAME_RATE, @@ -205,6 +202,10 @@ public: return _encrypted; } + dcp::Key key () const { + return _key; + } + int j2k_bandwidth () const { return _j2k_bandwidth; } @@ -255,6 +256,7 @@ public: void set_resolution (Resolution); void set_signed (bool); void set_encrypted (bool); + void set_key (dcp::Key key); void set_j2k_bandwidth (int); void set_isdcf_metadata (ISDCFMetadata); void set_video_frame_rate (int); diff --git a/src/wx/dcp_panel.cc b/src/wx/dcp_panel.cc index 0146a14f4..82872ad84 100644 --- a/src/wx/dcp_panel.cc +++ b/src/wx/dcp_panel.cc @@ -19,6 +19,7 @@ #include "dcp_panel.h" #include "wx_util.h" +#include "key_dialog.h" #include "isdcf_metadata_dialog.h" #include "lib/ratio.h" #include "lib/config.h" @@ -26,6 +27,7 @@ #include "lib/util.h" #include "lib/film.h" #include "lib/ffmpeg_content.h" +#include #include #include #include @@ -99,6 +101,21 @@ DCPPanel::DCPPanel (wxNotebook* n, boost::shared_ptr f) grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2)); ++r; + wxClientDC dc (_panel); + wxSize size = dc.GetTextExtent (wxT ("GGGGGGGG...")); + size.SetHeight (-1); + + { + add_label_to_grid_bag_sizer (grid, _panel, _("Key"), true, wxGBPosition (r, 0)); + wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL); + _key = new wxStaticText (_panel, wxID_ANY, "", wxDefaultPosition, size); + s->Add (_key, 1, wxALIGN_CENTER_VERTICAL); + _edit_key = new wxButton (_panel, wxID_ANY, _("Edit...")); + s->Add (_edit_key); + grid->Add (s, wxGBPosition (r, 1)); + ++r; + } + add_label_to_grid_bag_sizer (grid, _panel, _("Standard"), true, wxGBPosition (r, 0)); _standard = new wxChoice (_panel, wxID_ANY); grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); @@ -111,6 +128,7 @@ DCPPanel::DCPPanel (wxNotebook* n, boost::shared_ptr f) _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::dcp_content_type_changed, this)); _signed->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::signed_toggled, this)); _encrypted->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::encrypted_toggled, this)); + _edit_key->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::edit_key_clicked, this)); _standard->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::standard_changed, this)); vector const ct = DCPContentType::all (); @@ -124,6 +142,16 @@ DCPPanel::DCPPanel (wxNotebook* n, boost::shared_ptr f) Config::instance()->Changed.connect (boost::bind (&DCPPanel::config_changed, this)); } +void +DCPPanel::edit_key_clicked () +{ + KeyDialog* d = new KeyDialog (_panel, _film->key ()); + if (d->ShowModal () == wxID_OK) { + _film->set_key (d->key ()); + } + d->Destroy (); +} + void DCPPanel::name_changed () { @@ -258,10 +286,17 @@ DCPPanel::film_changed (int p) if (_film->encrypted ()) { _film->set_signed (true); _signed->Enable (false); + _key->Enable (_generally_sensitive); + _edit_key->Enable (_generally_sensitive); } else { _signed->Enable (_generally_sensitive); + _key->Enable (false); + _edit_key->Enable (false); } break; + case Film::KEY: + checked_set (_key, _film->key().hex().substr (0, 8) + "..."); + break; case Film::RESOLUTION: checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1); setup_dcp_name (); @@ -390,6 +425,7 @@ DCPPanel::set_film (shared_ptr film) film_changed (Film::SIGNED); film_changed (Film::BURN_SUBTITLES); film_changed (Film::ENCRYPTED); + film_changed (Film::KEY); film_changed (Film::J2K_BANDWIDTH); film_changed (Film::ISDCF_METADATA); film_changed (Film::VIDEO_FRAME_RATE); @@ -416,6 +452,8 @@ DCPPanel::set_general_sensitivity (bool s) _signed->Enable (si); _encrypted->Enable (s); + _key->Enable (s && _film && _film->encrypted ()); + _edit_key->Enable (s && _film && _film->encrypted ()); _frame_rate_choice->Enable (s); _frame_rate_spin->Enable (s); _audio_channels->Enable (s); diff --git a/src/wx/dcp_panel.h b/src/wx/dcp_panel.h index c5c76f27a..96786d8a1 100644 --- a/src/wx/dcp_panel.h +++ b/src/wx/dcp_panel.h @@ -67,6 +67,7 @@ private: void signed_toggled (); void burn_subtitles_toggled (); void encrypted_toggled (); + void edit_key_clicked (); void setup_frame_rate_widget (); void setup_container (); @@ -101,6 +102,8 @@ private: wxCheckBox* _signed; wxCheckBox* _burn_subtitles; wxCheckBox* _encrypted; + wxStaticText* _key; + wxButton* _edit_key; boost::shared_ptr _film; bool _generally_sensitive; diff --git a/src/wx/key_dialog.cc b/src/wx/key_dialog.cc new file mode 100644 index 000000000..d7c809609 --- /dev/null +++ b/src/wx/key_dialog.cc @@ -0,0 +1,73 @@ +/* + Copyright (C) 2015 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "key_dialog.h" +#include "wx_util.h" + +using std::cout; + +KeyDialog::KeyDialog (wxWindow* parent, dcp::Key key) + : TableDialog (parent, _("Key"), 3, true) +{ + add (_("Key"), true); + + wxClientDC dc (parent); + wxSize size = dc.GetTextExtent (wxT ("0123456790ABCDEF0123456790ABCDEF")); + size.SetHeight (-1); + + wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); + wxArrayString list; + + wxString n (wxT ("0123456789abcdefABCDEF")); + for (size_t i = 0; i < n.Length(); ++i) { + list.Add (n[i]); + } + + validator.SetIncludes (list); + + _key = add (new wxTextCtrl (this, wxID_ANY, _(""), wxDefaultPosition, size, 0, validator)); + _key->SetValue (std_to_wx (key.hex ())); + _key->SetMaxLength (32); + + _random = add (new wxButton (this, wxID_ANY, _("Random"))); + + _key->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&KeyDialog::key_changed, this)); + _random->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KeyDialog::random, this)); + + layout (); +} + +dcp::Key +KeyDialog::key () const +{ + return dcp::Key (wx_to_std (_key->GetValue ())); +} + +void +KeyDialog::key_changed () +{ + wxButton* ok = dynamic_cast (FindWindowById (wxID_OK)); + ok->Enable (_key->GetValue().Length() == 32); +} + +void +KeyDialog::random () +{ + _key->SetValue (dcp::Key().hex ()); +} diff --git a/src/wx/key_dialog.h b/src/wx/key_dialog.h new file mode 100644 index 000000000..81402d46e --- /dev/null +++ b/src/wx/key_dialog.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2015 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "table_dialog.h" +#include + +class KeyDialog : public TableDialog +{ +public: + KeyDialog (wxWindow *, dcp::Key); + + dcp::Key key () const; + +private: + void key_changed (); + void random (); + + wxTextCtrl* _key; + wxButton* _random; +}; diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index 9c70a001e..f1c6e30f3 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -363,7 +363,7 @@ Timeline::set_position_from_event (wxMouseEvent& ev) if (_snap) { - DCPTime const new_end = new_position + _down_view->content()->length_after_trim () - 1; + DCPTime const new_end = new_position + _down_view->content()->length_after_trim () - DCPTime (1); /* Signed `distance' to nearest thing (i.e. negative is left on the timeline, positive is right). */ @@ -377,9 +377,9 @@ Timeline::set_position_from_event (wxMouseEvent& ev) } maybe_snap (cv->content()->position(), new_position, nearest_distance); - maybe_snap (cv->content()->position(), new_end + 1, nearest_distance); - maybe_snap (cv->content()->end() + 1, new_position, nearest_distance); - maybe_snap (cv->content()->end() + 1, new_end, nearest_distance); + maybe_snap (cv->content()->position(), new_end + DCPTime (1), nearest_distance); + maybe_snap (cv->content()->end() + DCPTime (1), new_position, nearest_distance); + maybe_snap (cv->content()->end() + DCPTime (1), new_end, nearest_distance); } if (nearest_distance) { diff --git a/src/wx/wscript b/src/wx/wscript index aa5487f5f..1b701bb07 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -33,6 +33,7 @@ sources = """ hints_dialog.cc job_manager_view.cc kdm_dialog.cc + key_dialog.cc make_signer_chain_dialog.cc new_film_dialog.cc preset_colour_conversion_dialog.cc -- 2.30.2