Commit 0ce6ea52 authored by Dāvis Mosāns's avatar Dāvis Mosāns Committed by Harald Sitter
Browse files

Fix empty UDS_NAME for MTP

parent 38a62116
Pipeline #191108 passed with stage
in 2 minutes
......@@ -190,14 +190,14 @@ void MTPSlave::listDir(const QUrl &url)
if (pathItems.isEmpty()) {
qCDebug(LOG_KIO_MTP) << "Root directory, listing devices";
totalSize(filesize_t(m_kmtpDaemon.devices().size()));
const auto devices = m_kmtpDaemon.devices();
totalSize(filesize_t(devices.size()));
for (const KMTPDeviceInterface *device : devices) {
listEntry(getEntry(device));
}
qCDebug(LOG_KIO_MTP) << "[SUCCESS] :: Devices:" << m_kmtpDaemon.devices().size();
qCDebug(LOG_KIO_MTP) << "[SUCCESS] :: Devices:" << devices.size();
finished();
return;
}
......
......@@ -179,9 +179,9 @@ void KMTPd::deviceRemoved(const QString &udi)
}
});
Q_EMIT devicesChanged();
m_devices.removeOne(device);
delete device;
Q_EMIT devicesChanged();
}
}
......
......@@ -18,6 +18,8 @@ KMTPDInterface::KMTPDInterface(QObject *parent)
QDBusConnection::sessionBus());
updateDevices();
// sadly this isn't usable for device removal because we don't receive it then
// connect(m_dbusInterface, &org::kde::kmtp::Daemon::devicesChanged, this, &KMTPDInterface::updateDevices);
}
bool KMTPDInterface::isValid() const
......@@ -25,8 +27,9 @@ bool KMTPDInterface::isValid() const
return m_dbusInterface->isValid();
}
KMTPDeviceInterface *KMTPDInterface::deviceFromName(const QString &friendlyName) const
KMTPDeviceInterface *KMTPDInterface::deviceFromName(const QString &friendlyName)
{
updateDevices();
auto deviceIt = std::find_if(m_devices.constBegin(), m_devices.constEnd(), [friendlyName] (const KMTPDeviceInterface *device) {
return device->friendlyName() == friendlyName;
});
......@@ -34,8 +37,9 @@ KMTPDeviceInterface *KMTPDInterface::deviceFromName(const QString &friendlyName)
return deviceIt == m_devices.constEnd() ? nullptr : *deviceIt;
}
KMTPDeviceInterface *KMTPDInterface::deviceFromUdi(const QString &udi) const
KMTPDeviceInterface *KMTPDInterface::deviceFromUdi(const QString &udi)
{
updateDevices();
auto deviceIt = std::find_if(m_devices.constBegin(), m_devices.constEnd(), [udi] (const KMTPDeviceInterface *device) {
return device->udi() == udi;
});
......@@ -43,8 +47,10 @@ KMTPDeviceInterface *KMTPDInterface::deviceFromUdi(const QString &udi) const
return deviceIt == m_devices.constEnd() ? nullptr : *deviceIt;
}
QVector<KMTPDeviceInterface *> KMTPDInterface::devices() const
QVector<KMTPDeviceInterface *> KMTPDInterface::devices()
{
// have to always update because we don't receive signal for device removal
updateDevices();
return m_devices;
}
......
......@@ -29,10 +29,10 @@ public:
bool isValid() const;
KMTPDeviceInterface *deviceFromName(const QString &friendlyName) const;
KMTPDeviceInterface *deviceFromUdi(const QString &udi) const;
KMTPDeviceInterface *deviceFromName(const QString &friendlyName);
KMTPDeviceInterface *deviceFromUdi(const QString &udi);
QVector<KMTPDeviceInterface *> devices() const;
QVector<KMTPDeviceInterface *> devices();
// D-Bus properties
QString version() const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment