2 Copyright (C) 2012-2020 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/>.
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>
33 Drive::Drive (string xml)
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());
41 _size = doc.number_child<uint64_t>("Size");
42 _vendor = doc.optional_string_child("Vendor");
43 _model = doc.optional_string_child("Model");
48 Drive::as_xml () const
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());
56 root->add_child("Size")->add_child_text(dcp::raw_convert<string>(_size));
58 root->add_child("Vendor")->add_child_text(*_vendor);
61 root->add_child("Model")->add_child_text(*_model);
64 return doc.write_to_string("UTF-8");
69 Drive::description () const
72 snprintf(gb, 64, "%.1f", _size / 1000000000.0);
79 if (name.size() > 0) {
80 name += " " + *_model;
85 if (name.size() == 0) {
89 return String::compose(_("%1 (%2 GB) [%3]"), name, gb, _device);
93 Drive::log_summary () const
96 BOOST_FOREACH (boost::filesystem::path i, _mount_points) {
97 mp += i.string() + ",";
102 mp = mp.substr (0, mp.length() - 1);
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]")