2 Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "dolby_certificate_panel.h"
21 #include "download_certificate_dialog.h"
23 #include "lib/compose.hpp"
24 #include "lib/internet.h"
25 #include "lib/signal_manager.h"
27 #include <curl/curl.h>
28 #include <boost/algorithm/string.hpp>
29 #include <boost/foreach.hpp>
36 using boost::optional;
37 using boost::algorithm::split;
38 using boost::algorithm::is_any_of;
40 DolbyCertificatePanel::DolbyCertificatePanel (wxWindow* parent, DownloadCertificateDialog* dialog)
41 : DownloadCertificatePanel (parent, dialog)
43 add_label_to_sizer (_table, this, _("Country"), true);
44 _country = new wxChoice (this, wxID_ANY);
45 _table->Add (_country, 1, wxEXPAND);
46 _country->Append (N_("Hashemite Kingdom of Jordan"));
48 add_label_to_sizer (_table, this, _("Cinema"), true);
49 _cinema = new wxChoice (this, wxID_ANY);
50 _table->Add (_cinema, 1, wxEXPAND);
51 _cinema->Append (N_("Motion Picture Solutions London Mobile & QC"));
53 add_label_to_sizer (_table, this, _("Serial number"), true);
54 _serial = new wxChoice (this, wxID_ANY);
55 _table->Add (_serial, 1, wxEXPAND);
59 _country->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificatePanel::country_selected, this));
60 _cinema->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificatePanel::cinema_selected, this));
61 _serial->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DownloadCertificateDialog::setup_sensitivity, _dialog));
68 DolbyCertificatePanel::get_dir (string dir) const
70 string url = String::compose ("ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1", dir);
71 return ftp_ls (url, false);
75 DolbyCertificatePanel::setup_countries ()
77 if (_country->GetCount() > 0) {
82 _country->Append (_("Fetching..."));
83 _country->SetSelection (0);
85 /* See DoremiCertificatePanel for discussion about this daft delay */
88 signal_manager->when_idle (boost::bind (&DolbyCertificatePanel::finish_setup_countries, this));
92 DolbyCertificatePanel::finish_setup_countries ()
95 list<string> const c = get_dir ("");
97 BOOST_FOREACH (string i, c) {
98 _country->Append (std_to_wx (i));
100 } catch (NetworkError& e) {
101 error_dialog (this, wxString::Format (_("Could not get country list (%s)"), e.what()));
107 DolbyCertificatePanel::country_selected ()
110 _cinema->Append (_("Fetching..."));
111 _cinema->SetSelection (0);
116 signal_manager->when_idle (boost::bind (&DolbyCertificatePanel::finish_country_selected, this));
120 DolbyCertificatePanel::finish_country_selected ()
123 list<string> const c = get_dir (wx_to_std (_country->GetStringSelection()));
125 BOOST_FOREACH (string i, c) {
126 _cinema->Append (std_to_wx (i));
128 } catch (NetworkError& e) {
129 error_dialog (this, wxString::Format (_("Could not get cinema list (%s)"), e.what ()));
135 DolbyCertificatePanel::cinema_selected ()
138 _serial->Append (_("Fetching..."));
139 _serial->SetSelection (0);
144 signal_manager->when_idle (boost::bind (&DolbyCertificatePanel::finish_cinema_selected, this));
148 DolbyCertificatePanel::finish_cinema_selected ()
151 list<string> const s = get_dir (String::compose ("%1/%2", wx_to_std (_country->GetStringSelection()), wx_to_std (_cinema->GetStringSelection())));
153 BOOST_FOREACH (string i, s) {
155 split (a, i, is_any_of ("-_"));
157 _serial->Append (std_to_wx (a[3]), new wxStringClientData (std_to_wx (i)));
160 } catch (NetworkError& e) {
161 error_dialog (this, wxString::Format (_("Could not get screen list (%s)"), e.what()));
167 DolbyCertificatePanel::download (wxStaticText* message)
169 message->SetLabel (_("Downloading certificate"));
175 signal_manager->when_idle (boost::bind (&DolbyCertificatePanel::finish_download, this, message));
179 DolbyCertificatePanel::finish_download (wxStaticText* message)
181 string const zip = string_client_data (_serial->GetClientObject (_serial->GetSelection ()));
183 string const file = String::compose (
184 "ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1/%2/%3",
185 wx_to_std (_country->GetStringSelection()),
186 wx_to_std (_cinema->GetStringSelection()),
190 /* Work out the certificate file name inside the zip */
192 split (b, zip, is_any_of ("_"));
194 message->SetLabel (_("Unexpected certificate filename form"));
197 string const cert = b[0] + "_" + b[1] + ".pem.crt";
199 optional<string> error = get_from_zip_url (file, cert, boost::bind (&DownloadCertificatePanel::load, this, _1));
201 message->SetLabel (std_to_wx (error.get ()));
203 message->SetLabel (_("Certificate downloaded"));
204 _dialog->setup_sensitivity ();
209 DolbyCertificatePanel::ready_to_download () const
216 DolbyCertificatePanel::setup ()
218 signal_manager->when_idle (boost::bind (&DolbyCertificatePanel::setup_countries, this));