From: Carl Hetherington Date: Sun, 15 Nov 2015 18:38:47 +0000 (+0000) Subject: Rearrange cerficate download UI a bit. X-Git-Tag: v2.5.4~12 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=1a14ae26a73489ae8990bfda1a432d229c3bb2d5 Rearrange cerficate download UI a bit. --- diff --git a/src/wx/dolby_certificate_dialog.cc b/src/wx/dolby_certificate_dialog.cc deleted file mode 100644 index 8661cd5f8..000000000 --- a/src/wx/dolby_certificate_dialog.cc +++ /dev/null @@ -1,210 +0,0 @@ -/* - Copyright (C) 2014-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 "dolby_certificate_dialog.h" -#include "wx_util.h" -#include "lib/compose.hpp" -#include "lib/internet.h" -#include "lib/signal_manager.h" -#include "lib/util.h" -#include -#include -#include -#include - -using std::list; -using std::string; -using std::vector; -using std::cout; -using boost::optional; -using boost::algorithm::split; -using boost::algorithm::is_any_of; - -DolbyCertificateDialog::DolbyCertificateDialog (wxWindow* parent, boost::function load) - : DownloadCertificateDialog (parent, load) -{ - add (_("Country"), true); - _country = add (new wxChoice (this, wxID_ANY)); - _country->Append (N_("Hashemite Kingdom of Jordan")); - - add (_("Cinema"), true); - _cinema = add (new wxChoice (this, wxID_ANY)); - _cinema->Append (N_("Motion Picture Solutions London Mobile & QC")); - - add (_("Serial number"), true); - _serial = add (new wxChoice (this, wxID_ANY)); - - add_common_widgets (); - - _country->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::country_selected, this)); - _cinema->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::cinema_selected, this)); - _serial->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::serial_selected, this)); - signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::setup_countries, this)); - - _country->Clear (); - _cinema->Clear (); -} - -list -DolbyCertificateDialog::get_dir (string dir) const -{ - string url = String::compose ("ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1", dir); - return ftp_ls (url, false); -} - -void -DolbyCertificateDialog::setup_countries () -{ - if (_country->GetCount() > 0) { - /* Already set up */ - return; - } - - _country->Append (_("Fetching...")); - _country->SetSelection (0); - - /* See DoremiCertificateDialog for discussion about this daft delay */ - wxMilliSleep (200); - - signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_setup_countries, this)); -} - -void -DolbyCertificateDialog::finish_setup_countries () -{ - try { - list const c = get_dir (""); - _country->Clear (); - BOOST_FOREACH (string i, c) { - _country->Append (std_to_wx (i)); - } - } catch (NetworkError& e) { - error_dialog (this, wxString::Format (_("Could not get country list (%s)"), e.what())); - _country->Clear (); - } -} - -void -DolbyCertificateDialog::country_selected () -{ - _cinema->Clear (); - _cinema->Append (_("Fetching...")); - _cinema->SetSelection (0); - -#ifdef DCPOMATIC_OSX - wxMilliSleep (200); -#endif - signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_country_selected, this)); -} - -void -DolbyCertificateDialog::finish_country_selected () -{ - try { - list const c = get_dir (wx_to_std (_country->GetStringSelection())); - _cinema->Clear (); - BOOST_FOREACH (string i, c) { - _cinema->Append (std_to_wx (i)); - } - } catch (NetworkError& e) { - error_dialog (this, wxString::Format (_("Could not get cinema list (%s)"), e.what ())); - _cinema->Clear (); - } -} - -void -DolbyCertificateDialog::cinema_selected () -{ - _serial->Clear (); - _serial->Append (_("Fetching...")); - _serial->SetSelection (0); - -#ifdef DCPOMATIC_OSX - wxMilliSleep (200); -#endif - signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_cinema_selected, this)); -} - -void -DolbyCertificateDialog::finish_cinema_selected () -{ - try { - list const s = get_dir (String::compose ("%1/%2", wx_to_std (_country->GetStringSelection()), wx_to_std (_cinema->GetStringSelection()))); - _serial->Clear (); - BOOST_FOREACH (string i, s) { - vector a; - split (a, i, is_any_of ("-_")); - if (a.size() >= 4) { - _serial->Append (std_to_wx (a[3]), new wxStringClientData (std_to_wx (i))); - } - } - } catch (NetworkError& e) { - error_dialog (this, wxString::Format (_("Could not get screen list (%s)"), e.what())); - _serial->Clear (); - } -} - -void -DolbyCertificateDialog::serial_selected () -{ - _download->Enable (true); -} - -void -DolbyCertificateDialog::download () -{ - downloaded (false); - _message->SetLabel (_("Downloading certificate")); - -#ifdef DCPOMATIC_OSX - wxMilliSleep (200); -#endif - - signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_download, this)); -} - -void -DolbyCertificateDialog::finish_download () -{ - string const zip = string_client_data (_serial->GetClientObject (_serial->GetSelection ())); - - string const file = String::compose ( - "ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1/%2/%3", - wx_to_std (_country->GetStringSelection()), - wx_to_std (_cinema->GetStringSelection()), - zip - ); - - /* Work out the certificate file name inside the zip */ - vector b; - split (b, zip, is_any_of ("_")); - if (b.size() < 2) { - _message->SetLabel (_("Unexpected certificate filename form")); - return; - } - string const cert = b[0] + "_" + b[1] + ".pem.crt"; - - optional error = get_from_zip_url (file, cert, _load); - if (error) { - _message->SetLabel (std_to_wx (error.get ())); - } else { - _message->SetLabel (_("Certificate downloaded")); - downloaded (true); - } -} diff --git a/src/wx/dolby_certificate_dialog.h b/src/wx/dolby_certificate_dialog.h deleted file mode 100644 index e9bbffda0..000000000 --- a/src/wx/dolby_certificate_dialog.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (C) 2014 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 -#include "download_certificate_dialog.h" - -class DolbyCertificateDialog : public DownloadCertificateDialog -{ -public: - DolbyCertificateDialog (wxWindow *, boost::function); - -private: - void download (); - void finish_download (); - void setup_countries (); - void finish_setup_countries (); - void country_selected (); - void finish_country_selected (); - void cinema_selected (); - void finish_cinema_selected (); - void serial_selected (); - std::list get_dir (std::string) const; - - wxChoice* _country; - wxChoice* _cinema; - wxChoice* _serial; -}; diff --git a/src/wx/dolby_certificate_panel.cc b/src/wx/dolby_certificate_panel.cc new file mode 100644 index 000000000..8652f43b6 --- /dev/null +++ b/src/wx/dolby_certificate_panel.cc @@ -0,0 +1,218 @@ +/* + Copyright (C) 2014-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 "dolby_certificate_panel.h" +#include "download_certificate_dialog.h" +#include "wx_util.h" +#include "lib/compose.hpp" +#include "lib/internet.h" +#include "lib/signal_manager.h" +#include "lib/util.h" +#include +#include +#include +#include + +using std::list; +using std::string; +using std::vector; +using std::cout; +using boost::optional; +using boost::algorithm::split; +using boost::algorithm::is_any_of; + +DolbyCertificatePanel::DolbyCertificatePanel (wxWindow* parent, DownloadCertificateDialog* dialog) + : DownloadCertificatePanel (parent, dialog) +{ + add_label_to_sizer (_table, this, _("Country"), true); + _country = new wxChoice (this, wxID_ANY); + _table->Add (_country, 1, wxEXPAND); + _country->Append (N_("Hashemite Kingdom of Jordan")); + + add_label_to_sizer (_table, this, _("Cinema"), true); + _cinema = new wxChoice (this, wxID_ANY); + _table->Add (_cinema, 1, wxEXPAND); + _cinema->Append (N_("Motion Picture Solutions London Mobile & QC")); + + add_label_to_sizer (_table, this, _("Serial number"), true); + _serial = new wxChoice (this, wxID_ANY); + _table->Add (_serial, 1, wxEXPAND); + + layout (); + + _country->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificatePanel::country_selected, this)); + _cinema->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificatePanel::cinema_selected, this)); + _serial->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DownloadCertificateDialog::setup_sensitivity, _dialog)); + + _country->Clear (); + _cinema->Clear (); +} + +list +DolbyCertificatePanel::get_dir (string dir) const +{ + string url = String::compose ("ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1", dir); + return ftp_ls (url, false); +} + +void +DolbyCertificatePanel::setup_countries () +{ + if (_country->GetCount() > 0) { + /* Already set up */ + return; + } + + _country->Append (_("Fetching...")); + _country->SetSelection (0); + + /* See DoremiCertificatePanel for discussion about this daft delay */ + wxMilliSleep (200); + + signal_manager->when_idle (boost::bind (&DolbyCertificatePanel::finish_setup_countries, this)); +} + +void +DolbyCertificatePanel::finish_setup_countries () +{ + try { + list const c = get_dir (""); + _country->Clear (); + BOOST_FOREACH (string i, c) { + _country->Append (std_to_wx (i)); + } + } catch (NetworkError& e) { + error_dialog (this, wxString::Format (_("Could not get country list (%s)"), e.what())); + _country->Clear (); + } +} + +void +DolbyCertificatePanel::country_selected () +{ + _cinema->Clear (); + _cinema->Append (_("Fetching...")); + _cinema->SetSelection (0); + +#ifdef DCPOMATIC_OSX + wxMilliSleep (200); +#endif + signal_manager->when_idle (boost::bind (&DolbyCertificatePanel::finish_country_selected, this)); +} + +void +DolbyCertificatePanel::finish_country_selected () +{ + try { + list const c = get_dir (wx_to_std (_country->GetStringSelection())); + _cinema->Clear (); + BOOST_FOREACH (string i, c) { + _cinema->Append (std_to_wx (i)); + } + } catch (NetworkError& e) { + error_dialog (this, wxString::Format (_("Could not get cinema list (%s)"), e.what ())); + _cinema->Clear (); + } +} + +void +DolbyCertificatePanel::cinema_selected () +{ + _serial->Clear (); + _serial->Append (_("Fetching...")); + _serial->SetSelection (0); + +#ifdef DCPOMATIC_OSX + wxMilliSleep (200); +#endif + signal_manager->when_idle (boost::bind (&DolbyCertificatePanel::finish_cinema_selected, this)); +} + +void +DolbyCertificatePanel::finish_cinema_selected () +{ + try { + list const s = get_dir (String::compose ("%1/%2", wx_to_std (_country->GetStringSelection()), wx_to_std (_cinema->GetStringSelection()))); + _serial->Clear (); + BOOST_FOREACH (string i, s) { + vector a; + split (a, i, is_any_of ("-_")); + if (a.size() >= 4) { + _serial->Append (std_to_wx (a[3]), new wxStringClientData (std_to_wx (i))); + } + } + } catch (NetworkError& e) { + error_dialog (this, wxString::Format (_("Could not get screen list (%s)"), e.what())); + _serial->Clear (); + } +} + +void +DolbyCertificatePanel::download (wxStaticText* message) +{ + message->SetLabel (_("Downloading certificate")); + +#ifdef DCPOMATIC_OSX + wxMilliSleep (200); +#endif + + signal_manager->when_idle (boost::bind (&DolbyCertificatePanel::finish_download, this, message)); +} + +void +DolbyCertificatePanel::finish_download (wxStaticText* message) +{ + string const zip = string_client_data (_serial->GetClientObject (_serial->GetSelection ())); + + string const file = String::compose ( + "ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1/%2/%3", + wx_to_std (_country->GetStringSelection()), + wx_to_std (_cinema->GetStringSelection()), + zip + ); + + /* Work out the certificate file name inside the zip */ + vector b; + split (b, zip, is_any_of ("_")); + if (b.size() < 2) { + message->SetLabel (_("Unexpected certificate filename form")); + return; + } + string const cert = b[0] + "_" + b[1] + ".pem.crt"; + + optional error = get_from_zip_url (file, cert, boost::bind (&DownloadCertificatePanel::load, this, _1)); + if (error) { + message->SetLabel (std_to_wx (error.get ())); + } else { + message->SetLabel (_("Certificate downloaded")); + } +} + +bool +DolbyCertificatePanel::ready_to_download () const +{ + /* XXX */ + return false; +} + +void +DolbyCertificatePanel::setup () +{ + signal_manager->when_idle (boost::bind (&DolbyCertificatePanel::setup_countries, this)); +} diff --git a/src/wx/dolby_certificate_panel.h b/src/wx/dolby_certificate_panel.h new file mode 100644 index 000000000..1ac47ae76 --- /dev/null +++ b/src/wx/dolby_certificate_panel.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2014-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 "download_certificate_panel.h" +#include +#include + +class DolbyCertificatePanel : public DownloadCertificatePanel +{ +public: + DolbyCertificatePanel (wxWindow* parent, DownloadCertificateDialog* dialog); + + void setup (); + bool ready_to_download () const; + void download (wxStaticText* message); + +private: + void finish_download (wxStaticText* message); + void setup_countries (); + void finish_setup_countries (); + void country_selected (); + void finish_country_selected (); + void cinema_selected (); + void finish_cinema_selected (); + std::list get_dir (std::string) const; + + wxChoice* _country; + wxChoice* _cinema; + wxChoice* _serial; +}; diff --git a/src/wx/doremi_certificate_dialog.cc b/src/wx/doremi_certificate_dialog.cc deleted file mode 100644 index ffb2a0f99..000000000 --- a/src/wx/doremi_certificate_dialog.cc +++ /dev/null @@ -1,113 +0,0 @@ -/* - Copyright (C) 2014-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 -#include -#include "lib/compose.hpp" -#include "lib/util.h" -#include "lib/signal_manager.h" -#include "lib/internet.h" -#include "doremi_certificate_dialog.h" -#include "wx_util.h" -#include - -using std::string; -using std::cout; -using boost::function; -using boost::optional; - -DoremiCertificateDialog::DoremiCertificateDialog (wxWindow* parent, function load) - : DownloadCertificateDialog (parent, load) -{ - add (_("Server serial number"), true); - _serial = add (new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (300, -1))); - - _serial->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DoremiCertificateDialog::set_sensitivity, this)); - - add_common_widgets (); -} - -void -DoremiCertificateDialog::download () -{ - string const serial = wx_to_std (_serial->GetValue ()); - if (serial.length() != 6) { - error_dialog (this, _("Doremi serial numbers must have 6 digits")); - return; - } - - downloaded (false); - _message->SetLabel (_("Downloading certificate")); - - /* Hack: without this the SetLabel() above has no visible effect */ - wxMilliSleep (200); - - signal_manager->when_idle (boost::bind (&DoremiCertificateDialog::finish_download, this, serial)); -} - -void -DoremiCertificateDialog::finish_download (string serial) -{ - /* Try dcp2000, imb and ims prefixes (see mantis #375) */ - - optional error = get_from_zip_url ( - String::compose ( - "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/dcp2000-%2.dcicerts.zip", - serial.substr(0, 3), serial - ), - String::compose ("dcp2000-%1.cert.sha256.pem", serial), - _load - ); - - if (error) { - error = get_from_zip_url ( - String::compose ( - "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/imb-%2.dcicerts.zip", - serial.substr(0, 3), serial - ), - String::compose ("imb-%1.cert.sha256.pem", serial), - _load - ); - } - - if (error) { - error = get_from_zip_url ( - String::compose ( - "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/ims-%2.dcicerts.zip", - serial.substr(0, 3), serial - ), - String::compose ("ims-%1.cert.sha256.pem", serial), - _load - ); - } - - if (error) { - _message->SetLabel (wxT ("")); - error_dialog (this, std_to_wx (error.get ())); - } else { - _message->SetLabel (_("Certificate downloaded")); - downloaded (true); - } -} - -void -DoremiCertificateDialog::set_sensitivity () -{ - _download->Enable (!_serial->IsEmpty ()); -} diff --git a/src/wx/doremi_certificate_dialog.h b/src/wx/doremi_certificate_dialog.h deleted file mode 100644 index b249736ec..000000000 --- a/src/wx/doremi_certificate_dialog.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (C) 2014 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 "download_certificate_dialog.h" - -class DoremiCertificateDialog : public DownloadCertificateDialog -{ -public: - DoremiCertificateDialog (wxWindow *, boost::function); - -private: - void download (); - void set_sensitivity (); - - void finish_download (std::string serial); - - wxTextCtrl* _serial; -}; diff --git a/src/wx/doremi_certificate_panel.cc b/src/wx/doremi_certificate_panel.cc new file mode 100644 index 000000000..b80a660c1 --- /dev/null +++ b/src/wx/doremi_certificate_panel.cc @@ -0,0 +1,113 @@ +/* + Copyright (C) 2014-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 "doremi_certificate_panel.h" +#include "download_certificate_dialog.h" +#include "wx_util.h" +#include "lib/compose.hpp" +#include "lib/util.h" +#include "lib/signal_manager.h" +#include "lib/internet.h" +#include +#include +#include + +using std::string; +using std::cout; +using boost::function; +using boost::optional; + +DoremiCertificatePanel::DoremiCertificatePanel (wxWindow* parent, DownloadCertificateDialog* dialog) + : DownloadCertificatePanel (parent, dialog) +{ + add_label_to_sizer (_table, this, _("Server serial number"), true); + _serial = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (300, -1)); + _table->Add (_serial, 1, wxEXPAND); + + _serial->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DownloadCertificateDialog::setup_sensitivity, _dialog)); + + layout (); +} + +void +DoremiCertificatePanel::download (wxStaticText* message) +{ + string const serial = wx_to_std (_serial->GetValue ()); + if (serial.length() != 6) { + error_dialog (this, _("Doremi serial numbers must have 6 digits")); + return; + } + + message->SetLabel (_("Downloading certificate")); + + /* Hack: without this the SetLabel() above has no visible effect */ + wxMilliSleep (200); + + signal_manager->when_idle (boost::bind (&DoremiCertificatePanel::finish_download, this, serial, message)); +} + +void +DoremiCertificatePanel::finish_download (string serial, wxStaticText* message) +{ + /* Try dcp2000, imb and ims prefixes (see mantis #375) */ + + optional error = get_from_zip_url ( + String::compose ( + "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/dcp2000-%2.dcicerts.zip", + serial.substr(0, 3), serial + ), + String::compose ("dcp2000-%1.cert.sha256.pem", serial), + boost::bind (&DownloadCertificatePanel::load, this, _1) + ); + + if (error) { + error = get_from_zip_url ( + String::compose ( + "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/imb-%2.dcicerts.zip", + serial.substr(0, 3), serial + ), + String::compose ("imb-%1.cert.sha256.pem", serial), + boost::bind (&DownloadCertificatePanel::load, this, _1) + ); + } + + if (error) { + error = get_from_zip_url ( + String::compose ( + "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/ims-%2.dcicerts.zip", + serial.substr(0, 3), serial + ), + String::compose ("ims-%1.cert.sha256.pem", serial), + boost::bind (&DownloadCertificatePanel::load, this, _1) + ); + } + + if (error) { + message->SetLabel (wxT ("")); + error_dialog (this, std_to_wx (error.get ())); + } else { + message->SetLabel (_("Certificate downloaded")); + } +} + +bool +DoremiCertificatePanel::ready_to_download () const +{ + return !_serial->IsEmpty (); +} diff --git a/src/wx/doremi_certificate_panel.h b/src/wx/doremi_certificate_panel.h new file mode 100644 index 000000000..5fc455098 --- /dev/null +++ b/src/wx/doremi_certificate_panel.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2014-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 "download_certificate_panel.h" + +class DoremiCertificatePanel : public DownloadCertificatePanel +{ +public: + DoremiCertificatePanel (wxWindow* parent, DownloadCertificateDialog* dialog); + + bool ready_to_download () const; + void download (wxStaticText* message); + +private: + void finish_download (std::string serial, wxStaticText* message); + + wxTextCtrl* _serial; +}; diff --git a/src/wx/download_certificate_dialog.cc b/src/wx/download_certificate_dialog.cc index 275c943db..5a621d26f 100644 --- a/src/wx/download_certificate_dialog.cc +++ b/src/wx/download_certificate_dialog.cc @@ -17,47 +17,74 @@ */ -#include "wx_util.h" +#include "doremi_certificate_panel.h" +#include "dolby_certificate_panel.h" #include "download_certificate_dialog.h" -#include - -using boost::function; +#include "wx_util.h" -DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent, function load) - : TableDialog (parent, _("Download certificate"), 2, 1, true) - , _load (load) - , _message (0) - , _download (0) +DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent) + : wxDialog (parent, wxID_ANY, _("Download certificate")) { + wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL); -} + _notebook = new wxNotebook (this, wxID_ANY); + sizer->Add (_notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER); -void -DownloadCertificateDialog::add_common_widgets () -{ - add_spacer (); - _download = add (new wxButton (this, wxID_ANY, _("Download"))); + _pages.push_back (new DoremiCertificatePanel (_notebook, this)); + _setup.push_back (false); + _notebook->AddPage (_pages.back(), _("Doremi"), true); + _pages.push_back (new DolbyCertificatePanel (_notebook, this)); + _setup.push_back (false); + _notebook->AddPage (_pages.back(), _("Dolby"), false); - add_spacer (); - _message = add (new wxStaticText (this, wxID_ANY, wxT (""))); + _download = new wxButton (this, wxID_ANY, _("Download")); + sizer->Add (_download, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP); + _message = new wxStaticText (this, wxID_ANY, wxT ("")); + sizer->Add (_message, 0, wxALL, DCPOMATIC_SIZER_GAP); wxFont font = _message->GetFont(); font.SetStyle (wxFONTSTYLE_ITALIC); font.SetPointSize (font.GetPointSize() - 1); _message->SetFont (font); + wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL); + if (buttons) { + sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); + } + + SetSizerAndFit (sizer); + + _notebook->Bind (wxEVT_NOTEBOOK_PAGE_CHANGED, boost::bind (&DownloadCertificateDialog::page_changed, this)); _download->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DownloadCertificateDialog::download, this)); _download->Enable (false); - layout (); + page_changed (); +} + +void +DownloadCertificateDialog::download () +{ + _pages[_notebook->GetSelection()]->download (_message); +} - wxButton* ok = dynamic_cast (FindWindowById (wxID_OK, this)); - ok->Enable (false); +dcp::Certificate +DownloadCertificateDialog::certificate () const +{ + return _pages[_notebook->GetSelection()]->certificate (); +} + +void +DownloadCertificateDialog::setup_sensitivity () +{ + _download->Enable (_pages[_notebook->GetSelection()]->ready_to_download ()); } void -DownloadCertificateDialog::downloaded (bool done) +DownloadCertificateDialog::page_changed () { - wxButton* ok = dynamic_cast (FindWindowById (wxID_OK, this)); - ok->Enable (done); + int const n = _notebook->GetSelection(); + if (!_setup[n]) { + _pages[n]->setup (); + _setup[n] = true; + } } diff --git a/src/wx/download_certificate_dialog.h b/src/wx/download_certificate_dialog.h index 85d8f15ab..7d319dcfe 100644 --- a/src/wx/download_certificate_dialog.h +++ b/src/wx/download_certificate_dialog.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-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 @@ -17,29 +17,27 @@ */ -#ifndef DCPOMATIC_DOWNLOAD_CERTIFICATE_DIALOG_H -#define DCPOMATIC_DOWNLOAD_CERTIFICATE_DIALOG_H - #include -#include -#include -#include "table_dialog.h" +#include + +class DownloadCertificatePanel; -class DownloadCertificateDialog : public TableDialog +class DownloadCertificateDialog : public wxDialog { public: - DownloadCertificateDialog (wxWindow *, boost::function); + DownloadCertificateDialog (wxWindow* parent); -protected: - void add_common_widgets (); - void downloaded (bool done); + dcp::Certificate certificate () const; - boost::function _load; - wxStaticText* _message; - wxButton* _download; + void setup_sensitivity (); private: - virtual void download () = 0; -}; + void download (); + void page_changed (); -#endif + wxNotebook* _notebook; + std::vector _pages; + std::vector _setup; + wxButton* _download; + wxStaticText* _message; +}; diff --git a/src/wx/download_certificate_panel.cc b/src/wx/download_certificate_panel.cc new file mode 100644 index 000000000..7b670261b --- /dev/null +++ b/src/wx/download_certificate_panel.cc @@ -0,0 +1,63 @@ +/* + Copyright (C) 2014-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 "wx_util.h" +#include "download_certificate_panel.h" +#include +#include +#include + +using boost::function; + +DownloadCertificatePanel::DownloadCertificatePanel (wxWindow* parent, DownloadCertificateDialog* dialog) + : wxPanel (parent, wxID_ANY) + , _dialog (dialog) +{ + _overall_sizer = new wxBoxSizer (wxVERTICAL); + SetSizer (_overall_sizer); + + _table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); + _table->AddGrowableCol (1, 1); + + _overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER); +} + +void +DownloadCertificatePanel::layout () +{ + _overall_sizer->Layout (); + _overall_sizer->SetSizeHints (this); +} + +void +DownloadCertificatePanel::load (boost::filesystem::path file) +{ + try { + _certificate = dcp::Certificate (dcp::file_to_string (file)); + } catch (dcp::MiscError& e) { + error_dialog (this, wxString::Format (_("Could not read certificate file (%s)"), std_to_wx(e.what()).data())); + } +} + +dcp::Certificate +DownloadCertificatePanel::certificate () const +{ + DCPOMATIC_ASSERT (_certificate); + return _certificate.get (); +} diff --git a/src/wx/download_certificate_panel.h b/src/wx/download_certificate_panel.h new file mode 100644 index 000000000..850236128 --- /dev/null +++ b/src/wx/download_certificate_panel.h @@ -0,0 +1,53 @@ +/* + Copyright (C) 2014 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. + +*/ + +#ifndef DCPOMATIC_DOWNLOAD_CERTIFICATE_PANEL_H +#define DCPOMATIC_DOWNLOAD_CERTIFICATE_PANEL_H + +#include +#include +#include + +class DownloadCertificateDialog; + +class DownloadCertificatePanel : public wxPanel +{ +public: + DownloadCertificatePanel (wxWindow* parent, DownloadCertificateDialog* dialog); + + /* Do any setup that may take a noticeable amount of time */ + virtual void setup () {} + virtual bool ready_to_download () const = 0; + virtual void download (wxStaticText* message) = 0; + + void load (boost::filesystem::path); + dcp::Certificate certificate () const; + +protected: + void layout (); + + DownloadCertificateDialog* _dialog; + wxFlexGridSizer* _table; + +private: + wxSizer* _overall_sizer; + boost::optional _certificate; +}; + +#endif diff --git a/src/wx/screen_dialog.cc b/src/wx/screen_dialog.cc index 98a525318..02bbe96ea 100644 --- a/src/wx/screen_dialog.cc +++ b/src/wx/screen_dialog.cc @@ -19,8 +19,7 @@ #include "screen_dialog.h" #include "wx_util.h" -#include "doremi_certificate_dialog.h" -#include "dolby_certificate_dialog.h" +#include "download_certificate_dialog.h" #include "lib/compose.hpp" #include "lib/util.h" #include @@ -39,9 +38,6 @@ ScreenDialog::ScreenDialog (wxWindow* parent, string title, string name, optiona add (_("Name"), true); _name = add (new wxTextCtrl (this, wxID_ANY, std_to_wx (name), wxDefaultPosition, wxSize (320, -1))); - add (_("Server manufacturer"), true); - _manufacturer = add (new wxChoice (this, wxID_ANY)); - add (_("Certificate"), true); wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL); _load_certificate = new wxButton (this, wxID_ANY, _("Load from file...")); @@ -60,15 +56,8 @@ ScreenDialog::ScreenDialog (wxWindow* parent, string title, string name, optiona _certificate_text->SetFont (font); add (_certificate_text); - _manufacturer->Append (_("Unknown")); - _manufacturer->Append (_("Doremi")); - _manufacturer->Append (_("Dolby")); - _manufacturer->Append (_("Other")); - _manufacturer->SetSelection (0); - _load_certificate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreenDialog::select_certificate, this)); _download_certificate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreenDialog::download_certificate, this)); - _manufacturer->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&ScreenDialog::setup_sensitivity, this)); setup_sensitivity (); layout (); @@ -91,7 +80,7 @@ ScreenDialog::load_certificate (boost::filesystem::path file) { try { _certificate = dcp::Certificate (dcp::file_to_string (file)); - _certificate_text->SetValue (_certificate->certificate ()); + _certificate_text->SetValue (std_to_wx (_certificate->certificate ())); } catch (dcp::MiscError& e) { error_dialog (this, wxString::Format (_("Could not read certificate file (%s)"), std_to_wx(e.what()).data())); } @@ -112,16 +101,12 @@ ScreenDialog::select_certificate () void ScreenDialog::download_certificate () { - if (_manufacturer->GetStringSelection() == _("Doremi")) { - DownloadCertificateDialog* d = new DoremiCertificateDialog (this, boost::bind (&ScreenDialog::load_certificate, this, _1)); - d->ShowModal (); - d->Destroy (); - } else if (_manufacturer->GetStringSelection() == _("Dolby")) { - DownloadCertificateDialog* d = new DolbyCertificateDialog (this, boost::bind (&ScreenDialog::load_certificate, this, _1)); - d->ShowModal (); - d->Destroy (); + DownloadCertificateDialog* d = new DownloadCertificateDialog (this); + if (d->ShowModal() == wxID_OK) { + _certificate = d->certificate (); + _certificate_text->SetValue (std_to_wx (_certificate->certificate ())); } - + d->Destroy (); setup_sensitivity (); } @@ -132,9 +117,4 @@ ScreenDialog::setup_sensitivity () if (ok) { ok->Enable (static_cast(_certificate)); } - - _download_certificate->Enable ( - _manufacturer->GetStringSelection() == _("Doremi") || - _manufacturer->GetStringSelection() == _("Dolby") - ); } diff --git a/src/wx/screen_dialog.h b/src/wx/screen_dialog.h index 66f3f422f..36686273a 100644 --- a/src/wx/screen_dialog.h +++ b/src/wx/screen_dialog.h @@ -40,7 +40,6 @@ private: void setup_sensitivity (); wxTextCtrl* _name; - wxChoice* _manufacturer; wxButton* _load_certificate; wxButton* _download_certificate; wxTextCtrl* _certificate_text; diff --git a/src/wx/wscript b/src/wx/wscript index 821043b40..7b106c6b0 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -43,9 +43,10 @@ sources = """ image_sequence_dialog.cc isdcf_metadata_dialog.cc dir_picker_ctrl.cc - dolby_certificate_dialog.cc - doremi_certificate_dialog.cc + dolby_certificate_panel.cc + doremi_certificate_panel.cc download_certificate_dialog.cc + download_certificate_panel.cc file_picker_ctrl.cc film_editor.cc film_viewer.cc