More rearrangement and add Barco Alchemy.
[dcpomatic.git] / src / wx / download_certificate_dialog.cc
1 /*
2     Copyright (C) 2014-2015 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 "download_certificate_dialog.h"
24 #include "wx_util.h"
25
26 using boost::optional;
27
28 DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent)
29         : wxDialog (parent, wxID_ANY, _("Download certificate"))
30 {
31         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
32
33         _notebook = new wxNotebook (this, wxID_ANY);
34         sizer->Add (_notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
35
36         _download = new wxButton (this, wxID_ANY, _("Download"));
37         sizer->Add (_download, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
38
39         _message = new wxStaticText (this, wxID_ANY, wxT (""));
40         sizer->Add (_message, 0, wxALL, DCPOMATIC_SIZER_GAP);
41         wxFont font = _message->GetFont();
42         font.SetStyle (wxFONTSTYLE_ITALIC);
43         font.SetPointSize (font.GetPointSize() - 1);
44         _message->SetFont (font);
45
46         _pages.push_back (new DolbyDoremiCertificatePanel (this));
47         _pages.push_back (new BarcoAlchemyCertificatePanel (this));
48
49         BOOST_FOREACH (DownloadCertificatePanel* i, _pages) {
50                 _notebook->AddPage (i, i->name(), true);
51         }
52
53         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
54         if (buttons) {
55                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
56         }
57
58         SetSizerAndFit (sizer);
59
60         _notebook->Bind (wxEVT_NOTEBOOK_PAGE_CHANGED, &DownloadCertificateDialog::page_changed, this);
61         _download->Bind (wxEVT_BUTTON, boost::bind (&DownloadCertificateDialog::download, this));
62         _download->Enable (false);
63
64         _notebook->SetSelection (0);
65
66         setup_sensitivity ();
67 }
68
69 DownloadCertificateDialog::~DownloadCertificateDialog ()
70 {
71         _notebook->Unbind (wxEVT_NOTEBOOK_PAGE_CHANGED, &DownloadCertificateDialog::page_changed, this);
72 }
73
74 void
75 DownloadCertificateDialog::download ()
76 {
77         _pages[_notebook->GetSelection()]->download ();
78 }
79
80 dcp::Certificate
81 DownloadCertificateDialog::certificate () const
82 {
83         optional<dcp::Certificate> c = _pages[_notebook->GetSelection()]->certificate ();
84         DCPOMATIC_ASSERT (c);
85         return c.get ();
86 }
87
88 void
89 DownloadCertificateDialog::setup_sensitivity ()
90 {
91         DownloadCertificatePanel* p = _pages[_notebook->GetSelection()];
92         _download->Enable (p->ready_to_download ());
93         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
94         if (ok) {
95                 ok->Enable (static_cast<bool>(p->certificate ()));
96         }
97 }
98
99 void
100 DownloadCertificateDialog::page_changed (wxNotebookEvent &)
101 {
102         setup_sensitivity ();
103 }