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"
25 #include <dcp/raw_convert.h>
26 #include <boost/foreach.hpp>
27 DCPOMATIC_DISABLE_WARNINGS
28 #include <libxml++/libxml++.h>
29 DCPOMATIC_ENABLE_WARNINGS
36 Drive::Drive (string xml)
39 doc.read_string (xml);
40 _device = doc.string_child("Device");
41 BOOST_FOREACH (cxml::ConstNodePtr i, doc.node_children("MountPoint")) {
42 _mount_points.push_back (i->content());
44 _size = doc.number_child<uint64_t>("Size");
45 _vendor = doc.optional_string_child("Vendor");
46 _model = doc.optional_string_child("Model");
51 Drive::as_xml () const
54 xmlpp::Element* root = doc.create_root_node ("Drive");
55 root->add_child("Device")->add_child_text(_device);
56 BOOST_FOREACH (boost::filesystem::path i, _mount_points) {
57 root->add_child("MountPoint")->add_child_text(i.string());
59 root->add_child("Size")->add_child_text(dcp::raw_convert<string>(_size));
61 root->add_child("Vendor")->add_child_text(*_vendor);
64 root->add_child("Model")->add_child_text(*_model);
67 return doc.write_to_string("UTF-8");
72 Drive::description () const
75 snprintf(gb, 64, "%.1f", _size / 1000000000.0);
82 if (name.size() > 0) {
83 name += " " + *_model;
88 if (name.size() == 0) {
92 return String::compose(_("%1 (%2 GB) [%3]"), name, gb, _device);
96 Drive::log_summary () const
99 BOOST_FOREACH (boost::filesystem::path i, _mount_points) {
100 mp += i.string() + ",";
105 mp = mp.substr (0, mp.length() - 1);
108 return String::compose(
109 "Device %1 mounted on %2 size %3 vendor %4 model %5",
110 _device, mp, _size, _vendor.get_value_or("[none]"), _model.get_value_or("[none]")