From 692f9e2951a8bf600f95bb0b76c18df71c881504 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 13 Mar 2016 02:48:32 +0000 Subject: [PATCH] Ignore empty KDM email addresses (#818). --- ChangeLog | 2 ++ src/lib/util.cc | 6 ++++++ src/lib/util.h | 1 + src/tools/dcpomatic_kdm.cc | 2 +- src/wx/cinema_dialog.cc | 3 ++- src/wx/config_dialog.cc | 8 +++++++- src/wx/editable_list.cc | 24 ++++++++++++++++++++++++ src/wx/editable_list.h | 25 +++++++++++++++++++------ src/wx/screen_dialog.cc | 8 +++++++- src/wx/wscript | 1 + 10 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 src/wx/editable_list.cc diff --git a/ChangeLog b/ChangeLog index 0aa5b155a..0b6c9c432 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2016-03-13 Carl Hetherington + * Ignore empty email addresses for KDMs (#818). + * Fix crash when using non-English decimal separators in the audio gain calculator dialogue (#824). diff --git a/src/lib/util.cc b/src/lib/util.cc index 61c9dac06..6f366257c 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -636,3 +636,9 @@ relaxed_string_to_float (string s) return lexical_cast (s); } } + +bool +string_not_empty (string s) +{ + return !s.empty (); +} diff --git a/src/lib/util.h b/src/lib/util.h index 640933f00..142b21e96 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -75,5 +75,6 @@ extern std::map split_get_request (std::string url); extern std::string video_asset_filename (boost::shared_ptr asset); extern std::string audio_asset_filename (boost::shared_ptr asset); extern float relaxed_string_to_float (std::string); +extern bool string_not_empty (std::string); #endif diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc index b98ec84a9..6c3103da2 100644 --- a/src/tools/dcpomatic_kdm.cc +++ b/src/tools/dcpomatic_kdm.cc @@ -146,7 +146,7 @@ public: vector columns; columns.push_back (wx_to_std (_("CPL"))); _dkdm = new EditableList ( - overall_panel, columns, bind (&DOMFrame::dkdms, this), bind (&DOMFrame::set_dkdms, this, _1), bind (&column, _1), false + overall_panel, columns, bind (&DOMFrame::dkdms, this), bind (&DOMFrame::set_dkdms, this, _1), bind (&always_valid), bind (&column, _1), false ); vertical->Add (_dkdm, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP); diff --git a/src/wx/cinema_dialog.cc b/src/wx/cinema_dialog.cc index 6fb4acc6b..c0b7b5242 100644 --- a/src/wx/cinema_dialog.cc +++ b/src/wx/cinema_dialog.cc @@ -20,6 +20,7 @@ #include "cinema_dialog.h" #include "wx_util.h" #include "lib/dcpomatic_assert.h" +#include "lib/util.h" #include using std::string; @@ -63,7 +64,7 @@ CinemaDialog::CinemaDialog (wxWindow* parent, string title, string name, list columns; columns.push_back (wx_to_std (_("Address"))); _email_list = new EditableList ( - this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), bind (&column, _1) + this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), bind (&string_not_empty, _1), bind (&column, _1) ); sizer->Add (_email_list, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND); diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index 7e70326dc..50d806f35 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -639,6 +639,7 @@ private: columns, boost::bind (&Config::servers, Config::instance()), boost::bind (&Config::set_servers, Config::instance(), _1), + boost::bind (&always_valid), boost::bind (&EncodingServersPage::server_column, this, _1) ); @@ -1251,7 +1252,12 @@ private: columns.push_back (wx_to_std (_("Address"))); add_label_to_sizer (table, _panel, _("CC addresses"), true); _kdm_cc = new EditableList ( - _panel, columns, bind (&Config::kdm_cc, Config::instance()), bind (&Config::set_kdm_cc, Config::instance(), _1), bind (&column, _1) + _panel, + columns, + bind (&Config::kdm_cc, Config::instance()), + bind (&Config::set_kdm_cc, Config::instance(), _1), + bind (&string_not_empty, _1), + bind (&column, _1) ); table->Add (_kdm_cc, 1, wxEXPAND | wxALL); diff --git a/src/wx/editable_list.cc b/src/wx/editable_list.cc new file mode 100644 index 000000000..28017e01a --- /dev/null +++ b/src/wx/editable_list.cc @@ -0,0 +1,24 @@ +/* + Copyright (C) 2016 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. + +*/ + +bool +always_valid () +{ + return true; +} diff --git a/src/wx/editable_list.h b/src/wx/editable_list.h index 47eb254e9..b756a408b 100644 --- a/src/wx/editable_list.h +++ b/src/wx/editable_list.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2016 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 @@ -26,6 +26,8 @@ #include #include +bool always_valid (); + /** @param T type of things being edited. * @param S dialog to edit a thing. */ @@ -38,6 +40,7 @@ public: std::vector columns, boost::function ()> get, boost::function)> set, + boost::function valid, boost::function column, bool can_edit = true, bool title = true @@ -45,6 +48,7 @@ public: : wxPanel (parent) , _get (get) , _set (set) + , _valid (valid) , _columns (columns.size ()) , _column (column) , _edit (0) @@ -158,10 +162,13 @@ private: S* dialog = new S (this); if (dialog->ShowModal() == wxID_OK) { - add_to_control (dialog->get ()); - std::vector all = _get (); - all.push_back (dialog->get ()); - _set (all); + T const v = dialog->get (); + if (_valid (v)) { + add_to_control (v); + std::vector all = _get (); + all.push_back (v); + _set (all); + } } dialog->Destroy (); @@ -180,7 +187,12 @@ private: S* dialog = new S (this); dialog->set (all[item]); if (dialog->ShowModal() == wxID_OK) { - all[item] = dialog->get (); + T const v = dialog->get (); + if (!_valid (v)) { + return; + } + + all[item] = v; } dialog->Destroy (); @@ -217,6 +229,7 @@ private: boost::function ()> _get; boost::function )> _set; + boost::function _valid; int _columns; boost::function _column; diff --git a/src/wx/screen_dialog.cc b/src/wx/screen_dialog.cc index 705a7ff58..f640cdbc2 100644 --- a/src/wx/screen_dialog.cc +++ b/src/wx/screen_dialog.cc @@ -92,7 +92,13 @@ ScreenDialog::ScreenDialog (wxWindow* parent, string title, string name, optiona vector columns; columns.push_back (wx_to_std (_("Thumbprint"))); _trusted_device_list = new EditableList ( - this, columns, bind (&ScreenDialog::trusted_devices, this), bind (&ScreenDialog::set_trusted_devices, this, _1), bind (&column, _1), false + this, + columns, + bind (&ScreenDialog::trusted_devices, this), + bind (&ScreenDialog::set_trusted_devices, this, _1), + bind (&always_valid), + bind (&column, _1), + false ); _sizer->Add (_trusted_device_list, wxGBPosition (r, 0), wxGBSpan (1, 3), wxEXPAND); diff --git a/src/wx/wscript b/src/wx/wscript index e25335682..19ff17d4e 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -39,6 +39,7 @@ sources = """ content_properties_dialog.cc content_sub_panel.cc dcp_panel.cc + editable_list.cc email_dialog.cc image_sequence_dialog.cc image_subtitle_colour_dialog.cc -- 2.30.2