Daemon devices() can now filter by visible and/or paired
visibleDevices() is not needed anymore and has been removed
This commit is contained in:
parent
c70f2555f1
commit
3073e66bb3
3 changed files with 12 additions and 24 deletions
|
@ -123,22 +123,17 @@ void Daemon::forceOnNetworkChange()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Daemon::visibleDevices()
|
QStringList Daemon::devices(bool onlyReachable, bool onlyVisible)
|
||||||
{
|
{
|
||||||
QStringList ret;
|
QStringList ret;
|
||||||
Q_FOREACH(Device* device, mDevices) {
|
Q_FOREACH(Device* device, mDevices) {
|
||||||
if (device->isReachable()) {
|
if (onlyReachable && !device->isReachable()) continue;
|
||||||
ret.append(device->id());
|
if (onlyVisible && !device->isPaired()) continue;
|
||||||
}
|
ret.append(device->id());
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Daemon::devices()
|
|
||||||
{
|
|
||||||
return mDevices.keys();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl)
|
void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,7 @@ public Q_SLOTS:
|
||||||
Q_SCRIPTABLE void forceOnNetworkChange();
|
Q_SCRIPTABLE void forceOnNetworkChange();
|
||||||
|
|
||||||
//Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id
|
//Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id
|
||||||
Q_SCRIPTABLE QStringList devices(); //All known devices
|
Q_SCRIPTABLE QStringList devices(bool onlyReachable = false, bool onlyVisible = false);
|
||||||
Q_SCRIPTABLE QStringList visibleDevices(); //Only visible devices
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
Q_SCRIPTABLE void deviceAdded(const QString& id);
|
Q_SCRIPTABLE void deviceAdded(const QString& id);
|
||||||
|
|
|
@ -112,27 +112,21 @@ void DevicesModel::refreshDeviceList()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDBusPendingReply<QStringList> pendingDeviceIds = m_dbusInterface->devices();
|
|
||||||
|
bool onlyPaired = (m_displayFilter & StatusPaired);
|
||||||
|
bool onlyReachable = (m_displayFilter & StatusReachable);
|
||||||
|
|
||||||
|
QDBusPendingReply<QStringList> pendingDeviceIds = m_dbusInterface->devices(onlyReachable, onlyPaired);
|
||||||
pendingDeviceIds.waitForFinished();
|
pendingDeviceIds.waitForFinished();
|
||||||
if (pendingDeviceIds.isError()) return;
|
if (pendingDeviceIds.isError()) return;
|
||||||
|
|
||||||
const QStringList& deviceIds = pendingDeviceIds.value();
|
const QStringList& deviceIds = pendingDeviceIds.value();
|
||||||
|
|
||||||
Q_FOREACH(const QString& id, deviceIds) {
|
Q_FOREACH(const QString& id, deviceIds) {
|
||||||
|
|
||||||
DeviceDbusInterface* deviceDbusInterface = new DeviceDbusInterface(id,this);
|
|
||||||
|
|
||||||
bool onlyPaired = (m_displayFilter & StatusPaired);
|
|
||||||
if (onlyPaired && !deviceDbusInterface->isPaired()) continue;
|
|
||||||
bool onlyReachable = (m_displayFilter & StatusReachable);
|
|
||||||
if (onlyReachable && !deviceDbusInterface->isReachable()) continue;
|
|
||||||
|
|
||||||
int firstRow = m_deviceList.size();
|
int firstRow = m_deviceList.size();
|
||||||
int lastRow = firstRow;
|
int lastRow = firstRow;
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), firstRow, lastRow);
|
beginInsertRows(QModelIndex(), firstRow, lastRow);
|
||||||
m_deviceList.append(deviceDbusInterface);
|
m_deviceList.append(new DeviceDbusInterface(id,this));
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT dataChanged(index(0), index(m_deviceList.size()));
|
Q_EMIT dataChanged(index(0), index(m_deviceList.size()));
|
||||||
|
|
Loading…
Reference in a new issue