bool LockDevicePlugin::receivePacket(const NetworkPacket &np)
{
if (np.has(QStringLiteral("isLocked"))) {
bool locked = np.get(QStringLiteral("isLocked"));
if (m_remoteLocked != locked) {
m_remoteLocked = locked;
Q_EMIT lockedChanged(locked);
}
}
if (np.has(QStringLiteral("requestLocked"))) {
sendState();
}
// Receiving result of setLocked
if (np.has(QStringLiteral("lockResult"))) {
bool lockSuccess = np.get(QStringLiteral("lockResult"));
if (lockSuccess) {
Daemon::instance()->sendSimpleNotification(QStringLiteral("remoteLockSuccess"),
device()->name(),
i18n("Remote lock successful"),
QStringLiteral("error"));
} else {
Daemon::instance()->sendSimpleNotification(QStringLiteral("remoteLockFail"), device()->name(), i18n("Remote lock failed"), QStringLiteral("error"));
Daemon::instance()->reportError(device()->name(), i18n("Remote lock failed"));
}
}
if (np.has(QStringLiteral("setLocked"))) {
const bool lock = np.get(QStringLiteral("setLocked"));
bool success = false;
if (lock) {
success = LockWorkStation();
NetworkPacket np(PACKET_TYPE_LOCK, {{QStringLiteral("lockResult"), success}});
sendPacket(np);
}
sendState();
}
return true;
}
This sends a network packet if it is not locked.
If the user has requested that the device is locked, the method obtains the lock result from the network and sets the state to locked. Then it sends the network packet and returns true.