solid: implement graphic interface

interface named after graphics subsystem on Linux

for reference:
2557dbff56/plasma/applets/system-monitor/hwinfo.cpp (L103)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-11-02 15:29:05 +02:00
parent a02c347326
commit ae73a3d2d5
18 changed files with 428 additions and 6 deletions

View file

@ -46,6 +46,7 @@ set(solid_LIB_SRCS
powermanagement.cpp
video.cpp
smartcardreader.cpp
graphic.cpp
ifaces/acadapter.cpp
ifaces/audiointerface.cpp
@ -70,6 +71,7 @@ set(solid_LIB_SRCS
ifaces/storageaccess.cpp
ifaces/video.cpp
ifaces/smartcardreader.cpp
ifaces/graphic.cpp
backends/shared/rootdevice.cpp
backends/fstab/fstabmanager.cpp
@ -110,6 +112,7 @@ if(ENABLE_TESTING)
backends/fakehw/fakevideo.cpp
backends/fakehw/fakevolume.cpp
backends/fakehw/fakesmartcardreader.cpp
backends/fakehw/fakegraphic.cpp
)
endif()
@ -137,6 +140,7 @@ if(UDEV_FOUND)
backends/udev/udevstoragedrive.cpp
backends/udev/udevbattery.cpp
backends/udev/udevacadapter.cpp
backends/udev/udevgraphic.cpp
backends/udev/udevqtclient.cpp
backends/udev/udevqtdevice.cpp
)

View file

@ -660,4 +660,12 @@
<property key="isMounted">true</property>
<property key="mountPoint">/media/nfs</property>
</device>
<!-- Graphic -->
<device udi="/org/kde/solid/fakehw/pci_10de_0fc1_card0">
<property key="name">GK107 [GeForce GT 640]</property>
<property key="product">GK107 [GeForce GT 640]</property>
<property key="vendor">NVIDIA Corporation</property>
<property key="parent">/org/kde/solid/fakehw/computer</property>
</device>
</machine>

View file

