8509c97d150d502bff9c43be50dc18894be9ec2c
[dcpomatic.git] / src / wx / doremi_certificate_dialog.cc
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include <curl/curl.h>
21 #include <zip.h>
22 #include "lib/compose.hpp"
23 #include "lib/util.h"
24 #include "lib/internet.h"
25 #include "doremi_certificate_dialog.h"
26 #include "wx_util.h"
27
28 using std::string;
29 using boost::function;
30 using boost::optional;
31
32 DoremiCertificateDialog::DoremiCertificateDialog (wxWindow* parent, function<void (boost::filesystem::path)> load)
33         : DownloadCertificateDialog (parent, load)
34 {
35         add (_("Server serial number"), true);
36         _serial = add (new wxTextCtrl (this, wxID_ANY));
37
38         add_common_widgets ();
39 }
40
41 void
42 DoremiCertificateDialog::download ()
43 {
44         string const serial = wx_to_std (_serial->GetValue ());
45         if (serial.length() != 6) {
46                 error_dialog (this, _("Doremi serial numbers must have 6 digits"));
47                 return;
48         }
49
50         _message->SetLabel (_("Downloading certificate"));
51
52         optional<string> error = get_from_zip_url (
53                 String::compose (
54                         "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/dcp2000-%2.dcicerts.zip",
55                         serial.substr(0, 3), serial
56                         ),
57                 String::compose ("dcp2000-%1.cert.sha256.pem", serial),
58                 _load
59                 );
60
61         if (error) {
62                 error_dialog (this, std_to_wx (error.get ()));
63         } else {
64                 _message->SetLabel (wxT (""));
65         }
66 }