solid: remove unused Solid::GenericInterface

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-16 01:53:21 +03:00
parent c66d486a0e
commit 461b637c77
19 changed files with 47 additions and 565 deletions

View file

@ -26,7 +26,6 @@ set(solid_LIB_SRCS
device.cpp device.cpp
devicemanager.cpp devicemanager.cpp
deviceinterface.cpp deviceinterface.cpp
genericinterface.cpp
processor.cpp processor.cpp
block.cpp block.cpp
storagedrive.cpp storagedrive.cpp
@ -59,7 +58,6 @@ set(solid_LIB_SRCS
ifaces/device.cpp ifaces/device.cpp
ifaces/deviceinterface.cpp ifaces/deviceinterface.cpp
ifaces/devicemanager.cpp ifaces/devicemanager.cpp
ifaces/genericinterface.cpp
ifaces/networkinterface.cpp ifaces/networkinterface.cpp
ifaces/opticaldisc.cpp ifaces/opticaldisc.cpp
ifaces/portablemediaplayer.cpp ifaces/portablemediaplayer.cpp
@ -90,7 +88,6 @@ if(ENABLE_TESTING)
backends/fakehw/fakecdrom.cpp backends/fakehw/fakecdrom.cpp
backends/fakehw/fakedevice.cpp backends/fakehw/fakedevice.cpp
backends/fakehw/fakedeviceinterface.cpp backends/fakehw/fakedeviceinterface.cpp
backends/fakehw/fakegenericinterface.cpp
backends/fakehw/fakemanager.cpp backends/fakehw/fakemanager.cpp
backends/fakehw/fakenetworkinterface.cpp backends/fakehw/fakenetworkinterface.cpp
backends/fakehw/fakeopticaldisc.cpp backends/fakehw/fakeopticaldisc.cpp
@ -233,7 +230,6 @@ install(
device.h device.h
devicenotifier.h devicenotifier.h
deviceinterface.h deviceinterface.h
genericinterface.h
processor.h processor.h
block.h block.h
storageaccess.h storageaccess.h

View file

@ -20,7 +20,6 @@
#include "fakedevice.h" #include "fakedevice.h"
#include "fakedeviceinterface.h" #include "fakedeviceinterface.h"
#include "fakegenericinterface.h"
#include "fakeprocessor.h" #include "fakeprocessor.h"
#include "fakeblock.h" #include "fakeblock.h"
#include "fakestorage.h" #include "fakestorage.h"
@ -41,8 +40,6 @@
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtDBus/QDBusConnection> #include <QtDBus/QDBusConnection>
#include <solid/genericinterface.h>
#include "fakedevice_p.h" #include "fakedevice_p.h"
using namespace Solid::Backends::Fake; using namespace Solid::Backends::Fake;
@ -53,7 +50,6 @@ FakeDevice::FakeDevice(const QString &udi, const QMap<QString, QVariant> &proper
d->udi = udi; d->udi = udi;
d->propertyMap = propertyMap; d->propertyMap = propertyMap;
d->interfaceList = d->propertyMap["interfaces"].toString().simplified().split(','); d->interfaceList = d->propertyMap["interfaces"].toString().simplified().split(',');
d->interfaceList << "GenericInterface";
d->locked = false; d->locked = false;
d->broken = false; d->broken = false;
@ -69,8 +65,8 @@ FakeDevice::FakeDevice(const QString &udi, const QMap<QString, QVariant> &proper
createDeviceInterface(type); createDeviceInterface(type);
} }
connect(d.data(), SIGNAL(propertyChanged(QMap<QString,int>)), connect(d.data(), SIGNAL(propertyChanged(QStringList)),
this, SIGNAL(propertyChanged(QMap<QString,int>))); this, SIGNAL(propertyChanged(QStringList)));
connect(d.data(), SIGNAL(conditionRaised(QString,QString)), connect(d.data(), SIGNAL(conditionRaised(QString,QString)),
this, SIGNAL(conditionRaised(QString,QString))); this, SIGNAL(conditionRaised(QString,QString)));
} }
@ -78,8 +74,8 @@ FakeDevice::FakeDevice(const QString &udi, const QMap<QString, QVariant> &proper
FakeDevice::FakeDevice(const FakeDevice& dev) FakeDevice::FakeDevice(const FakeDevice& dev)
: Solid::Ifaces::Device(), d(dev.d) : Solid::Ifaces::Device(), d(dev.d)
{ {
connect(d.data(), SIGNAL(propertyChanged(QMap<QString,int>)), connect(d.data(), SIGNAL(propertyChanged(QStringList)),
this, SIGNAL(propertyChanged(QMap<QString,int>))); this, SIGNAL(propertyChanged(QStringList)));
connect(d.data(), SIGNAL(conditionRaised(QString,QString)), connect(d.data(), SIGNAL(conditionRaised(QString,QString)),
this, SIGNAL(conditionRaised(QString,QString))); this, SIGNAL(conditionRaised(QString,QString)));
} }
@ -168,17 +164,10 @@ bool FakeDevice::setProperty(const QString &key, const QVariant &value)
{ {
if (d->broken) return false; if (d->broken) return false;
Solid::GenericInterface::PropertyChange change_type = Solid::GenericInterface::PropertyModified;
if (!d->propertyMap.contains(key))
{
change_type = Solid::GenericInterface::PropertyAdded;
}
d->propertyMap[key] = value; d->propertyMap[key] = value;
QMap<QString,int> change; QStringList change;
change[key] = change_type; change.append(key);
emit d->propertyChanged(change); emit d->propertyChanged(change);
@ -191,8 +180,8 @@ bool FakeDevice::removeProperty(const QString &key)
d->propertyMap.remove(key); d->propertyMap.remove(key);
QMap<QString,int> change; QStringList change;
change[key] = Solid::GenericInterface::PropertyRemoved; change.append(key);
emit d->propertyChanged(change); emit d->propertyChanged(change);
@ -259,9 +248,6 @@ QObject *FakeDevice::createDeviceInterface(const Solid::DeviceInterface::Type &t
switch(type) switch(type)
{ {
case Solid::DeviceInterface::GenericInterface:
iface = new FakeGenericInterface(this);
break;
case Solid::DeviceInterface::Processor: case Solid::DeviceInterface::Processor:
iface = new FakeProcessor(this); iface = new FakeProcessor(this);
break; break;

View file

@ -24,6 +24,7 @@
#include <solid/ifaces/device.h> #include <solid/ifaces/device.h>
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtCore/QStringList>
#include <QtCore/QSharedPointer> #include <QtCore/QSharedPointer>
namespace Solid namespace Solid
@ -69,7 +70,7 @@ public:
virtual QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type); virtual QObject *createDeviceInterface(const Solid::DeviceInterface::Type &type);
Q_SIGNALS: Q_SIGNALS:
void propertyChanged(const QMap<QString,int> &changes); void propertyChanged(const QStringList &changes);
void conditionRaised(const QString &condition, const QString &reason); void conditionRaised(const QString &condition, const QString &reason);

View file

@ -44,7 +44,7 @@ public:
bool broken; bool broken;
Q_SIGNALS: Q_SIGNALS:
void propertyChanged(const QMap<QString,int> &changes); void propertyChanged(const QStringList &changes);
void conditionRaised(const QString &condition, const QString &reason); void conditionRaised(const QString &condition, const QString &reason);
friend class FakeDevice; friend class FakeDevice;

View file

@ -1,53 +0,0 @@
/*
Copyright 2007 Kevin Ottens <ervin@kde.org>
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 "fakegenericinterface.h"
using namespace Solid::Backends::Fake;
FakeGenericInterface::FakeGenericInterface(FakeDevice *device)
: FakeDeviceInterface(device)
{
connect(device, SIGNAL(propertyChanged(QMap<QString,int>)),
this, SIGNAL(propertyChanged(QMap<QString,int>)));
connect(device, SIGNAL(conditionRaised(QString,QString)),
this, SIGNAL(conditionRaised(QString,QString)));
}
FakeGenericInterface::~FakeGenericInterface()
{
}
QVariant FakeGenericInterface::property(const QString &key) const
{
return fakeDevice()->property(key);
}
QMap<QString, QVariant> FakeGenericInterface::allProperties() const
{
return fakeDevice()->allProperties();
}
bool FakeGenericInterface::propertyExists(const QString &key) const
{
return fakeDevice()->propertyExists(key);
}
#include "backends/fakehw/moc_fakegenericinterface.cpp"

View file

@ -1,54 +0,0 @@
/*
Copyright 2007 Kevin Ottens <ervin@kde.org>
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_FAKEGENERICINTERFACE_H
#define SOLID_BACKENDS_FAKEHW_FAKEGENERICINTERFACE_H
#include "fakedeviceinterface.h"
#include <solid/ifaces/genericinterface.h>
namespace Solid
{
namespace Backends
{
namespace Fake
{
class FakeGenericInterface : public FakeDeviceInterface, public Solid::Ifaces::GenericInterface
{
Q_OBJECT
Q_INTERFACES(Solid::Ifaces::GenericInterface)
public:
explicit FakeGenericInterface(FakeDevice *device);
~FakeGenericInterface();
virtual QVariant property(const QString &key) const;
virtual QMap<QString, QVariant> allProperties() const;
virtual bool propertyExists(const QString &key) const;
Q_SIGNALS:
void propertyChanged(const QMap<QString,int> &changes);
void conditionRaised(const QString &condition, const QString &reason);
};
}
}
}
#endif // SOLID_BACKENDS_FAKEHW_FAKEGENERICINTERFACE_H

View file

@ -53,8 +53,7 @@ FakeManager::FakeManager(QObject *parent, const QString &xmlFile)
parseMachineFile(); parseMachineFile();
d->supportedInterfaces << Solid::DeviceInterface::GenericInterface d->supportedInterfaces << Solid::DeviceInterface::Processor
<< Solid::DeviceInterface::Processor
<< Solid::DeviceInterface::Block << Solid::DeviceInterface::Block
<< Solid::DeviceInterface::StorageAccess << Solid::DeviceInterface::StorageAccess
<< Solid::DeviceInterface::StorageDrive << Solid::DeviceInterface::StorageDrive

View file

@ -25,8 +25,8 @@ using namespace Solid::Backends::Fake;
FakeStorageAccess::FakeStorageAccess(FakeDevice *device) FakeStorageAccess::FakeStorageAccess(FakeDevice *device)
: FakeDeviceInterface(device) : FakeDeviceInterface(device)
{ {
connect(device, SIGNAL(propertyChanged(QMap<QString,int>)), connect(device, SIGNAL(propertyChanged(QStringList)),
this, SLOT(onPropertyChanged(QMap<QString,int>))); this, SLOT(onPropertyChanged(QStringList)));
} }
FakeStorageAccess::~FakeStorageAccess() FakeStorageAccess::~FakeStorageAccess()
@ -70,9 +70,9 @@ bool FakeStorageAccess::teardown()
} }
} }
void Solid::Backends::Fake::FakeStorageAccess::onPropertyChanged(const QMap<QString,int> &changes) void Solid::Backends::Fake::FakeStorageAccess::onPropertyChanged(const QStringList &changes)
{ {
foreach (const QString &property, changes.keys()) { foreach (const QString &property, changes) {
if (property=="isMounted") { if (property=="isMounted") {
emit accessibilityChanged(fakeDevice()->property("isMounted").toBool(), fakeDevice()->udi()); emit accessibilityChanged(fakeDevice()->property("isMounted").toBool(), fakeDevice()->udi());
} }

View file

@ -54,7 +54,7 @@ Q_SIGNALS:
void teardownRequested(const QString &udi); void teardownRequested(const QString &udi);
private Q_SLOTS: private Q_SLOTS:
void onPropertyChanged(const QMap<QString,int> &changes); void onPropertyChanged(const QStringList &changes);
}; };
} }
} }

View file

@ -28,8 +28,6 @@
#include <solid/ifaces/device.h> #include <solid/ifaces/device.h>
#include <solid/genericinterface.h>
#include <solid/ifaces/genericinterface.h>
#include <solid/processor.h> #include <solid/processor.h>
#include <solid/ifaces/processor.h> #include <solid/ifaces/processor.h>
#include <solid/block.h> #include <solid/block.h>
@ -171,9 +169,6 @@ const Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInter
{ {
switch (type) switch (type)
{ {
case DeviceInterface::GenericInterface:
iface = deviceinterface_cast(Ifaces::GenericInterface, GenericInterface, dev_iface);
break;
case DeviceInterface::Processor: case DeviceInterface::Processor:
iface = deviceinterface_cast(Ifaces::Processor, Processor, dev_iface); iface = deviceinterface_cast(Ifaces::Processor, Processor, dev_iface);
break; break;

View file

@ -67,8 +67,6 @@ QString Solid::DeviceInterface::typeDescription(Type type)
{ {
case Unknown: case Unknown:
return QObject::tr("Unknown"); return QObject::tr("Unknown");
case GenericInterface:
return QObject::tr("Generic Interface");
case Processor: case Processor:
return QObject::tr("Processor"); return QObject::tr("Processor");
case Block: case Block:

View file

@ -61,13 +61,26 @@ namespace Solid
* - NetworkInterface: A network interface * - NetworkInterface: A network interface
* - Graphic: A graphic interface * - Graphic: A graphic interface
*/ */
enum Type { Unknown = 0, GenericInterface = 1, Processor = 2, enum Type {
Block = 3, StorageAccess = 4, StorageDrive = 5, Unknown = 0,
OpticalDrive = 6, StorageVolume = 7, OpticalDisc = 8, Processor = 1,
Camera = 9, PortableMediaPlayer = 10, Block = 2,
NetworkInterface = 11, AcAdapter = 12, Battery = 13, StorageAccess = 3,
Button = 14, AudioInterface = 15, Video = 16, StorageDrive = 4,
Graphic = 17, Last = 0xffff }; OpticalDrive = 5,
StorageVolume = 6,
OpticalDisc = 7,
Camera = 8,
PortableMediaPlayer = 9,
NetworkInterface = 10,
AcAdapter = 11,
Battery = 12,
Button = 13,
AudioInterface = 14,
Video = 15,
Graphic = 16,
Last = 0xffff
};
/** /**
* Destroys a DeviceInterface object. * Destroys a DeviceInterface object.

View file

@ -1,63 +0,0 @@
/*
Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
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 "genericinterface.h"
#include "genericinterface_p.h"
#include "soliddefs_p.h"
#include <solid/ifaces/genericinterface.h>
Solid::GenericInterface::GenericInterface(QObject *backendObject)
: DeviceInterface(*new GenericInterfacePrivate(), backendObject)
{
if (backendObject) {
connect(backendObject, SIGNAL(propertyChanged(QMap<QString,int>)),
this, SIGNAL(propertyChanged(QMap<QString,int>)));
connect(backendObject, SIGNAL(conditionRaised(QString,QString)),
this, SIGNAL(conditionRaised(QString,QString)));
}
}
Solid::GenericInterface::~GenericInterface()
{
}
QVariant Solid::GenericInterface::property(const QString &key) const
{
Q_D(const GenericInterface);
return_SOLID_CALL(Ifaces::GenericInterface *, d->backendObject(), QVariant(), property(key));
}
QMap<QString, QVariant> Solid::GenericInterface::allProperties() const
{
Q_D(const GenericInterface);
return_SOLID_CALL(Ifaces::GenericInterface *, d->backendObject(), QVariantMap(), allProperties());
}
bool Solid::GenericInterface::propertyExists(const QString &key) const
{
Q_D(const GenericInterface);
return_SOLID_CALL(Ifaces::GenericInterface *, d->backendObject(), false, propertyExists(key));
}
#include "moc_genericinterface.cpp"

View file

@ -1,150 +0,0 @@
/*
Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
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_GENERICINTERFACE_H
#define SOLID_GENERICINTERFACE_H
#include <QtCore/QMap>
#include <QtCore/QVariant>
#include <solid/solid_export.h>
#include <solid/deviceinterface.h>
namespace Solid
{
class GenericInterfacePrivate;
class Device;
/**
* Generic interface to deal with a device. It exposes a set of properties
* and is organized as a key/value set.
*
* Warning: Using this class could expose some backend specific details
* and lead to non portable code. Use it at your own risk, or during
* transitional phases when the provided device interfaces don't
* provide the necessary methods.
*/
class SOLID_EXPORT GenericInterface : public DeviceInterface
{
Q_OBJECT
Q_ENUMS(PropertyChange)
Q_DECLARE_PRIVATE(GenericInterface)
friend class Device;
public:
/**
* This enum type defines the type of change that can occur to a GenericInterface
* property.
*
* - PropertyModified : A property value has changed in the device
* - PropertyAdded : A new property has been added to the device
* - PropertyRemoved : A property has been removed from the device
*/
enum PropertyChange { PropertyModified, PropertyAdded, PropertyRemoved };
private:
/**
* Creates a new GenericInterface 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 GenericInterface(QObject *backendObject);
public:
/**
* Destroys a Processor object.
*/
virtual ~GenericInterface();
/**
* Get the Solid::DeviceInterface::Type of the GenericInterface device interface.
*
* @return the Processor device interface type
* @see Solid::Ifaces::Enums::DeviceInterface::Type
*/
static Type deviceInterfaceType() { return DeviceInterface::GenericInterface; }
/**
* Retrieves a property of the device.
*
* Warning: Using this method could expose some backend specific details
* and lead to non portable code. Use it at your own risk, or during
* transitional phases when the provided device interfaces don't
* provide the necessary methods.
*
* @param key the property key
* @return the actual value of the property, or QVariant() if the
* property is unknown
*/
QVariant property(const QString &key) const;
/**
* Retrieves a key/value map of all the known properties for the device.
*
* Warning: Using this method could expose some backend specific details
* and lead to non portable code. Use it at your own risk, or during
* transitional phases when the provided device interfaces don't
* provide the necessary methods.
*
* @return all the properties of the device
*/
QMap<QString, QVariant> allProperties() const;
/**
* Tests if a property exist in the device.
*
* Warning: Using this method could expose some backend specific details
* and lead to non portable code. Use it at your own risk, or during
* transitional phases when the provided device interfaces don't
* provide the necessary methods.
*
* @param key the property key
* @return true if the property is available in the device, false
* otherwise
*/
bool propertyExists(const QString &key) const;
Q_SIGNALS:
/**
* This signal is emitted when a property is changed in the device.
*
* @param changes the map describing the property changes that
* occurred in the device, keys are property name and values
* describe the kind of change done on the device property
* (added/removed/modified), it's one of the type Solid::Device::PropertyChange
*/
void propertyChanged(const QMap<QString,int> &changes);
/**
* This signal is emitted when an event occurred in the device.
* For example when a button is pressed.
*
* @param condition the condition name
* @param reason a message explaining why the condition has been raised
*/
void conditionRaised(const QString &condition, const QString &reason);
};
}
#endif

View file

@ -1,36 +0,0 @@
/*
Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
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_GENERICINTERFACE_P_H
#define SOLID_GENERICINTERFACE_P_H
#include "deviceinterface_p.h"
namespace Solid
{
class GenericInterfacePrivate : public DeviceInterfacePrivate
{
public:
GenericInterfacePrivate()
: DeviceInterfacePrivate() { }
};
}
#endif

View file

@ -1,26 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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 "genericinterface.h"
Solid::Ifaces::GenericInterface::~GenericInterface()
{
}

View file

@ -1,98 +0,0 @@
/*
Copyright 2006 Kevin Ottens <ervin@kde.org>
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_GENERICINTERFACE_H
#define SOLID_IFACES_GENERICINTERFACE_H
#include <QtCore/QObject>
#include <QtCore/QMap>
#include <QtCore/QVariant>
namespace Solid
{
namespace Ifaces
{
/**
* Generic interface to deal with a device. It exposes a set of properties
* and is organized a a key/value set.
*
* Warning: Using this class could expose some backend specific details
* and lead to non portable code. Use it at your own risk, or during
* transitional phases when the provided device interfaces don't
* provide the necessary methods.
*/
class GenericInterface
{
public:
/**
* Destroys a GenericInterface object.
*/
virtual ~GenericInterface();
/**
* Retrieves the value of a property.
*
* @param key the property name
* @returns the property value or QVariant() if the property doesn't exist
*/
virtual QVariant property(const QString &key) const = 0;
/**
* Retrieves all the properties of this device.
*
* @returns all properties in a map
*/
virtual QMap<QString, QVariant> allProperties() const = 0;
/**
* Tests if a property exist.
*
* @param key the property name
* @returns true if the property exists in this device, false otherwise
*/
virtual bool propertyExists(const QString &key) const = 0;
protected:
//Q_SIGNALS:
/**
* This signal is emitted when a property is changed in the device.
*
* @param changes the map describing the property changes that
* occurred in the device, keys are property name and values
* describe the kind of change done on the device property
* (added/removed/modified), it's one of the type Solid::Device::PropertyChange
*/
virtual void propertyChanged(const QMap<QString,int> &changes) = 0;
/**
* This signal is emitted when an event occurred in the device.
* For example when a button is pressed.
*
* @param condition the condition name
* @param reason a message explaining why the condition has been raised
*/
virtual void conditionRaised(const QString &condition, const QString &reason) = 0;
};
}
}
Q_DECLARE_INTERFACE(Solid::Ifaces::GenericInterface, "org.kde.Solid.Ifaces.GenericInterface/0.1")
#endif

View file

@ -24,7 +24,6 @@
#include <solid/devicenotifier.h> #include <solid/devicenotifier.h>
#include <solid/device.h> #include <solid/device.h>
#include <solid/genericinterface.h>
#include <solid/processor.h> #include <solid/processor.h>
#include <solid/storageaccess.h> #include <solid/storageaccess.h>
#include <solid/storagevolume.h> #include <solid/storagevolume.h>
@ -86,26 +85,9 @@ void SolidHwTest::testDeviceBasicFeatures()
invalid_dev = Solid::Device(); invalid_dev = Solid::Device();
QCOMPARE(invalid_dev.isValid(), false); QCOMPARE(invalid_dev.isValid(), false);
QCOMPARE(valid_dev.udi(), QString("/org/kde/solid/fakehw/storage_model_solid_writer")); QCOMPARE(valid_dev.udi(), QString("/org/kde/solid/fakehw/storage_model_solid_writer"));
QCOMPARE(invalid_dev.udi(), QString()); QCOMPARE(invalid_dev.udi(), QString());
// Query properties
QCOMPARE(valid_dev.as<Solid::GenericInterface>()->propertyExists("name"), true);
QCOMPARE(valid_dev.as<Solid::GenericInterface>()->propertyExists("foo.bar"), false);
QCOMPARE((QObject *)invalid_dev.as<Solid::GenericInterface>(), (QObject *)0);
QCOMPARE(valid_dev.as<Solid::GenericInterface>()->property("name"), QVariant("Solid IDE DVD Writer"));
QVERIFY(!valid_dev.as<Solid::GenericInterface>()->property("foo.bar").isValid());
Solid::Backends::Fake::FakeDevice *fake_device = fakeManager->findDevice("/org/kde/solid/fakehw/storage_model_solid_writer");
QMap<QString, QVariant> expected_properties = fake_device->allProperties();
QCOMPARE(valid_dev.as<Solid::GenericInterface>()->allProperties(), expected_properties);
// Query device interfaces // Query device interfaces
QCOMPARE(valid_dev.isDeviceInterface(Solid::DeviceInterface::StorageDrive), true); QCOMPARE(valid_dev.isDeviceInterface(Solid::DeviceInterface::StorageDrive), true);
QCOMPARE(valid_dev.isDeviceInterface(Solid::DeviceInterface::OpticalDrive), true); QCOMPARE(valid_dev.isDeviceInterface(Solid::DeviceInterface::OpticalDrive), true);
@ -168,9 +150,9 @@ void SolidHwTest::testDeviceSignals()
Solid::Device device("/org/kde/solid/fakehw/acpi_LID0"); Solid::Device device("/org/kde/solid/fakehw/acpi_LID0");
// We'll spy our button // We'll spy our button
connect(device.as<Solid::GenericInterface>(), SIGNAL(propertyChanged(QMap<QString,int>)), connect(fake, SIGNAL(propertyChanged(QStringList)),
this, SLOT(slotPropertyChanged(QMap<QString,int>))); this, SLOT(slotPropertyChanged(QStringList)));
QSignalSpy condition_raised(device.as<Solid::GenericInterface>(), SIGNAL(conditionRaised(QString,QString))); QSignalSpy condition_raised(fake, SIGNAL(conditionRaised(QString,QString)));
fake->setProperty("stateValue", true); // The button is now pressed (modified property) fake->setProperty("stateValue", true); // The button is now pressed (modified property)
fake->raiseCondition("Lid Closed", "Why not?"); // Since it's a LID we notify this change fake->raiseCondition("Lid Closed", "Why not?"); // Since it's a LID we notify this change
@ -180,27 +162,22 @@ void SolidHwTest::testDeviceSignals()
// 3 property changes occurred in the device // 3 property changes occurred in the device
QCOMPARE(m_changesList.count(), 3); QCOMPARE(m_changesList.count(), 3);
QMap<QString,int> changes; QStringList changes;
// First one is a "PropertyModified" for "button.state" // First one is a property modification for "button.state"
changes = m_changesList.at(0); changes = m_changesList.at(0);
QCOMPARE(changes.count(), 1); QCOMPARE(changes.count(), 1);
QVERIFY(changes.contains("stateValue")); QVERIFY(changes.contains("stateValue"));
QCOMPARE(changes["stateValue"], (int)Solid::GenericInterface::PropertyModified);
// Second one is a "PropertyAdded" for "hactar" // Second one is a property added for "hactar"
changes = m_changesList.at(1); changes = m_changesList.at(1);
QCOMPARE(changes.count(), 1); QCOMPARE(changes.count(), 1);
QVERIFY(changes.contains("hactar")); QVERIFY(changes.contains("hactar"));
QCOMPARE(changes["hactar"], (int)Solid::GenericInterface::PropertyAdded);
// Third one is a "PropertyRemoved" for "hactar" // Third one is a property removed for "hactar"
changes = m_changesList.at(2); changes = m_changesList.at(2);
QCOMPARE(changes.count(), 1); QCOMPARE(changes.count(), 1);
QVERIFY(changes.contains("hactar")); QVERIFY(changes.contains("hactar"));
QCOMPARE(changes["hactar"], (int)Solid::GenericInterface::PropertyRemoved);
// Only one condition has been raised in the device // Only one condition has been raised in the device
QCOMPARE(condition_raised.count(), 1); QCOMPARE(condition_raised.count(), 1);
@ -242,7 +219,6 @@ void SolidHwTest::testDeviceInterfaces()
Solid::Device cpu2("/org/kde/solid/fakehw/acpi_CPU0"); Solid::Device cpu2("/org/kde/solid/fakehw/acpi_CPU0");
QCOMPARE(cpu.as<Solid::Processor>(), cpu2.as<Solid::Processor>()); QCOMPARE(cpu.as<Solid::Processor>(), cpu2.as<Solid::Processor>());
QCOMPARE(cpu.as<Solid::GenericInterface>(), cpu2.as<Solid::GenericInterface>());
QPointer<Solid::Processor> p = cpu.as<Solid::Processor>(); QPointer<Solid::Processor> p = cpu.as<Solid::Processor>();
QVERIFY(p!=0); QVERIFY(p!=0);
@ -481,7 +457,7 @@ void SolidHwTest::testSetupTeardown()
} }
void SolidHwTest::slotPropertyChanged(const QMap<QString,int> &changes) void SolidHwTest::slotPropertyChanged(const QStringList &changes)
{ {
m_changesList << changes; m_changesList << changes;
} }
@ -496,7 +472,6 @@ void SolidHwTest::slotPropertyChanged(const QMap<QString,int> &changes)
QVERIFY(device.isDeviceInterface(DEVIFACE)); \ QVERIFY(device.isDeviceInterface(DEVIFACE)); \
QVERIFY(iface != 0); \ QVERIFY(iface != 0); \
QCOMPARE(iface, iface2); \ QCOMPARE(iface, iface2); \
QCOMPARE(device.as<Solid::GenericInterface>(), device.as<Solid::GenericInterface>()); \
\ \
QPointer<SOLIFACE> p = device.as<SOLIFACE>(); \ QPointer<SOLIFACE> p = device.as<SOLIFACE>(); \
QVERIFY(p != 0); \ QVERIFY(p != 0); \
@ -536,4 +511,3 @@ void SolidHwTest::testMisc()
} }
#include "moc_solidhwtest.cpp" #include "moc_solidhwtest.cpp"

View file

@ -50,10 +50,10 @@ private slots:
void testSetupTeardown(); void testSetupTeardown();
void testMisc(); void testMisc();
void slotPropertyChanged(const QMap<QString,int> &changes); void slotPropertyChanged(const QStringList &changes);
private: private:
Solid::Backends::Fake::FakeManager *fakeManager; Solid::Backends::Fake::FakeManager *fakeManager;
QList< QMap<QString,int> > m_changesList; QList<QStringList> m_changesList;
}; };
#endif #endif