2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #include <wx/filepicker.h>
21 #include <wx/validate.h>
22 #include <libdcp/exceptions.h>
23 #include "lib/compose.hpp"
24 #include "screen_dialog.h"
29 using boost::shared_ptr;
31 ScreenDialog::ScreenDialog (wxWindow* parent, string title, string name, shared_ptr<libdcp::Certificate> certificate)
32 : wxDialog (parent, wxID_ANY, std_to_wx (title))
33 , _certificate (certificate)
35 wxFlexGridSizer* table = new wxFlexGridSizer (2, 6, 6);
36 table->AddGrowableCol (1, 1);
38 add_label_to_sizer (table, this, "Name", true);
39 _name = new wxTextCtrl (this, wxID_ANY, std_to_wx (name), wxDefaultPosition, wxSize (320, -1));
40 table->Add (_name, 1, wxEXPAND);
42 add_label_to_sizer (table, this, "Certificate", true);
43 _certificate_load = new wxButton (this, wxID_ANY, wxT ("Load from file..."));
44 table->Add (_certificate_load, 1, wxEXPAND);
47 _certificate_text = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (320, 256), wxTE_MULTILINE | wxTE_READONLY);
49 _certificate_text->SetValue (certificate->certificate ());
51 wxFont font = wxSystemSettings::GetFont (wxSYS_ANSI_FIXED_FONT);
52 font.SetPointSize (font.GetPointSize() / 2);
53 _certificate_text->SetFont (font);
54 table->Add (_certificate_text, 1, wxEXPAND);
56 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
57 overall_sizer->Add (table, 1, wxEXPAND | wxALL, 6);
59 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
61 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
64 SetSizer (overall_sizer);
65 overall_sizer->Layout ();
66 overall_sizer->SetSizeHints (this);
68 _certificate_load->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreenDialog::load_certificate, this));
74 ScreenDialog::name () const
76 return wx_to_std (_name->GetValue());
79 shared_ptr<libdcp::Certificate>
80 ScreenDialog::certificate () const
86 ScreenDialog::load_certificate ()
88 wxFileDialog* d = new wxFileDialog (this, _("Select Certificate File"));
90 if (d->ShowModal () == wxID_OK) {
92 _certificate.reset (new libdcp::Certificate (boost::filesystem::path (wx_to_std (d->GetPath ()))));
93 _certificate_text->SetValue (_certificate->certificate ());
94 } catch (libdcp::MiscError& e) {
95 error_dialog (this, String::compose ("Could not read certificate file (%1)", e.what()));
101 setup_sensitivity ();
105 ScreenDialog::setup_sensitivity ()
107 wxButton* ok = dynamic_cast<wxButton*> (FindWindowById (wxID_OK, this));
108 ok->Enable (_certificate);