7#include "fakedevice_p.h"
9#include "fakebattery.h"
11#include "fakecamera.h"
13#include "fakedeviceinterface.h"
14#include "fakegenericinterface.h"
15#include "fakenetworkshare.h"
16#include "fakeopticaldisc.h"
17#include "fakeportablemediaplayer.h"
18#include "fakeprocessor.h"
19#include "fakestorage.h"
20#include "fakestorageaccess.h"
21#include "fakevolume.h"
25#include <QDBusConnection>
28#include <solid/genericinterface.h>
30using namespace Solid::Backends::Fake;
37 d->propertyMap = propertyMap;
38 d->interfaceList = d->propertyMap[QStringLiteral(
"interfaces")].toString().simplified().split(
QLatin1Char(
','));
39 d->interfaceList << QStringLiteral(
"GenericInterface");
51 for (
const QString &interface : std::as_const(d->interfaceList)) {
53 createDeviceInterface(type);
60FakeDevice::FakeDevice(
const FakeDevice &dev)
68FakeDevice::~FakeDevice()
80QString FakeDevice::parentUdi()
const
82 return d->propertyMap[QStringLiteral(
"parent")].toString();
85QString FakeDevice::vendor()
const
87 return d->propertyMap[QStringLiteral(
"vendor")].toString();
90QString FakeDevice::product()
const
92 return d->propertyMap[QStringLiteral(
"name")].toString();
97 if (parentUdi().isEmpty()) {
98 return QStringLiteral(
"system");
99 }
else if (queryDeviceInterface(Solid::DeviceInterface::OpticalDrive)) {
100 return QStringLiteral(
"cdrom-unmount");
101 }
else if (queryDeviceInterface(Solid::DeviceInterface::PortableMediaPlayer)) {
102 return QStringLiteral(
"ipod-unmount");
103 }
else if (queryDeviceInterface(Solid::DeviceInterface::Camera)) {
104 return QStringLiteral(
"camera-unmount");
105 }
else if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
106 return QStringLiteral(
"cpu");
107 }
else if (queryDeviceInterface(Solid::DeviceInterface::StorageDrive)) {
108 return QStringLiteral(
"hdd-unmount");
109 }
else if (queryDeviceInterface(Solid::DeviceInterface::Block)) {
110 return QStringLiteral(
"blockdevice");
112 return QStringLiteral(
"hwinfo");
118 if (queryDeviceInterface(Solid::DeviceInterface::StorageAccess)) {
119 if (property(QStringLiteral(
"isMounted")).toBool()) {
120 return {QStringLiteral(
"emblem-mounted")};
122 return {QStringLiteral(
"emblem-unmounted")};
129QString FakeDevice::description()
const
136 return d->propertyMap[key];
141 return d->propertyMap;
144bool FakeDevice::propertyExists(
const QString &key)
const
146 return d->propertyMap.contains(key);
157 if (!d->propertyMap.contains(key)) {
158 change_type = Solid::GenericInterface::PropertyAdded;
161 d->propertyMap[key] = value;
164 change[key] = change_type;
166 Q_EMIT d->propertyChanged(change);
171bool FakeDevice::removeProperty(
const QString &key)
173 if (d->broken || !d->propertyMap.contains(key)) {
177 d->propertyMap.remove(key);
180 change[key] = Solid::GenericInterface::PropertyRemoved;
182 Q_EMIT d->propertyChanged(change);
187void FakeDevice::setBroken(
bool broken)
192bool FakeDevice::isBroken()
197bool FakeDevice::lock(
const QString &reason)
199 if (d->broken || d->locked) {
204 d->lockReason = reason;
209bool FakeDevice::unlock()
211 if (d->broken || !d->locked) {
216 d->lockReason.clear();
221bool FakeDevice::isLocked()
const
226QString FakeDevice::lockReason()
const
228 return d->lockReason;
231void FakeDevice::raiseCondition(
const QString &condition,
const QString &reason)
233 Q_EMIT d->conditionRaised(condition, reason);
244 if (!queryDeviceInterface(type)) {
248 FakeDeviceInterface *iface =
nullptr;
251 case Solid::DeviceInterface::GenericInterface:
252 iface =
new FakeGenericInterface(
this);
254 case Solid::DeviceInterface::Processor:
255 iface =
new FakeProcessor(
this);
257 case Solid::DeviceInterface::Block:
258 iface =
new FakeBlock(
this);
260 case Solid::DeviceInterface::StorageDrive:
261 iface =
new FakeStorage(
this);
263 case Solid::DeviceInterface::OpticalDrive:
264 iface =
new FakeCdrom(
this);
266 case Solid::DeviceInterface::StorageVolume:
267 iface =
new FakeVolume(
this);
269 case Solid::DeviceInterface::OpticalDisc:
270 iface =
new FakeOpticalDisc(
this);
272 case Solid::DeviceInterface::StorageAccess:
273 iface =
new FakeStorageAccess(
this);
275 case Solid::DeviceInterface::Camera:
276 iface =
new FakeCamera(
this);
278 case Solid::DeviceInterface::PortableMediaPlayer:
279 iface =
new FakePortableMediaPlayer(
this);
281 case Solid::DeviceInterface::Battery:
282 iface =
new FakeBattery(
this);
284 case Solid::DeviceInterface::NetworkShare:
285 iface =
new FakeNetworkShare(
this);
287 case Solid::DeviceInterface::Unknown:
289 case Solid::DeviceInterface::Last:
304#include "moc_fakedevice.cpp"
305#include "moc_fakedevice_p.cpp"
static QString typeToString(Type type)
Type
This enum type defines the type of device interface that a Device can have.
static Type stringToType(const QString &type)
This class allows applications to deal with devices available in the underlying system.
QString udi() const
Retrieves the Universal Device Identifier (UDI).
PropertyChange
This enum type defines the type of change that can occur to a GenericInterface property.
Type type(const QSqlDatabase &db)
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
QDBusConnection sessionBus()
void unregisterObject(const QString &path, UnregisterMode mode)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)