diff --git a/src/core/device.cpp b/src/core/device.cpp index 7b4904e..ef6c2c1 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -1,68 +1,88 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * Copyright (C) 2016 by Andrius Štikonas * * * * 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 .* *************************************************************************/ #include "core/device.h" #include "core/partitiontable.h" #include "core/smartstatus.h" #include "util/capacity.h" #include /** 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(const QString& name, const QString& deviceNode, const qint32 logicalSize, const qint64 totalLogical, 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) { } +/** 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); +} + /** Destructs a Device. */ Device::~Device() { delete m_PartitionTable; } bool Device::operator==(const Device& other) const { return m_DeviceNode == other.m_DeviceNode; } bool Device::operator!=(const Device& other) const { return !(other == *this); } QString Device::prettyName() const { return i18nc("Device name – Capacity (device node)", "%1 – %2 (%3)", name(), Capacity::formatByteSize(capacity()), deviceNode()); } diff --git a/src/core/device.h b/src/core/device.h index e4453c7..03a57f8 100644 --- a/src/core/device.h +++ b/src/core/device.h @@ -1,126 +1,127 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * 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 .* *************************************************************************/ #if !defined(DEVICE__H) #define DEVICE__H #include "util/libpartitionmanagerexport.h" #include #include class PartitionTable; class CreatePartitionTableOperation; class CoreBackend; class SmartStatus; /** A abstract device interface. Represents a device like /dev/sda. Devices are the outermost entity; they contain a PartitionTable that itself contains Partitions. @see PartitionTable, Partition @author Volker Lanz */ class LIBKPMCORE_EXPORT Device : public QObject { - Q_DISABLE_COPY(Device) + Device &operator=(const Device &) = delete; friend class CreatePartitionTableOperation; friend class CoreBackend; public: enum Type { Disk_Device = 0, LVM_Device = 1, /* VG */ RAID_Device = 2, /* software RAID device */ Unknown_Device = 4 }; protected: - Device(const QString& name, const QString& deviceNode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Disk_Device); + explicit Device(const QString& name, const QString& deviceNode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Disk_Device); + explicit Device(const Device& other); public: virtual ~Device(); public: virtual bool operator==(const Device& other) const; virtual bool operator!=(const Device& other) const; virtual const QString& name() const { return m_Name; /**< @return the Device's name, usually some manufacturer string */ } virtual const QString& deviceNode() const { return m_DeviceNode; /**< @return the Device's node, for example "/dev/sda" */ } virtual PartitionTable* partitionTable() { return m_PartitionTable; /**< @return the Device's PartitionTable */ } 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; } virtual void setPartitionTable(PartitionTable* ptable) { m_PartitionTable = ptable; } virtual qint32 logicalSize() const { return m_LogicalSize; } virtual qint64 totalLogical() const { return m_TotalLogical; } virtual Device::Type type() const { return m_Type; } virtual QString prettyName() const; protected: QString m_Name; QString m_DeviceNode; qint32 m_LogicalSize; qint64 m_TotalLogical; PartitionTable* m_PartitionTable; QString m_IconName; SmartStatus* m_SmartStatus; Device::Type m_Type; }; #endif