d-pointerize Device class.
This commit is contained in:
parent
2e5f0fbcb2
commit
a71be700ba
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* Copyright (C) 2016-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -17,6 +17,7 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "core/device.h"
|
||||
#include "core/device_p.h"
|
||||
#include "core/partitiontable.h"
|
||||
#include "core/smartstatus.h"
|
||||
|
||||
|
@ -30,20 +31,21 @@
|
|||
*/
|
||||
Device::Device(const QString& name,
|
||||
const QString& deviceNode,
|
||||
const qint64 logicalSize,
|
||||
const qint64 totalLogical,
|
||||
const qint64 logicalSectorSize,
|
||||
const qint64 totalLogicalSectors,
|
||||
const QString& iconName,
|
||||
Device::Type type)
|
||||
: QObject()
|
||||
, m_Name(name.length() > 0 ? name : i18n("Unknown Device"))
|
||||
, m_DeviceNode(deviceNode)
|
||||
, m_LogicalSize(logicalSize)
|
||||
, m_TotalLogical(totalLogical)
|
||||
, m_PartitionTable(nullptr)
|
||||
, m_IconName(iconName.isEmpty() ? QStringLiteral("drive-harddisk") : iconName)
|
||||
, m_SmartStatus(type == Device::Disk_Device ? new SmartStatus(deviceNode) : nullptr)
|
||||
, m_Type(type)
|
||||
, d(std::make_shared<DevicePrivate>())
|
||||
{
|
||||
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;
|
||||
d->m_SmartStatus = type == Device::Disk_Device ? new SmartStatus(deviceNode) : nullptr;
|
||||
d->m_Type = type;
|
||||
}
|
||||
|
||||
/** Copy constructor for Device.
|
||||
|
@ -51,30 +53,31 @@ Device::Device(const QString& name,
|
|||
*/
|
||||
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);
|
||||
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;
|
||||
|
||||
if (other.d->m_PartitionTable)
|
||||
d->m_PartitionTable = new PartitionTable(*other.d->m_PartitionTable);
|
||||
if (other.d->m_SmartStatus)
|
||||
d->m_SmartStatus = new SmartStatus(*other.d->m_SmartStatus);
|
||||
}
|
||||
|
||||
/** Destructs a Device. */
|
||||
Device::~Device()
|
||||
{
|
||||
delete m_PartitionTable;
|
||||
delete d->m_PartitionTable;
|
||||
}
|
||||
|
||||
bool Device::operator==(const Device& other) const
|
||||
{
|
||||
return m_DeviceNode == other.m_DeviceNode;
|
||||
return d->m_DeviceNode == other.d->m_DeviceNode;
|
||||
}
|
||||
|
||||
bool Device::operator!=(const Device& other) const
|
||||
|
@ -86,3 +89,68 @@ QString Device::prettyName() const
|
|||
{
|
||||
return xi18nc("@item:inlistbox Device name – Capacity (device node)", "%1 – %2 (%3)", name(), Capacity::formatByteSize(capacity()), deviceNode());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -23,10 +23,13 @@
|
|||
#include <QString>
|
||||
#include <QObject>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class PartitionTable;
|
||||
class CreatePartitionTableOperation;
|
||||
class CoreBackend;
|
||||
class SmartStatus;
|
||||
struct DevicePrivate;
|
||||
|
||||
/** A device description.
|
||||
|
||||
|
@ -55,7 +58,7 @@ public:
|
|||
};
|
||||
|
||||
protected:
|
||||
explicit Device(const QString& name, const QString& deviceNode, const qint64 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Disk_Device);
|
||||
explicit Device(const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName = QString(), Device::Type type = Device::Disk_Device);
|
||||
|
||||
public:
|
||||
explicit Device(const Device& other);
|
||||
|
@ -65,78 +68,49 @@ public:
|
|||
virtual bool operator==(const Device& other) const;
|
||||
virtual bool operator!=(const Device& other) const;
|
||||
|
||||
virtual QString& name() {
|
||||
return m_Name; /**< @return the Device's name, usually some manufacturer string */
|
||||
}
|
||||
/**< @return the Device's name, usually some manufacturer string */
|
||||
virtual QString& name();
|
||||
virtual const QString& name() const;
|
||||
|
||||
virtual const QString& name() const {
|
||||
return m_Name; /**< @return the Device's name, usually some manufacturer string */
|
||||
}
|
||||
/**< @return the Device's node, for example "/dev/sda" */
|
||||
virtual const QString& deviceNode() const;
|
||||
|
||||
virtual const QString& deviceNode() const {
|
||||
return m_DeviceNode; /**< @return the Device's node, for example "/dev/sda" */
|
||||
}
|
||||
/**< @return the logical sector size the Device uses (would be extent size for e.g. LVM devices) */
|
||||
virtual qint64 logicalSize() const;
|
||||
|
||||
virtual PartitionTable* partitionTable() {
|
||||
return m_PartitionTable; /**< @return the Device's PartitionTable */
|
||||
}
|
||||
/**< @return the total number of logical sectors on the device */
|
||||
virtual qint64 totalLogical() const;
|
||||
|
||||
virtual const PartitionTable* partitionTable() const {
|
||||
return m_PartitionTable; /**< @return the Device's PartitionTable */
|
||||
}
|
||||
|
||||
virtual qint64 capacity() const { /**< @return the Device's capacity in bytes */
|
||||
return logicalSize() * totalLogical();
|
||||
}
|
||||
|
||||
virtual void setIconName(const QString& name) {
|
||||
m_IconName = name;
|
||||
}
|
||||
|
||||
virtual const QString& iconName() const {
|
||||
return m_IconName; /**< @return suggested icon name for this Device */
|
||||
}
|
||||
|
||||
virtual SmartStatus& smartStatus() {
|
||||
return *m_SmartStatus;
|
||||
}
|
||||
|
||||
virtual const SmartStatus& smartStatus() const {
|
||||
return *m_SmartStatus;
|
||||
}
|
||||
/**< @return the Device's PartitionTable */
|
||||
virtual PartitionTable* partitionTable();
|
||||
virtual const PartitionTable* partitionTable() const;
|
||||
|
||||
/**
|
||||
* Change the description of the partition table for different one.
|
||||
* The device itself is not changed; use CreatePartitionTableOperation
|
||||
* for that. The Device instance becomes the owner of @p ptable .
|
||||
*/
|
||||
virtual void setPartitionTable(PartitionTable* ptable) {
|
||||
m_PartitionTable = ptable;
|
||||
virtual void setPartitionTable(PartitionTable* ptable);
|
||||
|
||||
virtual qint64 capacity() const { /**< @return the Device's capacity in bytes */
|
||||
return logicalSize() * totalLogical();
|
||||
}
|
||||
|
||||
virtual qint64 logicalSize() const {
|
||||
return m_LogicalSize;
|
||||
}
|
||||
/**< @return suggested icon name for this Device */
|
||||
virtual const QString& iconName() const;
|
||||
|
||||
virtual qint64 totalLogical() const {
|
||||
return m_TotalLogical;
|
||||
}
|
||||
/**< @param name set the new Icon for this Device */
|
||||
virtual void setIconName(const QString& name);
|
||||
|
||||
virtual Device::Type type() const {
|
||||
return m_Type;
|
||||
}
|
||||
virtual SmartStatus& smartStatus();
|
||||
virtual const SmartStatus& smartStatus() const;
|
||||
|
||||
virtual Device::Type type() const;
|
||||
|
||||
virtual QString prettyName() const;
|
||||
|
||||
protected:
|
||||
QString m_Name;
|
||||
QString m_DeviceNode;
|
||||
qint64 m_LogicalSize;
|
||||
qint64 m_TotalLogical;
|
||||
PartitionTable* m_PartitionTable;
|
||||
QString m_IconName;
|
||||
SmartStatus* m_SmartStatus;
|
||||
Device::Type m_Type;
|
||||
std::shared_ptr<DevicePrivate> d;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* 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 <QString>
|
||||
|
||||
class PartitionTable;
|
||||
class SmartStatus;
|
||||
|
||||
struct DevicePrivate
|
||||
{
|
||||
QString m_Name;
|
||||
QString m_DeviceNode;
|
||||
qint64 m_LogicalSectorSize;
|
||||
qint64 m_TotalLogical;
|
||||
PartitionTable* m_PartitionTable;
|
||||
QString m_IconName;
|
||||
SmartStatus* m_SmartStatus;
|
||||
Device::Type m_Type;
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
|
||||
* Copyright (C) 2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -15,6 +16,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#include "core/device_p.h"
|
||||
#include "core/volumemanagerdevice.h"
|
||||
|
||||
/** Constructs an abstract Volume Manager Device with an empty PartitionTable.
|
||||
|
@ -34,3 +36,9 @@ QString VolumeManagerDevice::prettyDeviceNodeList() const
|
|||
{
|
||||
return deviceNodes().join(QStringLiteral(", "));
|
||||
}
|
||||
|
||||
void VolumeManagerDevice::setTotalLogical(qint64 n)
|
||||
{
|
||||
Q_ASSERT(n > 0);
|
||||
d->m_TotalLogical = n;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(KPMCORE_VOLUMEMANAGERDEVICE_H)
|
||||
|
||||
#ifndef KPMCORE_VOLUMEMANAGERDEVICE_H
|
||||
#define KPMCORE_VOLUMEMANAGERDEVICE_H
|
||||
|
||||
#include "util/libpartitionmanagerexport.h"
|
||||
|
@ -90,10 +89,7 @@ public:
|
|||
*
|
||||
* @param n Number of sectors.
|
||||
*/
|
||||
void setTotalLogical(qint64 n) {
|
||||
Q_ASSERT(n > 0);
|
||||
m_TotalLogical = n;
|
||||
}
|
||||
void setTotalLogical(qint64 n);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue