1From d2ceb83fe889d7cb40ad1e0d71e75d726a87fb28 Mon Sep 17 00:00:00 2001
2From: Christophe Chapuis <chris.chapuis@gmail.com>
3Date: Sat, 13 Jul 2019 11:17:08 +0000
4Subject: [PATCH] onGetModemsFinished: also emit modemRemoved and modemAdded
5
6VoiceCall only subscribes to these events, so we need to emit these
7more "atomic" events too.
8
9Signed-off-by: Christophe Chapuis <chris.chapuis@gmail.com>
10
11Upstream-Status: Pending
12---
13 src/qofonomanager.cpp | 21 ++++++++++++++++++---
14 1 file changed, 18 insertions(+), 3 deletions(-)
15
16diff --git a/src/qofonomanager.cpp b/src/qofonomanager.cpp
17index e1da658..38cf0e4 100644
18--- a/src/qofonomanager.cpp
19+++ b/src/qofonomanager.cpp
20@@ -88,15 +88,30 @@ void QOfonoManager::Private::handleGetModemsReply(QOfonoManager *obj, ObjectPath
21 {
22     const bool wasAvailable = available;
23     QString prevDefault = defaultModem();
24-    QStringList newModems;
25+    QStringList newModems, oldModems;
26     const int n = reply.count();
27     for (int i = 0; i < n; i++) {
28         newModems.append(reply.at(i).path.path());
29     }
30     qSort(newModems);
31     available = true;
32-    if (modems != newModems) {
33-        modems = newModems;
34+    oldModems = modems;
35+    modems = newModems;
36+
37+    // emit atomic events for add/remove
38+    Q_FOREACH(QString modem, oldModems) {
39+        if(!newModems.contains(modem)) {
40+            Q_EMIT obj->modemRemoved(modem);
41+        }
42+    }
43+    Q_FOREACH(QString modem, newModems) {
44+        if(!oldModems.contains(modem)) {
45+            Q_EMIT obj->modemAdded(modem);
46+        }
47+    }
48+
49+    // then update the whole list
50+    if (oldModems != newModems) {
51         Q_EMIT obj->modemsChanged(modems);
52     }
53     QString newDefault = defaultModem();
54