Rename _size -> _video_size
[dcpomatic.git] / src / wx / christie_certificate_panel.cc
1 /*
2     Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "christie_certificate_panel.h"
22 #include "download_certificate_dialog.h"
23 #include "wx_util.h"
24 #include "lib/internet.h"
25 #include "lib/compose.hpp"
26 #include "lib/config.h"
27
28 using std::string;
29 using boost::optional;
30 using boost::bind;
31 #if BOOST_VERSION >= 106100
32 using namespace boost::placeholders;
33 #endif
34
35 ChristieCertificatePanel::ChristieCertificatePanel (DownloadCertificateDialog* dialog)
36         : CredentialsDownloadCertificatePanel (
37                         dialog,
38                         bind(&Config::christie_username, Config::instance()),
39                         bind(&Config::set_christie_username, Config::instance(), _1),
40                         bind(&Config::unset_christie_username, Config::instance()),
41                         bind(&Config::christie_password, Config::instance()),
42                         bind(&Config::set_christie_password, Config::instance(), _1),
43                         bind(&Config::unset_christie_password, Config::instance())
44                         )
45
46 {
47
48 }
49
50 void
51 ChristieCertificatePanel::do_download ()
52 {
53         string const prefix = String::compose(
54                 "ftp://%1:%2@certificates.christiedigital.com/Certificates/",
55                 Config::instance()->christie_username().get(),
56                 Config::instance()->christie_password().get()
57                 );
58
59         string serial = wx_to_std (_serial->GetValue());
60         serial.insert (0, 12 - serial.length(), '0');
61
62         string const url = String::compose ("%1F-IMB/F-IMB_%2_sha256.pem", prefix, serial);
63
64         optional<string> all_errors;
65         bool ok = true;
66
67         optional<string> error = get_from_url (url, true, false, boost::bind(&DownloadCertificatePanel::load_certificate_from_chain, this, _1));
68         if (error) {
69                 all_errors = *error;
70
71                 string const url = String::compose ("%1IMB-S2/IMB-S2_%2_sha256.pem", prefix, serial);
72
73                 error = get_from_url (url, true, false, boost::bind(&DownloadCertificatePanel::load_certificate_from_chain, this, _1));
74                 if (error) {
75                         *all_errors += "\n" + *error;
76                         ok = false;
77                 }
78         }
79
80         if (ok) {
81                 _dialog->message()->SetLabel (_("Certificate downloaded"));
82                 _dialog->setup_sensitivity ();
83         } else {
84                 _dialog->message()->SetLabel(wxT(""));
85                 error_dialog (this, std_to_wx(*all_errors));
86         }
87 }
88
89 wxString
90 ChristieCertificatePanel::name () const
91 {
92         return _("Christie");
93 }