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