diff --git a/src/core/device.cpp b/src/core/device.cpp index 2db86df..b52177c 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -1,156 +1,155 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * Copyright (C) 2016-2018 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/device_p.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 qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName, Device::Type type) : QObject() , d(std::make_shared()) { 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_SmartStatus = type == Device::Disk_Device ? std::make_shared(deviceNode) : nullptr; d->m_Type = type; } /** Copy constructor for Device. * @param other the other Device. */ Device::Device(const Device& other) : QObject() { 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; + d->m_SmartStatus = other.d->m_SmartStatus; 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 d->m_PartitionTable; } bool Device::operator==(const Device& other) const { return d->m_DeviceNode == other.d->m_DeviceNode; } bool Device::operator!=(const Device& other) const { return !(other == *this); } 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; } diff --git a/src/core/device_p.h b/src/core/device_p.h index 5ddab62..0577fe3 100644 --- a/src/core/device_p.h +++ b/src/core/device_p.h @@ -1,35 +1,37 @@ /************************************************************************* * Copyright (C) 2018 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 +#include + 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; + std::shared_ptr m_SmartStatus; Device::Type m_Type; }; diff --git a/src/core/smartstatus.h b/src/core/smartstatus.h index d064b7e..88b410d 100644 --- a/src/core/smartstatus.h +++ b/src/core/smartstatus.h @@ -1,186 +1,186 @@ /************************************************************************* * Copyright (C) 2010 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 .* *************************************************************************/ #ifndef KPMCORE_SMARTSTATUS_H #define KPMCORE_SMARTSTATUS_H #include "util/libpartitionmanagerexport.h" #include "core/smartattribute.h" #include #include #include struct SkSmartAttributeParsedData; struct SkDisk; class LIBKPMCORE_EXPORT SmartStatus { public: enum Overall { Good, BadPast, BadSectors, BadNow, BadSectorsMany, Bad }; enum SelfTestStatus { Success, Aborted, Interrupted, Fatal, ErrorUnknown, ErrorEletrical, ErrorServo, ErrorRead, ErrorHandling, InProgress }; public: typedef QList Attributes; public: SmartStatus(const QString &device_path); public: void update(); const QString &devicePath() const { return m_DevicePath; } bool isValid() const { return m_InitSuccess; } bool status() const { return m_Status; } const QString &modelName() const { return m_ModelName; } const QString &serial() const { return m_Serial; } const QString &firmware() const { return m_Firmware; } quint64 temp() const { return m_Temp; } quint64 badSectors() const { return m_BadSectors; } quint64 powerCycles() const { return m_PowerCycles; } quint64 poweredOn() const { return m_PoweredOn; } const Attributes &attributes() const { return m_Attributes; } Overall overall() const { return m_Overall; } SelfTestStatus selfTestStatus() const { return m_SelfTestStatus; } void addAttributes(QList attr); static QString tempToString(quint64 mkelvin); static QString overallAssessmentToString(Overall o); static QString selfTestStatusToString(SmartStatus::SelfTestStatus s); -protected: +private: void setStatus(bool s) { m_Status = s; } void setModelName(const QString &name) { m_ModelName = name; } void setSerial(const QString &s) { m_Serial = s; } void setFirmware(const QString &f) { m_Firmware = f; } void setTemp(quint64 t) { m_Temp = t; } void setInitSuccess(bool b) { m_InitSuccess = b; } void setBadSectors(quint64 s) { m_BadSectors = s; } void setPowerCycles(quint64 p) { m_PowerCycles = p; } void setPoweredOn(quint64 t) { m_PoweredOn = t; } void setOverall(Overall o) { m_Overall = o; } void setSelfTestStatus(SelfTestStatus s) { m_SelfTestStatus = s; } private: const QString m_DevicePath; bool m_InitSuccess; bool m_Status; QString m_ModelName; QString m_Serial; QString m_Firmware; Overall m_Overall; SelfTestStatus m_SelfTestStatus; quint64 m_Temp; quint64 m_BadSectors; quint64 m_PowerCycles; quint64 m_PoweredOn; Attributes m_Attributes; }; #endif