Add simpler language tag dialog (#1931).
authorCarl Hetherington <cth@carlh.net>
Sat, 20 Mar 2021 07:38:25 +0000 (08:38 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 22 Mar 2021 08:56:55 +0000 (09:56 +0100)
platform/windows/wscript
src/lib/config.cc
src/lib/config.h
src/wx/language_tag_dialog.cc [new file with mode: 0644]
src/wx/language_tag_dialog.h [new file with mode: 0644]
src/wx/language_tag_widget.cc
src/wx/smpte_metadata_dialog.cc
src/wx/smpte_metadata_dialog.h
src/wx/wscript

index 9357e74ef5f95c742ee1747024e1da6d73efd217..930fbfa0d3448de0d0ca61d3d5d422245b53d7e0 100644 (file)
@@ -336,6 +336,7 @@ File "%cdist_deps%/share/libdcp/tags/language"
 File "%cdist_deps%/share/libdcp/tags/region"
 File "%cdist_deps%/share/libdcp/tags/script"
 File "%cdist_deps%/share/libdcp/tags/variant"
+File "%cdist_deps%/share/libdcp/tags/dcnc"
 
 SectionEnd
     """, file=f)
index 23b06f2e40a7ac9fdeea84eccd05344473c76b64..0dcc8411775f5f6e138a4055fa0604cf13b239e5 100644 (file)
@@ -176,6 +176,7 @@ Config::set_defaults ()
        _player_kdm_directory = boost::none;
        _audio_mapping = boost::none;
        _minimum_frame_size = 65536;
+       _custom_languages.clear ();
 
        _allowed_dcp_frame_rates.clear ();
        _allowed_dcp_frame_rates.push_back (24);
@@ -552,6 +553,15 @@ try
 
        _minimum_frame_size = f.optional_number_child<int>("MinimumFrameSize").get_value_or(65536);
 
+       for (auto i: f.node_children("CustomLanguage")) {
+               try {
+                       /* This will fail if it's called before dcp::init() as it won't recognise the
+                        * tag.  That's OK because the Config will be reloaded again later.
+                        */
+                       _custom_languages.push_back (dcp::LanguageTag(i->content()));
+               } catch (std::runtime_error& e) {}
+       }
+
        if (boost::filesystem::exists (_cinemas_file)) {
                cxml::Document f ("Cinemas");
                f.read_file (_cinemas_file);
@@ -981,6 +991,9 @@ Config::write_config () const
                _audio_mapping->as_xml (root->add_child("AudioMapping"));
        }
        root->add_child("MinimumFrameSize")->add_child_text(raw_convert<string>(_minimum_frame_size));
+       for (auto const& i: _custom_languages) {
+               root->add_child("CustomLanguage")->add_child_text(i.to_string());
+       }
 
        try {
                auto const s = doc.write_to_string_formatted ();
@@ -1420,3 +1433,14 @@ Config::set_audio_mapping_to_default ()
        _audio_mapping = audio_mapping (ch);
        changed (AUDIO_MAPPING);
 }
+
+
+void
+Config::add_custom_language (dcp::LanguageTag tag)
+{
+       if (find(_custom_languages.begin(), _custom_languages.end(), tag) == _custom_languages.end()) {
+               _custom_languages.push_back (tag);
+               changed ();
+       }
+}
+
index 0e8fccb5330d73a8470faaecd99368aa362da05e..3371e48bfc3b5dfa5cc1815b04de8d9f33c8d1c4 100644 (file)
@@ -33,6 +33,7 @@
 #include <dcp/name_format.h>
 #include <dcp/certificate_chain.h>
 #include <dcp/encrypted_kdm.h>
+#include <dcp/language_tag.h>
 #include <boost/signals2.hpp>
 #include <boost/filesystem.hpp>
 #include <vector>
@@ -540,6 +541,10 @@ public:
                return _minimum_frame_size;
        }
 
+       std::vector<dcp::LanguageTag> custom_languages () const {
+               return _custom_languages;
+       }
+
        /* SET (mostly) */
 
        void set_master_encoding_threads (int n) {
@@ -1055,6 +1060,8 @@ public:
                maybe_set (_minimum_frame_size, size);
        }
 
+       void add_custom_language (dcp::LanguageTag tag);
+
        void changed (Property p = OTHER);
        boost::signals2::signal<void (Property)> Changed;
        /** Emitted if read() failed on an existing Config file.  There is nothing
@@ -1269,6 +1276,7 @@ private:
        boost::optional<boost::filesystem::path> _player_kdm_directory;
        boost::optional<AudioMapping> _audio_mapping;
        int _minimum_frame_size;
+       std::vector<dcp::LanguageTag> _custom_languages;
 
        static int const _current_version;
 
diff --git a/src/wx/language_tag_dialog.cc b/src/wx/language_tag_dialog.cc
new file mode 100644 (file)
index 0000000..96e7c52
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+    Copyright (C) 2021 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 "full_language_tag_dialog.h"
+#include "language_tag_dialog.h"
+#include "wx_util.h"
+#include "lib/config.h"
+#include <wx/listctrl.h>
+#include <wx/wx.h>
+#include <dcp/language_tag.h>
+
+
+using std::vector;
+
+
+LanguageTagDialog::LanguageTagDialog (wxWindow* parent, dcp::LanguageTag tag)
+       : wxDialog (parent, wxID_ANY, _("Language Tag"))
+{
+       _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize(600, 700), wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER);
+       _list->AppendColumn ("", wxLIST_FORMAT_LEFT, 400);
+       _list->AppendColumn ("", wxLIST_FORMAT_LEFT, 150);
+       auto add = new wxButton (this, wxID_ANY, _("Add language..."));
+
+       auto overall_sizer = new wxBoxSizer (wxVERTICAL);
+       overall_sizer->Add (_list, 0, wxALL, DCPOMATIC_SIZER_GAP);
+       overall_sizer->Add (add, 0, wxALL, DCPOMATIC_SIZER_GAP);
+
+       auto buttons = CreateSeparatedButtonSizer (wxOK);
+       if (buttons) {
+               overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
+       }
+
+       SetSizerAndFit (overall_sizer);
+
+       for (auto const& i: dcp::dcnc_tags()) {
+               _presets.push_back (dcp::LanguageTag(i.first));
+       }
+
+       std::sort (_presets.begin(), _presets.end(), [](dcp::LanguageTag const& i, dcp::LanguageTag const& j) {
+               return i.description() < j.description();
+       });
+
+       _custom = Config::instance()->custom_languages ();
+
+       populate_list ();
+
+       set (tag);
+
+       add->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagDialog::add_language, this));
+}
+
+
+void
+LanguageTagDialog::add_language ()
+{
+       auto full = new FullLanguageTagDialog (GetParent());
+       auto r = full->ShowModal ();
+       if (r == wxID_OK) {
+               Config::instance()->add_custom_language (full->get());
+               set (full->get());
+       }
+       full->Destroy ();
+}
+
+
+void
+LanguageTagDialog::populate_list ()
+{
+       _list->DeleteAllItems ();
+
+       auto add = [this](vector<dcp::LanguageTag> const& tags) {
+               for (auto const& i: tags) {
+                       wxListItem it;
+                       it.SetId (_list->GetItemCount());
+                       it.SetColumn (0);
+                       it.SetText (std_to_wx(i.description()));
+                       _list->InsertItem (it);
+                       it.SetColumn (1);
+                       it.SetText (std_to_wx(i.to_string()));
+                       _list->SetItem (it);
+               }
+       };
+
+       add (_presets);
+       add (_custom);
+}
+
+
+void
+LanguageTagDialog::set (dcp::LanguageTag tag)
+{
+       size_t selection = 0;
+
+       auto iter = find(_presets.begin(), _presets.end(), tag);
+       if (iter == _presets.end()) {
+               iter = find(_custom.begin(), _custom.end(), tag);
+               if (iter == _custom.end()) {
+                       _custom.push_back (tag);
+                       selection = _presets.size() + _custom.size() - 1;
+                       populate_list ();
+                       _list->EnsureVisible (_list->GetItemCount() - 1);
+               } else {
+                       selection = _presets.size() + std::distance(_custom.begin(), iter);
+               }
+       } else {
+               selection = std::distance(_presets.begin(), iter);
+       }
+
+       _list->SetItemState (selection, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+}
+
+
+dcp::LanguageTag
+LanguageTagDialog::get () const
+{
+       auto selected = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+       DCPOMATIC_ASSERT (selected >= 0);
+
+       if (selected < static_cast<long>(_presets.size())) {
+               return _presets[selected];
+       }
+
+       selected -= _presets.size();
+
+       DCPOMATIC_ASSERT (selected < static_cast<long>(_custom.size()));
+       return _custom[selected];
+}
+
diff --git a/src/wx/language_tag_dialog.h b/src/wx/language_tag_dialog.h
new file mode 100644 (file)
index 0000000..ae6ea4e
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+    Copyright (C) 2021 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/>.
+
+*/
+
+
+#ifndef DCPOMATIC_LANGUAGE_TAG_DIALOG_H
+#define DCPOMATIC_LANGUAGE_TAG_DIALOG_H
+
+
+#include <dcp/language_tag.h>
+#include <wx/wx.h>
+
+
+class wxListCtrl;
+
+
+class LanguageTagDialog : public wxDialog
+{
+public:
+       LanguageTagDialog (wxWindow* parent, dcp::LanguageTag tag = dcp::LanguageTag("en"));
+
+       dcp::LanguageTag get () const;
+       void set (dcp::LanguageTag tag);
+
+private:
+       void add_language ();
+       void populate_list ();
+
+       std::vector<dcp::LanguageTag> _presets;
+       std::vector<dcp::LanguageTag> _custom;
+       wxListCtrl* _list;
+};
+
+#endif
index a032545adcfca1b7376c4b6ced9967e367bb2611..d71b5fc7aeef9597714dda432a944dc5c86a7ce0 100644 (file)
@@ -20,7 +20,7 @@
 
 
 #include "dcpomatic_button.h"
-#include "full_language_tag_dialog.h"
+#include "language_tag_dialog.h"
 #include "language_tag_widget.h"
 #include "wx_util.h"
 #include <wx/wx.h>
@@ -44,7 +44,7 @@ LanguageTagWidget::LanguageTagWidget (wxWindow* parent, wxString tooltip, dcp::L
 void
 LanguageTagWidget::edit ()
 {
-       auto d = new FullLanguageTagDialog(_parent, _tag);
+       auto d = new LanguageTagDialog(_parent, _tag);
        d->ShowModal ();
        set (d->get());
        Changed (d->get());
index 2f3869d5866e504bd102bd7862f4b5be7b45b38d..64afcac5c2240e6548b6c1a7da08c3042ed69219 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "content_version_dialog.h"
 #include "editable_list.h"
-#include "full_language_tag_dialog.h"
+#include "language_tag_dialog.h"
 #include "language_tag_widget.h"
 #include "smpte_metadata_dialog.h"
 #include "rating_dialog.h"
@@ -111,7 +111,7 @@ SMPTEMetadataDialog::SMPTEMetadataDialog (wxWindow* parent, weak_ptr<Film> weak_
 
        vector<EditableListColumn> columns;
        columns.push_back (EditableListColumn("Language", 250, true));
-       _additional_subtitle_languages = new EditableList<dcp::LanguageTag, FullLanguageTagDialog> (
+       _additional_subtitle_languages = new EditableList<dcp::LanguageTag, LanguageTagDialog> (
                this,
                columns,
                boost::bind(&SMPTEMetadataDialog::additional_subtitle_languages, this),
index 128d155f3f204a80c31dffd8f5ae9b72d9886216..558023b0f26bce6b474e07af6987c9cc46648688 100644 (file)
@@ -32,6 +32,7 @@ class Film;
 class RatingDialog;
 class ContentVersionDialog;
 class LanguageTagWidget;
+class LanguageTagDialog;
 
 
 class SMPTEMetadataDialog : public wxDialog, public WeakFilm
@@ -64,7 +65,7 @@ private:
        LanguageTagWidget* _audio_language;
        wxCheckBox* _enable_main_subtitle_language;
        LanguageTagWidget* _main_subtitle_language;
-       EditableList<dcp::LanguageTag, FullLanguageTagDialog>* _additional_subtitle_languages;
+       EditableList<dcp::LanguageTag, LanguageTagDialog>* _additional_subtitle_languages;
        wxStaticText* _release_territory;
        wxSpinCtrl* _version_number;
        wxChoice* _status;
index 41d51ded5979e69516d9cadb3723e0bd1b6d91f4..f70d2921c5bacda2674b116da107f8fe89550d5b 100644 (file)
@@ -93,6 +93,7 @@ sources = """
           kdm_dialog.cc
           kdm_output_panel.cc
           kdm_timing_panel.cc
+          language_tag_dialog.cc
           language_tag_widget.cc
           make_chain_dialog.cc
           markers_dialog.cc