generic: add new signal to solid device manager

its use case is shown in KFilePlacesModel, basically when a CD-ROM is
ejected it will be removed from the items in the model and when disc is
inserted item for it will be added to the model. Dolphin and Plasma require
changes of their own for this behaviour to be consistent across
applications

naming the method after OpticalDisc::availableContent(), have in mind it
should work when a disc is erased and written to for example or when a
device is formatted and no longer has filesystem which has not been tested
but in theory should work. may need additional checks for encrypted device
but that can be done in the future

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-06-09 23:54:30 +03:00
parent 8842c7f462
commit 9e554f60fa
8 changed files with 50 additions and 0 deletions

View file

@ -79,6 +79,7 @@ public:
void _k_initDeviceList();
void _k_deviceAdded(const QString &udi);
void _k_deviceRemoved(const QString &udi);
void _k_contentChanged(const QString &udi, const bool hascontent);
void _k_itemChanged(const QString &udi);
void _k_reloadBookmarks();
void _k_storageSetupDone(Solid::ErrorType error, QVariant errorData);
@ -304,6 +305,8 @@ void KFilePlacesModel::Private::_k_initDeviceList()
q, SLOT(_k_deviceAdded(QString)));
connect(notifier, SIGNAL(deviceRemoved(QString)),
q, SLOT(_k_deviceRemoved(QString)));
connect(notifier, SIGNAL(contentChanged(QString,bool)),
q, SLOT(_k_contentChanged(QString,bool)));
const QList<Solid::Device> &deviceList = Solid::Device::listFromQuery(predicate);
@ -332,6 +335,15 @@ void KFilePlacesModel::Private::_k_deviceRemoved(const QString &udi)
}
}
void KFilePlacesModel::Private::_k_contentChanged(const QString &udi, const bool hascontent)
{
if (hascontent) {
_k_deviceAdded(udi);
} else {
_k_deviceRemoved(udi);
}
}
void KFilePlacesModel::Private::_k_itemChanged(const QString &id)
{
for (int row = 0; row<items.size(); ++row) {

View file

@ -138,6 +138,7 @@ private:
Q_PRIVATE_SLOT(d, void _k_initDeviceList())
Q_PRIVATE_SLOT(d, void _k_deviceAdded(const QString&))
Q_PRIVATE_SLOT(d, void _k_deviceRemoved(const QString&))
Q_PRIVATE_SLOT(d, void _k_contentChanged(const QString&, const bool))
Q_PRIVATE_SLOT(d, void _k_itemChanged(const QString&))
Q_PRIVATE_SLOT(d, void _k_reloadBookmarks())
Q_PRIVATE_SLOT(d, void _k_storageSetupDone(Solid::ErrorType, QVariant))

View file

@ -179,6 +179,7 @@ UDevManager::UDevManager(QObject *parent)
{
connect(d->m_client, SIGNAL(deviceAdded(UdevQt::Device)), this, SLOT(slotDeviceAdded(UdevQt::Device)));
connect(d->m_client, SIGNAL(deviceRemoved(UdevQt::Device)), this, SLOT(slotDeviceRemoved(UdevQt::Device)));
connect(d->m_client, SIGNAL(deviceChanged(UdevQt::Device)), this, SLOT(slotDeviceChanged(UdevQt::Device)));
d->m_supportedInterfaces << Solid::DeviceInterface::GenericInterface
<< Solid::DeviceInterface::StorageAccess
@ -292,3 +293,13 @@ void UDevManager::slotDeviceRemoved(const UdevQt::Device &device)
d->m_devicesOfInterest.removeAll(udiPrefix() + device.sysfsPath());
}
}
void UDevManager::slotDeviceChanged(const UdevQt::Device &device)
{
if (d->isOfInterest(udiPrefix() + device.sysfsPath(), device)) {
if (device.subsystem() == "block") {
const QString idfsusage = device.deviceProperty("ID_FS_USAGE").toString();
emit contentChanged(udiPrefix() + device.sysfsPath(), (idfsusage == "filesystem"));
}
}
}

View file

@ -52,6 +52,7 @@ public:
private Q_SLOTS:
void slotDeviceAdded(const UdevQt::Device &device);
void slotDeviceRemoved(const UdevQt::Device &device);
void slotDeviceChanged(const UdevQt::Device &device);
private:
class Private;

View file

@ -45,6 +45,8 @@ Solid::DeviceManagerPrivate::DeviceManagerPrivate()
this, SLOT(_k_deviceAdded(QString)));
connect(backend, SIGNAL(deviceRemoved(QString)),
this, SLOT(_k_deviceRemoved(QString)));
connect(backend, SIGNAL(contentChanged(QString,bool)),
this, SLOT(_k_contentChanged(QString,bool)));
}
}
@ -209,6 +211,11 @@ void Solid::DeviceManagerPrivate::_k_deviceRemoved(const QString &udi)
emit deviceRemoved(udi);
}
void Solid::DeviceManagerPrivate::_k_contentChanged(const QString &udi, const bool hascontent)
{
emit contentChanged(udi, hascontent);
}
void Solid::DeviceManagerPrivate::_k_destroyed(QObject *object)
{
QString udi = m_reverseMap.take(object);

View file

@ -50,6 +50,7 @@ namespace Solid
private Q_SLOTS:
void _k_deviceAdded(const QString &udi);
void _k_deviceRemoved(const QString &udi);
void _k_contentChanged(const QString &udi, const bool hasContent);
void _k_destroyed(QObject *object);
private:

View file

@ -59,6 +59,15 @@ namespace Solid
* @param udi the old device UDI
*/
void deviceRemoved(const QString &udi);
/**
* This signal is emitted when a device content changes, e.g. CD-ROM eject.
*
* @param udi the device UDI
* @param hasContent the device has/does not have content
*/
void contentChanged(const QString &udi, const bool hasContent);
};
}

View file

@ -108,6 +108,14 @@ namespace Ifaces
* @param udi the old device identifier
*/
void deviceRemoved(const QString &udi);
/**
* This signal is emitted when a device content changes, e.g. CD-ROM eject.
*
* @param udi the device UDI
* @param hasContent the device has/does not have content
*/
void contentChanged(const QString &udi, const bool hasContent);
};
}
}