Add a 'Make DKDM' dialogue box to simplify and (hopefully) clarify DKDM creation...
[dcpomatic.git] / src / wx / cinema_dialog.cc
1 /*
2     Copyright (C) 2012-2016 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 "cinema_dialog.h"
22 #include "wx_util.h"
23 #include "lib/dcpomatic_assert.h"
24 #include "lib/util.h"
25 #include <boost/foreach.hpp>
26
27 using std::string;
28 using std::vector;
29 using std::copy;
30 using std::back_inserter;
31 using std::list;
32 using std::cout;
33 using boost::bind;
34
35 static string
36 column (string s)
37 {
38         return s;
39 }
40
41 CinemaDialog::CinemaDialog (wxWindow* parent, wxString title, string name, list<string> emails, string notes, int utc_offset_hour, int utc_offset_minute)
42         : wxDialog (parent, wxID_ANY, title)
43 {
44         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
45         SetSizer (overall_sizer);
46
47         wxGridBagSizer* sizer = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
48         int r = 0;
49
50         add_label_to_sizer (sizer, this, _("Name"), true, wxGBPosition (r, 0));
51         _name = new wxTextCtrl (this, wxID_ANY, std_to_wx (name), wxDefaultPosition, wxSize (500, -1));
52         sizer->Add (_name, wxGBPosition (r, 1));
53         ++r;
54
55         add_label_to_sizer (sizer, this, _("UTC offset (time zone)"), true, wxGBPosition (r, 0));
56         _utc_offset = new wxChoice (this, wxID_ANY);
57         sizer->Add (_utc_offset, wxGBPosition (r, 1));
58         ++r;
59
60         add_label_to_sizer (sizer, this, _("Notes"), true, wxGBPosition (r, 0));
61         _notes = new wxTextCtrl (this, wxID_ANY, std_to_wx (notes), wxDefaultPosition, wxSize (500, -1));
62         sizer->Add (_notes, wxGBPosition (r, 1));
63         ++r;
64
65         add_label_to_sizer (sizer, this, _("Email addresses for KDM delivery"), false, wxGBPosition (r, 0), wxGBSpan (1, 2));
66         ++r;
67
68         copy (emails.begin(), emails.end(), back_inserter (_emails));
69
70         vector<EditableListColumn> columns;
71         columns.push_back (EditableListColumn(wx_to_std(_("Address"))));
72         _email_list = new EditableList<string, EmailDialog> (
73                 this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), bind (&column, _1)
74                 );
75
76         sizer->Add (_email_list, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND);
77         ++r;
78
79         overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
80
81         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
82         if (buttons) {
83                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
84         }
85
86         /* Default to UTC */
87         size_t sel = get_offsets (_offsets);
88         for (size_t i = 0; i < _offsets.size(); ++i) {
89                 _utc_offset->Append (_offsets[i].name);
90                 if (_offsets[i].hour == utc_offset_hour && _offsets[i].minute == utc_offset_minute) {
91                         sel = i;
92                 }
93         }
94
95         _utc_offset->SetSelection (sel);
96
97         overall_sizer->Layout ();
98         overall_sizer->SetSizeHints (this);
99 }
100
101 string
102 CinemaDialog::name () const
103 {
104         return wx_to_std (_name->GetValue());
105 }
106
107 void
108 CinemaDialog::set_emails (vector<string> e)
109 {
110         _emails = e;
111 }
112
113 vector<string>
114 CinemaDialog::get_emails () const
115 {
116         return _emails;
117 }
118
119 list<string>
120 CinemaDialog::emails () const
121 {
122         list<string> e;
123         copy (_emails.begin(), _emails.end(), back_inserter (e));
124         return e;
125 }
126
127 int
128 CinemaDialog::utc_offset_hour () const
129 {
130         int const sel = _utc_offset->GetSelection();
131         if (sel < 0 || sel > int (_offsets.size())) {
132                 return 0;
133         }
134
135         return _offsets[sel].hour;
136 }
137
138 int
139 CinemaDialog::utc_offset_minute () const
140 {
141         int const sel = _utc_offset->GetSelection();
142         if (sel < 0 || sel > int (_offsets.size())) {
143                 return 0;
144         }
145
146         return _offsets[sel].minute;
147 }
148
149 string
150 CinemaDialog::notes () const
151 {
152         return wx_to_std (_notes->GetValue ());
153 }