Disallow KDM until times being before from times (#821).
authorCarl Hetherington <cth@carlh.net>
Fri, 22 Apr 2016 11:28:19 +0000 (12:28 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 22 Apr 2016 11:28:19 +0000 (12:28 +0100)
ChangeLog
src/wx/kdm_dialog.cc
src/wx/kdm_timing_panel.cc
src/wx/kdm_timing_panel.h

index f0912162bad4ad162c02f1118963235d3dc4adc9..b867e7943618d2ba2c6a699acaa914e65b9b2179 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2016-04-22  c.hetherington  <cth@carlh.net>
 
+       * Disallow KDM until times from being before from times (#821).
+
        * Warn when loading certificates from files that have
        other stuff after the certificate (#805).
 
index 5874dea54f65a97312b30d5d647a2b430d04f423..856808f11563040a7e1464e165832f05d6e17063 100644 (file)
@@ -95,6 +95,7 @@ KDMDialog::KDMDialog (wxWindow* parent, boost::shared_ptr<const Film> film)
        /* Bind */
 
        _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
+       _timing->TimingChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
 
        setup_sensitivity ();
 
@@ -113,7 +114,7 @@ KDMDialog::setup_sensitivity ()
 
        wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
        if (ok) {
-               ok->Enable (!_screens->screens().empty() && sd);
+               ok->Enable (!_screens->screens().empty() && _timing->valid() && sd);
        }
 }
 
index c0d0c27e8de12f5e2bfb8adf2d84791d3aeb24cf..6c5bd7e3b56a7fbf2bbfcf6d168ff5849b43b09e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 #include "wx_util.h"
 #include <wx/datectrl.h>
 #include <wx/timectrl.h>
+#include <wx/dateevt.h>
+
+using boost::bind;
 
 KDMTimingPanel::KDMTimingPanel (wxWindow* parent)
        : wxPanel (parent, wxID_ANY)
 {
+       wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
+
        wxFlexGridSizer* table = new wxFlexGridSizer (6, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
        add_label_to_sizer (table, this, _("From"), true);
        wxDateTime from;
@@ -43,7 +48,22 @@ KDMTimingPanel::KDMTimingPanel (wxWindow* parent)
        _until_time = new wxTimePickerCtrl (this, wxID_ANY, to);
        table->Add (_until_time, 1, wxEXPAND);
 
-       SetSizer (table);
+       overall_sizer->Add (table);
+
+       _warning = new wxStaticText (this, wxID_ANY, wxT (""));
+       overall_sizer->Add (_warning, 0, wxTOP, DCPOMATIC_SIZER_GAP);
+       wxFont font = _warning->GetFont();
+       font.SetStyle(wxFONTSTYLE_ITALIC);
+       font.SetPointSize(font.GetPointSize() - 1);
+       _warning->SetForegroundColour (wxColour (255, 0, 0));
+       _warning->SetFont(font);
+
+       _from_date->Bind (wxEVT_DATE_CHANGED, bind (&KDMTimingPanel::changed, this));
+       _until_date->Bind (wxEVT_DATE_CHANGED, bind (&KDMTimingPanel::changed, this));
+       _from_time->Bind (wxEVT_TIME_CHANGED, bind (&KDMTimingPanel::changed, this));
+       _until_time->Bind (wxEVT_TIME_CHANGED, bind (&KDMTimingPanel::changed, this));
+
+       SetSizer (overall_sizer);
 }
 
 boost::posix_time::ptime
@@ -68,3 +88,21 @@ KDMTimingPanel::until () const
 {
        return posix_time (_until_date, _until_time);
 }
+
+bool
+KDMTimingPanel::valid () const
+{
+       return until() > from();
+}
+
+void
+KDMTimingPanel::changed () const
+{
+       if (valid ()) {
+               _warning->SetLabel (wxT (""));
+       } else {
+               _warning->SetLabel (_("The 'until' time must be after the 'from' time."));
+       }
+
+       TimingChanged ();
+}
index 7e607296fcba677f706d35af61c6298b98db0ec8..d71e2d29265788d2939651930e9b74f71e450576 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
 
 #include <wx/wx.h>
 #include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/signals2.hpp>
 
 class wxDatePickerCtrl;
 class wxTimePickerCtrl;
@@ -33,11 +34,17 @@ public:
        /** @return KDM until time in local time */
        boost::posix_time::ptime until () const;
 
+       bool valid () const;
+
+       boost::signals2::signal<void ()> TimingChanged;
+
 private:
+       void changed () const;
        static boost::posix_time::ptime posix_time (wxDatePickerCtrl *, wxTimePickerCtrl *);
 
        wxDatePickerCtrl* _from_date;
        wxDatePickerCtrl* _until_date;
        wxTimePickerCtrl* _from_time;
        wxTimePickerCtrl* _until_time;
+       wxStaticText* _warning;
 };