Shift some more stuff around.
[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 "download_certificate_dialog.h"
24 #include "lib/signal_manager.h"
25 #include <dcp/util.h>
26 #include <dcp/exceptions.h>
27 #include <boost/bind.hpp>
28
29 using boost::function;
30 using boost::optional;
31
32 DownloadCertificatePanel::DownloadCertificatePanel (wxWindow* parent, wxStaticText* message, DownloadCertificateDialog* dialog)
33         : wxPanel (parent, wxID_ANY)
34         , _dialog (dialog)
35         , _message (message)
36 {
37         _overall_sizer = new wxBoxSizer (wxVERTICAL);
38         SetSizer (_overall_sizer);
39
40         _table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
41         _table->AddGrowableCol (1, 1);
42
43         _overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
44
45         add_label_to_sizer (_table, this, _("Serial number"), true);
46         _serial = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (300, -1));
47         _table->Add (_serial, 1, wxEXPAND);
48
49         _serial->Bind (wxEVT_TEXT, boost::bind (&DownloadCertificateDialog::setup_sensitivity, _dialog));
50
51         _overall_sizer->Layout ();
52         _overall_sizer->SetSizeHints (this);
53 }
54
55 void
56 DownloadCertificatePanel::load (boost::filesystem::path file)
57 {
58         try {
59                 _certificate = dcp::Certificate (dcp::file_to_string (file));
60         } catch (dcp::MiscError& e) {
61                 error_dialog (this, _("Could not read certificate file."), std_to_wx(e.what()));
62         }
63 }
64
65 optional<dcp::Certificate>
66 DownloadCertificatePanel::certificate () const
67 {
68         return _certificate;
69 }
70
71 void
72 DownloadCertificatePanel::download ()
73 {
74         _message->SetLabel (_("Downloading certificate"));
75
76         /* Hack: without this the SetLabel() above has no visible effect */
77         wxMilliSleep (200);
78
79         signal_manager->when_idle (boost::bind (&DownloadCertificatePanel::do_download, this, wx_to_std(_serial->GetValue())));
80 }
81
82 bool
83 DownloadCertificatePanel::ready_to_download () const
84 {
85         return !_serial->IsEmpty ();
86 }