diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-09-17 14:38:20 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-09-18 14:01:05 -0700 |
commit | 09ded17e1cae66e1aef95cbe5c3b86dd196c9be9 (patch) | |
tree | 61d49c229e07d24c2ec8f47cb2afd82445e77859 /divecomputer.cpp | |
parent | ca6f2c238aec0fd9dc0b12fad2df4028cf097fbb (diff) | |
download | subsurface-09ded17e1cae66e1aef95cbe5c3b86dd196c9be9.tar.gz |
Fix divecomputer nickname handling
Don't overwrite existing data.
[Dirk Hohndel: rewrote this a litte, but the logic is the same]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divecomputer.cpp')
-rw-r--r-- | divecomputer.cpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/divecomputer.cpp b/divecomputer.cpp index b45b74a44..af54e13f5 100644 --- a/divecomputer.cpp +++ b/divecomputer.cpp @@ -58,25 +58,41 @@ const DiveComputerNode *DiveComputerList::get(const QString &m) return NULL; } -void DiveComputerList::addDC(const QString &m, uint32_t d, const QString &n, const QString &s, const QString &f) +void DiveComputerNode::showchanges(const QString &n, const QString &s, const QString &f) const +{ + if (nickName != n) + qDebug("new nickname %s for DC model %s deviceId 0x%x", n.toUtf8().data(), model.toUtf8().data(), deviceId); + if (serialNumber != s) + qDebug("new serial number %s for DC model %s deviceId 0x%x", s.toUtf8().data(), model.toUtf8().data(), deviceId); + if (firmware != f) + qDebug("new firmware version %s for DC model %s deviceId 0x%x", f.toUtf8().data(), model.toUtf8().data(), deviceId); +} + +void DiveComputerList::addDC(QString m, uint32_t d, QString n, QString s, QString f) { if (m.isEmpty() || d == 0) return; const DiveComputerNode *existNode = this->getExact(m, d); - DiveComputerNode newNode(m, d, s, f, n); + if (existNode) { - if (newNode.changesValues(*existNode)) { - if (n.size() && existNode->nickName != n) - qDebug("new nickname %s for DC model %s deviceId 0x%x", n.toUtf8().data(), m.toUtf8().data(), d); - if (f.size() && existNode->firmware != f) - qDebug("new firmware version %s for DC model %s deviceId 0x%x", f.toUtf8().data(), m.toUtf8().data(), d); - if (s.size() && existNode->serialNumber != s) - qDebug("new serial number %s for DC model %s deviceId 0x%x", s.toUtf8().data(), m.toUtf8().data(), d); - } else { + // Update any non-existent fields from the old entry + if (n.isEmpty()) + n = existNode->nickName; + if (s.isEmpty()) + s = existNode->serialNumber; + if (f.isEmpty()) + f = existNode->firmware; + + // Do all the old values match? + if (n == existNode->nickName && s == existNode->serialNumber && f == existNode->firmware) return; - } + + // debugging: show changes + existNode->showchanges(n, s, f); dcMap.remove(m, *existNode); } + + DiveComputerNode newNode(m, d, s, f, n); dcMap.insert(m, newNode); } |