From 05241dc61e8c43a12f91ee9976a2ecb2337a3eaf Mon Sep 17 00:00:00 2001
From: Christophe Chapuis <chris.chapuis@gmail.com>
Date: Sat, 13 Jul 2019 11:17:08 +0000
Subject: [PATCH] onGetModemsFinished: also emit modemRemoved and modemAdded

VoiceCall only subscribes to these events, so we need to emit these
more "atomic" events too.

Signed-off-by: Christophe Chapuis <chris.chapuis@gmail.com>
---
 src/qofonomanager.cpp | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/qofonomanager.cpp b/src/qofonomanager.cpp
index deeb946..e94a3c7 100644
--- a/src/qofonomanager.cpp
+++ b/src/qofonomanager.cpp
@@ -40,15 +40,30 @@ void QOfonoManager::Private::handleGetModemsReply(QOfonoManager* obj, ObjectPath
 {
     bool wasAvailable = available;
     QString prevDefault = defaultModem();
-    QStringList newModems;
+    QStringList newModems, oldModems;
     const int n = reply.count();
     for (int i = 0; i < n; i++) {
         newModems.append(reply.at(i).path.path());
     }
     qSort(newModems);
     available = true;
-    if (modems != newModems) {
-        modems = newModems;
+    oldModems = modems;
+    modems = newModems;
+    
+    // emit atomic events for add/remove
+    Q_FOREACH(QString modem, oldModems) {
+        if(!newModems.contains(modem)) {
+            Q_EMIT obj->modemRemoved(modem);
+        }
+    }
+    Q_FOREACH(QString modem, newModems) {
+        if(!oldModems.contains(modem)) {
+            Q_EMIT obj->modemAdded(modem);
+        }
+    }
+    
+    // then update the whole list
+    if (oldModems != newModems) {
         Q_EMIT obj->modemsChanged(modems);
     }
     QString newDefault = defaultModem();
-- 
2.23.0

