2 Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
24 #include "dcpomatic_assert.h"
25 #include <libcxml/cxml.h>
26 #include <dcp/raw_convert.h>
27 #include <libxml++/libxml++.h>
33 using std::shared_ptr;
34 using std::make_shared;
35 using dcp::raw_convert;
36 using dcpomatic::Screen;
39 Cinema::Cinema (cxml::ConstNodePtr node)
40 : name (node->string_child ("Name"))
41 , notes (node->optional_string_child("Notes").get_value_or(""))
43 for (auto i: node->node_children("Email")) {
44 emails.push_back (i->content ());
47 if (node->optional_number_child<int>("UTCOffset")) {
48 _utc_offset_hour = node->number_child<int>("UTCOffset");
50 _utc_offset_hour = node->optional_number_child<int>("UTCOffsetHour").get_value_or (0);
53 _utc_offset_minute = node->optional_number_child<int>("UTCOffsetMinute").get_value_or (0);
56 /* This is necessary so that we can use shared_from_this in add_screen (which cannot be done from
60 Cinema::read_screens (cxml::ConstNodePtr node)
62 for (auto i: node->node_children("Screen")) {
63 add_screen (make_shared<Screen>(i));
68 Cinema::as_xml (xmlpp::Element* parent) const
70 parent->add_child("Name")->add_child_text (name);
72 for (auto i: emails) {
73 parent->add_child("Email")->add_child_text (i);
76 parent->add_child("Notes")->add_child_text (notes);
78 parent->add_child("UTCOffsetHour")->add_child_text (raw_convert<string> (_utc_offset_hour));
79 parent->add_child("UTCOffsetMinute")->add_child_text (raw_convert<string> (_utc_offset_minute));
81 for (auto i: _screens) {
82 i->as_xml (parent->add_child ("Screen"));
87 Cinema::add_screen (shared_ptr<Screen> s)
89 s->cinema = shared_from_this ();
90 _screens.push_back (s);
94 Cinema::remove_screen (shared_ptr<Screen> s)
100 Cinema::set_utc_offset_hour (int h)
102 DCPOMATIC_ASSERT (h >= -11 && h <= 12);
103 _utc_offset_hour = h;
107 Cinema::set_utc_offset_minute (int m)
109 DCPOMATIC_ASSERT (m >= 0 && m <= 59);
110 _utc_offset_minute = m;