Solid::Device Class
class Solid::DeviceAllows applications to deal with devices available in the underlying system. More...
| Header: | #include <Solid/Device> |
| CMake: | find_package(KF6 REQUIRED COMPONENTS Solid)target_link_libraries(mytarget PRIVATE KF6::Solid) |
Public Functions
| Device(const QString &udi = QString()) | |
| DevIface * | as() |
| const DevIface * | as() const |
| Solid::DeviceInterface * | asDeviceInterface(const Solid::DeviceInterface::Type &type) |
| const Solid::DeviceInterface * | asDeviceInterface(const Solid::DeviceInterface::Type &type) const |
| QString | description() const |
| QString | displayName() const |
| QStringList | emblems() const |
| QString | icon() const |
| bool | is() const |
| bool | isDeviceInterface(const Solid::DeviceInterface::Type &type) const |
| bool | isValid() const |
| Solid::Device | parent() const |
| QString | parentUdi() const |
| QString | product() const |
| QString | udi() const |
| QString | vendor() const |
Static Public Members
| QList<Solid::Device> | allDevices() |
| QList<Solid::Device> | listFromQuery(const Solid::Predicate &predicate, const QString &parentUdi = QString()) |
| QList<Solid::Device> | listFromQuery(const QString &predicate, const QString &parentUdi = QString()) |
| QList<Solid::Device> | listFromType(const Solid::DeviceInterface::Type &type, const QString &parentUdi = QString()) |
| Solid::Device | storageAccessFromPath(const QString &path) |
Detailed Description
Device stores a reference to device data provided by the backend.
Device objects are designed to be used by value. Copying these objects is quite cheap, so using pointers is generally not needed.
Member Function Documentation
[explicit] Device::Device(const QString &udi = QString())
Constructs a device for a given Universal Device Identifier udi.
[static] QList<Solid::Device> Device::allDevices()
Returns all devices available in the underlying system.
template <typename DevIface> DevIface *Device::as()
Returns a specialized interface to interact with the device corresponding to a given device interface, or nullptr if it doesn't exist.
const Solid::Processor* processor = device.as<Solid::Processor>();
template <typename DevIface> const DevIface *Device::as() const
Returns a specialized interface to interact with the device corresponding to a given device interface, or nullptr if it doesn't exist.
const Solid::Processor* processor = device.as<const Solid::Processor>();
Solid::DeviceInterface *Device::asDeviceInterface(const Solid::DeviceInterface::Type &type)
Returns a specialized interface to interact with the device corresponding to a particular device interface type, or nullptr if it doesn't exist.
const Solid::Battery* battery =
qobject_cast<const Solid::Battery>(device.asDeviceInterface(Solid::DeviceInterface::Battery));
const Solid::DeviceInterface *Device::asDeviceInterface(const Solid::DeviceInterface::Type &type) const
Returns a specialized interface to interact with the device corresponding to a particular device interface type, or nullptr if it doesn't exist.
QString Device::description() const
Returns the description of this device.
QString Device::displayName() const
Returns the display name to use for this device.
Same as description when not defined.
QStringList Device::emblems() const
Returns the names of the emblems representing the state of this device.
The naming follows the freedesktop.org specification.
QString Device::icon() const
Returns the name of the icon representing this device.
The naming follows the freedesktop.org specification.
template <typename DevIface> bool Device::is() const
Tests if a device provides a given device interface.
if (device.is<Solid::StorageDrive>()) {
// ...
}
bool Device::isDeviceInterface(const Solid::DeviceInterface::Type &type) const
Tests if a device interface type is available from the device.
if (device.isDeviceInterface(Solid::DeviceInterface::StorageAccess)) {
// ...
}
bool Device::isValid() const
Returns if this device is valid (available in the system).
[static] QList<Solid::Device> Device::listFromQuery(const Solid::Predicate &predicate, const QString &parentUdi = QString())
Returns a list of devices matching the given predicate query.
The parentUdi should match the provider for the device. For example:
- /org/kde/solid/udev
- /org/freedesktop/UPower
- /org/freedesktop/UDisks2
See also Solid::Predicate.
[static] QList<Solid::Device> Device::listFromQuery(const QString &predicate, const QString &parentUdi = QString())
This function overloads Device::listFromQuery().
[static] QList<Solid::Device> Device::listFromType(const Solid::DeviceInterface::Type &type, const QString &parentUdi = QString())
Returns a list of devices matching the given type.
The parentUdi should match the provider for the device. For example:
- /org/kde/solid/udev
- /org/freedesktop/UPower
- /org/freedesktop/UDisks2
Solid::Device Device::parent() const
Returns the parent of the Device.
See also parentUdi().
QString Device::parentUdi() const
Returns the Universal Device Identifier (UDI) of the Device's parent.
QString Device::product() const
Returns the name of the product corresponding to this device.
[static] Solid::Device Device::storageAccessFromPath(const QString &path)
Returns the Device containing the filesystem for the given path.
For Devices implementing the StorageVolume interface, only ones matching UsageType::FileSystem are returned, i.e. no backing encrypted volumes.
See also QFileInfo::canonicalFilePath.
QString Device::udi() const
Returns the Universal Device Identifier udi.
Warning: Don't use the UDI for anything except communication with Solid. Also don't store UDIs as there's no guarantee that the UDI stays the same when the hardware setup changed. The UDI is a unique identifier that is local to the computer in question and for the current boot session. The UDIs may change after a reboot. Similar hardware in other computers may have different values; different hardware could have the same UDI.
QString Device::vendor() const
Returns the name of the device vendor.