4a80dc9c03b0b4cb3e7ddaa22a9dd126e9ee6131
[dcpomatic.git] / src / wx / download_certificate_dialog.cc
1 /*
2     Copyright (C) 2014-2022 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 "barco_alchemy_certificate_panel.h"
23 #include "christie_certificate_panel.h"
24 #include "dcpomatic_button.h"
25 #include "dolby_doremi_certificate_panel.h"
26 #include "download_certificate_dialog.h"
27 #include "gdc_certificate_panel.h"
28 #include "qube_certificate_panel.h"
29 #include "static_text.h"
30 #include "wx_util.h"
31
32
33 using boost::optional;
34
35
36 DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent)
37         : wxDialog (parent, wxID_ANY, _("Download certificate"))
38 {
39         auto sizer = new wxBoxSizer (wxVERTICAL);
40
41         _notebook = new wxNotebook (this, wxID_ANY);
42         sizer->Add (_notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
43
44         _download = new Button (this, _("Download"));
45         sizer->Add (_download, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
46
47         _message = new StaticText (this, wxT (""));
48         sizer->Add (_message, 0, wxALL, DCPOMATIC_SIZER_GAP);
49         auto font = _message->GetFont();
50         font.SetStyle (wxFONTSTYLE_ITALIC);
51         font.SetPointSize (font.GetPointSize() - 1);
52         _message->SetFont (font);
53
54         _pages.push_back (new DolbyDoremiCertificatePanel (this));
55         _pages.push_back (new BarcoAlchemyCertificatePanel (this));
56         _pages.push_back (new ChristieCertificatePanel (this));
57         _pages.push_back (new GDCCertificatePanel (this));
58         _pages.push_back (new QubeCertificatePanel (this, N_("QXI")));
59         _pages.push_back (new QubeCertificatePanel (this, N_("QXPD")));
60
61         for (auto i: _pages) {
62                 _notebook->AddPage (i, i->name(), true);
63         }
64
65         auto buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
66         if (buttons) {
67                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
68         }
69
70         SetSizerAndFit (sizer);
71
72         _notebook->Bind (wxEVT_NOTEBOOK_PAGE_CHANGED, &DownloadCertificateDialog::page_changed, this);
73         _download->Bind (wxEVT_BUTTON, boost::bind (&DownloadCertificateDialog::download, this));
74         _download->Enable (false);
75
76         _notebook->SetSelection (0);
77
78         SetMinSize (wxSize(640, -1));
79
80         setup_sensitivity ();
81 }
82
83
84 DownloadCertificateDialog::~DownloadCertificateDialog ()
85 {
86         _notebook->Unbind (wxEVT_NOTEBOOK_PAGE_CHANGED, &DownloadCertificateDialog::page_changed, this);
87 }
88
89
90 void
91 DownloadCertificateDialog::download ()
92 {
93         _pages[_notebook->GetSelection()]->download ();
94 }
95
96
97 dcp::Certificate
98 DownloadCertificateDialog::certificate () const
99 {
100         auto c = _pages[_notebook->GetSelection()]->certificate ();
101         DCPOMATIC_ASSERT (c);
102         return *c;
103 }
104
105 void
106 DownloadCertificateDialog::setup_sensitivity ()
107 {
108         auto p = _pages[_notebook->GetSelection()];
109         _download->Enable (p->ready_to_download ());
110         auto ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
111         if (ok) {
112                 ok->Enable (static_cast<bool>(p->certificate ()));
113         }
114 }
115
116
117 void
118 DownloadCertificateDialog::page_changed (wxNotebookEvent& ev)
119 {
120         setup_sensitivity ();
121         ev.Skip ();
122 }