Emit less redundant events

This commit is contained in:
Albert Vaca 2015-06-21 19:39:04 -07:00
parent f71f498125
commit 08938689c5
3 changed files with 23 additions and 18 deletions

View file

@ -127,7 +127,11 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
if (d->mDevices.contains(id)) {
//qCDebug(KDECONNECT_CORE) << "It is a known device";
Device* device = d->mDevices[id];
bool wasReachable = device->isReachable();
device->addLink(identityPackage, dl);
if (!wasReachable) {
Q_EMIT deviceVisibilityChanged(id, true);
}
} else {
//qCDebug(KDECONNECT_CORE) << "It is a new device";
@ -137,8 +141,6 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
Q_EMIT deviceAdded(id);
}
Q_EMIT deviceVisibilityChanged(id, true);
}
void Daemon::onDeviceReachableStatusChanged()
@ -146,21 +148,17 @@ void Daemon::onDeviceReachableStatusChanged()
Device* device = (Device*)sender();
QString id = device->id();
Q_EMIT deviceVisibilityChanged(id, device->isReachable());
//qCDebug(KDECONNECT_CORE) << "Device" << device->name() << "reachable status changed:" << device->isReachable();
if (!device->isReachable()) {
if (!device->isPaired()) {
qCDebug(KDECONNECT_CORE) << "Destroying device" << device->name();
Q_EMIT deviceRemoved(id);
d->mDevices.remove(id);
device->deleteLater();
}
qCDebug(KDECONNECT_CORE) << "Device" << device->name() << "status changed. Reachable:" << device->isReachable() << ". Paired: " << device->isPaired();
if (!device->isReachable() && !device->isPaired()) {
qCDebug(KDECONNECT_CORE) << "Destroying device" << device->name();
d->mDevices.remove(id);
device->deleteLater();
Q_EMIT deviceRemoved(id);
} else {
Q_EMIT deviceVisibilityChanged(id, device->isReachable());
}
}
void Daemon::setAnnouncedName(QString name)

View file

@ -236,10 +236,13 @@ void Device::unpair()
void Device::unpairInternal()
{
bool alreadyUnpaired = (m_pairStatus != Device::Paired);
m_pairStatus = Device::NotPaired;
KdeConnectConfig::instance()->removeTrustedDevice(id());
reloadPlugins(); //Will unload the plugins
Q_EMIT pairingChanged(false);
if (!alreadyUnpaired) {
Q_EMIT pairingChanged(false);
}
}
void Device::pairingTimeout()
@ -444,6 +447,8 @@ void Device::acceptPairing()
void Device::setAsPaired()
{
bool alreadyPaired = (m_pairStatus == Device::Paired);
m_pairStatus = Device::Paired;
m_pairingTimeut.stop(); //Just in case it was started
@ -453,7 +458,9 @@ void Device::setAsPaired()
reloadPlugins(); //Will actually load the plugins
Q_EMIT pairingChanged(true);
if (!alreadyPaired) {
Q_EMIT pairingChanged(true);
}
}

View file

@ -121,8 +121,8 @@ private Q_SLOTS:
void pairingTimeout();
Q_SIGNALS:
Q_SCRIPTABLE void reachableStatusChanged();
Q_SCRIPTABLE void pluginsChanged();
Q_SCRIPTABLE void reachableStatusChanged();
Q_SCRIPTABLE void pairingChanged(bool paired);
Q_SCRIPTABLE void pairingFailed(const QString& error);
Q_SCRIPTABLE void nameChanged(const QString& name);