Use release territory from Interop/SMPTE metadata instead of ISDCF metadata dialogue.
[dcpomatic.git] / src / wx / metadata_dialog.cc
index 5462db6a45d45000fac6eb876fce2decc0b2754e..376591ca23760977457b23f8e767c3bfa1b21ba8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
+#include "dcpomatic_button.h"
+#include "full_language_tag_dialog.h"
 #include "metadata_dialog.h"
-#include "editable_list.h"
-#include "rating_dialog.h"
+#include "wx_util.h"
 #include "lib/film.h"
-#include <dcp/types.h>
-#include <wx/gbsizer.h>
+#include <boost/bind.hpp>
+#include <boost/weak_ptr.hpp>
+#include <wx/notebook.h>
+#include <wx/wx.h>
 
-using std::string;
-using std::vector;
-using boost::weak_ptr;
-using boost::shared_ptr;
 
-static string
-column (dcp::Rating r, int c)
-{
-       if (c == 0) {
-               return r.agency;
-       }
+using std::weak_ptr;
 
-       return r.label;
-}
 
-MetadataDialog::MetadataDialog (wxWindow* parent, weak_ptr<Film> film)
+MetadataDialog::MetadataDialog (wxWindow* parent, weak_ptr<Film> weak_film)
        : wxDialog (parent, wxID_ANY, _("Metadata"))
-       , _film (film)
+       , WeakFilm (weak_film)
 {
-       wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
-       SetSizer (overall_sizer);
 
-       wxFlexGridSizer* sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
-       sizer->AddGrowableCol (1, 1);
+}
 
-       {
-               int flags = wxALIGN_TOP | wxLEFT | wxRIGHT | wxTOP;
-#ifdef __WXOSX__
-               flags |= wxALIGN_RIGHT;
-#endif
-               wxStaticText* m = create_label (this, _("Ratings"), true);
-               sizer->Add (m, 0, flags, DCPOMATIC_SIZER_GAP);
-       }
 
-       vector<EditableListColumn> columns;
-       columns.push_back (EditableListColumn("Agency", 200, true));
-       columns.push_back (EditableListColumn("Label", 50, false));
-       _ratings = new EditableList<dcp::Rating, RatingDialog> (
-               this,
-               columns,
-               boost::bind(&MetadataDialog::ratings, this),
-               boost::bind(&MetadataDialog::set_ratings, this, _1),
-               boost::bind(&column, _1, _2),
-               true,
-               false
-               );
-       sizer->Add (_ratings, 1, wxEXPAND);
-
-       add_label_to_sizer (sizer, this, _("Content version"), true);
-       _content_version = new wxTextCtrl (this, wxID_ANY);
-       sizer->Add (_content_version, 1, wxEXPAND);
-
-       shared_ptr<Film> f = _film.lock();
-       DCPOMATIC_ASSERT (f);
-       _content_version->SetValue (std_to_wx(f->content_version()));
-
-       overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
-
-       wxSizer* buttons = CreateSeparatedButtonSizer (wxCLOSE);
+void
+MetadataDialog::setup ()
+{
+       auto notebook = new wxNotebook (this, wxID_ANY);
+
+       auto prepare = [notebook](std::function<void (wxPanel*, wxSizer*)> setup, wxString name) {
+               auto panel = new wxPanel (notebook, wxID_ANY);
+               auto sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+               sizer->AddGrowableCol (1, 1);
+               setup (panel, sizer);
+               auto overall_sizer = new wxBoxSizer (wxVERTICAL);
+               overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
+               panel->SetSizer (overall_sizer);
+               notebook->AddPage (panel, name);
+       };
+
+       prepare (boost::bind(&MetadataDialog::setup_standard, this, _1, _2), _("Standard"));
+       prepare (boost::bind(&MetadataDialog::setup_advanced, this, _1, _2), _("Advanced"));
+
+       auto overall_sizer = new wxBoxSizer (wxVERTICAL);
+       overall_sizer->Add (notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
+
+       auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
        if (buttons) {
                overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
        }
 
+       SetSizer (overall_sizer);
        overall_sizer->Layout ();
        overall_sizer->SetSizeHints (this);
 
-       _content_version->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::content_version_changed, this));
+       _film_changed_connection = film()->Change.connect(boost::bind(&MetadataDialog::film_changed, this, _1, _2));
+
+       film_changed (ChangeType::DONE, Film::Property::RELEASE_TERRITORY);
 }
 
-vector<dcp::Rating>
-MetadataDialog::ratings () const
+
+void
+MetadataDialog::film_changed (ChangeType type, Film::Property property)
 {
-       shared_ptr<Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       return film->ratings ();
+       if (type != ChangeType::DONE) {
+               return;
+       }
+
+       if (property == Film::Property::RELEASE_TERRITORY) {
+               auto rt = film()->release_territory();
+               checked_set (_enable_release_territory, static_cast<bool>(rt));
+               if (rt) {
+                       _release_territory = *rt;
+                       checked_set (_release_territory_text, std_to_wx(*dcp::LanguageTag::get_subtag_description(*_release_territory)));
+               }
+       }
 }
 
+
 void
-MetadataDialog::set_ratings (vector<dcp::Rating> r)
+MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
 {
-       shared_ptr<Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       film->set_ratings (r);
+       _enable_release_territory = new wxCheckBox (panel, wxID_ANY, _("Release territory"));
+       sizer->Add (_enable_release_territory, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
+       {
+               auto s = new wxBoxSizer (wxHORIZONTAL);
+               _release_territory_text = new wxStaticText (panel, wxID_ANY, wxT(""));
+               s->Add (_release_territory_text, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
+               _edit_release_territory = new Button (panel, _("Edit..."));
+               s->Add (_edit_release_territory, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
+               sizer->Add (s, 0, wxEXPAND);
+       }
+
+       _edit_release_territory->Bind (wxEVT_BUTTON, boost::bind(&MetadataDialog::edit_release_territory, this));
+       _enable_release_territory->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_release_territory_changed, this));
 }
 
+
 void
-MetadataDialog::content_version_changed ()
+MetadataDialog::edit_release_territory ()
 {
-       shared_ptr<Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       film->set_content_version (wx_to_std(_content_version->GetValue()));
+       DCPOMATIC_ASSERT (film()->release_territory());
+       auto d = new RegionSubtagDialog(this, *film()->release_territory());
+       d->ShowModal ();
+       auto tag = d->get();
+       if (tag) {
+               _release_territory = *tag;
+               film()->set_release_territory(*tag);
+       }
+       d->Destroy ();
 }
+
+
+void
+MetadataDialog::setup_sensitivity ()
+{
+       auto const enabled = _enable_release_territory->GetValue();
+       _release_territory_text->Enable (enabled);
+       _edit_release_territory->Enable (enabled);
+}
+
+
+void
+MetadataDialog::enable_release_territory_changed ()
+{
+       setup_sensitivity ();
+       if (_enable_release_territory->GetValue()) {
+               film()->set_release_territory (_release_territory.get_value_or(dcp::LanguageTag::RegionSubtag("US")));
+       } else {
+               film()->set_release_territory ();
+       }
+}
+