Trim spaces from entries to certificate download pages.
[dcpomatic.git] / src / wx / gdc_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 "download_certificate_dialog.h"
23 #include "gdc_certificate_panel.h"
24 #include "wx_util.h"
25 #include "lib/compose.hpp"
26 #include "lib/config.h"
27 #include "lib/internet.h"
28 #include <boost/algorithm/string.hpp>
29
30
31 using std::string;
32 using namespace boost::algorithm;
33 using boost::bind;
34 using boost::optional;
35 #if BOOST_VERSION >= 106100
36 using namespace boost::placeholders;
37 #endif
38
39
40 GDCCertificatePanel::GDCCertificatePanel (DownloadCertificateDialog* dialog)
41         : CredentialsDownloadCertificatePanel (
42                         dialog,
43                         bind(&Config::gdc_username, Config::instance()),
44                         bind(&Config::set_gdc_username, Config::instance(), _1),
45                         bind(&Config::unset_gdc_username, Config::instance()),
46                         bind(&Config::gdc_password, Config::instance()),
47                         bind(&Config::set_gdc_password, Config::instance(), _1),
48                         bind(&Config::unset_gdc_password, Config::instance())
49                         )
50 {
51
52 }
53
54 void
55 GDCCertificatePanel::do_download ()
56 {
57         string serial = wx_to_std (_serial->GetValue());
58         trim(serial);
59         if (!serial.empty() && serial[0] == 'A') {
60                 /* We're adding the A ourselves */
61                 serial = serial.substr(1);
62         }
63         string url = String::compose(
64                 "ftp://%1:%2@ftp.gdc-tech.com/SHA256/A%3.crt.pem",
65                 Config::instance()->gdc_username().get(),
66                 Config::instance()->gdc_password().get(),
67                 serial
68                 );
69         trim(url);
70
71         auto error = get_from_url (url, true, false, boost::bind(&DownloadCertificatePanel::load_certificate, this, _1, _2));
72
73         if (error) {
74                 _dialog->message()->SetLabel(wxT(""));
75                 error_dialog (this, std_to_wx(*error));
76         } else {
77                 _dialog->message()->SetLabel (_("Certificate downloaded"));
78                 _dialog->setup_sensitivity ();
79         }
80 }
81
82 wxString
83 GDCCertificatePanel::name () const
84 {
85         return _("GDC");
86 }