Fix reading device events
* Fix logic error that prevented the `devStatusChanged()` event from being emitted when a device has connected * Fix reading device ID from event data
This commit is contained in:
parent
2fab93a00a
commit
ae319f604b
|
@ -1976,20 +1976,26 @@ void SyncthingConnection::readDeviceEvent(SyncthingEventId eventId, DateTime eve
|
|||
if (eventId < m_lastConnectionsUpdateEvent) {
|
||||
return;
|
||||
}
|
||||
const QString dev(eventData.value(QLatin1String("device")).toString());
|
||||
if (dev.isEmpty()) {
|
||||
const auto devId = [&eventData] {
|
||||
const auto dev = eventData.value(QLatin1String("device")).toString();
|
||||
if (!dev.isEmpty()) {
|
||||
return dev;
|
||||
}
|
||||
return eventData.value(QLatin1String("id")).toString();
|
||||
}();
|
||||
if (devId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// handle "DeviceRejected"-event
|
||||
if (eventType == QLatin1String("DeviceRejected")) {
|
||||
readDevRejected(eventTime, dev, eventData);
|
||||
readDevRejected(eventTime, devId, eventData);
|
||||
return;
|
||||
}
|
||||
|
||||
// find relevant device info
|
||||
int index;
|
||||
auto *const devInfo(findDevInfo(dev, index));
|
||||
auto *const devInfo = findDevInfo(devId, index);
|
||||
if (!devInfo) {
|
||||
return;
|
||||
}
|
||||
|
@ -1998,7 +2004,7 @@ void SyncthingConnection::readDeviceEvent(SyncthingEventId eventId, DateTime eve
|
|||
SyncthingDevStatus status = devInfo->status;
|
||||
bool paused = devInfo->paused;
|
||||
if (eventType == QLatin1String("DeviceConnected")) {
|
||||
devInfo->setConnectedStateAccordingToCompletion();
|
||||
status = devInfo->computeConnectedStateAccordingToCompletion();
|
||||
} else if (eventType == QLatin1String("DeviceDisconnected")) {
|
||||
status = SyncthingDevStatus::Disconnected;
|
||||
} else if (eventType == QLatin1String("DevicePaused")) {
|
||||
|
|
|
@ -35,7 +35,8 @@ struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingDev {
|
|||
explicit SyncthingDev(const QString &id = QString(), const QString &name = QString());
|
||||
QString statusString() const;
|
||||
bool isConnected() const;
|
||||
void setConnectedStateAccordingToCompletion();
|
||||
SyncthingDevStatus computeConnectedStateAccordingToCompletion() const;
|
||||
SyncthingDevStatus setConnectedStateAccordingToCompletion();
|
||||
const QString displayName() const;
|
||||
|
||||
QString id;
|
||||
|
@ -76,9 +77,14 @@ inline bool SyncthingDev::isConnected() const
|
|||
}
|
||||
}
|
||||
|
||||
inline void SyncthingDev::setConnectedStateAccordingToCompletion()
|
||||
inline SyncthingDevStatus SyncthingDev::computeConnectedStateAccordingToCompletion() const
|
||||
{
|
||||
status = overallCompletion.needed.isNull() ? SyncthingDevStatus::Idle : SyncthingDevStatus::Synchronizing;
|
||||
return overallCompletion.needed.isNull() ? SyncthingDevStatus::Idle : SyncthingDevStatus::Synchronizing;
|
||||
}
|
||||
|
||||
inline SyncthingDevStatus SyncthingDev::setConnectedStateAccordingToCompletion()
|
||||
{
|
||||
return status = computeConnectedStateAccordingToCompletion();
|
||||
}
|
||||
|
||||
inline const QString SyncthingDev::displayName() const
|
||||
|
|
Loading…
Reference in New Issue