@ -38,6 +38,7 @@
#include "fakeaudiointerface.h"
#include "fakedvbinterface.h"
#include "fakesmartcardreader.h"
#include "fakegraphic.h"
#include <QtCore/QStringList>
#include <QtDBus/QDBusConnection>
@ -318,6 +319,9 @@ QObject *FakeDevice::createDeviceInterface(const Solid::DeviceInterface::Type &t
case Solid::DeviceInterface::NetworkShare:
iface = new FakeNetworkShare(this);
break;
case Solid::DeviceInterface::Graphic:
iface = new FakeGraphic(this);
break;
case Solid::DeviceInterface::Unknown:
break;
case Solid::DeviceInterface::Last:

View file

@ -0,0 +1,35 @@
/*
Copyright 2021 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 "fakegraphic.h"
using namespace Solid::Backends::Fake;
FakeGraphic::FakeGraphic(FakeDevice *device)
: FakeDeviceInterface(device)
{
}
FakeGraphic::~FakeGraphic()
{
}
#include "backends/fakehw/moc_fakegraphic.cpp"

View file

@ -0,0 +1,46 @@
/*
Copyright 2021 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_FAKEHW_FAKEGRAPHIC_H
#define SOLID_BACKENDS_FAKEHW_FAKEGRAPHIC_H
#include "fakedeviceinterface.h"
#include <solid/ifaces/graphic.h>
namespace Solid
{
namespace Backends
{
namespace Fake
{
class FakeGraphic : public FakeDeviceInterface, virtual public Solid::Ifaces::Graphic
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Graphic)
public:
explicit FakeGraphic(FakeDevice *device);
~FakeGraphic();
};
}
}
}
#endif // SOLID_BACKENDS_FAKEHW_FAKEGRAPHIC_H

View file

@ -72,7 +72,8 @@ FakeManager::FakeManager(QObject *parent, const QString &xmlFile)
<< Solid::DeviceInterface::Video
<< Solid::DeviceInterface::SerialInterface
<< Solid::DeviceInterface::SmartCardReader
<< Solid::DeviceInterface::NetworkShare;
<< Solid::DeviceInterface::NetworkShare
<< Solid::DeviceInterface::Graphic;
}
FakeManager::~FakeManager()

View file

@ -35,6 +35,7 @@
#include "udevserialinterface.h"
#include "udevnetworkinterface.h"
#include "udevbutton.h"
#include "udevgraphic.h"
#include "udevmanager.h"
#include "cpuinfo.h"
#include "../shared/pciidstables.h"
@ -288,6 +289,8 @@ QString UDevDevice::icon() const
return QLatin1String("modem");
} else if (queryDeviceInterface(Solid::DeviceInterface::Button)) {
return QLatin1String("insert-button");
} else if (queryDeviceInterface(Solid::DeviceInterface::Graphic)) {
return QLatin1String("video-display");
}
return QString();
@ -472,6 +475,8 @@ QString UDevDevice::description() const
return QObject::tr("Unknown Button");
}
return QString();
} else if (queryDeviceInterface(Solid::DeviceInterface::Graphic)) {
return QString("Video display");
}
return QString();
@ -526,6 +531,9 @@ bool UDevDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type)
case Solid::DeviceInterface::Button:
return deviceProperty("ID_INPUT_KEY").toInt() == 1;
case Solid::DeviceInterface::Graphic:
return deviceProperty("PCI_CLASS").toInt() == 30000;
default:
return false;
}
@ -590,6 +598,9 @@ QObject *UDevDevice::createDeviceInterface(const Solid::DeviceInterface::Type &t
case Solid::DeviceInterface::Button:
return new Button(this);
case Solid::DeviceInterface::Graphic:
return new Graphic(this);
default:
qFatal("Shouldn't happen");
return 0;

View file

@ -0,0 +1,34 @@
/*
Copyright 2021 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 "udevgraphic.h"
using namespace Solid::Backends::UDev;
Graphic::Graphic(UDevDevice *device)
: DeviceInterface(device)
{
}
Graphic::~Graphic()
{
}
#include "moc_udevgraphic.cpp"

View file

@ -0,0 +1,46 @@
/*
Copyright 2021 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_UDEV_UDEVGRAPHIC_H
#define SOLID_BACKENDS_UDEV_UDEVGRAPHIC_H
#include <solid/ifaces/graphic.h>
#include "udevdeviceinterface.h"
namespace Solid
{
namespace Backends
{
namespace UDev
{
class Graphic : public DeviceInterface, virtual public Solid::Ifaces::Graphic
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::Graphic)
public:
Graphic(UDevDevice *device);
virtual ~Graphic();
};
}
}
}
#endif // SOLID_BACKENDS_UDEV_UDEVGRAPHIC_H

View file

@ -60,7 +60,8 @@ UDevManager::Private::Private()
<< "video4linux"
<< "net"
<< "usb"
<< "input";
<< "input"
<< "pci";
m_client = new UdevQt::Client(subsystems);
}
@ -111,7 +112,7 @@ bool UDevManager::Private::checkOfInterest(const UdevQt::Device &device)
return (sysfsDir.exists("sysdev") || sysfsDir.exists("cpufreq") || sysfsDir.exists("topology/core_id"));
}
if (device.subsystem() == QLatin1String("sound") &&
device.deviceProperty("SOUND_FORM_FACTOR") != "internal") {
device.deviceProperty("SOUND_FORM_FACTOR") != "internal") {
return true;
}
@ -126,6 +127,11 @@ bool UDevManager::Private::checkOfInterest(const UdevQt::Device &device)
}
}
if (device.subsystem() == QLatin1String("pci")) {
const QString pciclass = device.deviceProperty("PCI_CLASS");
return (pciclass == QLatin1String("30000")); // VGA controller
}
if (device.subsystem() == QLatin1String("input")) {
const QStringList deviceProperties = device.deviceProperties();
return (device.deviceProperty("ID_INPUT_KEY").toInt() == 1 && (deviceProperties.contains("KEY") || deviceProperties.contains("SW")));
@ -164,7 +170,8 @@ UDevManager::UDevManager(QObject *parent)
<< Solid::DeviceInterface::DvbInterface
<< Solid::DeviceInterface::Block
<< Solid::DeviceInterface::Video
<< Solid::DeviceInterface::Button;
<< Solid::DeviceInterface::Button
<< Solid::DeviceInterface::Graphic;
}
UDevManager::~UDevManager()

View file

@ -68,7 +68,8 @@
#include <solid/ifaces/serialinterface.h>
#include <solid/smartcardreader.h>
#include <solid/ifaces/smartcardreader.h>
#include <solid/graphic.h>
#include <solid/ifaces/graphic.h>
Solid::Device::Device(const QString &udi)
{
@ -238,6 +239,9 @@ const Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInter
case DeviceInterface::NetworkShare:
iface = deviceinterface_cast(Ifaces::NetworkShare, NetworkShare, dev_iface);
break;
case DeviceInterface::Graphic:
iface = deviceinterface_cast(Ifaces::Graphic, Graphic, dev_iface);
break;
case DeviceInterface::Unknown:
case DeviceInterface::Last:
break;

View file

@ -62,6 +62,7 @@ namespace Solid
* - SerialInterface: A serial interface
* - SmartCardReader: A smart card reader interface
* - NetworkShare: A network share interface
* - Graphic: A graphic interface
*/
enum Type { Unknown = 0, GenericInterface = 1, Processor = 2,
Block = 3, StorageAccess = 4, StorageDrive = 5,
@ -70,7 +71,7 @@ namespace Solid
NetworkInterface = 11, AcAdapter = 12, Battery = 13,
Button = 14, AudioInterface = 15, DvbInterface = 16, Video = 17,
SerialInterface = 18, SmartCardReader = 19, NetworkShare = 20,
Last = 0xffff };
Graphic = 21, Last = 0xffff };
/**
* Destroys a DeviceInterface object.

38
solid/solid/graphic.cpp Normal file
View file

@ -0,0 +1,38 @@
/*
Copyright 2021 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 "graphic.h"
#include "graphic_p.h"
#include "soliddefs_p.h"
#include <solid/ifaces/graphic.h>
Solid::Graphic::Graphic(QObject *backendObject)
: DeviceInterface(*new GraphicPrivate(), backendObject)
{
}
Solid::Graphic::~Graphic()
{
}
#include "moc_graphic.cpp"

72
solid/solid/graphic.h Normal file
View file

@ -0,0 +1,72 @@
/*
Copyright 2021 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_GRAPHIC_H
#define SOLID_GRAPHIC_H
#include <solid/solid_export.h>
#include <solid/deviceinterface.h>
namespace Solid
{
class GraphicPrivate;
class Device;
/**
* This device interface is available on graphic devices.
*
* A graphic device is typically used to render and output data to display.
*/
class SOLID_EXPORT Graphic : public DeviceInterface
{
Q_OBJECT
Q_DECLARE_PRIVATE(Graphic)
friend class Device;
private:
/**
* Creates a new Graphic object.
* You generally won't need this. It's created when necessary using
* Device::as().
*
* @param backendObject the device interface object provided by the backend
* @see Solid::Device::as()
*/
explicit Graphic(QObject *backendObject);
public:
/**
* Destroys a Graphic object.
*/
virtual ~Graphic();
/**
* Get the Solid::DeviceInterface::Type of the Graphic device interface.
*
* @return the Graphic device interface type
* @see Solid::DeviceInterface::Type
*/
static Type deviceInterfaceType() { return DeviceInterface::Graphic; }
};
}
#endif

