From 3595c490a6151953b4e212c5b229b3abd631bb79 Mon Sep 17 00:00:00 2001 From: Demitrius Belai Date: Tue, 5 Jul 2022 16:42:26 -0300 Subject: [PATCH] Add whole hard drive in disk plugin Disk Plugin was using StorageAccess but it only monitor partitions. This commit changes to StorageVolume for showing hard drives too (sda, sdb). Obvious it can not monitor free space on non partition volume so that is skiped. --- plugins/disks/disks.cpp | 67 +++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/plugins/disks/disks.cpp b/plugins/disks/disks.cpp index 58b2f9e..1c86625 100644 --- a/plugins/disks/disks.cpp +++ b/plugins/disks/disks.cpp @@ -54,14 +54,15 @@ private: QString VolumeObject::idHelper(const Solid::Device &device) { auto volume = device.as(); - return volume->uuid().isEmpty() ? volume->label() : volume->uuid(); + auto block = device.as(); + return volume->uuid().isEmpty() ? volume->label().isEmpty() ? QUrl(block->device()).fileName() : volume->label() : volume->uuid(); } VolumeObject::VolumeObject(const Solid::Device &device, KSysGuard::SensorContainer* parent) : SensorObject(idHelper(device), device.displayName(), parent) , udi(device.udi()) - , mountPoint(device.as()->filePath()) + , mountPoint(device.is() ? device.as()->filePath() : QString()) { auto volume = device.as(); @@ -75,19 +76,21 @@ VolumeObject::VolumeObject(const Solid::Device &device, KSysGuard::SensorContain m_total->setUnit(KSysGuard::UnitByte); m_total->setVariantType(QVariant::ULongLong); - m_used = new KSysGuard::SensorProperty("used", i18nc("@title", "Used Space"), this); - m_used->setPrefix(name()); - m_used->setShortName(i18nc("@title Short for 'Used Space'", "Used")); - m_used->setUnit(KSysGuard::UnitByte); - m_used->setVariantType(QVariant::ULongLong); - m_used->setMax(volume->size()); - - m_free = new KSysGuard::SensorProperty("free", i18nc("@title", "Free Space"), this); - m_free->setPrefix(name()); - m_free->setShortName(i18nc("@title Short for 'Free Space'", "Free")); - m_free->setUnit(KSysGuard::UnitByte); - m_free->setVariantType(QVariant::ULongLong); - m_free->setMax(volume->size()); + if (volume->usage() != Solid::StorageVolume::PartitionTable) { + m_used = new KSysGuard::SensorProperty("used", i18nc("@title", "Used Space"), this); + m_used->setPrefix(name()); + m_used->setShortName(i18nc("@title Short for 'Used Space'", "Used")); + m_used->setUnit(KSysGuard::UnitByte); + m_used->setVariantType(QVariant::ULongLong); + m_used->setMax(volume->size()); + + m_free = new KSysGuard::SensorProperty("free", i18nc("@title", "Free Space"), this); + m_free->setPrefix(name()); + m_free->setShortName(i18nc("@title Short for 'Free Space'", "Free")); + m_free->setUnit(KSysGuard::UnitByte); + m_free->setVariantType(QVariant::ULongLong); + m_free->setMax(volume->size()); + } m_readRate = new KSysGuard::SensorProperty("read", i18nc("@title", "Read Rate"), 0, this); m_readRate->setPrefix(name()); @@ -101,17 +104,22 @@ VolumeObject::VolumeObject(const Solid::Device &device, KSysGuard::SensorContain m_writeRate->setUnit(KSysGuard::UnitByteRate); m_writeRate->setVariantType(QVariant::Double); - auto usedPercent = new KSysGuard::PercentageSensor(this, "usedPercent", i18nc("@title", "Percentage Used")); - usedPercent->setPrefix(name()); - usedPercent->setBaseSensor(m_used); + if (volume->usage() != Solid::StorageVolume::PartitionTable) { + auto usedPercent = new KSysGuard::PercentageSensor(this, "usedPercent", i18nc("@title", "Percentage Used")); + usedPercent->setPrefix(name()); + usedPercent->setBaseSensor(m_used); - auto freePercent = new KSysGuard::PercentageSensor(this, "freePercent", i18nc("@title", "Percentage Free")); - freePercent->setPrefix(name()); - freePercent->setBaseSensor(m_free); + auto freePercent = new KSysGuard::PercentageSensor(this, "freePercent", i18nc("@title", "Percentage Free")); + freePercent->setPrefix(name()); + freePercent->setBaseSensor(m_free); + } } void VolumeObject::update() { + if (mountPoint.isEmpty()) { + return; + } auto job = KIO::fileSystemFreeSpace(QUrl::fromLocalFile(mountPoint)); connect(job, &KIO::FileSystemFreeSpaceJob::result, this, [this] (KJob *job, KIO::filesize_t size, KIO::filesize_t available) { if (!job->error()) { @@ -139,9 +147,9 @@ DisksPlugin::DisksPlugin(QObject *parent, const QVariantList &args) : SensorPlugin(parent, args) { auto container = new KSysGuard::SensorContainer("disk", i18n("Disks"), this); - auto storageAccesses = Solid::Device::listFromType(Solid::DeviceInterface::StorageAccess); - for (const auto &storageAccess : storageAccesses) { - addDevice(storageAccess); + auto storageVolumes = Solid::Device::listFromType(Solid::DeviceInterface::StorageVolume); + for (const auto &storageVolume : storageVolumes) { + addDevice(storageVolume); } connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, this, [this] (const QString &udi) { addDevice(Solid::Device(udi)); @@ -176,7 +184,7 @@ void DisksPlugin::addDevice(const Solid::Device& device) auto container = containers()[0]; const auto volume = device.as(); auto access = device.as(); - if (!access || !volume || volume->isIgnored()) { + if (!volume || (volume->isIgnored() && volume->usage() != Solid::StorageVolume::PartitionTable)) { return; } Solid::Device drive = device; @@ -192,7 +200,14 @@ void DisksPlugin::addDevice(const Solid::Device& device) } drive = drive.parent(); } - + if (volume->usage() == Solid::StorageVolume::PartitionTable) { + auto block = device.as(); + m_volumesByDevice.insert(block->device(), new VolumeObject(device, container)); + return; + } + if (!access) { + return; + } if (access->filePath() != QString()) { createAccessibleVolumeObject(device); } -- GitLab