Cleanup: remove unused include.
[dcpomatic.git] / src / lib / cinema.cc
1 /*
2     Copyright (C) 2013-2021 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
22 #include "cinema.h"
23 #include "screen.h"
24 #include "dcpomatic_assert.h"
25 #include <libcxml/cxml.h>
26 #include <dcp/raw_convert.h>
27 #include <libxml++/libxml++.h>
28
29
30 using std::list;
31 using std::string;
32 using std::shared_ptr;
33 using std::make_shared;
34 using dcp::raw_convert;
35 using dcpomatic::Screen;
36
37
38 Cinema::Cinema (cxml::ConstNodePtr node)
39         : name (node->string_child ("Name"))
40         , notes (node->optional_string_child("Notes").get_value_or(""))
41 {
42         for (auto i: node->node_children("Email")) {
43                 emails.push_back (i->content ());
44         }
45
46         if (node->optional_number_child<int>("UTCOffset")) {
47                 _utc_offset_hour = node->number_child<int>("UTCOffset");
48         } else {
49                 _utc_offset_hour = node->optional_number_child<int>("UTCOffsetHour").get_value_or (0);
50         }
51
52         _utc_offset_minute = node->optional_number_child<int>("UTCOffsetMinute").get_value_or (0);
53 }
54
55 /* This is necessary so that we can use shared_from_this in add_screen (which cannot be done from
56    a constructor)
57 */
58 void
59 Cinema::read_screens (cxml::ConstNodePtr node)
60 {
61         for (auto i: node->node_children("Screen")) {
62                 add_screen (make_shared<Screen>(i));
63         }
64 }
65
66 void
67 Cinema::as_xml (xmlpp::Element* parent) const
68 {
69         parent->add_child("Name")->add_child_text (name);
70
71         for (auto i: emails) {
72                 parent->add_child("Email")->add_child_text (i);
73         }
74
75         parent->add_child("Notes")->add_child_text (notes);
76
77         parent->add_child("UTCOffsetHour")->add_child_text (raw_convert<string> (_utc_offset_hour));
78         parent->add_child("UTCOffsetMinute")->add_child_text (raw_convert<string> (_utc_offset_minute));
79
80         for (auto i: _screens) {
81                 i->as_xml (parent->add_child ("Screen"));
82         }
83 }
84
85 void
86 Cinema::add_screen (shared_ptr<Screen> s)
87 {
88         s->cinema = shared_from_this ();
89         _screens.push_back (s);
90 }
91
92 void
93 Cinema::remove_screen (shared_ptr<Screen> s)
94 {
95         _screens.remove (s);
96 }
97
98 void
99 Cinema::set_utc_offset_hour (int h)
100 {
101         DCPOMATIC_ASSERT (h >= -11 && h <= 12);
102         _utc_offset_hour = h;
103 }
104
105 void
106 Cinema::set_utc_offset_minute (int m)
107 {
108         DCPOMATIC_ASSERT (m >= 0 && m <= 59);
109         _utc_offset_minute = m;
110 }