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()
37QString UDevDevice::parentUdi()
const
39 return QStringLiteral(UDEV_UDI_PREFIX);
42QString UDevDevice::vendor()
const
44 QString vendor = m_device.sysfsProperty(QStringLiteral(
"manufacturer")).
toString();
46 if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
48 vendor = extractCpuVendor(deviceNumber());
58QString UDevDevice::product()
const
60 QString product = m_device.sysfsProperty(QStringLiteral(
"product")).
toString();
62 if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
64 product = extractCpuModel(deviceNumber());
76 if (parentUdi().isEmpty()) {
80 if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
82 }
else if (queryDeviceInterface(Solid::DeviceInterface::PortableMediaPlayer)) {
85 }
else if (queryDeviceInterface(Solid::DeviceInterface::Camera)) {
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:
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:
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
182 const QVariant res = m_device.deviceProperty(key);
186 return m_device.sysfsProperty(key);
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.
The single responsibility of this class is to create arguments valid for logind Inhibit call.
QString tr(const char *sourceText, const char *disambiguation, int n)
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
bool isValid() const const
QString toString() const const