Supporters update.
[dcpomatic.git] / src / wx / download_certificate_panel.cc
1 /*
2     Copyright (C) 2014-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 "download_certificate_dialog.h"
23 #include "download_certificate_panel.h"
24 #include "wx_util.h"
25 #include "lib/compose.hpp"
26 #include "lib/signal_manager.h"
27 #include <dcp/certificate_chain.h>
28 #include <dcp/exceptions.h>
29 #include <dcp/util.h>
30 #include <boost/bind/bind.hpp>
31
32
33 using std::string;
34 using boost::optional;
35
36
37 DownloadCertificatePanel::DownloadCertificatePanel (DownloadCertificateDialog* dialog)
38         : wxPanel (dialog->notebook(), wxID_ANY)
39         , _dialog (dialog)
40 {
41         _overall_sizer = new wxBoxSizer (wxVERTICAL);
42         SetSizer (_overall_sizer);
43
44         _table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
45         _table->AddGrowableCol (1, 1);
46
47         _overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
48
49         add_label_to_sizer (_table, this, _("Serial number"), true, 0, wxALIGN_CENTER_VERTICAL);
50         _serial = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (300, -1));
51         _table->Add (_serial, 1, wxEXPAND);
52
53         _serial->Bind (wxEVT_TEXT, boost::bind (&DownloadCertificateDialog::setup_sensitivity, _dialog));
54
55         _overall_sizer->Layout ();
56         _overall_sizer->SetSizeHints (this);
57 }
58
59
60 optional<string>
61 DownloadCertificatePanel::load_certificate (boost::filesystem::path file, string url)
62 {
63         try {
64                 _certificate = dcp::Certificate (dcp::file_to_string(file));
65                 _url = url;
66         } catch (dcp::MiscError& e) {
67                 return String::compose(wx_to_std(_("Could not read certificate file (%1)")), e.what());
68         }
69         return {};
70 }
71
72
73 optional<string>
74 DownloadCertificatePanel::load_certificate_from_chain (boost::filesystem::path file, string url)
75 {
76         try {
77                 _certificate = dcp::CertificateChain(dcp::file_to_string(file)).leaf();
78                 _url = url;
79         } catch (dcp::MiscError& e) {
80                 return String::compose(wx_to_std(_("Could not read certificate file (%1)")), e.what());
81         }
82         return {};
83 }
84
85
86 optional<dcp::Certificate>
87 DownloadCertificatePanel::certificate () const
88 {
89         return _certificate;
90
91 }
92
93
94 optional<string>
95 DownloadCertificatePanel::url () const
96 {
97         return _url;
98
99 }
100
101 void
102 DownloadCertificatePanel::download ()
103 {
104         _dialog->message()->SetLabel (_("Downloading certificate"));
105
106         /* Hack: without this the SetLabel() above has no visible effect */
107         wxMilliSleep (200);
108
109         signal_manager->when_idle (boost::bind(&DownloadCertificatePanel::do_download, this));
110 }
111
112
113 bool
114 DownloadCertificatePanel::ready_to_download () const
115 {
116         return !_serial->IsEmpty();
117 }