C++11 tidying.
[dcpomatic.git] / src / wx / qube_certificate_panel.cc
1 /*
2     Copyright (C) 2019-2021 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 "qube_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/predicate.hpp>
29
30
31 using std::string;
32 using std::list;
33 using boost::optional;
34 #if BOOST_VERSION >= 106100
35 using namespace boost::placeholders;
36 #endif
37
38
39 static string const base = "ftp://certificates.qubecinema.com/";
40
41
42 QubeCertificatePanel::QubeCertificatePanel (DownloadCertificateDialog* dialog, string type)
43         : DownloadCertificatePanel (dialog)
44         , _type (type)
45 {
46
47 }
48
49
50 void
51 QubeCertificatePanel::do_download ()
52 {
53         auto files = ls_url(String::compose("%1SMPTE-%2/", base, _type));
54         if (files.empty()) {
55                 error_dialog (this, _("Could not read certificates from Qube server."));
56                 return;
57         }
58
59         auto const serial = wx_to_std(_serial->GetValue());
60         optional<string> name;
61         for (auto i: files) {
62                 if (boost::algorithm::starts_with(i, String::compose("%1-%2-", _type, serial))) {
63                         name = i;
64                         break;
65                 }
66         }
67
68         if (!name) {
69                 _dialog->message()->SetLabel(wxT(""));
70                 error_dialog (this, wxString::Format(_("Could not find serial number %s"), std_to_wx(serial).data()));
71                 return;
72         }
73
74         auto error = get_from_url (String::compose("%1SMPTE-%2/%3", base, _type, *name), true, false, boost::bind(&DownloadCertificatePanel::load_certificate, this, _1));
75
76         if (error) {
77                 _dialog->message()->SetLabel(wxT(""));
78                 error_dialog (this, std_to_wx(*error));
79         } else {
80                 _dialog->message()->SetLabel (_("Certificate downloaded"));
81                 _dialog->setup_sensitivity ();
82         }
83 }
84
85
86 wxString
87 QubeCertificatePanel::name () const
88 {
89         return _("Qube") + " " + std_to_wx(_type);
90 }