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