Commit 6fe7a9b1 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Make it possible for the DevicesModel to react to device name changes

parent bb97cc19
......@@ -255,7 +255,7 @@ void Device::addLink(const NetworkPackage& identityPackage, DeviceLink* link)
m_deviceLinks.append(link);
//re-read the device name from the identityPackage because it could have changed
m_deviceName = identityPackage.get<QString>("deviceName");
setName(identityPackage.get<QString>("deviceName"));
m_deviceType = str2type(identityPackage.get<QString>("deviceType"));
//Theoretically we will never add two links from the same provider (the provider should destroy
......@@ -497,3 +497,11 @@ QString Device::iconName() const
}
return QString();
}
void Device::setName(const QString &name)
{
if (m_deviceName != name) {
m_deviceName = name;
Q_EMIT nameChanged(name);
}
}
......@@ -41,7 +41,7 @@ class KDECONNECTCORE_EXPORT Device
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device")
Q_PROPERTY(QString id READ id CONSTANT)
Q_PROPERTY(QString iconName READ iconName CONSTANT)
Q_PROPERTY(QString name READ name)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableStatusChanged)
enum PairStatus {
......@@ -121,8 +121,11 @@ Q_SIGNALS:
Q_SCRIPTABLE void pairingSuccesful();
Q_SCRIPTABLE void pairingFailed(const QString& error);
Q_SCRIPTABLE void unpaired();
Q_SCRIPTABLE void nameChanged(const QString& name);
private:
void setName(const QString &name);
const QString m_deviceId;
QString m_deviceName;
DeviceType m_deviceType;
......
......@@ -85,7 +85,7 @@ void DevicesModel::deviceAdded(const QString& id)
Q_EMIT dataChanged(idx, idx);
} else {
beginInsertRows(QModelIndex(), m_deviceList.count(), m_deviceList.count());
m_deviceList.append(new DeviceDbusInterface(id, this));
appendDevice(id);
endInsertRows();
}
}
......@@ -152,11 +152,26 @@ void DevicesModel::receivedDeviceList(QDBusPendingCallWatcher* watcher)
beginInsertRows(QModelIndex(), 0, deviceIds.count()-1);
Q_FOREACH(const QString& id, deviceIds) {
m_deviceList.append(new DeviceDbusInterface(id, this));
appendDevice(id);
}
endInsertRows();
}
void DevicesModel::appendDevice(const QString& id)
{
DeviceDbusInterface* dev = new DeviceDbusInterface(id, this);
m_deviceList.append(dev);
connect(dev, SIGNAL(nameChanged(QString)), SLOT(nameChanged(QString)));
}
void DevicesModel::nameChanged(const QString& newName)
{
int row = m_deviceList.indexOf(static_cast<DeviceDbusInterface*>(sender()));
Q_ASSERT(row>=0);
const QModelIndex idx = index(row, 0);
Q_EMIT dataChanged(idx, idx);
}
void DevicesModel::clearDevices()
{
if (!m_deviceList.isEmpty()) {
......
......@@ -75,6 +75,7 @@ private Q_SLOTS:
void deviceRemoved(const QString& id);
void refreshDeviceList();
void receivedDeviceList(QDBusPendingCallWatcher* watcher);
void nameChanged(const QString& newName);
Q_SIGNALS:
void rowsChanged();
......@@ -82,6 +83,7 @@ Q_SIGNALS:
private:
void clearDevices();
int rowForDeviceId(const QString& id) const;
void appendDevice(const QString& id);
DaemonDbusInterface* m_dbusInterface;
QVector<DeviceDbusInterface*> m_deviceList;
......
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