Refresh list of local devices when list of mount points changes.

BUG:127
This commit is contained in:
craig.p.drummond
2012-11-06 16:46:46 +00:00
committed by craig.p.drummond
parent 1512602128
commit 780fc3720b

View File

@@ -331,8 +331,8 @@ void DevicesModel::setEnabled(bool e)
connect(Covers::self(), SIGNAL(cover(const Song &, const QImage &, const QString &)),
this, SLOT(setCover(const Song &, const QImage &, const QString &)));
loadLocal();
#ifdef ENABLE_REMOTE_DEVICES
connect(MountPoints::self(), SIGNAL(updated()), this, SLOT(mountsChanged()));
#ifdef ENABLE_REMOTE_DEVICES
loadRemote();
#endif
} else {
@@ -340,9 +340,7 @@ void DevicesModel::setEnabled(bool e)
disconnect(Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(const QString &)), this, SLOT(deviceRemoved(const QString &)));
disconnect(Covers::self(), SIGNAL(cover(const Song &, const QImage &, const QString &)),
this, SLOT(setCover(const Song &, const QImage &, const QString &)));
#ifdef ENABLE_REMOTE_DEVICES
disconnect(MountPoints::self(), SIGNAL(updated()), this, SLOT(mountsChanged()));
#endif
clear();
}
inhibitMenuUpdate=false;
@@ -681,16 +679,26 @@ void DevicesModel::mountsChanged()
}
#endif
// This was here to fix BUG:127, but seems to not be required. If it is required, then connect/disconnect of this
// slot needs to be outside of the #ifdef ENABLE_REMOTE_DEVICES section in setEnabled()
// loadLocal();
// For some reason if a device without a partition (e.g. /dev/sdc) is mounted whilst cantata is running, then we receive no deviceAdded signal
// So, as a work-around, each time a device is mounted - check for all local devices. :-)
// BUG:127
loadLocal();
}
void DevicesModel::loadLocal()
{
// Build set of currently known MTP/UMS devices...
QSet<QString> existingUdis;
foreach (const Device *dev, devices) {
if (Device::Mtp==dev->devType() || Device::Ums==dev->devType()) {
existingUdis.insert(dev->udi());
}
}
QList<Solid::Device> deviceList = Solid::Device::listFromType(Solid::DeviceInterface::PortableMediaPlayer);
foreach (const Solid::Device &device, deviceList) {
if (indexOf(device.udi())>=0) {
if (existingUdis.contains(device.udi())) {
existingUdis.remove(device.udi());
continue;
}
if (device.as<Solid::StorageDrive>()) {
@@ -703,7 +711,8 @@ void DevicesModel::loadLocal()
deviceList = Solid::Device::listFromType(Solid::DeviceInterface::StorageAccess);
foreach (const Solid::Device &device, deviceList)
{
if (indexOf(device.udi())>=0) {
if (existingUdis.contains(device.udi())) {
existingUdis.remove(device.udi());
continue;
}
DBUG << "Solid::StorageAccess with udi:" << device.udi() << "product:" << device.product() << "vendor:" << device.vendor();
@@ -722,6 +731,12 @@ void DevicesModel::loadLocal()
addLocalDevice(device.udi());
}
}
// Remove any previous MTP/UMS devices that were not listed above.
// This is to fix BUG:127
foreach (const QString &udi, existingUdis) {
deviceRemoved(udi);
}
}
#ifdef ENABLE_REMOTE_DEVICES