Add LanguageTagWidget and use it for the SMPTE metadata.
authorCarl Hetherington <cth@carlh.net>
Sun, 15 Nov 2020 22:16:56 +0000 (23:16 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 15 Nov 2020 22:16:56 +0000 (23:16 +0100)
src/wx/language_tag_widget.cc [new file with mode: 0644]
src/wx/language_tag_widget.h [new file with mode: 0644]
src/wx/smpte_metadata_dialog.cc
src/wx/smpte_metadata_dialog.h
src/wx/wscript

diff --git a/src/wx/language_tag_widget.cc b/src/wx/language_tag_widget.cc
new file mode 100644 (file)
index 0000000..592741b
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+    Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "dcpomatic_button.h"
+#include "language_tag_dialog.h"
+#include "language_tag_widget.h"
+#include "wx_util.h"
+#include <wx/wx.h>
+
+
+LanguageTagWidget::LanguageTagWidget (wxWindow* parent, wxSizer* sizer, wxString label, wxString tooltip, dcp::LanguageTag tag)
+       : _parent (parent)
+{
+       add_label_to_sizer(sizer, parent, label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
+       wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
+       _language = new wxStaticText (parent, wxID_ANY, wxT(""));
+       _language->SetToolTip (tooltip);
+       set (tag);
+       s->Add (_language, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
+       _edit = new Button (parent, _("Edit..."));
+       s->Add (_edit, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
+       sizer->Add (s, 0, wxEXPAND);
+
+       _edit->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagWidget::edit, this));
+}
+
+
+void
+LanguageTagWidget::edit ()
+{
+       LanguageTagDialog* d = new LanguageTagDialog(_parent, _tag);
+       d->ShowModal ();
+       set (d->get());
+       Changed (d->get());
+       d->Destroy ();
+}
+
+
+void
+LanguageTagWidget::set (dcp::LanguageTag tag)
+{
+       _tag = tag;
+       checked_set (_language, std_to_wx(tag.to_string()));
+}
diff --git a/src/wx/language_tag_widget.h b/src/wx/language_tag_widget.h
new file mode 100644 (file)
index 0000000..eee72f6
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+    Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include <dcp/language_tag.h>
+#include <wx/wx.h>
+#include <boost/noncopyable.hpp>
+#include <boost/signals2.hpp>
+
+
+class wxButton;
+class wxSizer;
+class wxStaticText;
+class wxWindow;
+
+
+class LanguageTagWidget : public boost::noncopyable
+{
+public:
+       LanguageTagWidget (wxWindow* parent, wxSizer* sizer, wxString label, wxString tooltip, dcp::LanguageTag tag);
+
+       void set (dcp::LanguageTag tag);
+
+       boost::signals2::signal<void (dcp::LanguageTag)> Changed;
+
+private:
+       void edit ();
+
+       wxStaticText* _language;
+       wxButton* _edit;
+       wxWindow* _parent;
+       dcp::LanguageTag _tag;
+};
+
index ba45329f28ca9c1b0d07f96161f9a45e9f24771f..faf63d6cade749b5921540725da18dc5febad2cf 100644 (file)
@@ -21,6 +21,7 @@
 #include "content_version_dialog.h"
 #include "editable_list.h"
 #include "language_tag_dialog.h"
+#include "language_tag_widget.h"
 #include "smpte_metadata_dialog.h"
 #include "rating_dialog.h"
 #include "lib/film.h"
@@ -66,29 +67,21 @@ SMPTEMetadataDialog::SMPTEMetadataDialog (wxWindow* parent, weak_ptr<Film> weak_
        wxFlexGridSizer* sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
        sizer->AddGrowableCol (1, 1);
 
-       wxButton* edit_name_language = 0;
-       add_label_to_sizer(sizer, this, _("Title language"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
-       {
-               wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
-               _name_language = new wxStaticText (this, wxID_ANY, wxT(""));
-               _name_language->SetToolTip (wxString::Format(_("The language that the film's title (\"%s\") is in"), std_to_wx(film()->name())));
-               s->Add (_name_language, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
-               edit_name_language = new Button (this, _("Edit..."));
-               s->Add (edit_name_language, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
-               sizer->Add (s, 0, wxEXPAND);
-       }
+       _name_language = new LanguageTagWidget(
+               this,
+               sizer,
+               _("Title language"),
+               wxString::Format(_("The language that the film's title (\"%s\") is in"), std_to_wx(film()->name())),
+               film()->name_language()
+               );
 
-       wxButton* edit_audio_language = 0;
-       add_label_to_sizer(sizer, this, _("Audio language"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
-       {
-               wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
-               _audio_language = new wxStaticText (this, wxID_ANY, wxT(""));
-               _audio_language->SetToolTip (_("The main language that is spoken in the film's soundtrack"));
-               s->Add (_audio_language, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
-               edit_audio_language = new Button (this, _("Edit..."));
-               s->Add (edit_audio_language, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
-               sizer->Add (s, 0, wxEXPAND);
-       }
+       _audio_language = new LanguageTagWidget(
+               this,
+               sizer,
+               _("Audio language"),
+               _("The main language that is spoken in the film's soundtrack"),
+               film()->audio_language()
+               );
 
        Button* edit_release_territory = 0;
        add_label_to_sizer (sizer, this, _("Release territory"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
@@ -195,8 +188,8 @@ SMPTEMetadataDialog::SMPTEMetadataDialog (wxWindow* parent, weak_ptr<Film> weak_
        _luminance_unit->Append (_("candela per m²"));
        _luminance_unit->Append (_("foot lambert"));
 
-       edit_name_language->Bind (wxEVT_BUTTON, boost::bind(&SMPTEMetadataDialog::edit_name_language, this));
-       edit_audio_language->Bind (wxEVT_BUTTON, boost::bind(&SMPTEMetadataDialog::edit_audio_language, this));
+       _name_language->Changed.connect (boost::bind(&SMPTEMetadataDialog::name_language_changed, this, _1));
+       _audio_language->Changed.connect (boost::bind(&SMPTEMetadataDialog::audio_language_changed, this, _1));
        edit_release_territory->Bind (wxEVT_BUTTON, boost::bind(&SMPTEMetadataDialog::edit_release_territory, this));
        _version_number->Bind (wxEVT_SPINCTRL, boost::bind(&SMPTEMetadataDialog::version_number_changed, this));
        _status->Bind (wxEVT_CHOICE, boost::bind(&SMPTEMetadataDialog::status_changed, this));
@@ -230,7 +223,7 @@ SMPTEMetadataDialog::film_changed (ChangeType type, Film::Property property)
        }
 
        if (property == Film::NAME_LANGUAGE) {
-               checked_set (_name_language, std_to_wx(film()->name_language().to_string()));
+               _name_language->set (film()->name_language());
        } else if (property == Film::RELEASE_TERRITORY) {
                checked_set (_release_territory, std_to_wx(*dcp::LanguageTag::get_subtag_description(dcp::LanguageTag::REGION, film()->release_territory().subtag())));
        } else if (property == Film::VERSION_NUMBER) {
@@ -296,22 +289,16 @@ SMPTEMetadataDialog::set_content_versions (vector<string> cv)
 
 
 void
-SMPTEMetadataDialog::edit_name_language ()
+SMPTEMetadataDialog::name_language_changed (dcp::LanguageTag tag)
 {
-       LanguageTagDialog* d = new LanguageTagDialog(this, film()->name_language());
-       d->ShowModal ();
-       film()->set_name_language (d->get());
-       d->Destroy ();
+       film()->set_name_language (tag);
 }
 
 
 void
-SMPTEMetadataDialog::edit_audio_language ()
+SMPTEMetadataDialog::audio_language_changed (dcp::LanguageTag tag)
 {
-       LanguageTagDialog* d = new LanguageTagDialog(this, film()->audio_language());
-       d->ShowModal ();
-       film()->set_audio_language (d->get());
-       d->Destroy ();
+       film()->set_audio_language (tag);
 }
 
 
index 4859002e1a8b50d097424e9270d6c263e316254e..e47ffe288e9853358d8a22b6dbc336ae05802a81 100644 (file)
@@ -30,6 +30,7 @@
 class Film;
 class RatingDialog;
 class ContentVersionDialog;
+class LanguageTagWidget;
 
 
 class SMPTEMetadataDialog : public wxDialog
@@ -42,8 +43,8 @@ private:
        void set_ratings (std::vector<dcp::Rating> r);
        std::vector<std::string> content_versions () const;
        void set_content_versions (std::vector<std::string> v);
-       void edit_name_language ();
-       void edit_audio_language ();
+       void name_language_changed (dcp::LanguageTag tag);
+       void audio_language_changed (dcp::LanguageTag tag);
        void edit_release_territory ();
        void version_number_changed ();
        void status_changed ();
@@ -55,8 +56,8 @@ private:
        boost::shared_ptr<Film> film () const;
 
        boost::weak_ptr<Film> _film;
-       wxStaticText* _name_language;
-       wxStaticText* _audio_language;
+       LanguageTagWidget* _name_language;
+       LanguageTagWidget* _audio_language;
        wxStaticText* _release_territory;
        wxSpinCtrl* _version_number;
        wxChoice* _status;
index 3f0ca2b979e1a32eacefa0df7d34bcff6c8bfd9b..a5597a87b9ead7dba02d8a5280da73ddaa04d2ef 100644 (file)
@@ -94,6 +94,7 @@ sources = """
           kdm_output_panel.cc
           kdm_timing_panel.cc
           language_tag_dialog.cc
+          language_tag_widget.cc
           make_chain_dialog.cc
           markers_dialog.cc
           message_dialog.cc