Update the AWS device name when it changes in the cloud

This commit is contained in:
Michael Zanetti 2020-01-09 13:26:54 +01:00
parent 583cd927b8
commit 2fd9382675
5 changed files with 33 additions and 4 deletions

View File

@ -970,7 +970,7 @@ void AWSClient::fetchDevices()
QString deviceId = entry.toMap().value("deviceId").toString();
QString name = entry.toMap().value("name").toString();
bool online = entry.toMap().value("online").toBool();
// qDebug() << "Have cloud device:" << deviceId << name << "online:" << online;
qDebug() << "Have cloud device:" << deviceId << name << "online:" << online;
AWSDevice *d = m_devices->getDevice(deviceId);
if (!d) {
@ -978,6 +978,7 @@ void AWSClient::fetchDevices()
m_devices->insert(d);
}
d->setOnline(online);
d->setName(name);
actualDevices.append(d->id());
}
@ -1144,6 +1145,21 @@ void AWSDevices::insert(AWSDevice *device)
device->setParent(this);
beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
m_list.append(device);
connect(device, &AWSDevice::onlineChanged, this, [this, device](){
int idx = m_list.indexOf(device);
if (idx >= 0) {
emit dataChanged(index(idx), index(idx), {RoleOnline});
}
});
connect(device, &AWSDevice::nameChanged, this, [this, device](){
int idx = m_list.indexOf(device);
if (idx >= 0) {
emit dataChanged(index(idx), index(idx), {RoleName});
}
});
endInsertRows();
emit countChanged();
}
@ -1196,6 +1212,14 @@ QString AWSDevice::name() const
return m_name;
}
void AWSDevice::setName(const QString &name)
{
if (m_name != name) {
m_name = name;
emit nameChanged();
}
}
bool AWSDevice::online() const
{
return m_online;

View File

@ -12,18 +12,20 @@ class QNetworkAccessManager;
class AWSDevice: public QObject {
Q_OBJECT
Q_PROPERTY(QString id READ id CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(bool online READ online NOTIFY onlineChanged)
public:
AWSDevice(const QString &id, const QString &name, bool online = false, QObject *parent = nullptr);
QString id() const;
QString name() const;
void setName(const QString &name);
bool online() const;
void setOnline(bool online);
signals:
void onlineChanged();
void nameChanged();
private:
QString m_id;

View File

@ -275,6 +275,9 @@ void NymeaConnection::onError(QAbstractSocket::SocketError error)
transport->deleteLater();
}
qDebug() << "A transport error happened for" << transport->url() << error << "(Still trying on" << m_transportCandidates.count() << "connections)";
foreach (Connection *c, m_transportCandidates) {
qDebug() << "Connection candidate:" << c->url();
}
if (m_transportCandidates.isEmpty()) {
m_connectionStatus = errorStatus;
emit connectionStatusChanged();

View File

@ -214,7 +214,7 @@ Page {
errorLabel.text = qsTr("Failed to connect to the login server. Please mase sure your network connection is working.")
break;
default:
errorLabel.text = qsTr("An unexpected error happened. Please report this isse. Error code:").arg(error)
errorLabel.text = qsTr("An unexpected error happened. Please report this isse. Error code: %1").arg(error)
break;
}
errorLabel.visible = (error !== AWSClient.LoginErrorNoError)

@ -1 +1 @@
Subproject commit eacffb695f8870c75b027a701277f6ec4455d327
Subproject commit 9c7075192b2b799feb302b48618eb4ef4d942172