Fixed KCM device list not being refreshed

When a the device visibilita changes
This commit is contained in:
Albert Vaca 2013-08-15 22:45:33 +02:00
parent f28088c915
commit 05983267e3
2 changed files with 17 additions and 14 deletions

View file

@ -133,8 +133,6 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
Device* device = mDevices[id];
device->addLink(dl);
Q_EMIT deviceVisibilityChanged(id, true);
} else {
qDebug() << "It is a new device";
@ -145,9 +143,10 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
mDevices[id] = device;
Q_EMIT deviceAdded(id);
Q_EMIT deviceVisibilityChanged(id, true);
}
Q_EMIT deviceVisibilityChanged(id, true);
}
void Daemon::onDeviceReachableStatusChanged()
@ -156,9 +155,9 @@ void Daemon::onDeviceReachableStatusChanged()
Device* device = (Device*)sender();
QString id = device->id();
if (!device->reachable()) {
Q_EMIT deviceVisibilityChanged(id, device->reachable());
Q_EMIT deviceVisibilityChanged(id, false);
if (!device->reachable()) {
if (!device->paired()) {
Q_EMIT deviceRemoved(id);

View file

@ -37,9 +37,12 @@ DevicesModel::DevicesModel(QObject *parent)
deviceAdded(id);
}
connect(m_dbusInterface,SIGNAL(deviceAdded(QString)),this,SLOT(deviceAdded(QString)));
connect(m_dbusInterface,SIGNAL(deviceVisibilityChanged(QString,bool)),this,SLOT(deviceStatusChanged(QString)));
connect(m_dbusInterface,SIGNAL(deviceRemoved(QString)),this,SLOT(deviceRemoved(QString)));
connect(m_dbusInterface, SIGNAL(deviceAdded(QString)),
this, SLOT(deviceAdded(QString)));
connect(m_dbusInterface, SIGNAL(deviceVisibilityChanged(QString,bool)),
this, SLOT(deviceStatusChanged(QString)));
connect(m_dbusInterface, SIGNAL(deviceRemoved(QString)),
this, SLOT(deviceRemoved(QString)));
}
DevicesModel::~DevicesModel()
@ -64,11 +67,12 @@ void DevicesModel::deviceRemoved(const QString& id)
refreshDeviceList();
}
void DevicesModel::deviceStatusChanged(const QString& id)
{
Q_UNUSED(id);
emit dataChanged(index(0),index(rowCount()));
//FIXME: Emitting dataChanged does not invalidate the view, refreshDeviceList does
//Q_EMIT dataChanged(index(0),index(rowCount()));
refreshDeviceList();
}
void DevicesModel::refreshDeviceList()
@ -79,13 +83,16 @@ void DevicesModel::refreshDeviceList()
m_deviceList.clear();
endRemoveRows();
}
QList<QString> deviceIds = m_dbusInterface->devices();
Q_FOREACH(const QString& id, deviceIds) {
beginInsertRows(QModelIndex(), rowCount(), rowCount() + 1);
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_deviceList.append(new DeviceDbusInterface(id,this));
endInsertRows();
}
Q_EMIT dataChanged(index(0),index(deviceIds.count()));
}
/*
bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent)
@ -128,7 +135,6 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
}
}
if (!index.isValid()
|| index.row() < 0
|| index.row() >= m_deviceList.count()
@ -139,7 +145,6 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
DeviceDbusInterface* device = m_deviceList[index.row()];
//FIXME: This function gets called lots of times per second, producing lots of dbus calls
switch (role) {
case IconModelRole: {
@ -158,7 +163,6 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
if (device->reachable()) status |= StatusReachable;
return status;
}
default:
return QVariant();
}