Switch Device::Type enum to enum class.

This commit is contained in:
Andrius Štikonas 2018-04-09 02:57:45 +01:00
parent 1021e375b4
commit 3ccd04e675
19 changed files with 34 additions and 34 deletions

View File

@ -45,7 +45,7 @@ Device::Device(std::shared_ptr<DevicePrivate> 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<SmartStatus>(deviceNode) : nullptr;
d->m_SmartStatus = type == Device::Type::Disk_Device ? std::make_shared<SmartStatus>(deviceNode) : nullptr;
d->m_Type = type;
}

View File

@ -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<DevicePrivate> 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<DevicePrivate> 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);

View File

@ -99,7 +99,7 @@ DiskDevice::DiskDevice(const QString& name,
qint32 cylinders,
qint64 sectorSize,
const QString& iconName)
: Device(std::make_shared<DiskDevicePrivate>(), name, deviceNode, sectorSize, (static_cast<qint64>(heads) * cylinders * numSectors), iconName, Device::Disk_Device)
: Device(std::make_shared<DiskDevicePrivate>(), name, deviceNode, sectorSize, (static_cast<qint64>(heads) * cylinders * numSectors), iconName, Device::Type::Disk_Device)
{
d_ptr->m_Heads = heads;
d_ptr->m_SectorsPerTrack = numSectors;

View File

@ -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();

View File

@ -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();

View File

@ -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<const DiskDevice&>(d);
if (!parent.isRoot()) {
Partition* extended = dynamic_cast<Partition*>(&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<const DiskDevice&>(d);
if (type() == PartitionTable::msdos) {

View File

@ -42,7 +42,7 @@ class LIBKPMCORE_EXPORT VolumeManagerDevice : public Device
Q_DISABLE_COPY(VolumeManagerDevice)
public:
VolumeManagerDevice(std::shared_ptr<VolumeManagerDevicePrivate> 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<VolumeManagerDevicePrivate> 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)

View File

@ -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<CoreBackendDevice> 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 <filename>%1</filename> to set the system type for partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
} else
report->line() << xi18nc("@info:progress", "Could not open device <filename>%1</filename> to set the system type for partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
} else if (device().type() == Device::LVM_Device) {
} else if (device().type() == Device::Type::LVM_Device) {
rval = true;
}
}

View File

@ -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<CoreBackendDevice> 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 <filename>%1</filename> to create new partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
} else
report->line() << xi18nc("@info:progress", "Could not open device <filename>%1</filename> to create new partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
} else if (device().type() == Device::LVM_Device) {
} else if (device().type() == Device::Type::LVM_Device) {
LvmDevice& dev = dynamic_cast<LvmDevice&>(device());
partition().setState(Partition::StateNone);

View File

@ -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<CoreBackendDevice> 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 <filename>%1</filename>.", 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
}

View File

@ -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)) {

View File

@ -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<LvmDevice&>(device()));
}
const auto lvmPVs = static_cast<LvmDevice&>(device()).physicalVolumes();

View File

@ -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 {

View File

@ -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<CoreBackendDevice> 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 <filename>%1</filename> to delete partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
} else
report->line() << xi18nc("@info:progress", "Deleting partition failed: Could not open device <filename>%1</filename>.", device().deviceNode());
} else if (device().type() == Device::LVM_Device) {
} else if (device().type() == Device::Type::LVM_Device) {
LvmDevice& dev = dynamic_cast<LvmDevice&>(device());
rval = LvmDevice::removeLV(*report, dev, partition());
}

View File

@ -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<LvmDevice&>(device()));
}

View File

@ -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<CoreBackendDevice> 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 <filename>%1</filename> while trying to resize/move partition <filename>%2</filename>.", 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);

View File

@ -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

View File

@ -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;

View File

@ -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)