11#include "udevcamera.h"
12#include "udevgenericinterface.h"
13#include "udevportablemediaplayer.h"
14#include "udevprocessor.h"
16#include <sys/socket.h>
18#include <linux/if_arp.h>
20using namespace Solid::Backends::UDev;
22UDevDevice::UDevDevice(
const UdevQt::Device device)
28UDevDevice::~UDevDevice()
32QString UDevDevice::udi()
const
37QString UDevDevice::parentUdi()
const
39 return QStringLiteral(UDEV_UDI_PREFIX);
42QString UDevDevice::vendor()
const
44 QString vendor = m_device.sysfsProperty(QStringLiteral(
"manufacturer")).toString();
45 if (vendor.isEmpty()) {
46 if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
48 vendor = extractCpuVendor(deviceNumber());
51 if (vendor.isEmpty()) {
52 vendor = m_device.deviceProperty(QStringLiteral(
"ID_VENDOR")).toString().replace(QLatin1Char(
'_'), QLatin1Char(
' '));
58QString UDevDevice::product()
const
60 QString product = m_device.sysfsProperty(QStringLiteral(
"product")).toString();
61 if (product.isEmpty()) {
62 if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
64 product = extractCpuModel(deviceNumber());
67 if (product.isEmpty()) {
68 product = m_device.deviceProperty(QStringLiteral(
"ID_MODEL")).toString().replace(QLatin1Char(
'_'), QLatin1Char(
' '));
74QString UDevDevice::icon()
const
76 if (parentUdi().isEmpty()) {
77 return QLatin1String(
"computer");
80 if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
81 return QLatin1String(
"cpu");
82 }
else if (queryDeviceInterface(Solid::DeviceInterface::PortableMediaPlayer)) {
84 return QLatin1String(
"multimedia-player");
85 }
else if (queryDeviceInterface(Solid::DeviceInterface::Camera)) {
86 return QLatin1String(
"camera-photo");
92QStringList UDevDevice::emblems()
const
97QString UDevDevice::description()
const
99 if (parentUdi().isEmpty()) {
100 return tr(
"Computer");
103 if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
104 return tr(
"Processor");
105 }
else if (queryDeviceInterface(Solid::DeviceInterface::PortableMediaPlayer)) {
110 const PortableMediaPlayer *player =
new PortableMediaPlayer(
const_cast<UDevDevice *
>(
this));
111 if (player->supportedProtocols().
contains(QStringLiteral(
"mtp"))) {
115 return tr(
"Portable Media Player");
117 }
else if (queryDeviceInterface(Solid::DeviceInterface::Camera)) {
127 case Solid::DeviceInterface::GenericInterface:
130 case Solid::DeviceInterface::Processor:
131 return m_device.subsystem() == QLatin1String(
"cpu");
133 case Solid::DeviceInterface::Camera:
134 return m_device.subsystem() == QLatin1String(
"usb") && property(QStringLiteral(
"ID_GPHOTO2")).isValid();
136 case Solid::DeviceInterface::PortableMediaPlayer:
137 return m_device.subsystem() == QLatin1String(
"usb") && property(QStringLiteral(
"ID_MEDIA_PLAYER")).isValid();
139 case Solid::DeviceInterface::Block:
140 return !property(QStringLiteral(
"MAJOR")).toString().isEmpty();
149 if (!queryDeviceInterface(type)) {
154 case Solid::DeviceInterface::GenericInterface:
155 return new GenericInterface(
this);
157 case Solid::DeviceInterface::Processor:
158 return new Processor(
this);
160 case Solid::DeviceInterface::Camera:
161 return new Camera(
this);
163 case Solid::DeviceInterface::PortableMediaPlayer:
164 return new PortableMediaPlayer(
this);
166 case Solid::DeviceInterface::Block:
167 return new Block(
this);
170 qFatal(
"Shouldn't happen");
175QString UDevDevice::device()
const
180QVariant UDevDevice::property(
const QString &key)
const
182 const QVariant res = m_device.deviceProperty(key);
186 return m_device.sysfsProperty(key);
189QMap<QString, QVariant> UDevDevice::allProperties()
const
191 QMap<QString, QVariant> res;
192 const QStringList
properties = m_device.deviceProperties();
193 for (
const QString &prop : properties) {
194 res[prop] = property(prop);
199bool UDevDevice::propertyExists(
const QString &key)
const
201 return m_device.deviceProperties().
contains(key);
204QString UDevDevice::systemAttribute(
const char *attribute)
const
209QString UDevDevice::deviceName()
const
211 return m_device.sysfsPath();
214int UDevDevice::deviceNumber()
const
216 return m_device.sysfsNumber();
219QString UDevDevice::devicePath()
const
221 return QStringLiteral(UDEV_UDI_PREFIX) + deviceName();
224UdevQt::Device UDevDevice::udevDevice()
229#include "moc_udevdevice.cpp"
Type
This enum type defines the type of device interface that a Device can have.
This class allows applications to deal with devices available in the underlying system.
bool contains(const Key &key) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString fromLatin1(QByteArrayView str)
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
bool isValid() const const