2 Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "download_certificate_panel.h"
23 #include "download_certificate_dialog.h"
24 #include "lib/signal_manager.h"
25 #include "lib/compose.hpp"
27 #include <dcp/certificate_chain.h>
28 #include <dcp/exceptions.h>
29 #include <boost/bind/bind.hpp>
32 using boost::function;
33 using boost::optional;
35 DownloadCertificatePanel::DownloadCertificatePanel (DownloadCertificateDialog* dialog)
36 : wxPanel (dialog->notebook(), wxID_ANY)
39 _overall_sizer = new wxBoxSizer (wxVERTICAL);
40 SetSizer (_overall_sizer);
42 _table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
43 _table->AddGrowableCol (1, 1);
45 _overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
47 add_label_to_sizer (_table, this, _("Serial number"), true, 0, wxALIGN_CENTER_VERTICAL);
48 _serial = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (300, -1));
49 _table->Add (_serial, 1, wxEXPAND);
51 _serial->Bind (wxEVT_TEXT, boost::bind (&DownloadCertificateDialog::setup_sensitivity, _dialog));
53 _overall_sizer->Layout ();
54 _overall_sizer->SetSizeHints (this);
59 DownloadCertificatePanel::load_certificate (boost::filesystem::path file)
62 _certificate = dcp::Certificate (dcp::file_to_string (file));
63 } catch (dcp::MiscError& e) {
64 return String::compose(wx_to_std(_("Could not read certificate file (%1)")), e.what());
66 return optional<string>();
71 DownloadCertificatePanel::load_certificate_from_chain (boost::filesystem::path file)
74 _certificate = dcp::CertificateChain (dcp::file_to_string(file)).leaf();
75 } catch (dcp::MiscError& e) {
76 return String::compose(wx_to_std(_("Could not read certificate file (%1)")), e.what());
78 return optional<string>();
82 optional<dcp::Certificate>
83 DownloadCertificatePanel::certificate () const
89 DownloadCertificatePanel::download ()
91 _dialog->message()->SetLabel (_("Downloading certificate"));
93 /* Hack: without this the SetLabel() above has no visible effect */
96 signal_manager->when_idle (boost::bind (&DownloadCertificatePanel::do_download, this));
100 DownloadCertificatePanel::ready_to_download () const
102 return !_serial->IsEmpty ();