Changeset View
Changeset View
Standalone View
Standalone View
plugins/lockdevice/lockdeviceplugin.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | bool LockDevicePlugin::isLocked() const | 49 | bool LockDevicePlugin::isLocked() const | ||
50 | { | 50 | { | ||
51 | return m_remoteLocked; | 51 | return m_remoteLocked; | ||
52 | } | 52 | } | ||
53 | void LockDevicePlugin::setLocked(bool locked) | 53 | void LockDevicePlugin::setLocked(bool locked) | ||
54 | { | 54 | { | ||
55 | NetworkPackage np(PACKAGE_TYPE_LOCK_REQUEST, {{"setLocked", locked}}); | 55 | NetworkPacket np(PACKET_TYPE_LOCK_REQUEST, {{"setLocked", locked}}); | ||
56 | sendPackage(np); | 56 | sendPacket(np); | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | bool LockDevicePlugin::receivePackage(const NetworkPackage & np) | 59 | bool LockDevicePlugin::receivePacket(const NetworkPacket & np) | ||
60 | { | 60 | { | ||
61 | if (np.has(QStringLiteral("isLocked"))) { | 61 | if (np.has(QStringLiteral("isLocked"))) { | ||
62 | bool locked = np.get<bool>(QStringLiteral("isLocked")); | 62 | bool locked = np.get<bool>(QStringLiteral("isLocked")); | ||
63 | if (m_remoteLocked != locked) { | 63 | if (m_remoteLocked != locked) { | ||
64 | m_remoteLocked = locked; | 64 | m_remoteLocked = locked; | ||
65 | Q_EMIT lockedChanged(locked); | 65 | Q_EMIT lockedChanged(locked); | ||
66 | } | 66 | } | ||
67 | } | 67 | } | ||
68 | 68 | | |||
69 | bool sendState = np.has(QStringLiteral("requestLocked")); | 69 | bool sendState = np.has(QStringLiteral("requestLocked")); | ||
70 | if (np.has(QStringLiteral("setLocked"))) { | 70 | if (np.has(QStringLiteral("setLocked"))) { | ||
71 | iface()->SetActive(np.get<bool>(QStringLiteral("setLocked"))); | 71 | iface()->SetActive(np.get<bool>(QStringLiteral("setLocked"))); | ||
72 | sendState = true; | 72 | sendState = true; | ||
73 | } | 73 | } | ||
74 | if (sendState) { | 74 | if (sendState) { | ||
75 | NetworkPackage np(PACKAGE_TYPE_LOCK, QVariantMap {{"isLocked", QVariant::fromValue<bool>(iface()->GetActive())}}); | 75 | NetworkPacket np(PACKET_TYPE_LOCK, QVariantMap {{"isLocked", QVariant::fromValue<bool>(iface()->GetActive())}}); | ||
76 | sendPackage(np); | 76 | sendPacket(np); | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | return true; | 79 | return true; | ||
80 | } | 80 | } | ||
81 | 81 | | |||
82 | OrgFreedesktopScreenSaverInterface* LockDevicePlugin::iface() | 82 | OrgFreedesktopScreenSaverInterface* LockDevicePlugin::iface() | ||
83 | { | 83 | { | ||
84 | if (!m_iface) { | 84 | if (!m_iface) { | ||
85 | m_iface = new OrgFreedesktopScreenSaverInterface(QStringLiteral("org.freedesktop.ScreenSaver"), QStringLiteral("/org/freedesktop/ScreenSaver"), QDBusConnection::sessionBus()); | 85 | m_iface = new OrgFreedesktopScreenSaverInterface(QStringLiteral("org.freedesktop.ScreenSaver"), QStringLiteral("/org/freedesktop/ScreenSaver"), QDBusConnection::sessionBus()); | ||
86 | if(!m_iface->isValid()) | 86 | if(!m_iface->isValid()) | ||
87 | qCWarning(KDECONNECT_PLUGIN_LOCKREMOTE) << "Couldn't connect to the ScreenSaver interface"; | 87 | qCWarning(KDECONNECT_PLUGIN_LOCKREMOTE) << "Couldn't connect to the ScreenSaver interface"; | ||
88 | } | 88 | } | ||
89 | return m_iface; | 89 | return m_iface; | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | void LockDevicePlugin::connected() | 92 | void LockDevicePlugin::connected() | ||
93 | { | 93 | { | ||
94 | NetworkPackage np(PACKAGE_TYPE_LOCK_REQUEST, {{"requestLocked", QVariant()}}); | 94 | NetworkPacket np(PACKET_TYPE_LOCK_REQUEST, {{"requestLocked", QVariant()}}); | ||
95 | sendPackage(np); | 95 | sendPacket(np); | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | QString LockDevicePlugin::dbusPath() const | 98 | QString LockDevicePlugin::dbusPath() const | ||
99 | { | 99 | { | ||
100 | return "/modules/kdeconnect/devices/" + device()->id() + "/lockdevice"; | 100 | return "/modules/kdeconnect/devices/" + device()->id() + "/lockdevice"; | ||
101 | } | 101 | } | ||
102 | 102 | | |||
103 | #include "lockdeviceplugin.moc" | 103 | #include "lockdeviceplugin.moc" |