[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:
parent
e11809fcd0
commit
8523fc0f86
4 changed files with 13 additions and 34 deletions
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 = ""
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue