plugins/lockdevice: add support for remote lock success/failure notification

This commit is contained in:
Piyush Aggarwal 2021-06-01 22:56:15 +05:30
parent 89f52af438
commit f60a7bdd19
2 changed files with 28 additions and 2 deletions

View file

@ -648,3 +648,13 @@ Comment[zh_CN]=收到通知
Comment[zh_TW]=收到通知
Action=Popup
ShowInHistory=false
[Event/remoteLockSuccess]
Name=Remote Lock Successful
Comment=Remote lock successful
Action=Popup
[Event/remoteLockFailure]
Name=Remote Lock Failure
Comment=Remote lock failed
Action=Popup

View file

@ -12,6 +12,7 @@
#include <QDebug>
#include "plugin_lock_debug.h"
#include <core/daemon.h>
#include <core/device.h>
#include <dbushelper.h>
@ -82,12 +83,27 @@ bool LockDevicePlugin::receivePacket(const NetworkPacket & np)
sendState();
}
// Receiving result of setLocked
if (np.has(QStringLiteral("lockResult"))) {
bool lockSuccess = np.get<bool>(QStringLiteral("lockResult"));
if (lockSuccess) {
Daemon::instance()->sendSimpleNotification(QStringLiteral("remoteLockSuccess"), device()->name(), i18n("Remote lock successful"), QStringLiteral("lock"));
} else {
Daemon::instance()->sendSimpleNotification(QStringLiteral("remoteLockFailure"), 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<bool>(QStringLiteral("setLocked"));
bool success = false;
if (lock) {
m_login1Interface.Lock();
} else {
success = m_login1Interface.lockedHint();
NetworkPacket np(PACKET_TYPE_LOCK, {{QStringLiteral("lockResult"), success}});
sendPacket(np);
}
else {
m_login1Interface.Unlock();
}