From 3ccd04e675cdda72c5f15aae2a948e58b251049a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Mon, 9 Apr 2018 02:57:45 +0100 Subject: [PATCH] Switch Device::Type enum to enum class. --- src/core/device.cpp | 2 +- src/core/device.h | 12 ++++++------ src/core/diskdevice.cpp | 2 +- src/core/lvmdevice.cpp | 2 +- src/core/operationstack.cpp | 2 +- src/core/partitiontable.cpp | 12 ++++++------ src/core/volumemanagerdevice.h | 2 +- src/jobs/createfilesystemjob.cpp | 4 ++-- src/jobs/createpartitionjob.cpp | 4 ++-- src/jobs/createpartitiontablejob.cpp | 4 ++-- src/jobs/deactivatelogicalvolumejob.cpp | 2 +- src/jobs/deactivatevolumegroupjob.cpp | 2 +- src/jobs/deletefilesystemjob.cpp | 2 +- src/jobs/deletepartitionjob.cpp | 4 ++-- src/jobs/removevolumegroupjob.cpp | 2 +- src/jobs/setpartgeometryjob.cpp | 4 ++-- src/ops/createpartitiontableoperation.cpp | 2 +- src/ops/deactivatevolumegroupoperation.cpp | 2 +- src/ops/removevolumegroupoperation.cpp | 2 +- 19 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/core/device.cpp b/src/core/device.cpp index cc1d29d..fce2f05 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -45,7 +45,7 @@ Device::Device(std::shared_ptr d_ptr, d->m_TotalLogical = totalLogicalSectors; d->m_PartitionTable = nullptr; d->m_IconName = iconName.isEmpty() ? QStringLiteral("drive-harddisk") : iconName; - d->m_SmartStatus = type == Device::Disk_Device ? std::make_shared(deviceNode) : nullptr; + d->m_SmartStatus = type == Device::Type::Disk_Device ? std::make_shared(deviceNode) : nullptr; d->m_Type = type; } diff --git a/src/core/device.h b/src/core/device.h index f99e642..5425539 100644 --- a/src/core/device.h +++ b/src/core/device.h @@ -50,15 +50,15 @@ class LIBKPMCORE_EXPORT Device : public QObject friend class CoreBackend; public: - enum Type { - Disk_Device = 0, - LVM_Device = 1, /* VG */ - RAID_Device = 2, /* software RAID device */ - Unknown_Device = 4 + enum class Type { + Unknown_Device, + Disk_Device, + LVM_Device, /* VG */ + RAID_Device, /* software RAID device */ }; protected: - explicit Device(std::shared_ptr d_ptr, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName = QString(), Device::Type type = Device::Disk_Device); + explicit Device(std::shared_ptr d_ptr, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName = QString(), Device::Type type = Device::Type::Disk_Device); public: explicit Device(const Device& other); diff --git a/src/core/diskdevice.cpp b/src/core/diskdevice.cpp index c23cb58..38c8175 100644 --- a/src/core/diskdevice.cpp +++ b/src/core/diskdevice.cpp @@ -99,7 +99,7 @@ DiskDevice::DiskDevice(const QString& name, qint32 cylinders, qint64 sectorSize, const QString& iconName) - : Device(std::make_shared(), name, deviceNode, sectorSize, (static_cast(heads) * cylinders * numSectors), iconName, Device::Disk_Device) + : Device(std::make_shared(), name, deviceNode, sectorSize, (static_cast(heads) * cylinders * numSectors), iconName, Device::Type::Disk_Device) { d_ptr->m_Heads = heads; d_ptr->m_SectorsPerTrack = numSectors; diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index 917410c..118cd4f 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -63,7 +63,7 @@ LvmDevice::LvmDevice(const QString& vgName, const QString& iconName) getPeSize(vgName), getTotalPE(vgName), iconName, - Device::LVM_Device) + Device::Type::LVM_Device) { d_ptr->m_peSize = logicalSize(); d_ptr->m_totalPE = totalLogical(); diff --git a/src/core/operationstack.cpp b/src/core/operationstack.cpp index 8e7bd57..0a9b9f5 100644 --- a/src/core/operationstack.cpp +++ b/src/core/operationstack.cpp @@ -555,7 +555,7 @@ void OperationStack::addDevice(Device* d) static bool deviceLessThan(const Device* d1, const Device* d2) { // Display alphabetically sorted disk devices above LVM VGs - if (d1->type() == Device::LVM_Device && d2->type() == Device::Disk_Device ) + if (d1->type() == Device::Type::LVM_Device && d2->type() == Device::Type::Disk_Device ) return false; return d1->deviceNode() <= d2->deviceNode(); diff --git a/src/core/partitiontable.cpp b/src/core/partitiontable.cpp index aca5149..acc2080 100644 --- a/src/core/partitiontable.cpp +++ b/src/core/partitiontable.cpp @@ -274,7 +274,7 @@ QStringList PartitionTable::flagNames(Flags flags) bool PartitionTable::getUnallocatedRange(const Device& d, PartitionNode& parent, qint64& start, qint64& end) { - if (d.type() == Device::Disk_Device) { + if (d.type() == Device::Type::Disk_Device) { const DiskDevice& device = dynamic_cast(d); if (!parent.isRoot()) { Partition* extended = dynamic_cast(&parent); @@ -295,7 +295,7 @@ bool PartitionTable::getUnallocatedRange(const Device& d, PartitionNode& parent, } return end - start + 1 >= PartitionAlignment::sectorAlignment(device); - } else if (d.type() == Device::LVM_Device) { + } else if (d.type() == Device::Type::LVM_Device) { if (end - start + 1 > 0) { return true; } @@ -319,7 +319,7 @@ Partition* createUnallocated(const Device& device, PartitionNode& parent, qint64 r |= PartitionRole::Logical; // Mark unallocated space in LVM VG as LVM LV so that pasting can be easily disabled (it does not work yet) - if (device.type() == Device::LVM_Device) + if (device.type() == Device::Type::LVM_Device) r |= PartitionRole::Lvm_Lv; if (!PartitionTable::getUnallocatedRange(device, parent, start, end)) @@ -379,7 +379,7 @@ void PartitionTable::insertUnallocated(const Device& d, PartitionNode* p, qint64 qint64 lastEnd = start; - if (d.type() == Device::LVM_Device && !p->children().isEmpty()) { + if (d.type() == Device::Type::LVM_Device && !p->children().isEmpty()) { // rearranging the sectors of all partitions to keep unallocated space at the end lastEnd = 0; std::sort(children().begin(), children().end(), [](const Partition* p1, const Partition* p2) { return p1->deviceNode() < p2->deviceNode(); }); @@ -428,7 +428,7 @@ void PartitionTable::updateUnallocated(const Device& d) qint64 PartitionTable::defaultFirstUsable(const Device& d, TableType t) { Q_UNUSED(t) - if (d.type() == Device::LVM_Device) { + if (d.type() == Device::Type::LVM_Device) { return 0; } @@ -518,7 +518,7 @@ bool PartitionTable::tableTypeIsReadOnly(TableType l) */ bool PartitionTable::isSectorBased(const Device& d) const { - if (d.type() == Device::Disk_Device) { + if (d.type() == Device::Type::Disk_Device) { const DiskDevice& diskDevice = dynamic_cast(d); if (type() == PartitionTable::msdos) { diff --git a/src/core/volumemanagerdevice.h b/src/core/volumemanagerdevice.h index 60dd4d3..891aa68 100644 --- a/src/core/volumemanagerdevice.h +++ b/src/core/volumemanagerdevice.h @@ -42,7 +42,7 @@ class LIBKPMCORE_EXPORT VolumeManagerDevice : public Device Q_DISABLE_COPY(VolumeManagerDevice) public: - VolumeManagerDevice(std::shared_ptr d, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Unknown_Device); + VolumeManagerDevice(std::shared_ptr d, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Type::Unknown_Device); /** * @return list of physical device's path that makes up volumeManagerDevice.(e.g: /dev/sda, /dev/sdb1) diff --git a/src/jobs/createfilesystemjob.cpp b/src/jobs/createfilesystemjob.cpp index c4894e3..264f219 100644 --- a/src/jobs/createfilesystemjob.cpp +++ b/src/jobs/createfilesystemjob.cpp @@ -59,7 +59,7 @@ bool CreateFileSystemJob::run(Report& parent) else createResult = partition().fileSystem().create(*report, partition().deviceNode()); if (createResult) { - if (device().type() == Device::Disk_Device) { + if (device().type() == Device::Type::Disk_Device) { std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { @@ -75,7 +75,7 @@ bool CreateFileSystemJob::run(Report& parent) report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to set the system type for partition %2.", device().deviceNode(), partition().deviceNode()); } else report->line() << xi18nc("@info:progress", "Could not open device %1 to set the system type for partition %2.", device().deviceNode(), partition().deviceNode()); - } else if (device().type() == Device::LVM_Device) { + } else if (device().type() == Device::Type::LVM_Device) { rval = true; } } diff --git a/src/jobs/createpartitionjob.cpp b/src/jobs/createpartitionjob.cpp index a67a132..79f635e 100644 --- a/src/jobs/createpartitionjob.cpp +++ b/src/jobs/createpartitionjob.cpp @@ -50,7 +50,7 @@ bool CreatePartitionJob::run(Report& parent) Report* report = jobStarted(parent); - if (device().type() == Device::Disk_Device) { + if (device().type() == Device::Type::Disk_Device) { std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { @@ -70,7 +70,7 @@ bool CreatePartitionJob::run(Report& parent) report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to create new partition %2.", device().deviceNode(), partition().deviceNode()); } else report->line() << xi18nc("@info:progress", "Could not open device %1 to create new partition %2.", device().deviceNode(), partition().deviceNode()); - } else if (device().type() == Device::LVM_Device) { + } else if (device().type() == Device::Type::LVM_Device) { LvmDevice& dev = dynamic_cast(device()); partition().setState(Partition::StateNone); diff --git a/src/jobs/createpartitiontablejob.cpp b/src/jobs/createpartitiontablejob.cpp index 8ceb8b9..557a5e4 100644 --- a/src/jobs/createpartitiontablejob.cpp +++ b/src/jobs/createpartitiontablejob.cpp @@ -44,7 +44,7 @@ bool CreatePartitionTableJob::run(Report& parent) Report* report = jobStarted(parent); - if (device().type() == Device::Disk_Device) { + if (device().type() == Device::Type::Disk_Device) { std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice != nullptr) { @@ -53,7 +53,7 @@ bool CreatePartitionTableJob::run(Report& parent) rval = backendDevice->createPartitionTable(*report, *device().partitionTable()); } else report->line() << xi18nc("@info:progress", "Creating partition table failed: Could not open device %1.", device().deviceNode()); - } else if (device().type() == Device::LVM_Device) { + } else if (device().type() == Device::Type::LVM_Device) { //TODO: figure what to do with LVM partitionTable } diff --git a/src/jobs/deactivatelogicalvolumejob.cpp b/src/jobs/deactivatelogicalvolumejob.cpp index 327ad5c..5ce85da 100644 --- a/src/jobs/deactivatelogicalvolumejob.cpp +++ b/src/jobs/deactivatelogicalvolumejob.cpp @@ -41,7 +41,7 @@ bool DeactivateLogicalVolumeJob::run(Report& parent) Report* report = jobStarted(parent); - if (device().type() == Device::LVM_Device) { + if (device().type() == Device::Type::LVM_Device) { for (const auto &p : device().partitionTable()->children()) { if (!p->roles().has(PartitionRole::Unallocated)) { if (!LvmDevice::deactivateLV(*report, *p)) { diff --git a/src/jobs/deactivatevolumegroupjob.cpp b/src/jobs/deactivatevolumegroupjob.cpp index ae56ac6..2cc2ea3 100644 --- a/src/jobs/deactivatevolumegroupjob.cpp +++ b/src/jobs/deactivatevolumegroupjob.cpp @@ -39,7 +39,7 @@ bool DeactivateVolumeGroupJob::run(Report& parent) Report* report = jobStarted(parent); - if (device().type() == Device::LVM_Device) { + if (device().type() == Device::Type::LVM_Device) { rval = LvmDevice::deactivateVG(*report, static_cast(device())); } const auto lvmPVs = static_cast(device()).physicalVolumes(); diff --git a/src/jobs/deletefilesystemjob.cpp b/src/jobs/deletefilesystemjob.cpp index 6ff797e..176f851 100644 --- a/src/jobs/deletefilesystemjob.cpp +++ b/src/jobs/deletefilesystemjob.cpp @@ -65,7 +65,7 @@ bool DeleteFileSystemJob::run(Report& parent) if (partition().roles().has(PartitionRole::Extended)) { rval = true; - } else if (device().type() == Device::LVM_Device) { + } else if (device().type() == Device::Type::LVM_Device) { rval = true; } else { diff --git a/src/jobs/deletepartitionjob.cpp b/src/jobs/deletepartitionjob.cpp index 20bada2..07c30ff 100644 --- a/src/jobs/deletepartitionjob.cpp +++ b/src/jobs/deletepartitionjob.cpp @@ -57,7 +57,7 @@ bool DeletePartitionJob::run(Report& parent) Report* report = jobStarted(parent); - if (device().type() == Device::Disk_Device) { + if (device().type() == Device::Type::Disk_Device) { std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { @@ -74,7 +74,7 @@ bool DeletePartitionJob::run(Report& parent) report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to delete partition %2.", device().deviceNode(), partition().deviceNode()); } else report->line() << xi18nc("@info:progress", "Deleting partition failed: Could not open device %1.", device().deviceNode()); - } else if (device().type() == Device::LVM_Device) { + } else if (device().type() == Device::Type::LVM_Device) { LvmDevice& dev = dynamic_cast(device()); rval = LvmDevice::removeLV(*report, dev, partition()); } diff --git a/src/jobs/removevolumegroupjob.cpp b/src/jobs/removevolumegroupjob.cpp index d5026ae..97792f7 100644 --- a/src/jobs/removevolumegroupjob.cpp +++ b/src/jobs/removevolumegroupjob.cpp @@ -37,7 +37,7 @@ bool RemoveVolumeGroupJob::run(Report& parent) Report* report = jobStarted(parent); - if (device().type() == Device::LVM_Device) { + if (device().type() == Device::Type::LVM_Device) { rval = LvmDevice::removeVG(*report, dynamic_cast(device())); } diff --git a/src/jobs/setpartgeometryjob.cpp b/src/jobs/setpartgeometryjob.cpp index 153c352..30e218a 100644 --- a/src/jobs/setpartgeometryjob.cpp +++ b/src/jobs/setpartgeometryjob.cpp @@ -55,7 +55,7 @@ bool SetPartGeometryJob::run(Report& parent) Report* report = jobStarted(parent); - if(device().type() == Device::Disk_Device) { + if(device().type() == Device::Type::Disk_Device) { std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { @@ -72,7 +72,7 @@ bool SetPartGeometryJob::run(Report& parent) } } else report->line() << xi18nc("@info:progress", "Could not open device %1 while trying to resize/move partition %2.", device().deviceNode(), partition().deviceNode()); - } else if (device().type() == Device::LVM_Device) { + } else if (device().type() == Device::Type::LVM_Device) { partition().setFirstSector(newStart()); partition().setLastSector(newStart() + newLength() - 1); diff --git a/src/ops/createpartitiontableoperation.cpp b/src/ops/createpartitiontableoperation.cpp index 9260be6..f3ed270 100644 --- a/src/ops/createpartitiontableoperation.cpp +++ b/src/ops/createpartitiontableoperation.cpp @@ -93,7 +93,7 @@ bool CreatePartitionTableOperation::execute(Report& parent) */ bool CreatePartitionTableOperation::canCreate(const Device* device) { - return (device != nullptr) && (device->partitionTable() == nullptr || !device->partitionTable()->isChildMounted()) && (device->type() != Device::LVM_Device); + return (device != nullptr) && (device->partitionTable() == nullptr || !device->partitionTable()->isChildMounted()) && (device->type() != Device::Type::LVM_Device); } QString CreatePartitionTableOperation::description() const diff --git a/src/ops/deactivatevolumegroupoperation.cpp b/src/ops/deactivatevolumegroupoperation.cpp index a002e84..2a2db83 100644 --- a/src/ops/deactivatevolumegroupoperation.cpp +++ b/src/ops/deactivatevolumegroupoperation.cpp @@ -63,7 +63,7 @@ void DeactivateVolumeGroupOperation::undo() */ bool DeactivateVolumeGroupOperation::isDeactivatable(const VolumeManagerDevice* dev) { - if (dev->type() == Device::LVM_Device) { + if (dev->type() == Device::Type::LVM_Device) { for (const auto &p : dev->partitionTable()->children()) { if (p->isMounted()) { return false; diff --git a/src/ops/removevolumegroupoperation.cpp b/src/ops/removevolumegroupoperation.cpp index b523c83..605de3b 100644 --- a/src/ops/removevolumegroupoperation.cpp +++ b/src/ops/removevolumegroupoperation.cpp @@ -61,7 +61,7 @@ void RemoveVolumeGroupOperation::undo() bool RemoveVolumeGroupOperation::isRemovable(const VolumeManagerDevice* dev) { // TODO: allow removal when LVs are inactive. - if (dev->type() == Device::LVM_Device) { + if (dev->type() == Device::Type::LVM_Device) { if (dev->partitionTable()->children().count() == 0) // This is necessary to prevent a crash during applying of operations return true; else if (dev->partitionTable()->children().count() > 1)