Add GUI and storage for UTC offset in Cinema.
[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 <boost/foreach.hpp>
24
25 using std::string;
26 using std::vector;
27 using std::copy;
28 using std::back_inserter;
29 using std::list;
30 using std::cout;
31 using boost::bind;
32
33 static string
34 column (string s)
35 {
36         return s;
37 }
38
39 CinemaDialog::CinemaDialog (wxWindow* parent, string title, string name, list<string> emails, int utc_offset)
40         : wxDialog (parent, wxID_ANY, std_to_wx (title))
41 {
42         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
43         SetSizer (overall_sizer);
44
45         wxGridBagSizer* sizer = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
46         int r = 0;
47
48         add_label_to_sizer (sizer, this, _("Name"), true, wxGBPosition (r, 0));
49         _name = new wxTextCtrl (this, wxID_ANY, std_to_wx (name), wxDefaultPosition, wxSize (500, -1));
50         sizer->Add (_name, wxGBPosition (r, 1));
51         ++r;
52
53         add_label_to_sizer (sizer, this, _("UTC offset (time zone)"), true, wxGBPosition (r, 0));
54         _utc_offset = new wxChoice (this, wxID_ANY);
55         sizer->Add (_utc_offset, wxGBPosition (r, 1));
56         ++r;
57
58         add_label_to_sizer (sizer, this, _("Email addresses for KDM delivery"), false, wxGBPosition (r, 0), wxGBSpan (1, 2));
59         ++r;
60
61         copy (emails.begin(), emails.end(), back_inserter (_emails));
62
63         vector<string> columns;
64         columns.push_back (wx_to_std (_("Address")));
65         _email_list = new EditableList<string, EmailDialog> (
66                 this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), bind (&column, _1)
67                 );
68
69         sizer->Add (_email_list, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND);
70         ++r;
71
72         overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
73
74         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
75         if (buttons) {
76                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
77         }
78
79         for (int i = -11; i <= -1; ++i) {
80                 _utc_offset->Append (wxString::Format (_("UTC%d"), i));
81         }
82         _utc_offset->Append (_("UTC"));
83         for (int i = 1; i <= 12; ++i) {
84                 _utc_offset->Append (wxString::Format (_("UTC+%d"), i));
85         }
86
87         _utc_offset->SetSelection (utc_offset + 11);
88
89         overall_sizer->Layout ();
90         overall_sizer->SetSizeHints (this);
91 }
92
93 string
94 CinemaDialog::name () const
95 {
96         return wx_to_std (_name->GetValue());
97 }
98
99 void
100 CinemaDialog::set_emails (vector<string> e)
101 {
102         _emails = e;
103 }
104
105 vector<string>
106 CinemaDialog::get_emails () const
107 {
108         return _emails;
109 }
110
111 list<string>
112 CinemaDialog::emails () const
113 {
114         list<string> e;
115         copy (_emails.begin(), _emails.end(), back_inserter (e));
116         return e;
117 }
118
119 int
120 CinemaDialog::utc_offset () const
121 {
122         return _utc_offset->GetSelection() - 11;
123 }