[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
This commit is contained in:
Nicolas Fella 2022-05-30 22:29:17 +02:00
parent e11809fcd0
commit 8523fc0f86
4 changed files with 13 additions and 34 deletions

View file

@ -28,14 +28,14 @@ class AppData : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString initialMessage MEMBER m_initialMessage NOTIFY initialMessageChanged) 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: public:
Q_SIGNAL void initialMessageChanged(); Q_SIGNAL void initialMessageChanged();
Q_SIGNAL void initialDeviceChanged(); Q_SIGNAL void deviceIdChanged();
QString m_initialMessage; QString m_initialMessage;
QString m_initialDevice; QString m_deviceId;
}; };
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -77,7 +77,7 @@ int main(int argc, char *argv[])
aboutData.processCommandLine(&parser); aboutData.processCommandLine(&parser);
data.m_initialMessage = parser.value(QStringLiteral("message")); 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); KDBusService service(KDBusService::Unique);
@ -85,9 +85,9 @@ int main(int argc, char *argv[])
parser.parse(args); parser.parse(args);
data.m_initialMessage = parser.value(QStringLiteral("message")); 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(); Q_EMIT data.initialMessageChanged();
}); });

View file

@ -19,8 +19,6 @@ Kirigami.ScrollablePage
id: page id: page
property bool deviceConnected property bool deviceConnected
property string deviceId
// property QtObject device
property string conversationId property string conversationId
property bool isMultitarget property bool isMultitarget
property string initialMessage property string initialMessage
@ -29,7 +27,7 @@ Kirigami.ScrollablePage
property bool isInitalized: false property bool isInitalized: false
property var conversationModel: ConversationModel { property var conversationModel: ConversationModel {
deviceId: page.deviceId deviceId: AppData.deviceId
threadId: page.conversationId threadId: page.conversationId
addressList: page.addresses addressList: page.addresses

View file

@ -89,16 +89,13 @@ Kirigami.ScrollablePage
} }
property int devicesCount property int devicesCount
property QtObject device
readonly property bool deviceConnected: devicesCount > 0 readonly property bool deviceConnected: devicesCount > 0
readonly property alias lastDeviceId: conversationListModel.deviceId
property string currentSearchText property string currentSearchText
Component { Component {
id: chatView id: chatView
ConversationDisplay { ConversationDisplay {
deviceId: page.lastDeviceId
deviceConnected: page.deviceConnected deviceConnected: page.deviceConnected
} }
} }
@ -181,7 +178,7 @@ Kirigami.ScrollablePage
filterCaseSensitivity: Qt.CaseInsensitive filterCaseSensitivity: Qt.CaseInsensitive
sourceModel: ConversationListModel { sourceModel: ConversationListModel {
id: conversationListModel id: conversationListModel
deviceId: device ? device.id() : "" deviceId: AppData.deviceId
} }
} }
@ -203,8 +200,7 @@ Kirigami.ScrollablePage
addresses: addresses, addresses: addresses,
conversationId: model.conversationId, conversationId: model.conversationId,
isMultitarget: isMultitarget, isMultitarget: isMultitarget,
initialMessage: page.initialMessage, initialMessage: page.initialMessage})
device: device})
initialMessage = "" initialMessage = ""
} }

View file

@ -19,7 +19,6 @@ Kirigami.ApplicationWindow
height: 600 height: 600
property alias devicesCount : instantiator.count property alias devicesCount : instantiator.count
property QtObject device
property var deviceActions : [] property var deviceActions : []
@ -28,26 +27,13 @@ Kirigami.ApplicationWindow
Kirigami.Action { Kirigami.Action {
required property string deviceId required property string deviceId
required property string name required property string name
required property var device
text: name text: name
onTriggered: { onTriggered: {
root.device = device AppData.deviceId = deviceId
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
}
} }
icon.name: AppData.deviceId === deviceId ? "checkmark" : ""
} }
} }
@ -64,8 +50,8 @@ Kirigami.ApplicationWindow
root.deviceActions.push(obj) root.deviceActions.push(obj)
root.globalDrawer.actions[0].children = root.deviceActions root.globalDrawer.actions[0].children = root.deviceActions
if (!root.device && (AppData.initialDevice == "" || AppData.initialDevice === obj.deviceId)) { if (!AppData.deviceId) {
root.device = obj.device AppData.deviceId = obj.deviceId
} }
} }
@ -79,7 +65,6 @@ Kirigami.ApplicationWindow
pageStack.initialPage: ConversationList { pageStack.initialPage: ConversationList {
title: i18nd("kdeconnect-sms", "KDE Connect SMS") title: i18nd("kdeconnect-sms", "KDE Connect SMS")
device: root.device;
devicesCount: root.devicesCount; devicesCount: root.devicesCount;
} }