Rearrange cerficate download UI a bit.
[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 "doremi_certificate_panel.h"
21 #include "dolby_certificate_panel.h"
22 #include "download_certificate_dialog.h"
23 #include "wx_util.h"
24
25 DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent)
26         : wxDialog (parent, wxID_ANY, _("Download certificate"))
27 {
28         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
29
30         _notebook = new wxNotebook (this, wxID_ANY);
31         sizer->Add (_notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
32
33         _pages.push_back (new DoremiCertificatePanel (_notebook, this));
34         _setup.push_back (false);
35         _notebook->AddPage (_pages.back(), _("Doremi"), true);
36         _pages.push_back (new DolbyCertificatePanel (_notebook, this));
37         _setup.push_back (false);
38         _notebook->AddPage (_pages.back(), _("Dolby"), false);
39
40         _download = new wxButton (this, wxID_ANY, _("Download"));
41         sizer->Add (_download, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
42
43         _message = new wxStaticText (this, wxID_ANY, wxT (""));
44         sizer->Add (_message, 0, wxALL, DCPOMATIC_SIZER_GAP);
45         wxFont font = _message->GetFont();
46         font.SetStyle (wxFONTSTYLE_ITALIC);
47         font.SetPointSize (font.GetPointSize() - 1);
48         _message->SetFont (font);
49
50         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
51         if (buttons) {
52                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
53         }
54
55         SetSizerAndFit (sizer);
56
57         _notebook->Bind (wxEVT_NOTEBOOK_PAGE_CHANGED, boost::bind (&DownloadCertificateDialog::page_changed, this));
58         _download->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DownloadCertificateDialog::download, this));
59         _download->Enable (false);
60
61         page_changed ();
62 }
63
64 void
65 DownloadCertificateDialog::download ()
66 {
67         _pages[_notebook->GetSelection()]->download (_message);
68 }
69
70 dcp::Certificate
71 DownloadCertificateDialog::certificate () const
72 {
73         return _pages[_notebook->GetSelection()]->certificate ();
74 }
75
76 void
77 DownloadCertificateDialog::setup_sensitivity ()
78 {
79         _download->Enable (_pages[_notebook->GetSelection()]->ready_to_download ());
80 }
81
82 void
83 DownloadCertificateDialog::page_changed ()
84 {
85         int const n = _notebook->GetSelection();
86         if (!_setup[n]) {
87                 _pages[n]->setup ();
88                 _setup[n] = true;
89         }
90 }