36
solid/solid/graphic_p.h Normal file
View file

@ -0,0 +1,36 @@
/*
Copyright 2021 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_GRAPHIC_P_H
#define SOLID_GRAPHIC_P_H
#include "deviceinterface_p.h"
namespace Solid
{
class GraphicPrivate : public DeviceInterfacePrivate
{
public:
GraphicPrivate()
: DeviceInterfacePrivate() { }
};
}
#endif

View file

@ -0,0 +1,26 @@
/*
Copyright 2021 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 "graphic.h"
Solid::Ifaces::Graphic::~Graphic()
{
}

View file

@ -0,0 +1,48 @@
/*
Copyright 2021 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_IFACES_GRAPHIC_H
#define SOLID_IFACES_GRAPHIC_H
#include <solid/ifaces/deviceinterface.h>
namespace Solid
{
namespace Ifaces
{
/**
* This device interface is available on graphic devices.
*
* A graphic device is typically used to render and output data to display.
*/
class Graphic : virtual public DeviceInterface
{
public:
/**
* Destroys a Graphic object.
*/
virtual ~Graphic();
};
}
}
Q_DECLARE_INTERFACE(Solid::Ifaces::Graphic, "org.kde.Solid.Ifaces.Graphic/0.1")
#endif

View file

@ -290,6 +290,7 @@ void SolidHwTest::testDeviceInterfaceIntrospection_data()
QTest::newRow("DeviceInterface: Battery") << "Battery" << (int)Solid::DeviceInterface::Battery;
QTest::newRow("DeviceInterface: Button") << "Button" << (int)Solid::DeviceInterface::Button;
QTest::newRow("DeviceInterface: AudioInterface") << "AudioInterface" << (int)Solid::DeviceInterface::AudioInterface;
QTest::newRow("DeviceInterface: Graphic") << "Graphic" << (int)Solid::DeviceInterface::Graphic;
}
void SolidHwTest::testDeviceInterfaceIntrospection()