2020-09-20 20:33:16 +01:00
|
|
|
|
/*
|
|
|
|
|
SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
|
|
|
|
|
SPDX-FileCopyrightText: 2012-2018 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
|
SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
|
|
|
|
|
SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
|
|
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
*/
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
|
|
#include "core/device.h"
|
2018-04-08 14:45:59 +01:00
|
|
|
|
#include "core/device_p.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
#include "core/partitiontable.h"
|
|
|
|
|
#include "core/smartstatus.h"
|
|
|
|
|
|
|
|
|
|
#include "util/capacity.h"
|
|
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
2018-04-09 00:34:45 +01:00
|
|
|
|
/** Constructs a Device with an empty PartitionTable.
|
|
|
|
|
@param name the Device's name, usually some string defined by the manufacturer
|
|
|
|
|
@param deviceNode the Device's node, for example "/dev/sda"
|
|
|
|
|
*/
|
|
|
|
|
Device::Device(std::shared_ptr<DevicePrivate> d_ptr,
|
|
|
|
|
const QString& name,
|
|
|
|
|
const QString& deviceNode,
|
|
|
|
|
const qint64 logicalSectorSize,
|
|
|
|
|
const qint64 totalLogicalSectors,
|
|
|
|
|
const QString& iconName,
|
|
|
|
|
Device::Type type)
|
|
|
|
|
: QObject()
|
|
|
|
|
, d(d_ptr)
|
|
|
|
|
{
|
|
|
|
|
d->m_Name = name.length() > 0 ? name : i18n("Unknown Device");
|
|
|
|
|
d->m_DeviceNode = deviceNode;
|
|
|
|
|
d->m_LogicalSectorSize = logicalSectorSize;
|
|
|
|
|
d->m_TotalLogical = totalLogicalSectors;
|
|
|
|
|
d->m_PartitionTable = nullptr;
|
|
|
|
|
d->m_IconName = iconName.isEmpty() ? QStringLiteral("drive-harddisk") : iconName;
|
2018-04-09 02:57:45 +01:00
|
|
|
|
d->m_SmartStatus = type == Device::Type::Disk_Device ? std::make_shared<SmartStatus>(deviceNode) : nullptr;
|
2018-04-09 00:34:45 +01:00
|
|
|
|
d->m_Type = type;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-07 16:35:35 +01:00
|
|
|
|
/** Copy constructor for Device.
|
|
|
|
|
* @param other the other Device.
|
|
|
|
|
*/
|
|
|
|
|
Device::Device(const Device& other)
|
|
|
|
|
: QObject()
|
2018-04-11 01:52:46 +01:00
|
|
|
|
, d(std::make_shared<DevicePrivate>())
|
2016-09-07 16:35:35 +01:00
|
|
|
|
{
|
2018-04-08 14:45:59 +01:00
|
|
|
|
d->m_Name = other.d->m_Name;
|
|
|
|
|
d->m_DeviceNode = other.d->m_DeviceNode;
|
|
|
|
|
d->m_LogicalSectorSize = other.d->m_LogicalSectorSize;
|
|
|
|
|
d->m_TotalLogical = other.d->m_TotalLogical;
|
|
|
|
|
d->m_PartitionTable = nullptr;
|
|
|
|
|
d->m_IconName = other.d->m_IconName;
|
|
|
|
|
d->m_SmartStatus = nullptr;
|
|
|
|
|
d->m_Type = other.d->m_Type;
|
2018-04-08 14:58:02 +01:00
|
|
|
|
d->m_SmartStatus = other.d->m_SmartStatus;
|
2018-04-08 14:45:59 +01:00
|
|
|
|
|
|
|
|
|
if (other.d->m_PartitionTable)
|
|
|
|
|
d->m_PartitionTable = new PartitionTable(*other.d->m_PartitionTable);
|
2016-09-07 16:35:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
|
/** Destructs a Device. */
|
|
|
|
|
Device::~Device()
|
|
|
|
|
{
|
2018-04-08 14:45:59 +01:00
|
|
|
|
delete d->m_PartitionTable;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Device::operator==(const Device& other) const
|
|
|
|
|
{
|
2018-04-08 14:45:59 +01:00
|
|
|
|
return d->m_DeviceNode == other.d->m_DeviceNode;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Device::operator!=(const Device& other) const
|
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
|
return !(other == *this);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Device::prettyName() const
|
|
|
|
|
{
|
2016-09-18 11:55:35 +01:00
|
|
|
|
return xi18nc("@item:inlistbox Device name – Capacity (device node)", "%1 – %2 (%3)", name(), Capacity::formatByteSize(capacity()), deviceNode());
|
2015-06-04 01:29:22 +01:00
|
|
|
|
}
|
2018-04-08 14:45:59 +01:00
|
|
|
|
|
|
|
|
|
QString& Device::name()
|
|
|
|
|
{
|
|
|
|
|
return d->m_Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString& Device::name() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString& Device::deviceNode() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_DeviceNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 Device::logicalSize() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_LogicalSectorSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 Device::totalLogical() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_TotalLogical;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PartitionTable* Device::partitionTable()
|
|
|
|
|
{
|
|
|
|
|
return d->m_PartitionTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PartitionTable* Device::partitionTable() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_PartitionTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Device::setPartitionTable(PartitionTable* ptable)
|
|
|
|
|
{
|
|
|
|
|
d->m_PartitionTable = ptable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString& Device::iconName() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_IconName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Device::setIconName(const QString& name)
|
|
|
|
|
{
|
|
|
|
|
d->m_IconName = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SmartStatus& Device::smartStatus()
|
|
|
|
|
{
|
|
|
|
|
return *(d->m_SmartStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SmartStatus& Device::smartStatus() const
|
|
|
|
|
{
|
|
|
|
|
return *(d->m_SmartStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Device::Type Device::type() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_Type;
|
|
|
|
|
}
|