7#include "udevmanager.h"
9#include "../shared/rootdevice.h"
11#include "udevdevice.h"
17using namespace Solid::Backends::UDev;
18using namespace Solid::Backends::Shared;
20class UDevManager::Private
26 bool isOfInterest(
const QString &udi,
const UdevQt::Device &device);
27 bool checkOfInterest(
const UdevQt::Device &device);
29 UdevQt::Client *m_client;
34UDevManager::Private::Private()
37 subsystems <<
"processor";
39 subsystems <<
"sound";
44 subsystems <<
"input";
45 m_client =
new UdevQt::Client(subsystems);
48UDevManager::Private::~Private()
53bool UDevManager::Private::isOfInterest(
const QString &udi,
const UdevQt::Device &device)
55 if (m_devicesOfInterest.contains(udi)) {
59 bool isOfInterest = checkOfInterest(device);
61 m_devicesOfInterest.append(udi);
67bool UDevManager::Private::checkOfInterest(
const UdevQt::Device &device)
69 const QString subsystem = device.subsystem();
70#ifdef UDEV_DETAILED_OUTPUT
71 qDebug() <<
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
72 qDebug() <<
"Path:" << device.sysfsPath();
73 qDebug() <<
"Properties:" << device.deviceProperties();
77 qDebug() <<
"\t" << key <<
":" << device.deviceProperty(key).
toString();
79 qDebug() <<
"Driver:" << device.driver();
80 qDebug() <<
"Subsystem:" << subsystem;
81 qDebug() <<
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
91 if (subsystem ==
QLatin1String(
"sound") && device.deviceProperty(
"SOUND_FORM_FACTOR").
toString() !=
"internal") {
108 if (device.deviceProperty(
"ID_INPUT_MOUSE").
toInt() == 1
109 || device.deviceProperty(
"ID_INPUT_TOUCHPAD").
toInt() == 1
110 || device.deviceProperty(
"ID_INPUT_TABLET").
toInt() == 1
111 || device.deviceProperty(
"ID_INPUT_JOYSTICK").
toInt() == 1
112 || device.deviceProperty(
"ID_INPUT_TOUCHSCREEN").
toInt() == 1) {
121 && device.parent().deviceProperty(
"ID_MEDIA_PLAYER").
toString().
isEmpty())
122 || (device.deviceProperty(
"ID_GPHOTO2").
toInt() == 1
123 && device.parent().deviceProperty(
"ID_GPHOTO2").
toInt() != 1);
131 connect(d->m_client, SIGNAL(deviceAdded(UdevQt::Device)),
this, SLOT(slotDeviceAdded(UdevQt::Device)));
132 connect(d->m_client, SIGNAL(deviceRemoved(UdevQt::Device)),
this, SLOT(slotDeviceRemoved(UdevQt::Device)));
135 d->m_supportedInterfaces << Solid::DeviceInterface::GenericInterface
136 << Solid::DeviceInterface::Processor
137 << Solid::DeviceInterface::Camera
138 << Solid::DeviceInterface::PortableMediaPlayer
139 << Solid::DeviceInterface::Block;
143UDevManager::~UDevManager()
148QString UDevManager::udiPrefix()
const
155 return d->m_supportedInterfaces;
162 for (
const UdevQt::Device &device : deviceList) {
163 if (d->isOfInterest(udiPrefix() + device.sysfsPath(), device)) {
164 res << udiPrefix() + device.sysfsPath();
176 for (
const UdevQt::Device &dev : deviceList) {
177 UDevDevice device(dev);
178 if (device.queryDeviceInterface(type) && d->isOfInterest(udiPrefix() + dev.sysfsPath(), dev) && device.parentUdi() == parentUdi) {
179 result << udiPrefix() + dev.sysfsPath();
185 if (type == DeviceInterface::Unknown) {
192 if (type == Solid::DeviceInterface::Processor) {
193 deviceList = (d->m_client->devicesBySubsystem(QStringLiteral(
"processor"))
194 + d->m_client->devicesBySubsystem(QStringLiteral(
"cpu")));
195 }
else if (type == Solid::DeviceInterface::Camera) {
196 deviceList = d->m_client->devicesBySubsystemsAndProperties({QStringLiteral(
"usb")},
197 {{QStringLiteral(
"ID_GPHOTO2"), QStringLiteral(
"*")}});
198 }
else if (type == Solid::DeviceInterface::PortableMediaPlayer) {
199 deviceList = d->m_client->devicesBySubsystemsAndProperties({QStringLiteral(
"usb")},
200 {{QStringLiteral(
"ID_MEDIA_PLAYER"), QStringLiteral(
"*")}});
202 deviceList = d->m_client->allDevices();
205 for (
const UdevQt::Device &dev :
std::as_const(deviceList)) {
206 UDevDevice device(dev);
207 if (device.queryDeviceInterface(type)
208 && d->isOfInterest(udiPrefix() + dev.sysfsPath(), dev)) {
209 result << udiPrefix() + dev.sysfsPath();
218 if (udi_ == udiPrefix()) {
219 RootDevice *
const device =
new RootDevice(UDEV_UDI_PREFIX);
220 device->setProduct(
tr(
"Devices"));
221 device->setDescription(
tr(
"Devices declared in your system"));
222 device->setIcon(
"computer");
228 UdevQt::Device device = d->m_client->deviceBySysfsPath(udi);
231 return new UDevDevice(device);
237void UDevManager::slotDeviceAdded(
const UdevQt::Device &device)
239 if (d->isOfInterest(udiPrefix() + device.sysfsPath(), device)) {
244void UDevManager::slotDeviceRemoved(
const UdevQt::Device &device)
246 if (d->isOfInterest(udiPrefix() + device.sysfsPath(), device)) {
248 d->m_devicesOfInterest.
removeAll(udiPrefix() + device.sysfsPath());
252#include "moc_udevmanager.cpp"
Type
This enum type defines the type of device interface that a Device can have.
void deviceAdded(const QString &udi)
This signal is emitted when a new device appears in the system.
void deviceRemoved(const QString &udi)
This signal is emitted when a device disappears from the system.
DeviceManager(QObject *parent=nullptr)
Constructs a DeviceManager.
QString path(const QString &relativePath)
The single responsibility of this class is to create arguments valid for logind Inhibit call.
bool startsWith(QByteArrayView bv) const const
bool exists() const const
qsizetype removeAll(const AT &t)
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
qsizetype length() const const
QString right(qsizetype n) const const
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QByteArray toLatin1() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
int toInt(bool *ok) const const
QString toString() const const