Rename TYPE_DEBUG_PLAYER to TYPE_DEBUG_VIDEO_VIEW.
[dcpomatic.git] / src / lib / cross_common.cc
1 /*
2     Copyright (C) 2012-2020 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 "cross.h"
22 #include "compose.hpp"
23 #include "dcpomatic_log.h"
24 #include <dcp/raw_convert.h>
25 #include <boost/foreach.hpp>
26 #include <libxml++/libxml++.h>
27 #include <iostream>
28
29 #include "i18n.h"
30
31 using std::string;
32
33 Drive::Drive (string xml)
34 {
35         cxml::Document doc;
36         doc.read_string (xml);
37         _device = doc.string_child("Device");
38         BOOST_FOREACH (cxml::ConstNodePtr i, doc.node_children("MountPoint")) {
39                 _mount_points.push_back (i->content());
40         }
41         _size = doc.number_child<uint64_t>("Size");
42         _vendor = doc.optional_string_child("Vendor");
43         _model = doc.optional_string_child("Model");
44 }
45
46
47 string
48 Drive::as_xml () const
49 {
50         xmlpp::Document doc;
51         xmlpp::Element* root = doc.create_root_node ("Drive");
52         root->add_child("Device")->add_child_text(_device);
53         BOOST_FOREACH (boost::filesystem::path i, _mount_points) {
54                 root->add_child("MountPoint")->add_child_text(i.string());
55         }
56         root->add_child("Size")->add_child_text(dcp::raw_convert<string>(_size));
57         if (_vendor) {
58                 root->add_child("Vendor")->add_child_text(*_vendor);
59         }
60         if (_model) {
61                 root->add_child("Model")->add_child_text(*_model);
62         }
63
64         return doc.write_to_string("UTF-8");
65 }
66
67
68 string
69 Drive::description () const
70 {
71         char gb[64];
72         snprintf(gb, 64, "%.1f", _size / 1000000000.0);
73
74         string name;
75         if (_vendor) {
76                 name += *_vendor;
77         }
78         if (_model) {
79                 if (name.size() > 0) {
80                         name += " " + *_model;
81                 } else {
82                         name = *_model;
83                 }
84         }
85         if (name.size() == 0) {
86                 name = _("Unknown");
87         }
88
89         return String::compose(_("%1 (%2 GB) [%3]"), name, gb, _device);
90 }
91
92 string
93 Drive::log_summary () const
94 {
95         string mp;
96         BOOST_FOREACH (boost::filesystem::path i, _mount_points) {
97                 mp += i.string() + ",";
98         }
99         if (mp.empty()) {
100                 mp = "[none]";
101         } else {
102                 mp = mp.substr (0, mp.length() - 1);
103         }
104
105         return String::compose(
106                 "Device %1 mounted on %2 size %3 vendor %4 model %5",
107                 _device, mp, _size, _vendor.get_value_or("[none]"), _model.get_value_or("[none]")
108                         );
109 }