2015-06-04 01:29:22 +01:00
|
|
|
|
/*************************************************************************
|
|
|
|
|
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
2016-03-02 19:00:31 +00:00
|
|
|
|
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
2015-06-04 01:29:22 +01:00
|
|
|
|
* *
|
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "core/device.h"
|
|
|
|
|
#include "core/partitiontable.h"
|
|
|
|
|
#include "core/smartstatus.h"
|
|
|
|
|
|
|
|
|
|
#include "util/capacity.h"
|
|
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
|
|
/** Constructs a Device with an empty PartitionTable.
|
2015-07-13 15:16:36 +01:00
|
|
|
|
@param name the Device's name, usually some string defined by the manufacturer
|
2016-08-14 18:13:13 +01:00
|
|
|
|
@param deviceNode the Device's node, for example "/dev/sda"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
*/
|
2016-05-31 19:28:31 +01:00
|
|
|
|
Device::Device(const QString& name,
|
2016-08-14 18:13:13 +01:00
|
|
|
|
const QString& deviceNode,
|
2017-09-11 13:41:03 +01:00
|
|
|
|
const qint64 logicalSize,
|
2016-05-31 19:28:31 +01:00
|
|
|
|
const qint64 totalLogical,
|
2016-08-14 18:13:13 +01:00
|
|
|
|
const QString& iconName,
|
2016-05-31 19:28:31 +01:00
|
|
|
|
Device::Type type)
|
|
|
|
|
: QObject()
|
|
|
|
|
, m_Name(name.length() > 0 ? name : i18n("Unknown Device"))
|
2016-08-14 18:13:13 +01:00
|
|
|
|
, m_DeviceNode(deviceNode)
|
2016-05-31 19:28:31 +01:00
|
|
|
|
, m_LogicalSize(logicalSize)
|
|
|
|
|
, m_TotalLogical(totalLogical)
|
|
|
|
|
, m_PartitionTable(nullptr)
|
2016-08-14 18:13:13 +01:00
|
|
|
|
, m_IconName(iconName.isEmpty() ? QStringLiteral("drive-harddisk") : iconName)
|
|
|
|
|
, m_SmartStatus(type == Device::Disk_Device ? new SmartStatus(deviceNode) : nullptr)
|
2016-05-31 19:28:31 +01:00
|
|
|
|
, m_Type(type)
|
2015-06-04 01:29:22 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-07 16:35:35 +01:00
|
|
|
|
/** Copy constructor for Device.
|
|
|
|
|
* @param other the other Device.
|
|
|
|
|
*/
|
|
|
|
|
Device::Device(const Device& other)
|
|
|
|
|
: QObject()
|
|
|
|
|
, m_Name(other.m_Name)
|
|
|
|
|
, m_DeviceNode(other.m_DeviceNode)
|
|
|
|
|
, m_LogicalSize(other.m_LogicalSize)
|
|
|
|
|
, m_TotalLogical(other.m_TotalLogical)
|
|
|
|
|
, m_PartitionTable(nullptr)
|
|
|
|
|
, m_IconName(other.m_IconName)
|
|
|
|
|
, m_SmartStatus(nullptr)
|
|
|
|
|
, m_Type(other.m_Type)
|
|
|
|
|
{
|
|
|
|
|
if (other.m_PartitionTable)
|
|
|
|
|
m_PartitionTable = new PartitionTable(*other.m_PartitionTable);
|
|
|
|
|
if (other.m_SmartStatus)
|
|
|
|
|
m_SmartStatus = new SmartStatus(*other.m_SmartStatus);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
|
/** Destructs a Device. */
|
|
|
|
|
Device::~Device()
|
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
|
delete m_PartitionTable;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Device::operator==(const Device& other) const
|
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
|
return m_DeviceNode == other.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
|
|
|
|
}
|