No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / wx / key_dialog.cc
1 /*
2     Copyright (C) 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 "key_dialog.h"
22 #include "wx_util.h"
23 #include <iostream>
24
25 using std::cout;
26
27 KeyDialog::KeyDialog (wxWindow* parent, dcp::Key key)
28         : TableDialog (parent, _("Key"), 3, 1, true)
29 {
30         add (_("Key"), true);
31
32         wxClientDC dc (parent);
33         wxSize size = dc.GetTextExtent (wxT ("0123456790ABCDEF0123456790ABCDEF"));
34         size.SetHeight (-1);
35
36         wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
37         wxArrayString list;
38
39         wxString n (wxT ("0123456789abcdefABCDEF"));
40         for (size_t i = 0; i < n.Length(); ++i) {
41                 list.Add (n[i]);
42         }
43
44         validator.SetIncludes (list);
45
46         _key = add (new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, size, 0, validator));
47         _key->SetValue (std_to_wx (key.hex ()));
48         _key->SetMaxLength (32);
49
50         _random = add (new wxButton (this, wxID_ANY, _("Random")));
51
52         _key->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&KeyDialog::key_changed, this));
53         _random->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KeyDialog::random, this));
54
55         layout ();
56 }
57
58 dcp::Key
59 KeyDialog::key () const
60 {
61         return dcp::Key (wx_to_std (_key->GetValue ()));
62 }
63
64 void
65 KeyDialog::key_changed ()
66 {
67         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
68         ok->Enable (_key->GetValue().Length() == 32);
69 }
70
71 void
72 KeyDialog::random ()
73 {
74         _key->SetValue (dcp::Key().hex ());
75 }