Move some stuff into DownloadCertificatePanel; add name().
[dcpomatic.git] / src / wx / download_certificate_panel.cc
1 /*
2     Copyright (C) 2014-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 #include "wx_util.h"
22 #include "download_certificate_panel.h"
23 #include "lib/signal_manager.h"
24 #include <dcp/util.h>
25 #include <dcp/exceptions.h>
26 #include <boost/bind.hpp>
27
28 using boost::function;
29 using boost::optional;
30
31 DownloadCertificatePanel::DownloadCertificatePanel (wxWindow* parent, DownloadCertificateDialog* dialog)
32         : wxPanel (parent, wxID_ANY)
33         , _dialog (dialog)
34 {
35         _overall_sizer = new wxBoxSizer (wxVERTICAL);
36         SetSizer (_overall_sizer);
37
38         _table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
39         _table->AddGrowableCol (1, 1);
40
41         _overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
42 }
43
44 void
45 DownloadCertificatePanel::layout ()
46 {
47         _overall_sizer->Layout ();
48         _overall_sizer->SetSizeHints (this);
49 }
50
51 void
52 DownloadCertificatePanel::load (boost::filesystem::path file)
53 {
54         try {
55                 _certificate = dcp::Certificate (dcp::file_to_string (file));
56         } catch (dcp::MiscError& e) {
57                 error_dialog (this, _("Could not read certificate file."), std_to_wx(e.what()));
58         }
59 }
60
61 optional<dcp::Certificate>
62 DownloadCertificatePanel::certificate () const
63 {
64         return _certificate;
65 }
66
67 void
68 DownloadCertificatePanel::download (wxStaticText* message)
69 {
70         message->SetLabel (_("Downloading certificate"));
71
72         /* Hack: without this the SetLabel() above has no visible effect */
73         wxMilliSleep (200);
74
75         signal_manager->when_idle (boost::bind (&DownloadCertificatePanel::do_download, this, message));
76 }