From ab4bb419790aaca067b2984115e16ee315f3159b Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Sat, 5 Aug 2023 18:51:42 +0200 Subject: [PATCH] Fix last active time in devices page --- src/models/devicesmodel.cpp | 10 ++++++++++ src/models/devicesmodel.h | 1 + src/qml/Settings/DeviceDelegate.qml | 6 +++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/models/devicesmodel.cpp b/src/models/devicesmodel.cpp index de34443b0..50e550f27 100644 --- a/src/models/devicesmodel.cpp +++ b/src/models/devicesmodel.cpp @@ -5,6 +5,9 @@ #include "controller.h" +#include +#include + #include #include @@ -52,6 +55,12 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const } else { return false; } + case TimestampString: + if (device.lastSeenTs) { + return QDateTime::fromMSecsSinceEpoch(*device.lastSeenTs).toString(QLocale().dateTimeFormat(QLocale::ShortFormat)); + } else { + return false; + } case Type: if (device.deviceId == m_connection->deviceId()) { return This; @@ -81,6 +90,7 @@ QHash DevicesModel::roleNames() const {DisplayName, "displayName"}, {LastIp, "lastIp"}, {LastTimestamp, "lastTimestamp"}, + {TimestampString, "timestamp"}, {Type, "type"}, }; } diff --git a/src/models/devicesmodel.h b/src/models/devicesmodel.h index ec2b19456..70aa9cd9f 100644 --- a/src/models/devicesmodel.h +++ b/src/models/devicesmodel.h @@ -40,6 +40,7 @@ public: DisplayName, /**< Display name set by the user for this device. */ LastIp, /**< The IP address where this device was last seen. */ LastTimestamp, /**< The timestamp when this devices was last seen. */ + TimestampString, /**< String for the timestamp when this devices was last seen. */ Type, /**< The category to sort this device into. */ }; Q_ENUM(Roles) diff --git a/src/qml/Settings/DeviceDelegate.qml b/src/qml/Settings/DeviceDelegate.qml index 0a8a21025..e945fcfd6 100644 --- a/src/qml/Settings/DeviceDelegate.qml +++ b/src/qml/Settings/DeviceDelegate.qml @@ -15,7 +15,7 @@ MobileForm.AbstractFormDelegate { id: deviceDelegate required property string id - required property int lastTimestamp + required property string timestamp required property string displayName property bool editDeviceName: false @@ -49,7 +49,7 @@ MobileForm.AbstractFormDelegate { QQC2.Label { Layout.fillWidth: true - text: deviceDelegate.id + ", Last activity: " + (new Date(deviceDelegate.lastTimestamp)).toLocaleString(Qt.locale(), Locale.ShortFormat) + text: i18nc("@label", "%1, Last activity: %2", deviceDelegate.id, deviceDelegate.timestamp) color: Kirigami.Theme.disabledTextColor font: Kirigami.Theme.smallFont elide: Text.ElideRight @@ -131,4 +131,4 @@ MobileForm.AbstractFormDelegate { } } } -} \ No newline at end of file +}