Use new Dolby website for both Doremi and Dolby certificates (#775).
[dcpomatic.git] / src / wx / download_certificate_dialog.cc
1 /*
2     Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "dolby_doremi_certificate_panel.h"
21 #include "download_certificate_dialog.h"
22 #include "wx_util.h"
23
24 using boost::optional;
25
26 DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent)
27         : wxDialog (parent, wxID_ANY, _("Download certificate"))
28 {
29         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
30
31         _notebook = new wxNotebook (this, wxID_ANY);
32         sizer->Add (_notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
33
34         _pages.push_back (new DolbyDoremiCertificatePanel (_notebook, this));
35         _setup.push_back (false);
36         _notebook->AddPage (_pages.back(), _("Dolby / Doremi"), true);
37
38         _download = new wxButton (this, wxID_ANY, _("Download"));
39         sizer->Add (_download, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
40
41         _message = new wxStaticText (this, wxID_ANY, wxT (""));
42         sizer->Add (_message, 0, wxALL, DCPOMATIC_SIZER_GAP);
43         wxFont font = _message->GetFont();
44         font.SetStyle (wxFONTSTYLE_ITALIC);
45         font.SetPointSize (font.GetPointSize() - 1);
46         _message->SetFont (font);
47
48         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
49         if (buttons) {
50                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
51         }
52
53         SetSizerAndFit (sizer);
54
55         _notebook->Bind (wxEVT_NOTEBOOK_PAGE_CHANGED, &DownloadCertificateDialog::page_changed, this);
56         _download->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DownloadCertificateDialog::download, this));
57         _download->Enable (false);
58
59         wxNotebookEvent ev;
60         page_changed (ev);
61 }
62
63 DownloadCertificateDialog::~DownloadCertificateDialog ()
64 {
65         _notebook->Unbind (wxEVT_NOTEBOOK_PAGE_CHANGED, &DownloadCertificateDialog::page_changed, this);
66 }
67
68 void
69 DownloadCertificateDialog::download ()
70 {
71         _pages[_notebook->GetSelection()]->download (_message);
72 }
73
74 dcp::Certificate
75 DownloadCertificateDialog::certificate () const
76 {
77         optional<dcp::Certificate> c = _pages[_notebook->GetSelection()]->certificate ();
78         DCPOMATIC_ASSERT (c);
79         return c.get ();
80 }
81
82 void
83 DownloadCertificateDialog::setup_sensitivity ()
84 {
85         DownloadCertificatePanel* p = _pages[_notebook->GetSelection()];
86         _download->Enable (p->ready_to_download ());
87         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
88         if (ok) {
89                 ok->Enable (static_cast<bool>(p->certificate ()));
90         }
91
92 }
93
94 void
95 DownloadCertificateDialog::page_changed (wxNotebookEvent &)
96 {
97         int const n = _notebook->GetSelection();
98         if (!_setup[n]) {
99                 _pages[n]->setup ();
100                 _setup[n] = true;
101         }
102
103         setup_sensitivity ();
104 }