Changeset View
Changeset View
Standalone View
Standalone View
core/backends/lan/lanpairinghandler.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #include <KLocalizedString> | 21 | #include <KLocalizedString> | ||
22 | 22 | | |||
23 | #include "core_debug.h" | 23 | #include "core_debug.h" | ||
24 | #include "daemon.h" | 24 | #include "daemon.h" | ||
25 | #include "kdeconnectconfig.h" | 25 | #include "kdeconnectconfig.h" | ||
26 | #include "landevicelink.h" | 26 | #include "landevicelink.h" | ||
27 | #include "lanpairinghandler.h" | 27 | #include "lanpairinghandler.h" | ||
28 | #include "networkpackagetypes.h" | 28 | #include "networkpackettypes.h" | ||
29 | 29 | | |||
30 | LanPairingHandler::LanPairingHandler(DeviceLink* deviceLink) | 30 | LanPairingHandler::LanPairingHandler(DeviceLink* deviceLink) | ||
31 | : PairingHandler(deviceLink) | 31 | : PairingHandler(deviceLink) | ||
32 | , m_status(NotPaired) | 32 | , m_status(NotPaired) | ||
33 | { | 33 | { | ||
34 | m_pairingTimeout.setSingleShot(true); | 34 | m_pairingTimeout.setSingleShot(true); | ||
35 | m_pairingTimeout.setInterval(pairingTimeoutMsec()); | 35 | m_pairingTimeout.setInterval(pairingTimeoutMsec()); | ||
36 | connect(&m_pairingTimeout, &QTimer::timeout, this, &LanPairingHandler::pairingTimeout); | 36 | connect(&m_pairingTimeout, &QTimer::timeout, this, &LanPairingHandler::pairingTimeout); | ||
37 | } | 37 | } | ||
38 | 38 | | |||
39 | void LanPairingHandler::packageReceived(const NetworkPackage& np) | 39 | void LanPairingHandler::packetReceived(const NetworkPacket& np) | ||
40 | { | 40 | { | ||
41 | bool wantsPair = np.get<bool>(QStringLiteral("pair")); | 41 | bool wantsPair = np.get<bool>(QStringLiteral("pair")); | ||
42 | 42 | | |||
43 | if (wantsPair) { | 43 | if (wantsPair) { | ||
44 | 44 | | |||
45 | if (isPairRequested()) { //We started pairing | 45 | if (isPairRequested()) { //We started pairing | ||
46 | 46 | | |||
47 | qCDebug(KDECONNECT_CORE) << "Pair answer"; | 47 | qCDebug(KDECONNECT_CORE) << "Pair answer"; | ||
Show All 27 Lines | 74 | if (m_status == Paired) { | |||
75 | Q_EMIT pairingError(i18n("%1: Already paired", deviceLink()->name())); | 75 | Q_EMIT pairingError(i18n("%1: Already paired", deviceLink()->name())); | ||
76 | return false; | 76 | return false; | ||
77 | } | 77 | } | ||
78 | if (m_status == RequestedByPeer) { | 78 | if (m_status == RequestedByPeer) { | ||
79 | qCDebug(KDECONNECT_CORE) << deviceLink()->name() << ": Pairing already started by the other end, accepting their request."; | 79 | qCDebug(KDECONNECT_CORE) << deviceLink()->name() << ": Pairing already started by the other end, accepting their request."; | ||
80 | return acceptPairing(); | 80 | return acceptPairing(); | ||
81 | } | 81 | } | ||
82 | 82 | | |||
83 | NetworkPackage np(PACKAGE_TYPE_PAIR, {{"pair", true}}); | 83 | NetworkPacket np(PACKET_TYPE_PAIR, {{"pair", true}}); | ||
84 | const bool success = deviceLink()->sendPackage(np); | 84 | const bool success = deviceLink()->sendPacket(np); | ||
85 | if (success) { | 85 | if (success) { | ||
86 | setInternalPairStatus(Requested); | 86 | setInternalPairStatus(Requested); | ||
87 | } | 87 | } | ||
88 | return success; | 88 | return success; | ||
89 | } | 89 | } | ||
90 | 90 | | |||
91 | bool LanPairingHandler::acceptPairing() | 91 | bool LanPairingHandler::acceptPairing() | ||
92 | { | 92 | { | ||
93 | NetworkPackage np(PACKAGE_TYPE_PAIR, {{"pair", true}}); | 93 | NetworkPacket np(PACKET_TYPE_PAIR, {{"pair", true}}); | ||
94 | bool success = deviceLink()->sendPackage(np); | 94 | bool success = deviceLink()->sendPacket(np); | ||
95 | if (success) { | 95 | if (success) { | ||
96 | setInternalPairStatus(Paired); | 96 | setInternalPairStatus(Paired); | ||
97 | } | 97 | } | ||
98 | return success; | 98 | return success; | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | void LanPairingHandler::rejectPairing() | 101 | void LanPairingHandler::rejectPairing() | ||
102 | { | 102 | { | ||
103 | NetworkPackage np(PACKAGE_TYPE_PAIR, {{"pair", false}}); | 103 | NetworkPacket np(PACKET_TYPE_PAIR, {{"pair", false}}); | ||
104 | deviceLink()->sendPackage(np); | 104 | deviceLink()->sendPacket(np); | ||
105 | setInternalPairStatus(NotPaired); | 105 | setInternalPairStatus(NotPaired); | ||
106 | } | 106 | } | ||
107 | 107 | | |||
108 | void LanPairingHandler::unpair() { | 108 | void LanPairingHandler::unpair() { | ||
109 | NetworkPackage np(PACKAGE_TYPE_PAIR, {{"pair", false}}); | 109 | NetworkPacket np(PACKET_TYPE_PAIR, {{"pair", false}}); | ||
110 | deviceLink()->sendPackage(np); | 110 | deviceLink()->sendPacket(np); | ||
111 | setInternalPairStatus(NotPaired); | 111 | setInternalPairStatus(NotPaired); | ||
112 | } | 112 | } | ||
113 | 113 | | |||
114 | void LanPairingHandler::pairingTimeout() | 114 | void LanPairingHandler::pairingTimeout() | ||
115 | { | 115 | { | ||
116 | NetworkPackage np(PACKAGE_TYPE_PAIR, {{"pair", false}}); | 116 | NetworkPacket np(PACKET_TYPE_PAIR, {{"pair", false}}); | ||
117 | deviceLink()->sendPackage(np); | 117 | deviceLink()->sendPacket(np); | ||
118 | setInternalPairStatus(NotPaired); //Will emit the change as well | 118 | setInternalPairStatus(NotPaired); //Will emit the change as well | ||
119 | Q_EMIT pairingError(i18n("Timed out")); | 119 | Q_EMIT pairingError(i18n("Timed out")); | ||
120 | } | 120 | } | ||
121 | 121 | | |||
122 | void LanPairingHandler::setInternalPairStatus(LanPairingHandler::InternalPairStatus status) | 122 | void LanPairingHandler::setInternalPairStatus(LanPairingHandler::InternalPairStatus status) | ||
123 | { | 123 | { | ||
124 | if (status == Requested || status == RequestedByPeer) { | 124 | if (status == Requested || status == RequestedByPeer) { | ||
125 | m_pairingTimeout.start(); | 125 | m_pairingTimeout.start(); | ||
Show All 17 Lines |