kdeconnect-kde/plugins/lockdevice/lockdeviceplugin-win.cpp
Alexander Lohnau 2e67f95017 Add explicit moc includes to cpp files
The rationale is explained in https://planet.kde.org/friedrich-kossebau-2023-06-28-include-also-moc-files-of-headers/

In case of KDEConnect, it impressively speeds up compilation. Before it
took 390 seconds on a clean build and with this change it took 330 seconds.
This is due to the mocs_compilation having to include the header files
and thus all their headers. Due to the lots of small plugins we have,
this means that the same headers must be compiled plenty of times.
When we include the moc files directly in the C++ file, they are already
available.
2023-07-30 07:27:45 +00:00

102 lines
3 KiB
C++

/**
* 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 "plugin_lock_debug.h"
#include <QDebug>
#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)
{
}
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"
#include "moc_lockdeviceplugin-win.cpp"