From 8523fc0f86f052ed8c5c41d944b7f5459834d040 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Mon, 30 May 2022 22:29:17 +0200 Subject: [PATCH] [smsapp] Simplify device handling The current device id is de-facto a global value Store it in a singleton instead of passing it between our components --- smsapp/main.cpp | 12 ++++++------ smsapp/qml/ConversationDisplay.qml | 4 +--- smsapp/qml/ConversationList.qml | 8 ++------ smsapp/qml/main.qml | 23 ++++------------------- 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/smsapp/main.cpp b/smsapp/main.cpp index 427a24c01..bca3097c2 100644 --- a/smsapp/main.cpp +++ b/smsapp/main.cpp @@ -28,14 +28,14 @@ class AppData : public QObject { Q_OBJECT Q_PROPERTY(QString initialMessage MEMBER m_initialMessage NOTIFY initialMessageChanged) - Q_PROPERTY(QString initialDevice MEMBER m_initialDevice NOTIFY initialDeviceChanged) + Q_PROPERTY(QString deviceId MEMBER m_deviceId NOTIFY deviceIdChanged) public: Q_SIGNAL void initialMessageChanged(); - Q_SIGNAL void initialDeviceChanged(); + Q_SIGNAL void deviceIdChanged(); QString m_initialMessage; - QString m_initialDevice; + QString m_deviceId; }; int main(int argc, char *argv[]) @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) aboutData.processCommandLine(&parser); data.m_initialMessage = parser.value(QStringLiteral("message")); - data.m_initialDevice = parser.value(QStringLiteral("device")); + data.m_deviceId = parser.value(QStringLiteral("device")); KDBusService service(KDBusService::Unique); @@ -85,9 +85,9 @@ int main(int argc, char *argv[]) parser.parse(args); data.m_initialMessage = parser.value(QStringLiteral("message")); - data.m_initialDevice = parser.value(QStringLiteral("device")); + data.m_deviceId = parser.value(QStringLiteral("device")); - Q_EMIT data.initialDeviceChanged(); + Q_EMIT data.deviceIdChanged(); Q_EMIT data.initialMessageChanged(); }); diff --git a/smsapp/qml/ConversationDisplay.qml b/smsapp/qml/ConversationDisplay.qml index 9c3aa9e86..f7afbfcdf 100644 --- a/smsapp/qml/ConversationDisplay.qml +++ b/smsapp/qml/ConversationDisplay.qml @@ -19,8 +19,6 @@ Kirigami.ScrollablePage id: page property bool deviceConnected - property string deviceId -// property QtObject device property string conversationId property bool isMultitarget property string initialMessage @@ -29,7 +27,7 @@ Kirigami.ScrollablePage property bool isInitalized: false property var conversationModel: ConversationModel { - deviceId: page.deviceId + deviceId: AppData.deviceId threadId: page.conversationId addressList: page.addresses diff --git a/smsapp/qml/ConversationList.qml b/smsapp/qml/ConversationList.qml index 71ed7fc17..918fe4fc5 100644 --- a/smsapp/qml/ConversationList.qml +++ b/smsapp/qml/ConversationList.qml @@ -89,16 +89,13 @@ Kirigami.ScrollablePage } property int devicesCount - property QtObject device readonly property bool deviceConnected: devicesCount > 0 - readonly property alias lastDeviceId: conversationListModel.deviceId property string currentSearchText Component { id: chatView ConversationDisplay { - deviceId: page.lastDeviceId deviceConnected: page.deviceConnected } } @@ -181,7 +178,7 @@ Kirigami.ScrollablePage filterCaseSensitivity: Qt.CaseInsensitive sourceModel: ConversationListModel { id: conversationListModel - deviceId: device ? device.id() : "" + deviceId: AppData.deviceId } } @@ -203,8 +200,7 @@ Kirigami.ScrollablePage addresses: addresses, conversationId: model.conversationId, isMultitarget: isMultitarget, - initialMessage: page.initialMessage, - device: device}) + initialMessage: page.initialMessage}) initialMessage = "" } diff --git a/smsapp/qml/main.qml b/smsapp/qml/main.qml index 5c9081b50..91fd7fcff 100644 --- a/smsapp/qml/main.qml +++ b/smsapp/qml/main.qml @@ -19,7 +19,6 @@ Kirigami.ApplicationWindow height: 600 property alias devicesCount : instantiator.count - property QtObject device property var deviceActions : [] @@ -28,26 +27,13 @@ Kirigami.ApplicationWindow Kirigami.Action { required property string deviceId required property string name - required property var device text: name onTriggered: { - root.device = device - AppData.initialDevice = "" - } - icon.name: root.device === device ? "checkmark" : "" - } - } - - Connections { - target: AppData - function onInitialDeviceChanged() { - for (var action of root.deviceActions) { - if (action.deviceId == AppData.initialDevice) { - root.device = action.device - } + AppData.deviceId = deviceId } + icon.name: AppData.deviceId === deviceId ? "checkmark" : "" } } @@ -64,8 +50,8 @@ Kirigami.ApplicationWindow root.deviceActions.push(obj) root.globalDrawer.actions[0].children = root.deviceActions - if (!root.device && (AppData.initialDevice == "" || AppData.initialDevice === obj.deviceId)) { - root.device = obj.device + if (!AppData.deviceId) { + AppData.deviceId = obj.deviceId } } @@ -79,7 +65,6 @@ Kirigami.ApplicationWindow pageStack.initialPage: ConversationList { title: i18nd("kdeconnect-sms", "KDE Connect SMS") - device: root.device; devicesCount: root.devicesCount; }