Commit f3656d96 authored by Richard Liebscher's avatar Richard Liebscher
Browse files

Save changed device name and type

parent 79164ca8
Pipeline #29408 canceled with stage
...@@ -276,7 +276,7 @@ void Device::addLink(const NetworkPacket& identityPacket, DeviceLink* link) ...@@ -276,7 +276,7 @@ void Device::addLink(const NetworkPacket& identityPacket, DeviceLink* link)
//qCDebug(KDECONNECT_CORE) << "Adding link to" << id() << "via" << link->provider(); //qCDebug(KDECONNECT_CORE) << "Adding link to" << id() << "via" << link->provider();
setName(identityPacket.get<QString>(QStringLiteral("deviceName"))); setName(identityPacket.get<QString>(QStringLiteral("deviceName")));
d->m_deviceType = str2type(identityPacket.get<QString>(QStringLiteral("deviceType"))); setType(identityPacket.get<QString>(QStringLiteral("deviceType")));
if (d->m_deviceLinks.contains(link)) { if (d->m_deviceLinks.contains(link)) {
return; return;
...@@ -506,10 +506,21 @@ void Device::setName(const QString& name) ...@@ -506,10 +506,21 @@ void Device::setName(const QString& name)
{ {
if (d->m_deviceName != name) { if (d->m_deviceName != name) {
d->m_deviceName = name; d->m_deviceName = name;
KdeConnectConfig::instance().setDeviceProperty(d->m_deviceId, QStringLiteral("name"), name);
Q_EMIT nameChanged(name); Q_EMIT nameChanged(name);
} }
} }
void Device::setType(const QString& strtype)
{
auto type = str2type(strtype);
if (d->m_deviceType != type) {
d->m_deviceType = type;
KdeConnectConfig::instance().setDeviceProperty(d->m_deviceId, QStringLiteral("type"), strtype);
Q_EMIT typeChanged(strtype);
}
}
KdeConnectPlugin* Device::plugin(const QString& pluginName) const KdeConnectPlugin* Device::plugin(const QString& pluginName) const
{ {
return d->m_plugins[pluginName]; return d->m_plugins[pluginName];
......
...@@ -36,7 +36,7 @@ class KDECONNECTCORE_EXPORT Device ...@@ -36,7 +36,7 @@ class KDECONNECTCORE_EXPORT Device
{ {
Q_OBJECT Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device") Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device")
Q_PROPERTY(QString type READ type CONSTANT) Q_PROPERTY(QString type READ type NOTIFY typeChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString iconName READ iconName CONSTANT) Q_PROPERTY(QString iconName READ iconName CONSTANT)
Q_PROPERTY(QString statusIconName READ statusIconName NOTIFY statusIconNameChanged) Q_PROPERTY(QString statusIconName READ statusIconName NOTIFY statusIconNameChanged)
...@@ -134,6 +134,7 @@ Q_SIGNALS: ...@@ -134,6 +134,7 @@ Q_SIGNALS:
Q_SCRIPTABLE void trustedChanged(bool trusted); Q_SCRIPTABLE void trustedChanged(bool trusted);
Q_SCRIPTABLE void pairingError(const QString& error); Q_SCRIPTABLE void pairingError(const QString& error);
Q_SCRIPTABLE void nameChanged(const QString& name); Q_SCRIPTABLE void nameChanged(const QString& name);
Q_SCRIPTABLE void typeChanged(const QString& type);
Q_SCRIPTABLE void statusIconNameChanged(); Q_SCRIPTABLE void statusIconNameChanged();
Q_SCRIPTABLE void hasPairingRequestsChanged(bool hasPairingRequests); Q_SCRIPTABLE void hasPairingRequestsChanged(bool hasPairingRequests);
...@@ -143,6 +144,7 @@ private: //Methods ...@@ -143,6 +144,7 @@ private: //Methods
static QString type2str(DeviceType deviceType); static QString type2str(DeviceType deviceType);
void setName(const QString& name); void setName(const QString& name);
void setType(const QString& strtype);
QString iconForStatus(bool reachable, bool paired) const; QString iconForStatus(bool reachable, bool paired) const;
private: private:
......
...@@ -195,6 +195,10 @@ void KdeConnectConfig::removeTrustedDevice(const QString& deviceId) ...@@ -195,6 +195,10 @@ void KdeConnectConfig::removeTrustedDevice(const QString& deviceId)
// Utility functions to set and get a value // Utility functions to set and get a value
void KdeConnectConfig::setDeviceProperty(const QString& deviceId, const QString& key, const QString& value) void KdeConnectConfig::setDeviceProperty(const QString& deviceId, const QString& key, const QString& value)
{ {
// do not store values for untrusted devices (it would make them trusted)
if (!trustedDevices().contains(deviceId))
return;
d->m_trustedDevices->beginGroup(deviceId); d->m_trustedDevices->beginGroup(deviceId);
d->m_trustedDevices->setValue(key, value); d->m_trustedDevices->setValue(key, value);
d->m_trustedDevices->endGroup(); d->m_trustedDevices->endGroup();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment