Commit bf4ac716 authored by Piyush Aggarwal's avatar Piyush Aggarwal 🎮
Browse files

plugins/lockdevice: add support for Windows

parent f60a7bdd
Pipeline #66324 passed with stage
in 3 minutes and 54 seconds
......@@ -8,7 +8,13 @@ ecm_qt_declare_logging_category(
DEFAULT_SEVERITY Warning
EXPORT kdeconnect-kde DESCRIPTION "kdeconnect (plugin lockremote)")
kdeconnect_add_plugin(kdeconnect_lockdevice JSON kdeconnect_lockdevice.json SOURCES lockdeviceplugin.cpp ${lockdevice_SRCS} ${debug_file_SRCS})
if (WIN32)
list(APPEND lockdevice_SRCS lockdeviceplugin-win.cpp)
else ()
list(APPEND lockdevice_SRCS lockdeviceplugin.cpp)
endif()
kdeconnect_add_plugin(kdeconnect_lockdevice JSON kdeconnect_lockdevice.json SOURCES ${lockdevice_SRCS} ${debug_file_SRCS})
target_link_libraries(kdeconnect_lockdevice
kdeconnectcore
......
/**
* SPDX-FileCopyrightText: 2021 Piyush Aggarwal <piyushaggarwal002@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "lockdeviceplugin-win.h"
#include <KLocalizedString>
#include <KPluginFactory>
#include <QDebug>
#include "plugin_lock_debug.h"
#include <core/daemon.h>
#include <core/device.h>
#include <dbushelper.h>
#include <Windows.h>
#pragma comment( lib, "user32.lib" )
K_PLUGIN_CLASS_WITH_JSON(LockDevicePlugin, "kdeconnect_lockdevice.json")
LockDevicePlugin::LockDevicePlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args)
, m_remoteLocked(false)
{
}
LockDevicePlugin::~LockDevicePlugin()
{
}
bool LockDevicePlugin::isLocked() const
{
return m_remoteLocked; // Windows doesn't support monitoring lock status, m_remoteLocked is never updated
}
void LockDevicePlugin::setLocked(bool locked)
{
NetworkPacket np(PACKET_TYPE_LOCK_REQUEST, {{QStringLiteral("setLocked"), locked}});
sendPacket(np);
}
bool LockDevicePlugin::receivePacket(const NetworkPacket &np)
{
if (np.has(QStringLiteral("isLocked"))) {
bool locked = np.get<bool>(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<bool>(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<bool>(QStringLiteral("setLocked"));
bool success = false;
if (lock) {
success = LockWorkStation();
NetworkPacket np(PACKET_TYPE_LOCK, {{QStringLiteral("lockResult"), success}});
sendPacket(np);
}
sendState();
}
return true;
}
void LockDevicePlugin::sendState()
{
NetworkPacket np(PACKET_TYPE_LOCK, {{QStringLiteral("isLocked"), m_localLocked}});
sendPacket(np);
}
void LockDevicePlugin::connected()
{
NetworkPacket np(PACKET_TYPE_LOCK_REQUEST, {{QStringLiteral("requestLocked"), QVariant()}});
sendPacket(np);
}
QString LockDevicePlugin::dbusPath() const
{
return QStringLiteral("/modules/kdeconnect/devices/") + device()->id() + QStringLiteral("/lockdevice");
}
#include "lockdeviceplugin-win.moc"
/**
* SPDX-FileCopyrightText: 2021 Piyush Aggarwal <piyushaggarwal002@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#ifndef LOCKDEVICEPLUGIN_WIN_H
#define LOCKDEVICEPLUGIN_WIN_H
#include <QObject>
#include <core/kdeconnectplugin.h>
#define PACKET_TYPE_LOCK QStringLiteral("kdeconnect.lock")
#define PACKET_TYPE_LOCK_REQUEST QStringLiteral("kdeconnect.lock.request")
class Q_DECL_EXPORT LockDevicePlugin
: public KdeConnectPlugin
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.lockdevice")
Q_PROPERTY(bool isLocked READ isLocked WRITE setLocked NOTIFY lockedChanged)
public:
explicit LockDevicePlugin(QObject* parent, const QVariantList &args);
~LockDevicePlugin() override;
bool isLocked() const;
Q_SCRIPTABLE void setLocked(bool);
QString dbusPath() const override;
void connected() override;
bool receivePacket(const NetworkPacket &np) override;
Q_SIGNALS:
Q_SCRIPTABLE void lockedChanged(bool locked);
private:
void sendState();
bool m_remoteLocked = false;
bool m_localLocked = false;
};
#endif //LOCKDEVICEPLUGIN_WIN_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment