2 Copyright (C) 2014 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 <boost/algorithm/string.hpp>
21 #include <curl/curl.h>
22 #include "lib/compose.hpp"
23 #include "lib/internet.h"
24 #include "dolby_certificate_dialog.h"
30 using std::stringstream;
32 using boost::optional;
33 using boost::algorithm::split;
34 using boost::algorithm::is_any_of;
36 DolbyCertificateDialog::DolbyCertificateDialog (wxWindow* parent, boost::function<void (boost::filesystem::path)> load)
37 : DownloadCertificateDialog (parent, load)
39 add (_("Country"), true);
40 _country = add (new wxChoice (this, wxID_ANY));
41 _country->Append (N_("Hashemite Kingdom of Jordan"));
43 add (_("Cinema"), true);
44 _cinema = add (new wxChoice (this, wxID_ANY));
45 _cinema->Append (N_("Motion Picture Solutions London Mobile & QC"));
47 add (_("Serial number"), true);
48 _serial = add (new wxChoice (this, wxID_ANY));
50 add_common_widgets ();
52 _country->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::country_selected, this));
53 _cinema->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::cinema_selected, this));
54 _serial->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::serial_selected, this));
55 Bind (wxEVT_IDLE, boost::bind (&DolbyCertificateDialog::setup_countries, this));
62 DolbyCertificateDialog::get_dir (string dir) const
64 string url = String::compose ("ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1", dir);
69 DolbyCertificateDialog::setup_countries ()
71 if (_country->GetCount() > 0) {
76 _country->Append (_("Fetching..."));
77 _country->SetSelection (0);
80 list<string> const countries = get_dir ("");
82 for (list<string>::const_iterator i = countries.begin(); i != countries.end(); ++i) {
83 _country->Append (std_to_wx (*i));
88 DolbyCertificateDialog::country_selected ()
91 _cinema->Append (_("Fetching..."));
92 _cinema->SetSelection (0);
95 list<string> const cinemas = get_dir (wx_to_std (_country->GetStringSelection()));
97 for (list<string>::const_iterator i = cinemas.begin(); i != cinemas.end(); ++i) {
98 _cinema->Append (std_to_wx (*i));
103 DolbyCertificateDialog::cinema_selected ()
106 _serial->Append (_("Fetching..."));
107 _serial->SetSelection (0);
110 string const dir = String::compose ("%1/%2", wx_to_std (_country->GetStringSelection()), wx_to_std (_cinema->GetStringSelection()));
111 list<string> const zips = get_dir (dir);
114 for (list<string>::const_iterator i = zips.begin(); i != zips.end(); ++i) {
116 split (a, *i, is_any_of ("-_"));
118 _serial->Append (std_to_wx (a[3]), new wxStringClientData (std_to_wx (*i)));
124 DolbyCertificateDialog::serial_selected ()
126 _download->Enable (true);
130 DolbyCertificateDialog::download ()
132 _message->SetLabel (_("Downloading certificate"));
135 string const zip = string_client_data (_serial->GetClientObject (_serial->GetSelection ()));
137 string const file = String::compose (
138 "ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1/%2/%3",
139 wx_to_std (_country->GetStringSelection()),
140 wx_to_std (_cinema->GetStringSelection()),
144 /* Work out the certificate file name inside the zip */
146 split (b, zip, is_any_of ("_"));
148 _message->SetLabel (_("Unexpected certificate filename form"));
151 string const cert = b[0] + "_" + b[1] + ".pem.crt";
153 optional<string> error = get_from_zip_url (file, cert, _load);
155 _message->SetLabel (std_to_wx (error.get ()));
157 _message->SetLabel (_("Certificate downloaded"));