Fix last active time in devices page

This commit is contained in:
Tobias Fella
2023-08-05 18:51:42 +02:00
parent c2398b19dc
commit ab4bb41979
3 changed files with 14 additions and 3 deletions

View File

@@ -5,6 +5,9 @@
#include "controller.h"
#include <QDateTime>
#include <QLocale>
#include <KLocalizedString>
#include <Quotient/csapi/device_management.h>
@@ -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<int, QByteArray> DevicesModel::roleNames() const
{DisplayName, "displayName"},
{LastIp, "lastIp"},
{LastTimestamp, "lastTimestamp"},
{TimestampString, "timestamp"},
{Type, "type"},
};
}

View File

@@ -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)

View File

@@ -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 {
}
}
}
}
}