debc0679595653dc8ed72848119e23b760ddc171
[dcpomatic.git] / src / wx / cinema_dialog.cc
1 /*
2     Copyright (C) 2012-2016 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 "lib/dcpomatic_assert.h"
23 #include "lib/util.h"
24 #include <boost/foreach.hpp>
25
26 using std::string;
27 using std::vector;
28 using std::copy;
29 using std::back_inserter;
30 using std::list;
31 using std::cout;
32 using boost::bind;
33
34 static string
35 column (string s)
36 {
37         return s;
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         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
44         SetSizer (overall_sizer);
45
46         wxGridBagSizer* 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<string> columns;
70         columns.push_back (wx_to_std (_("Address")));
71         _email_list = new EditableList<string, EmailDialog> (
72                 this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), bind (&string_not_empty, _1), bind (&column, _1)
73                 );
74
75         sizer->Add (_email_list, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND);
76         ++r;
77
78         overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
79
80         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
81         if (buttons) {
82                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
83         }
84
85         _offsets.push_back (Offset (_("UTC-11"),  -11,  0));
86         _offsets.push_back (Offset (_("UTC-10"),  -10,  0));
87         _offsets.push_back (Offset (_("UTC-9"),    -9,  0));
88         _offsets.push_back (Offset (_("UTC-8"),    -8,  0));
89         _offsets.push_back (Offset (_("UTC-7"),    -7,  0));
90         _offsets.push_back (Offset (_("UTC-6"),    -6,  0));
91         _offsets.push_back (Offset (_("UTC-5"),    -5,  0));
92         _offsets.push_back (Offset (_("UTC-4:30"), -4, 30));
93         _offsets.push_back (Offset (_("UTC-4"),    -4,  0));
94         _offsets.push_back (Offset (_("UTC-3:30"), -3, 30));
95         _offsets.push_back (Offset (_("UTC-3"),    -3,  0));
96         _offsets.push_back (Offset (_("UTC-2"),    -2,  0));
97         _offsets.push_back (Offset (_("UTC-1"),    -1,  0));
98         _offsets.push_back (Offset (_("UTC")  ,     0,  0));
99         _offsets.push_back (Offset (_("UTC+1"),     1,  0));
100         _offsets.push_back (Offset (_("UTC+2"),     2,  0));
101         _offsets.push_back (Offset (_("UTC+3"),     3,  0));
102         _offsets.push_back (Offset (_("UTC+4"),     4,  0));
103         _offsets.push_back (Offset (_("UTC+5"),     5,  0));
104         _offsets.push_back (Offset (_("UTC+6"),     6,  0));
105         _offsets.push_back (Offset (_("UTC+7"),     7,  0));
106         _offsets.push_back (Offset (_("UTC+8"),     8,  0));
107         _offsets.push_back (Offset (_("UTC+9"),     9,  0));
108         _offsets.push_back (Offset (_("UTC+10"),   10,  0));
109         _offsets.push_back (Offset (_("UTC+11"),   11,  0));
110         _offsets.push_back (Offset (_("UTC+12"),   12,  0));
111
112         /* Default to UTC */
113         size_t sel = 13;
114         for (size_t i = 0; i < _offsets.size(); ++i) {
115                 _utc_offset->Append (_offsets[i].name);
116                 if (_offsets[i].hour == utc_offset_hour && _offsets[i].minute == utc_offset_minute) {
117                         sel = i;
118                 }
119         }
120
121         _utc_offset->SetSelection (sel);
122
123         overall_sizer->Layout ();
124         overall_sizer->SetSizeHints (this);
125 }
126
127 string
128 CinemaDialog::name () const
129 {
130         return wx_to_std (_name->GetValue());
131 }
132
133 void
134 CinemaDialog::set_emails (vector<string> e)
135 {
136         _emails = e;
137 }
138
139 vector<string>
140 CinemaDialog::get_emails () const
141 {
142         return _emails;
143 }
144
145 list<string>
146 CinemaDialog::emails () const
147 {
148         list<string> e;
149         copy (_emails.begin(), _emails.end(), back_inserter (e));
150         return e;
151 }
152
153 int
154 CinemaDialog::utc_offset_hour () const
155 {
156         int const sel = _utc_offset->GetSelection();
157         if (sel < 0 || sel > int (_offsets.size())) {
158                 return 0;
159         }
160
161         return _offsets[sel].hour;
162 }
163
164 int
165 CinemaDialog::utc_offset_minute () const
166 {
167         int const sel = _utc_offset->GetSelection();
168         if (sel < 0 || sel > int (_offsets.size())) {
169                 return 0;
170         }
171
172         return _offsets[sel].minute;
173 }
174
175 string
176 CinemaDialog::notes () const
177 {
178         return wx_to_std (_notes->GetValue ());
179 }