Supporters update.
[dcpomatic.git] / src / wx / barco_alchemy_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
22 #include "barco_alchemy_certificate_panel.h"
23 #include "download_certificate_dialog.h"
24 #include "wx_util.h"
25 #include "lib/internet.h"
26 #include "lib/compose.hpp"
27 #include "lib/config.h"
28 #include <boost/algorithm/string.hpp>
29
30
31 using std::string;
32 using namespace boost::algorithm;
33 using boost::optional;
34 #if BOOST_VERSION >= 106100
35 using namespace boost::placeholders;
36 #endif
37
38
39 BarcoAlchemyCertificatePanel::BarcoAlchemyCertificatePanel (DownloadCertificateDialog* dialog)
40         : CredentialsDownloadCertificatePanel (
41                         dialog,
42                         boost::bind(&Config::barco_username, Config::instance()),
43                         boost::bind(&Config::set_barco_username, Config::instance(), _1),
44                         boost::bind(&Config::unset_barco_username, Config::instance()),
45                         boost::bind(&Config::barco_password, Config::instance()),
46                         boost::bind(&Config::set_barco_password, Config::instance(), _1),
47                         boost::bind(&Config::unset_barco_password, Config::instance())
48                         )
49 {
50
51 }
52
53 bool
54 BarcoAlchemyCertificatePanel::ready_to_download () const
55 {
56         return CredentialsDownloadCertificatePanel::ready_to_download() && _serial->GetValue().Length() == 10;
57 }
58
59 void
60 BarcoAlchemyCertificatePanel::do_download ()
61 {
62         string serial = wx_to_std (_serial->GetValue());
63         trim(serial);
64         string url = String::compose (
65                 "ftp://%1:%2@certificates.barco.com/%3xxx/%4/Barco-ICMP.%5_cert.pem",
66                 Config::instance()->barco_username().get(),
67                 Config::instance()->barco_password().get(),
68                 serial.substr(0, 7),
69                 serial,
70                 serial
71                 );
72         trim(url);
73
74         auto error = get_from_url (url, true, false, boost::bind (&DownloadCertificatePanel::load_certificate, this, _1, _2));
75         if (error) {
76                 _dialog->message()->SetLabel(wxT(""));
77                 error_dialog (this, std_to_wx(*error));
78         } else {
79                 _dialog->message()->SetLabel (_("Certificate downloaded"));
80                 _dialog->setup_sensitivity ();
81         }
82 }
83
84 wxString
85 BarcoAlchemyCertificatePanel::name () const
86 {
87         return _("Barco Alchemy");
88 }