File indexing completed on 2024-04-21 05:33:27
0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0002 // SPDX-FileCopyrightText: 2020-2021 Harald Sitter <sitter@kde.org> 0003 0004 #include "soliddevicenotifier.h" 0005 0006 #include <Solid/Block> 0007 #include <Solid/DeviceInterface> 0008 #include <Solid/DeviceNotifier> 0009 #include <Solid/StorageDrive> 0010 #include <Solid/StorageVolume> 0011 0012 #include "device.h" 0013 0014 #include "kded_debug.h" 0015 0016 void SolidDeviceNotifier::start() 0017 { 0018 connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, this, &SolidDeviceNotifier::checkUDI); 0019 connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceRemoved, this, &SolidDeviceNotifier::removeUDI); 0020 loadData(); 0021 } 0022 0023 void SolidDeviceNotifier::loadData() 0024 { 0025 const auto devices = Solid::Device::listFromType(Solid::DeviceInterface::StorageVolume); 0026 for (const auto &device : devices) { 0027 checkSolidDevice(device); 0028 } 0029 } 0030 0031 void SolidDeviceNotifier::checkUDI(const QString &udi) 0032 { 0033 checkSolidDevice(Solid::Device(udi)); 0034 } 0035 0036 void SolidDeviceNotifier::checkSolidDevice(const Solid::Device &device) 0037 { 0038 qCDebug(KDED) << "!!!! " << device.udi(); 0039 0040 // This seems fairly awkward on a solid level. The actual device 0041 // isn't really trivial to identify. It certainly mustn't be a 0042 // filesystem but beyond that it's entirely unclear. 0043 // The trouble here is that we'll only want to run smartctl on 0044 // actual devices, not the partitions on the devices as otherwise 0045 // we'll have trouble validating the output as we'd not know 0046 // if it is incomplete because the device wasn't a device or 0047 // there's no data or smartctl is broken or the auth helper is broken... 0048 if (!device.is<Solid::StorageVolume>()) { 0049 qCDebug(KDED) << " not a volume"; 0050 return; // certainly not an interesting device 0051 } 0052 switch (device.as<Solid::StorageVolume>()->usage()) { 0053 case Solid::StorageVolume::Unused: 0054 Q_FALLTHROUGH(); 0055 case Solid::StorageVolume::FileSystem: 0056 Q_FALLTHROUGH(); 0057 case Solid::StorageVolume::Encrypted: 0058 Q_FALLTHROUGH(); 0059 case Solid::StorageVolume::Other: 0060 Q_FALLTHROUGH(); 0061 case Solid::StorageVolume::Raid: 0062 qCDebug(KDED) << " bad type" << device.as<Solid::StorageVolume>()->usage(); 0063 return; 0064 case Solid::StorageVolume::PartitionTable: 0065 break; 0066 } 0067 0068 qCDebug(KDED) << "evaluating!"; 0069 0070 Q_EMIT addDevice(new Device(device)); 0071 } 0072 0073 #include "moc_soliddevicenotifier.cpp"