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