Fix layout of KDM CC configuration (#793).
[dcpomatic.git] / src / wx / cinema_dialog.cc
1 /*
2     Copyright (C) 2012 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 "cinema_dialog.h"
21 #include "wx_util.h"
22 #include <boost/foreach.hpp>
23
24 using std::string;
25 using std::vector;
26 using std::copy;
27 using std::back_inserter;
28 using std::list;
29 using std::cout;
30 using boost::bind;
31
32 static string
33 column (string s)
34 {
35         return s;
36 }
37
38 CinemaDialog::CinemaDialog (wxWindow* parent, string title, string name, list<string> emails)
39         : wxDialog (parent, wxID_ANY, std_to_wx (title))
40 {
41         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
42         SetSizer (overall_sizer);
43
44         wxGridBagSizer* sizer = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
45         int r = 0;
46
47         add_label_to_sizer (sizer, this, _("Name"), true, wxGBPosition (r, 0));
48         _name = new wxTextCtrl (this, wxID_ANY, std_to_wx (name), wxDefaultPosition, wxSize (500, -1));
49         sizer->Add (_name, wxGBPosition (r, 1));
50         ++r;
51
52         add_label_to_sizer (sizer, this, _("Email addresses for KDM delivery"), false, wxGBPosition (r, 0), wxGBSpan (1, 2));
53         ++r;
54
55         copy (emails.begin(), emails.end(), back_inserter (_emails));
56
57         vector<string> columns;
58         columns.push_back (wx_to_std (_("Address")));
59         _email_list = new EditableList<string, EmailDialog> (
60                 this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), bind (&column, _1)
61                 );
62
63         sizer->Add (_email_list, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND);
64         ++r;
65
66         overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
67
68         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
69         if (buttons) {
70                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
71         }
72
73         overall_sizer->Layout ();
74         overall_sizer->SetSizeHints (this);
75 }
76
77 string
78 CinemaDialog::name () const
79 {
80         return wx_to_std (_name->GetValue());
81 }
82
83 void
84 CinemaDialog::set_emails (vector<string> e)
85 {
86         _emails = e;
87 }
88
89 vector<string>
90 CinemaDialog::get_emails () const
91 {
92         return _emails;
93 }
94
95 list<string>
96 CinemaDialog::emails () const
97 {
98         list<string> e;
99         copy (_emails.begin(), _emails.end(), back_inserter (e));
100         return e;
101 }