solid: implement Solid::Input interface for devinfo backend

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-10 22:33:57 +03:00
parent 5c66432bfe
commit 72f316b08d
5 changed files with 140 additions and 1 deletions

View file

@ -176,6 +176,7 @@ if(DEVINFO_FOUND)
backends/devinfo/devinfoprocessor.cpp
backends/devinfo/devinfonetworkinterface.cpp
backends/devinfo/devinfographic.cpp
backends/devinfo/devinfoinput.cpp
backends/devinfo/devdqt.cpp
)

View file

@ -23,6 +23,7 @@
#include "devinfoprocessor.h"
#include "devinfonetworkinterface.h"
#include "devinfographic.h"
#include "devinfoinput.h"
#include "kdevicedatabase.h"
#include "klocale.h"
@ -191,6 +192,18 @@ QString DevinfoDevice::icon() const
return QLatin1String("network-wired");
} else if (queryDeviceInterface(Solid::DeviceInterface::Graphic)) {
return QLatin1String("video-display");
} else if (queryDeviceInterface(Solid::DeviceInterface::Input)) {
const Input inputIface(const_cast<DevinfoDevice *>(this));
switch (inputIface.inputType()) {
case Solid::Input::UnknownInput:
return QString();
case Solid::Input::Mouse:
return QLatin1String("input-mouse");
case Solid::Input::Keyboard:
return QLatin1String("input-keyboard");
case Solid::Input::Joystick:
return QLatin1String("input-gaming");
}
}
return QString();
}
@ -215,6 +228,19 @@ QString DevinfoDevice::description() const
return i18n("Networking Interface");
} else if (queryDeviceInterface(Solid::DeviceInterface::Graphic)) {
return i18n("Graphic display");
} else if (queryDeviceInterface(Solid::DeviceInterface::Input)) {
const Input inputIface(const_cast<DevinfoDevice *>(this));
switch (inputIface.inputType()) {
case Solid::Input::UnknownInput:
return i18n("Unknown Input");
case Solid::Input::Mouse:
return i18n("Mouse");
case Solid::Input::Keyboard:
return i18n("Keyboard");
case Solid::Input::Joystick:
return i18n("Joystick");
}
return QString();
}
return deviceProperty(DevinfoDevice::DeviceDescription);
}
@ -231,6 +257,9 @@ bool DevinfoDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &typ
case Solid::DeviceInterface::Graphic: {
return (devicePnP(DevinfoDevice::PnPClass) == "0x030000"); // VGA controller
}
case Solid::DeviceInterface::Input: {
return (m_device.indexOf("/atkbd") >= 0 || m_device.indexOf("/psm") >= 0);
}
default: {
return false;
}
@ -252,6 +281,9 @@ QObject *DevinfoDevice::createDeviceInterface(const Solid::DeviceInterface::Type
case Solid::DeviceInterface::Graphic: {
return new Graphic(this);
}
case Solid::DeviceInterface::Input: {
return new Input(this);
}
default: {
Q_ASSERT(false);
return 0;

View file

@ -0,0 +1,54 @@
/*
Copyright 2024 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "devinfoinput.h"
#include "devinfodevice.h"
#include <QtCore/QDebug>
using namespace Solid::Backends::Devinfo;
Input::Input(DevinfoDevice *device)
: DeviceInterface(device)
{
}
Input::~Input()
{
}
QString Input::driver() const
{
const QByteArray pnpdriver = m_device->deviceProperty(DevinfoDevice::DeviceDriver);
return QString::fromLatin1(pnpdriver.constData(), pnpdriver.size());
}
Solid::Input::InputType Input::inputType() const
{
const QByteArray devicename = device->deviceProperty(DevinfoDevice::DeviceName);
if (devicename.contains("/atkbd")) {
return Solid::Input::Keyboard;
} else if (devicename.contains("/psm")) {
return Solid::Input::Mouse;
}
return Solid::Input::UnknownInput;
}
#include "backends/devinfo/moc_devinfoinput.cpp"

View file

@ -0,0 +1,51 @@
/*
Copyright 2024 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLID_BACKENDS_DEVINFO_INPUT_H
#define SOLID_BACKENDS_DEVINFO_INPUT_H
#include <solid/ifaces/input.h>
#include "devinfodeviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace Devinfo
{
class DevinfoDevice;
class Input : public DeviceInterface, virtual public Solid::Ifaces::Input
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Input)
public:
Input(DevinfoDevice *device);
virtual ~Input();
virtual QString driver() const;
virtual Solid::Input::InputType inputType() const;
};
}
}
}
#endif // SOLID_BACKENDS_DEVINFO_INPUT_H

View file

@ -79,7 +79,8 @@ DevinfoManager::DevinfoManager(QObject *parent)
d->m_supportedInterfaces
<< Solid::DeviceInterface::Processor
<< Solid::DeviceInterface::NetworkInterface
<< Solid::DeviceInterface::Graphic;
<< Solid::DeviceInterface::Graphic
<< Solid::DeviceInterface::Input;
}
DevinfoManager::~DevinfoManager()