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_dialog.h"
22 #include "lib/compose.hpp"
23 #include "lib/internet.h"
24 #include "lib/signal_manager.h"
26 #include <curl/curl.h>
27 #include <boost/algorithm/string.hpp>
28 #include <boost/foreach.hpp>
35 using boost::optional;
36 using boost::algorithm::split;
37 using boost::algorithm::is_any_of;
39 DolbyCertificateDialog::DolbyCertificateDialog (wxWindow* parent, boost::function<void (boost::filesystem::path)> load)
40 : DownloadCertificateDialog (parent, load)
42 add (_("Country"), true);
43 _country = add (new wxChoice (this, wxID_ANY));
44 _country->Append (N_("Hashemite Kingdom of Jordan"));
46 add (_("Cinema"), true);
47 _cinema = add (new wxChoice (this, wxID_ANY));
48 _cinema->Append (N_("Motion Picture Solutions London Mobile & QC"));
50 add (_("Serial number"), true);
51 _serial = add (new wxChoice (this, wxID_ANY));
53 add_common_widgets ();
55 _country->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::country_selected, this));
56 _cinema->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::cinema_selected, this));
57 _serial->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::serial_selected, this));
58 signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::setup_countries, this));
65 DolbyCertificateDialog::get_dir (string dir) const
67 string url = String::compose ("ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1", dir);
68 return ftp_ls (url, false);
72 DolbyCertificateDialog::setup_countries ()
74 if (_country->GetCount() > 0) {
79 _country->Append (_("Fetching..."));
80 _country->SetSelection (0);
82 /* See DoremiCertificateDialog for discussion about this daft delay */
85 signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_setup_countries, this));
89 DolbyCertificateDialog::finish_setup_countries ()
92 list<string> const c = get_dir ("");
94 BOOST_FOREACH (string i, c) {
95 _country->Append (std_to_wx (i));
97 } catch (NetworkError& e) {
98 error_dialog (this, wxString::Format (_("Could not get country list (%s)"), e.what()));
104 DolbyCertificateDialog::country_selected ()
107 _cinema->Append (_("Fetching..."));
108 _cinema->SetSelection (0);
113 signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_country_selected, this));
117 DolbyCertificateDialog::finish_country_selected ()
120 list<string> const c = get_dir (wx_to_std (_country->GetStringSelection()));
122 BOOST_FOREACH (string i, c) {
123 _cinema->Append (std_to_wx (i));
125 } catch (NetworkError& e) {
126 error_dialog (this, wxString::Format (_("Could not get cinema list (%s)"), e.what ()));
132 DolbyCertificateDialog::cinema_selected ()
135 _serial->Append (_("Fetching..."));
136 _serial->SetSelection (0);
141 signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_cinema_selected, this));
145 DolbyCertificateDialog::finish_cinema_selected ()
148 list<string> const s = get_dir (String::compose ("%1/%2", wx_to_std (_country->GetStringSelection()), wx_to_std (_cinema->GetStringSelection())));
150 BOOST_FOREACH (string i, s) {
152 split (a, i, is_any_of ("-_"));
154 _serial->Append (std_to_wx (a[3]), new wxStringClientData (std_to_wx (i)));
157 } catch (NetworkError& e) {
158 error_dialog (this, wxString::Format (_("Could not get screen list (%s)"), e.what()));
164 DolbyCertificateDialog::serial_selected ()
166 _download->Enable (true);
170 DolbyCertificateDialog::download ()
173 _message->SetLabel (_("Downloading certificate"));
179 signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_download, this));
183 DolbyCertificateDialog::finish_download ()
185 string const zip = string_client_data (_serial->GetClientObject (_serial->GetSelection ()));
187 string const file = String::compose (
188 "ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1/%2/%3",
189 wx_to_std (_country->GetStringSelection()),
190 wx_to_std (_cinema->GetStringSelection()),
194 /* Work out the certificate file name inside the zip */
196 split (b, zip, is_any_of ("_"));
198 _message->SetLabel (_("Unexpected certificate filename form"));
201 string const cert = b[0] + "_" + b[1] + ".pem.crt";
203 optional<string> error = get_from_zip_url (file, cert, _load);
205 _message->SetLabel (std_to_wx (error.get ()));
207 _message->SetLabel (_("Certificate downloaded"));