diff --git a/models/devicesmodel.cpp b/models/devicesmodel.cpp index 55fe4031d..de308f1a8 100644 --- a/models/devicesmodel.cpp +++ b/models/devicesmodel.cpp @@ -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 existingUdis; + foreach (const Device *dev, devices) { + if (Device::Mtp==dev->devType() || Device::Ums==dev->devType()) { + existingUdis.insert(dev->udi()); + } + } + QList 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()) { @@ -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