mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 17:40:47 +03:00
Merge pull request #767 from Thulinma/deviceRenaming
Allow changing device names, display last seen time and IP
This commit is contained in:
commit
159f840aae
3 changed files with 105 additions and 19 deletions
|
@ -281,6 +281,8 @@ ApplicationWindow {
|
||||||
required property int verificationStatus
|
required property int verificationStatus
|
||||||
required property string deviceId
|
required property string deviceId
|
||||||
required property string deviceName
|
required property string deviceName
|
||||||
|
required property string lastIp
|
||||||
|
required property var lastTs
|
||||||
|
|
||||||
width: devicelist.width
|
width: devicelist.width
|
||||||
spacing: 4
|
spacing: 4
|
||||||
|
@ -288,21 +290,90 @@ ApplicationWindow {
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
Text {
|
RowLayout {
|
||||||
Layout.fillWidth: true
|
Text {
|
||||||
Layout.alignment: Qt.AlignLeft
|
Layout.fillWidth: true
|
||||||
elide: Text.ElideRight
|
Layout.alignment: Qt.AlignLeft
|
||||||
font.bold: true
|
elide: Text.ElideRight
|
||||||
color: Nheko.colors.text
|
font.bold: true
|
||||||
text: deviceId
|
color: Nheko.colors.text
|
||||||
|
text: deviceId
|
||||||
|
}
|
||||||
|
|
||||||
|
Image {
|
||||||
|
Layout.preferredHeight: 16
|
||||||
|
Layout.preferredWidth: 16
|
||||||
|
visible: profile.isSelf && verificationStatus != VerificationStatus.NOT_APPLICABLE
|
||||||
|
source: {
|
||||||
|
switch (verificationStatus) {
|
||||||
|
case VerificationStatus.VERIFIED:
|
||||||
|
return "image://colorimage/:/icons/icons/ui/lock.png?green";
|
||||||
|
case VerificationStatus.UNVERIFIED:
|
||||||
|
return "image://colorimage/:/icons/icons/ui/unlock.png?yellow";
|
||||||
|
case VerificationStatus.SELF:
|
||||||
|
return "image://colorimage/:/icons/icons/ui/checkmark.png?green";
|
||||||
|
default:
|
||||||
|
return "image://colorimage/:/icons/icons/ui/unlock.png?red";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageButton {
|
||||||
|
Layout.alignment: Qt.AlignTop
|
||||||
|
image: ":/icons/icons/ui/power-button-off.png"
|
||||||
|
hoverEnabled: true
|
||||||
|
ToolTip.visible: hovered
|
||||||
|
ToolTip.text: qsTr("Sign out this device.")
|
||||||
|
onClicked: profile.signOutDevice(deviceId)
|
||||||
|
visible: profile.isSelf
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: deviceNameRow
|
||||||
|
property bool isEditingAllowed
|
||||||
|
|
||||||
|
TextInput {
|
||||||
|
id: deviceNameField
|
||||||
|
readOnly: !deviceNameRow.isEditingAllowed
|
||||||
|
text: deviceName
|
||||||
|
color: Nheko.colors.text
|
||||||
|
Layout.alignment: Qt.AlignLeft
|
||||||
|
Layout.fillWidth: true
|
||||||
|
selectByMouse: true
|
||||||
|
onAccepted: {
|
||||||
|
profile.changeDeviceName(deviceId, deviceNameField.text);
|
||||||
|
deviceNameRow.isEditingAllowed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageButton {
|
||||||
|
visible: profile.isSelf
|
||||||
|
hoverEnabled: true
|
||||||
|
ToolTip.visible: hovered
|
||||||
|
ToolTip.text: qsTr("Change device name.")
|
||||||
|
image: deviceNameRow.isEditingAllowed ? ":/icons/icons/ui/checkmark.png" : ":/icons/icons/ui/edit.png"
|
||||||
|
onClicked: {
|
||||||
|
if (deviceNameRow.isEditingAllowed) {
|
||||||
|
profile.changeDeviceName(deviceId, deviceNameField.text);
|
||||||
|
deviceNameRow.isEditingAllowed = false;
|
||||||
|
} else {
|
||||||
|
deviceNameRow.isEditingAllowed = true;
|
||||||
|
deviceNameField.focus = true;
|
||||||
|
deviceNameField.selectAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
|
visible: profile.isSelf
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignLeft
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
color: Nheko.colors.text
|
color: Nheko.colors.text
|
||||||
text: deviceName
|
text: qsTr("Last seen %1 from %2").arg(new Date(lastTs).toLocaleString(Locale.ShortFormat)).arg(lastIp?lastIp:"???")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -310,7 +381,7 @@ ApplicationWindow {
|
||||||
Image {
|
Image {
|
||||||
Layout.preferredHeight: 16
|
Layout.preferredHeight: 16
|
||||||
Layout.preferredWidth: 16
|
Layout.preferredWidth: 16
|
||||||
visible: verificationStatus != VerificationStatus.NOT_APPLICABLE
|
visible: !profile.isSelf && verificationStatus != VerificationStatus.NOT_APPLICABLE
|
||||||
source: {
|
source: {
|
||||||
switch (verificationStatus) {
|
switch (verificationStatus) {
|
||||||
case VerificationStatus.VERIFIED:
|
case VerificationStatus.VERIFIED:
|
||||||
|
@ -338,14 +409,7 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageButton {
|
|
||||||
image: ":/icons/icons/ui/power-button-off.png"
|
|
||||||
hoverEnabled: true
|
|
||||||
ToolTip.visible: hovered
|
|
||||||
ToolTip.text: qsTr("Sign out this device.")
|
|
||||||
onClicked: profile.signOutDevice(deviceId)
|
|
||||||
visible: profile.isSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,8 @@ DeviceInfoModel::roleNames() const
|
||||||
{DeviceId, "deviceId"},
|
{DeviceId, "deviceId"},
|
||||||
{DeviceName, "deviceName"},
|
{DeviceName, "deviceName"},
|
||||||
{VerificationStatus, "verificationStatus"},
|
{VerificationStatus, "verificationStatus"},
|
||||||
|
{LastIp, "lastIp"},
|
||||||
|
{LastTs, "lastTs"},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +80,10 @@ DeviceInfoModel::data(const QModelIndex &index, int role) const
|
||||||
return deviceList_[index.row()].display_name;
|
return deviceList_[index.row()].display_name;
|
||||||
case VerificationStatus:
|
case VerificationStatus:
|
||||||
return QVariant::fromValue(deviceList_[index.row()].verification_status);
|
return QVariant::fromValue(deviceList_[index.row()].verification_status);
|
||||||
|
case LastIp:
|
||||||
|
return deviceList_[index.row()].lastIp;
|
||||||
|
case LastTs:
|
||||||
|
return deviceList_[index.row()].lastTs;
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -334,6 +340,19 @@ UserProfile::changeUsername(QString username)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserProfile::changeDeviceName(QString deviceID, QString deviceName)
|
||||||
|
{
|
||||||
|
http::client()->set_device_name(
|
||||||
|
deviceID.toStdString(), deviceName.toStdString(), [this](mtx::http::RequestErr err) {
|
||||||
|
if (err) {
|
||||||
|
nhlog::net()->warn("could not change device name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
refreshDevices();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UserProfile::verify(QString device)
|
UserProfile::verify(QString device)
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,7 +62,7 @@ public:
|
||||||
|
|
||||||
verification::Status verification_status;
|
verification::Status verification_status;
|
||||||
QString lastIp;
|
QString lastIp;
|
||||||
size_t lastTs;
|
qlonglong lastTs;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeviceInfoModel : public QAbstractListModel
|
class DeviceInfoModel : public QAbstractListModel
|
||||||
|
@ -74,6 +74,8 @@ public:
|
||||||
DeviceId,
|
DeviceId,
|
||||||
DeviceName,
|
DeviceName,
|
||||||
VerificationStatus,
|
VerificationStatus,
|
||||||
|
LastIp,
|
||||||
|
LastTs,
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit DeviceInfoModel(QObject *parent = nullptr)
|
explicit DeviceInfoModel(QObject *parent = nullptr)
|
||||||
|
@ -141,6 +143,7 @@ public:
|
||||||
Q_INVOKABLE void kickUser();
|
Q_INVOKABLE void kickUser();
|
||||||
Q_INVOKABLE void startChat();
|
Q_INVOKABLE void startChat();
|
||||||
Q_INVOKABLE void changeUsername(QString username);
|
Q_INVOKABLE void changeUsername(QString username);
|
||||||
|
Q_INVOKABLE void changeDeviceName(QString deviceID, QString deviceName);
|
||||||
Q_INVOKABLE void changeAvatar();
|
Q_INVOKABLE void changeAvatar();
|
||||||
Q_INVOKABLE void openGlobalProfile();
|
Q_INVOKABLE void openGlobalProfile();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue