No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / wx / kdm_timing_panel.cc
1 /*
2     Copyright (C) 2015-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 "kdm_timing_panel.h"
22 #include "wx_util.h"
23 #include <wx/datectrl.h>
24 #include <wx/timectrl.h>
25 #include <wx/dateevt.h>
26
27 using boost::bind;
28
29 KDMTimingPanel::KDMTimingPanel (wxWindow* parent)
30         : wxPanel (parent, wxID_ANY)
31 {
32         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
33
34         wxFlexGridSizer* table = new wxFlexGridSizer (6, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
35         add_label_to_sizer (table, this, _("From"), true);
36         wxDateTime from;
37         from.SetToCurrent ();
38         _from_date = new wxDatePickerCtrl (this, wxID_ANY, from);
39         table->Add (_from_date, 1, wxEXPAND);
40         _from_time = new wxTimePickerCtrl (this, wxID_ANY, from);
41         table->Add (_from_time, 1, wxEXPAND);
42
43         add_label_to_sizer (table, this, _("until"), true);
44         wxDateTime to = from;
45         /* 1 week from now */
46         to.Add (wxDateSpan (0, 0, 1, 0));
47         _until_date = new wxDatePickerCtrl (this, wxID_ANY, to);
48         table->Add (_until_date, 1, wxEXPAND);
49         _until_time = new wxTimePickerCtrl (this, wxID_ANY, to);
50         table->Add (_until_time, 1, wxEXPAND);
51
52         overall_sizer->Add (table);
53
54         _warning = new wxStaticText (this, wxID_ANY, wxT (""));
55         overall_sizer->Add (_warning, 0, wxTOP, DCPOMATIC_SIZER_GAP);
56         wxFont font = _warning->GetFont();
57         font.SetStyle(wxFONTSTYLE_ITALIC);
58         font.SetPointSize(font.GetPointSize() - 1);
59         _warning->SetForegroundColour (wxColour (255, 0, 0));
60         _warning->SetFont(font);
61
62         _from_date->Bind (wxEVT_DATE_CHANGED, bind (&KDMTimingPanel::changed, this));
63         _until_date->Bind (wxEVT_DATE_CHANGED, bind (&KDMTimingPanel::changed, this));
64         _from_time->Bind (wxEVT_TIME_CHANGED, bind (&KDMTimingPanel::changed, this));
65         _until_time->Bind (wxEVT_TIME_CHANGED, bind (&KDMTimingPanel::changed, this));
66
67         SetSizer (overall_sizer);
68 }
69
70 boost::posix_time::ptime
71 KDMTimingPanel::from () const
72 {
73         return posix_time (_from_date, _from_time);
74 }
75
76 boost::posix_time::ptime
77 KDMTimingPanel::posix_time (wxDatePickerCtrl* date_picker, wxTimePickerCtrl* time_picker)
78 {
79         wxDateTime const date = date_picker->GetValue ();
80         wxDateTime const time = time_picker->GetValue ();
81         return boost::posix_time::ptime (
82                 boost::gregorian::date (date.GetYear(), date.GetMonth() + 1, date.GetDay()),
83                 boost::posix_time::time_duration (time.GetHour(), time.GetMinute(), time.GetSecond())
84                 );
85 }
86
87 boost::posix_time::ptime
88 KDMTimingPanel::until () const
89 {
90         return posix_time (_until_date, _until_time);
91 }
92
93 bool
94 KDMTimingPanel::valid () const
95 {
96         return until() > from();
97 }
98
99 void
100 KDMTimingPanel::changed () const
101 {
102         if (valid ()) {
103                 _warning->SetLabel (wxT (""));
104         } else {
105                 _warning->SetLabel (_("The 'until' time must be after the 'from' time."));
106         }
107
108         TimingChanged ();
109 }