From c74d789ed75e87bccd094f45f082674f8f8d2f2f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 11 Apr 2016 13:05:00 +0100 Subject: [PATCH] Add UTC-3:30 timezone to cinema (#831). --- ChangeLog | 2 ++ src/lib/cinema.cc | 25 ++++++++++++--- src/lib/cinema.h | 24 +++++++++++---- src/lib/film.cc | 4 +-- src/tools/dcpomatic_kdm.cc | 4 +-- src/wx/cinema_dialog.cc | 62 ++++++++++++++++++++++++++++++++------ src/wx/cinema_dialog.h | 27 +++++++++++++++-- src/wx/screens_panel.cc | 7 +++-- 8 files changed, 125 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c60df9ca..a5c68e776 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2016-04-11 Carl Hetherington + * Add UTC-3:30 timezone to Cinema configuration (#831). + * Add option to preview left or right eye (#809). 2016-04-09 Carl Hetherington diff --git a/src/lib/cinema.cc b/src/lib/cinema.cc index 5e2b1b533..e9a7dce68 100644 --- a/src/lib/cinema.cc +++ b/src/lib/cinema.cc @@ -32,11 +32,18 @@ using boost::shared_ptr; Cinema::Cinema (cxml::ConstNodePtr node) : name (node->string_child ("Name")) - , _utc_offset (node->optional_number_child("UTCOffset").get_value_or (0)) { BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children("Email")) { emails.push_back (i->content ()); } + + if (node->optional_number_child("UTCOffset")) { + _utc_offset_hour = node->number_child("UTCOffset"); + } else { + _utc_offset_hour = node->optional_number_child("UTCOffsetHour").get_value_or (0); + } + + _utc_offset_minute = node->optional_number_child("UTCOffsetMinute").get_value_or (0); } /* This is necessary so that we can use shared_from_this in add_screen (which cannot be done from @@ -60,7 +67,8 @@ Cinema::as_xml (xmlpp::Element* parent) const parent->add_child("Email")->add_child_text (i); } - parent->add_child("UTCOffset")->add_child_text (dcp::raw_convert (_utc_offset)); + parent->add_child("UTCOffsetHour")->add_child_text (dcp::raw_convert (_utc_offset_hour)); + parent->add_child("UTCOffsetMinute")->add_child_text (dcp::raw_convert (_utc_offset_minute)); BOOST_FOREACH (shared_ptr i, _screens) { i->as_xml (parent->add_child ("Screen")); @@ -81,8 +89,15 @@ Cinema::remove_screen (shared_ptr s) } void -Cinema::set_utc_offset (int o) +Cinema::set_utc_offset_hour (int h) +{ + DCPOMATIC_ASSERT (h >= -11 && h <= 12); + _utc_offset_hour = h; +} + +void +Cinema::set_utc_offset_minute (int m) { - DCPOMATIC_ASSERT (o >= -11 && o <= 12); - _utc_offset = o; + DCPOMATIC_ASSERT (m >= 0 && m <= 59); + _utc_offset_minute = m; } diff --git a/src/lib/cinema.h b/src/lib/cinema.h index 7df83c767..70508f233 100644 --- a/src/lib/cinema.h +++ b/src/lib/cinema.h @@ -39,10 +39,11 @@ class Screen; class Cinema : public boost::enable_shared_from_this { public: - Cinema (std::string const & n, std::list const & e, int utc_offset) + Cinema (std::string const & n, std::list const & e, int utc_offset_hour, int utc_offset_minute) : name (n) , emails (e) - , _utc_offset (utc_offset) + , _utc_offset_hour (utc_offset_hour) + , _utc_offset_minute (utc_offset_minute) {} Cinema (cxml::ConstNodePtr); @@ -54,13 +55,20 @@ public: void add_screen (boost::shared_ptr); void remove_screen (boost::shared_ptr); - void set_utc_offset (int o); + void set_utc_offset_hour (int h); + void set_utc_offset_minute (int m); std::string name; std::list emails; - int utc_offset () const { - return _utc_offset; + + int utc_offset_hour () const { + return _utc_offset_hour; + } + + int utc_offset_minute () const { + return _utc_offset_minute; } + std::list > screens () const { return _screens; } @@ -70,5 +78,9 @@ private: /** Offset such that the equivalent time in UTC can be determined by subtracting the offset from the local time. */ - int _utc_offset; + int _utc_offset_hour; + /** Additional minutes to add to _utc_offset_hour if _utc_offset_hour is + positive, or to subtract if _utc_offset_hour is negative. + */ + int _utc_offset_minute; }; diff --git a/src/lib/film.cc b/src/lib/film.cc index e669ea4ae..1775f7c7f 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1208,8 +1208,8 @@ Film::make_kdms ( i->recipient.get(), i->trusted_devices, dcp, - dcp::LocalTime (from, i->cinema->utc_offset(), 0), - dcp::LocalTime (until, i->cinema->utc_offset(), 0), + dcp::LocalTime (from, i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()), + dcp::LocalTime (until, i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()), formulation ); diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc index 6c3103da2..3f156f4b9 100644 --- a/src/tools/dcpomatic_kdm.cc +++ b/src/tools/dcpomatic_kdm.cc @@ -271,8 +271,8 @@ private: /* Make an empty KDM */ dcp::DecryptedKDM kdm ( - dcp::LocalTime (_timing->from(), i->cinema->utc_offset(), 0), - dcp::LocalTime (_timing->until(), i->cinema->utc_offset(), 0), + dcp::LocalTime (_timing->from(), i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()), + dcp::LocalTime (_timing->until(), i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()), decrypted.annotation_text(), decrypted.content_title_text(), dcp::LocalTime().as_string() diff --git a/src/wx/cinema_dialog.cc b/src/wx/cinema_dialog.cc index c0b7b5242..b4663195f 100644 --- a/src/wx/cinema_dialog.cc +++ b/src/wx/cinema_dialog.cc @@ -37,7 +37,7 @@ column (string s) return s; } -CinemaDialog::CinemaDialog (wxWindow* parent, string title, string name, list emails, int utc_offset) +CinemaDialog::CinemaDialog (wxWindow* parent, string title, string name, list emails, int utc_offset_hour, int utc_offset_minute) : wxDialog (parent, wxID_ANY, std_to_wx (title)) { wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); @@ -77,15 +77,41 @@ CinemaDialog::CinemaDialog (wxWindow* parent, string title, string name, listAdd (buttons, wxSizerFlags().Expand().DoubleBorder()); } - for (int i = -11; i <= -1; ++i) { - _utc_offset->Append (wxString::Format (_("UTC%d"), i)); - } - _utc_offset->Append (_("UTC")); - for (int i = 1; i <= 12; ++i) { - _utc_offset->Append (wxString::Format (_("UTC+%d"), i)); + _offsets.push_back (Offset (_("UTC-11"), -11, 0)); + _offsets.push_back (Offset (_("UTC-10"), -10, 0)); + _offsets.push_back (Offset (_("UTC-9"), -9, 0)); + _offsets.push_back (Offset (_("UTC-8"), -8, 0)); + _offsets.push_back (Offset (_("UTC-7"), -7, 0)); + _offsets.push_back (Offset (_("UTC-6"), -6, 0)); + _offsets.push_back (Offset (_("UTC-5"), -5, 0)); + _offsets.push_back (Offset (_("UTC-4"), -4, 0)); + _offsets.push_back (Offset (_("UTC-3:30"), -3, 30)); + _offsets.push_back (Offset (_("UTC-3"), -3, 0)); + _offsets.push_back (Offset (_("UTC-2"), -2, 0)); + _offsets.push_back (Offset (_("UTC-1"), -1, 0)); + _offsets.push_back (Offset (_("UTC") , 0, 0)); + _offsets.push_back (Offset (_("UTC+1"), 1, 0)); + _offsets.push_back (Offset (_("UTC+2"), 2, 0)); + _offsets.push_back (Offset (_("UTC+3"), 3, 0)); + _offsets.push_back (Offset (_("UTC+4"), 4, 0)); + _offsets.push_back (Offset (_("UTC+5"), 5, 0)); + _offsets.push_back (Offset (_("UTC+6"), 6, 0)); + _offsets.push_back (Offset (_("UTC+7"), 7, 0)); + _offsets.push_back (Offset (_("UTC+8"), 8, 0)); + _offsets.push_back (Offset (_("UTC+9"), 9, 0)); + _offsets.push_back (Offset (_("UTC+10"), 10, 0)); + _offsets.push_back (Offset (_("UTC+11"), 11, 0)); + _offsets.push_back (Offset (_("UTC+12"), 12, 0)); + + size_t sel; + for (size_t i = 0; i < _offsets.size(); ++i) { + _utc_offset->Append (_offsets[i].name); + if (_offsets[i].hour == utc_offset_hour && _offsets[i].minute == utc_offset_minute) { + sel = i; + } } - _utc_offset->SetSelection (utc_offset + 11); + _utc_offset->SetSelection (sel); overall_sizer->Layout (); overall_sizer->SetSizeHints (this); @@ -118,7 +144,23 @@ CinemaDialog::emails () const } int -CinemaDialog::utc_offset () const +CinemaDialog::utc_offset_hour () const { - return _utc_offset->GetSelection() - 11; + size_t const sel = _utc_offset->GetSelection(); + if (sel < 0 || sel > _offsets.size()) { + return 0; + } + + return _offsets[sel].hour; +} + +int +CinemaDialog::utc_offset_minute () const +{ + size_t const sel = _utc_offset->GetSelection(); + if (sel < 0 || sel > _offsets.size()) { + return 0; + } + + return _offsets[sel].minute; } diff --git a/src/wx/cinema_dialog.h b/src/wx/cinema_dialog.h index a34935e51..2949d6c8c 100644 --- a/src/wx/cinema_dialog.h +++ b/src/wx/cinema_dialog.h @@ -27,11 +27,19 @@ class CinemaDialog : public wxDialog { public: - CinemaDialog (wxWindow *, std::string, std::string name = "", std::list emails = std::list (), int utc_offset = 0); + CinemaDialog ( + wxWindow *, + std::string, + std::string name = "", + std::list emails = std::list (), + int utc_offset_hour = 0, + int utc_offset_minute = 0 + ); std::string name () const; std::list emails () const; - int utc_offset () const; + int utc_offset_hour () const; + int utc_offset_minute () const; private: std::vector get_emails () const; @@ -41,4 +49,19 @@ private: EditableList* _email_list; std::vector _emails; wxChoice* _utc_offset; + + struct Offset + { + Offset (wxString n, int h, int m) + : name (n) + , hour (h) + , minute (m) + {} + + wxString name; + int hour; + int minute; + }; + + std::vector _offsets; }; diff --git a/src/wx/screens_panel.cc b/src/wx/screens_panel.cc index a75316d8c..ddb088c2f 100644 --- a/src/wx/screens_panel.cc +++ b/src/wx/screens_panel.cc @@ -149,7 +149,7 @@ ScreensPanel::add_cinema_clicked () { CinemaDialog* d = new CinemaDialog (this, "Add Cinema"); if (d->ShowModal () == wxID_OK) { - shared_ptr c (new Cinema (d->name(), d->emails(), d->utc_offset())); + shared_ptr c (new Cinema (d->name(), d->emails(), d->utc_offset_hour(), d->utc_offset_minute())); Config::instance()->add_cinema (c); add_cinema (c); } @@ -166,11 +166,12 @@ ScreensPanel::edit_cinema_clicked () pair > c = *_selected_cinemas.begin(); - CinemaDialog* d = new CinemaDialog (this, "Edit cinema", c.second->name, c.second->emails, c.second->utc_offset()); + CinemaDialog* d = new CinemaDialog (this, "Edit cinema", c.second->name, c.second->emails, c.second->utc_offset_hour(), c.second->utc_offset_minute()); if (d->ShowModal () == wxID_OK) { c.second->name = d->name (); c.second->emails = d->emails (); - c.second->set_utc_offset (d->utc_offset ()); + c.second->set_utc_offset_hour (d->utc_offset_hour ()); + c.second->set_utc_offset_minute (d->utc_offset_minute ()); _targets->SetItemText (c.first, std_to_wx (d->name())); Config::instance()->changed (); } -- 2.30.2